]> git.saurik.com Git - wxWidgets.git/blame - include/wx/button.h
Extract conversion from wx to GtkMessageType in a separate file.
[wxWidgets.git] / include / wx / button.h
CommitLineData
1e6feb95
VZ
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
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_BUTTON_H_BASE_
13#define _WX_BUTTON_H_BASE_
c801d85f 14
997176a3
VZ
15#include "wx/defs.h"
16
7ef8bfc4 17// ----------------------------------------------------------------------------
0b4f47a3 18// wxButton flags shared with other classes
7ef8bfc4
VZ
19// ----------------------------------------------------------------------------
20
0b4f47a3 21#if wxUSE_TOGGLEBTN || wxUSE_BUTTON
7ccb2521
VZ
22
23// These flags affect label alignment
7ef8bfc4
VZ
24#define wxBU_LEFT 0x0040
25#define wxBU_TOP 0x0080
26#define wxBU_RIGHT 0x0100
27#define wxBU_BOTTOM 0x0200
041ae202 28#define wxBU_ALIGN_MASK ( wxBU_LEFT | wxBU_TOP | wxBU_RIGHT | wxBU_BOTTOM )
0b4f47a3
DS
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
7ef8bfc4
VZ
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
a2117591
VZ
46// this flag can be used to disable using the text label in the button: it is
47// mostly useful when creating buttons showing bitmap and having stock id as
48// without it both the standard label corresponding to the stock id and the
49// bitmap would be shown
50#define wxBU_NOTEXT 0x0002
51
52
81cb7b5a 53#include "wx/bitmap.h"
1e6feb95
VZ
54#include "wx/control.h"
55
53a2db12 56extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
1e6feb95
VZ
57
58// ----------------------------------------------------------------------------
59// wxButton: a push button
60// ----------------------------------------------------------------------------
61
53a2db12 62class WXDLLIMPEXP_CORE wxButtonBase : public wxControl
1e6feb95
VZ
63{
64public:
6463b9f5 65 wxButtonBase() { }
fc7a2a60 66
2352862a
VZ
67 // show the image in the button in addition to the label: this method is
68 // supported on all (major) platforms
69 void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT)
70 {
71 SetBitmapLabel(bitmap);
72 SetBitmapPosition(dir);
73 }
74
75 wxBitmap GetBitmap() const { return DoGetBitmap(State_Normal); }
76
77 // Methods for setting individual images for different states: normal,
78 // selected (meaning pushed or pressed), focused (meaning normal state for
79 // a focused button), disabled or hover (a.k.a. hot or current).
80 //
81 // Remember that SetBitmap() itself must be called before any other
82 // SetBitmapXXX() methods (except for SetBitmapLabel() which is a synonym
83 // for it anyhow) and that all bitmaps passed to these functions should be
84 // of the same size.
85 void SetBitmapLabel(const wxBitmap& bitmap)
86 { DoSetBitmap(bitmap, State_Normal); }
87 void SetBitmapPressed(const wxBitmap& bitmap)
88 { DoSetBitmap(bitmap, State_Pressed); }
89 void SetBitmapDisabled(const wxBitmap& bitmap)
90 { DoSetBitmap(bitmap, State_Disabled); }
91 void SetBitmapCurrent(const wxBitmap& bitmap)
92 { DoSetBitmap(bitmap, State_Current); }
93 void SetBitmapFocus(const wxBitmap& bitmap)
94 { DoSetBitmap(bitmap, State_Focused); }
95
96 wxBitmap GetBitmapLabel() const { return DoGetBitmap(State_Normal); }
97 wxBitmap GetBitmapPressed() const { return DoGetBitmap(State_Pressed); }
98 wxBitmap GetBitmapDisabled() const { return DoGetBitmap(State_Disabled); }
99 wxBitmap GetBitmapCurrent() const { return DoGetBitmap(State_Current); }
100 wxBitmap GetBitmapFocus() const { return DoGetBitmap(State_Focused); }
101
1e6feb95
VZ
102
103 // set the margins around the image
2352862a
VZ
104 void SetBitmapMargins(wxCoord x, wxCoord y) { DoSetBitmapMargins(x, y); }
105 void SetBitmapMargins(const wxSize& sz) { DoSetBitmapMargins(sz.x, sz.y); }
106
107 // set the image position relative to the text, i.e. wxLEFT means that the
108 // image is to the left of the text (this is the default)
233f10bf 109 void SetBitmapPosition(wxDirection dir);
2352862a 110
1e6feb95 111
94aff5ff
VZ
112 // make this button the default button in its top level window
113 //
114 // returns the old default item (possibly NULL)
115 virtual wxWindow *SetDefault();
1e6feb95 116
e8e24dfa
RD
117 // Buttons on MSW can look bad if they are not native colours, because
118 // then they become owner-drawn and not theme-drawn. Disable it here
119 // in wxButtonBase to make it consistent.
120 virtual bool ShouldInheritColours() const { return false; }
121
1e6feb95
VZ
122 // returns the default button size for this platform
123 static wxSize GetDefaultSize();
fc7a2a60 124
2352862a
VZ
125 // wxUniv-compatible and deprecated equivalents to SetBitmapXXX()
126#if WXWIN_COMPATIBILITY_2_8
127 void SetImageLabel(const wxBitmap& bitmap) { SetBitmap(bitmap); }
128 void SetImageMargins(wxCoord x, wxCoord y) { SetBitmapMargins(x, y); }
129#endif // WXWIN_COMPATIBILITY_2_8
130
131 // backwards compatible names for pressed/current bitmaps: they're not
132 // deprecated as there is nothing really wrong with using them and no real
133 // advantage to using the new names but the new names are still preferred
134 wxBitmap GetBitmapSelected() const { return GetBitmapPressed(); }
135 wxBitmap GetBitmapHover() const { return GetBitmapCurrent(); }
136
137 void SetBitmapSelected(const wxBitmap& bitmap) { SetBitmapPressed(bitmap); }
138 void SetBitmapHover(const wxBitmap& bitmap) { SetBitmapCurrent(bitmap); }
139
dc797d8e 140
233f10bf
VZ
141 // this enum is not part of wx public API, it is public because it is used
142 // in non wxButton-derived classes internally
143 //
144 // also notice that MSW code relies on the values of the enum elements, do
145 // not change them without revising src/msw/button.cpp
2352862a
VZ
146 enum State
147 {
148 State_Normal,
2352862a 149 State_Current, // a.k.a. hot or "hovering"
233f10bf 150 State_Pressed, // a.k.a. "selected" in public API for some reason
2352862a
VZ
151 State_Disabled,
152 State_Focused,
153 State_Max
154 };
155
a2117591
VZ
156 // return true if this button shouldn't show the text label, either because
157 // it doesn't have it or because it was explicitly disabled with wxBU_NOTEXT
158 bool DontShowLabel() const
159 {
160 return HasFlag(wxBU_NOTEXT) || GetLabel().empty();
161 }
162
163 // return true if we do show the label
164 bool ShowsLabel() const
165 {
166 return !DontShowLabel();
167 }
168
233f10bf
VZ
169protected:
170 // choose the default border for this window
171 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
172
2352862a
VZ
173 virtual wxBitmap DoGetBitmap(State WXUNUSED(which)) const
174 { return wxBitmap(); }
175 virtual void DoSetBitmap(const wxBitmap& WXUNUSED(bitmap),
176 State WXUNUSED(which))
177 { }
a6fd73d3
VZ
178
179 virtual wxSize DoGetBitmapMargins() const
180 { return wxSize(0, 0); }
181
2352862a
VZ
182 virtual void DoSetBitmapMargins(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
183 { }
a6fd73d3 184
233f10bf
VZ
185 virtual void DoSetBitmapPosition(wxDirection WXUNUSED(dir))
186 { }
2352862a
VZ
187
188
c0c133e1 189 wxDECLARE_NO_COPY_CLASS(wxButtonBase);
1e6feb95
VZ
190};
191
192#if defined(__WXUNIVERSAL__)
193 #include "wx/univ/button.h"
194#elif defined(__WXMSW__)
195 #include "wx/msw/button.h"
2049ba38 196#elif defined(__WXMOTIF__)
1e6feb95 197 #include "wx/motif/button.h"
1be7a35c 198#elif defined(__WXGTK20__)
1e6feb95 199 #include "wx/gtk/button.h"
1be7a35c
MR
200#elif defined(__WXGTK__)
201 #include "wx/gtk1/button.h"
34138703 202#elif defined(__WXMAC__)
ef0e9220 203 #include "wx/osx/button.h"
e64df9bc
DE
204#elif defined(__WXCOCOA__)
205 #include "wx/cocoa/button.h"
1777b9bb 206#elif defined(__WXPM__)
1e6feb95 207 #include "wx/os2/button.h"
db101bd3
WS
208#elif defined(__WXPALMOS__)
209 #include "wx/palmos/button.h"
c801d85f
KB
210#endif
211
1e6feb95
VZ
212#endif // wxUSE_BUTTON
213
c801d85f 214#endif
34138703 215 // _WX_BUTTON_H_BASE_