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