]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/button.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxButton
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 A button is a control that contains a text string, and is one of the most
13 common elements of a GUI.
15 It may be placed on a @ref wxDialog "dialog box" or on a @ref wxPanel panel,
16 or indeed on almost any other window.
20 Left-justifies the label. Windows and GTK+ only.
22 Aligns the label to the top of the button. Windows and GTK+ only.
24 Right-justifies the bitmap label. Windows and GTK+ only.
26 Aligns the label to the bottom of the button. Windows and GTK+ only.
28 Creates the button as small as possible instead of making it of the
29 standard size (which is the default behaviour ).
31 Creates a flat button. Windows and GTK+ only.
34 @beginEventEmissionTable{wxCommandEvent}
35 @event{EVT_BUTTON(id, func)}
36 Process a wxEVT_COMMAND_BUTTON_CLICKED event, when the button is clicked.
40 Since version 2.9.1 wxButton supports showing both text and an image, see
41 SetBitmap() and SetBitmapLabel(), SetBitmapDisabled() &c methods. In the
42 previous wxWidgets versions this functionality was only available in (the
43 now trivial) wxBitmapButton class which was only capable of showing an
46 A button may have either a single image for all states or different images
47 for the following states:
48 @li @b normal: the default state
49 @li @b disabled: bitmap shown when the button is disabled.
50 @li @b pressed: bitmap shown when the button is pushed (e.g. while the user
51 keeps the mouse button pressed on it)
52 @li @b focus: bitmap shown when the button has keyboard focus (but is not
53 pressed as in this case the button is in the pressed state)
54 @li @b current: bitmap shown when the mouse is over the button (but it is
55 not pressed although it may have focus). Notice that if current bitmap
56 is not specified but the current platform UI uses hover images for the
57 buttons (such as Windows XP or GTK+), then the focus bitmap is used for
58 hover state as well. This makes it possible to set focus bitmap only to
59 get reasonably good behaviour on all platforms.
61 All of the bitmaps must be of the same size and the normal bitmap must be
62 set first (to a valid bitmap), before setting any other ones.
64 The position of the image inside the button be configured using
65 SetBitmapPosition(). By default the image is on the left of the text.
69 @appearance{button.png}
73 class wxButton
: public wxControl
82 Constructor, creating and showing a button.
84 The preferred way to create standard buttons is to use default value of
85 @a label. If no label is supplied and @a id is one of standard IDs from
86 @ref page_stockitems "this list", a standard label will be used.
88 In addition to that, the button will be decorated with stock icons under GTK+ 2.
91 Parent window. Must not be @NULL.
93 Button identifier. A value of wxID_ANY indicates a default value.
95 Text to be displayed on the button.
99 Button size. If the default size is specified then the button is sized
100 appropriately for the text.
102 Window style. See wxButton class description.
108 @see Create(), wxValidator
110 wxButton(wxWindow
* parent
, wxWindowID id
,
111 const wxString
& label
= wxEmptyString
,
112 const wxPoint
& pos
= wxDefaultPosition
,
113 const wxSize
& size
= wxDefaultSize
,
115 const wxValidator
& validator
= wxDefaultValidator
,
116 const wxString
& name
= wxButtonNameStr
);
119 Button creation function for two-step creation.
120 For more details, see wxButton().
122 bool Create(wxWindow
* parent
, wxWindowID id
,
123 const wxString
& label
= wxEmptyString
,
124 const wxPoint
& pos
= wxDefaultPosition
,
125 const wxSize
& size
= wxDefaultSize
,
127 const wxValidator
& validator
= wxDefaultValidator
,
128 const wxString
& name
= wxButtonNameStr
);
131 Return the bitmap shown by the button.
133 The returned bitmap may be invalid only if the button doesn't show any
140 wxBitmap
GetBitmap() const;
143 Returns the bitmap used when the mouse is over the button, which may be
146 @see SetBitmapCurrent()
148 @since 2.9.1 (available as wxBitmapButton::GetBitmapHover() in previous
151 wxBitmap
GetBitmapCurrent() const;
154 Returns the bitmap for the disabled state, which may be invalid.
156 @see SetBitmapDisabled()
158 @since 2.9.1 (available in wxBitmapButton only in previous versions)
160 wxBitmap
GetBitmapDisabled() const;
163 Returns the bitmap for the focused state, which may be invalid.
165 @see SetBitmapFocus()
167 @since 2.9.1 (available in wxBitmapButton only in previous versions)
169 wxBitmap
GetBitmapFocus() const;
172 Returns the bitmap for the normal state.
174 This is exactly the same as GetBitmap() but uses a name
175 backwards-compatible with wxBitmapButton.
177 @see SetBitmap(), SetBitmapLabel()
179 @since 2.9.1 (available in wxBitmapButton only in previous versions)
181 wxBitmap
GetBitmapLabel() const;
184 Returns the bitmap for the pressed state, which may be invalid.
186 @see SetBitmapPressed()
188 @since 2.9.1 (available as wxBitmapButton::GetBitmapSelected() in
191 wxBitmap
GetBitmapPressed() const;
194 Returns the default size for the buttons. It is advised to make all the dialog
195 buttons of the same size and this function allows to retrieve the (platform and
196 current font dependent size) which should be the best suited for this.
198 static wxSize
GetDefaultSize();
201 Returns the string label for the button.
205 wxString
GetLabel() const;
208 Sets the bitmap to display in the button.
210 The bitmap is displayed together with the button label. This method
211 sets up a single bitmap which is used in all button states, use
212 SetBitmapDisabled(), SetBitmapPressed(), SetBitmapCurrent() or
213 SetBitmapFocus() to change the individual images used in different
217 The bitmap to display in the button. May be invalid to remove any
218 currently displayed bitmap.
220 The position of the bitmap inside the button. By default it is
221 positioned to the left of the text, near to the left button border.
222 Other possible values include wxRIGHT, wxTOP and wxBOTTOM.
224 @see SetBitmapPosition(), SetBitmapMargins()
228 void SetBitmap(const wxBitmap
& bitmap
, wxDirection dir
= wxLEFT
);
231 Sets the bitmap to be shown when the mouse is over the button.
233 @see GetBitmapCurrent()
235 @since 2.9.1 (available as wxBitmapButton::SetBitmapHover() in previous
238 void SetBitmapCurrent(const wxBitmap
& bitmap
);
241 Sets the bitmap for the disabled button appearance.
243 @see GetBitmapDisabled(), SetBitmapLabel(),
244 SetBitmapPressed(), SetBitmapFocus()
246 @since 2.9.1 (available in wxBitmapButton only in previous versions)
248 void SetBitmapDisabled(const wxBitmap
& bitmap
);
251 Sets the bitmap for the button appearance when it has the keyboard
254 @see GetBitmapFocus(), SetBitmapLabel(),
255 SetBitmapPressed(), SetBitmapDisabled()
257 @since 2.9.1 (available in wxBitmapButton only in previous versions)
259 void SetBitmapFocus(const wxBitmap
& bitmap
);
262 Sets the bitmap label for the button.
264 @remarks This is the bitmap used for the unselected state, and for all
265 other states if no other bitmaps are provided.
267 @see SetBitmap(), GetBitmapLabel()
269 @since 2.9.1 (available in wxBitmapButton only in previous versions)
271 void SetBitmapLabel(const wxBitmap
& bitmap
);
274 Sets the bitmap for the selected (depressed) button appearance.
276 @since 2.9.1 (available as wxBitmapButton::SetBitmapSelected() in
279 void SetBitmapPressed(const wxBitmap
& bitmap
);
282 Set the margins between the bitmap and the text of the button.
284 This method is currently only implemented under MSW. If it is not
285 called, default margin is used around the bitmap.
287 @see SetBitmap(), SetBitmapPosition()
292 void SetBitmapMargins(wxCoord x
, wxCoord y
);
293 void SetBitmapMargins(const wxSize
& sz
);
297 Set the position at which the bitmap is displayed.
299 This method should only be called if the button does have an associated
305 Direction in which the bitmap should be positioned, one of wxLEFT,
306 wxRIGHT, wxTOP or wxBOTTOM.
308 void SetBitmapPosition(wxDirection dir
);
311 This sets the button to be the default item in its top-level window
312 (e.g. the panel or the dialog box containing it).
314 As normal, pressing return causes the default button to be depressed when
315 the return key is pressed.
317 See also wxWindow::SetFocus() which sets the keyboard focus for windows
318 and text panel items, and wxTopLevelWindow::SetDefaultItem().
320 @remarks Under Windows, only dialog box buttons respond to this function.
322 @return the old default item (possibly NULL)
324 virtual wxWindow
* SetDefault();
327 Sets the string label for the button.
332 void SetLabel(const wxString
& label
);