]>
Commit | Line | Data |
---|---|---|
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 | |
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 | ||
ce7fe42e | 22 | wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent ); |
43be3c33 | 23 | |
bd88c1fa | 24 | IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxButton) |
43be3c33 | 25 | |
bd88c1fa | 26 | wxToggleButton::wxToggleButton() |
43be3c33 | 27 | { |
bd88c1fa | 28 | Init(); |
43be3c33 JS |
29 | } |
30 | ||
bd88c1fa PC |
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) | |
43be3c33 | 40 | { |
bd88c1fa PC |
41 | Init(); |
42 | Create(parent, id, bitmap, label, pos, size, style, validator, name); | |
43be3c33 JS |
43 | } |
44 | ||
bd88c1fa PC |
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) | |
43be3c33 | 53 | { |
bd88c1fa PC |
54 | Init(); |
55 | Create(parent, id, label, pos, size, style, validator, name); | |
43be3c33 JS |
56 | } |
57 | ||
bd88c1fa | 58 | wxToggleButton::~wxToggleButton() |
43be3c33 | 59 | { |
43be3c33 JS |
60 | } |
61 | ||
bd88c1fa | 62 | void wxToggleButton::Init() |
43be3c33 | 63 | { |
bd88c1fa PC |
64 | m_isPressed = false; |
65 | m_value = false; | |
43be3c33 JS |
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 | { | |
ce7fe42e | 86 | wxCommandEvent event(wxEVT_TOGGLEBUTTON, GetId()); |
43be3c33 JS |
87 | InitCommandEvent(event); |
88 | event.SetInt(GetValue()); | |
89 | Command(event); | |
90 | } | |
91 | ||
43be3c33 JS |
92 | void wxToggleButton::SetValue(bool state) |
93 | { | |
94 | m_value = state; | |
95 | Refresh(); | |
96 | } | |
97 | ||
43be3c33 | 98 | #endif // wxUSE_TOGGLEBTN |