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