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