]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/tglbtn.cpp
get rid of one of the extra slashes in the download URLs
[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$
92e6d869
SC
9// Copyright: (c) Stefan Csomor
10// License: wxWindows license
eabe6af8
SC
11/////////////////////////////////////////////////////////////////////////////
12
13// ============================================================================
14// declatations
15// ============================================================================
16
17// ----------------------------------------------------------------------------
18// headers
19// ----------------------------------------------------------------------------
20
3d1a4878 21#include "wx/wxprec.h"
eabe6af8
SC
22
23#if wxUSE_TOGGLEBTN
24
3d1a4878 25#include "wx/tglbtn.h"
eabe6af8
SC
26#include "wx/mac/uma.h"
27// Button
28
eabe6af8
SC
29// ----------------------------------------------------------------------------
30// macros
31// ----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
34DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
35
36// ============================================================================
37// implementation
38// ============================================================================
39
40// ----------------------------------------------------------------------------
41// wxToggleButton
42// ----------------------------------------------------------------------------
43
44// Single check box item
45bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
46 const wxString& label,
47 const wxPoint& pos,
48 const wxSize& size, long style,
49 const wxValidator& validator,
50 const wxString& name)
51{
facd6764
SC
52 m_macIsUserPane = FALSE ;
53
eabe6af8
SC
54 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
55 return false;
eabe6af8 56
facd6764 57 m_label = label ;
eabe6af8 58
facd6764 59 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
4c37f124 60
b905d6cc 61 m_peer = new wxMacControl(this) ;
4c37f124 62 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
5ca0d812 63 kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
21fd5529 64
eabe6af8 65
facd6764 66 MacPostControlCreate(pos,size) ;
eabe6af8
SC
67
68 return TRUE;
69}
70
71wxSize wxToggleButton::DoGetBestSize() const
72{
73 int wBtn = 70 ;
74 int hBtn = 20 ;
75
b635e17f 76 int lBtn = m_label.Length() * 8 + 12 ;
eabe6af8
SC
77 if (lBtn > wBtn)
78 wBtn = lBtn;
79
eabe6af8
SC
80 return wxSize ( wBtn , hBtn ) ;
81}
82
83void wxToggleButton::SetValue(bool val)
84{
5ca0d812 85 m_peer->SetValue( val ) ;
eabe6af8
SC
86}
87
88bool wxToggleButton::GetValue() const
89{
5ca0d812 90 return m_peer->GetValue() ;
eabe6af8
SC
91}
92
93void wxToggleButton::Command(wxCommandEvent & event)
94{
95 SetValue((event.GetInt() != 0));
96 ProcessCommand(event);
97}
98
4c37f124 99wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
eabe6af8 100{
4c37f124
SC
101 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
102 event.SetInt(GetValue());
103 event.SetEventObject(this);
104 ProcessCommand(event);
105 return noErr ;
eabe6af8
SC
106}
107
108#endif // wxUSE_TOGGLEBTN
109