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 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
34 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
36 // ============================================================================
38 // ============================================================================
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // Single check box item
45 bool wxToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
46 const wxString
& label
,
48 const wxSize
& size
, long style
,
49 const wxValidator
& validator
,
52 m_macIsUserPane
= FALSE
;
54 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
57 m_labelOrig
= m_label
= label
;
59 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
61 m_peer
= new wxMacControl(this) ;
62 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
63 kControlBevelButtonNormalBevel
, kControlBehaviorToggles
, NULL
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
66 MacPostControlCreate(pos
,size
) ;
71 wxSize
wxToggleButton::DoGetBestSize() const
76 int lBtn
= m_label
.Length() * 8 + 12 ;
80 return wxSize ( wBtn
, hBtn
) ;
83 void wxToggleButton::SetValue(bool val
)
85 m_peer
->SetValue( val
) ;
88 bool wxToggleButton::GetValue() const
90 return m_peer
->GetValue() ;
93 void wxToggleButton::Command(wxCommandEvent
& event
)
95 SetValue((event
.GetInt() != 0));
96 ProcessCommand(event
);
99 wxInt32
wxToggleButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
101 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
102 event
.SetInt(GetValue());
103 event
.SetEventObject(this);
104 ProcessCommand(event
);
108 #endif // wxUSE_TOGGLEBTN