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
) )
46 m_labelOrig
= m_label
= label
;
48 m_peer
= wxWidgetImpl::CreateButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() );
50 MacPostControlCreate( pos
, size
);
55 wxWindow
*wxButton::SetDefault()
57 wxWindow
*btnOldDefault
= wxButtonBase::SetDefault();
61 btnOldDefault
->GetPeer()->SetDefaultButton( false );
64 m_peer
->SetDefaultButton( true );
69 void wxButton::Command (wxCommandEvent
& WXUNUSED(event
))
71 m_peer
->PerformClick() ;
72 // ProcessCommand(event);
75 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
77 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
78 event
.SetEventObject(this);
79 ProcessCommand(event
);
83 //-------------------------------------------------------
84 // wxDisclosureTriangle
85 //-------------------------------------------------------
87 bool wxDisclosureTriangle::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
88 const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name
)
90 m_macIsUserPane
= false ;
92 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
95 m_peer
= wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() );
97 MacPostControlCreate( pos
, size
);
98 // passing the text in the param doesn't seem to work, so lets do it again
104 void wxDisclosureTriangle::SetOpen( bool open
)
106 m_peer
->SetValue( open
? 1 : 0 );
109 bool wxDisclosureTriangle::IsOpen() const
111 return m_peer
->GetValue() == 1;
114 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) )
116 // Just emit button event for now
117 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
118 event
.SetEventObject(this);
119 ProcessCommand(event
);
124 wxSize
wxDisclosureTriangle::DoGetBestSize() const
126 wxSize size
= wxWindow::DoGetBestSize();
128 // under Carbon the base class GetBestSize() implementation doesn't seem to
129 // take the label into account at all, correct for it here
131 size
.x
+= GetTextExtent(GetLabel()).x
;
132 #endif // wxOSX_USE_CARBON