]> git.saurik.com Git - wxWidgets.git/blob - src/univ/tglbtn.cpp
fix warning about unused variable in release build by using standard wxLogLastError...
[wxWidgets.git] / src / univ / tglbtn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: univ/tglbtn.cpp
3 // Purpose: wxToggleButton
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 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_TOGGLEBTN
19
20 #include "wx/tglbtn.h"
21
22 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
23
24 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxButton)
25
26 wxToggleButton::wxToggleButton()
27 {
28 Init();
29 }
30
31 wxToggleButton::wxToggleButton(wxWindow *parent,
32 wxWindowID id,
33 const wxBitmap& bitmap,
34 const wxString& label,
35 const wxPoint& pos,
36 const wxSize& size,
37 long style,
38 const wxValidator& validator,
39 const wxString& name)
40 {
41 Init();
42 Create(parent, id, bitmap, label, pos, size, style, validator, name);
43 }
44
45 wxToggleButton::wxToggleButton(wxWindow *parent,
46 wxWindowID id,
47 const wxString& label,
48 const wxPoint& pos,
49 const wxSize& size,
50 long style,
51 const wxValidator& validator,
52 const wxString& name)
53 {
54 Init();
55 Create(parent, id, label, pos, size, style, validator, name);
56 }
57
58 wxToggleButton::~wxToggleButton()
59 {
60 }
61
62 void wxToggleButton::Init()
63 {
64 m_isPressed = false;
65 m_value = false;
66 }
67
68 void wxToggleButton::Toggle()
69 {
70 if ( m_isPressed )
71 Release();
72 else
73 Press();
74
75 if ( !m_isPressed )
76 {
77 // releasing button after it had been pressed generates a click event
78 // and toggles value
79 m_value = !m_value;
80 Click();
81 }
82 }
83
84 void wxToggleButton::Click()
85 {
86 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, GetId());
87 InitCommandEvent(event);
88 event.SetInt(GetValue());
89 Command(event);
90 }
91
92 void wxToggleButton::SetValue(bool state)
93 {
94 m_value = state;
95 Refresh();
96 }
97
98 #endif // wxUSE_TOGGLEBTN