]> git.saurik.com Git - wxWidgets.git/blame - src/univ/tglbtn.cpp
Fix another crash when conversion fails in Unix PostScript code.
[wxWidgets.git] / src / univ / tglbtn.cpp
CommitLineData
43be3c33 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/univ/tglbtn.cpp
43be3c33
JS
3// Purpose: wxToggleButton
4// Author: Vadim Zeitlin
5// Modified by: David Bjorkevik
6// Created: 16.05.06
43be3c33
JS
7// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
43be3c33
JS
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
17#if wxUSE_TOGGLEBTN
18
13199c3d
PC
19#include "wx/tglbtn.h"
20
ce7fe42e 21wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent );
43be3c33 22
bd88c1fa 23IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxButton)
43be3c33 24
bd88c1fa 25wxToggleButton::wxToggleButton()
43be3c33 26{
bd88c1fa 27 Init();
43be3c33
JS
28}
29
bd88c1fa
PC
30wxToggleButton::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)
43be3c33 39{
bd88c1fa
PC
40 Init();
41 Create(parent, id, bitmap, label, pos, size, style, validator, name);
43be3c33
JS
42}
43
bd88c1fa
PC
44wxToggleButton::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)
43be3c33 52{
bd88c1fa
PC
53 Init();
54 Create(parent, id, label, pos, size, style, validator, name);
43be3c33
JS
55}
56
bd88c1fa 57wxToggleButton::~wxToggleButton()
43be3c33 58{
43be3c33
JS
59}
60
bd88c1fa 61void wxToggleButton::Init()
43be3c33 62{
bd88c1fa
PC
63 m_isPressed = false;
64 m_value = false;
43be3c33
JS
65}
66
67void 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
83void wxToggleButton::Click()
84{
ce7fe42e 85 wxCommandEvent event(wxEVT_TOGGLEBUTTON, GetId());
43be3c33
JS
86 InitCommandEvent(event);
87 event.SetInt(GetValue());
88 Command(event);
89}
90
43be3c33
JS
91void wxToggleButton::SetValue(bool state)
92{
93 m_value = state;
94 Refresh();
95}
96
43be3c33 97#endif // wxUSE_TOGGLEBTN