]> git.saurik.com Git - wxWidgets.git/blame - src/osx/button_osx.cpp
remove run-time check for now-required GTK 2.4
[wxWidgets.git] / src / osx / button_osx.cpp
CommitLineData
e53b3d16
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/button_osx.cpp
3// Purpose: wxButton
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
b5b208a1 7// RCS-ID: $Id$
e53b3d16
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/button.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/panel.h"
18 #include "wx/toplevel.h"
19 #include "wx/dcclient.h"
01495abf 20 #include "wx/stattext.h"
e53b3d16
SC
21#endif
22
23#include "wx/stockitem.h"
24
25#include "wx/osx/private.h"
26
01495abf
VZ
27namespace
28{
29
30// Returns true only if the id is wxID_HELP and the label is "Help" or empty.
31bool IsHelpButtonWithStandardLabel(wxWindowID id, const wxString& label)
32{
33 if ( id != wxID_HELP )
34 return false;
35
36 if ( label.empty() )
37 return true;
38
39 const wxString labelText = wxStaticText::GetLabelText(label);
40 return labelText == "Help" || labelText == _("Help");
41}
42
43} // anonymous namespace
44
e53b3d16
SC
45bool wxButton::Create(wxWindow *parent,
46 wxWindowID id,
01495abf 47 const wxString& labelOrig,
e53b3d16
SC
48 const wxPoint& pos,
49 const wxSize& size,
50 long style,
51 const wxValidator& validator,
52 const wxString& name)
53{
d15694e8
SC
54 DontCreatePeer();
55
b38dc31f
SC
56 m_marginX =
57 m_marginY = 0;
58
8e4c2912
VZ
59 // FIXME: this hack is needed because we're called from
60 // wxBitmapButton::Create() with this style and we currently use a
61 // different wxWidgetImpl method (CreateBitmapButton() rather than
62 // CreateButton()) for creating bitmap buttons, but we really ought
63 // to unify the creation of buttons of all kinds and then remove
64 // this check
65 if ( style & wxBU_NOTEXT )
66 {
2ac0ac7c 67 return wxControl::Create(parent, id, pos, size, style,
8e4c2912
VZ
68 validator, name);
69 }
70
01495abf
VZ
71 wxString label;
72
73 // Ignore the standard label for help buttons if possible, they use "?"
74 // label under Mac which looks better.
75 if ( !IsHelpButtonWithStandardLabel(id, labelOrig) )
76 {
77 label = labelOrig.empty() && wxIsStockID(id) ? wxGetStockLabel(id)
78 : labelOrig;
79 }
e53b3d16 80
e53b3d16
SC
81
82 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
83 return false;
84
85284ca4
VZ
85 m_labelOrig =
86 m_label = label ;
4644cfba 87
22756322 88 SetPeer(wxWidgetImpl::CreateButton( this, parent, id, label, pos, size, style, GetExtraStyle() ));
e53b3d16
SC
89
90 MacPostControlCreate( pos, size );
91
92 return true;
93}
94
85284ca4
VZ
95void wxButton::SetLabel(const wxString& label)
96{
01495abf
VZ
97 if ( IsHelpButtonWithStandardLabel(GetId(), label) )
98 {
99 // ignore the standard label for the help buttons, it's not used
100 return;
101 }
102
b4354db1 103 wxAnyButton::SetLabel(label);
f672c969
VZ
104}
105
e53b3d16
SC
106wxWindow *wxButton::SetDefault()
107{
108 wxWindow *btnOldDefault = wxButtonBase::SetDefault();
109
110 if ( btnOldDefault )
111 {
112 btnOldDefault->GetPeer()->SetDefaultButton( false );
113 }
114
22756322 115 GetPeer()->SetDefaultButton( true );
e53b3d16
SC
116
117 return btnOldDefault;
118}
119
0faf03bf 120void wxButton::Command (wxCommandEvent & WXUNUSED(event))
e53b3d16 121{
22756322 122 GetPeer()->PerformClick() ;
e53b3d16
SC
123 // ProcessCommand(event);
124}
125
0faf03bf 126bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
127{
128 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
129 event.SetEventObject(this);
130 ProcessCommand(event);
131 return true;
132}
133
888cd683
RD
134/* static */
135wxSize wxButtonBase::GetDefaultSize()
136{
137 return wxAnyButton::GetDefaultSize();
138}
139
e53b3d16
SC
140//-------------------------------------------------------
141// wxDisclosureTriangle
142//-------------------------------------------------------
143
144bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label,
145 const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name )
d15694e8
SC
146{
147 DontCreatePeer();
e53b3d16
SC
148 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
149 return false;
150
22756322 151 SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() ));
e53b3d16
SC
152
153 MacPostControlCreate( pos, size );
4c51a665 154 // passing the text in the param doesn't seem to work, so let's do it again
e53b3d16 155 SetLabel( label );
4644cfba 156
e53b3d16
SC
157 return true;
158}
159
160void wxDisclosureTriangle::SetOpen( bool open )
161{
22756322 162 GetPeer()->SetValue( open ? 1 : 0 );
e53b3d16
SC
163}
164
165bool wxDisclosureTriangle::IsOpen() const
166{
22756322 167 return GetPeer()->GetValue() == 1;
e53b3d16
SC
168}
169
0faf03bf 170bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
171{
172 // Just emit button event for now
173 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
174 event.SetEventObject(this);
175 ProcessCommand(event);
176
177 return true;
178}
179
180wxSize wxDisclosureTriangle::DoGetBestSize() const
181{
4644cfba
VZ
182 wxSize size = wxWindow::DoGetBestSize();
183
184 // under Carbon the base class GetBestSize() implementation doesn't seem to
185 // take the label into account at all, correct for it here
186#if wxOSX_USE_CARBON
187 size.x += GetTextExtent(GetLabel()).x;
188#endif // wxOSX_USE_CARBON
189
190 return size;
e53b3d16
SC
191}
192