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: anybutton.h 65680 2010-09-30 11:44:45Z VZ $
7 // Copyright: (c) Vadim Zetlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_ANYBUTTON_H_BASE_
12 #define _WX_ANYBUTTON_H_BASE_
16 #ifdef wxHAS_ANY_BUTTON
18 // ----------------------------------------------------------------------------
19 // wxAnyButton specific flags
20 // ----------------------------------------------------------------------------
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 )
29 // These two flags are obsolete
30 #define wxBU_NOAUTODRAW 0x0000
31 #define wxBU_AUTODRAW 0x0004
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
36 #define wxBU_EXACTFIT 0x0001
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
45 #include "wx/bitmap.h"
46 #include "wx/control.h"
48 // ----------------------------------------------------------------------------
49 // wxAnyButton: common button functionality
50 // ----------------------------------------------------------------------------
52 class WXDLLIMPEXP_CORE wxAnyButtonBase
: public wxControl
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
)
61 SetBitmapLabel(bitmap
);
62 SetBitmapPosition(dir
);
65 wxBitmap
GetBitmap() const { return DoGetBitmap(State_Normal
); }
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).
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
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
); }
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
); }
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(); }
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
);
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; }
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
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(); }
120 void SetBitmapSelected(const wxBitmap
& bitmap
) { SetBitmapPressed(bitmap
); }
121 void SetBitmapHover(const wxBitmap
& bitmap
) { SetBitmapCurrent(bitmap
); }
124 // this enum is not part of wx public API, it is public because it is used
125 // in non wxAnyButton-derived classes internally
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
132 State_Current
, // a.k.a. hot or "hovering"
133 State_Pressed
, // a.k.a. "selected" in public API for some reason
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
143 return HasFlag(wxBU_NOTEXT
) || GetLabel().empty();
146 // return true if we do show the label
147 bool ShowsLabel() const
149 return !DontShowLabel();
153 // choose the default border for this window
154 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
156 virtual wxBitmap
DoGetBitmap(State
WXUNUSED(which
)) const
157 { return wxBitmap(); }
158 virtual void DoSetBitmap(const wxBitmap
& WXUNUSED(bitmap
),
159 State
WXUNUSED(which
))
162 virtual wxSize
DoGetBitmapMargins() const
163 { return wxSize(0, 0); }
165 virtual void DoSetBitmapMargins(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
168 virtual void DoSetBitmapPosition(wxDirection
WXUNUSED(dir
))
171 virtual bool DoGetAuthNeeded() const { return false; }
172 virtual void DoSetAuthNeeded(bool WXUNUSED(show
)) { }
175 wxDECLARE_NO_COPY_CLASS(wxAnyButtonBase
);
178 //#if defined(__WXUNIVERSAL__)
179 // #include "wx/univ/anybutton.h"
180 #if 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 //#elif defined(__WXPALMOS__)
195 // #include "wx/palmos/anybutton.h"
197 typedef wxAnyButtonBase wxAnyButton
;
200 #endif // wxHAS_ANY_BUTTON
202 #endif // _WX_ANYBUTTON_H_BASE_