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_COMMAND_TOGGLEBUTTON_CLICKED
, 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
,
50 m_macIsUserPane
= FALSE
;
52 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
55 m_labelOrig
= m_label
= label
;
57 SetPeer(wxWidgetImpl::CreateToggleButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() )) ;
59 MacPostControlCreate(pos
,size
) ;
64 wxSize
wxToggleButton::DoGetBestSize() const
69 int lBtn
= m_label
.Length() * 8 + 12 ;
73 return wxSize ( wBtn
, hBtn
) ;
76 void wxToggleButton::SetValue(bool val
)
78 GetPeer()->SetValue( val
) ;
81 bool wxToggleButton::GetValue() const
83 return GetPeer()->GetValue() ;
86 void wxToggleButton::Command(wxCommandEvent
& event
)
88 SetValue((event
.GetInt() != 0));
89 ProcessCommand(event
);
92 bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
94 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
95 event
.SetInt(GetValue());
96 event
.SetEventObject(this);
97 ProcessCommand(event
);
101 // ----------------------------------------------------------------------------
102 // wxBitmapToggleButton
103 // ----------------------------------------------------------------------------
105 IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton
, wxControl
)
107 bool wxBitmapToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
108 const wxBitmap
& label
,
110 const wxSize
& size
, long style
,
111 const wxValidator
& validator
,
112 const wxString
& name
)
114 m_macIsUserPane
= FALSE
;
119 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
121 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
124 SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
126 MacPostControlCreate(pos
,size
) ;
131 wxSize
wxBitmapToggleButton::DoGetBestSize() const
133 if (!m_bitmap
.IsOk())
134 return wxSize(20,20);
137 best
.x
= m_bitmap
.GetWidth() + 2 * m_marginX
;
138 best
.y
= m_bitmap
.GetHeight() + 2 * m_marginY
;
143 void wxBitmapToggleButton::SetValue(bool val
)
145 GetPeer()->SetValue( val
) ;
148 bool wxBitmapToggleButton::GetValue() const
150 return GetPeer()->GetValue() ;
153 void wxBitmapToggleButton::Command(wxCommandEvent
& event
)
155 SetValue((event
.GetInt() != 0));
156 ProcessCommand(event
);
159 bool wxBitmapToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
161 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
162 event
.SetInt(GetValue());
163 event
.SetEventObject(this);
164 ProcessCommand(event
);
168 #endif // wxUSE_TOGGLEBTN