]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/tglbtn.cpp
make wxChoice and wxListBox inherit from wxControlWithItems and not wxControl for...
[wxWidgets.git] / src / mac / carbon / tglbtn.cpp
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$
9 // Copyright: (c) Stefan Csomor
10 // License: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // ============================================================================
14 // declatations
15 // ============================================================================
16
17 // ----------------------------------------------------------------------------
18 // headers
19 // ----------------------------------------------------------------------------
20
21 #include "wx/wxprec.h"
22
23 #if wxUSE_TOGGLEBTN
24
25 #include "wx/tglbtn.h"
26 #include "wx/mac/uma.h"
27 // Button
28
29 // ----------------------------------------------------------------------------
30 // macros
31 // ----------------------------------------------------------------------------
32
33 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
34 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 // ----------------------------------------------------------------------------
41 // wxToggleButton
42 // ----------------------------------------------------------------------------
43
44 // Single check box item
45 bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
46 const wxString& label,
47 const wxPoint& pos,
48 const wxSize& size, long style,
49 const wxValidator& validator,
50 const wxString& name)
51 {
52 m_macIsUserPane = FALSE ;
53
54 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
55 return false;
56
57 m_labelOrig = m_label = label ;
58
59 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
60
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() ) );
64
65
66 MacPostControlCreate(pos,size) ;
67
68 return TRUE;
69 }
70
71 wxSize wxToggleButton::DoGetBestSize() const
72 {
73 int wBtn = 70 ;
74 int hBtn = 20 ;
75
76 int lBtn = m_label.Length() * 8 + 12 ;
77 if (lBtn > wBtn)
78 wBtn = lBtn;
79
80 return wxSize ( wBtn , hBtn ) ;
81 }
82
83 void wxToggleButton::SetValue(bool val)
84 {
85 m_peer->SetValue( val ) ;
86 }
87
88 bool wxToggleButton::GetValue() const
89 {
90 return m_peer->GetValue() ;
91 }
92
93 void wxToggleButton::Command(wxCommandEvent & event)
94 {
95 SetValue((event.GetInt() != 0));
96 ProcessCommand(event);
97 }
98
99 wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
100 {
101 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
102 event.SetInt(GetValue());
103 event.SetEventObject(this);
104 ProcessCommand(event);
105 return noErr ;
106 }
107
108 #endif // wxUSE_TOGGLEBTN
109