]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/control.h
Override default handling so that we can position windows off-screen like on other...
[wxWidgets.git] / interface / wx / control.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.h
3 // Purpose: interface of wxControl
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 Flags used by wxControl::Ellipsize function.
11 */
12 enum wxEllipsizeFlags
13 {
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,
37
38 /// The default flags for wxControl::Ellipsize.
39 wxELLIPSIZE_FLAGS_DEFAULT = wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS|
40 wxELLIPSIZE_FLAGS_EXPAND_TABS
41 };
42
43
44 /**
45 The different ellipsization modes supported by the
46 wxControl::Ellipsize function.
47 */
48 enum wxEllipsizeMode
49 {
50 /// Don't ellipsize the text at all. @since 2.9.1
51 wxELLIPSIZE_NONE,
52
53 /// Put the ellipsis at the start of the string, if the string needs ellipsization.
54 wxELLIPSIZE_START,
55
56 /// Put the ellipsis in the middle of the string, if the string needs ellipsization.
57 wxELLIPSIZE_MIDDLE,
58
59 /// Put the ellipsis at the end of the string, if the string needs ellipsization.
60 wxELLIPSIZE_END
61 };
62
63 /**
64 @class wxControl
65
66 This is the base class for a control or "widget".
67
68 A control is generally a small window which processes user input and/or
69 displays one or more item of data.
70
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
81 @library{wxcore}
82 @category{ctrl}
83
84 @see wxValidator
85 */
86 class wxControl : public wxWindow
87 {
88 public:
89 /**
90 Simulates the effect of the user issuing a command to the item.
91
92 @see wxCommandEvent
93 */
94 virtual void Command(wxCommandEvent& event);
95
96 /**
97 Replaces parts of the @a label string with ellipsis, if needed, so
98 that it doesn't exceed @a maxWidth.
99
100 @param label
101 The string to ellipsize
102 @param dc
103 The DC used to retrieve the character widths through the
104 wxDC::GetPartialTextExtents() function.
105 @param mode
106 The ellipsization modes. See ::wxEllipsizeMode.
107 @param maxWidth
108 The maximum width of the returned string in pixels.
109 @param flags
110 One or more of the ::wxEllipsize
111 */
112 static wxString Ellipsize(const wxString& label, const wxDC& dc,
113 wxEllipsizeMode mode, int maxWidth,
114 int flags = wxELLIPSIZE_FLAGS_DEFAULT);
115
116 /**
117 Returns the control's text.
118
119 @note The returned string contains mnemonics ("&" characters) if it has
120 any, use GetLabelText() if they are undesired.
121 */
122 wxString GetLabel() const;
123
124 /**
125 Returns the control's label without mnemonics.
126 */
127 wxString GetLabelText() const;
128
129 /**
130 Returns the given @a label string without mnemonics ("&" characters).
131 */
132 static wxString GetLabelText(const wxString& label);
133
134 /**
135 Removes the mnemonics ("&" characters) from the given string.
136 */
137 static wxString RemoveMnemonics(const wxString& str);
138
139 /**
140 Escape the special mnemonics characters ("&") in the given string.
141
142 This function can be helpful if you need to set the controls label to a
143 user-provided string. If the string contains ampersands, they wouldn't
144 appear on the display but be used instead to indicate that the
145 character following the first of them can be used as a control mnemonic.
146 While this can sometimes be desirable (e.g. to allow the user to
147 configure mnemonics of the controls), more often you will want to use
148 this function before passing a user-defined string to SetLabel().
149 Alternatively, if the label is entirely user-defined, you can just call
150 SetLabelText() directly -- but this function must be used if the label
151 is a combination of a part defined by program containing the control
152 mnemonics and a user-defined part.
153
154 @param text
155 The string such as it should appear on the display.
156 @return
157 The same string with the ampersands in it doubled.
158 */
159 static wxString EscapeMnemonics(const wxString& text);
160
161 /**
162 Sets the item's text.
163
164 Any "&" characters in the @a label are special and indicate that the
165 following character is a @e mnemonic for this control and can be used to
166 activate it from the keyboard (typically by using @e Alt key in
167 combination with it). To insert a literal ampersand character, you need
168 to double it, i.e. use use "&&". If this behaviour is undesirable, use
169 SetLabelText() instead.
170 */
171 void SetLabel(const wxString& label);
172
173 /**
174 Sets the item's text to exactly the given string.
175
176 Unlike SetLabel(), this function shows exactly the @a text passed to it
177 in the control, without interpreting ampersands in it in any way.
178 Notice that it means that the control can't have any mnemonic defined
179 for it using this function.
180
181 @see EscapeMnemonics()
182 */
183 void SetLabelText(const wxString& text);
184 };
185