1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/button_osx.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/button.h"
18 #include "wx/toplevel.h"
19 #include "wx/dcclient.h"
20 #include "wx/stattext.h"
23 #include "wx/stockitem.h"
25 #include "wx/osx/private.h"
30 // Returns true only if the id is wxID_HELP and the label is "Help" or empty.
31 bool IsHelpButtonWithStandardLabel(wxWindowID id
, const wxString
& label
)
33 if ( id
!= wxID_HELP
)
39 const wxString labelText
= wxStaticText::GetLabelText(label
);
40 return labelText
== "Help" || labelText
== _("Help");
43 } // anonymous namespace
45 bool wxButton::Create(wxWindow
*parent
,
47 const wxString
& labelOrig
,
51 const wxValidator
& validator
,
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
65 if ( style
& wxBU_NOTEXT
)
67 return wxControl::Create(parent
, id
, pos
, size
, style
,
73 // Ignore the standard label for help buttons if possible, they use "?"
74 // label under Mac which looks better.
75 if ( !IsHelpButtonWithStandardLabel(id
, labelOrig
) )
77 label
= labelOrig
.empty() && wxIsStockID(id
) ? wxGetStockLabel(id
)
82 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
88 SetPeer(wxWidgetImpl::CreateButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
90 MacPostControlCreate( pos
, size
);
95 void wxButton::SetLabel(const wxString
& label
)
97 if ( IsHelpButtonWithStandardLabel(GetId(), label
) )
99 // ignore the standard label for the help buttons, it's not used
103 wxAnyButton::SetLabel(label
);
105 OSXUpdateAfterLabelChange(label
);
109 wxWindow
*wxButton::SetDefault()
111 wxWindow
*btnOldDefault
= wxButtonBase::SetDefault();
115 btnOldDefault
->GetPeer()->SetDefaultButton( false );
118 GetPeer()->SetDefaultButton( true );
120 return btnOldDefault
;
123 void wxButton::Command (wxCommandEvent
& WXUNUSED(event
))
125 GetPeer()->PerformClick() ;
126 // ProcessCommand(event);
129 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
131 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
132 event
.SetEventObject(this);
133 ProcessCommand(event
);
138 wxSize
wxButtonBase::GetDefaultSize()
140 return wxAnyButton::GetDefaultSize();
143 //-------------------------------------------------------
144 // wxDisclosureTriangle
145 //-------------------------------------------------------
147 bool wxDisclosureTriangle::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
148 const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name
)
151 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
154 SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
156 MacPostControlCreate( pos
, size
);
157 // passing the text in the param doesn't seem to work, so let's do it again
163 void wxDisclosureTriangle::SetOpen( bool open
)
165 GetPeer()->SetValue( open
? 1 : 0 );
168 bool wxDisclosureTriangle::IsOpen() const
170 return GetPeer()->GetValue() == 1;
173 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) )
175 // Just emit button event for now
176 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
177 event
.SetEventObject(this);
178 ProcessCommand(event
);
183 wxSize
wxDisclosureTriangle::DoGetBestSize() const
185 wxSize size
= wxWindow::DoGetBestSize();
187 // under Carbon the base class GetBestSize() implementation doesn't seem to
188 // take the label into account at all, correct for it here
190 size
.x
+= GetTextExtent(GetLabel()).x
;
191 #endif // wxOSX_USE_CARBON