1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/button.cpp 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  18 #include "wx/button.h" 
  24 #include "wx/stockitem.h" 
  26 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
) 
  28 #include "wx/mac/uma.h" 
  31 static const int kMacOSXHorizontalBorder 
= 2 ; 
  32 static const int kMacOSXVerticalBorder 
= 4 ; 
  34 bool wxButton::Create(wxWindow 
*parent
, wxWindowID id
, const wxString
& lbl
, 
  36            const wxSize
& size
, long style
, 
  37            const wxValidator
& validator
, 
  41     if (label
.empty() && wxIsStockID(id
)) 
  42         label 
= wxGetStockLabel(id
); 
  44     if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
  50     if ( UMAHasAquaLayout() ) 
  52         m_macHorizontalBorder 
= kMacOSXHorizontalBorder
; 
  53         m_macVerticalBorder 
= kMacOSXVerticalBorder
; 
  56     MacPreControlCreate( parent 
, id 
,  label 
, pos 
, size 
,style
, validator 
, name 
, &bounds 
, title 
) ; 
  58     m_macControl 
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 0 , 0 , 1, 
  59           kControlPushButtonProc 
, (long) this ) ; 
  60     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, wxT("No valid mac control") ) ; 
  62     MacPostControlCreate() ; 
  67 void wxButton::SetDefault() 
  69     wxWindow 
*parent 
= GetParent(); 
  70     wxButton 
*btnOldDefault 
= NULL
; 
  73         btnOldDefault 
= wxDynamicCast(parent
->GetDefaultItem(), 
  75         parent
->SetDefaultItem(this); 
  79     if ( btnOldDefault 
&& btnOldDefault
->m_macControl 
) 
  82         ::SetControlData( (ControlHandle
) btnOldDefault
->m_macControl 
, kControlButtonPart 
, 
  83                            kControlPushButtonDefaultTag 
, sizeof( Boolean 
) , (char*)(&inData
) ) ; 
  85     if ( (ControlHandle
) m_macControl 
) 
  88         ::SetControlData(  (ControlHandle
) m_macControl 
, kControlButtonPart 
, 
  89                            kControlPushButtonDefaultTag 
, sizeof( Boolean 
) , (char*)(&inData
) ) ; 
  93 wxSize 
wxButton::DoGetBestSize() const 
  95     wxSize sz 
= GetDefaultSize() ; 
  97     int wBtn 
= m_label
.length() * 8 + 12 + 2 * kMacOSXHorizontalBorder 
; 
  99     if (wBtn 
> sz
.x
) sz
.x 
= wBtn
; 
 104 wxSize 
wxButton::GetDefaultSize() 
 109     if ( UMAHasAquaLayout() ) 
 111         wBtn 
+= 2 * kMacOSXHorizontalBorder 
; 
 112         hBtn 
+= 2 * kMacOSXVerticalBorder 
; 
 115     return wxSize(wBtn
, hBtn
); 
 118 void wxButton::Command (wxCommandEvent 
& event
) 
 120     if ( (ControlHandle
) m_macControl 
) 
 122         HiliteControl(  (ControlHandle
) m_macControl 
, kControlButtonPart 
) ; 
 123         unsigned long finalTicks 
; 
 124         Delay( 8 , &finalTicks 
) ; 
 125         HiliteControl(  (ControlHandle
) m_macControl 
, 0 ) ; 
 127     ProcessCommand (event
); 
 130 void wxButton::MacHandleControlClick( WXWidget 
WXUNUSED(control
) , wxInt16 controlpart 
, bool WXUNUSED(mouseStillDown
) ) 
 132     if ( controlpart 
!= kControlNoPart 
) 
 134         wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId 
); 
 135         event
.SetEventObject(this); 
 136         ProcessCommand(event
);