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