From a4487c056ba9b22144cea974ec86dcc0267a7bc2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 17 Feb 2018 17:13:34 +0100 Subject: [PATCH] Preserve style changes in wxGTK wxTextEntry auto-complete code Don't overwrite the current window style with the style that it had when AutoComplete() was called in wxGTK code, just turn wxTE_PROCESS_ENTER off or on, without touching the other bits. This still can result in setting wxTE_PROCESS_ENTER bit itself unexpectedly if it somehow is changed while the completion popup is shown, but this shouldn't happen often (if ever) in practice and, at least, the other bits are preserved no matter what. See https://github.com/wxWidgets/wxWidgets/pull/729 --- src/gtk/textentry.cpp | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index d34229d3b2b0..c608a609de11 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -228,11 +228,33 @@ class wxTextAutoCompleteData // see wxTextCtrl::OnChar() void ToggleProcessEnterFlag(bool toggleOff) { - long flags = m_origWinFlags; + wxWindow* const win = GetEditableWindow(m_entry); + + long flags = win->GetWindowStyleFlag(); if ( toggleOff ) + { + // Store the original window flags before we change them. + m_hadProcessEnterFlag = (flags & wxTE_PROCESS_ENTER) != 0; + if ( !m_hadProcessEnterFlag ) + { + // No need to do anything, it was already off. + return; + } + flags &= ~wxTE_PROCESS_ENTER; + } + else // Restore the original flags. + { + if ( !m_hadProcessEnterFlag ) + { + // We hadn't turned it off, no need to turn it back on. + return; + } - GetEditableWindow(m_entry)->SetWindowStyleFlag(flags); + flags |= wxTE_PROCESS_ENTER; + } + + win->SetWindowStyleFlag(flags); } virtual ~wxTextAutoCompleteData() @@ -261,9 +283,11 @@ class wxTextAutoCompleteData explicit wxTextAutoCompleteData(wxTextEntry* entry) : m_entry(entry), - m_widgetEntry(entry->GetEntry()), - m_origWinFlags(GetEditableWindow(m_entry)->GetWindowStyleFlag()) + m_widgetEntry(entry->GetEntry()) { + // This will be really set in ToggleProcessEnterFlag(). + m_hadProcessEnterFlag = false; + GtkEntryCompletion* const completion = gtk_entry_completion_new(); gtk_entry_completion_set_text_column (completion, 0); @@ -305,8 +329,9 @@ class wxTextAutoCompleteData // And its GTK widget. GtkEntry* const m_widgetEntry; - // The original flags of the associated wxTextEntry. - const long m_origWinFlags; + // True if the window had wxTE_PROCESS_ENTER flag before we turned it off + // in ToggleProcessEnterFlag(). + bool m_hadProcessEnterFlag; wxDECLARE_NO_COPY_CLASS(wxTextAutoCompleteData); };