1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/anybutton.h
3 // Purpose: wxAnyButtonBase class
4 // Author: Vadim Zetlin
5 // Created: 2000-08-15 (extracted from button.h)
6 // Copyright: (c) Vadim Zetlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_ANYBUTTON_H_BASE_
11 #define _WX_ANYBUTTON_H_BASE_
15 #ifdef wxHAS_ANY_BUTTON
17 // ----------------------------------------------------------------------------
18 // wxAnyButton specific flags
19 // ----------------------------------------------------------------------------
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 )
28 // These two flags are obsolete
29 #define wxBU_NOAUTODRAW 0x0000
30 #define wxBU_AUTODRAW 0x0004
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
35 #define wxBU_EXACTFIT 0x0001
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
44 #include "wx/bitmap.h"
45 #include "wx/control.h"
47 // ----------------------------------------------------------------------------
48 // wxAnyButton: common button functionality
49 // ----------------------------------------------------------------------------
51 class WXDLLIMPEXP_CORE wxAnyButtonBase
: public wxControl
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
)
60 SetBitmapLabel(bitmap
);
61 SetBitmapPosition(dir
);
64 wxBitmap
GetBitmap() const { return DoGetBitmap(State_Normal
); }
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).
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
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
); }
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
); }
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(); }
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
);
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; }
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
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(); }
119 void SetBitmapSelected(const wxBitmap
& bitmap
) { SetBitmapPressed(bitmap
); }
120 void SetBitmapHover(const wxBitmap
& bitmap
) { SetBitmapCurrent(bitmap
); }
123 // this enum is not part of wx public API, it is public because it is used
124 // in non wxAnyButton-derived classes internally
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
131 State_Current
, // a.k.a. hot or "hovering"
132 State_Pressed
, // a.k.a. "selected" in public API for some reason
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
142 return HasFlag(wxBU_NOTEXT
) || GetLabel().empty();
145 // return true if we do show the label
146 bool ShowsLabel() const
148 return !DontShowLabel();
152 // choose the default border for this window
153 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
155 virtual wxBitmap
DoGetBitmap(State
WXUNUSED(which
)) const
156 { return wxBitmap(); }
157 virtual void DoSetBitmap(const wxBitmap
& WXUNUSED(bitmap
),
158 State
WXUNUSED(which
))
161 virtual wxSize
DoGetBitmapMargins() const
162 { return wxSize(0, 0); }
164 virtual void DoSetBitmapMargins(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
167 virtual void DoSetBitmapPosition(wxDirection
WXUNUSED(dir
))
170 virtual bool DoGetAuthNeeded() const { return false; }
171 virtual void DoSetAuthNeeded(bool WXUNUSED(show
)) { }
174 wxDECLARE_NO_COPY_CLASS(wxAnyButtonBase
);
177 #if defined(__WXUNIVERSAL__)
178 #include "wx/univ/anybutton.h"
179 #elif defined(__WXMSW__)
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"
194 typedef wxAnyButtonBase wxAnyButton
;
197 #endif // wxHAS_ANY_BUTTON
199 #endif // _WX_ANYBUTTON_H_BASE_