]>
Commit | Line | Data |
---|---|---|
e53b3d16 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/tglbtn_osx.cpp | |
3 | // Purpose: Definition of the wxToggleButton class, which implements a | |
4 | // toggle button under wxMac. | |
5 | // Author: Stefan Csomor | |
6 | // Modified by: | |
7 | // Created: 08.02.01 | |
e53b3d16 | 8 | // Copyright: (c) Stefan Csomor |
526954c5 | 9 | // Licence: wxWindows licence |
e53b3d16 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declatations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #if wxUSE_TOGGLEBTN | |
23 | ||
24 | #include "wx/tglbtn.h" | |
25 | #include "wx/osx/private.h" | |
03647350 | 26 | #include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN |
e53b3d16 SC |
27 | |
28 | // ---------------------------------------------------------------------------- | |
29 | // macros | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
32 | IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) | |
ce7fe42e | 33 | wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent ); |
e53b3d16 SC |
34 | |
35 | // ============================================================================ | |
36 | // implementation | |
37 | // ============================================================================ | |
38 | // ---------------------------------------------------------------------------- | |
39 | // wxToggleButton | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
42 | bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, | |
43 | const wxString& label, | |
44 | const wxPoint& pos, | |
45 | const wxSize& size, long style, | |
46 | const wxValidator& validator, | |
47 | const wxString& name) | |
48 | { | |
d15694e8 SC |
49 | DontCreatePeer(); |
50 | ||
b4354db1 VZ |
51 | m_marginX = |
52 | m_marginY = 0; | |
53 | ||
54 | // FIXME: this hack is needed because we're called from | |
55 | // wxBitmapToggleButton::Create() with this style and we currently use a | |
56 | // different wxWidgetImpl method (CreateBitmapToggleButton() rather than | |
57 | // CreateToggleButton()) for creating bitmap buttons, but we really ought | |
58 | // to unify the creation of buttons of all kinds and then remove | |
59 | // this check | |
60 | if ( style & wxBU_NOTEXT ) | |
61 | { | |
62 | return wxControl::Create(parent, id, pos, size, style, | |
63 | validator, name); | |
64 | } | |
65 | ||
e53b3d16 SC |
66 | if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) |
67 | return false; | |
03647350 | 68 | |
e53b3d16 SC |
69 | m_labelOrig = m_label = label ; |
70 | ||
22756322 | 71 | SetPeer(wxWidgetImpl::CreateToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )) ; |
e53b3d16 SC |
72 | |
73 | MacPostControlCreate(pos,size) ; | |
03647350 | 74 | |
e53b3d16 SC |
75 | return TRUE; |
76 | } | |
77 | ||
e53b3d16 SC |
78 | void wxToggleButton::SetValue(bool val) |
79 | { | |
22756322 | 80 | GetPeer()->SetValue( val ) ; |
e53b3d16 SC |
81 | } |
82 | ||
83 | bool wxToggleButton::GetValue() const | |
84 | { | |
22756322 | 85 | return GetPeer()->GetValue() ; |
e53b3d16 SC |
86 | } |
87 | ||
88 | void wxToggleButton::Command(wxCommandEvent & event) | |
89 | { | |
90 | SetValue((event.GetInt() != 0)); | |
91 | ProcessCommand(event); | |
92 | } | |
93 | ||
03647350 | 94 | bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) |
e53b3d16 | 95 | { |
ce7fe42e | 96 | wxCommandEvent event(wxEVT_TOGGLEBUTTON, m_windowId); |
e53b3d16 SC |
97 | event.SetInt(GetValue()); |
98 | event.SetEventObject(this); | |
99 | ProcessCommand(event); | |
100 | return true ; | |
101 | } | |
102 | ||
103 | // ---------------------------------------------------------------------------- | |
104 | // wxBitmapToggleButton | |
105 | // ---------------------------------------------------------------------------- | |
106 | ||
b4354db1 | 107 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton) |
e53b3d16 SC |
108 | |
109 | bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, | |
110 | const wxBitmap& label, | |
111 | const wxPoint& pos, | |
112 | const wxSize& size, long style, | |
113 | const wxValidator& validator, | |
114 | const wxString& name) | |
115 | { | |
d15694e8 SC |
116 | DontCreatePeer(); |
117 | ||
b4354db1 VZ |
118 | if ( !wxToggleButton::Create(parent, id, wxEmptyString, pos, size, style | wxBU_NOTEXT | wxBU_EXACTFIT, validator, name) ) |
119 | return false; | |
03647350 | 120 | |
11a449ac RR |
121 | m_marginX = |
122 | m_marginY = wxDEFAULT_BUTTON_MARGIN; | |
03647350 | 123 | |
b4354db1 | 124 | m_bitmaps[State_Normal] = label; |
03647350 | 125 | |
22756322 | 126 | SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )); |
e53b3d16 SC |
127 | |
128 | MacPostControlCreate(pos,size) ; | |
03647350 | 129 | |
e53b3d16 SC |
130 | return TRUE; |
131 | } | |
132 | ||
e53b3d16 SC |
133 | #endif // wxUSE_TOGGLEBTN |
134 |