]> git.saurik.com Git - wxWidgets.git/blame - src/osx/tglbtn_osx.cpp
Enable another test in wxAnyTestCase under OS X.
[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)
ce7fe42e 34wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, 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
b4354db1
VZ
52 m_marginX =
53 m_marginY = 0;
54
55 // FIXME: this hack is needed because we're called from
56 // wxBitmapToggleButton::Create() with this style and we currently use a
57 // different wxWidgetImpl method (CreateBitmapToggleButton() rather than
58 // CreateToggleButton()) for creating bitmap buttons, but we really ought
59 // to unify the creation of buttons of all kinds and then remove
60 // this check
61 if ( style & wxBU_NOTEXT )
62 {
63 return wxControl::Create(parent, id, pos, size, style,
64 validator, name);
65 }
66
e53b3d16
SC
67 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
68 return false;
03647350 69
e53b3d16
SC
70 m_labelOrig = m_label = label ;
71
22756322 72 SetPeer(wxWidgetImpl::CreateToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )) ;
e53b3d16
SC
73
74 MacPostControlCreate(pos,size) ;
03647350 75
e53b3d16
SC
76 return TRUE;
77}
78
e53b3d16
SC
79void wxToggleButton::SetValue(bool val)
80{
22756322 81 GetPeer()->SetValue( val ) ;
e53b3d16
SC
82}
83
84bool wxToggleButton::GetValue() const
85{
22756322 86 return GetPeer()->GetValue() ;
e53b3d16
SC
87}
88
89void wxToggleButton::Command(wxCommandEvent & event)
90{
91 SetValue((event.GetInt() != 0));
92 ProcessCommand(event);
93}
94
03647350 95bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16 96{
ce7fe42e 97 wxCommandEvent event(wxEVT_TOGGLEBUTTON, m_windowId);
e53b3d16
SC
98 event.SetInt(GetValue());
99 event.SetEventObject(this);
100 ProcessCommand(event);
101 return true ;
102}
103
104// ----------------------------------------------------------------------------
105// wxBitmapToggleButton
106// ----------------------------------------------------------------------------
107
b4354db1 108IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton)
e53b3d16
SC
109
110bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id,
111 const wxBitmap& label,
112 const wxPoint& pos,
113 const wxSize& size, long style,
114 const wxValidator& validator,
115 const wxString& name)
116{
d15694e8
SC
117 DontCreatePeer();
118
b4354db1
VZ
119 if ( !wxToggleButton::Create(parent, id, wxEmptyString, pos, size, style | wxBU_NOTEXT | wxBU_EXACTFIT, validator, name) )
120 return false;
03647350 121
11a449ac
RR
122 m_marginX =
123 m_marginY = wxDEFAULT_BUTTON_MARGIN;
03647350 124
b4354db1 125 m_bitmaps[State_Normal] = label;
03647350 126
22756322 127 SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ));
e53b3d16
SC
128
129 MacPostControlCreate(pos,size) ;
03647350 130
e53b3d16
SC
131 return TRUE;
132}
133
e53b3d16
SC
134#endif // wxUSE_TOGGLEBTN
135