]> git.saurik.com Git - wxWidgets.git/blob - src/univ/tglbtn.cpp
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / src / univ / tglbtn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/tglbtn.cpp
3 // Purpose: wxToggleButton
4 // Author: Vadim Zeitlin
5 // Modified by: David Bjorkevik
6 // Created: 16.05.06
7 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_TOGGLEBTN
18
19 #include "wx/tglbtn.h"
20
21 wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent );
22
23 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxButton)
24
25 wxToggleButton::wxToggleButton()
26 {
27 Init();
28 }
29
30 wxToggleButton::wxToggleButton(wxWindow *parent,
31 wxWindowID id,
32 const wxBitmap& bitmap,
33 const wxString& label,
34 const wxPoint& pos,
35 const wxSize& size,
36 long style,
37 const wxValidator& validator,
38 const wxString& name)
39 {
40 Init();
41 Create(parent, id, bitmap, label, pos, size, style, validator, name);
42 }
43
44 wxToggleButton::wxToggleButton(wxWindow *parent,
45 wxWindowID id,
46 const wxString& label,
47 const wxPoint& pos,
48 const wxSize& size,
49 long style,
50 const wxValidator& validator,
51 const wxString& name)
52 {
53 Init();
54 Create(parent, id, label, pos, size, style, validator, name);
55 }
56
57 wxToggleButton::~wxToggleButton()
58 {
59 }
60
61 void wxToggleButton::Init()
62 {
63 m_isPressed = false;
64 m_value = false;
65 }
66
67 void wxToggleButton::Toggle()
68 {
69 if ( m_isPressed )
70 Release();
71 else
72 Press();
73
74 if ( !m_isPressed )
75 {
76 // releasing button after it had been pressed generates a click event
77 // and toggles value
78 m_value = !m_value;
79 Click();
80 }
81 }
82
83 void wxToggleButton::Click()
84 {
85 wxCommandEvent event(wxEVT_TOGGLEBUTTON, GetId());
86 InitCommandEvent(event);
87 event.SetInt(GetValue());
88 Command(event);
89 }
90
91 void wxToggleButton::SetValue(bool state)
92 {
93 m_value = state;
94 Refresh();
95 }
96
97 #endif // wxUSE_TOGGLEBTN