Replace wxST_MARKUP style with wxControl::SetLabelMarkup().
This is an incompatible change which removes the wxStaticText-specific wxST_MARKUP style and adds wxControl::SetLabelMarkup() replacing it. It doesn't actually change anything yet but it simplifies wxStaticText code a lot by getting rid of many markup-related functions in it which had to behave differently depending on whether wxST_MARKUP was used or not and also paves way for adding markup support for the other controls in the future. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67055 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -316,6 +316,8 @@ Changes in behaviour which may result in compilation errors
|
|||||||
just "%" wxLongLongFmtSpec "x", i.e. simply remove wxT() from the strings you
|
just "%" wxLongLongFmtSpec "x", i.e. simply remove wxT() from the strings you
|
||||||
concatenate with it.
|
concatenate with it.
|
||||||
|
|
||||||
|
- wxST_MARKUP doesn't exist any more, use wxControl::SetLabelMarkup() instead.
|
||||||
|
|
||||||
|
|
||||||
Deprecated methods and their replacements
|
Deprecated methods and their replacements
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
@@ -94,6 +94,27 @@ public:
|
|||||||
// get just the text of the label, without mnemonic characters ('&')
|
// get just the text of the label, without mnemonic characters ('&')
|
||||||
virtual wxString GetLabelText() const { return GetLabelText(GetLabel()); }
|
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
|
// controls by default inherit the colours of their parents, if a
|
||||||
// particular control class doesn't want to do it, it can override
|
// particular control class doesn't want to do it, it can override
|
||||||
// ShouldInheritColours() to return false
|
// ShouldInheritColours() to return false
|
||||||
@@ -162,6 +183,12 @@ protected:
|
|||||||
const wxValidator& validator,
|
const wxValidator& validator,
|
||||||
const wxString& name);
|
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
|
// initialize the common fields of wxCommandEvent
|
||||||
void InitCommandEvent(wxCommandEvent& event) const;
|
void InitCommandEvent(wxCommandEvent& event) const;
|
||||||
|
|
||||||
@@ -170,6 +197,11 @@ protected:
|
|||||||
wxEllipsizeMode mode, int maxWidth,
|
wxEllipsizeMode mode, int maxWidth,
|
||||||
int replacementWidth);
|
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,
|
// this field contains the label in wx format, i.e. with '&' mnemonics,
|
||||||
// as it was passed to the last SetLabel() call
|
// as it was passed to the last SetLabel() call
|
||||||
wxString m_labelOrig;
|
wxString m_labelOrig;
|
||||||
|
@@ -56,6 +56,14 @@ protected:
|
|||||||
|
|
||||||
virtual wxString DoGetLabel() const;
|
virtual wxString DoGetLabel() const;
|
||||||
virtual void DoSetLabel(const wxString& str);
|
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)
|
DECLARE_DYNAMIC_CLASS(wxStaticText)
|
||||||
};
|
};
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
* wxStaticText flags
|
* wxStaticText flags
|
||||||
*/
|
*/
|
||||||
#define wxST_NO_AUTORESIZE 0x0001
|
#define wxST_NO_AUTORESIZE 0x0001
|
||||||
#define wxST_MARKUP 0x0002
|
// free 0x0002 bit
|
||||||
#define wxST_ELLIPSIZE_START 0x0004
|
#define wxST_ELLIPSIZE_START 0x0004
|
||||||
#define wxST_ELLIPSIZE_MIDDLE 0x0008
|
#define wxST_ELLIPSIZE_MIDDLE 0x0008
|
||||||
#define wxST_ELLIPSIZE_END 0x0010
|
#define wxST_ELLIPSIZE_END 0x0010
|
||||||
@@ -50,47 +50,17 @@ public:
|
|||||||
HasFlag(wxST_ELLIPSIZE_END);
|
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
|
protected: // functions required for wxST_ELLIPSIZE_* support
|
||||||
|
|
||||||
// choose the default border for this window
|
// choose the default border for this window
|
||||||
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
|
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
|
||||||
|
|
||||||
// calls only RemoveMarkup() on the original label
|
// Calls Ellipsize() on the real label if necessary. Unlike GetLabelText(),
|
||||||
// if the wxST_MARKUP style is set
|
// keeps the mnemonics instead of removing them.
|
||||||
// (but unlike GetLabelText won't remove mnemonics)
|
virtual wxString GetEllipsizedLabel() const;
|
||||||
virtual wxString GetLabelWithoutMarkup() const;
|
|
||||||
|
|
||||||
// just calls RemoveMarkup() & Ellipsize() on the original label
|
// Replaces parts of the string with ellipsis according to the ellipsize
|
||||||
// if the wxST_MARKUP & wxST_ELLIPSIZE_* styles are set
|
// style. Shouldn't be called if we don't have any.
|
||||||
// (but unlike GetLabelText won't remove mnemonics)
|
|
||||||
virtual wxString GetEllipsizedLabelWithoutMarkup() const;
|
|
||||||
|
|
||||||
// replaces parts of the string with ellipsis if needed
|
|
||||||
wxString Ellipsize(const wxString& label) const;
|
wxString Ellipsize(const wxString& label) const;
|
||||||
|
|
||||||
// to be called when updating the size of the static text:
|
// to be called when updating the size of the static text:
|
||||||
|
@@ -138,6 +138,166 @@ public:
|
|||||||
*/
|
*/
|
||||||
void SetLabelText(const wxString& 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
|
public: // static functions
|
||||||
|
|
||||||
@@ -149,9 +309,8 @@ public: // static functions
|
|||||||
/**
|
/**
|
||||||
Returns the given @a str string without mnemonics ("&" characters).
|
Returns the given @a str string without mnemonics ("&" characters).
|
||||||
|
|
||||||
@note This function is identic to GetLabelText() and is provided both for symmetry
|
@note This function is identical to GetLabelText() and is provided
|
||||||
with the wxStaticText::RemoveMarkup() function and to allow to write more
|
mostly for symmetry with EscapeMnemonics().
|
||||||
readable code (since this function has a more descriptive name respect GetLabelText()).
|
|
||||||
*/
|
*/
|
||||||
static wxString RemoveMnemonics(const wxString& str);
|
static wxString RemoveMnemonics(const wxString& str);
|
||||||
|
|
||||||
|
@@ -10,8 +10,10 @@
|
|||||||
@class wxStaticText
|
@class wxStaticText
|
||||||
|
|
||||||
A static text control displays one or more lines of read-only text.
|
A static text control displays one or more lines of read-only text.
|
||||||
wxStaticText supports the three classic text alignments, label ellipsization
|
wxStaticText supports the three classic text alignments, label
|
||||||
and formatting markup.
|
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
|
@beginStyleTable
|
||||||
@style{wxALIGN_LEFT}
|
@style{wxALIGN_LEFT}
|
||||||
@@ -25,7 +27,7 @@
|
|||||||
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
|
given, the control will not change its size (this style is
|
||||||
especially useful with controls which also have the @c wxALIGN_RIGHT or
|
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()).
|
longer after a call to SetLabel()).
|
||||||
@style{wxST_ELLIPSIZE_START}
|
@style{wxST_ELLIPSIZE_START}
|
||||||
If the labeltext width exceeds the control width, replace the beginning
|
If the labeltext width exceeds the control width, replace the beginning
|
||||||
@@ -36,8 +38,6 @@
|
|||||||
@style{wxST_ELLIPSIZE_END}
|
@style{wxST_ELLIPSIZE_END}
|
||||||
If the label text width exceeds the control width, replace the end
|
If the label text width exceeds the control width, replace the end
|
||||||
of the label with an ellipsis; uses wxControl::Ellipsize.
|
of the label with an ellipsis; uses wxControl::Ellipsize.
|
||||||
@style{wxST_MARKUP}
|
|
||||||
Support markup in the label; see SetLabel() for more information.
|
|
||||||
@endStyleTable
|
@endStyleTable
|
||||||
|
|
||||||
@library{wxcore}
|
@library{wxcore}
|
||||||
@@ -89,154 +89,12 @@ public:
|
|||||||
const wxSize& size = wxDefaultSize, long style = 0,
|
const wxSize& size = wxDefaultSize, long style = 0,
|
||||||
const wxString& name = wxStaticTextNameStr);
|
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
|
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.
|
@c wxST_ELLIPSIZE_START, @c wxST_ELLIPSIZE_MIDDLE or @c wxST_ELLIPSIZE_END styles.
|
||||||
*/
|
*/
|
||||||
bool IsEllipsized() const;
|
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
|
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
|
most @a width pixels wide if possible (the lines are broken at words
|
||||||
@@ -249,34 +107,5 @@ public:
|
|||||||
@since 2.6.2
|
@since 2.6.2
|
||||||
*/
|
*/
|
||||||
void Wrap(int width);
|
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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -216,7 +216,6 @@ void StaticWidgetsPage::CreateContent()
|
|||||||
|
|
||||||
m_chkGeneric = CreateCheckBoxAndAddToSizer(sizerLeft,
|
m_chkGeneric = CreateCheckBoxAndAddToSizer(sizerLeft,
|
||||||
"&Generic wxStaticText");
|
"&Generic wxStaticText");
|
||||||
m_chkMarkup = CreateCheckBoxAndAddToSizer(sizerLeft, "Support &markup");
|
|
||||||
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, "&Vertical line");
|
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, "&Vertical line");
|
||||||
m_chkAutoResize = CreateCheckBoxAndAddToSizer(sizerLeft, "&Fit to text");
|
m_chkAutoResize = CreateCheckBoxAndAddToSizer(sizerLeft, "&Fit to text");
|
||||||
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
||||||
@@ -341,7 +340,6 @@ void StaticWidgetsPage::Reset()
|
|||||||
m_chkVert->SetValue(false);
|
m_chkVert->SetValue(false);
|
||||||
m_chkAutoResize->SetValue(true);
|
m_chkAutoResize->SetValue(true);
|
||||||
m_chkEllipsize->SetValue(true);
|
m_chkEllipsize->SetValue(true);
|
||||||
m_chkMarkup->SetValue(true);
|
|
||||||
|
|
||||||
m_radioHAlign->SetSelection(StaticHAlign_Left);
|
m_radioHAlign->SetSelection(StaticHAlign_Left);
|
||||||
m_radioVAlign->SetSelection(StaticVAlign_Top);
|
m_radioVAlign->SetSelection(StaticVAlign_Top);
|
||||||
@@ -372,12 +370,6 @@ void StaticWidgetsPage::CreateStatic()
|
|||||||
flagsDummyText |= wxST_NO_AUTORESIZE;
|
flagsDummyText |= wxST_NO_AUTORESIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_chkMarkup->GetValue() )
|
|
||||||
{
|
|
||||||
flagsText |= wxST_MARKUP;
|
|
||||||
flagsDummyText |= wxST_MARKUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
int align = 0;
|
int align = 0;
|
||||||
switch ( m_radioHAlign->GetSelection() )
|
switch ( m_radioHAlign->GetSelection() )
|
||||||
{
|
{
|
||||||
@@ -457,7 +449,7 @@ void StaticWidgetsPage::CreateStatic()
|
|||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
flagsDummyText);
|
flagsDummyText);
|
||||||
m_statMarkup = new wxGenericStaticText(this, wxID_ANY,
|
m_statMarkup = new wxGenericStaticText(this, wxID_ANY,
|
||||||
m_textLabelWithMarkup->GetValue(),
|
wxString(),
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
flagsText);
|
flagsText);
|
||||||
}
|
}
|
||||||
@@ -468,10 +460,13 @@ void StaticWidgetsPage::CreateStatic()
|
|||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
flagsDummyText);
|
flagsDummyText);
|
||||||
m_statMarkup = new wxStaticText(this, wxID_ANY,
|
m_statMarkup = new wxStaticText(this, wxID_ANY,
|
||||||
m_textLabelWithMarkup->GetValue(),
|
wxString(),
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
flagsText);
|
flagsText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_statMarkup->SetLabelMarkup(m_textLabelWithMarkup->GetValue());
|
||||||
|
|
||||||
if ( m_chkGreen->GetValue() )
|
if ( m_chkGreen->GetValue() )
|
||||||
m_statMarkup->SetBackgroundColour(*wxGREEN);
|
m_statMarkup->SetBackgroundColour(*wxGREEN);
|
||||||
#if wxUSE_STATLINE
|
#if wxUSE_STATLINE
|
||||||
@@ -539,7 +534,7 @@ void StaticWidgetsPage::OnButtonLabelText(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void StaticWidgetsPage::OnButtonLabelWithMarkupText(wxCommandEvent& WXUNUSED(event))
|
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
|
// test GetLabel() and GetLabelText(); the first should return the
|
||||||
// label as it is written in the relative text control; the second should
|
// label as it is written in the relative text control; the second should
|
||||||
|
@@ -38,6 +38,8 @@
|
|||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/private/markupparser.h"
|
||||||
|
|
||||||
const char wxControlNameStr[] = "control";
|
const char wxControlNameStr[] = "control";
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -230,6 +232,27 @@ wxControlBase::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(va
|
|||||||
return attrs;
|
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
|
// wxControlBase - ellipsization code
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -195,49 +195,6 @@ void wxStaticTextBase::Wrap(int width)
|
|||||||
wrapper.WrapLabel(this, width);
|
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
|
// wxStaticTextBase - generic implementation for wxST_ELLIPSIZE_* support
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -247,7 +204,7 @@ void wxStaticTextBase::UpdateLabel()
|
|||||||
if (!IsEllipsized())
|
if (!IsEllipsized())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxString newlabel = GetEllipsizedLabelWithoutMarkup();
|
wxString newlabel = GetEllipsizedLabel();
|
||||||
|
|
||||||
// we need to touch the "real" label (i.e. the text set inside the control,
|
// 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().
|
// using port-specific functions) instead of the string returned by GetLabel().
|
||||||
@@ -260,18 +217,7 @@ void wxStaticTextBase::UpdateLabel()
|
|||||||
DoSetLabel(newlabel);
|
DoSetLabel(newlabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxStaticTextBase::GetLabelWithoutMarkup() const
|
wxString wxStaticTextBase::GetEllipsizedLabel() 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
|
// this function should be used only by ports which do not support
|
||||||
// ellipsis in static texts: we first remove markup (which cannot
|
// ellipsis in static texts: we first remove markup (which cannot
|
||||||
@@ -279,11 +225,6 @@ wxString wxStaticTextBase::GetEllipsizedLabelWithoutMarkup() const
|
|||||||
|
|
||||||
wxString ret(m_labelOrig);
|
wxString ret(m_labelOrig);
|
||||||
|
|
||||||
// the order of the following two blocks is important!
|
|
||||||
|
|
||||||
if (HasFlag(wxST_MARKUP))
|
|
||||||
ret = RemoveMarkup(ret);
|
|
||||||
|
|
||||||
if (IsEllipsized())
|
if (IsEllipsized())
|
||||||
ret = Ellipsize(ret);
|
ret = Ellipsize(ret);
|
||||||
|
|
||||||
|
@@ -85,7 +85,7 @@ wxSize wxGenericStaticText::DoGetBestClientSize() const
|
|||||||
void wxGenericStaticText::SetLabel(const wxString& label)
|
void wxGenericStaticText::SetLabel(const wxString& label)
|
||||||
{
|
{
|
||||||
wxControl::SetLabel(label);
|
wxControl::SetLabel(label);
|
||||||
DoSetLabel(GetEllipsizedLabelWithoutMarkup());
|
DoSetLabel(GetEllipsizedLabel());
|
||||||
if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
|
if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
|
||||||
InvalidateBestSize();
|
InvalidateBestSize();
|
||||||
Refresh();
|
Refresh();
|
||||||
|
@@ -101,32 +101,24 @@ bool wxStaticText::Create(wxWindow *parent,
|
|||||||
return true;
|
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") );
|
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();
|
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:
|
// GTK+ < 2.6 does not support ellipsization so we need to do it
|
||||||
// since we need to use our generic code for ellipsization (which does not
|
// manually and as our ellipsization code doesn't deal with markup, we
|
||||||
// behaves well in conjunction with markup; i.e. it may break the markup
|
// have no choice but to ignore it in this case and always use plain
|
||||||
// validity erasing portions of the string), we also need to strip out
|
// text.
|
||||||
// the markup (if present) from the label.
|
GTKSetLabelForLabel(GTK_LABEL(m_widget), GetEllipsizedLabel());
|
||||||
|
}
|
||||||
label = GetEllipsizedLabelWithoutMarkup();
|
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
|
// adjust the label size to the new label unless disabled
|
||||||
if ( !HasFlag(wxST_NO_AUTORESIZE) &&
|
if ( !HasFlag(wxST_NO_AUTORESIZE) &&
|
||||||
@@ -134,6 +126,26 @@ void wxStaticText::SetLabel( const wxString& str )
|
|||||||
SetSize( GetBestSize() );
|
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 )
|
bool wxStaticText::SetFont( const wxFont &font )
|
||||||
{
|
{
|
||||||
const bool wasUnderlined = GetFont().GetUnderlined();
|
const bool wasUnderlined = GetFont().GetUnderlined();
|
||||||
@@ -228,11 +240,7 @@ wxString wxStaticText::DoGetLabel() const
|
|||||||
|
|
||||||
void wxStaticText::DoSetLabel(const wxString& str)
|
void wxStaticText::DoSetLabel(const wxString& str)
|
||||||
{
|
{
|
||||||
// this function looks like GTKSetLabelForLabel() but here we just want to modify
|
GTKSetLabelForLabel(GTK_LABEL(m_widget), str);
|
||||||
// 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@@ -74,8 +74,8 @@ void wxStaticText::SetLabel(const wxString& label)
|
|||||||
{
|
{
|
||||||
m_labelOrig = label; // save original label
|
m_labelOrig = label; // save original label
|
||||||
|
|
||||||
// Motif does not support neither ellipsize nor markup in static text:
|
// Motif does not support ellipsized labels natively
|
||||||
DoSetLabel(GetEllipsizedLabelWithoutMarkup());
|
DoSetLabel(GetEllipsizedLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
// for wxST_ELLIPSIZE_* support:
|
// for wxST_ELLIPSIZE_* support:
|
||||||
|
@@ -186,10 +186,10 @@ void wxStaticText::SetLabel(const wxString& label)
|
|||||||
|
|
||||||
#ifdef SS_ENDELLIPSIS
|
#ifdef SS_ENDELLIPSIS
|
||||||
if ( styleReal & SS_ENDELLIPSIS )
|
if ( styleReal & SS_ENDELLIPSIS )
|
||||||
DoSetLabel(GetLabelWithoutMarkup());
|
DoSetLabel(GetLabel());
|
||||||
else
|
else
|
||||||
#endif // SS_ENDELLIPSIS
|
#endif // SS_ENDELLIPSIS
|
||||||
DoSetLabel(GetEllipsizedLabelWithoutMarkup());
|
DoSetLabel(GetEllipsizedLabel());
|
||||||
|
|
||||||
// adjust the size of the window to fit to the label unless autoresizing is
|
// adjust the size of the window to fit to the label unless autoresizing is
|
||||||
// disabled
|
// disabled
|
||||||
|
@@ -233,9 +233,8 @@ void wxStaticText::SetLabel(
|
|||||||
{
|
{
|
||||||
m_labelOrig = rsLabel; // save original label
|
m_labelOrig = rsLabel; // save original label
|
||||||
|
|
||||||
// OS/2 does not support neither ellipsize nor markup in static text:
|
// OS/2 does not support ellipsized labels in static text:
|
||||||
DoSetLabel(rsLabel);
|
DoSetLabel(GetEllipsizedLabel());
|
||||||
DoSetLabel(GetEllipsizedLabelWithoutMarkup());
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Adjust the size of the window to fit to the label unless autoresizing is
|
// Adjust the size of the window to fit to the label unless autoresizing is
|
||||||
|
@@ -62,11 +62,11 @@ void wxStaticText::SetLabel(const wxString& label)
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
// leave ellipsization to the OS
|
// leave ellipsization to the OS
|
||||||
DoSetLabel(GetLabelWithoutMarkup());
|
DoSetLabel(GetLabel());
|
||||||
}
|
}
|
||||||
else // not supported natively
|
else // not supported natively
|
||||||
{
|
{
|
||||||
DoSetLabel(GetEllipsizedLabelWithoutMarkup());
|
DoSetLabel(GetEllipsizedLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
|
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
|
||||||
|
@@ -74,8 +74,8 @@ void wxStaticText::SetLabel(const wxString& str)
|
|||||||
// save original label
|
// save original label
|
||||||
m_labelOrig = str;
|
m_labelOrig = str;
|
||||||
|
|
||||||
// draw as real label the result of GetEllipsizedLabelWithoutMarkup:
|
// draw as real label the abbreviated version of it
|
||||||
DoSetLabel(GetEllipsizedLabelWithoutMarkup());
|
DoSetLabel(GetEllipsizedLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxStaticText::DoSetLabel(const wxString& str)
|
void wxStaticText::DoSetLabel(const wxString& str)
|
||||||
|
@@ -48,7 +48,7 @@ private:
|
|||||||
void GetLabelText();
|
void GetLabelText();
|
||||||
void Statics();
|
void Statics();
|
||||||
|
|
||||||
wxStaticText *m_st, *m_stWithMarkup;
|
wxStaticText *m_st;
|
||||||
|
|
||||||
// we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox
|
// we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox
|
||||||
wxCheckBox *m_cb;
|
wxCheckBox *m_cb;
|
||||||
@@ -71,20 +71,16 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LabelTestCase, "LabelTestCase" );
|
|||||||
void LabelTestCase::setUp()
|
void LabelTestCase::setUp()
|
||||||
{
|
{
|
||||||
m_st = new wxStaticText(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL);
|
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);
|
m_cb = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_st->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_st->GetLabel() );
|
||||||
CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_stWithMarkup->GetLabel() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_cb->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_cb->GetLabel() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void LabelTestCase::tearDown()
|
void LabelTestCase::tearDown()
|
||||||
{
|
{
|
||||||
wxDELETE(m_st);
|
wxDELETE(m_st);
|
||||||
wxDELETE(m_stWithMarkup);
|
|
||||||
wxDELETE(m_cb);
|
wxDELETE(m_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,12 +90,10 @@ void LabelTestCase::tearDown()
|
|||||||
|
|
||||||
#define SET_LABEL(str) \
|
#define SET_LABEL(str) \
|
||||||
m_st->SetLabel(str); \
|
m_st->SetLabel(str); \
|
||||||
m_stWithMarkup->SetLabel(str); \
|
|
||||||
m_cb->SetLabel(str);
|
m_cb->SetLabel(str);
|
||||||
|
|
||||||
#define SET_LABEL_TEXT(str) \
|
#define SET_LABEL_TEXT(str) \
|
||||||
m_st->SetLabelText(str); \
|
m_st->SetLabelText(str); \
|
||||||
m_stWithMarkup->SetLabelText(str); \
|
|
||||||
m_cb->SetLabelText(str);
|
m_cb->SetLabelText(str);
|
||||||
|
|
||||||
void LabelTestCase::GetLabel()
|
void LabelTestCase::GetLabel()
|
||||||
@@ -119,7 +113,6 @@ void LabelTestCase::GetLabel()
|
|||||||
|
|
||||||
// GetLabel() should always return the string passed to SetLabel()
|
// GetLabel() should always return the string passed to SetLabel()
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabel() );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_stWithMarkup->GetLabel() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabel() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,27 +122,23 @@ void LabelTestCase::GetLabel()
|
|||||||
const wxString& testLabel = "label without mnemonics and markup";
|
const wxString& testLabel = "label without mnemonics and markup";
|
||||||
SET_LABEL_TEXT(testLabel);
|
SET_LABEL_TEXT(testLabel);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabel() );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_stWithMarkup->GetLabel() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabel() );
|
||||||
|
|
||||||
const wxString& testLabel2 = "label with &mnemonic";
|
const wxString& testLabel2 = "label with &mnemonic";
|
||||||
const wxString& testLabelText2 = "label with &&mnemonic";
|
const wxString& testLabelText2 = "label with &&mnemonic";
|
||||||
SET_LABEL_TEXT(testLabel2);
|
SET_LABEL_TEXT(testLabel2);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabel() );
|
||||||
CPPUNIT_ASSERT_EQUAL( "label with &mnemonic", m_stWithMarkup->GetLabel() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabel() );
|
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabel() );
|
||||||
|
|
||||||
const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
||||||
SET_LABEL_TEXT(testLabel3);
|
SET_LABEL_TEXT(testLabel3);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabel() );
|
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() );
|
CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->GetLabel() );
|
||||||
|
|
||||||
const wxString& testLabel4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";
|
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";
|
const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &&mnemonic";
|
||||||
SET_LABEL_TEXT(testLabel4);
|
SET_LABEL_TEXT(testLabel4);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabel() );
|
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() );
|
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabel() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,27 +149,23 @@ void LabelTestCase::GetLabelText()
|
|||||||
const wxString& testLabel = "label without mnemonics and markup";
|
const wxString& testLabel = "label without mnemonics and markup";
|
||||||
SET_LABEL(testLabel);
|
SET_LABEL(testLabel);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabelText() );
|
CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabelText() );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_stWithMarkup->GetLabelText() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabelText() );
|
CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabelText() );
|
||||||
|
|
||||||
const wxString& testLabel2 = "label with &mnemonic";
|
const wxString& testLabel2 = "label with &mnemonic";
|
||||||
const wxString& testLabelText2 = "label with mnemonic";
|
const wxString& testLabelText2 = "label with mnemonic";
|
||||||
SET_LABEL(testLabel2);
|
SET_LABEL(testLabel2);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabelText() );
|
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabelText() );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_stWithMarkup->GetLabelText() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabelText() );
|
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabelText() );
|
||||||
|
|
||||||
const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
||||||
SET_LABEL(testLabel3);
|
SET_LABEL(testLabel3);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabelText() );
|
CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabelText() );
|
||||||
CPPUNIT_ASSERT_EQUAL( "label with some markup", m_stWithMarkup->GetLabelText() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->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& 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";
|
const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> and mnemonic";
|
||||||
SET_LABEL(testLabel4);
|
SET_LABEL(testLabel4);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabelText() );
|
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() );
|
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabelText() );
|
||||||
|
|
||||||
|
|
||||||
@@ -199,7 +184,6 @@ void LabelTestCase::GetLabelText()
|
|||||||
|
|
||||||
// GetLabelText() should always return the string passed to SetLabelText()
|
// GetLabelText() should always return the string passed to SetLabelText()
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabelText() );
|
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( testLabelArray[s], m_cb->GetLabelText() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +193,4 @@ 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( "&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>&\"\"'") );
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user