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 // RCS-ID: $Id: tglbtn.cpp 54129 2008-06-11 19:30:52Z SC $
9 // Copyright: (c) Stefan Csomor
10 // License: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/wxprec.h"
25 #include "wx/tglbtn.h"
26 #include "wx/osx/private.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
34 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
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 m_peer
= 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 m_peer
->SetValue( val
) ;
81 bool wxToggleButton::GetValue() const
83 return m_peer
->GetValue() ;
86 void wxToggleButton::Command(wxCommandEvent
& event
)
88 SetValue((event
.GetInt() != 0));
89 ProcessCommand(event
);
92 bool wxToggleButton::HandleClicked( double 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
;
118 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
121 m_peer
= wxWidgetImpl::CreateBitmapToggleButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ) ;
123 MacPostControlCreate(pos
,size
) ;
128 wxSize
wxBitmapToggleButton::DoGetBestSize() const
130 if (!m_bitmap
.IsOk())
131 return wxSize(20,20);
133 return wxSize ( m_bitmap
.GetWidth()+6, m_bitmap
.GetHeight()+6 ) ;
136 void wxBitmapToggleButton::SetValue(bool val
)
138 m_peer
->SetValue( val
) ;
141 bool wxBitmapToggleButton::GetValue() const
143 return m_peer
->GetValue() ;
146 void wxBitmapToggleButton::Command(wxCommandEvent
& event
)
148 SetValue((event
.GetInt() != 0));
149 ProcessCommand(event
);
152 bool wxBitmapToggleButton::HandleClicked( double timestampsec
)
154 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
155 event
.SetInt(GetValue());
156 event
.SetEventObject(this);
157 ProcessCommand(event
);
161 #endif // wxUSE_TOGGLEBTN