From: Vadim Zeitlin Date: Sun, 21 Aug 2011 12:06:16 +0000 (+0000) Subject: Replace wxComboBox::IsEmpty() with Is{List,Text}Empty(). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/36a96421b31530604c9dcccc0ba2a2861359f462 Replace wxComboBox::IsEmpty() with Is{List,Text}Empty(). IsEmpty() didn't exist in all ports (notably not wxMSW) and its meaning was unclear anyhow, so remove it even from the ports where it did exist and add clear Is{List,Text}Empty() replacements instead. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68808 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 2b53227ba1..c25a86af53 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -333,6 +333,9 @@ Changes in behaviour which may result in compilation errors - wxST_MARKUP doesn't exist any more, use wxControl::SetLabelMarkup() instead. +- wxComboBox::IsEmpty(), which was previously available in some ports (but not + wxMSW), doesn't exist any more, use either IsListEmpty() or IsTextEmpty(). + Deprecated methods and their replacements ----------------------------------------- @@ -453,6 +456,7 @@ All (GUI): - Allow marking wxTreeBook nodes to expand initially in XRC (RedTide). - Added customizable wxDocManager::OnMRUFileNotExist() virtual method. - Fix stock labels when not using mnemonics for Chinese (cw.ahbong). +- Added wxComboBox::IsListEmpty() and IsTextEmpty(). OSX: diff --git a/include/wx/combobox.h b/include/wx/combobox.h index a0245f9e23..831bed1c24 100644 --- a/include/wx/combobox.h +++ b/include/wx/combobox.h @@ -36,7 +36,13 @@ public: wxItemContainer::Clear(); } - bool IsEmpty() const { return wxItemContainer::IsEmpty(); } + // IsEmpty() is ambiguous because we inherit it from both wxItemContainer + // and wxTextEntry, and even if defined it here to help the compiler with + // choosing one of them, it would still be confusing for the human users of + // this class. So instead define the clearly named methods below and leave + // IsEmpty() ambiguous to trigger a compilation error if it's used. + bool IsListEmpty() const { return wxItemContainer::IsEmpty(); } + bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); } // also bring in GetSelection() versions of both base classes in scope // diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index fb718013c5..02ae7e481a 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -97,7 +97,9 @@ public: wxItemContainer::Clear(); } - bool IsEmpty() const { return wxItemContainer::IsEmpty(); } + // See wxComboBoxBase discussion of IsEmpty(). + bool IsListEmpty() const { return wxItemContainer::IsEmpty(); } + bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); } void OnChar( wxKeyEvent &event ); diff --git a/include/wx/motif/combobox.h b/include/wx/motif/combobox.h index e7e3598ed6..94ca4efb1c 100644 --- a/include/wx/motif/combobox.h +++ b/include/wx/motif/combobox.h @@ -69,6 +69,10 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxComboBoxNameStr); + // See wxComboBoxBase discussion of IsEmpty(). + bool IsListEmpty() const { return wxItemContainer::IsEmpty(); } + bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); } + // resolve ambiguities among virtual functions inherited from both base // classes virtual void Clear(); diff --git a/include/wx/msw/combobox.h b/include/wx/msw/combobox.h index f656e081e8..4f4a99458b 100644 --- a/include/wx/msw/combobox.h +++ b/include/wx/msw/combobox.h @@ -75,6 +75,10 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxComboBoxNameStr); + // See wxComboBoxBase discussion of IsEmpty(). + bool IsListEmpty() const { return wxItemContainer::IsEmpty(); } + bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); } + // resolve ambiguities among virtual functions inherited from both base // classes virtual void Clear(); diff --git a/include/wx/os2/combobox.h b/include/wx/os2/combobox.h index 92039b8a37..233d0f0d02 100644 --- a/include/wx/os2/combobox.h +++ b/include/wx/os2/combobox.h @@ -96,6 +96,10 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxChoice, ,const wxString& rsName = wxComboBoxNameStr ); + // See wxComboBoxBase discussion of IsEmpty(). + bool IsListEmpty() const { return wxItemContainer::IsEmpty(); } + bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); } + // resolve ambiguities among virtual functions inherited from both base // classes virtual void Clear(); diff --git a/include/wx/univ/combobox.h b/include/wx/univ/combobox.h index 04343ac4fe..ac63fd63c3 100644 --- a/include/wx/univ/combobox.h +++ b/include/wx/univ/combobox.h @@ -129,7 +129,9 @@ public: wxItemContainer::Clear(); } - bool IsEmpty() const { return wxItemContainer::IsEmpty(); } + // See wxComboBoxBase discussion of IsEmpty(). + bool IsListEmpty() const { return wxItemContainer::IsEmpty(); } + bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); } // wxControlWithItems methods virtual void DoClear(); diff --git a/interface/wx/combobox.h b/interface/wx/combobox.h index 602916cccf..e77f8a8fd2 100644 --- a/interface/wx/combobox.h +++ b/interface/wx/combobox.h @@ -224,6 +224,39 @@ public: */ virtual long GetInsertionPoint() const; + /** + IsEmpty() is not available in this class. + + This method is documented here only to notice that it can't be used + with this class because of the ambiguity between the methods with the + same name inherited from wxItemContainer and wxTextEntry base classes. + + Because of this, any attempt to call it results in a compilation error + and you should use either IsListEmpty() or IsTextEmpty() depending on + what exactly do you want to test. + */ + bool IsEmpty() const; + + /** + Returns true if the list of combobox choices is empty. + + Use this method instead of (not available in this class) IsEmpty() to + test if the list of items is empty. + + @since 2.9.3 + */ + bool IsListEmpty() const; + + /** + Returns true if the text of the combobox is empty. + + Use this method instead of (not available in this class) IsEmpty() to + test if the text currently entered into the combobox is empty. + + @since 2.9.3 + */ + bool IsTextEmpty() const; + /** Same as wxTextEntry::SetSelection(). diff --git a/tests/Makefile.in b/tests/Makefile.in index 396d64ab28..8df2f3c8e9 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -922,7 +922,17 @@ test_gui_xrctest.o: $(srcdir)/xml/xrctest.cpp $(TEST_GUI_ODEP) # warnings don't matter when we expect compilation to fail anyhow so we can # use this variable to enable the compilation of code which is supposed to # fail -failtest: +failtest: failtest_combobox failtest_evthandler + +failtest_combobox: + @$(RM) test_gui_comboboxtest.o + if $(MAKE) CXXWARNINGS=-DTEST_INVALID_COMBOBOX_ISEMPTY test_gui_comboboxtest.o 2>/dev/null; then \ + echo "*** Compilation with TEST_INVALID_COMBOBOX_ISEMPTY unexpectedly succeeded.">&2; \ + exit 1; \ + fi; \ + exit 0 + +failtest_evthandler: @$(RM) test_evthandler.o @for d in GLOBAL STATIC METHOD FUNCTOR NO_HANDLER DERIVED WRONG_CLASS; do \ if $(MAKE) CXXWARNINGS=-DTEST_INVALID_BIND_$$d test_evthandler.o 2>/dev/null; then \ diff --git a/tests/controls/comboboxtest.cpp b/tests/controls/comboboxtest.cpp index 3086578c7f..a624d62d60 100644 --- a/tests/controls/comboboxtest.cpp +++ b/tests/controls/comboboxtest.cpp @@ -62,12 +62,14 @@ private: CPPUNIT_TEST( PopDismiss ); CPPUNIT_TEST( Sort ); CPPUNIT_TEST( ReadOnly ); + CPPUNIT_TEST( IsEmpty ); CPPUNIT_TEST_SUITE_END(); void Size(); void PopDismiss(); void Sort(); void ReadOnly(); + void IsEmpty(); wxComboBox *m_combo; @@ -194,4 +196,27 @@ void ComboBoxTestCase::ReadOnly() #endif } +void ComboBoxTestCase::IsEmpty() +{ + CPPUNIT_ASSERT( m_combo->IsListEmpty() ); + CPPUNIT_ASSERT( m_combo->IsTextEmpty() ); + + m_combo->Append("foo"); + CPPUNIT_ASSERT( !m_combo->IsListEmpty() ); + CPPUNIT_ASSERT( m_combo->IsTextEmpty() ); + + m_combo->SetValue("bar"); + CPPUNIT_ASSERT( !m_combo->IsListEmpty() ); + CPPUNIT_ASSERT( !m_combo->IsTextEmpty() ); + + m_combo->Clear(); + CPPUNIT_ASSERT( m_combo->IsListEmpty() ); + CPPUNIT_ASSERT( m_combo->IsTextEmpty() ); + +#ifdef TEST_INVALID_COMBOBOX_ISEMPTY + // Compiling this should fail, see failtest target definition in test.bkl. + m_combo->IsEmpty(); +#endif +} + #endif //wxUSE_COMBOBOX diff --git a/tests/test.bkl b/tests/test.bkl index ba5bf00ae7..d650f8d470 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -253,7 +253,17 @@ # warnings don't matter when we expect compilation to fail anyhow so we can # use this variable to enable the compilation of code which is supposed to # fail -failtest: +failtest: failtest_combobox failtest_evthandler + +failtest_combobox: + @$(RM) test_gui_comboboxtest.o + if $(MAKE) CXXWARNINGS=-DTEST_INVALID_COMBOBOX_ISEMPTY test_gui_comboboxtest.o 2>/dev/null; then \ + echo "*** Compilation with TEST_INVALID_COMBOBOX_ISEMPTY unexpectedly succeeded.">&2; \ + exit 1; \ + fi; \ + exit 0 + +failtest_evthandler: @$(RM) test_evthandler.o @for d in GLOBAL STATIC METHOD FUNCTOR NO_HANDLER DERIVED WRONG_CLASS; do \ if $(MAKE) CXXWARNINGS=-DTEST_INVALID_BIND_$$d test_evthandler.o 2>/dev/null; then \