1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "button.h" 
  18 #include "wx/button.h" 
  20 #include "wx/stockitem.h" 
  22 #if !USE_SHARED_LIBRARY 
  23 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
) 
  26 #include "wx/mac/uma.h" 
  29 static const int kMacOSXHorizontalBorder 
= 2 ; 
  30 static const int kMacOSXVerticalBorder 
= 4 ; 
  32 bool wxButton::Create(wxWindow 
*parent
, wxWindowID id
, const wxString
& lbl
, 
  34            const wxSize
& size
, long style
, 
  35            const wxValidator
& validator
, 
  39     if (label
.empty() && wxIsStockID(id
)) 
  40         label 
= wxGetStockLabel(id
); 
  42     if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
  48     if ( UMAHasAquaLayout() ) 
  50         m_macHorizontalBorder 
= kMacOSXHorizontalBorder
; 
  51         m_macVerticalBorder 
= kMacOSXVerticalBorder
; 
  54     MacPreControlCreate( parent 
, id 
,  label 
, pos 
, size 
,style
, validator 
, name 
, &bounds 
, title 
) ; 
  56     m_macControl 
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 0 , 0 , 1,  
  57           kControlPushButtonProc 
, (long) this ) ; 
  58     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, wxT("No valid mac control") ) ; 
  60     MacPostControlCreate() ; 
  65 void wxButton::SetDefault() 
  67     wxWindow 
*parent 
= GetParent(); 
  68     wxButton 
*btnOldDefault 
= NULL
; 
  71         btnOldDefault 
= wxDynamicCast(parent
->GetDefaultItem(), 
  73         parent
->SetDefaultItem(this); 
  77     if ( btnOldDefault 
&& btnOldDefault
->m_macControl 
) 
  80         ::SetControlData( (ControlHandle
) btnOldDefault
->m_macControl 
, kControlButtonPart 
, 
  81                            kControlPushButtonDefaultTag 
, sizeof( Boolean 
) , (char*)(&inData
) ) ; 
  83     if ( (ControlHandle
) m_macControl 
) 
  86         ::SetControlData(  (ControlHandle
) m_macControl 
, kControlButtonPart 
, 
  87                            kControlPushButtonDefaultTag 
, sizeof( Boolean 
) , (char*)(&inData
) ) ; 
  91 wxSize 
wxButton::DoGetBestSize() const 
  93   wxSize sz 
= GetDefaultSize() ; 
  95   int wBtn 
= m_label
.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder 
; 
  97   if (wBtn 
> sz
.x
) sz
.x 
= wBtn
; 
 102 wxSize 
wxButton::GetDefaultSize() 
 107     if ( UMAHasAquaLayout() ) 
 109         wBtn 
+= 2 * kMacOSXHorizontalBorder 
; 
 110         hBtn 
+= 2 * kMacOSXVerticalBorder 
; 
 113     return wxSize(wBtn
, hBtn
); 
 116 void wxButton::Command (wxCommandEvent 
& event
) 
 118     if ( (ControlHandle
) m_macControl 
) 
 120         HiliteControl(  (ControlHandle
) m_macControl 
, kControlButtonPart 
) ; 
 121         unsigned long finalTicks 
; 
 122         Delay( 8 , &finalTicks 
) ; 
 123         HiliteControl(  (ControlHandle
) m_macControl 
, 0 ) ; 
 125     ProcessCommand (event
); 
 128 void wxButton::MacHandleControlClick( WXWidget 
WXUNUSED(control
) , wxInt16 controlpart 
, bool WXUNUSED(mouseStillDown
) )  
 130     if ( controlpart 
!= kControlNoPart 
) 
 132         wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId 
); 
 133         event
.SetEventObject(this); 
 134         ProcessCommand(event
);