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
);
135 wxSize
wxButtonBase::GetDefaultSize()
137 return wxAnyButton::GetDefaultSize();
140 //-------------------------------------------------------
141 // wxDisclosureTriangle
142 //-------------------------------------------------------
144 bool wxDisclosureTriangle::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
145 const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name
)
148 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
151 SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
153 MacPostControlCreate( pos
, size
);
154 // passing the text in the param doesn't seem to work, so let's do it again
160 void wxDisclosureTriangle::SetOpen( bool open
)
162 GetPeer()->SetValue( open
? 1 : 0 );
165 bool wxDisclosureTriangle::IsOpen() const
167 return GetPeer()->GetValue() == 1;
170 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) )
172 // Just emit button event for now
173 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
174 event
.SetEventObject(this);
175 ProcessCommand(event
);
180 wxSize
wxDisclosureTriangle::DoGetBestSize() const
182 wxSize size
= wxWindow::DoGetBestSize();
184 // under Carbon the base class GetBestSize() implementation doesn't seem to
185 // take the label into account at all, correct for it here
187 size
.x
+= GetTextExtent(GetLabel()).x
;
188 #endif // wxOSX_USE_CARBON