]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: stattext.h | |
e54c96f1 | 3 | // Purpose: interface of wxStaticText |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxStaticText | |
7c913512 | 11 | |
23324ae1 | 12 | A static text control displays one or more lines of read-only text. |
4520d583 FM |
13 | wxStaticText supports the three classic text alignments, label ellipsization |
14 | and formatting markup. | |
7c913512 | 15 | |
23324ae1 | 16 | @beginStyleTable |
8c6791e4 | 17 | @style{wxALIGN_LEFT} |
5c87527c | 18 | Align the text to the left. |
8c6791e4 | 19 | @style{wxALIGN_RIGHT} |
5c87527c | 20 | Align the text to the right. |
8c6791e4 | 21 | @style{wxALIGN_CENTRE} |
5c87527c | 22 | Center the text (horizontally). |
8c6791e4 | 23 | @style{wxST_NO_AUTORESIZE} |
23324ae1 | 24 | By default, the control will adjust its size to exactly fit to the |
32ee98eb | 25 | size of the text when SetLabel() is called. If this style flag is |
23324ae1 | 26 | given, the control will not change its size (this style is |
32ee98eb FM |
27 | especially useful with controls which also have the @c wxALIGN_RIGHT or |
28 | the @c wxALIGN_CENTRE style because otherwise they won't make sense any | |
29 | longer after a call to SetLabel()). | |
8c6791e4 | 30 | @style{wxST_ELLIPSIZE_START} |
4520d583 | 31 | If the labeltext width exceeds the control width, replace the beginning |
5c87527c | 32 | of the label with an ellipsis; uses wxControl::Ellipsize. |
8c6791e4 | 33 | @style{wxST_ELLIPSIZE_MIDDLE} |
4520d583 | 34 | If the label text width exceeds the control width, replace the middle |
5c87527c | 35 | of the label with an ellipsis; uses wxControl::Ellipsize. |
8c6791e4 | 36 | @style{wxST_ELLIPSIZE_END} |
4520d583 | 37 | If the label text width exceeds the control width, replace the end |
5c87527c | 38 | of the label with an ellipsis; uses wxControl::Ellipsize. |
8c6791e4 | 39 | @style{wxST_MARKUP} |
5c87527c | 40 | Support markup in the label; see SetLabel() for more information. |
23324ae1 | 41 | @endStyleTable |
7c913512 | 42 | |
23324ae1 FM |
43 | @library{wxcore} |
44 | @category{ctrl} | |
7e59b885 | 45 | @appearance{statictext.png} |
7c913512 | 46 | |
e54c96f1 | 47 | @see wxStaticBitmap, wxStaticBox |
23324ae1 FM |
48 | */ |
49 | class wxStaticText : public wxControl | |
50 | { | |
51 | public: | |
671600d8 RR |
52 | /** |
53 | Default constructor. | |
54 | */ | |
55 | wxStaticText(); | |
4701dc09 | 56 | |
23324ae1 FM |
57 | /** |
58 | Constructor, creating and showing a text control. | |
3c4f71cc | 59 | |
7c913512 | 60 | @param parent |
4cc4bfaf | 61 | Parent window. Should not be @NULL. |
7c913512 | 62 | @param id |
4cc4bfaf | 63 | Control identifier. A value of -1 denotes a default value. |
7c913512 | 64 | @param label |
4cc4bfaf | 65 | Text label. |
7c913512 | 66 | @param pos |
4cc4bfaf | 67 | Window position. |
7c913512 | 68 | @param size |
4cc4bfaf | 69 | Window size. |
7c913512 | 70 | @param style |
4cc4bfaf | 71 | Window style. See wxStaticText. |
7c913512 | 72 | @param name |
4cc4bfaf | 73 | Window name. |
3c4f71cc | 74 | |
4cc4bfaf | 75 | @see Create() |
23324ae1 | 76 | */ |
7c913512 FM |
77 | wxStaticText(wxWindow* parent, wxWindowID id, |
78 | const wxString& label, | |
79 | const wxPoint& pos = wxDefaultPosition, | |
80 | const wxSize& size = wxDefaultSize, | |
81 | long style = 0, | |
11e3af6e | 82 | const wxString& name = wxStaticTextNameStr); |
23324ae1 FM |
83 | |
84 | /** | |
85 | Creation function, for two-step construction. For details see wxStaticText(). | |
86 | */ | |
43c48e1e | 87 | bool Create(wxWindow* parent, wxWindowID id, const wxString& label, |
23324ae1 | 88 | const wxPoint& pos = wxDefaultPosition, |
43c48e1e FM |
89 | const wxSize& size = wxDefaultSize, long style = 0, |
90 | const wxString& name = wxStaticTextNameStr); | |
23324ae1 FM |
91 | |
92 | /** | |
93 | Returns the contents of the control. | |
4701dc09 | 94 | |
32ee98eb | 95 | Note that the returned string may contain both the mnemonics (@& characters), |
23324ae1 | 96 | if any, and markup tags, if any. |
32ee98eb | 97 | |
4701dc09 | 98 | Use GetLabelText() if only the label text is needed. |
23324ae1 | 99 | */ |
328f5751 | 100 | wxString GetLabel() const; |
23324ae1 | 101 | |
23324ae1 | 102 | /** |
4701dc09 FM |
103 | This method returns the control's label without the mnemonics characters |
104 | (if any) and without the markup (if the control has @c wxST_MARKUP style). | |
105 | */ | |
106 | wxString GetLabelText() const; | |
107 | ||
4520d583 FM |
108 | /** |
109 | Returns @true if the window styles for this control contains one of the | |
110 | @c wxST_ELLIPSIZE_START, @c wxST_ELLIPSIZE_MIDDLE or @c wxST_ELLIPSIZE_END styles. | |
111 | */ | |
112 | bool IsEllipsized() const; | |
113 | ||
32ee98eb FM |
114 | // NB: when writing docs for the following function remember that Doxygen |
115 | // will always expand HTML entities (e.g. ") and thus we need to | |
116 | // write e.g. "&lt;" to have in the output the "<" string. | |
4520d583 | 117 | |
23324ae1 FM |
118 | /** |
119 | Sets the static text label and updates the controls size to exactly fit the | |
32ee98eb | 120 | label unless the control has @c wxST_NO_AUTORESIZE flag. |
4701dc09 | 121 | |
23324ae1 FM |
122 | This function allows to set decorated static label text on platforms which |
123 | support it (currently only GTK+ 2). For the other platforms, the markup is | |
124 | ignored. | |
4701dc09 | 125 | |
23324ae1 | 126 | The supported tags are: |
3f5506cf | 127 | <TABLE> |
32ee98eb FM |
128 | <TR> |
129 | <TD><b>Tag</b></TD> | |
130 | <TD><b>Description</b></TD> | |
131 | </TR> | |
3f5506cf RR |
132 | <TR> |
133 | <TD><b></TD> | |
134 | <TD>bold text</TD> | |
135 | </TR> | |
136 | <TR> | |
137 | <TD><big></TD> | |
138 | <TD>bigger text</TD> | |
139 | </TR> | |
140 | <TR> | |
141 | <TD><i></TD> | |
142 | <TD>italic text</TD> | |
143 | </TR> | |
144 | <TR> | |
145 | <TD><s></TD> | |
146 | <TD>strike-through text</TD> | |
147 | </TR> | |
148 | <TR> | |
149 | <TD><sub></TD> | |
150 | <TD>subscript text</TD> | |
151 | </TR> | |
152 | <TR> | |
153 | <TD><sup></TD> | |
154 | <TD>superscript text</TD> | |
155 | </TR> | |
156 | <TR> | |
157 | <TD><small></TD> | |
158 | <TD>smaller text</TD> | |
159 | </TR> | |
160 | <TR> | |
161 | <TD><tt></TD> | |
162 | <TD>monospaced text</TD> | |
163 | </TR> | |
164 | <TR> | |
165 | <TD><u></TD> | |
166 | <TD>underlined text</TD> | |
167 | </TR> | |
168 | <TR> | |
169 | <TD><span></TD> | |
4701dc09 FM |
170 | <TD>generic formatter tag; see Pango Markup |
171 | (http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html) | |
172 | for more information.</TD> | |
3f5506cf RR |
173 | </TR> |
174 | </TABLE> | |
3c4f71cc | 175 | |
23324ae1 | 176 | Note that the string must be well-formed (e.g. all tags must be correctly |
4701dc09 | 177 | closed) otherwise it can be not shown correctly or at all. |
23324ae1 | 178 | Also note that you need to escape the following special characters: |
4701dc09 | 179 | |
3f5506cf RR |
180 | <TABLE> |
181 | <TR> | |
f045c7f5 FM |
182 | <TD><b>Special character</b></TD> |
183 | <TD><b>Escape as</b></TD> | |
3f5506cf RR |
184 | </TR> |
185 | <TR> | |
186 | <TD>@c &</TD> | |
f045c7f5 | 187 | <TD>@c &amp; or as @c &&</TD> |
3f5506cf RR |
188 | </TR> |
189 | <TR> | |
190 | <TD>@c '</TD> | |
191 | <TD>@c &apos;</TD> | |
192 | </TR> | |
193 | <TR> | |
194 | <TD>@c "</TD> | |
195 | <TD>@c &quot;</TD> | |
196 | </TR> | |
197 | <TR> | |
198 | <TD>@c <</TD> | |
199 | <TD>@c &lt;</TD> | |
200 | </TR> | |
201 | <TR> | |
202 | <TD>@c ></TD> | |
203 | <TD>@c &gt;</TD> | |
204 | </TR> | |
205 | </TABLE> | |
4701dc09 | 206 | |
3f5506cf | 207 | The non-escaped ampersand @c & characters are interpreted as |
23324ae1 | 208 | mnemonics; see wxControl::SetLabel. |
3c4f71cc | 209 | |
23324ae1 | 210 | Example: |
3c4f71cc | 211 | |
7c913512 | 212 | @param label |
4701dc09 FM |
213 | The new label to set. |
214 | It may contain newline characters and the markup tags described above. | |
23324ae1 FM |
215 | */ |
216 | virtual void SetLabel(const wxString& label); | |
32ee98eb FM |
217 | |
218 | /** | |
219 | Sets the control's label to exactly the given string. | |
220 | ||
221 | Unlike SetLabel(), this function shows exactly the @a text passed to it | |
222 | in the control, without interpreting ampersands in it in any way. | |
223 | Notice that it means that the control can't have any mnemonic defined | |
224 | for it using this function. | |
225 | ||
226 | */ | |
227 | virtual void SetLabelText(const wxString& text); | |
23324ae1 FM |
228 | |
229 | /** | |
230 | This functions wraps the controls label so that each of its lines becomes at | |
4cc4bfaf | 231 | most @a width pixels wide if possible (the lines are broken at words |
4701dc09 FM |
232 | boundaries so it might not be the case if words are too long). |
233 | ||
234 | If @a width is negative, no wrapping is done. Note that this width is not | |
cd3eb0f7 SN |
235 | necessarily the total width of the control, since a few pixels for the |
236 | border (depending on the controls border style) may be added. | |
3c4f71cc | 237 | |
1e24c2af | 238 | @since 2.6.2 |
23324ae1 FM |
239 | */ |
240 | void Wrap(int width); | |
32ee98eb FM |
241 | |
242 | ||
243 | public: // static functions | |
244 | ||
245 | /** | |
246 | Returns the given @a label string without the mnemonics characters (if any) | |
247 | and without the markup. | |
248 | ||
249 | Note that since this function is static it will always remove markup | |
250 | (since it cannot check @c wxST_MARKUP presence/absence!). | |
251 | */ | |
252 | static wxString GetLabelText(const wxString& label); | |
253 | ||
254 | /** | |
255 | Escapes all the symbols of @a str that have a special meaning (<tt><>"'&</tt>) for | |
256 | wxStaticText objects with the @c wxST_MARKUP style. | |
257 | ||
258 | Those symbols are replaced the corresponding entities | |
259 | (&lt; &gt; &quot; &apos; &amp;). | |
260 | */ | |
261 | static wxString EscapeMarkup(const wxString& str); | |
262 | ||
263 | /** | |
264 | Removes the markup accepted by wxStaticText when the @c wxST_MARKUP style is used, | |
265 | and then returns the cleaned string. | |
266 | ||
267 | See SetLabel() for more info about the markup. | |
268 | */ | |
269 | static wxString RemoveMarkup(const wxString& str); | |
23324ae1 | 270 | }; |
e54c96f1 | 271 |