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 #pragma implementation "button.h"
26 #include "wx/tglbtn.h"
30 #include "wx/mac/uma.h"
33 static const int kMacOSXHorizontalBorder
= 2 ;
34 static const int kMacOSXVerticalBorder
= 4 ;
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
41 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
43 // ============================================================================
45 // ============================================================================
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // Single check box item
52 bool wxToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
53 const wxString
& label
,
55 const wxSize
& size
, long style
,
56 const wxValidator
& validator
,
59 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
65 if ( UMAHasAquaLayout() )
67 m_macHorizontalBorder
= kMacOSXHorizontalBorder
;
68 m_macVerticalBorder
= kMacOSXVerticalBorder
;
71 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
73 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , kControlBehaviorToggles
, 1,
74 kControlBevelButtonNormalBevelProc
, (long) this ) ;
75 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
77 MacPostControlCreate() ;
82 wxSize
wxToggleButton::DoGetBestSize() const
87 int lBtn
= m_label
.Length() * 10 + 12 ;
91 if ( UMAHasAquaLayout() )
93 wBtn
+= 2 * kMacOSXHorizontalBorder
;
94 hBtn
+= 2 * kMacOSXVerticalBorder
;
96 return wxSize ( wBtn
, hBtn
) ;
99 void wxToggleButton::SetValue(bool val
)
101 ::SetControl32BitValue( (ControlHandle
) m_macControl
, val
) ;
104 bool wxToggleButton::GetValue() const
106 return GetControl32BitValue( (ControlHandle
) m_macControl
) ;
109 void wxToggleButton::Command(wxCommandEvent
& event
)
111 SetValue((event
.GetInt() != 0));
112 ProcessCommand(event
);
115 void wxToggleButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
117 if ( controlpart
!= kControlNoPart
)
119 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
120 event
.SetInt(GetValue());
121 event
.SetEventObject(this);
122 ProcessCommand(event
);
126 #endif // wxUSE_TOGGLEBTN