Merge wxComboCtrl::InstallInputHandlers() into CreateTextCtrl()

This function was always called after calling CreateTextCtrl() and
couldn't be called at any other moment, so it didn't make much sense to
have it as a separate function, just install the custom input handler
when (re)creating the text control.

This simplifies the derived classes code.
This commit is contained in:
Vadim Zeitlin
2021-07-10 16:49:57 +01:00
parent f3f3b00c6b
commit cf3ebcea1a
4 changed files with 9 additions and 31 deletions

View File

@@ -509,9 +509,6 @@ protected:
// (e.g. from WriteText()) // (e.g. from WriteText())
void OnSetValue(const wxString& value); void OnSetValue(const wxString& value);
// Installs standard input handler to combo (and optionally to the textctrl)
void InstallInputHandlers();
// Flags for DrawButton // Flags for DrawButton
enum enum
{ {

View File

@@ -1068,22 +1068,19 @@ bool wxComboCtrlBase::Create(wxWindow *parent,
return true; return true;
} }
void wxComboCtrlBase::InstallInputHandlers()
{
if ( m_text )
{
m_textEvtHandler = new wxComboBoxExtraInputHandler(this);
m_text->PushEventHandler(m_textEvtHandler);
}
}
void void
wxComboCtrlBase::CreateTextCtrl(int style) wxComboCtrlBase::CreateTextCtrl(int style)
{ {
if ( !(m_windowStyle & wxCB_READONLY) ) if ( !(m_windowStyle & wxCB_READONLY) )
{ {
if ( m_text ) if ( m_text )
{
m_text->RemoveEventHandler(m_textEvtHandler);
delete m_textEvtHandler;
m_textEvtHandler = NULL;
m_text->Destroy(); m_text->Destroy();
}
// wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
// not used by the wxPropertyGrid and therefore the tab is processed by // not used by the wxPropertyGrid and therefore the tab is processed by
@@ -1094,14 +1091,6 @@ wxComboCtrlBase::CreateTextCtrl(int style)
if ( HasFlag(wxTE_PROCESS_ENTER) ) if ( HasFlag(wxTE_PROCESS_ENTER) )
style |= wxTE_PROCESS_ENTER; style |= wxTE_PROCESS_ENTER;
// Ignore EVT_TEXT generated by the constructor (but only
// if the event redirector already exists)
// NB: This must be " = 1" instead of "++";
if ( m_textEvtHandler )
m_ignoreEvtText = 1;
else
m_ignoreEvtText = 0;
m_text = new wxComboCtrlTextCtrl(); m_text = new wxComboCtrlTextCtrl();
m_text->Create(this, wxID_ANY, m_valueString, m_text->Create(this, wxID_ANY, m_valueString,
wxDefaultPosition, wxSize(10,-1), wxDefaultPosition, wxSize(10,-1),
@@ -1115,6 +1104,9 @@ wxComboCtrlBase::CreateTextCtrl(int style)
} }
m_text->SetHint(m_hintText); m_text->SetHint(m_hintText);
m_textEvtHandler = new wxComboBoxExtraInputHandler(this);
m_text->PushEventHandler(m_textEvtHandler);
} }
} }

View File

@@ -177,9 +177,6 @@ bool wxGenericComboCtrl::Create(wxWindow *parent,
// Create textctrl, if necessary // Create textctrl, if necessary
CreateTextCtrl( tcBorder ); CreateTextCtrl( tcBorder );
// Add keyboard input handlers for main control and textctrl
InstallInputHandlers();
// Set background style for double-buffering, when needed // Set background style for double-buffering, when needed
// (cannot use when system draws background automatically) // (cannot use when system draws background automatically)
if ( !HasTransparentBackground() ) if ( !HasTransparentBackground() )
@@ -419,12 +416,7 @@ void wxGenericComboCtrl::SetCustomPaintWidth( int width )
// Common textctrl re-creation code // Common textctrl re-creation code
if ( tcCreateStyle != -1 ) if ( tcCreateStyle != -1 )
{ {
tc->RemoveEventHandler(m_textEvtHandler);
delete m_textEvtHandler;
CreateTextCtrl( tcCreateStyle ); CreateTextCtrl( tcCreateStyle );
InstallInputHandlers();
} }
} }
#endif // UNRELIABLE_TEXTCTRL_BORDER #endif // UNRELIABLE_TEXTCTRL_BORDER

View File

@@ -120,9 +120,6 @@ bool wxComboCtrl::Create(wxWindow *parent,
// Create textctrl, if necessary // Create textctrl, if necessary
CreateTextCtrl( wxNO_BORDER ); CreateTextCtrl( wxNO_BORDER );
// Add keyboard input handlers for main control and textctrl
InstallInputHandlers();
// SetInitialSize should be called last // SetInitialSize should be called last
SetInitialSize(size); SetInitialSize(size);