1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/button_osx.cpp
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: button.cpp 54845 2008-07-30 14:52:41Z SC $
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"
22 #include "wx/stockitem.h"
24 #include "wx/osx/private.h"
26 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
28 bool wxButton::Create(wxWindow
*parent
,
34 const wxValidator
& validator
,
38 if (label
.empty() && wxIsStockID(id
) && !(id
== wxID_HELP
))
39 label
= wxGetStockLabel(id
);
41 m_macIsUserPane
= false ;
43 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
49 m_peer
= wxWidgetImpl::CreateButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() );
51 MacPostControlCreate( pos
, size
);
56 void wxButton::SetLabel(const wxString
& label
)
58 if ( GetId() == wxID_HELP
|| HasFlag(wxBU_NOTEXT
) )
60 // just store the label internally but don't really use it for the
67 wxButtonBase::SetLabel(label
);
70 wxWindow
*wxButton::SetDefault()
72 wxWindow
*btnOldDefault
= wxButtonBase::SetDefault();
76 btnOldDefault
->GetPeer()->SetDefaultButton( false );
79 m_peer
->SetDefaultButton( true );
84 void wxButton::Command (wxCommandEvent
& WXUNUSED(event
))
86 m_peer
->PerformClick() ;
87 // ProcessCommand(event);
90 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
92 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
93 event
.SetEventObject(this);
94 ProcessCommand(event
);
98 //-------------------------------------------------------
99 // wxDisclosureTriangle
100 //-------------------------------------------------------
102 bool wxDisclosureTriangle::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
103 const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name
)
105 m_macIsUserPane
= false ;
107 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
110 m_peer
= wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() );
112 MacPostControlCreate( pos
, size
);
113 // passing the text in the param doesn't seem to work, so lets do it again
119 void wxDisclosureTriangle::SetOpen( bool open
)
121 m_peer
->SetValue( open
? 1 : 0 );
124 bool wxDisclosureTriangle::IsOpen() const
126 return m_peer
->GetValue() == 1;
129 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) )
131 // Just emit button event for now
132 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
133 event
.SetEventObject(this);
134 ProcessCommand(event
);
139 wxSize
wxDisclosureTriangle::DoGetBestSize() const
141 wxSize size
= wxWindow::DoGetBestSize();
143 // under Carbon the base class GetBestSize() implementation doesn't seem to
144 // take the label into account at all, correct for it here
146 size
.x
+= GetTextExtent(GetLabel()).x
;
147 #endif // wxOSX_USE_CARBON