added stock buttons support
[wxWidgets.git] / include / wx / univ / button.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/button.h
3 // Purpose: wxButton for wxUniversal
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 15.08.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_BUTTON_H_
13 #define _WX_UNIV_BUTTON_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "univbutton.h"
17 #endif
18
19 class WXDLLEXPORT wxInputHandler;
20
21 #include "wx/bitmap.h"
22
23 // ----------------------------------------------------------------------------
24 // the actions supported by this control
25 // ----------------------------------------------------------------------------
26
27 #define wxACTION_BUTTON_TOGGLE _T("toggle") // press/release the button
28 #define wxACTION_BUTTON_PRESS _T("press") // press the button
29 #define wxACTION_BUTTON_RELEASE _T("release") // release the button
30 #define wxACTION_BUTTON_CLICK _T("click") // generate button click event
31
32 // ----------------------------------------------------------------------------
33 // wxButton: a push button
34 // ----------------------------------------------------------------------------
35
36 class WXDLLEXPORT wxButton : public wxButtonBase
37 {
38 public:
39 wxButton() { Init(); }
40 wxButton(wxWindow *parent,
41 wxWindowID id,
42 const wxBitmap& bitmap,
43 const wxString& label,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
46 long style = 0,
47 const wxValidator& validator = wxDefaultValidator,
48 const wxString& name = wxButtonNameStr)
49 {
50 Init();
51
52 Create(parent, id, bitmap, label, pos, size, style, validator, name);
53 }
54
55 wxButton(wxWindow *parent, wxWindowID id, wxStockItemID stock,
56 const wxString& descriptiveLabel = wxEmptyString,
57 const wxPoint& pos = wxDefaultPosition,
58 long style = 0,
59 const wxValidator& validator = wxDefaultValidator,
60 const wxString& name = wxButtonNameStr)
61 {
62 Init();
63
64 Create(parent, id, stock, descriptiveLabel, pos, style, validator, name);
65 }
66
67 wxButton(wxWindow *parent,
68 wxWindowID id,
69 const wxString& label,
70 const wxPoint& pos = wxDefaultPosition,
71 const wxSize& size = wxDefaultSize,
72 long style = 0,
73 const wxValidator& validator = wxDefaultValidator,
74 const wxString& name = wxButtonNameStr)
75 {
76 Init();
77
78 Create(parent, id, label, pos, size, style, validator, name);
79 }
80
81 bool Create(wxWindow *parent,
82 wxWindowID id,
83 const wxString& label,
84 const wxPoint& pos = wxDefaultPosition,
85 const wxSize& size = wxDefaultSize,
86 long style = 0,
87 const wxValidator& validator = wxDefaultValidator,
88 const wxString& name = wxButtonNameStr)
89 {
90 return Create(parent, id, wxNullBitmap, label,
91 pos, size, style, validator, name);
92 }
93
94 bool Create(wxWindow *parent, wxWindowID id, wxStockItemID stock,
95 const wxString& descriptiveLabel = wxEmptyString,
96 const wxPoint& pos = wxDefaultPosition,
97 long style = 0,
98 const wxValidator& validator = wxDefaultValidator,
99 const wxString& name = wxButtonNameStr)
100 {
101 return CreateStock(parent, id, stock, descriptiveLabel,
102 pos, style, validator, name);
103 }
104
105 bool Create(wxWindow *parent,
106 wxWindowID id,
107 const wxBitmap& bitmap,
108 const wxString& label,
109 const wxPoint& pos = wxDefaultPosition,
110 const wxSize& size = wxDefaultSize,
111 long style = 0,
112 const wxValidator& validator = wxDefaultValidator,
113 const wxString& name = wxButtonNameStr);
114
115 virtual ~wxButton();
116
117 virtual void SetImageLabel(const wxBitmap& bitmap);
118 virtual void SetImageMargins(wxCoord x, wxCoord y);
119 virtual void SetDefault();
120
121 virtual bool IsPressed() const { return m_isPressed; }
122 virtual bool IsDefault() const { return m_isDefault; }
123
124 // wxButton actions
125 void Toggle();
126 virtual void Press();
127 virtual void Release();
128 virtual void Click();
129
130 protected:
131 virtual bool PerformAction(const wxControlAction& action,
132 long numArg = -1,
133 const wxString& strArg = wxEmptyString);
134 virtual wxSize DoGetBestClientSize() const;
135
136 virtual bool DoDrawBackground(wxDC& dc);
137 virtual void DoDraw(wxControlRenderer *renderer);
138
139 virtual bool CanBeHighlighted() const { return true; }
140
141 // common part of all ctors
142 void Init();
143
144 // current state
145 bool m_isPressed,
146 m_isDefault;
147
148 // the (optional) image to show and the margins around it
149 wxBitmap m_bitmap;
150 wxCoord m_marginBmpX,
151 m_marginBmpY;
152
153 private:
154 DECLARE_DYNAMIC_CLASS(wxButton)
155 };
156
157 // ----------------------------------------------------------------------------
158 // wxStdButtonInputHandler: translates SPACE and ENTER keys and the left mouse
159 // click into button press/release actions
160 // ----------------------------------------------------------------------------
161
162 class WXDLLEXPORT wxStdButtonInputHandler : public wxStdInputHandler
163 {
164 public:
165 wxStdButtonInputHandler(wxInputHandler *inphand);
166
167 virtual bool HandleKey(wxInputConsumer *consumer,
168 const wxKeyEvent& event,
169 bool pressed);
170 virtual bool HandleMouse(wxInputConsumer *consumer,
171 const wxMouseEvent& event);
172 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
173 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
174 virtual bool HandleActivation(wxInputConsumer *consumer, bool activated);
175
176 private:
177 // the window (button) which has capture or NULL and the flag telling if
178 // the mouse is inside the button which captured it or not
179 wxWindow *m_winCapture;
180 bool m_winHasMouse;
181 };
182
183 #endif // _WX_UNIV_BUTTON_H_
184