From ee2ec18e88701d8f0709009616584153ca85d7a7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Oct 2006 22:40:14 +0000 Subject: [PATCH] moved DoSetValue() to wxTextCtrlBase instead of having it in almost, but not quite all, derived classes; linking fixes for wxCocoa/wxX11/wxMotif git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/textctrl.h | 5 ++- include/wx/gtk/textctrl.h | 4 +-- include/wx/gtk1/textctrl.h | 5 +-- include/wx/mac/carbon/textctrl.h | 25 +++++++------- include/wx/motif/textctrl.h | 7 ++-- include/wx/msw/textctrl.h | 4 +-- include/wx/os2/textctrl.h | 5 +-- include/wx/palmos/textctrl.h | 6 ++-- include/wx/textctrl.h | 19 ++++++----- include/wx/univ/textctrl.h | 6 ++-- include/wx/x11/textctrl.h | 10 ++---- src/cocoa/textctrl.mm | 5 ++- src/common/textcmn.cpp | 20 ++++++++++- src/gtk/textctrl.cpp | 4 +-- src/mac/carbon/textctrl.cpp | 20 +++-------- src/motif/textctrl.cpp | 5 ++- src/palmos/textctrl.cpp | 58 +------------------------------- src/univ/textctrl.cpp | 9 ++--- src/x11/textctrl.cpp | 5 ++- 19 files changed, 80 insertions(+), 142 deletions(-) diff --git a/include/wx/cocoa/textctrl.h b/include/wx/cocoa/textctrl.h index f6ea42dd6e..79d49c74de 100644 --- a/include/wx/cocoa/textctrl.h +++ b/include/wx/cocoa/textctrl.h @@ -55,9 +55,6 @@ protected: // ------------------------------------------------------------------------ public: virtual wxString GetValue() const; - virtual void SetValue(const wxString& value); - - virtual void ChangeValue(const wxString &value); virtual int GetLineLength(long lineNo) const; virtual wxString GetLineText(long lineNo) const; @@ -118,6 +115,8 @@ public: protected: virtual wxSize DoGetBestSize() const; + + virtual void DoSetValue(const wxString& value, int flags = 0); }; #endif // __WX_COCOA_TEXTCTRL_H__ diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 017116609f..8cf1c69570 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -44,8 +44,6 @@ public: virtual wxString GetValue() const; virtual bool IsEmpty() const; - virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); } - virtual void ChangeValue(const wxString& value) { DoSetValue(value); } virtual int GetLineLength(long lineNo) const; virtual wxString GetLineText(long lineNo) const; @@ -191,7 +189,7 @@ protected: // has the control been frozen by Freeze()? bool IsFrozen() const { return m_frozenness > 0; } - void DoSetValue(const wxString &value, int flags = 0); + virtual void DoSetValue(const wxString &value, int flags = 0); private: // change the font for everything in this control diff --git a/include/wx/gtk1/textctrl.h b/include/wx/gtk1/textctrl.h index 8c8f3dec07..f42b1b8193 100644 --- a/include/wx/gtk1/textctrl.h +++ b/include/wx/gtk1/textctrl.h @@ -43,9 +43,6 @@ public: // ---------------------------------- virtual wxString GetValue() const; - virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); } - - virtual void ChangeValue(const wxString &value) { DoSetValue(value); } virtual int GetLineLength(long lineNo) const; virtual wxString GetLineText(long lineNo) const; @@ -184,7 +181,7 @@ protected: // override this and return true. virtual bool UseGTKStyleBase() const { return true; } - void DoSetValue(const wxString &value, int flags = 0); + virtual void DoSetValue(const wxString &value, int flags = 0); private: // change the font for everything in this control diff --git a/include/wx/mac/carbon/textctrl.h b/include/wx/mac/carbon/textctrl.h index f77e41423a..1818f2d602 100644 --- a/include/wx/mac/carbon/textctrl.h +++ b/include/wx/mac/carbon/textctrl.h @@ -61,9 +61,6 @@ public: // accessors // --------- virtual wxString GetValue() const; - virtual void SetValue(const wxString& value); - - virtual void ChangeValue(const wxString &value); virtual int GetLineLength(long lineNo) const; virtual wxString GetLineText(long lineNo) const; @@ -187,13 +184,15 @@ public: wxMacTextControl * GetPeer() const { return (wxMacTextControl*) m_peer; } - + protected: // common part of all ctors void Init(); virtual wxSize DoGetBestSize() const; + virtual void DoSetValue(const wxString& value, int flags = 0); + bool m_editable; // flag is set to true when the user edits the controls contents @@ -201,17 +200,17 @@ protected: // need to make this public because of the current implementation via callbacks unsigned long m_maxLength; - - bool GetTriggerOnSetValue() const - { - return m_triggerOnSetValue; + + bool GetTriggerOnSetValue() const + { + return m_triggerOnSetValue; } - - void SetTriggerOnSetValue(bool trigger) - { - m_triggerOnSetValue = trigger; + + void SetTriggerOnSetValue(bool trigger) + { + m_triggerOnSetValue = trigger; } - + bool m_triggerOnSetValue ; private : diff --git a/include/wx/motif/textctrl.h b/include/wx/motif/textctrl.h index 3fdfa7ee31..22b8f50eeb 100644 --- a/include/wx/motif/textctrl.h +++ b/include/wx/motif/textctrl.h @@ -43,10 +43,6 @@ public: // accessors // --------- virtual wxString GetValue() const; - virtual void SetValue(const wxString& value) - { ChangeValue(value); SendTextUpdatedEvent(); } - - virtual void ChangeValue(const wxString &value); virtual int GetLineLength(long lineNo) const; virtual wxString GetLineText(long lineNo) const; @@ -130,6 +126,9 @@ protected: wxString m_fileName; virtual wxSize DoGetBestSize() const; + + virtual void DoSetValue(const wxString& value, int flags = 0); + public: // Motif-specific void* m_tempCallbackStruct; diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 8649f1491e..028032725d 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -46,8 +46,6 @@ public: virtual wxString GetValue() const; virtual bool IsEmpty() const; - virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); } - virtual void ChangeValue(const wxString& value) { DoSetValue(value); } virtual wxString GetRange(long from, long to) const; @@ -209,7 +207,7 @@ protected: // common part of all ctors void Init(); - void DoSetValue(const wxString &value, int flags = 0); + virtual void DoSetValue(const wxString &value, int flags = 0); // return true if this control has a user-set limit on amount of text (i.e. // the limit is due to a previous call to SetMaxLength() and not built in) diff --git a/include/wx/os2/textctrl.h b/include/wx/os2/textctrl.h index e6197dd8fd..c868ddc7ae 100644 --- a/include/wx/os2/textctrl.h +++ b/include/wx/os2/textctrl.h @@ -47,9 +47,6 @@ public: // ---------------------------------- // virtual wxString GetValue(void) const; - virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); } - - virtual void ChangeValue(const wxString &value) { DoSetValue(value); } virtual int GetLineLength(long nLineNo) const; virtual wxString GetLineText(long nLineNo) const; @@ -183,7 +180,7 @@ protected: ,WXDWORD* dwExstyle ) const; - void DoSetValue(const wxString &value, int flags = 0); + virtual void DoSetValue(const wxString &value, int flags = 0); bool m_bSkipUpdate; diff --git a/include/wx/palmos/textctrl.h b/include/wx/palmos/textctrl.h index bfb5c9b663..98d73a6be2 100644 --- a/include/wx/palmos/textctrl.h +++ b/include/wx/palmos/textctrl.h @@ -45,9 +45,6 @@ public: // ---------------------------------- virtual wxString GetValue() const; - virtual void SetValue(const wxString& value); - - virtual void ChangeValue(const wxString &value); virtual int GetLineLength(long lineNo) const; virtual wxString GetLineText(long lineNo) const; @@ -181,6 +178,9 @@ protected: // common part of all ctors void Init(); + virtual void DoSetValue(const wxString& value, int flags = 0); + + // intercept WM_GETDLGCODE virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 39908a03bf..fd6ad89317 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -298,11 +298,12 @@ public: // --------- virtual wxString GetValue() const = 0; - virtual void SetValue(const wxString& value) = 0; - virtual bool IsEmpty() const { return GetValue().empty(); } - virtual void ChangeValue(const wxString &value) = 0; + virtual void SetValue(const wxString& value) + { DoSetValue(value, SetValue_SendEvent); } + virtual void ChangeValue(const wxString& value) + { DoSetValue(value); } virtual wxString GetRange(long from, long to) const; @@ -422,6 +423,9 @@ public: wxTextCtrl& operator<<(double d); wxTextCtrl& operator<<(const wxChar c); + // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does + void SendTextUpdatedEvent(); + // do the window-specific processing after processing the update event virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); @@ -433,17 +437,16 @@ protected: int overflow(int i); #endif // wxHAS_TEXT_WINDOW_STREAM - // typically, wxTextCtrl classes will use a DoSetValue() function to - // implement both SetValue() and ChangeValue() functions and these - // flags are meant to be passed to such DoSetValue() + // flags for DoSetValue(): common part of SetValue() and ChangeValue() and + // also used to implement WriteText() in wxMSW enum { SetValue_SendEvent = 1, SetValue_SelectionOnly = 2 }; - // generate the wxEVT_COMMAND_TEXT_UPDATED event - void SendTextUpdatedEvent(); + virtual void DoSetValue(const wxString& value, int flags = 0) = 0; + // the name of the last file loaded with LoadFile() which will be used by // SaveFile() by default diff --git a/include/wx/univ/textctrl.h b/include/wx/univ/textctrl.h index 2ec12ca172..44cfaa4b46 100644 --- a/include/wx/univ/textctrl.h +++ b/include/wx/univ/textctrl.h @@ -105,9 +105,6 @@ public: // ---------------------------------- virtual wxString GetValue() const; - virtual void SetValue(const wxString& value); - - virtual void ChangeValue(const wxString &value); virtual int GetLineLength(wxTextCoord lineNo) const; virtual wxString GetLineText(wxTextCoord lineNo) const; @@ -262,6 +259,9 @@ protected: // calc the size from the text extent virtual wxSize DoGetBestClientSize() const; + // implements Set/ChangeValue() + virtual void DoSetValue(const wxString& value, int flags = 0); + // common part of all ctors void Init(); diff --git a/include/wx/x11/textctrl.h b/include/wx/x11/textctrl.h index f201439b07..97cbf58971 100644 --- a/include/wx/x11/textctrl.h +++ b/include/wx/x11/textctrl.h @@ -116,10 +116,6 @@ public: // implement base class pure virtuals // ---------------------------------- - virtual wxString GetValue() const; - virtual void SetValue(const wxString& value) - { ChangeValue(value); SendTextUpdatedEvent(); } - virtual void ChangeValue(const wxString &value); virtual int GetLineLength(long lineNo) const; @@ -132,10 +128,6 @@ public: // more readable flag testing methods // ---------------------------------- -#if 0 - // it seems now in wxTextCtrlBase - bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE); } -#endif bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; } bool WrapLines() const { return false; } @@ -274,6 +266,8 @@ protected: virtual wxSize DoGetBestSize() const; + virtual void DoSetValue(const wxString& value, int flags = 0); + friend class wxSourceUndoStep; wxSourceLineArray m_lines; diff --git a/src/cocoa/textctrl.mm b/src/cocoa/textctrl.mm index ba2bc6060d..d755334440 100644 --- a/src/cocoa/textctrl.mm +++ b/src/cocoa/textctrl.mm @@ -135,10 +135,13 @@ void wxTextCtrl::Replace(long, long, wxString const&) { } -void wxTextCtrl::SetValue(wxString const& value) +void wxTextCtrl::DoSetValue(wxString const& value, int flags) { wxAutoNSAutoreleasePool pool; [GetNSTextField() setStringValue: wxNSStringWithWxString(value)]; + + if ( flags & SetValue_SendEvent ) + SendTextUpdatedEvent(); } void wxTextCtrl::WriteText(wxString const&) diff --git a/src/common/textcmn.cpp b/src/common/textcmn.cpp index 8722f3ba0c..6f53679d6b 100644 --- a/src/common/textcmn.cpp +++ b/src/common/textcmn.cpp @@ -243,7 +243,7 @@ bool wxTextCtrlBase::DoSaveFile(const wxString& filename, int WXUNUSED(fileType) { // if it worked, save for future calls m_filename = filename; - + // it's not modified any longer DiscardEdits(); @@ -525,6 +525,24 @@ wxTextCtrlBase::HitTest(const wxPoint& WXUNUSED(pt), return wxTE_HT_UNKNOWN; } +// ---------------------------------------------------------------------------- +// events +// ---------------------------------------------------------------------------- + +void wxTextCtrlBase::SendTextUpdatedEvent() +{ + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, 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(GetValue()); + + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); +} + #else // !wxUSE_TEXTCTRL // define this one even if !wxUSE_TEXTCTRL because it is also used by other diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index a16a86876f..0638f5c1fa 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -448,9 +448,7 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) if ( win->MarkDirtyOnChange() ) win->MarkDirty(); - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); - event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event ); + win->SendTextUpdatedEvent(); } } diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index bd00109085..30e828c631 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -547,32 +547,20 @@ void wxTextCtrl::GetSelection(long* from, long* to) const GetPeer()->GetSelection( from , to ) ; } -void wxTextCtrl::SetValue(const wxString& str) +void wxTextCtrl::DoSetValue(const wxString& str, int flags) { // optimize redraws if ( GetValue() == str ) - return ; + return; GetPeer()->SetStringValue( str ) ; - if ( m_triggerOnSetValue ) + if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) { - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); - event.SetString( GetValue() ); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); + SendTextUpdatedEvent(); } } -void wxTextCtrl::ChangeValue(const wxString& str) -{ - // optimize redraws - if ( GetValue() == str ) - return ; - - GetPeer()->SetStringValue( str ) ; -} - void wxTextCtrl::SetMaxLength(unsigned long len) { m_maxLength = len ; diff --git a/src/motif/textctrl.cpp b/src/motif/textctrl.cpp index d09a620465..8213b6b8cd 100644 --- a/src/motif/textctrl.cpp +++ b/src/motif/textctrl.cpp @@ -240,7 +240,7 @@ wxString wxTextCtrl::GetValue() const return str; } -void wxTextCtrl::ChangeValue(const wxString& text) +void wxTextCtrl::DoSetValue(const wxString& text, int flags) { m_inSetValue = true; @@ -254,6 +254,9 @@ void wxTextCtrl::ChangeValue(const wxString& text) m_modified = true; m_inSetValue = false; + + if ( flags & SetValue_SendEvent ) + SendTextUpdatedEvent(); } // Clipboard operations diff --git a/src/palmos/textctrl.cpp b/src/palmos/textctrl.cpp index 7302a7fe63..e925b130c6 100644 --- a/src/palmos/textctrl.cpp +++ b/src/palmos/textctrl.cpp @@ -229,66 +229,10 @@ wxString wxTextCtrl::GetValue() const return res; } -void wxTextCtrl::SetValue(const wxString& value) +void wxTextCtrl::DoSetValue(const wxString& value, int flags) { } -void wxTextCtrl::ChangeValue(const wxString& value) -{ -} - -#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU) - -// TODO: using memcpy() would improve performance a lot for big amounts of text - -DWORD CALLBACK -wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb) -{ - return 0; -} - -// helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut -struct wxStreamOutData -{ - wchar_t *wpc; - size_t len; -}; - -DWORD CALLBACK -wxRichEditStreamOut(DWORD_PTR dwCookie, BYTE *buf, LONG cb, LONG *pcb) -{ - return 0; -} - - -#if wxUSE_UNICODE_MSLU - #define UNUSED_IF_MSLU(param) -#else - #define UNUSED_IF_MSLU(param) param -#endif - -bool -wxTextCtrl::StreamIn(const wxString& value, - wxFontEncoding UNUSED_IF_MSLU(encoding), - bool selectionOnly) -{ - return false; -} - -#if !wxUSE_UNICODE_MSLU - -wxString -wxTextCtrl::StreamOut(wxFontEncoding encoding, bool selectionOnly) const -{ - wxString out; - - return out; -} - -#endif // !wxUSE_UNICODE_MSLU - -#endif // wxUSE_RICHEDIT - void wxTextCtrl::WriteText(const wxString& value) { } diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 17ed256745..5b1c204822 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -778,7 +778,7 @@ wxTextCtrl::~wxTextCtrl() // set/get the value // ---------------------------------------------------------------------------- -void wxTextCtrl::ChangeValue(const wxString& value) +void wxTextCtrl::DoSetValue(const wxString& value, int flags) { if ( IsSingleLine() && (value == GetValue()) ) { @@ -792,12 +792,9 @@ void wxTextCtrl::ChangeValue(const wxString& value) { SetInsertionPoint(0); } -} -void wxTextCtrl::SetValue(const wxString& value) -{ - ChangeValue(value); - SendTextUpdatedEvent(); + if ( flags & SetValue_SendEvent ) + SendTextUpdatedEvent(); } const wxArrayString& wxTextCtrl::GetLines() const diff --git a/src/x11/textctrl.cpp b/src/x11/textctrl.cpp index 8f8aa99e48..02692fea0f 100644 --- a/src/x11/textctrl.cpp +++ b/src/x11/textctrl.cpp @@ -277,7 +277,7 @@ wxString wxTextCtrl::GetValue() const return ret; } -void wxTextCtrl::ChangeValue(const wxString& value) +void wxTextCtrl::DoSetValue(const wxString& value, int flags) { m_modified = false; @@ -343,6 +343,9 @@ void wxTextCtrl::ChangeValue(const wxString& value) MyAdjustScrollbars(); Refresh(); + + if ( flags & SetValue_SendEvent ) + SendTextUpdatedEvent(); } int wxTextCtrl::GetLineLength(long lineNo) const -- 2.47.2