]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/button.h
wiring osx native notification during launch
[wxWidgets.git] / interface / wx / button.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.h
e54c96f1 3// Purpose: interface of wxButton
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
8ff9b17d 9
23324ae1
FM
10/**
11 @class wxButton
7c913512 12
8024723d
FM
13 A button is a control that contains a text string, and is one of the most
14 common elements of a GUI.
15
16 It may be placed on a @ref wxDialog "dialog box" or on a @ref wxPanel panel,
17 or indeed on almost any other window.
7c913512 18
0f5fe332
VZ
19 By default, i.e. if none of the alignment styles are specified, the label
20 is centered both horizontally and vertically. If the button has both a
21 label and a bitmap, the alignment styles above specify the location of the
22 rectangle combining both the label and the bitmap and the bitmap position
23 set with wxButton::SetBitmapPosition() defines the relative position of the
24 bitmap with respect to the label (however currently non-default alignment
25 combinations are not implemented on all platforms).
26
e5d05b90
VZ
27 Since version 2.9.1 wxButton supports showing both text and an image
28 (currently only when using wxMSW, wxGTK or wxOSX/Cocoa ports), see
2352862a
VZ
29 SetBitmap() and SetBitmapLabel(), SetBitmapDisabled() &c methods. In the
30 previous wxWidgets versions this functionality was only available in (the
31 now trivial) wxBitmapButton class which was only capable of showing an
32 image without text.
33
34 A button may have either a single image for all states or different images
e5d05b90
VZ
35 for the following states (different images are not currently supported
36 under OS X where the normal image is used for all states):
2352862a
VZ
37 @li @b normal: the default state
38 @li @b disabled: bitmap shown when the button is disabled.
39 @li @b pressed: bitmap shown when the button is pushed (e.g. while the user
40 keeps the mouse button pressed on it)
41 @li @b focus: bitmap shown when the button has keyboard focus (but is not
42 pressed as in this case the button is in the pressed state)
43 @li @b current: bitmap shown when the mouse is over the button (but it is
44 not pressed although it may have focus). Notice that if current bitmap
45 is not specified but the current platform UI uses hover images for the
46 buttons (such as Windows XP or GTK+), then the focus bitmap is used for
47 hover state as well. This makes it possible to set focus bitmap only to
48 get reasonably good behaviour on all platforms.
49
50 All of the bitmaps must be of the same size and the normal bitmap must be
ce39ca74
VZ
51 set first (to a valid bitmap), before setting any other ones. Also, if the
52 size of the bitmaps is changed later, you need to change the size of the
53 normal bitmap before setting any other bitmaps with the new size (and you
54 do need to reset all of them as their original values can be lost when the
55 normal bitmap size changes).
2352862a
VZ
56
57 The position of the image inside the button be configured using
58 SetBitmapPosition(). By default the image is on the left of the text.
59
ef74fc64
FM
60 Please also notice that GTK+ uses a global setting called @c gtk-button-images
61 to determine if the images should be shown in the buttons
b3f5fbf6
VZ
62 at all. If it is off (which is the case in e.g. Gnome 2.28 by default), no
63 images will be shown, consistently with the native behaviour.
64
ef74fc64
FM
65 @beginStyleTable
66 @style{wxBU_LEFT}
67 Left-justifies the label. Windows and GTK+ only.
68 @style{wxBU_TOP}
69 Aligns the label to the top of the button. Windows and GTK+ only.
70 @style{wxBU_RIGHT}
71 Right-justifies the bitmap label. Windows and GTK+ only.
72 @style{wxBU_BOTTOM}
73 Aligns the label to the bottom of the button. Windows and GTK+ only.
74 @style{wxBU_EXACTFIT}
f2f18548
VZ
75 By default, all buttons are made of at least the standard button size,
76 even if their contents is small enough to fit into a smaller size. This
77 is done for consistency as most platforms use buttons of the same size
78 in the native dialogs, but can be overridden by specifying this flag.
79 If it is given, the button will be made just big enough for its
80 contents. Notice that under MSW the button will still have at least the
81 standard height, even with this style, if it has a non-empty label.
ef74fc64
FM
82 @style{wxBU_NOTEXT}
83 Disables the display of the text label in the button even if it has one
84 or its id is one of the standard stock ids with an associated label:
85 without using this style a button which is only supposed to show a
86 bitmap but uses a standard id would display a label too.
87 @style{wxBORDER_NONE}
88 Creates a button without border. This is currently implemented in MSW,
419b2003
VZ
89 GTK2 and OSX/Cocoa and OSX/Carbon ports but in the latter only applies
90 to buttons with bitmaps and using bitmap of one of the standard sizes
91 only, namely 128*128, 48*48, 24*24 or 16*16. In all the other cases
92 wxBORDER_NONE is ignored under OSX/Carbon (these restrictions don't
93 exist in OSX/Cocoa however).
ef74fc64
FM
94 @endStyleTable
95
96 @beginEventEmissionTable{wxCommandEvent}
97 @event{EVT_BUTTON(id, func)}
ce7fe42e 98 Process a @c wxEVT_BUTTON event, when the button is clicked.
ef74fc64
FM
99 @endEventTable
100
23324ae1
FM
101 @library{wxcore}
102 @category{ctrl}
ce154616 103 @appearance{button}
7c913512 104
e54c96f1 105 @see wxBitmapButton
23324ae1 106*/
884a3e9d 107class wxButton : public wxAnyButton
23324ae1
FM
108{
109public:
8024723d
FM
110 /**
111 Default ctor.
112 */
113 wxButton();
114
23324ae1
FM
115 /**
116 Constructor, creating and showing a button.
8024723d 117
23324ae1 118 The preferred way to create standard buttons is to use default value of
8024723d 119 @a label. If no label is supplied and @a id is one of standard IDs from
01495abf
VZ
120 @ref page_stockitems "this list", a standard label will be used. In
121 other words, if you use a predefined @c wxID_XXX constant, just omit
122 the label completely rather than specifying it. In particular, help
123 buttons (the ones with @a id of @c wxID_HELP) under Mac OS X can't
124 display any label at all and while wxButton will detect if the standard
125 "Help" label is used and ignore it, using any other label will prevent
126 the button from correctly appearing as a help button and so should be
127 avoided.
128
8024723d
FM
129
130 In addition to that, the button will be decorated with stock icons under GTK+ 2.
131
7c913512 132 @param parent
4cc4bfaf 133 Parent window. Must not be @NULL.
7c913512 134 @param id
ef74fc64 135 Button identifier. A value of @c wxID_ANY indicates a default value.
7c913512 136 @param label
4cc4bfaf 137 Text to be displayed on the button.
7c913512 138 @param pos
4cc4bfaf 139 Button position.
7c913512 140 @param size
4cc4bfaf
FM
141 Button size. If the default size is specified then the button is sized
142 appropriately for the text.
7c913512 143 @param style
8024723d 144 Window style. See wxButton class description.
7c913512 145 @param validator
4cc4bfaf 146 Window validator.
7c913512 147 @param name
4cc4bfaf 148 Window name.
8024723d 149
4cc4bfaf 150 @see Create(), wxValidator
23324ae1 151 */
7c913512
FM
152 wxButton(wxWindow* parent, wxWindowID id,
153 const wxString& label = wxEmptyString,
154 const wxPoint& pos = wxDefaultPosition,
155 const wxSize& size = wxDefaultSize,
156 long style = 0,
157 const wxValidator& validator = wxDefaultValidator,
a6052817 158 const wxString& name = wxButtonNameStr);
23324ae1 159
23324ae1 160 /**
8024723d
FM
161 Button creation function for two-step creation.
162 For more details, see wxButton().
23324ae1
FM
163 */
164 bool Create(wxWindow* parent, wxWindowID id,
165 const wxString& label = wxEmptyString,
166 const wxPoint& pos = wxDefaultPosition,
167 const wxSize& size = wxDefaultSize,
168 long style = 0,
a6052817
FM
169 const wxValidator& validator = wxDefaultValidator,
170 const wxString& name = wxButtonNameStr);
23324ae1 171
f2d7fdf7
VZ
172 /**
173 Returns @true if an authentication needed symbol is displayed on the
174 button.
175
176 @remarks This method always returns @false if the platform is not
177 Windows Vista or newer.
178
179 @see SetAuthNeeded()
180
181 @since 2.9.1
182 */
183 bool GetAuthNeeded() const;
184
1404c3f3 185
23324ae1
FM
186 /**
187 Returns the default size for the buttons. It is advised to make all the dialog
188 buttons of the same size and this function allows to retrieve the (platform and
189 current font dependent size) which should be the best suited for this.
190 */
d2aa927a 191 static wxSize GetDefaultSize();
23324ae1
FM
192
193 /**
194 Returns the string label for the button.
8024723d 195
4cc4bfaf 196 @see SetLabel()
23324ae1 197 */
328f5751 198 wxString GetLabel() const;
23324ae1 199
f2d7fdf7
VZ
200 /**
201 Sets whether an authentication needed symbol should be displayed on the
202 button.
203
204 @remarks This method doesn't do anything if the platform is not Windows
205 Vista or newer.
206
207 @see GetAuthNeeded()
208
209 @since 2.9.1
210 */
211 void SetAuthNeeded(bool needed = true);
212
2352862a 213
23324ae1 214 /**
2fd0ada5
FM
215 This sets the button to be the default item in its top-level window
216 (e.g. the panel or the dialog box containing it).
8024723d
FM
217
218 As normal, pressing return causes the default button to be depressed when
219 the return key is pressed.
220
221 See also wxWindow::SetFocus() which sets the keyboard focus for windows
222 and text panel items, and wxTopLevelWindow::SetDefaultItem().
223
23324ae1 224 @remarks Under Windows, only dialog box buttons respond to this function.
2fd0ada5 225
ef74fc64 226 @return the old default item (possibly @NULL)
23324ae1 227 */
2fd0ada5 228 virtual wxWindow* SetDefault();
23324ae1
FM
229
230 /**
231 Sets the string label for the button.
8024723d 232
7c913512 233 @param label
4cc4bfaf 234 The label to set.
23324ae1
FM
235 */
236 void SetLabel(const wxString& label);
237};
e54c96f1 238