]> git.saurik.com Git - wxWidgets.git/blame - src/osx/tglbtn_osx.cpp
Try to display '...' text on editor buttons more consistently on wxGTK. This is done...
[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"
27// Button
28
29// ----------------------------------------------------------------------------
30// macros
31// ----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
34DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
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
92bool wxToggleButton::HandleClicked( double timestampsec )
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
118 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
119 return false;
120
121 m_peer = wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ) ;
122
123 MacPostControlCreate(pos,size) ;
124
125 return TRUE;
126}
127
128wxSize wxBitmapToggleButton::DoGetBestSize() const
129{
130 if (!m_bitmap.IsOk())
131 return wxSize(20,20);
132
133 return wxSize ( m_bitmap.GetWidth()+6, m_bitmap.GetHeight()+6 ) ;
134}
135
136void wxBitmapToggleButton::SetValue(bool val)
137{
138 m_peer->SetValue( val ) ;
139}
140
141bool wxBitmapToggleButton::GetValue() const
142{
143 return m_peer->GetValue() ;
144}
145
146void wxBitmapToggleButton::Command(wxCommandEvent & event)
147{
148 SetValue((event.GetInt() != 0));
149 ProcessCommand(event);
150}
151
152bool wxBitmapToggleButton::HandleClicked( double timestampsec )
153{
154 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
155 event.SetInt(GetValue());
156 event.SetEventObject(this);
157 ProcessCommand(event);
158 return noErr ;
159}
160
161#endif // wxUSE_TOGGLEBTN
162