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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
22 #pragma implementation "button.h"
25 #include "wx/wxprec.h"
29 #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 m_macIsUserPane
= FALSE
;
61 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
66 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
68 m_peer
= new wxMacControl() ;
69 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
70 kControlBevelButtonNormalBevel
, kControlBehaviorToggles
, NULL
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
73 MacPostControlCreate(pos
,size
) ;
78 wxSize
wxToggleButton::DoGetBestSize() const
83 int lBtn
= m_label
.Length() * 8 + 12 ;
87 return wxSize ( wBtn
, hBtn
) ;
90 void wxToggleButton::SetValue(bool val
)
92 m_peer
->SetValue( val
) ;
95 bool wxToggleButton::GetValue() const
97 return m_peer
->GetValue() ;
100 void wxToggleButton::Command(wxCommandEvent
& event
)
102 SetValue((event
.GetInt() != 0));
103 ProcessCommand(event
);
106 wxInt32
wxToggleButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
108 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
109 event
.SetInt(GetValue());
110 event
.SetEventObject(this);
111 ProcessCommand(event
);
115 #endif // wxUSE_TOGGLEBTN