]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/tglbtn.cpp
changing code that doesn't work on 10.5 as advertised
[wxWidgets.git] / src / mac / carbon / tglbtn.cpp
CommitLineData
eabe6af8
SC
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
6// Modified by:
7// Created: 08.02.01
8// RCS-ID: $Id$
92e6d869
SC
9// Copyright: (c) Stefan Csomor
10// License: wxWindows license
eabe6af8
SC
11/////////////////////////////////////////////////////////////////////////////
12
13// ============================================================================
14// declatations
15// ============================================================================
16
17// ----------------------------------------------------------------------------
18// headers
19// ----------------------------------------------------------------------------
20
3d1a4878 21#include "wx/wxprec.h"
eabe6af8
SC
22
23#if wxUSE_TOGGLEBTN
24
3d1a4878 25#include "wx/tglbtn.h"
eabe6af8
SC
26#include "wx/mac/uma.h"
27// Button
28
eabe6af8
SC
29// ----------------------------------------------------------------------------
30// macros
31// ----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
34DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
35
36// ============================================================================
37// implementation
38// ============================================================================
eabe6af8
SC
39// ----------------------------------------------------------------------------
40// wxToggleButton
41// ----------------------------------------------------------------------------
42
eabe6af8
SC
43bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
44 const wxString& label,
45 const wxPoint& pos,
46 const wxSize& size, long style,
47 const wxValidator& validator,
48 const wxString& name)
49{
facd6764
SC
50 m_macIsUserPane = FALSE ;
51
eabe6af8
SC
52 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
53 return false;
eabe6af8 54
ab0f37b9 55 m_labelOrig = m_label = label ;
eabe6af8 56
facd6764 57 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
4c37f124 58
b905d6cc 59 m_peer = new wxMacControl(this) ;
4c37f124 60 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
5ca0d812 61 kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
21fd5529 62
eabe6af8 63
facd6764 64 MacPostControlCreate(pos,size) ;
eabe6af8
SC
65
66 return TRUE;
67}
68
69wxSize wxToggleButton::DoGetBestSize() const
70{
71 int wBtn = 70 ;
72 int hBtn = 20 ;
73
b635e17f 74 int lBtn = m_label.Length() * 8 + 12 ;
eabe6af8
SC
75 if (lBtn > wBtn)
76 wBtn = lBtn;
77
eabe6af8
SC
78 return wxSize ( wBtn , hBtn ) ;
79}
80
81void wxToggleButton::SetValue(bool val)
82{
5ca0d812 83 m_peer->SetValue( val ) ;
eabe6af8
SC
84}
85
86bool wxToggleButton::GetValue() const
87{
5ca0d812 88 return m_peer->GetValue() ;
eabe6af8
SC
89}
90
91void wxToggleButton::Command(wxCommandEvent & event)
92{
93 SetValue((event.GetInt() != 0));
94 ProcessCommand(event);
95}
96
4c37f124 97wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
eabe6af8 98{
4c37f124
SC
99 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
100 event.SetInt(GetValue());
101 event.SetEventObject(this);
102 ProcessCommand(event);
103 return noErr ;
eabe6af8
SC
104}
105
f8b13b58 106// ----------------------------------------------------------------------------
10ff9c61 107// wxBitmapToggleButton
f8b13b58
RR
108// ----------------------------------------------------------------------------
109
10ff9c61 110IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl)
f8b13b58 111
10ff9c61 112bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id,
f8b13b58
RR
113 const wxBitmap& label,
114 const wxPoint& pos,
115 const wxSize& size, long style,
116 const wxValidator& validator,
117 const wxString& name)
118{
119 m_macIsUserPane = FALSE ;
120
121 m_bitmap = label;
122
123 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
124 return false;
125
126 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
127
128 m_peer = new wxMacControl(this) ;
129
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() ) );
134
135 MacPostControlCreate(pos,size) ;
136
137 return TRUE;
138}
139
10ff9c61 140wxSize wxBitmapToggleButton::DoGetBestSize() const
f8b13b58
RR
141{
142 if (!m_bitmap.IsOk())
143 return wxSize(20,20);
144
145 return wxSize ( m_bitmap.GetWidth()+6, m_bitmap.GetHeight()+6 ) ;
146}
147
10ff9c61 148void wxBitmapToggleButton::SetValue(bool val)
f8b13b58
RR
149{
150 m_peer->SetValue( val ) ;
151}
152
10ff9c61 153bool wxBitmapToggleButton::GetValue() const
f8b13b58
RR
154{
155 return m_peer->GetValue() ;
156}
157
10ff9c61 158void wxBitmapToggleButton::Command(wxCommandEvent & event)
f8b13b58
RR
159{
160 SetValue((event.GetInt() != 0));
161 ProcessCommand(event);
162}
163
10ff9c61 164wxInt32 wxBitmapToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
f8b13b58
RR
165{
166 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
167 event.SetInt(GetValue());
168 event.SetEventObject(this);
169 ProcessCommand(event);
170 return noErr ;
171}
172
eabe6af8
SC
173#endif // wxUSE_TOGGLEBTN
174