just "%" wxLongLongFmtSpec "x", i.e. simply remove wxT() from the strings you
concatenate with it.
+- wxST_MARKUP doesn't exist any more, use wxControl::SetLabelMarkup() instead.
+
Deprecated methods and their replacements
-----------------------------------------
// get just the text of the label, without mnemonic characters ('&')
virtual wxString GetLabelText() const { return GetLabelText(GetLabel()); }
+
+ // Set the label with markup (and mnemonics). Markup is a simple subset of
+ // HTML with tags such as <b>, <i> and <span>. By default it is not
+ // supported i.e. all the markup is simply stripped and SetLabel() is
+ // called but some controls in some ports do support this already and in
+ // the future most of them should.
+ //
+ // Notice that, being HTML-like, markup also supports XML entities so '<'
+ // should be encoded as "<" and so on, a bare '<' in the input will
+ // likely result in an error. As an exception, a bare '&' is allowed and
+ // indicates that the next character is a mnemonic. To insert a literal '&'
+ // in the control you need to use "&" in the input string.
+ //
+ // Returns true if the label was set, even if the markup in it was ignored.
+ // False is only returned if we failed to parse the label.
+ bool SetLabelMarkup(const wxString& markup)
+ {
+ return DoSetLabelMarkup(markup);
+ }
+
+
// 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
const wxValidator& validator,
const wxString& name);
+ // This function may be overridden in the derived classes to implement
+ // support for labels with markup. The base class version simply strips the
+ // markup and calls SetLabel() with the remaining text.
+ virtual bool DoSetLabelMarkup(const wxString& markup);
+
+
// initialize the common fields of wxCommandEvent
void InitCommandEvent(wxCommandEvent& event) const;
wxEllipsizeMode mode, int maxWidth,
int replacementWidth);
+ // Remove markup from the given string, returns empty string on error i.e.
+ // if markup was syntactically invalid.
+ static wxString RemoveMarkup(const wxString& markup);
+
+
// this field contains the label in wx format, i.e. with '&' mnemonics,
// as it was passed to the last SetLabel() call
wxString m_labelOrig;
virtual wxString DoGetLabel() const;
virtual void DoSetLabel(const wxString& str);
+ virtual bool DoSetLabelMarkup(const wxString& markup);
+
+private:
+ // Common part of SetLabel() and DoSetLabelMarkup().
+ typedef void (wxStaticText::*GTKLabelSetter)(GtkLabel *, const wxString&);
+
+ void GTKDoSetLabel(GTKLabelSetter setter, const wxString& label);
+
DECLARE_DYNAMIC_CLASS(wxStaticText)
};
* wxStaticText flags
*/
#define wxST_NO_AUTORESIZE 0x0001
-#define wxST_MARKUP 0x0002
+// free 0x0002 bit
#define wxST_ELLIPSIZE_START 0x0004
#define wxST_ELLIPSIZE_MIDDLE 0x0008
#define wxST_ELLIPSIZE_END 0x0010
HasFlag(wxST_ELLIPSIZE_END);
}
- // get the string without mnemonic characters ('&') and without markup
- // (if the wxST_MARKUP style is set)
- virtual wxString GetLabelText() const;
-
- // 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 recognized by wxStaticText and returns the cleaned string
- static wxString RemoveMarkup(const wxString& str);
-
- // escapes all special symbols (<>"'&) present in the given string
- // using the corresponding entities (< > " ' &)
- static wxString EscapeMarkup(const wxString& str);
-
protected: // functions required for wxST_ELLIPSIZE_* support
// choose the default border for this window
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
- // 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;
+ // Calls Ellipsize() on the real label if necessary. Unlike GetLabelText(),
+ // keeps the mnemonics instead of removing them.
+ virtual wxString GetEllipsizedLabel() const;
- // replaces parts of the string with ellipsis if needed
+ // Replaces parts of the string with ellipsis according to the ellipsize
+ // style. Shouldn't be called if we don't have any.
wxString Ellipsize(const wxString& label) const;
// to be called when updating the size of the static text:
*/
void SetLabelText(const wxString& text);
+ // 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 controls label to a string using markup.
+
+ Simple markup supported by this function can be used to apply different
+ fonts or colours to different parts of the control label when supported
+ (currently only wxStaticText under GTK+ 2). If markup is not supported
+ by the control or platform, it is simply stripped and SetLabel() is
+ used with the resulting string.
+
+ For example,
+ @code
+ wxStaticText *text;
+ ...
+ text->SetLabelMarkup("<b>&Bed</b> &mp; "
+ "<span foreground='red'>breakfast</span> "
+ "available <big>HERE</big>");
+ @endcode
+ would show the string using bold, red and big for the corresponding
+ words under wxGTK but will simply show the string "Bed & breakfast
+ available HERE" on the other platforms. In any case, the "B" of "Bed"
+ will be underlined to indicate that it can be used as a mnemonic for
+ this control.
+
+ The supported tags are:
+ <TABLE>
+ <TR>
+ <TD><b>Tag</b></TD>
+ <TD><b>Description</b></TD>
+ </TR>
+ <TR>
+ <TD><b></TD>
+ <TD>bold text</TD>
+ </TR>
+ <TR>
+ <TD><big></TD>
+ <TD>bigger text</TD>
+ </TR>
+ <TR>
+ <TD><i></TD>
+ <TD>italic text</TD>
+ </TR>
+ <TR>
+ <TD><s></TD>
+ <TD>strike-through text</TD>
+ </TR>
+ <TR>
+ <TD><small></TD>
+ <TD>smaller text</TD>
+ </TR>
+ <TR>
+ <TD><tt></TD>
+ <TD>monospaced text</TD>
+ </TR>
+ <TR>
+ <TD><u></TD>
+ <TD>underlined text</TD>
+ </TR>
+ <TR>
+ <TD><span></TD>
+ <TD>generic formatter tag, see the table below for supported
+ attributes.
+ </TD>
+ </TR>
+ </TABLE>
+
+ Supported @c <span> attributes:
+ <TABLE>
+ <TR>
+ <TD><b>Name</b></TD>
+ <TD><b>Description</b></TD>
+ </TR>
+ <TR>
+ <TD>foreground, fgcolor, color</TD>
+ <TD>Foreground text colour, can be a name or RGB value.</TD>
+ </TR>
+ <TR>
+ <TD>background, bgcolor</TD>
+ <TD>Background text colour, can be a name or RGB value.</TD>
+ </TR>
+ <TR>
+ <TD>font_family, face</TD>
+ <TD>Font face name.</TD>
+ </TR>
+ <TR>
+ <TD>font_weight, weight</TD>
+ <TD>Numeric value in 0..900 range or one of "ultralight",
+ "light", "normal" (all meaning non-bold), "bold", "ultrabold"
+ and "heavy" (all meaning bold).</TD>
+ </TR>
+ <TR>
+ <TD>font_style, style</TD>
+ <TD>Either "oblique" or "italic" (both with the same meaning)
+ or "normal".</TD>
+ </TR>
+ <TR>
+ <TD>size</TD>
+ <TD>The font size can be specified either as "smaller" or
+ "larger" relatively to the current font, as a CSS font size
+ name ("xx-small", "x-small", "small", "medium", "large",
+ "x-large" or "xx-large") or as a number giving font size in
+ 1024th parts of a point, i.e. 10240 for a 10pt font.</TD>
+ </TR>
+ </TABLE>
+
+ This markup language is a strict subset of Pango markup (described at
+ http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html)
+ and any tags and span attributes not documented above can't be used
+ under non-GTK platforms.
+
+ Also note that you need to escape the following special characters:
+ <TABLE>
+ <TR>
+ <TD><b>Special character</b></TD>
+ <TD><b>Escape as</b></TD>
+ </TR>
+ <TR>
+ <TD>@c &</TD>
+ <TD>@c &amp; or as @c &&</TD>
+ </TR>
+ <TR>
+ <TD>@c '</TD>
+ <TD>@c &apos;</TD>
+ </TR>
+ <TR>
+ <TD>@c "</TD>
+ <TD>@c &quot;</TD>
+ </TR>
+ <TR>
+ <TD>@c <</TD>
+ <TD>@c &lt;</TD>
+ </TR>
+ <TR>
+ <TD>@c ></TD>
+ <TD>@c &gt;</TD>
+ </TR>
+ </TABLE>
+
+ The non-escaped ampersand @c & characters are interpreted as
+ mnemonics as with wxControl::SetLabel.
+
+
+ @param markup
+ String containing markup for the label. It may contain newline
+ characters and the markup tags described above.
+ @return
+ @true if the new label was set (even if markup in it was ignored)
+ or @false if we failed to parse the markup. In this case the label
+ remains unchanged.
+
+ Note that the string must be well-formed (e.g. all tags must be correctly
+ closed) and won't be shown at all otherwise.
+
+ @since 2.9.2
+ */
+ bool SetLabelMarkup(const wxString& markup);
+
public: // static functions
/**
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()).
+ @note This function is identical to GetLabelText() and is provided
+ mostly for symmetry with EscapeMnemonics().
*/
static wxString RemoveMnemonics(const wxString& str);
@class wxStaticText
A static text control displays one or more lines of read-only text.
- wxStaticText supports the three classic text alignments, label ellipsization
- and formatting markup.
+ wxStaticText supports the three classic text alignments, label
+ ellipsization i.e. replacing parts of the text with the ellipsis ("...") if
+ the label doesn't fit into the provided space and also formatting markup
+ with wxControl::SetLabelMarkup().
@beginStyleTable
@style{wxALIGN_LEFT}
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 the @c wxALIGN_RIGHT or
- the @c wxALIGN_CENTRE style because otherwise they won't make sense any
+ 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
@style{wxST_ELLIPSIZE_END}
If the label text width exceeds the control width, replace the end
of the label with an ellipsis; uses wxControl::Ellipsize.
- @style{wxST_MARKUP}
- Support markup in the label; see SetLabel() for more information.
@endStyleTable
@library{wxcore}
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = wxStaticTextNameStr);
- /**
- Returns the contents of the control.
-
- Note that the returned string may contain both mnemonics (@& characters),
- and markup tags, if they were passed to the SetLabel() function.
-
- Use GetLabelText() if only the label text, without mnemonics and without
- markup if the @c wxST_MARKUP style is set, is needed.
-
- 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 and eventually markup).
- */
- wxString GetLabel() const;
-
- /**
- This method returns the control's label without the mnemonics characters
- (if any) and without the markup (if the control has the @c wxST_MARKUP style).
-
- Note that because of the stripping of the mnemonics and markup the returned
- string may differ from the string which was passed to SetLabel() but should
- always be the same which was passed to SetLabelText().
- */
- wxString GetLabelText() const;
-
/**
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;
- // 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 @c wxST_NO_AUTORESIZE flag.
-
- This function allows to set decorated static label text, when the @c wxST_MARKUP
- style is used, on those platforms which support it (currently only GTK+ 2).
- For the other platforms or when @c wxST_MARKUP is not used, the markup is ignored.
-
- The supported tags are:
- <TABLE>
- <TR>
- <TD><b>Tag</b></TD>
- <TD><b>Description</b></TD>
- </TR>
- <TR>
- <TD><b></TD>
- <TD>bold text</TD>
- </TR>
- <TR>
- <TD><big></TD>
- <TD>bigger text</TD>
- </TR>
- <TR>
- <TD><i></TD>
- <TD>italic text</TD>
- </TR>
- <TR>
- <TD><s></TD>
- <TD>strike-through text</TD>
- </TR>
- <TR>
- <TD><sub></TD>
- <TD>subscript text</TD>
- </TR>
- <TR>
- <TD><sup></TD>
- <TD>superscript text</TD>
- </TR>
- <TR>
- <TD><small></TD>
- <TD>smaller text</TD>
- </TR>
- <TR>
- <TD><tt></TD>
- <TD>monospaced text</TD>
- </TR>
- <TR>
- <TD><u></TD>
- <TD>underlined text</TD>
- </TR>
- <TR>
- <TD><span></TD>
- <TD>generic formatter tag; see Pango Markup
- (http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html)
- for more information.</TD>
- </TR>
- </TABLE>
-
- Note that the string must be well-formed (e.g. all tags must be correctly
- closed) otherwise it can be not shown correctly or at all.
- Also note that you need to escape the following special characters:
-
- <TABLE>
- <TR>
- <TD><b>Special character</b></TD>
- <TD><b>Escape as</b></TD>
- </TR>
- <TR>
- <TD>@c &</TD>
- <TD>@c &amp; or as @c &&</TD>
- </TR>
- <TR>
- <TD>@c '</TD>
- <TD>@c &apos;</TD>
- </TR>
- <TR>
- <TD>@c "</TD>
- <TD>@c &quot;</TD>
- </TR>
- <TR>
- <TD>@c <</TD>
- <TD>@c &lt;</TD>
- </TR>
- <TR>
- <TD>@c ></TD>
- <TD>@c &gt;</TD>
- </TR>
- </TABLE>
-
- The non-escaped ampersand @c & characters are interpreted as
- mnemonics; see wxControl::SetLabel.
-
- Example:
-
- @param label
- The new label to set.
- 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 and,
- if @c wxST_MARKUP is used, without interpreting markup tags.
- Notice that it means that the control can't have any mnemonic nor markup defined
- for it using this function.
-
- @see EscapeMarkup()
- */
- virtual void SetLabelText(const wxString& text);
-
/**
This functions wraps the controls label so that each of its lines becomes at
most @a width pixels wide if possible (the lines are broken at words
@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 (<tt><>"'&</tt>) 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);
};
m_chkGeneric = CreateCheckBoxAndAddToSizer(sizerLeft,
"&Generic wxStaticText");
- m_chkMarkup = CreateCheckBoxAndAddToSizer(sizerLeft, "Support &markup");
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, "&Vertical line");
m_chkAutoResize = CreateCheckBoxAndAddToSizer(sizerLeft, "&Fit to text");
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
m_chkVert->SetValue(false);
m_chkAutoResize->SetValue(true);
m_chkEllipsize->SetValue(true);
- m_chkMarkup->SetValue(true);
m_radioHAlign->SetSelection(StaticHAlign_Left);
m_radioVAlign->SetSelection(StaticVAlign_Top);
flagsDummyText |= wxST_NO_AUTORESIZE;
}
- if ( m_chkMarkup->GetValue() )
- {
- flagsText |= wxST_MARKUP;
- flagsDummyText |= wxST_MARKUP;
- }
-
int align = 0;
switch ( m_radioHAlign->GetSelection() )
{
wxDefaultPosition, wxDefaultSize,
flagsDummyText);
m_statMarkup = new wxGenericStaticText(this, wxID_ANY,
- m_textLabelWithMarkup->GetValue(),
+ wxString(),
wxDefaultPosition, wxDefaultSize,
flagsText);
}
wxDefaultPosition, wxDefaultSize,
flagsDummyText);
m_statMarkup = new wxStaticText(this, wxID_ANY,
- m_textLabelWithMarkup->GetValue(),
+ wxString(),
wxDefaultPosition, wxDefaultSize,
flagsText);
}
+
+ m_statMarkup->SetLabelMarkup(m_textLabelWithMarkup->GetValue());
+
if ( m_chkGreen->GetValue() )
m_statMarkup->SetBackgroundColour(*wxGREEN);
#if wxUSE_STATLINE
void StaticWidgetsPage::OnButtonLabelWithMarkupText(wxCommandEvent& WXUNUSED(event))
{
- m_statMarkup->SetLabel(m_textLabelWithMarkup->GetValue());
+ m_statMarkup->SetLabelMarkup(m_textLabelWithMarkup->GetValue());
// test GetLabel() and GetLabelText(); the first should return the
// label as it is written in the relative text control; the second should
#include "wx/settings.h"
#endif
+#include "wx/private/markupparser.h"
+
const char wxControlNameStr[] = "control";
// ============================================================================
return attrs;
}
+// ----------------------------------------------------------------------------
+// wxControl markup support
+// ----------------------------------------------------------------------------
+
+/* static */
+wxString wxControlBase::RemoveMarkup(const wxString& markup)
+{
+ return wxMarkupParser::Strip(markup);
+}
+
+bool wxControlBase::DoSetLabelMarkup(const wxString& markup)
+{
+ const wxString label = RemoveMarkup(markup);
+ if ( label.empty() && !markup.empty() )
+ return false;
+
+ SetLabel(label);
+
+ return true;
+}
+
// ----------------------------------------------------------------------------
// wxControlBase - ellipsization code
// ----------------------------------------------------------------------------
wrapper.WrapLabel(this, width);
}
-wxString wxStaticTextBase::GetLabelText() const
-{
- wxString ret(GetLabel());
-
- if (HasFlag(wxST_MARKUP))
- ret = RemoveMarkup(ret);
- return RemoveMnemonics(ret);
-}
-
-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)
-{
- wxString ret = RemoveMarkup(label);
- // always remove the markup (this function is static
- // and cannot check for wxST_MARKUP presence/absence)
-
- return RemoveMnemonics(ret);
-}
-
-/* static */
-wxString wxStaticTextBase::RemoveMarkup(const wxString& text)
-{
- return wxMarkupParser::Strip(text);
-}
-
-/* static */
-wxString wxStaticTextBase::EscapeMarkup(const wxString& text)
-{
- return wxMarkupParser::Quote(text);
-}
-
-
// ----------------------------------------------------------------------------
// wxStaticTextBase - generic implementation for wxST_ELLIPSIZE_* support
// ----------------------------------------------------------------------------
if (!IsEllipsized())
return;
- wxString newlabel = GetEllipsizedLabelWithoutMarkup();
+ wxString newlabel = GetEllipsizedLabel();
// we need to touch the "real" label (i.e. the text set inside the control,
// using port-specific functions) instead of the string returned by GetLabel().
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
+wxString wxStaticTextBase::GetEllipsizedLabel() const
{
// this function should be used only by ports which do not support
// ellipsis in static texts: we first remove markup (which cannot
wxString ret(m_labelOrig);
- // the order of the following two blocks is important!
-
- if (HasFlag(wxST_MARKUP))
- ret = RemoveMarkup(ret);
-
if (IsEllipsized())
ret = Ellipsize(ret);
void wxGenericStaticText::SetLabel(const wxString& label)
{
wxControl::SetLabel(label);
- DoSetLabel(GetEllipsizedLabelWithoutMarkup());
+ DoSetLabel(GetEllipsizedLabel());
if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
InvalidateBestSize();
Refresh();
return true;
}
-void wxStaticText::SetLabel( const wxString& str )
+void wxStaticText::GTKDoSetLabel(GTKLabelSetter setter, const wxString& label)
{
wxCHECK_RET( m_widget != NULL, wxT("invalid static text") );
- // save the label inside m_labelOrig in case user calls GetLabel() later
- m_labelOrig = str;
-
InvalidateBestSize();
- wxString label(str);
- if (gtk_check_version(2,6,0) &&
- IsEllipsized())
+ if (gtk_check_version(2,6,0) && IsEllipsized())
{
- // GTK+ < 2.6 does not support ellipsization:
- // since we need to use our generic code for ellipsization (which does not
- // behaves well in conjunction with markup; i.e. it may break the markup
- // validity erasing portions of the string), we also need to strip out
- // the markup (if present) from the label.
-
- label = GetEllipsizedLabelWithoutMarkup();
+ // GTK+ < 2.6 does not support ellipsization so we need to do it
+ // manually and as our ellipsization code doesn't deal with markup, we
+ // have no choice but to ignore it in this case and always use plain
+ // text.
+ GTKSetLabelForLabel(GTK_LABEL(m_widget), GetEllipsizedLabel());
+ }
+ else // Ellipsization not needed or supported by GTK+.
+ {
+ (this->*setter)(GTK_LABEL(m_widget), label);
}
-
- if ( HasFlag(wxST_MARKUP) )
- GTKSetLabelWithMarkupForLabel(GTK_LABEL(m_widget), label);
- else
- GTKSetLabelForLabel(GTK_LABEL(m_widget), label);
// adjust the label size to the new label unless disabled
if ( !HasFlag(wxST_NO_AUTORESIZE) &&
SetSize( GetBestSize() );
}
+void wxStaticText::SetLabel(const wxString& label)
+{
+ m_labelOrig = label;
+
+ GTKDoSetLabel(&wxStaticText::GTKSetLabelForLabel, label);
+}
+
+bool wxStaticText::DoSetLabelMarkup(const wxString& markup)
+{
+ const wxString stripped = RemoveMarkup(markup);
+ if ( stripped.empty() && !markup.empty() )
+ return false;
+
+ m_labelOrig = stripped;
+
+ GTKDoSetLabel(&wxStaticText::GTKSetLabelWithMarkupForLabel, markup);
+
+ return true;
+}
+
bool wxStaticText::SetFont( const wxFont &font )
{
const bool wasUnderlined = GetFont().GetUnderlined();
void wxStaticText::DoSetLabel(const wxString& str)
{
- // this function looks like GTKSetLabelForLabel() but here we just want to modify
- // the GTK control without altering any internal wxStaticText variable
-
- const wxString labelGTK = GTKConvertMnemonics(str);
- gtk_label_set_text_with_mnemonic(GTK_LABEL(m_widget), wxGTK_CONV(labelGTK));
+ GTKSetLabelForLabel(GTK_LABEL(m_widget), str);
}
// static
{
m_labelOrig = label; // save original label
- // Motif does not support neither ellipsize nor markup in static text:
- DoSetLabel(GetEllipsizedLabelWithoutMarkup());
+ // Motif does not support ellipsized labels natively
+ DoSetLabel(GetEllipsizedLabel());
}
// for wxST_ELLIPSIZE_* support:
#ifdef SS_ENDELLIPSIS
if ( styleReal & SS_ENDELLIPSIS )
- DoSetLabel(GetLabelWithoutMarkup());
+ DoSetLabel(GetLabel());
else
#endif // SS_ENDELLIPSIS
- DoSetLabel(GetEllipsizedLabelWithoutMarkup());
+ DoSetLabel(GetEllipsizedLabel());
// adjust the size of the window to fit to the label unless autoresizing is
// disabled
{
m_labelOrig = rsLabel; // save original label
- // OS/2 does not support neither ellipsize nor markup in static text:
- DoSetLabel(rsLabel);
- DoSetLabel(GetEllipsizedLabelWithoutMarkup());
+ // OS/2 does not support ellipsized labels in static text:
+ DoSetLabel(GetEllipsizedLabel());
//
// Adjust the size of the window to fit to the label unless autoresizing is
)
{
// leave ellipsization to the OS
- DoSetLabel(GetLabelWithoutMarkup());
+ DoSetLabel(GetLabel());
}
else // not supported natively
{
- DoSetLabel(GetEllipsizedLabelWithoutMarkup());
+ DoSetLabel(GetEllipsizedLabel());
}
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
// save original label
m_labelOrig = str;
- // draw as real label the result of GetEllipsizedLabelWithoutMarkup:
- DoSetLabel(GetEllipsizedLabelWithoutMarkup());
+ // draw as real label the abbreviated version of it
+ DoSetLabel(GetEllipsizedLabel());
}
void wxStaticText::DoSetLabel(const wxString& str)
void GetLabelText();
void Statics();
- wxStaticText *m_st, *m_stWithMarkup;
+ wxStaticText *m_st;
// we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox
wxCheckBox *m_cb;
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);
}
#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()
// 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() );
}
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 <span foreground='blue'>some</span> <b>markup</b>";
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 <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";
const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> 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() );
}
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 <span foreground='blue'>some</span> <b>markup</b>";
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 <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";
const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> 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() );
// 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() );
}
}
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("<b></b>") );
- CPPUNIT_ASSERT_EQUAL( "<b></b>&""'",
- wxStaticText::EscapeMarkup("<b></b>&\"\"'") );
}