From 28fdd8db44bc6070c71a77af783fb4da0b554d8c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Oct 2006 17:52:39 +0000 Subject: [PATCH] added wxTextCtrl::IsEmpty() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41740 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/gtk/textctrl.h | 4 ++-- include/wx/msw/textctrl.h | 3 ++- include/wx/textctrl.h | 2 ++ src/gtk/textctrl.cpp | 8 ++++++++ src/msw/textctrl.cpp | 9 +++++++++ 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 856405f603..8637c9deee 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -69,6 +69,7 @@ All (GUI): - Added wxAboutBox() function for displaying the standard about dialog - Added wxID_PAGE_SETUP standard id. - Added wxSize::IncBy() and DecBy() methods. +- Added wxTextCtrl::IsEmpty() - Added file type parameter to wxTextCtrl::LoadFile, wxTextCtrl::SaveFile for consistency with wxRichTextCtrl. - wxRichTextCtrl: fixed range out-by-one bug to be consistent with wxTextCtrl API, diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 8cde769c6b..017116609f 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -43,9 +43,9 @@ 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 void ChangeValue(const wxString& value) { DoSetValue(value); } virtual int GetLineLength(long lineNo) const; virtual wxString GetLineText(long lineNo) const; diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index dee8fd0bbe..8649f1491e 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -45,8 +45,9 @@ 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 void ChangeValue(const wxString& value) { DoSetValue(value); } virtual wxString GetRange(long from, long to) const; diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 172301b6ad..39908a03bf 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -300,6 +300,8 @@ 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 wxString GetRange(long from, long to) const; diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index f10fd64e01..cf14bf7797 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -821,6 +821,14 @@ wxFontEncoding wxTextCtrl::GetTextEncoding() const return enc; } +bool wxTextCtrl::IsEmpty() const +{ + if ( IsMultiLine() ) + return gtk_text_buffer_get_char_count(m_buffer) != 0; + + return wxTextCtrlBase::IsEmpty(); +} + void wxTextCtrl::DoSetValue( const wxString &value, int flags ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index a71654a1ec..53ec9740c7 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -662,6 +662,15 @@ void wxTextCtrl::SetWindowStyleFlag(long style) // set/get the controls text // ---------------------------------------------------------------------------- +bool wxTextCtrl::IsEmpty() const +{ + // this is an optimization for multiline controls containing a lot of text + if ( IsMultiLine() && GetNumberOfLines() != 1 ) + return false; + + return wxTextCtrlBase::IsEmpty(); +} + wxString wxTextCtrl::GetValue() const { // range 0..-1 is special for GetRange() and means to retrieve all text -- 2.45.2