diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index af00d41d06..d9a6090ae7 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -665,11 +665,6 @@ public: 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 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); diff --git a/include/wx/textentry.h b/include/wx/textentry.h index f773635ea1..701893bc8f 100644 --- a/include/wx/textentry.h +++ b/include/wx/textentry.h @@ -158,6 +158,16 @@ public: wxPoint GetMargins() const { 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: // flags for DoSetValue(): common part of SetValue() and ChangeValue() and // also used to implement WriteText() in wxMSW @@ -207,8 +217,19 @@ protected: friend class EventsSuppressor; - // return true if the events are currently not suppressed - bool EventsAllowed() const { return m_eventsBlock == 0; } + // generate the wxEVT_COMMAND_TEXT_UPDATED event for this window + 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: // 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 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 unsigned m_eventsBlock; diff --git a/src/cocoa/textctrl.mm b/src/cocoa/textctrl.mm index d33626cd18..b42cb65b2e 100644 --- a/src/cocoa/textctrl.mm +++ b/src/cocoa/textctrl.mm @@ -94,15 +94,7 @@ void wxTextCtrl::Cocoa_didChangeText(void) void wxTextCtrl::CocoaTarget_action(void) { - // NSTextField only sends the action message on enter key press and thus - // 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); + SendTextUpdatedEvent(); } void wxTextCtrl::AppendText(wxString const&) diff --git a/src/common/textcmn.cpp b/src/common/textcmn.cpp index 06824dd481..fa4d41ffbc 100644 --- a/src/common/textcmn.cpp +++ b/src/common/textcmn.cpp @@ -1006,25 +1006,6 @@ wxTextAreaBase::HitTest(const wxPoint& WXUNUSED(pt), long * WXUNUSED(pos)) const 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 // define this one even if !wxUSE_TEXTCTRL because it is also used by other diff --git a/src/common/textentrycmn.cpp b/src/common/textentrycmn.cpp index f7b11237ef..9dc8ca9461 100644 --- a/src/common/textentrycmn.cpp +++ b/src/common/textentrycmn.cpp @@ -279,4 +279,25 @@ wxPoint wxTextEntryBase::DoGetMargins() const 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 diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 1c2fa3c814..23573fcdd1 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -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) ClearSelection(); - if ( EventsAllowed() ) - SendTextUpdatedEvent(); + SendTextUpdatedEventIfAllowed(); } void wxTextCtrl::Remove(wxTextPos from, wxTextPos to)