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 // ============================================================================
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 bool wxToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
44 const wxString
& label
,
46 const wxSize
& size
, long style
,
47 const wxValidator
& validator
,
50 m_macIsUserPane
= FALSE
;
52 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
55 m_labelOrig
= m_label
= label
;
57 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
59 m_peer
= new wxMacControl(this) ;
60 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
61 kControlBevelButtonNormalBevel
, kControlBehaviorToggles
, NULL
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
64 MacPostControlCreate(pos
,size
) ;
69 wxSize
wxToggleButton::DoGetBestSize() const
74 int lBtn
= m_label
.Length() * 8 + 12 ;
78 return wxSize ( wBtn
, hBtn
) ;
81 void wxToggleButton::SetValue(bool val
)
83 m_peer
->SetValue( val
) ;
86 bool wxToggleButton::GetValue() const
88 return m_peer
->GetValue() ;
91 void wxToggleButton::Command(wxCommandEvent
& event
)
93 SetValue((event
.GetInt() != 0));
94 ProcessCommand(event
);
97 wxInt32
wxToggleButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
99 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
100 event
.SetInt(GetValue());
101 event
.SetEventObject(this);
102 ProcessCommand(event
);
106 // ----------------------------------------------------------------------------
107 // wxBitmapToggleButton
108 // ----------------------------------------------------------------------------
110 IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton
, wxControl
)
112 bool wxBitmapToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
113 const wxBitmap
& label
,
115 const wxSize
& size
, long style
,
116 const wxValidator
& validator
,
117 const wxString
& name
)
119 m_macIsUserPane
= FALSE
;
123 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
126 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
128 m_peer
= new wxMacControl(this) ;
130 ControlButtonContentInfo info
;
131 wxMacCreateBitmapButton( &info
, m_bitmap
);
132 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
133 kControlBevelButtonNormalBevel
, kControlBehaviorOffsetContents
| kControlBehaviorToggles
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
135 MacPostControlCreate(pos
,size
) ;
140 wxSize
wxBitmapToggleButton::DoGetBestSize() const
142 if (!m_bitmap
.IsOk())
143 return wxSize(20,20);
145 return wxSize ( m_bitmap
.GetWidth()+6, m_bitmap
.GetHeight()+6 ) ;
148 void wxBitmapToggleButton::SetValue(bool val
)
150 m_peer
->SetValue( val
) ;
153 bool wxBitmapToggleButton::GetValue() const
155 return m_peer
->GetValue() ;
158 void wxBitmapToggleButton::Command(wxCommandEvent
& event
)
160 SetValue((event
.GetInt() != 0));
161 ProcessCommand(event
);
164 wxInt32
wxBitmapToggleButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
166 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
167 event
.SetInt(GetValue());
168 event
.SetEventObject(this);
169 ProcessCommand(event
);
173 #endif // wxUSE_TOGGLEBTN