]> git.saurik.com Git - wxWidgets.git/blame - src/osx/tglbtn_osx.cpp
rename wxDECLARE_LOCAL_EVENT to just wxDECLARE_EVENT
[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
8// RCS-ID: $Id: tglbtn.cpp 54129 2008-06-11 19:30:52Z SC $
9// Copyright: (c) Stefan Csomor
10// License: wxWindows license
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"
166040cf 27#include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN
e53b3d16
SC
28
29// ----------------------------------------------------------------------------
30// macros
31// ----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
3c778901 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{
50 m_macIsUserPane = FALSE ;
51
52 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
53 return false;
54
55 m_labelOrig = m_label = label ;
56
57 m_peer = wxWidgetImpl::CreateToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ) ;
58
59 MacPostControlCreate(pos,size) ;
60
61 return TRUE;
62}
63
64wxSize wxToggleButton::DoGetBestSize() const
65{
66 int wBtn = 70 ;
67 int hBtn = 20 ;
68
69 int lBtn = m_label.Length() * 8 + 12 ;
70 if (lBtn > wBtn)
71 wBtn = lBtn;
72
73 return wxSize ( wBtn , hBtn ) ;
74}
75
76void wxToggleButton::SetValue(bool val)
77{
78 m_peer->SetValue( val ) ;
79}
80
81bool wxToggleButton::GetValue() const
82{
83 return m_peer->GetValue() ;
84}
85
86void wxToggleButton::Command(wxCommandEvent & event)
87{
88 SetValue((event.GetInt() != 0));
89 ProcessCommand(event);
90}
91
4eb5a0ec 92bool wxToggleButton::OSXHandleClicked( double 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{
114 m_macIsUserPane = FALSE ;
115
116 m_bitmap = label;
117
11a449ac
RR
118 m_marginX =
119 m_marginY = wxDEFAULT_BUTTON_MARGIN;
120
e53b3d16
SC
121 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
122 return false;
123
124 m_peer = wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ) ;
125
126 MacPostControlCreate(pos,size) ;
127
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{
145 m_peer->SetValue( val ) ;
146}
147
148bool wxBitmapToggleButton::GetValue() const
149{
150 return m_peer->GetValue() ;
151}
152
153void wxBitmapToggleButton::Command(wxCommandEvent & event)
154{
155 SetValue((event.GetInt() != 0));
156 ProcessCommand(event);
157}
158
4eb5a0ec 159bool wxBitmapToggleButton::OSXHandleClicked( double 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