Add support for showing "elevation" icon in wxMSW buttons.
[wxWidgets.git] / include / wx / button.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/button.h
3 // Purpose: wxButtonBase class
4 // Author: Vadim Zetlin
5 // Modified by:
6 // Created: 15.08.00
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zetlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BUTTON_H_BASE_
13 #define _WX_BUTTON_H_BASE_
14
15 #include "wx/defs.h"
16
17 // ----------------------------------------------------------------------------
18 // wxButton flags shared with other classes
19 // ----------------------------------------------------------------------------
20
21 #if wxUSE_TOGGLEBTN || wxUSE_BUTTON
22
23 // These flags affect label alignment
24 #define wxBU_LEFT 0x0040
25 #define wxBU_TOP 0x0080
26 #define wxBU_RIGHT 0x0100
27 #define wxBU_BOTTOM 0x0200
28 #define wxBU_ALIGN_MASK ( wxBU_LEFT | wxBU_TOP | wxBU_RIGHT | wxBU_BOTTOM )
29 #endif
30
31 #if wxUSE_BUTTON
32
33 // ----------------------------------------------------------------------------
34 // wxButton specific flags
35 // ----------------------------------------------------------------------------
36
37 // These two flags are obsolete
38 #define wxBU_NOAUTODRAW 0x0000
39 #define wxBU_AUTODRAW 0x0004
40
41 // by default, the buttons will be created with some (system dependent)
42 // minimal size to make them look nicer, giving this style will make them as
43 // small as possible
44 #define wxBU_EXACTFIT 0x0001
45
46 // this flag can be used to disable using the text label in the button: it is
47 // mostly useful when creating buttons showing bitmap and having stock id as
48 // without it both the standard label corresponding to the stock id and the
49 // bitmap would be shown
50 #define wxBU_NOTEXT 0x0002
51
52
53 #include "wx/bitmap.h"
54 #include "wx/control.h"
55
56 extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
57
58 // ----------------------------------------------------------------------------
59 // wxButton: a push button
60 // ----------------------------------------------------------------------------
61
62 class WXDLLIMPEXP_CORE wxButtonBase : public wxControl
63 {
64 public:
65 wxButtonBase() { }
66
67 // show the authentication needed symbol on the button: this is currently
68 // only implemented on Windows Vista and newer (on which it shows the UAC
69 // shield symbol)
70 void SetAuthNeeded(bool show = true) { DoSetAuthNeeded(show); }
71 bool GetAuthNeeded() const { return DoGetAuthNeeded(); }
72
73 // show the image in the button in addition to the label: this method is
74 // supported on all (major) platforms
75 void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT)
76 {
77 SetBitmapLabel(bitmap);
78 SetBitmapPosition(dir);
79 }
80
81 wxBitmap GetBitmap() const { return DoGetBitmap(State_Normal); }
82
83 // Methods for setting individual images for different states: normal,
84 // selected (meaning pushed or pressed), focused (meaning normal state for
85 // a focused button), disabled or hover (a.k.a. hot or current).
86 //
87 // Remember that SetBitmap() itself must be called before any other
88 // SetBitmapXXX() methods (except for SetBitmapLabel() which is a synonym
89 // for it anyhow) and that all bitmaps passed to these functions should be
90 // of the same size.
91 void SetBitmapLabel(const wxBitmap& bitmap)
92 { DoSetBitmap(bitmap, State_Normal); }
93 void SetBitmapPressed(const wxBitmap& bitmap)
94 { DoSetBitmap(bitmap, State_Pressed); }
95 void SetBitmapDisabled(const wxBitmap& bitmap)
96 { DoSetBitmap(bitmap, State_Disabled); }
97 void SetBitmapCurrent(const wxBitmap& bitmap)
98 { DoSetBitmap(bitmap, State_Current); }
99 void SetBitmapFocus(const wxBitmap& bitmap)
100 { DoSetBitmap(bitmap, State_Focused); }
101
102 wxBitmap GetBitmapLabel() const { return DoGetBitmap(State_Normal); }
103 wxBitmap GetBitmapPressed() const { return DoGetBitmap(State_Pressed); }
104 wxBitmap GetBitmapDisabled() const { return DoGetBitmap(State_Disabled); }
105 wxBitmap GetBitmapCurrent() const { return DoGetBitmap(State_Current); }
106 wxBitmap GetBitmapFocus() const { return DoGetBitmap(State_Focused); }
107
108
109 // set the margins around the image
110 void SetBitmapMargins(wxCoord x, wxCoord y) { DoSetBitmapMargins(x, y); }
111 void SetBitmapMargins(const wxSize& sz) { DoSetBitmapMargins(sz.x, sz.y); }
112
113 // set the image position relative to the text, i.e. wxLEFT means that the
114 // image is to the left of the text (this is the default)
115 void SetBitmapPosition(wxDirection dir);
116
117
118 // make this button the default button in its top level window
119 //
120 // returns the old default item (possibly NULL)
121 virtual wxWindow *SetDefault();
122
123 // Buttons on MSW can look bad if they are not native colours, because
124 // then they become owner-drawn and not theme-drawn. Disable it here
125 // in wxButtonBase to make it consistent.
126 virtual bool ShouldInheritColours() const { return false; }
127
128 // returns the default button size for this platform
129 static wxSize GetDefaultSize();
130
131 // wxUniv-compatible and deprecated equivalents to SetBitmapXXX()
132 #if WXWIN_COMPATIBILITY_2_8
133 void SetImageLabel(const wxBitmap& bitmap) { SetBitmap(bitmap); }
134 void SetImageMargins(wxCoord x, wxCoord y) { SetBitmapMargins(x, y); }
135 #endif // WXWIN_COMPATIBILITY_2_8
136
137 // backwards compatible names for pressed/current bitmaps: they're not
138 // deprecated as there is nothing really wrong with using them and no real
139 // advantage to using the new names but the new names are still preferred
140 wxBitmap GetBitmapSelected() const { return GetBitmapPressed(); }
141 wxBitmap GetBitmapHover() const { return GetBitmapCurrent(); }
142
143 void SetBitmapSelected(const wxBitmap& bitmap) { SetBitmapPressed(bitmap); }
144 void SetBitmapHover(const wxBitmap& bitmap) { SetBitmapCurrent(bitmap); }
145
146
147 // this enum is not part of wx public API, it is public because it is used
148 // in non wxButton-derived classes internally
149 //
150 // also notice that MSW code relies on the values of the enum elements, do
151 // not change them without revising src/msw/button.cpp
152 enum State
153 {
154 State_Normal,
155 State_Current, // a.k.a. hot or "hovering"
156 State_Pressed, // a.k.a. "selected" in public API for some reason
157 State_Disabled,
158 State_Focused,
159 State_Max
160 };
161
162 // return true if this button shouldn't show the text label, either because
163 // it doesn't have it or because it was explicitly disabled with wxBU_NOTEXT
164 bool DontShowLabel() const
165 {
166 return HasFlag(wxBU_NOTEXT) || GetLabel().empty();
167 }
168
169 // return true if we do show the label
170 bool ShowsLabel() const
171 {
172 return !DontShowLabel();
173 }
174
175 protected:
176 // choose the default border for this window
177 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
178
179 virtual bool DoGetAuthNeeded() const { return false; }
180 virtual void DoSetAuthNeeded(bool WXUNUSED(show)) { }
181
182 virtual wxBitmap DoGetBitmap(State WXUNUSED(which)) const
183 { return wxBitmap(); }
184 virtual void DoSetBitmap(const wxBitmap& WXUNUSED(bitmap),
185 State WXUNUSED(which))
186 { }
187
188 virtual wxSize DoGetBitmapMargins() const
189 { return wxSize(0, 0); }
190
191 virtual void DoSetBitmapMargins(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
192 { }
193
194 virtual void DoSetBitmapPosition(wxDirection WXUNUSED(dir))
195 { }
196
197
198 wxDECLARE_NO_COPY_CLASS(wxButtonBase);
199 };
200
201 #if defined(__WXUNIVERSAL__)
202 #include "wx/univ/button.h"
203 #elif defined(__WXMSW__)
204 #include "wx/msw/button.h"
205 #elif defined(__WXMOTIF__)
206 #include "wx/motif/button.h"
207 #elif defined(__WXGTK20__)
208 #include "wx/gtk/button.h"
209 #elif defined(__WXGTK__)
210 #include "wx/gtk1/button.h"
211 #elif defined(__WXMAC__)
212 #include "wx/osx/button.h"
213 #elif defined(__WXCOCOA__)
214 #include "wx/cocoa/button.h"
215 #elif defined(__WXPM__)
216 #include "wx/os2/button.h"
217 #elif defined(__WXPALMOS__)
218 #include "wx/palmos/button.h"
219 #endif
220
221 #endif // wxUSE_BUTTON
222
223 #endif
224 // _WX_BUTTON_H_BASE_