]> git.saurik.com Git - wxWidgets.git/blame - src/univ/tglbtn.cpp
fix for HP and IBM compilers, calls to static template functions must be qualified
[wxWidgets.git] / src / univ / tglbtn.cpp
CommitLineData
43be3c33
JS
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
43be3c33
JS
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#if wxUSE_TOGGLEBTN
19
13199c3d
PC
20#include "wx/tglbtn.h"
21
43be3c33
JS
22DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
23
bd88c1fa 24IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxButton)
43be3c33 25
bd88c1fa 26wxToggleButton::wxToggleButton()
43be3c33 27{
bd88c1fa 28 Init();
43be3c33
JS
29}
30
bd88c1fa
PC
31wxToggleButton::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)
43be3c33 40{
bd88c1fa
PC
41 Init();
42 Create(parent, id, bitmap, label, pos, size, style, validator, name);
43be3c33
JS
43}
44
bd88c1fa
PC
45wxToggleButton::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)
43be3c33 53{
bd88c1fa
PC
54 Init();
55 Create(parent, id, label, pos, size, style, validator, name);
43be3c33
JS
56}
57
bd88c1fa 58wxToggleButton::~wxToggleButton()
43be3c33 59{
43be3c33
JS
60}
61
bd88c1fa 62void wxToggleButton::Init()
43be3c33 63{
bd88c1fa
PC
64 m_isPressed = false;
65 m_value = false;
43be3c33
JS
66}
67
68void 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
84void wxToggleButton::Click()
85{
86 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, GetId());
87 InitCommandEvent(event);
88 event.SetInt(GetValue());
89 Command(event);
90}
91
43be3c33
JS
92void wxToggleButton::SetValue(bool state)
93{
94 m_value = state;
95 Refresh();
96}
97
43be3c33 98#endif // wxUSE_TOGGLEBTN