]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/tglbtn.cpp
Include wx/stattext.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / mac / classic / tglbtn.cpp
CommitLineData
2646f485 1/////////////////////////////////////////////////////////////////////////////
18f3decb 2// Name: src/mac/classic/tglbtn.cpp
2646f485
SC
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
18f3decb
WS
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
2646f485
SC
19// ============================================================================
20// declatations
21// ============================================================================
22
23// ----------------------------------------------------------------------------
24// headers
25// ----------------------------------------------------------------------------
26
2646f485
SC
27#include "wx/tglbtn.h"
28
29#if wxUSE_TOGGLEBTN
30
31#include "wx/mac/uma.h"
32// Button
33
34static const int kMacOSXHorizontalBorder = 2 ;
35static const int kMacOSXVerticalBorder = 4 ;
36
37// ----------------------------------------------------------------------------
38// macros
39// ----------------------------------------------------------------------------
40
41IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
42DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
43
44// ============================================================================
45// implementation
46// ============================================================================
47
48// ----------------------------------------------------------------------------
49// wxToggleButton
50// ----------------------------------------------------------------------------
51
52// Single check box item
53bool 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 }
18f3decb 71
2646f485
SC
72 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
73
18f3decb 74 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , kControlBehaviorToggles , 1,
2646f485
SC
75 kControlBevelButtonNormalBevelProc , (long) this ) ;
76 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
18f3decb 77
2646f485 78 MacPostControlCreate() ;
18f3decb
WS
79
80 return true;
2646f485
SC
81}
82
83wxSize wxToggleButton::DoGetBestSize() const
84{
18f3decb 85 int wBtn = 70 ;
2646f485
SC
86 int hBtn = 20 ;
87
88 int lBtn = m_label.Length() * 8 + 12 ;
18f3decb 89 if (lBtn > wBtn)
2646f485
SC
90 wBtn = lBtn;
91
92 if ( UMAHasAquaLayout() )
93 {
94 wBtn += 2 * kMacOSXHorizontalBorder ;
95 hBtn += 2 * kMacOSXVerticalBorder ;
96 }
97 return wxSize ( wBtn , hBtn ) ;
98}
99
100void wxToggleButton::SetValue(bool val)
101{
102 ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ;
103}
104
105bool wxToggleButton::GetValue() const
106{
107 return GetControl32BitValue( (ControlHandle) m_macControl ) ;
108}
109
110void wxToggleButton::Command(wxCommandEvent & event)
111{
112 SetValue((event.GetInt() != 0));
113 ProcessCommand(event);
114}
115
18f3decb 116void wxToggleButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
2646f485
SC
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