]> git.saurik.com Git - wxWidgets.git/blame - src/osx/button_osx.cpp
Fix compilation with MinGW -std=c++11 option.
[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{
8e4c2912
VZ
54 // FIXME: this hack is needed because we're called from
55 // wxBitmapButton::Create() with this style and we currently use a
56 // different wxWidgetImpl method (CreateBitmapButton() rather than
57 // CreateButton()) for creating bitmap buttons, but we really ought
58 // to unify the creation of buttons of all kinds and then remove
59 // this check
ce63f2e9 60 if ( style & wxBU_NOTEXT && !ShouldCreatePeer() )
8e4c2912 61 {
2ac0ac7c 62 return wxControl::Create(parent, id, pos, size, style,
8e4c2912
VZ
63 validator, name);
64 }
65
ce63f2e9
VZ
66 DontCreatePeer();
67
68 m_marginX =
69 m_marginY = 0;
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);
0afa3752 104#if wxOSX_USE_COCOA
5af80d31 105 OSXUpdateAfterLabelChange(label);
0afa3752 106#endif
f672c969
VZ
107}
108
e53b3d16
SC
109wxWindow *wxButton::SetDefault()
110{
111 wxWindow *btnOldDefault = wxButtonBase::SetDefault();
112
113 if ( btnOldDefault )
114 {
115 btnOldDefault->GetPeer()->SetDefaultButton( false );
116 }
117
22756322 118 GetPeer()->SetDefaultButton( true );
e53b3d16
SC
119
120 return btnOldDefault;
121}
122
0faf03bf 123void wxButton::Command (wxCommandEvent & WXUNUSED(event))
e53b3d16 124{
22756322 125 GetPeer()->PerformClick() ;
e53b3d16
SC
126 // ProcessCommand(event);
127}
128
0faf03bf 129bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
130{
131 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
132 event.SetEventObject(this);
133 ProcessCommand(event);
134 return true;
135}
136
888cd683
RD
137/* static */
138wxSize wxButtonBase::GetDefaultSize()
139{
140 return wxAnyButton::GetDefaultSize();
141}
142
e53b3d16
SC
143//-------------------------------------------------------
144// wxDisclosureTriangle
145//-------------------------------------------------------
146
147bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label,
148 const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name )
d15694e8
SC
149{
150 DontCreatePeer();
e53b3d16
SC
151 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
152 return false;
153
22756322 154 SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() ));
e53b3d16
SC
155
156 MacPostControlCreate( pos, size );
4c51a665 157 // passing the text in the param doesn't seem to work, so let's do it again
e53b3d16 158 SetLabel( label );
4644cfba 159
e53b3d16
SC
160 return true;
161}
162
163void wxDisclosureTriangle::SetOpen( bool open )
164{
22756322 165 GetPeer()->SetValue( open ? 1 : 0 );
e53b3d16
SC
166}
167
168bool wxDisclosureTriangle::IsOpen() const
169{
22756322 170 return GetPeer()->GetValue() == 1;
e53b3d16
SC
171}
172
0faf03bf 173bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
174{
175 // Just emit button event for now
176 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
177 event.SetEventObject(this);
178 ProcessCommand(event);
179
180 return true;
181}
182
183wxSize wxDisclosureTriangle::DoGetBestSize() const
184{
4644cfba
VZ
185 wxSize size = wxWindow::DoGetBestSize();
186
187 // under Carbon the base class GetBestSize() implementation doesn't seem to
188 // take the label into account at all, correct for it here
189#if wxOSX_USE_CARBON
190 size.x += GetTextExtent(GetLabel()).x;
191#endif // wxOSX_USE_CARBON
192
193 return size;
e53b3d16
SC
194}
195