1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/button.h
3 // Purpose: wxToggleButton for wxUniversal
4 // Author: Vadim Zeitlin
5 // Modified by: David Bjorkevik
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIV_TGLBTN_H_
13 #define _WX_UNIV_TGLBTN_H_
15 class WXDLLEXPORT wxInputHandler
;
17 #include "wx/bitmap.h"
18 #include "wx/checkbox.h"
20 // ----------------------------------------------------------------------------
21 // the actions supported by this control
22 // ----------------------------------------------------------------------------
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
29 // ----------------------------------------------------------------------------
30 // wxToggleButton: a push button
31 // ----------------------------------------------------------------------------
33 class WXDLLIMPEXP_CORE wxToggleButton
: public wxControl
36 wxToggleButton() { Init(); }
37 wxToggleButton(wxWindow
*parent
,
39 const wxBitmap
& bitmap
,
40 const wxString
& label
= wxEmptyString
,
41 const wxPoint
& pos
= wxDefaultPosition
,
42 const wxSize
& size
= wxDefaultSize
,
44 const wxValidator
& validator
= wxDefaultValidator
,
45 const wxString
& name
= wxCheckBoxNameStr
)
49 Create(parent
, id
, bitmap
, label
, pos
, size
, style
, validator
, name
);
52 wxToggleButton(wxWindow
*parent
,
54 const wxString
& label
= wxEmptyString
,
55 const wxPoint
& pos
= wxDefaultPosition
,
56 const wxSize
& size
= wxDefaultSize
,
58 const wxValidator
& validator
= wxDefaultValidator
,
59 const wxString
& name
= wxCheckBoxNameStr
)
63 Create(parent
, id
, label
, pos
, size
, style
, validator
, name
);
66 bool Create(wxWindow
*parent
,
68 const wxString
& label
= wxEmptyString
,
69 const wxPoint
& pos
= wxDefaultPosition
,
70 const wxSize
& size
= wxDefaultSize
,
72 const wxValidator
& validator
= wxDefaultValidator
,
73 const wxString
& name
= wxCheckBoxNameStr
)
75 return Create(parent
, id
, wxNullBitmap
, label
,
76 pos
, size
, style
, validator
, name
);
79 bool Create(wxWindow
*parent
,
81 const wxBitmap
& bitmap
,
82 const wxString
& label
= wxEmptyString
,
83 const wxPoint
& pos
= wxDefaultPosition
,
84 const wxSize
& size
= wxDefaultSize
,
86 const wxValidator
& validator
= wxDefaultValidator
,
87 const wxString
& name
= wxCheckBoxNameStr
);
89 virtual ~wxToggleButton();
91 virtual void SetImageLabel(const wxBitmap
& bitmap
);
92 virtual void SetImageMargins(wxCoord x
, wxCoord y
);
94 virtual bool IsPressed() const { return m_isPressed
|| m_value
; }
96 // wxToggleButton actions
99 virtual void Release();
100 virtual void Click();
103 void SetValue(bool state
);
104 bool GetValue() const { return m_value
; }
106 // returns the default button size for this platform
107 static wxSize
GetDefaultSize();
110 virtual bool PerformAction(const wxControlAction
& action
,
112 const wxString
& strArg
= wxEmptyString
);
113 virtual wxSize
DoGetBestClientSize() const;
115 virtual bool DoDrawBackground(wxDC
& dc
);
116 virtual void DoDraw(wxControlRenderer
*renderer
);
118 virtual bool CanBeHighlighted() const { return true; }
120 // common part of all ctors
123 // current state - is the user currently pressing the button
129 // the (optional) image to show and the margins around it
131 wxCoord m_marginBmpX
,
135 DECLARE_DYNAMIC_CLASS(wxToggleButton
)
137 // wxStdToggleButtonInputHandler: translates SPACE and ENTER keys and the left mouse
138 // click into button press/release actions
139 // ----------------------------------------------------------------------------
141 class WXDLLEXPORT wxStdToggleButtonInputHandler
: public wxStdInputHandler
144 wxStdToggleButtonInputHandler(wxInputHandler
*inphand
);
146 virtual bool HandleKey(wxInputConsumer
*consumer
,
147 const wxKeyEvent
& event
,
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
);
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
;
162 #endif // _WX_UNIV_TGLBTN_H_