]> git.saurik.com Git - wxWidgets.git/blame - src/osx/tglbtn_osx.cpp
Extensive documentation typo patch (closes #13063).
[wxWidgets.git] / src / osx / tglbtn_osx.cpp
CommitLineData
e53b3d16
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/tglbtn_osx.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
b5b208a1 8// RCS-ID: $Id$
e53b3d16 9// Copyright: (c) Stefan Csomor
526954c5 10// Licence: wxWindows licence
e53b3d16
SC
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/osx/private.h"
03647350 27#include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN
e53b3d16
SC
28
29// ----------------------------------------------------------------------------
30// macros
31// ----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
9b11752c 34wxDEFINE_EVENT( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEvent );
e53b3d16
SC
35
36// ============================================================================
37// implementation
38// ============================================================================
39// ----------------------------------------------------------------------------
40// wxToggleButton
41// ----------------------------------------------------------------------------
42
43bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
44 const wxString& label,
45 const wxPoint& pos,
46 const wxSize& size, long style,
47 const wxValidator& validator,
48 const wxString& name)
49{
d15694e8
SC
50 DontCreatePeer();
51
e53b3d16
SC
52 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
53 return false;
03647350 54
e53b3d16
SC
55 m_labelOrig = m_label = label ;
56
22756322 57 SetPeer(wxWidgetImpl::CreateToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )) ;
e53b3d16
SC
58
59 MacPostControlCreate(pos,size) ;
03647350 60
e53b3d16
SC
61 return TRUE;
62}
63
64wxSize wxToggleButton::DoGetBestSize() const
65{
03647350 66 int wBtn = 70 ;
e53b3d16
SC
67 int hBtn = 20 ;
68
69 int lBtn = m_label.Length() * 8 + 12 ;
03647350 70 if (lBtn > wBtn)
e53b3d16
SC
71 wBtn = lBtn;
72
73 return wxSize ( wBtn , hBtn ) ;
74}
75
76void wxToggleButton::SetValue(bool val)
77{
22756322 78 GetPeer()->SetValue( val ) ;
e53b3d16
SC
79}
80
81bool wxToggleButton::GetValue() const
82{
22756322 83 return GetPeer()->GetValue() ;
e53b3d16
SC
84}
85
86void wxToggleButton::Command(wxCommandEvent & event)
87{
88 SetValue((event.GetInt() != 0));
89 ProcessCommand(event);
90}
91
03647350 92bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
93{
94 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
95 event.SetInt(GetValue());
96 event.SetEventObject(this);
97 ProcessCommand(event);
98 return true ;
99}
100
101// ----------------------------------------------------------------------------
102// wxBitmapToggleButton
103// ----------------------------------------------------------------------------
104
105IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl)
106
107bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id,
108 const wxBitmap& label,
109 const wxPoint& pos,
110 const wxSize& size, long style,
111 const wxValidator& validator,
112 const wxString& name)
113{
d15694e8
SC
114 DontCreatePeer();
115
e53b3d16 116 m_bitmap = label;
03647350 117
11a449ac
RR
118 m_marginX =
119 m_marginY = wxDEFAULT_BUTTON_MARGIN;
03647350 120
e53b3d16
SC
121 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
122 return false;
03647350 123
22756322 124 SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ));
e53b3d16
SC
125
126 MacPostControlCreate(pos,size) ;
03647350 127
e53b3d16
SC
128 return TRUE;
129}
130
131wxSize wxBitmapToggleButton::DoGetBestSize() const
132{
133 if (!m_bitmap.IsOk())
134 return wxSize(20,20);
11a449ac
RR
135
136 wxSize best;
137 best.x = m_bitmap.GetWidth() + 2 * m_marginX;
138 best.y = m_bitmap.GetHeight() + 2 * m_marginY;
139
140 return best;
e53b3d16
SC
141}
142
143void wxBitmapToggleButton::SetValue(bool val)
144{
22756322 145 GetPeer()->SetValue( val ) ;
e53b3d16
SC
146}
147
148bool wxBitmapToggleButton::GetValue() const
149{
22756322 150 return GetPeer()->GetValue() ;
e53b3d16
SC
151}
152
153void wxBitmapToggleButton::Command(wxCommandEvent & event)
154{
155 SetValue((event.GetInt() != 0));
156 ProcessCommand(event);
157}
158
03647350 159bool wxBitmapToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
160{
161 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
162 event.SetInt(GetValue());
163 event.SetEventObject(this);
164 ProcessCommand(event);
165 return noErr ;
166}
167
168#endif // wxUSE_TOGGLEBTN
169