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