]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/tglbtn.cpp
add wxTLW::UseNativeDecorations[ByDefault]() to allow the programmer to control wheth...
[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 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 m_macIsUserPane = FALSE ;
56
57 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
58 return false;
59
60 m_label = label ;
61
62 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
63
64 m_peer = new wxMacControl(this) ;
65 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
66 kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
67
68
69 MacPostControlCreate(pos,size) ;
70
71 return TRUE;
72 }
73
74 wxSize wxToggleButton::DoGetBestSize() const
75 {
76 int wBtn = 70 ;
77 int hBtn = 20 ;
78
79 int lBtn = m_label.Length() * 8 + 12 ;
80 if (lBtn > wBtn)
81 wBtn = lBtn;
82
83 return wxSize ( wBtn , hBtn ) ;
84 }
85
86 void wxToggleButton::SetValue(bool val)
87 {
88 m_peer->SetValue( val ) ;
89 }
90
91 bool wxToggleButton::GetValue() const
92 {
93 return m_peer->GetValue() ;
94 }
95
96 void wxToggleButton::Command(wxCommandEvent & event)
97 {
98 SetValue((event.GetInt() != 0));
99 ProcessCommand(event);
100 }
101
102 wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
103 {
104 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
105 event.SetInt(GetValue());
106 event.SetEventObject(this);
107 ProcessCommand(event);
108 return noErr ;
109 }
110
111 #endif // wxUSE_TOGGLEBTN
112