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
, 
  37     // FIXME: this hack is needed because we're called from 
  38     //        wxBitmapButton::Create() with this style and we currently use a 
  39     //        different wxWidgetImpl method (CreateBitmapButton() rather than 
  40     //        CreateButton()) for creating bitmap buttons, but we really ought 
  41     //        to unify the creation of buttons of all kinds and then remove 
  43     if ( style 
& wxBU_NOTEXT 
) 
  45         return wxControl::Create(parent
, id
, pos
, size
, style
, 
  50     if (label
.empty() && wxIsStockID(id
) && !(id 
== wxID_HELP
)) 
  51         label 
= wxGetStockLabel(id
); 
  53     m_macIsUserPane 
= false ; 
  55     if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
  61     m_peer 
= wxWidgetImpl::CreateButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ); 
  63     MacPostControlCreate( pos
, size 
); 
  68 void wxButton::SetLabel(const wxString
& label
) 
  70     if ( GetId() == wxID_HELP 
|| HasFlag(wxBU_NOTEXT
) ) 
  72         // just store the label internally but don't really use it for the 
  79     wxButtonBase::SetLabel(label
); 
  82 // there is no support for button bitmaps in wxOSX/Carbon so there is no need 
  83 // for these methods there 
  86 wxBitmap 
wxButton::DoGetBitmap(State which
) const 
  88     return which 
== State_Normal 
? m_peer
->GetBitmap() : wxBitmap(); 
  91 void wxButton::DoSetBitmap(const wxBitmap
& bitmap
, State which
) 
  93     if ( which 
== State_Normal 
) 
  94         m_peer
->SetBitmap(bitmap
); 
  97 void wxButton::DoSetBitmapPosition(wxDirection dir
) 
  99     m_peer
->SetBitmapPosition(dir
); 
 102 #endif // wxOSX_USE_COCOA 
 104 wxWindow 
*wxButton::SetDefault() 
 106     wxWindow 
*btnOldDefault 
= wxButtonBase::SetDefault(); 
 110         btnOldDefault
->GetPeer()->SetDefaultButton( false ); 
 113     m_peer
->SetDefaultButton( true ); 
 115     return btnOldDefault
; 
 118 void wxButton::Command (wxCommandEvent 
& WXUNUSED(event
)) 
 120     m_peer
->PerformClick() ; 
 121     // ProcessCommand(event); 
 124 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec
) ) 
 126     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
); 
 127     event
.SetEventObject(this); 
 128     ProcessCommand(event
); 
 132 //------------------------------------------------------- 
 133 // wxDisclosureTriangle 
 134 //------------------------------------------------------- 
 136 bool wxDisclosureTriangle::Create(wxWindow 
*parent
, wxWindowID id
, const wxString
& label
, 
 137    const wxPoint
& pos
, const wxSize
& size
, long style
,const wxValidator
& validator
, const wxString
& name 
) 
 139     m_macIsUserPane 
= false ; 
 141     if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
 144     m_peer 
= wxWidgetImpl::CreateDisclosureTriangle(this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ); 
 146     MacPostControlCreate( pos
, size 
); 
 147     // passing the text in the param doesn't seem to work, so lets do it again 
 153 void wxDisclosureTriangle::SetOpen( bool open 
) 
 155     m_peer
->SetValue( open 
? 1 : 0 ); 
 158 bool wxDisclosureTriangle::IsOpen() const 
 160    return m_peer
->GetValue() == 1; 
 163 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec
) ) 
 165     // Just emit button event for now 
 166     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
); 
 167     event
.SetEventObject(this); 
 168     ProcessCommand(event
); 
 173 wxSize 
wxDisclosureTriangle::DoGetBestSize() const 
 175     wxSize size 
= wxWindow::DoGetBestSize(); 
 177     // under Carbon the base class GetBestSize() implementation doesn't seem to 
 178     // take the label into account at all, correct for it here 
 180     size
.x 
+= GetTextExtent(GetLabel()).x
; 
 181 #endif // wxOSX_USE_CARBON