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