]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/tglbtn.cpp
Unused variable removal.
[wxWidgets.git] / src / mac / classic / tglbtn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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) 2000 Johnny C. Norris II
10 // License: Rocketeer license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 // ============================================================================
20 // declatations
21 // ============================================================================
22
23 // ----------------------------------------------------------------------------
24 // headers
25 // ----------------------------------------------------------------------------
26
27 #include "wx/tglbtn.h"
28
29 #if wxUSE_TOGGLEBTN
30
31 #include "wx/mac/uma.h"
32 // Button
33
34 static const int kMacOSXHorizontalBorder = 2 ;
35 static const int kMacOSXVerticalBorder = 4 ;
36
37 // ----------------------------------------------------------------------------
38 // macros
39 // ----------------------------------------------------------------------------
40
41 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
43
44 // ============================================================================
45 // implementation
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 // wxToggleButton
50 // ----------------------------------------------------------------------------
51
52 // Single check box item
53 bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
54 const wxString& label,
55 const wxPoint& pos,
56 const wxSize& size, long style,
57 const wxValidator& validator,
58 const wxString& name)
59 {
60 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
61 return false;
62
63 Rect bounds ;
64 Str255 title ;
65
66 if ( UMAHasAquaLayout() )
67 {
68 m_macHorizontalBorder = kMacOSXHorizontalBorder;
69 m_macVerticalBorder = kMacOSXVerticalBorder;
70 }
71
72 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
73
74 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , kControlBehaviorToggles , 1,
75 kControlBevelButtonNormalBevelProc , (long) this ) ;
76 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
77
78 MacPostControlCreate() ;
79
80 return true;
81 }
82
83 wxSize wxToggleButton::DoGetBestSize() const
84 {
85 int wBtn = 70 ;
86 int hBtn = 20 ;
87
88 int lBtn = m_label.Length() * 8 + 12 ;
89 if (lBtn > wBtn)
90 wBtn = lBtn;
91
92 if ( UMAHasAquaLayout() )
93 {
94 wBtn += 2 * kMacOSXHorizontalBorder ;
95 hBtn += 2 * kMacOSXVerticalBorder ;
96 }
97 return wxSize ( wBtn , hBtn ) ;
98 }
99
100 void wxToggleButton::SetValue(bool val)
101 {
102 ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ;
103 }
104
105 bool wxToggleButton::GetValue() const
106 {
107 return GetControl32BitValue( (ControlHandle) m_macControl ) ;
108 }
109
110 void wxToggleButton::Command(wxCommandEvent & event)
111 {
112 SetValue((event.GetInt() != 0));
113 ProcessCommand(event);
114 }
115
116 void wxToggleButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
117 {
118 if ( controlpart != kControlNoPart )
119 {
120 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
121 event.SetInt(GetValue());
122 event.SetEventObject(this);
123 ProcessCommand(event);
124 }
125 }
126
127 #endif // wxUSE_TOGGLEBTN