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"
27 #include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN
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
;
119 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
121 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
124 m_peer
= 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 m_peer
->SetValue( val
) ;
148 bool wxBitmapToggleButton::GetValue() const
150 return m_peer
->GetValue() ;
153 void wxBitmapToggleButton::Command(wxCommandEvent
& event
)
155 SetValue((event
.GetInt() != 0));
156 ProcessCommand(event
);
159 bool wxBitmapToggleButton::HandleClicked( double 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