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 // there is no support for button bitmaps in wxOSX/Carbon so there is no need
71 // for these methods there
74 wxBitmap
wxButton::DoGetBitmap(State which
) const
76 return which
== State_Normal
? m_peer
->GetBitmap() : wxBitmap();
79 void wxButton::DoSetBitmap(const wxBitmap
& bitmap
, State which
)
81 if ( which
== State_Normal
)
82 m_peer
->SetBitmap(bitmap
);
85 void wxButton::DoSetBitmapPosition(wxDirection dir
)
87 m_peer
->SetBitmapPosition(dir
);
90 #endif // wxOSX_USE_COCOA
92 wxWindow
*wxButton::SetDefault()
94 wxWindow
*btnOldDefault
= wxButtonBase::SetDefault();
98 btnOldDefault
->GetPeer()->SetDefaultButton( false );
101 m_peer
->SetDefaultButton( true );
103 return btnOldDefault
;
106 void wxButton::Command (wxCommandEvent
& WXUNUSED(event
))
108 m_peer
->PerformClick() ;
109 // ProcessCommand(event);
112 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
114 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
115 event
.SetEventObject(this);
116 ProcessCommand(event
);
120 //-------------------------------------------------------
121 // wxDisclosureTriangle
122 //-------------------------------------------------------
124 bool wxDisclosureTriangle::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
125 const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name
)
127 m_macIsUserPane
= false ;
129 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
132 m_peer
= wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() );
134 MacPostControlCreate( pos
, size
);
135 // passing the text in the param doesn't seem to work, so lets do it again
141 void wxDisclosureTriangle::SetOpen( bool open
)
143 m_peer
->SetValue( open
? 1 : 0 );
146 bool wxDisclosureTriangle::IsOpen() const
148 return m_peer
->GetValue() == 1;
151 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) )
153 // Just emit button event for now
154 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
155 event
.SetEventObject(this);
156 ProcessCommand(event
);
161 wxSize
wxDisclosureTriangle::DoGetBestSize() const
163 wxSize size
= wxWindow::DoGetBestSize();
165 // under Carbon the base class GetBestSize() implementation doesn't seem to
166 // take the label into account at all, correct for it here
168 size
.x
+= GetTextExtent(GetLabel()).x
;
169 #endif // wxOSX_USE_CARBON