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