1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxControl
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 Flags used by wxControl::Ellipsize function.
15 wxELLIPSIZE_FLAGS_NONE
= 0,
18 Take mnemonics into account when calculating the text width.
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
28 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
= 1,
31 Expand tabs in spaces when calculating the text width.
33 This flag tells wxControl::Ellipsize() to calculate the width of tab
34 characters @c '\\t' as 6 spaces.
36 wxELLIPSIZE_FLAGS_EXPAND_TABS
= 2,
38 /// The default flags for wxControl::Ellipsize.
39 wxELLIPSIZE_FLAGS_DEFAULT
= wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
|
40 wxELLIPSIZE_FLAGS_EXPAND_TABS
45 The different ellipsization modes supported by the
46 wxControl::Ellipsize function.
50 /// Don't ellipsize the text at all. @since 2.9.1
53 /// Put the ellipsis at the start of the string, if the string needs ellipsization.
56 /// Put the ellipsis in the middle of the string, if the string needs ellipsization.
59 /// Put the ellipsis at the end of the string, if the string needs ellipsization.
66 This is the base class for a control or "widget".
68 A control is generally a small window which processes user input and/or
69 displays one or more item of data.
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
77 @event{EVT_TEXT_PASTE(id, func)}
78 Clipboard content was pasted into the control.
86 class wxControl
: public wxWindow
94 Pointer to a parent window.
96 Control identifier. If wxID_ANY, will automatically create an identifier.
98 Control position. wxDefaultPosition indicates that wxWidgets
99 should generate a default position for the control.
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.
106 Control style. For generic window styles, please see wxWindow.
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
);
117 Default constructor to allow 2-phase creation.
121 bool Create(wxWindow
*parent
, wxWindowID id
,
122 const wxPoint
& pos
= wxDefaultPosition
,
123 const wxSize
& size
= wxDefaultSize
, long style
= 0,
124 const wxValidator
& validator
= wxDefaultValidator
,
125 const wxString
& name
= wxControlNameStr
);
128 Simulates the effect of the user issuing a command to the item.
132 virtual void Command(wxCommandEvent
& event
);
135 Returns the control's label, as it was passed to SetLabel().
137 Note that the returned string may contains mnemonics ("&" characters) if they were
138 passed to the SetLabel() function; use GetLabelText() if they are undesired.
140 Also note that the returned string is always the string which was passed to
141 SetLabel() but may be different from the string passed to SetLabelText()
142 (since this last one escapes mnemonic characters).
144 wxString
GetLabel() const;
147 Returns the control's label without mnemonics.
149 Note that because of the stripping of the mnemonics the returned string may differ
150 from the string which was passed to SetLabel() but should always be the same which
151 was passed to SetLabelText().
153 wxString
GetLabelText() const;
156 Sets the control's label.
158 All "&" characters in the @a label are special and indicate that the
159 following character is a @e mnemonic for this control and can be used to
160 activate it from the keyboard (typically by using @e Alt key in
161 combination with it). To insert a literal ampersand character, you need
162 to double it, i.e. use "&&". If this behaviour is undesirable, use
163 SetLabelText() instead.
165 void SetLabel(const wxString
& label
);
168 Sets the control's label to exactly the given string.
170 Unlike SetLabel(), this function shows exactly the @a text passed to it
171 in the control, without interpreting ampersands in it in any way.
172 Notice that it means that the control can't have any mnemonic defined
173 for it using this function.
175 @see EscapeMnemonics()
177 void SetLabelText(const wxString
& text
);
179 // NB: when writing docs for the following function remember that Doxygen
180 // will always expand HTML entities (e.g. ") and thus we need to
181 // write e.g. "&lt;" to have in the output the "<" string.
184 Sets the controls label to a string using markup.
186 Simple markup supported by this function can be used to apply different
187 fonts or colours to different parts of the control label when supported.
188 If markup is not supported by the control or platform, it is simply
189 stripped and SetLabel() is used with the resulting string.
195 text->SetLabelMarkup("<b>&Bed</b> &mp; "
196 "<span foreground='red'>breakfast</span> "
197 "available <big>HERE</big>");
199 would show the string using bold, red and big for the corresponding
200 words under wxGTK but will simply show the string "Bed & breakfast
201 available HERE" on the other platforms. In any case, the "B" of "Bed"
202 will be underlined to indicate that it can be used as a mnemonic for
205 The supported tags are:
209 <TD><b>Description</b></TD>
225 <TD>strike-through text</TD>
228 <TD><small></TD>
229 <TD>smaller text</TD>
233 <TD>monospaced text</TD>
237 <TD>underlined text</TD>
240 <TD><span></TD>
241 <TD>generic formatter tag, see the table below for supported
247 Supported @c <span> attributes:
251 <TD><b>Description</b></TD>
254 <TD>foreground, fgcolor, color</TD>
255 <TD>Foreground text colour, can be a name or RGB value.</TD>
258 <TD>background, bgcolor</TD>
259 <TD>Background text colour, can be a name or RGB value.</TD>
262 <TD>font_family, face</TD>
263 <TD>Font face name.</TD>
266 <TD>font_weight, weight</TD>
267 <TD>Numeric value in 0..900 range or one of "ultralight",
268 "light", "normal" (all meaning non-bold), "bold", "ultrabold"
269 and "heavy" (all meaning bold).</TD>
272 <TD>font_style, style</TD>
273 <TD>Either "oblique" or "italic" (both with the same meaning)
278 <TD>The font size can be specified either as "smaller" or
279 "larger" relatively to the current font, as a CSS font size
280 name ("xx-small", "x-small", "small", "medium", "large",
281 "x-large" or "xx-large") or as a number giving font size in
282 1024th parts of a point, i.e. 10240 for a 10pt font.</TD>
286 This markup language is a strict subset of Pango markup (described at
287 http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html)
288 and any tags and span attributes not documented above can't be used
289 under non-GTK platforms.
291 Also note that you need to escape the following special characters:
294 <TD><b>Special character</b></TD>
295 <TD><b>Escape as</b></TD>
299 <TD>@c &amp; or as @c &&</TD>
303 <TD>@c &apos;</TD>
307 <TD>@c &quot;</TD>
319 The non-escaped ampersand @c & characters are interpreted as
320 mnemonics as with wxControl::SetLabel.
324 String containing markup for the label. It may contain markup tags
325 described above and newline characters but currently only wxGTK and
326 wxOSX support multiline labels with markup, the generic
327 implementation (also used in wxMSW) only handles single line markup
328 labels. Notice that the string must be well-formed (e.g. all tags
329 must be correctly closed) and won't be shown at all otherwise.
331 @true if the new label was set (even if markup in it was ignored)
332 or @false if we failed to parse the markup. In this case the label
336 Currently wxButton supports markup in all major ports (wxMSW, wxGTK and
337 wxOSX/Cocoa) while wxStaticText supports it in wxGTK and wxOSX and its
338 generic version (which can be used under MSW if markup support is
339 required). Extending support to more controls is planned in the future.
343 bool SetLabelMarkup(const wxString
& markup
);
346 public: // static functions
349 Returns the given @a label string without mnemonics ("&" characters).
351 static wxString
GetLabelText(const wxString
& label
);
354 Returns the given @a str string without mnemonics ("&" characters).
356 @note This function is identical to GetLabelText() and is provided
357 mostly for symmetry with EscapeMnemonics().
359 static wxString
RemoveMnemonics(const wxString
& str
);
362 Escapes the special mnemonics characters ("&") in the given string.
364 This function can be helpful if you need to set the controls label to a
365 user-provided string. If the string contains ampersands, they wouldn't
366 appear on the display but be used instead to indicate that the
367 character following the first of them can be used as a control mnemonic.
368 While this can sometimes be desirable (e.g. to allow the user to
369 configure mnemonics of the controls), more often you will want to use
370 this function before passing a user-defined string to SetLabel().
371 Alternatively, if the label is entirely user-defined, you can just call
372 SetLabelText() directly -- but this function must be used if the label
373 is a combination of a part defined by program containing the control
374 mnemonics and a user-defined part.
377 The string such as it should appear on the display.
379 The same string with the ampersands in it doubled.
381 static wxString
EscapeMnemonics(const wxString
& text
);
384 Replaces parts of the @a label string with ellipsis, if needed, so
385 that it fits into @a maxWidth pixels if possible.
387 Note that this function does @em not guarantee that the returned string
388 will always be shorter than @a maxWidth; if @a maxWidth is extremely
389 small, ellipsized text may be larger.
392 The string to ellipsize
394 The DC used to retrieve the character widths through the
395 wxDC::GetPartialTextExtents() function.
397 The ellipsization mode. This is the setting which determines
398 which part of the string should be replaced by the ellipsis.
399 See ::wxEllipsizeMode enumeration values for more info.
401 The maximum width of the returned string in pixels.
402 This argument determines how much characters of the string need to
403 be removed (and replaced by ellipsis).
405 One or more of the ::wxEllipsizeFlags enumeration values combined.
407 static wxString
Ellipsize(const wxString
& label
, const wxDC
& dc
,
408 wxEllipsizeMode mode
, int maxWidth
,
409 int flags
= wxELLIPSIZE_FLAGS_DEFAULT
);