Move SendTextUpdatedEvent() down to wxTextEntryBase from wxTextCtrlBase.

This will allow reusing it in wxComboBox implementation as well.

Also add SendTextUpdatedEventIfAllowed() which can be used to only send the
events if they were not blocked at wxTextEntry level.

No real changes otherwise.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63880 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-04-06 18:46:24 +00:00
parent ca1f7cb563
commit 501358073b
6 changed files with 50 additions and 37 deletions

View File

@@ -665,11 +665,6 @@ public:
virtual bool EmulateKeyPress(const wxKeyEvent& event); virtual bool EmulateKeyPress(const wxKeyEvent& event);
// generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does and
// return true if the event was processed
static bool SendTextUpdatedEvent(wxWindow *win);
bool SendTextUpdatedEvent() { return SendTextUpdatedEvent(this); }
// do the window-specific processing after processing the update event // do the window-specific processing after processing the update event
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);

View File

@@ -158,6 +158,16 @@ public:
wxPoint GetMargins() const wxPoint GetMargins() const
{ return DoGetMargins(); } { return DoGetMargins(); }
// events
// ------
// generate the wxEVT_COMMAND_TEXT_UPDATED event for GetEditableWindow(),
// like SetValue() does and return true if the event was processed
//
// NB: this is public for wxRichTextCtrl use only right now, do not call it
static bool SendTextUpdatedEvent(wxWindow *win);
protected: protected:
// flags for DoSetValue(): common part of SetValue() and ChangeValue() and // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
// also used to implement WriteText() in wxMSW // also used to implement WriteText() in wxMSW
@@ -207,8 +217,19 @@ protected:
friend class EventsSuppressor; friend class EventsSuppressor;
// return true if the events are currently not suppressed // generate the wxEVT_COMMAND_TEXT_UPDATED event for this window
bool EventsAllowed() const { return m_eventsBlock == 0; } bool SendTextUpdatedEvent()
{
return SendTextUpdatedEvent(GetEditableWindow());
}
// generate the wxEVT_COMMAND_TEXT_UPDATED event for this window if the
// events are not currently disabled
void SendTextUpdatedEventIfAllowed()
{
if ( EventsAllowed() )
SendTextUpdatedEvent();
}
private: private:
// suppress or resume the text changed events generation: don't use these // suppress or resume the text changed events generation: don't use these
@@ -233,6 +254,10 @@ private:
// initially the generation of the events is enabled // initially the generation of the events is enabled
virtual void EnableTextChangedEvents(bool WXUNUSED(enable)) { } virtual void EnableTextChangedEvents(bool WXUNUSED(enable)) { }
// return true if the events are currently not suppressed
bool EventsAllowed() const { return m_eventsBlock == 0; }
// if this counter is non-null, events are blocked // if this counter is non-null, events are blocked
unsigned m_eventsBlock; unsigned m_eventsBlock;

View File

@@ -94,15 +94,7 @@ void wxTextCtrl::Cocoa_didChangeText(void)
void wxTextCtrl::CocoaTarget_action(void) void wxTextCtrl::CocoaTarget_action(void)
{ {
// NSTextField only sends the action message on enter key press and thus SendTextUpdatedEvent();
// we send the appropriate event type.
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId());
// See wxTextCtrlBase::SendTextUpdatedEvent for why we don't set the string.
//event.SetString(GetValue());
event.SetEventObject(this);
HandleWindowEvent(event);
} }
void wxTextCtrl::AppendText(wxString const&) void wxTextCtrl::AppendText(wxString const&)

View File

@@ -1006,25 +1006,6 @@ wxTextAreaBase::HitTest(const wxPoint& WXUNUSED(pt), long * WXUNUSED(pos)) const
return wxTE_HT_UNKNOWN; return wxTE_HT_UNKNOWN;
} }
// ----------------------------------------------------------------------------
// events
// ----------------------------------------------------------------------------
/* static */
bool wxTextCtrlBase::SendTextUpdatedEvent(wxWindow *win)
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, win->GetId());
// do not do this as it could be very inefficient if the text control
// contains a lot of text and we're not using ref-counted wxString
// implementation -- instead, event.GetString() will query the control for
// its current text if needed
//event.SetString(win->GetValue());
event.SetEventObject(win);
return win->GetEventHandler()->ProcessEvent(event);
}
#else // !wxUSE_TEXTCTRL #else // !wxUSE_TEXTCTRL
// define this one even if !wxUSE_TEXTCTRL because it is also used by other // define this one even if !wxUSE_TEXTCTRL because it is also used by other

View File

@@ -279,4 +279,25 @@ wxPoint wxTextEntryBase::DoGetMargins() const
return wxPoint(-1, -1); return wxPoint(-1, -1);
} }
// ----------------------------------------------------------------------------
// events
// ----------------------------------------------------------------------------
/* static */
bool wxTextEntryBase::SendTextUpdatedEvent(wxWindow *win)
{
wxCHECK_MSG( win, false, "can't send an event without a window" );
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, win->GetId());
// do not do this as it could be very inefficient if the text control
// contains a lot of text and we're not using ref-counted wxString
// implementation -- instead, event.GetString() will query the control for
// its current text if needed
//event.SetString(win->GetValue());
event.SetEventObject(win);
return win->HandleWindowEvent(event);
}
#endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX

View File

@@ -1264,8 +1264,7 @@ void wxTextCtrl::Replace(wxTextPos from, wxTextPos to, const wxString& text)
// now call it to do the rest (not related to refreshing) // now call it to do the rest (not related to refreshing)
ClearSelection(); ClearSelection();
if ( EventsAllowed() ) SendTextUpdatedEventIfAllowed();
SendTextUpdatedEvent();
} }
void wxTextCtrl::Remove(wxTextPos from, wxTextPos to) void wxTextCtrl::Remove(wxTextPos from, wxTextPos to)