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