1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/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 #include "wx/wxprec.h" 
  19 // ============================================================================ 
  21 // ============================================================================ 
  23 // ---------------------------------------------------------------------------- 
  25 // ---------------------------------------------------------------------------- 
  27 #include "wx/tglbtn.h" 
  31 #include "wx/mac/uma.h" 
  34 static const int kMacOSXHorizontalBorder 
= 2 ; 
  35 static const int kMacOSXVerticalBorder 
= 4 ; 
  37 // ---------------------------------------------------------------------------- 
  39 // ---------------------------------------------------------------------------- 
  41 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
) 
  42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
) 
  44 // ============================================================================ 
  46 // ============================================================================ 
  48 // ---------------------------------------------------------------------------- 
  50 // ---------------------------------------------------------------------------- 
  52 // Single check box item 
  53 bool wxToggleButton::Create(wxWindow 
*parent
, wxWindowID id
, 
  54                             const wxString
& label
, 
  56                             const wxSize
& size
, long style
, 
  57                             const wxValidator
& validator
, 
  60     if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
  66     if ( UMAHasAquaLayout() ) 
  68         m_macHorizontalBorder 
= kMacOSXHorizontalBorder
; 
  69         m_macVerticalBorder 
= kMacOSXVerticalBorder
; 
  72     MacPreControlCreate( parent 
, id 
,  label 
, pos 
, size 
,style
, validator 
, name 
, &bounds 
, title 
) ; 
  74     m_macControl 
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 0 , kControlBehaviorToggles 
, 1, 
  75           kControlBevelButtonNormalBevelProc  
, (long) this ) ; 
  76     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, wxT("No valid mac control") ) ; 
  78     MacPostControlCreate() ; 
  83 wxSize 
wxToggleButton::DoGetBestSize() const 
  88     int lBtn 
= m_label
.Length() * 8 + 12 ; 
  92     if ( UMAHasAquaLayout() ) 
  94         wBtn 
+= 2 * kMacOSXHorizontalBorder 
; 
  95         hBtn 
+= 2 * kMacOSXVerticalBorder 
; 
  97     return wxSize ( wBtn 
, hBtn 
) ; 
 100 void wxToggleButton::SetValue(bool val
) 
 102     ::SetControl32BitValue( (ControlHandle
) m_macControl 
, val 
) ; 
 105 bool wxToggleButton::GetValue() const 
 107     return GetControl32BitValue( (ControlHandle
) m_macControl 
) ; 
 110 void wxToggleButton::Command(wxCommandEvent 
& event
) 
 112    SetValue((event
.GetInt() != 0)); 
 113    ProcessCommand(event
); 
 116 void wxToggleButton::MacHandleControlClick( WXWidget 
WXUNUSED(control
) , wxInt16 controlpart 
, bool WXUNUSED(mouseStillDown
) ) 
 118     if ( controlpart 
!= kControlNoPart 
) 
 120         wxCommandEvent 
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
); 
 121         event
.SetInt(GetValue()); 
 122         event
.SetEventObject(this); 
 123         ProcessCommand(event
); 
 127 #endif // wxUSE_TOGGLEBTN