From a8c05945b4e7dc87fb216466b29d3afcbf712169 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Oct 2021 21:38:41 +0100 Subject: [PATCH 1/3] Log the length of the window label if creating it fails in wxMSW This can be useful in case of unexpected window creation failure, so log it because it doesn't cost much for something that is supposed to practically never happen anyhow. --- src/msw/window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 87d3486ae8..449ad39e3f 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4049,8 +4049,8 @@ WXHWND wxWindowMSW::MSWCreateWindowAtAnyPosition(WXDWORD exStyle, const wxChar* { wxLogLastError(wxString::Format ( - wxT("CreateWindowEx(\"%s\", flags=%08lx, ex=%08lx)"), - clName, style, exStyle + wxT("CreateWindowEx(\"%s\", flags=%08lx, ex=%08lx, title-len=%zu)"), + clName, style, exStyle, title ? wxStrlen(title) : 0 )); } else if ( !IsTopLevel() && !MSWIsPositionDirectlySupported(x, y) ) From d585bb1ebd30b61b2eba1816cca8412393dbc98f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Oct 2021 21:39:37 +0100 Subject: [PATCH 2/3] Automatically turn wxTE_RICH2 for wxMSW wxTextCtrl if necessary When creating a wxTextCtrl with the initial text which is too long to fit into a plain EDIT, automatically create RICHEDIT instead. This is not perfect, e.g. it still doesn't make calling SetValue() with long text later work, but it seems to still be preferable to failing to create the window completely, which results in many other more difficult to diagnose problems later. --- src/msw/textctrl.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 4e06cff953..dfd2b08f10 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -583,7 +583,22 @@ bool wxTextCtrl::MSWCreateText(const wxString& value, m_updatesCount = -2; if ( !MSWCreateControl(windowClass.t_str(), msStyle, pos, size, valueWin) ) + { + // There is one case in which window creation may realistically fail + // and this is when we create a plain EDIT control with too long text, + // so try to detect this and transparently switch to using RICHEDIT in + // this case (note that the exact length cut off is unknown and might + // be system-dependent, but even though plain EDIT works for texts + // longer than 64KiB, we don't lose much by trying to use RICHEDIT if + // creating it failed). + if ( !HasFlag(wxTE_RICH | wxTE_RICH2) && value.length() >= 0x10000 ) + { + m_windowStyle |= wxTE_RICH2; + return MSWCreateText(value, pos, size); + } + return false; + } m_updatesCount = -1; From b744e271e35ef6c7396461d11577ad41d837f852 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Oct 2021 21:41:30 +0100 Subject: [PATCH 3/3] Create multiline controls with wxTE_RICH2 in wxTextEntryDialog While wxMSW now turns this style on automatically if necessary, it's still better to avoid the failure during the initial control creation, so enable wxTE_RICH2 from the beginning in wxTextEntryDialog, where it shouldn't result in any incompatibilities. --- src/generic/textdlgg.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/generic/textdlgg.cpp b/src/generic/textdlgg.cpp index 912b46ef00..b9d2e10995 100644 --- a/src/generic/textdlgg.cpp +++ b/src/generic/textdlgg.cpp @@ -97,7 +97,11 @@ bool wxTextEntryDialog::Create(wxWindow *parent, topsizer->Add(CreateTextSizer(message), flagsBorder2); #endif - // 2) text ctrl + // 2) text ctrl: create it with wxTE_RICH2 style to allow putting more than + // 64KiB of text into it + if ( style & wxTE_MULTILINE ) + style |= wxTE_RICH2; + m_textctrl = new wxTextCtrl(this, wxID_TEXT, value, wxDefaultPosition, wxSize(300, wxDefaultCoord), style & ~wxTextEntryDialogStyle);