preparation work for implementing images support in wxButton: move wxBitmapButton...
[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 #include "wx/control.h"
47
48 class WXDLLIMPEXP_FWD_CORE wxBitmap;
49
50 extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
51
52 // ----------------------------------------------------------------------------
53 // wxButton: a push button
54 // ----------------------------------------------------------------------------
55
56 class WXDLLIMPEXP_CORE wxButtonBase : public wxControl
57 {
58 public:
59 wxButtonBase() { }
60
61 // show the image in the button in addition to the label: this method is
62 // supported on all (major) platforms
63 void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT)
64 {
65 SetBitmapLabel(bitmap);
66 SetBitmapPosition(dir);
67 }
68
69 wxBitmap GetBitmap() const { return DoGetBitmap(State_Normal); }
70
71 // Methods for setting individual images for different states: normal,
72 // selected (meaning pushed or pressed), focused (meaning normal state for
73 // a focused button), disabled or hover (a.k.a. hot or current).
74 //
75 // Remember that SetBitmap() itself must be called before any other
76 // SetBitmapXXX() methods (except for SetBitmapLabel() which is a synonym
77 // for it anyhow) and that all bitmaps passed to these functions should be
78 // of the same size.
79 void SetBitmapLabel(const wxBitmap& bitmap)
80 { DoSetBitmap(bitmap, State_Normal); }
81 void SetBitmapPressed(const wxBitmap& bitmap)
82 { DoSetBitmap(bitmap, State_Pressed); }
83 void SetBitmapDisabled(const wxBitmap& bitmap)
84 { DoSetBitmap(bitmap, State_Disabled); }
85 void SetBitmapCurrent(const wxBitmap& bitmap)
86 { DoSetBitmap(bitmap, State_Current); }
87 void SetBitmapFocus(const wxBitmap& bitmap)
88 { DoSetBitmap(bitmap, State_Focused); }
89
90 wxBitmap GetBitmapLabel() const { return DoGetBitmap(State_Normal); }
91 wxBitmap GetBitmapPressed() const { return DoGetBitmap(State_Pressed); }
92 wxBitmap GetBitmapDisabled() const { return DoGetBitmap(State_Disabled); }
93 wxBitmap GetBitmapCurrent() const { return DoGetBitmap(State_Current); }
94 wxBitmap GetBitmapFocus() const { return DoGetBitmap(State_Focused); }
95
96
97 // set the margins around the image
98 void SetBitmapMargins(wxCoord x, wxCoord y) { DoSetBitmapMargins(x, y); }
99 void SetBitmapMargins(const wxSize& sz) { DoSetBitmapMargins(sz.x, sz.y); }
100
101 // set the image position relative to the text, i.e. wxLEFT means that the
102 // image is to the left of the text (this is the default)
103 virtual void SetBitmapPosition(wxDirection WXUNUSED(dir)) { }
104
105
106 // make this button the default button in its top level window
107 //
108 // returns the old default item (possibly NULL)
109 virtual wxWindow *SetDefault();
110
111 // Buttons on MSW can look bad if they are not native colours, because
112 // then they become owner-drawn and not theme-drawn. Disable it here
113 // in wxButtonBase to make it consistent.
114 virtual bool ShouldInheritColours() const { return false; }
115
116 // returns the default button size for this platform
117 static wxSize GetDefaultSize();
118
119 // wxUniv-compatible and deprecated equivalents to SetBitmapXXX()
120 #if WXWIN_COMPATIBILITY_2_8
121 void SetImageLabel(const wxBitmap& bitmap) { SetBitmap(bitmap); }
122 void SetImageMargins(wxCoord x, wxCoord y) { SetBitmapMargins(x, y); }
123 #endif // WXWIN_COMPATIBILITY_2_8
124
125 // backwards compatible names for pressed/current bitmaps: they're not
126 // deprecated as there is nothing really wrong with using them and no real
127 // advantage to using the new names but the new names are still preferred
128 wxBitmap GetBitmapSelected() const { return GetBitmapPressed(); }
129 wxBitmap GetBitmapHover() const { return GetBitmapCurrent(); }
130
131 void SetBitmapSelected(const wxBitmap& bitmap) { SetBitmapPressed(bitmap); }
132 void SetBitmapHover(const wxBitmap& bitmap) { SetBitmapCurrent(bitmap); }
133
134 protected:
135 // choose the default border for this window
136 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
137
138 enum State
139 {
140 State_Normal,
141 State_Pressed, // a.k.a. "selected" in public API for some reason
142 State_Current, // a.k.a. hot or "hovering"
143 State_Disabled,
144 State_Focused,
145 State_Max
146 };
147
148 virtual wxBitmap DoGetBitmap(State WXUNUSED(which)) const
149 { return wxBitmap(); }
150 virtual void DoSetBitmap(const wxBitmap& WXUNUSED(bitmap),
151 State WXUNUSED(which))
152 { }
153 virtual void DoSetBitmapMargins(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
154 { }
155
156
157 wxDECLARE_NO_COPY_CLASS(wxButtonBase);
158 };
159
160 #if defined(__WXUNIVERSAL__)
161 #include "wx/univ/button.h"
162 #elif defined(__WXMSW__)
163 #include "wx/msw/button.h"
164 #elif defined(__WXMOTIF__)
165 #include "wx/motif/button.h"
166 #elif defined(__WXGTK20__)
167 #include "wx/gtk/button.h"
168 #elif defined(__WXGTK__)
169 #include "wx/gtk1/button.h"
170 #elif defined(__WXMAC__)
171 #include "wx/osx/button.h"
172 #elif defined(__WXCOCOA__)
173 #include "wx/cocoa/button.h"
174 #elif defined(__WXPM__)
175 #include "wx/os2/button.h"
176 #elif defined(__WXPALMOS__)
177 #include "wx/palmos/button.h"
178 #endif
179
180 #endif // wxUSE_BUTTON
181
182 #endif
183 // _WX_BUTTON_H_BASE_