From: Francesco Montorsi Date: Sun, 21 Mar 2010 21:39:15 +0000 (+0000) Subject: reorder GetLabel(), GetLabelText(), SetLabel() and SetLabelText() function declaratio... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/32ee98eb765b9b574b8bc0da4396c1203f499d76 reorder GetLabel(), GetLabelText(), SetLabel() and SetLabelText() function declarations, implementations and relative documentations. Add wxStaticTextBase::GetLabelWithoutMarkup() and use it in the wxMSW implementation of wxStaticText::SetLabel() to close bug #11446; the function RemoveMarkup() which was previously used in fact could not check for presence/absence of wxST_MARKUP style since it's a static function. Add wxStaticTextBase::SetLabelText() functions for symmetry with wxControlBase::SetLabelText() Add test unit for both wxControl::*Label* and wxStaticText::*Label* functions. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63733 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/control.h b/include/wx/control.h index 8f1a1767c1..31ceeef421 100644 --- a/include/wx/control.h +++ b/include/wx/control.h @@ -71,6 +71,7 @@ public: // get the control alignment (left/right/centre, top/bottom/centre) int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; } + // set label with mnemonics virtual void SetLabel(const wxString& label) { m_labelOrig = label; @@ -80,21 +81,19 @@ public: wxWindow::SetLabel(label); } - virtual wxString GetLabel() const - { - // return the original string, as it was passed to SetLabel() - // (i.e. with wx-style mnemonics) - return m_labelOrig; - } - - // get just the text of the label, without mnemonic characters ('&') - wxString GetLabelText() const { return GetLabelText(GetLabel()); } + // return the original string, as it was passed to SetLabel() + // (i.e. with wx-style mnemonics) + virtual wxString GetLabel() const { return m_labelOrig; } - void SetLabelText(const wxString& text) + // set label text (mnemonics will be escaped) + virtual void SetLabelText(const wxString& text) { SetLabel(EscapeMnemonics(text)); } + // get just the text of the label, without mnemonic characters ('&') + virtual wxString GetLabelText() const { return GetLabelText(GetLabel()); } + // controls by default inherit the colours of their parents, if a // particular control class doesn't want to do it, it can override // ShouldInheritColours() to return false @@ -114,23 +113,29 @@ public: - // static utilities - // ---------------- - - // replaces parts of the (multiline) string with ellipsis if needed - static wxString Ellipsize(const wxString& label, const wxDC& dc, - wxEllipsizeMode mode, int maxWidth, - int flags = wxELLIPSIZE_FLAGS_DEFAULT); + // static utilities for mnemonics char (&) handling + // ------------------------------------------------ - // get the string without mnemonic characters ('&') + // returns the given string without mnemonic characters ('&') static wxString GetLabelText(const wxString& label); - // removes the mnemonics characters + // returns the given string without mnemonic characters ('&') + // this function is identic to GetLabelText() and is provided for clarity + // and for symmetry with the wxStaticText::RemoveMarkup() function. static wxString RemoveMnemonics(const wxString& str); // escapes (by doubling them) the mnemonics static wxString EscapeMnemonics(const wxString& str); + + // miscellaneous static utilities + // ------------------------------ + + // replaces parts of the given (multiline) string with an ellipsis if needed + static wxString Ellipsize(const wxString& label, const wxDC& dc, + wxEllipsizeMode mode, int maxWidth, + int flags = wxELLIPSIZE_FLAGS_DEFAULT); + // return the accel index in the string or -1 if none and puts the modified // string into second parameter if non NULL static int FindAccelIndex(const wxString& label, diff --git a/include/wx/stattext.h b/include/wx/stattext.h index f8d7ede736..f9e202ac1b 100644 --- a/include/wx/stattext.h +++ b/include/wx/stattext.h @@ -51,16 +51,24 @@ public: } // get the string without mnemonic characters ('&') and without markup - // (if wxST_MARKUP is being used) + // (if the wxST_MARKUP style is set) virtual wxString GetLabelText() const; - // public utilities (symmetric to those in wxControl about mnemonics): + // set label text (mnemonics and markup, if the wxST_MARKUP style is set, + // will be escaped) + virtual void SetLabelText(const wxString& text); + + + // static utilities for markup handling + // (symmetric to those in wxControl about mnemonics) + // ------------------------------------------------- // get the string without mnemonic characters ('&') and without markup + // (note that markup is always removed; this function is static and cannot + // check for wxST_MARKUP style presence/absence!) static wxString GetLabelText(const wxString& label); - // removes the markup accepted by wxStaticText when wxST_MARKUP is used, - // and then returns the cleaned string + // removes the markup recognized by wxStaticText and returns the cleaned string static wxString RemoveMarkup(const wxString& str); // escapes all special symbols (<>"'&) present in the given string @@ -72,7 +80,14 @@ protected: // functions required for wxST_ELLIPSIZE_* support // choose the default border for this window virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } - // just calls RemoveMarkup & Ellipsize on the original label. + // calls only RemoveMarkup() on the original label + // if the wxST_MARKUP style is set + // (but unlike GetLabelText won't remove mnemonics) + virtual wxString GetLabelWithoutMarkup() const; + + // just calls RemoveMarkup() & Ellipsize() on the original label + // if the wxST_MARKUP & wxST_ELLIPSIZE_* styles are set + // (but unlike GetLabelText won't remove mnemonics) virtual wxString GetEllipsizedLabelWithoutMarkup() const; // replaces parts of the string with ellipsis if needed diff --git a/interface/wx/control.h b/interface/wx/control.h index 5823f31262..eb5bdc7cd5 100644 --- a/interface/wx/control.h +++ b/interface/wx/control.h @@ -94,58 +94,68 @@ public: virtual void Command(wxCommandEvent& event); /** - Replaces parts of the @a label string with ellipsis, if needed, so - that it doesn't exceed @a maxWidth. - - Note that this functions is guaranteed to always returns a string - whose rendering on the given DC takes less than @a maxWidth pixels - in horizontal. - - @param label - The string to ellipsize - @param dc - The DC used to retrieve the character widths through the - wxDC::GetPartialTextExtents() function. - @param mode - The ellipsization mode. This is the setting which determines - which part of the string should be replaced by the ellipsis. - See ::wxEllipsizeMode enumeration values for more info. - @param maxWidth - The maximum width of the returned string in pixels. - This argument determines how much characters of the string need to - be removed (and replaced by ellipsis). - @param flags - One or more of the ::wxEllipsizeFlags enumeration values combined. - */ - static wxString Ellipsize(const wxString& label, const wxDC& dc, - wxEllipsizeMode mode, int maxWidth, - int flags = wxELLIPSIZE_FLAGS_DEFAULT); + Returns the control's label, as it was passed to SetLabel(). - /** - Returns the control's text. + Note that the returned string may contains mnemonics ("&" characters) if they were + passed to the SetLabel() function; use GetLabelText() if they are undesired. - @note The returned string contains mnemonics ("&" characters) if it has - any, use GetLabelText() if they are undesired. + Also note that the returned string is always the string which was passed to + SetLabel() but may be different from the string passed to SetLabelText() + (since this last one escapes mnemonic characters). */ wxString GetLabel() const; /** Returns the control's label without mnemonics. + + Note that because of the stripping of the mnemonics the returned string may differ + from the string which was passed to SetLabel(). */ wxString GetLabelText() const; + /** + Sets the control's label. + + All "&" characters in the @a label are special and indicate that the + following character is a @e mnemonic for this control and can be used to + activate it from the keyboard (typically by using @e Alt key in + combination with it). To insert a literal ampersand character, you need + to double it, i.e. use use "&&". If this behaviour is undesirable, use + SetLabelText() instead. + */ + void SetLabel(const wxString& label); + + /** + Sets the control's label to exactly the given string. + + Unlike SetLabel(), this function shows exactly the @a text passed to it + in the control, without interpreting ampersands in it in any way. + Notice that it means that the control can't have any mnemonic defined + for it using this function. + + @see EscapeMnemonics() + */ + void SetLabelText(const wxString& text); + + +public: // static functions + /** Returns the given @a label string without mnemonics ("&" characters). */ static wxString GetLabelText(const wxString& label); /** - Removes the mnemonics ("&" characters) from the given string. + Returns the given @a str string without mnemonics ("&" characters). + + @note This function is identic to GetLabelText() and is provided both for symmetry + with the wxStaticText::RemoveMarkup() function and to allow to write more + readable code (since this function has a more descriptive name respect GetLabelText()). */ static wxString RemoveMnemonics(const wxString& str); /** - Escape the special mnemonics characters ("&") in the given string. + Escapes the special mnemonics characters ("&") in the given string. This function can be helpful if you need to set the controls label to a user-provided string. If the string contains ampersands, they wouldn't @@ -167,27 +177,31 @@ public: static wxString EscapeMnemonics(const wxString& text); /** - Sets the item's text. + Replaces parts of the @a label string with ellipsis, if needed, so + that it doesn't exceed @a maxWidth. + + Note that this functions is guaranteed to always returns a string + whose rendering on the given DC takes less than @a maxWidth pixels + in horizontal. - Any "&" characters in the @a label are special and indicate that the - following character is a @e mnemonic for this control and can be used to - activate it from the keyboard (typically by using @e Alt key in - combination with it). To insert a literal ampersand character, you need - to double it, i.e. use use "&&". If this behaviour is undesirable, use - SetLabelText() instead. + @param label + The string to ellipsize + @param dc + The DC used to retrieve the character widths through the + wxDC::GetPartialTextExtents() function. + @param mode + The ellipsization mode. This is the setting which determines + which part of the string should be replaced by the ellipsis. + See ::wxEllipsizeMode enumeration values for more info. + @param maxWidth + The maximum width of the returned string in pixels. + This argument determines how much characters of the string need to + be removed (and replaced by ellipsis). + @param flags + One or more of the ::wxEllipsizeFlags enumeration values combined. */ - void SetLabel(const wxString& label); - - /** - Sets the item's text to exactly the given string. - - Unlike SetLabel(), this function shows exactly the @a text passed to it - in the control, without interpreting ampersands in it in any way. - Notice that it means that the control can't have any mnemonic defined - for it using this function. - - @see EscapeMnemonics() - */ - void SetLabelText(const wxString& text); + static wxString Ellipsize(const wxString& label, const wxDC& dc, + wxEllipsizeMode mode, int maxWidth, + int flags = wxELLIPSIZE_FLAGS_DEFAULT); }; diff --git a/interface/wx/stattext.h b/interface/wx/stattext.h index 4e297aabc5..412dde24ce 100644 --- a/interface/wx/stattext.h +++ b/interface/wx/stattext.h @@ -22,11 +22,11 @@ Center the text (horizontally). @style{wxST_NO_AUTORESIZE} By default, the control will adjust its size to exactly fit to the - size of the text when SetLabel is called. If this style flag is + size of the text when SetLabel() is called. If this style flag is given, the control will not change its size (this style is - especially useful with controls which also have wxALIGN_RIGHT or - CENTER style because otherwise they won't make sense any longer - after a call to SetLabel). + especially useful with controls which also have the @c wxALIGN_RIGHT or + the @c wxALIGN_CENTRE style because otherwise they won't make sense any + longer after a call to SetLabel()). @style{wxST_ELLIPSIZE_START} If the labeltext width exceeds the control width, replace the beginning of the label with an ellipsis; uses wxControl::Ellipsize. @@ -89,23 +89,12 @@ public: const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxStaticTextNameStr); - // NB: when writing docs for the following function remember that Doxygen - // will always expand HTML entities (e.g. ") and thus we need to - // write e.g. "&lt;" to have in the output the "<" string. - /** - Escapes all the symbols of @a str that have a special meaning (<>"'&) for - wxStaticText objects with the @c wxST_MARKUP style. - - Those symbols are replaced the corresponding entities - (&lt; &gt; &quot; &apos; &amp;). - */ - static wxString EscapeMarkup(const wxString& str); - /** Returns the contents of the control. - Note that the returned string contains both the mnemonics (@& characters), + Note that the returned string may contain both the mnemonics (@& characters), if any, and markup tags, if any. + Use GetLabelText() if only the label text is needed. */ wxString GetLabel() const; @@ -116,29 +105,19 @@ public: */ wxString GetLabelText() const; - /** - This overload returns the given @a label string without the - mnemonics characters (if any) and without the markup. - */ - static wxString GetLabelText(const wxString& label); - /** Returns @true if the window styles for this control contains one of the @c wxST_ELLIPSIZE_START, @c wxST_ELLIPSIZE_MIDDLE or @c wxST_ELLIPSIZE_END styles. */ bool IsEllipsized() const; - /** - Removes the markup accepted by wxStaticText when the @c wxST_MARKUP style is used, - and then returns the cleaned string. - - See SetLabel() for more info about the markup. - */ - static wxString RemoveMarkup(const wxString& str); + // NB: when writing docs for the following function remember that Doxygen + // will always expand HTML entities (e.g. ") and thus we need to + // write e.g. "&lt;" to have in the output the "<" string. /** Sets the static text label and updates the controls size to exactly fit the - label unless the control has wxST_NO_AUTORESIZE flag. + label unless the control has @c wxST_NO_AUTORESIZE flag. This function allows to set decorated static label text on platforms which support it (currently only GTK+ 2). For the other platforms, the markup is @@ -146,6 +125,10 @@ public: The supported tags are: + + + + @@ -231,6 +214,17 @@ public: It may contain newline characters and the markup tags described above. */ virtual void SetLabel(const wxString& label); + + /** + Sets the control's label to exactly the given string. + + Unlike SetLabel(), this function shows exactly the @a text passed to it + in the control, without interpreting ampersands in it in any way. + Notice that it means that the control can't have any mnemonic defined + for it using this function. + + */ + virtual void SetLabelText(const wxString& text); /** This functions wraps the controls label so that each of its lines becomes at @@ -244,5 +238,34 @@ public: @since 2.6.2 */ void Wrap(int width); + + +public: // static functions + + /** + Returns the given @a label string without the mnemonics characters (if any) + and without the markup. + + Note that since this function is static it will always remove markup + (since it cannot check @c wxST_MARKUP presence/absence!). + */ + static wxString GetLabelText(const wxString& label); + + /** + Escapes all the symbols of @a str that have a special meaning (<>"'&) for + wxStaticText objects with the @c wxST_MARKUP style. + + Those symbols are replaced the corresponding entities + (&lt; &gt; &quot; &apos; &amp;). + */ + static wxString EscapeMarkup(const wxString& str); + + /** + Removes the markup accepted by wxStaticText when the @c wxST_MARKUP style is used, + and then returns the cleaned string. + + See SetLabel() for more info about the markup. + */ + static wxString RemoveMarkup(const wxString& str); }; diff --git a/src/common/ctrlcmn.cpp b/src/common/ctrlcmn.cpp index 851237fe56..c21a631713 100644 --- a/src/common/ctrlcmn.cpp +++ b/src/common/ctrlcmn.cpp @@ -88,13 +88,6 @@ bool wxControlBase::CreateControl(wxWindowBase *parent, return true; } -/* static */ -wxString wxControlBase::GetLabelText(const wxString& label) -{ - // we don't want strip the TABs here, just the mnemonics - return wxStripMenuCodes(label, wxStrip_Mnemonics); -} - void wxControlBase::Command(wxCommandEvent& event) { (void)GetEventHandler()->ProcessEvent(event); @@ -154,9 +147,17 @@ void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event) #endif // wxUSE_RADIOBTN } +/* static */ +wxString wxControlBase::GetLabelText(const wxString& label) +{ + // we don't want strip the TABs here, just the mnemonics + return wxStripMenuCodes(label, wxStrip_Mnemonics); +} + /* static */ wxString wxControlBase::RemoveMnemonics(const wxString& str) { + // we don't want strip the TABs here, just the mnemonics return wxStripMenuCodes(str, wxStrip_Mnemonics); } diff --git a/src/common/stattextcmn.cpp b/src/common/stattextcmn.cpp index e9a22fd8f5..95ced81a86 100644 --- a/src/common/stattextcmn.cpp +++ b/src/common/stattextcmn.cpp @@ -154,15 +154,28 @@ wxString wxStaticTextBase::GetLabelText() const return RemoveMnemonics(ret); } -/*static*/ +void wxStaticTextBase::SetLabelText(const wxString& text) +{ + wxString str = text; + + if (HasFlag(wxST_MARKUP)) + str = EscapeMarkup(str); // escapes markup and the & characters (which are also mnemonics) + else + str = EscapeMnemonics(text); // escape only the mnemonics + SetLabel(str); +} + +/* static */ wxString wxStaticTextBase::GetLabelText(const wxString& label) { - // remove markup wxString ret = RemoveMarkup(label); + // always remove the markup (this function is static + // and cannot check for wxST_MARKUP presence/absence) + return RemoveMnemonics(ret); } -/*static*/ +/* static */ wxString wxStaticTextBase::RemoveMarkup(const wxString& text) { // strip out of "text" the markup for platforms which don't support it natively @@ -293,6 +306,17 @@ void wxStaticTextBase::UpdateLabel() DoSetLabel(newlabel); } +wxString wxStaticTextBase::GetLabelWithoutMarkup() const +{ + wxString ret(m_labelOrig); + + if (HasFlag(wxST_MARKUP)) + ret = RemoveMarkup(ret); + + // unlike GetLabelText() we don't remove the mnemonics here! + return ret; +} + wxString wxStaticTextBase::GetEllipsizedLabelWithoutMarkup() const { // this function should be used only by ports which do not support diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index a2862c2179..1309628465 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -214,13 +214,13 @@ void wxStaticText::SetLabel(const wxString& label) } #endif // SS_ENDELLIPSIS - // this call will save the label in m_labelOrig and set it into this window - // (through wxWindow::SetLabel) + // save the label in m_labelOrig with both the markup (if any) and + // the mnemonics characters (if any) m_labelOrig = label; #ifdef SS_ENDELLIPSIS if ( styleReal & SS_ENDELLIPSIS ) - DoSetLabel(RemoveMarkup(label)); + DoSetLabel(GetLabelWithoutMarkup()); else #endif // SS_ENDELLIPSIS DoSetLabel(GetEllipsizedLabelWithoutMarkup()); diff --git a/tests/Makefile.in b/tests/Makefile.in index 21d0ac5c2b..06d196338f 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -141,6 +141,7 @@ TEST_GUI_OBJECTS = \ test_gui_config.o \ test_gui_comboboxtest.o \ test_gui_headerctrltest.o \ + test_gui_label.o \ test_gui_listctrltest.o \ test_gui_textctrltest.o \ test_gui_textentrytest.o \ @@ -590,6 +591,9 @@ test_gui_comboboxtest.o: $(srcdir)/controls/comboboxtest.cpp $(TEST_GUI_ODEP) test_gui_headerctrltest.o: $(srcdir)/controls/headerctrltest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/headerctrltest.cpp +test_gui_label.o: $(srcdir)/controls/label.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/label.cpp + test_gui_listctrltest.o: $(srcdir)/controls/listctrltest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/listctrltest.cpp diff --git a/tests/controls/label.cpp b/tests/controls/label.cpp new file mode 100644 index 0000000000..d9d2eebdeb --- /dev/null +++ b/tests/controls/label.cpp @@ -0,0 +1,213 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/controls/label.cpp +// Purpose: wxControl and wxStaticText label tests +// Author: Francesco Montorsi +// Created: 2010-3-21 +// RCS-ID: $Id$ +// Copyright: (c) 2010 Francesco Montorsi +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/app.h" +#endif // WX_PRECOMP + +#include "wx/control.h" +#include "wx/stattext.h" +#include "wx/checkbox.h" + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class LabelTestCase : public CppUnit::TestCase +{ +public: + LabelTestCase() { } + + virtual void setUp(); + virtual void tearDown(); + +private: + CPPUNIT_TEST_SUITE( LabelTestCase ); + CPPUNIT_TEST( GetLabel ); + CPPUNIT_TEST( GetLabelText ); + CPPUNIT_TEST( Statics ); + CPPUNIT_TEST_SUITE_END(); + + void GetLabel(); + void GetLabelText(); + void Statics(); + + wxStaticText *m_st, *m_stWithMarkup; + + // we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox + wxCheckBox *m_cb; + + DECLARE_NO_COPY_CLASS(LabelTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( LabelTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LabelTestCase, "LabelTestCase" ); + +// ---------------------------------------------------------------------------- +// test initialization +// ---------------------------------------------------------------------------- + +#define ORIGINAL_LABEL "original label" + +void LabelTestCase::setUp() +{ + m_st = new wxStaticText(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL); + m_stWithMarkup = new wxStaticText(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL, + wxDefaultPosition, wxDefaultSize, wxST_MARKUP); + + m_cb = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL); + + CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_st->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_stWithMarkup->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_cb->GetLabel() ); +} + +void LabelTestCase::tearDown() +{ + wxDELETE(m_st); + wxDELETE(m_stWithMarkup); + wxDELETE(m_cb); +} + +// ---------------------------------------------------------------------------- +// the tests themselves +// ---------------------------------------------------------------------------- + +#define SET_LABEL(str) \ + m_st->SetLabel(str); \ + m_stWithMarkup->SetLabel(str); \ + m_cb->SetLabel(str); + +#define SET_LABEL_TEXT(str) \ + m_st->SetLabelText(str); \ + m_stWithMarkup->SetLabelText(str); \ + m_cb->SetLabelText(str); + +void LabelTestCase::GetLabel() +{ + const wxString testLabelArray[] = { + "label without mnemonics and markup", + "label with &mnemonic", + "label with somemarkup", + "label with somemarkup and &mnemonic", + }; + + // test calls to SetLabel() and then to GetLabel() + + for ( unsigned int s = 0; s < WXSIZEOF(testLabelArray); s++ ) + { + SET_LABEL(testLabelArray[s]); + + // GetLabel() should always return the string passed to SetLabel() + CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_stWithMarkup->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabel() ); + } + + + // test calls to SetLabelText() and then to GetLabel() + + const wxString& testLabel = "label without mnemonics and markup"; + SET_LABEL_TEXT(testLabel); + CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( testLabel, m_stWithMarkup->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabel() ); + + const wxString& testLabel2 = "label with &mnemonic"; + const wxString& testLabelText2 = "label with &&mnemonic"; + SET_LABEL_TEXT(testLabel2); + CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( "label with &mnemonic", m_stWithMarkup->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabel() ); + + const wxString& testLabel3 = "label with somemarkup"; + SET_LABEL_TEXT(testLabel3); + CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( "label with <span foreground='blue'>some</span> <b>markup</b>", m_stWithMarkup->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->GetLabel() ); + + const wxString& testLabel4 = "label with somemarkup and &mnemonic"; + const wxString& testLabelText4 = "label with somemarkup and &&mnemonic"; + SET_LABEL_TEXT(testLabel4); + CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic", m_stWithMarkup->GetLabel() ); + CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabel() ); +} + +void LabelTestCase::GetLabelText() +{ + // test calls to SetLabel() and then to GetLabelText() + + const wxString& testLabel = "label without mnemonics and markup"; + SET_LABEL(testLabel); + CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabel, m_stWithMarkup->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabelText() ); + + const wxString& testLabel2 = "label with &mnemonic"; + const wxString& testLabelText2 = "label with mnemonic"; + SET_LABEL(testLabel2); + CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabelText2, m_stWithMarkup->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabelText() ); + + const wxString& testLabel3 = "label with somemarkup"; + SET_LABEL(testLabel3); + CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( "label with some markup", m_stWithMarkup->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->GetLabelText() ); + + const wxString& testLabel4 = "label with somemarkup and &mnemonic"; + const wxString& testLabelText4 = "label with somemarkup and mnemonic"; + SET_LABEL(testLabel4); + CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( "label with some markup and mnemonic", m_stWithMarkup->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabelText() ); + + + const wxString testLabelArray[] = { + "label without mnemonics and markup", + "label with &mnemonic", + "label with somemarkup", + "label with somemarkup and &mnemonic", + }; + + // test calls to SetLabelText() and then to GetLabelText() + + for ( unsigned int s = 0; s < WXSIZEOF(testLabelArray); s++ ) + { + SET_LABEL_TEXT(testLabelArray[s]); + + // GetLabelText() should always return the string passed to SetLabelText() + CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_stWithMarkup->GetLabelText() ); + CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabelText() ); + } +} + +void LabelTestCase::Statics() +{ + CPPUNIT_ASSERT_EQUAL( "mnemonic", wxControl::RemoveMnemonics("&mnemonic") ); + CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&mnemonic") ); + CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&&mnemonic") ); + CPPUNIT_ASSERT_EQUAL( "", wxStaticText::RemoveMarkup("") ); +} diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 373f224538..241dc034fa 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -126,6 +126,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_config.obj \ $(OBJS)\test_gui_comboboxtest.obj \ $(OBJS)\test_gui_headerctrltest.obj \ + $(OBJS)\test_gui_label.obj \ $(OBJS)\test_gui_listctrltest.obj \ $(OBJS)\test_gui_textctrltest.obj \ $(OBJS)\test_gui_textentrytest.obj \ @@ -141,7 +142,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_garbage.obj \ $(OBJS)\test_gui_settings.obj \ $(OBJS)\test_gui_socket.obj \ - $(OBJS)\test_gui_boxsizer.obj \ + $(OBJS)\test_gui_boxsizer.obj \ $(OBJS)\test_gui_clientsize.obj \ $(OBJS)\test_gui_setsize.obj @@ -644,6 +645,9 @@ $(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp $(OBJS)\test_gui_headerctrltest.obj: .\controls\headerctrltest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\headerctrltest.cpp +$(OBJS)\test_gui_label.obj: .\controls\label.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\label.cpp + $(OBJS)\test_gui_listctrltest.obj: .\controls\listctrltest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\listctrltest.cpp @@ -689,9 +693,9 @@ $(OBJS)\test_gui_settings.obj: .\misc\settings.cpp $(OBJS)\test_gui_socket.obj: .\net\socket.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp -$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp - $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp - +$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp + $(OBJS)\test_gui_clientsize.obj: .\window\clientsize.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\window\clientsize.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 1595d84da8..1aeb186b29 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -120,6 +120,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_config.o \ $(OBJS)\test_gui_comboboxtest.o \ $(OBJS)\test_gui_headerctrltest.o \ + $(OBJS)\test_gui_label.o \ $(OBJS)\test_gui_listctrltest.o \ $(OBJS)\test_gui_textctrltest.o \ $(OBJS)\test_gui_textentrytest.o \ @@ -135,7 +136,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_garbage.o \ $(OBJS)\test_gui_settings.o \ $(OBJS)\test_gui_socket.o \ - $(OBJS)\test_gui_boxsizer.o \ + $(OBJS)\test_gui_boxsizer.o \ $(OBJS)\test_gui_clientsize.o \ $(OBJS)\test_gui_setsize.o @@ -626,6 +627,9 @@ $(OBJS)\test_gui_comboboxtest.o: ./controls/comboboxtest.cpp $(OBJS)\test_gui_headerctrltest.o: ./controls/headerctrltest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_label.o: ./controls/label.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_listctrltest.o: ./controls/listctrltest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< @@ -671,9 +675,9 @@ $(OBJS)\test_gui_settings.o: ./misc/settings.cpp $(OBJS)\test_gui_socket.o: ./net/socket.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< -$(OBJS)\test_gui_boxsizer.o: ./sizers/boxsizer.cpp - $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< - +$(OBJS)\test_gui_boxsizer.o: ./sizers/boxsizer.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_clientsize.o: ./window/clientsize.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 04e39ba393..6ca56cd97d 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -121,6 +121,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_config.obj \ $(OBJS)\test_gui_comboboxtest.obj \ $(OBJS)\test_gui_headerctrltest.obj \ + $(OBJS)\test_gui_label.obj \ $(OBJS)\test_gui_listctrltest.obj \ $(OBJS)\test_gui_textctrltest.obj \ $(OBJS)\test_gui_textentrytest.obj \ @@ -136,7 +137,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_garbage.obj \ $(OBJS)\test_gui_settings.obj \ $(OBJS)\test_gui_socket.obj \ - $(OBJS)\test_gui_boxsizer.obj \ + $(OBJS)\test_gui_boxsizer.obj \ $(OBJS)\test_gui_clientsize.obj \ $(OBJS)\test_gui_setsize.obj TEST_GUI_RESOURCES = \ @@ -770,6 +771,9 @@ $(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp $(OBJS)\test_gui_headerctrltest.obj: .\controls\headerctrltest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\headerctrltest.cpp +$(OBJS)\test_gui_label.obj: .\controls\label.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\label.cpp + $(OBJS)\test_gui_listctrltest.obj: .\controls\listctrltest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\listctrltest.cpp @@ -815,9 +819,9 @@ $(OBJS)\test_gui_settings.obj: .\misc\settings.cpp $(OBJS)\test_gui_socket.obj: .\net\socket.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp -$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp - $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp - +$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp + $(OBJS)\test_gui_clientsize.obj: .\window\clientsize.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\window\clientsize.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index f6da0821db..299502875f 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -364,6 +364,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_config.obj & $(OBJS)\test_gui_comboboxtest.obj & $(OBJS)\test_gui_headerctrltest.obj & + $(OBJS)\test_gui_label.obj & $(OBJS)\test_gui_listctrltest.obj & $(OBJS)\test_gui_textctrltest.obj & $(OBJS)\test_gui_textentrytest.obj & @@ -379,7 +380,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_garbage.obj & $(OBJS)\test_gui_settings.obj & $(OBJS)\test_gui_socket.obj & - $(OBJS)\test_gui_boxsizer.obj & + $(OBJS)\test_gui_boxsizer.obj & $(OBJS)\test_gui_clientsize.obj & $(OBJS)\test_gui_setsize.obj @@ -681,6 +682,9 @@ $(OBJS)\test_gui_comboboxtest.obj : .AUTODEPEND .\controls\comboboxtest.cpp $(OBJS)\test_gui_headerctrltest.obj : .AUTODEPEND .\controls\headerctrltest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< +$(OBJS)\test_gui_label.obj : .AUTODEPEND .\controls\label.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_listctrltest.obj : .AUTODEPEND .\controls\listctrltest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< @@ -726,9 +730,9 @@ $(OBJS)\test_gui_settings.obj : .AUTODEPEND .\misc\settings.cpp $(OBJS)\test_gui_socket.obj : .AUTODEPEND .\net\socket.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< -$(OBJS)\test_gui_boxsizer.obj : .AUTODEPEND .\sizers\boxsizer.cpp - $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< - +$(OBJS)\test_gui_boxsizer.obj : .AUTODEPEND .\sizers\boxsizer.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_clientsize.obj : .AUTODEPEND .\window\clientsize.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< diff --git a/tests/test.bkl b/tests/test.bkl index edb0c7ea8f..4b85193a27 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -122,6 +122,7 @@ config/config.cpp controls/comboboxtest.cpp controls/headerctrltest.cpp + controls/label.cpp controls/listctrltest.cpp controls/textctrltest.cpp controls/textentrytest.cpp diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index bb0d682928..afb37c5331 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -235,10 +235,10 @@ LINK32=link.exe # PROP Default_Filter "" # Begin Source File -SOURCE=.\sizers\boxsizer.cpp -# End Source File -# Begin Source File - +SOURCE=.\sizers\boxsizer.cpp +# End Source File +# Begin Source File + SOURCE=.\window\clientsize.cpp # End Source File # Begin Source File @@ -293,6 +293,10 @@ SOURCE=.\image\image.cpp # End Source File # Begin Source File +SOURCE=.\controls\label.cpp +# End Source File +# Begin Source File + SOURCE=.\controls\listctrltest.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index ae44f24eac..dd00cfe5de 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -566,9 +566,9 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> - - + + + + diff --git a/tests/test_vc8_test_gui.vcproj b/tests/test_vc8_test_gui.vcproj index 54314be5b8..7ce61f53c7 100644 --- a/tests/test_vc8_test_gui.vcproj +++ b/tests/test_vc8_test_gui.vcproj @@ -828,10 +828,10 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > - - + + @@ -947,6 +947,10 @@ RelativePath=".\image\image.cpp" > + + diff --git a/tests/test_vc9_test_gui.vcproj b/tests/test_vc9_test_gui.vcproj index 761934ff67..fd6952f626 100644 --- a/tests/test_vc9_test_gui.vcproj +++ b/tests/test_vc9_test_gui.vcproj @@ -1,10 +1,16 @@ + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
TagDescription
<b> bold text