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) Stefan Csomor
10 // License: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/wxprec.h"
25 #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 m_macIsUserPane
= FALSE
;
57 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
62 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
64 m_peer
= new wxMacControl(this) ;
65 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
66 kControlBevelButtonNormalBevel
, kControlBehaviorToggles
, NULL
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
69 MacPostControlCreate(pos
,size
) ;
74 wxSize
wxToggleButton::DoGetBestSize() const
79 int lBtn
= m_label
.Length() * 8 + 12 ;
83 return wxSize ( wBtn
, hBtn
) ;
86 void wxToggleButton::SetValue(bool val
)
88 m_peer
->SetValue( val
) ;
91 bool wxToggleButton::GetValue() const
93 return m_peer
->GetValue() ;
96 void wxToggleButton::Command(wxCommandEvent
& event
)
98 SetValue((event
.GetInt() != 0));
99 ProcessCommand(event
);
102 wxInt32
wxToggleButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
104 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
105 event
.SetInt(GetValue());
106 event
.SetEventObject(this);
107 ProcessCommand(event
);
111 #endif // wxUSE_TOGGLEBTN