1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/tglbtn.cpp
3 // Purpose: Definition of the wxToggleButton class, which implements a
4 // toggle button under wxMac.
5 // Author: Stefan Csomor
9 // Copyright: (c) 2000 Johnny C. Norris II
10 // License: Rocketeer license
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
22 #include "wx/tglbtn.h"
26 #include "wx/mac/uma.h"
29 static const int kMacOSXHorizontalBorder
= 2 ;
30 static const int kMacOSXVerticalBorder
= 4 ;
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
37 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
39 // ============================================================================
41 // ============================================================================
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 // Single check box item
48 bool wxToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
49 const wxString
& label
,
51 const wxSize
& size
, long style
,
52 const wxValidator
& validator
,
55 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
61 if ( UMAHasAquaLayout() )
63 m_macHorizontalBorder
= kMacOSXHorizontalBorder
;
64 m_macVerticalBorder
= kMacOSXVerticalBorder
;
67 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
69 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , kControlBehaviorToggles
, 1,
70 kControlBevelButtonNormalBevelProc
, (long) this ) ;
71 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
73 MacPostControlCreate() ;
78 wxSize
wxToggleButton::DoGetBestSize() const
83 int lBtn
= m_label
.Length() * 8 + 12 ;
87 if ( UMAHasAquaLayout() )
89 wBtn
+= 2 * kMacOSXHorizontalBorder
;
90 hBtn
+= 2 * kMacOSXVerticalBorder
;
92 return wxSize ( wBtn
, hBtn
) ;
95 void wxToggleButton::SetValue(bool val
)
97 ::SetControl32BitValue( (ControlHandle
) m_macControl
, val
) ;
100 bool wxToggleButton::GetValue() const
102 return GetControl32BitValue( (ControlHandle
) m_macControl
) ;
105 void wxToggleButton::Command(wxCommandEvent
& event
)
107 SetValue((event
.GetInt() != 0));
108 ProcessCommand(event
);
111 void wxToggleButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
113 if ( controlpart
!= kControlNoPart
)
115 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
116 event
.SetInt(GetValue());
117 event
.SetEventObject(this);
118 ProcessCommand(event
);
122 #endif // wxUSE_TOGGLEBTN