]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/button_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/button_osx.cpp
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/button.h"
17 #include "wx/toplevel.h"
18 #include "wx/dcclient.h"
19 #include "wx/stattext.h"
22 #include "wx/stockitem.h"
24 #include "wx/osx/private.h"
29 // Returns true only if the id is wxID_HELP and the label is "Help" or empty.
30 bool IsHelpButtonWithStandardLabel(wxWindowID id
, const wxString
& label
)
32 if ( id
!= wxID_HELP
)
38 const wxString labelText
= wxStaticText::GetLabelText(label
);
39 return labelText
== "Help" || labelText
== _("Help");
42 } // anonymous namespace
44 bool wxButton::Create(wxWindow
*parent
,
46 const wxString
& labelOrig
,
50 const wxValidator
& validator
,
53 // FIXME: this hack is needed because we're called from
54 // wxBitmapButton::Create() with this style and we currently use a
55 // different wxWidgetImpl method (CreateBitmapButton() rather than
56 // CreateButton()) for creating bitmap buttons, but we really ought
57 // to unify the creation of buttons of all kinds and then remove
59 if ( style
& wxBU_NOTEXT
&& !ShouldCreatePeer() )
61 return wxControl::Create(parent
, id
, pos
, size
, style
,
72 // Ignore the standard label for help buttons if possible, they use "?"
73 // label under Mac which looks better.
74 if ( !IsHelpButtonWithStandardLabel(id
, labelOrig
) )
76 label
= labelOrig
.empty() && wxIsStockID(id
) ? wxGetStockLabel(id
)
81 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
87 SetPeer(wxWidgetImpl::CreateButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
89 MacPostControlCreate( pos
, size
);
94 void wxButton::SetLabel(const wxString
& label
)
96 if ( IsHelpButtonWithStandardLabel(GetId(), label
) )
98 // ignore the standard label for the help buttons, it's not used
102 wxAnyButton::SetLabel(label
);
104 OSXUpdateAfterLabelChange(label
);
108 wxWindow
*wxButton::SetDefault()
110 wxWindow
*btnOldDefault
= wxButtonBase::SetDefault();
114 btnOldDefault
->GetPeer()->SetDefaultButton( false );
117 GetPeer()->SetDefaultButton( true );
119 return btnOldDefault
;
122 void wxButton::Command (wxCommandEvent
& WXUNUSED(event
))
124 GetPeer()->PerformClick() ;
125 // ProcessCommand(event);
128 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
130 wxCommandEvent
event(wxEVT_BUTTON
, m_windowId
);
131 event
.SetEventObject(this);
132 ProcessCommand(event
);
137 wxSize
wxButtonBase::GetDefaultSize()
139 return wxAnyButton::GetDefaultSize();
142 //-------------------------------------------------------
143 // wxDisclosureTriangle
144 //-------------------------------------------------------
146 bool wxDisclosureTriangle::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
147 const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name
)
150 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
153 SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
155 MacPostControlCreate( pos
, size
);
156 // passing the text in the param doesn't seem to work, so let's do it again
162 void wxDisclosureTriangle::SetOpen( bool open
)
164 GetPeer()->SetValue( open
? 1 : 0 );
167 bool wxDisclosureTriangle::IsOpen() const
169 return GetPeer()->GetValue() == 1;
172 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) )
174 // Just emit button event for now
175 wxCommandEvent
event(wxEVT_BUTTON
, m_windowId
);
176 event
.SetEventObject(this);
177 ProcessCommand(event
);
182 wxSize
wxDisclosureTriangle::DoGetBestSize() const
184 wxSize size
= wxWindow::DoGetBestSize();
186 // under Carbon the base class GetBestSize() implementation doesn't seem to
187 // take the label into account at all, correct for it here
189 size
.x
+= GetTextExtent(GetLabel()).x
;
190 #endif // wxOSX_USE_CARBON