]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
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 | |
65571936 | 9 | // Licence: wxWindows licence |
1e6feb95 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_BUTTON_H_BASE_ |
13 | #define _WX_BUTTON_H_BASE_ | |
c801d85f | 14 | |
997176a3 VZ |
15 | #include "wx/defs.h" |
16 | ||
7ef8bfc4 | 17 | // ---------------------------------------------------------------------------- |
0b4f47a3 | 18 | // wxButton flags shared with other classes |
7ef8bfc4 VZ |
19 | // ---------------------------------------------------------------------------- |
20 | ||
0b4f47a3 | 21 | #if wxUSE_TOGGLEBTN || wxUSE_BUTTON |
7ccb2521 VZ |
22 | |
23 | // These flags affect label alignment | |
7ef8bfc4 VZ |
24 | #define wxBU_LEFT 0x0040 |
25 | #define wxBU_TOP 0x0080 | |
26 | #define wxBU_RIGHT 0x0100 | |
27 | #define wxBU_BOTTOM 0x0200 | |
041ae202 | 28 | #define wxBU_ALIGN_MASK ( wxBU_LEFT | wxBU_TOP | wxBU_RIGHT | wxBU_BOTTOM ) |
0b4f47a3 DS |
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 | ||
7ef8bfc4 VZ |
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 | ||
81cb7b5a | 46 | #include "wx/bitmap.h" |
1e6feb95 VZ |
47 | #include "wx/control.h" |
48 | ||
53a2db12 | 49 | extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[]; |
1e6feb95 VZ |
50 | |
51 | // ---------------------------------------------------------------------------- | |
52 | // wxButton: a push button | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
53a2db12 | 55 | class WXDLLIMPEXP_CORE wxButtonBase : public wxControl |
1e6feb95 VZ |
56 | { |
57 | public: | |
6463b9f5 | 58 | wxButtonBase() { } |
fc7a2a60 | 59 | |
2352862a VZ |
60 | // show the image in the button in addition to the label: this method is |
61 | // supported on all (major) platforms | |
62 | void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT) | |
63 | { | |
64 | SetBitmapLabel(bitmap); | |
65 | SetBitmapPosition(dir); | |
66 | } | |
67 | ||
68 | wxBitmap GetBitmap() const { return DoGetBitmap(State_Normal); } | |
69 | ||
70 | // Methods for setting individual images for different states: normal, | |
71 | // selected (meaning pushed or pressed), focused (meaning normal state for | |
72 | // a focused button), disabled or hover (a.k.a. hot or current). | |
73 | // | |
74 | // Remember that SetBitmap() itself must be called before any other | |
75 | // SetBitmapXXX() methods (except for SetBitmapLabel() which is a synonym | |
76 | // for it anyhow) and that all bitmaps passed to these functions should be | |
77 | // of the same size. | |
78 | void SetBitmapLabel(const wxBitmap& bitmap) | |
79 | { DoSetBitmap(bitmap, State_Normal); } | |
80 | void SetBitmapPressed(const wxBitmap& bitmap) | |
81 | { DoSetBitmap(bitmap, State_Pressed); } | |
82 | void SetBitmapDisabled(const wxBitmap& bitmap) | |
83 | { DoSetBitmap(bitmap, State_Disabled); } | |
84 | void SetBitmapCurrent(const wxBitmap& bitmap) | |
85 | { DoSetBitmap(bitmap, State_Current); } | |
86 | void SetBitmapFocus(const wxBitmap& bitmap) | |
87 | { DoSetBitmap(bitmap, State_Focused); } | |
88 | ||
89 | wxBitmap GetBitmapLabel() const { return DoGetBitmap(State_Normal); } | |
90 | wxBitmap GetBitmapPressed() const { return DoGetBitmap(State_Pressed); } | |
91 | wxBitmap GetBitmapDisabled() const { return DoGetBitmap(State_Disabled); } | |
92 | wxBitmap GetBitmapCurrent() const { return DoGetBitmap(State_Current); } | |
93 | wxBitmap GetBitmapFocus() const { return DoGetBitmap(State_Focused); } | |
94 | ||
1e6feb95 VZ |
95 | |
96 | // set the margins around the image | |
2352862a VZ |
97 | void SetBitmapMargins(wxCoord x, wxCoord y) { DoSetBitmapMargins(x, y); } |
98 | void SetBitmapMargins(const wxSize& sz) { DoSetBitmapMargins(sz.x, sz.y); } | |
99 | ||
100 | // set the image position relative to the text, i.e. wxLEFT means that the | |
101 | // image is to the left of the text (this is the default) | |
233f10bf | 102 | void SetBitmapPosition(wxDirection dir); |
2352862a | 103 | |
1e6feb95 | 104 | |
94aff5ff VZ |
105 | // make this button the default button in its top level window |
106 | // | |
107 | // returns the old default item (possibly NULL) | |
108 | virtual wxWindow *SetDefault(); | |
1e6feb95 | 109 | |
e8e24dfa RD |
110 | // Buttons on MSW can look bad if they are not native colours, because |
111 | // then they become owner-drawn and not theme-drawn. Disable it here | |
112 | // in wxButtonBase to make it consistent. | |
113 | virtual bool ShouldInheritColours() const { return false; } | |
114 | ||
1e6feb95 VZ |
115 | // returns the default button size for this platform |
116 | static wxSize GetDefaultSize(); | |
fc7a2a60 | 117 | |
2352862a VZ |
118 | // wxUniv-compatible and deprecated equivalents to SetBitmapXXX() |
119 | #if WXWIN_COMPATIBILITY_2_8 | |
120 | void SetImageLabel(const wxBitmap& bitmap) { SetBitmap(bitmap); } | |
121 | void SetImageMargins(wxCoord x, wxCoord y) { SetBitmapMargins(x, y); } | |
122 | #endif // WXWIN_COMPATIBILITY_2_8 | |
123 | ||
124 | // backwards compatible names for pressed/current bitmaps: they're not | |
125 | // deprecated as there is nothing really wrong with using them and no real | |
126 | // advantage to using the new names but the new names are still preferred | |
127 | wxBitmap GetBitmapSelected() const { return GetBitmapPressed(); } | |
128 | wxBitmap GetBitmapHover() const { return GetBitmapCurrent(); } | |
129 | ||
130 | void SetBitmapSelected(const wxBitmap& bitmap) { SetBitmapPressed(bitmap); } | |
131 | void SetBitmapHover(const wxBitmap& bitmap) { SetBitmapCurrent(bitmap); } | |
132 | ||
dc797d8e | 133 | |
233f10bf VZ |
134 | // this enum is not part of wx public API, it is public because it is used |
135 | // in non wxButton-derived classes internally | |
136 | // | |
137 | // also notice that MSW code relies on the values of the enum elements, do | |
138 | // not change them without revising src/msw/button.cpp | |
2352862a VZ |
139 | enum State |
140 | { | |
141 | State_Normal, | |
2352862a | 142 | State_Current, // a.k.a. hot or "hovering" |
233f10bf | 143 | State_Pressed, // a.k.a. "selected" in public API for some reason |
2352862a VZ |
144 | State_Disabled, |
145 | State_Focused, | |
146 | State_Max | |
147 | }; | |
148 | ||
233f10bf VZ |
149 | protected: |
150 | // choose the default border for this window | |
151 | virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } | |
152 | ||
2352862a VZ |
153 | virtual wxBitmap DoGetBitmap(State WXUNUSED(which)) const |
154 | { return wxBitmap(); } | |
155 | virtual void DoSetBitmap(const wxBitmap& WXUNUSED(bitmap), | |
156 | State WXUNUSED(which)) | |
157 | { } | |
158 | virtual void DoSetBitmapMargins(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) | |
159 | { } | |
233f10bf VZ |
160 | virtual void DoSetBitmapPosition(wxDirection WXUNUSED(dir)) |
161 | { } | |
2352862a VZ |
162 | |
163 | ||
c0c133e1 | 164 | wxDECLARE_NO_COPY_CLASS(wxButtonBase); |
1e6feb95 VZ |
165 | }; |
166 | ||
167 | #if defined(__WXUNIVERSAL__) | |
168 | #include "wx/univ/button.h" | |
169 | #elif defined(__WXMSW__) | |
170 | #include "wx/msw/button.h" | |
2049ba38 | 171 | #elif defined(__WXMOTIF__) |
1e6feb95 | 172 | #include "wx/motif/button.h" |
1be7a35c | 173 | #elif defined(__WXGTK20__) |
1e6feb95 | 174 | #include "wx/gtk/button.h" |
1be7a35c MR |
175 | #elif defined(__WXGTK__) |
176 | #include "wx/gtk1/button.h" | |
34138703 | 177 | #elif defined(__WXMAC__) |
ef0e9220 | 178 | #include "wx/osx/button.h" |
e64df9bc DE |
179 | #elif defined(__WXCOCOA__) |
180 | #include "wx/cocoa/button.h" | |
1777b9bb | 181 | #elif defined(__WXPM__) |
1e6feb95 | 182 | #include "wx/os2/button.h" |
db101bd3 WS |
183 | #elif defined(__WXPALMOS__) |
184 | #include "wx/palmos/button.h" | |
c801d85f KB |
185 | #endif |
186 | ||
1e6feb95 VZ |
187 | #endif // wxUSE_BUTTON |
188 | ||
c801d85f | 189 | #endif |
34138703 | 190 | // _WX_BUTTON_H_BASE_ |