]>
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
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
24 #include "wx/tglbtn.h"
25 #include "wx/osx/private.h"
26 #include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
33 wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON
, wxCommandEvent
);
35 // ============================================================================
37 // ============================================================================
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 bool wxToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
43 const wxString
& label
,
45 const wxSize
& size
, long style
,
46 const wxValidator
& validator
,
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
60 if ( style
& wxBU_NOTEXT
)
62 return wxControl::Create(parent
, id
, pos
, size
, style
,
66 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
69 m_labelOrig
= m_label
= label
;
71 SetPeer(wxWidgetImpl::CreateToggleButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() )) ;
73 MacPostControlCreate(pos
,size
) ;
78 void wxToggleButton::SetValue(bool val
)
80 GetPeer()->SetValue( val
) ;
83 bool wxToggleButton::GetValue() const
85 return GetPeer()->GetValue() ;
88 void wxToggleButton::Command(wxCommandEvent
& event
)
90 SetValue((event
.GetInt() != 0));
91 ProcessCommand(event
);
94 bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
96 wxCommandEvent
event(wxEVT_TOGGLEBUTTON
, m_windowId
);
97 event
.SetInt(GetValue());
98 event
.SetEventObject(this);
99 ProcessCommand(event
);
103 // ----------------------------------------------------------------------------
104 // wxBitmapToggleButton
105 // ----------------------------------------------------------------------------
107 IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton
, wxToggleButton
)
109 bool wxBitmapToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
110 const wxBitmap
& label
,
112 const wxSize
& size
, long style
,
113 const wxValidator
& validator
,
114 const wxString
& name
)
118 if ( !wxToggleButton::Create(parent
, id
, wxEmptyString
, pos
, size
, style
| wxBU_NOTEXT
| wxBU_EXACTFIT
, validator
, name
) )
122 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
124 m_bitmaps
[State_Normal
] = label
;
126 SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
128 MacPostControlCreate(pos
,size
) ;
133 #endif // wxUSE_TOGGLEBTN