]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/tglbtn_osx.cpp
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
9 // Copyright: (c) Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/wxprec.h"
25 #include "wx/tglbtn.h"
26 #include "wx/osx/private.h"
27 #include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
34 wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON
, wxCommandEvent
);
36 // ============================================================================
38 // ============================================================================
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 bool wxToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
44 const wxString
& label
,
46 const wxSize
& size
, long style
,
47 const wxValidator
& validator
,
55 // FIXME: this hack is needed because we're called from
56 // wxBitmapToggleButton::Create() with this style and we currently use a
57 // different wxWidgetImpl method (CreateBitmapToggleButton() rather than
58 // CreateToggleButton()) for creating bitmap buttons, but we really ought
59 // to unify the creation of buttons of all kinds and then remove
61 if ( style
& wxBU_NOTEXT
)
63 return wxControl::Create(parent
, id
, pos
, size
, style
,
67 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
70 m_labelOrig
= m_label
= label
;
72 SetPeer(wxWidgetImpl::CreateToggleButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() )) ;
74 MacPostControlCreate(pos
,size
) ;
79 void wxToggleButton::SetValue(bool val
)
81 GetPeer()->SetValue( val
) ;
84 bool wxToggleButton::GetValue() const
86 return GetPeer()->GetValue() ;
89 void wxToggleButton::Command(wxCommandEvent
& event
)
91 SetValue((event
.GetInt() != 0));
92 ProcessCommand(event
);
95 bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
97 wxCommandEvent
event(wxEVT_TOGGLEBUTTON
, m_windowId
);
98 event
.SetInt(GetValue());
99 event
.SetEventObject(this);
100 ProcessCommand(event
);
104 // ----------------------------------------------------------------------------
105 // wxBitmapToggleButton
106 // ----------------------------------------------------------------------------
108 IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton
, wxToggleButton
)
110 bool wxBitmapToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
111 const wxBitmap
& label
,
113 const wxSize
& size
, long style
,
114 const wxValidator
& validator
,
115 const wxString
& name
)
119 if ( !wxToggleButton::Create(parent
, id
, wxEmptyString
, pos
, size
, style
| wxBU_NOTEXT
| wxBU_EXACTFIT
, validator
, name
) )
123 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
125 m_bitmaps
[State_Normal
] = label
;
127 SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
129 MacPostControlCreate(pos
,size
) ;
134 #endif // wxUSE_TOGGLEBTN