]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/control.h
fixes for missing or broken interface items for Phoenix
[wxWidgets.git] / interface / wx / control.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: control.h
e54c96f1 3// Purpose: interface of wxControl
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
a78618b0
FM
9/**
10 Flags used by wxControl::Ellipsize function.
11*/
12enum wxEllipsizeFlags
13{
355ce7ad
VZ
14 /// No special flags.
15 wxELLIPSIZE_FLAGS_NONE = 0,
16
17 /**
18 Take mnemonics into account when calculating the text width.
19
20 With this flag when calculating the size of the passed string,
21 mnemonics characters (see wxControl::SetLabel) will be automatically
22 reduced to a single character. This leads to correct calculations only
23 if the string passed to Ellipsize() will be used with
24 wxControl::SetLabel. If you don't want ampersand to be interpreted as
25 mnemonics (e.g. because you use wxControl::SetLabelText) then don't use
26 this flag.
27 */
28 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS = 1,
29
30 /**
31 Expand tabs in spaces when calculating the text width.
32
33 This flag tells wxControl::Ellipsize() to calculate the width of tab
34 characters @c '\\t' as 6 spaces.
35 */
36 wxELLIPSIZE_FLAGS_EXPAND_TABS = 2,
a78618b0
FM
37
38 /// The default flags for wxControl::Ellipsize.
355ce7ad
VZ
39 wxELLIPSIZE_FLAGS_DEFAULT = wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS|
40 wxELLIPSIZE_FLAGS_EXPAND_TABS
a78618b0
FM
41};
42
43
5c87527c
FM
44/**
45 The different ellipsization modes supported by the
46 wxControl::Ellipsize function.
47*/
48enum wxEllipsizeMode
49{
c937bcac
VZ
50 /// Don't ellipsize the text at all. @since 2.9.1
51 wxELLIPSIZE_NONE,
52
a78618b0 53 /// Put the ellipsis at the start of the string, if the string needs ellipsization.
5c87527c 54 wxELLIPSIZE_START,
a78618b0
FM
55
56 /// Put the ellipsis in the middle of the string, if the string needs ellipsization.
5c87527c 57 wxELLIPSIZE_MIDDLE,
a78618b0
FM
58
59 /// Put the ellipsis at the end of the string, if the string needs ellipsization.
5c87527c
FM
60 wxELLIPSIZE_END
61};
62
23324ae1
FM
63/**
64 @class wxControl
7c913512 65
cdbcf4c2 66 This is the base class for a control or "widget".
7c913512 67
23324ae1
FM
68 A control is generally a small window which processes user input and/or
69 displays one or more item of data.
7c913512 70
3051a44a
FM
71 @beginEventEmissionTable{wxClipboardTextEvent}
72 @event{EVT_TEXT_COPY(id, func)}
73 Some or all of the controls content was copied to the clipboard.
74 @event{EVT_TEXT_CUT(id, func)}
75 Some or all of the controls content was cut (i.e. copied and
76 deleted).
77 @event{EVT_TEXT_PASTE(id, func)}
78 Clipboard content was pasted into the control.
79 @endEventTable
80
23324ae1
FM
81 @library{wxcore}
82 @category{ctrl}
7c913512 83
e54c96f1 84 @see wxValidator
23324ae1
FM
85*/
86class wxControl : public wxWindow
87{
88public:
86381d42
RD
89
90 /**
91 Constructs a control.
92
93 @param parent
94 Pointer to a parent window.
95 @param id
96 Control identifier. If wxID_ANY, will automatically create an identifier.
97 @param pos
98 Control position. wxDefaultPosition indicates that wxWidgets
99 should generate a default position for the control.
100 @param size
101 Control size. wxDefaultSize indicates that wxWidgets should generate
102 a default size for the window. If no suitable size can be found, the
103 window will be sized to 20x20 pixels so that the window is visible but
104 obviously not correctly sized.
105 @param style
106 Control style. For generic window styles, please see wxWindow.
107 @param name
108 Control name.
109 */
110 wxControl(wxWindow *parent, wxWindowID id,
111 const wxPoint& pos = wxDefaultPosition,
112 const wxSize& size = wxDefaultSize, long style = 0,
113 const wxValidator& validator = wxDefaultValidator,
114 const wxString& name = wxControlNameStr);
115
116 bool Create(wxWindow *parent, wxWindowID id,
117 const wxPoint& pos = wxDefaultPosition,
118 const wxSize& size = wxDefaultSize, long style = 0,
119 const wxValidator& validator = wxDefaultValidator,
120 const wxString& name = wxControlNameStr);
121
23324ae1 122 /**
bd0812fe
BP
123 Simulates the effect of the user issuing a command to the item.
124
125 @see wxCommandEvent
23324ae1 126 */
b7e94bd7 127 virtual void Command(wxCommandEvent& event);
23324ae1 128
5c87527c 129 /**
32ee98eb 130 Returns the control's label, as it was passed to SetLabel().
5c87527c 131
32ee98eb
FM
132 Note that the returned string may contains mnemonics ("&" characters) if they were
133 passed to the SetLabel() function; use GetLabelText() if they are undesired.
bd0812fe 134
32ee98eb
FM
135 Also note that the returned string is always the string which was passed to
136 SetLabel() but may be different from the string passed to SetLabelText()
137 (since this last one escapes mnemonic characters).
23324ae1 138 */
328f5751 139 wxString GetLabel() const;
23324ae1 140
23324ae1 141 /**
bd0812fe 142 Returns the control's label without mnemonics.
32ee98eb
FM
143
144 Note that because of the stripping of the mnemonics the returned string may differ
a7d354c6
FM
145 from the string which was passed to SetLabel() but should always be the same which
146 was passed to SetLabelText().
23324ae1 147 */
4707b84c 148 wxString GetLabelText() const;
bd0812fe 149
32ee98eb
FM
150 /**
151 Sets the control's label.
152
153 All "&" characters in the @a label are special and indicate that the
154 following character is a @e mnemonic for this control and can be used to
155 activate it from the keyboard (typically by using @e Alt key in
156 combination with it). To insert a literal ampersand character, you need
57ab6f23 157 to double it, i.e. use "&&". If this behaviour is undesirable, use
32ee98eb
FM
158 SetLabelText() instead.
159 */
160 void SetLabel(const wxString& label);
161
162 /**
163 Sets the control's label to exactly the given string.
164
165 Unlike SetLabel(), this function shows exactly the @a text passed to it
166 in the control, without interpreting ampersands in it in any way.
167 Notice that it means that the control can't have any mnemonic defined
168 for it using this function.
169
170 @see EscapeMnemonics()
171 */
172 void SetLabelText(const wxString& text);
173
3da9cffc
VZ
174 // NB: when writing docs for the following function remember that Doxygen
175 // will always expand HTML entities (e.g. ") and thus we need to
176 // write e.g. "<" to have in the output the "<" string.
177
178 /**
179 Sets the controls label to a string using markup.
180
181 Simple markup supported by this function can be used to apply different
7d5051cb
VZ
182 fonts or colours to different parts of the control label when supported.
183 If markup is not supported by the control or platform, it is simply
184 stripped and SetLabel() is used with the resulting string.
3da9cffc
VZ
185
186 For example,
187 @code
188 wxStaticText *text;
189 ...
190 text->SetLabelMarkup("<b>&amp;Bed</b> &amp;mp; "
191 "<span foreground='red'>breakfast</span> "
192 "available <big>HERE</big>");
193 @endcode
194 would show the string using bold, red and big for the corresponding
195 words under wxGTK but will simply show the string "Bed &amp; breakfast
196 available HERE" on the other platforms. In any case, the "B" of "Bed"
197 will be underlined to indicate that it can be used as a mnemonic for
198 this control.
199
200 The supported tags are:
201 <TABLE>
202 <TR>
203 <TD><b>Tag</b></TD>
204 <TD><b>Description</b></TD>
205 </TR>
206 <TR>
207 <TD>&lt;b&gt;</TD>
208 <TD>bold text</TD>
209 </TR>
210 <TR>
211 <TD>&lt;big&gt;</TD>
212 <TD>bigger text</TD>
213 </TR>
214 <TR>
215 <TD>&lt;i&gt;</TD>
216 <TD>italic text</TD>
217 </TR>
218 <TR>
219 <TD>&lt;s&gt;</TD>
220 <TD>strike-through text</TD>
221 </TR>
222 <TR>
223 <TD>&lt;small&gt;</TD>
224 <TD>smaller text</TD>
225 </TR>
226 <TR>
227 <TD>&lt;tt&gt;</TD>
228 <TD>monospaced text</TD>
229 </TR>
230 <TR>
231 <TD>&lt;u&gt;</TD>
232 <TD>underlined text</TD>
233 </TR>
234 <TR>
235 <TD>&lt;span&gt;</TD>
236 <TD>generic formatter tag, see the table below for supported
237 attributes.
238 </TD>
239 </TR>
240 </TABLE>
241
242 Supported @c &lt;span&gt; attributes:
243 <TABLE>
244 <TR>
245 <TD><b>Name</b></TD>
246 <TD><b>Description</b></TD>
247 </TR>
248 <TR>
249 <TD>foreground, fgcolor, color</TD>
250 <TD>Foreground text colour, can be a name or RGB value.</TD>
251 </TR>
252 <TR>
253 <TD>background, bgcolor</TD>
254 <TD>Background text colour, can be a name or RGB value.</TD>
255 </TR>
256 <TR>
257 <TD>font_family, face</TD>
258 <TD>Font face name.</TD>
259 </TR>
260 <TR>
261 <TD>font_weight, weight</TD>
262 <TD>Numeric value in 0..900 range or one of "ultralight",
263 "light", "normal" (all meaning non-bold), "bold", "ultrabold"
264 and "heavy" (all meaning bold).</TD>
265 </TR>
266 <TR>
267 <TD>font_style, style</TD>
268 <TD>Either "oblique" or "italic" (both with the same meaning)
269 or "normal".</TD>
270 </TR>
271 <TR>
272 <TD>size</TD>
273 <TD>The font size can be specified either as "smaller" or
274 "larger" relatively to the current font, as a CSS font size
275 name ("xx-small", "x-small", "small", "medium", "large",
276 "x-large" or "xx-large") or as a number giving font size in
277 1024th parts of a point, i.e. 10240 for a 10pt font.</TD>
278 </TR>
279 </TABLE>
280
281 This markup language is a strict subset of Pango markup (described at
282 http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html)
283 and any tags and span attributes not documented above can't be used
284 under non-GTK platforms.
285
286 Also note that you need to escape the following special characters:
287 <TABLE>
288 <TR>
289 <TD><b>Special character</b></TD>
290 <TD><b>Escape as</b></TD>
291 </TR>
292 <TR>
293 <TD>@c &amp;</TD>
294 <TD>@c &amp;amp; or as @c &amp;&amp;</TD>
295 </TR>
296 <TR>
297 <TD>@c &apos;</TD>
298 <TD>@c &amp;apos;</TD>
299 </TR>
300 <TR>
301 <TD>@c &quot;</TD>
302 <TD>@c &amp;quot;</TD>
303 </TR>
304 <TR>
305 <TD>@c &lt;</TD>
306 <TD>@c &amp;lt;</TD>
307 </TR>
308 <TR>
309 <TD>@c &gt;</TD>
310 <TD>@c &amp;gt;</TD>
311 </TR>
312 </TABLE>
313
314 The non-escaped ampersand @c &amp; characters are interpreted as
315 mnemonics as with wxControl::SetLabel.
316
317
318 @param markup
7d5051cb
VZ
319 String containing markup for the label. It may contain markup tags
320 described above and newline characters but currently only wxGTK and
321 wxOSX support multiline labels with markup, the generic
322 implementation (also used in wxMSW) only handles single line markup
323 labels. Notice that the string must be well-formed (e.g. all tags
324 must be correctly closed) and won't be shown at all otherwise.
3da9cffc
VZ
325 @return
326 @true if the new label was set (even if markup in it was ignored)
327 or @false if we failed to parse the markup. In this case the label
328 remains unchanged.
329
7d5051cb
VZ
330
331 Currently wxButton supports markup in all major ports (wxMSW, wxGTK and
332 wxOSX/Cocoa) while wxStaticText supports it in wxGTK and wxOSX and its
333 generic version (which can be used under MSW if markup support is
334 required). Extending support to more controls is planned in the future.
3da9cffc
VZ
335
336 @since 2.9.2
337 */
338 bool SetLabelMarkup(const wxString& markup);
339
32ee98eb
FM
340
341public: // static functions
342
bd0812fe 343 /**
4520d583 344 Returns the given @a label string without mnemonics ("&" characters).
bd0812fe
BP
345 */
346 static wxString GetLabelText(const wxString& label);
23324ae1 347
4520d583 348 /**
32ee98eb
FM
349 Returns the given @a str string without mnemonics ("&" characters).
350
3da9cffc
VZ
351 @note This function is identical to GetLabelText() and is provided
352 mostly for symmetry with EscapeMnemonics().
4520d583
FM
353 */
354 static wxString RemoveMnemonics(const wxString& str);
355
5b8b2c84 356 /**
32ee98eb 357 Escapes the special mnemonics characters ("&") in the given string.
5b8b2c84
VZ
358
359 This function can be helpful if you need to set the controls label to a
360 user-provided string. If the string contains ampersands, they wouldn't
361 appear on the display but be used instead to indicate that the
362 character following the first of them can be used as a control mnemonic.
363 While this can sometimes be desirable (e.g. to allow the user to
364 configure mnemonics of the controls), more often you will want to use
365 this function before passing a user-defined string to SetLabel().
366 Alternatively, if the label is entirely user-defined, you can just call
367 SetLabelText() directly -- but this function must be used if the label
368 is a combination of a part defined by program containing the control
369 mnemonics and a user-defined part.
370
371 @param text
372 The string such as it should appear on the display.
373 @return
374 The same string with the ampersands in it doubled.
375 */
376 static wxString EscapeMnemonics(const wxString& text);
377
23324ae1 378 /**
32ee98eb 379 Replaces parts of the @a label string with ellipsis, if needed, so
508fc76d
VS
380 that it fits into @a maxWidth pixels if possible.
381
382 Note that this function does @em not guarantee that the returned string
383 will always be shorter than @a maxWidth; if @a maxWidth is extremely
384 small, ellipsized text may be larger.
bd0812fe 385
32ee98eb
FM
386 @param label
387 The string to ellipsize
388 @param dc
389 The DC used to retrieve the character widths through the
390 wxDC::GetPartialTextExtents() function.
391 @param mode
392 The ellipsization mode. This is the setting which determines
393 which part of the string should be replaced by the ellipsis.
394 See ::wxEllipsizeMode enumeration values for more info.
395 @param maxWidth
396 The maximum width of the returned string in pixels.
397 This argument determines how much characters of the string need to
398 be removed (and replaced by ellipsis).
399 @param flags
400 One or more of the ::wxEllipsizeFlags enumeration values combined.
23324ae1 401 */
32ee98eb
FM
402 static wxString Ellipsize(const wxString& label, const wxDC& dc,
403 wxEllipsizeMode mode, int maxWidth,
404 int flags = wxELLIPSIZE_FLAGS_DEFAULT);
23324ae1 405};
e54c96f1 406