Skip to content

Commit

Permalink
Preserve style changes in wxGTK wxTextEntry auto-complete code
Browse files Browse the repository at this point in the history
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 wxWidgets#729
  • Loading branch information
vadz committed Feb 18, 2018
1 parent 8278f7b commit a4487c0
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/gtk/textentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
};
Expand Down

0 comments on commit a4487c0

Please sign in to comment.