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
);
106 wxWindow
*wxButton::SetDefault()
108 wxWindow
*btnOldDefault
= wxButtonBase::SetDefault();
112 btnOldDefault
->GetPeer()->SetDefaultButton( false );
115 GetPeer()->SetDefaultButton( true );
117 return btnOldDefault
;
120 void wxButton::Command (wxCommandEvent
& WXUNUSED(event
))
122 GetPeer()->PerformClick() ;
123 // ProcessCommand(event);
126 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
128 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
129 event
.SetEventObject(this);
130 ProcessCommand(event
);
134 //-------------------------------------------------------
135 // wxDisclosureTriangle
136 //-------------------------------------------------------
138 bool wxDisclosureTriangle::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
139 const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name
)
142 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
145 SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
147 MacPostControlCreate( pos
, size
);
148 // passing the text in the param doesn't seem to work, so let's do it again
154 void wxDisclosureTriangle::SetOpen( bool open
)
156 GetPeer()->SetValue( open
? 1 : 0 );
159 bool wxDisclosureTriangle::IsOpen() const
161 return GetPeer()->GetValue() == 1;
164 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) )
166 // Just emit button event for now
167 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
168 event
.SetEventObject(this);
169 ProcessCommand(event
);
174 wxSize
wxDisclosureTriangle::DoGetBestSize() const
176 wxSize size
= wxWindow::DoGetBestSize();
178 // under Carbon the base class GetBestSize() implementation doesn't seem to
179 // take the label into account at all, correct for it here
181 size
.x
+= GetTextExtent(GetLabel()).x
;
182 #endif // wxOSX_USE_CARBON