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"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
25 #include "wx/mac/uma.h"
28 static const int kMacOSXHorizontalBorder
= 2 ;
29 static const int kMacOSXVerticalBorder
= 4 ;
31 wxButtonBase::wxButtonBase()
35 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
37 const wxSize
& size
, long style
,
38 const wxValidator
& validator
,
41 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
47 if ( UMAHasAquaLayout() )
49 m_macHorizontalBorder
= kMacOSXHorizontalBorder
;
50 m_macVerticalBorder
= kMacOSXVerticalBorder
;
53 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
55 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , 0 , 1,
56 kControlPushButtonProc
, (long) this ) ;
57 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
59 MacPostControlCreate() ;
64 void wxButton::SetDefault()
66 wxWindow
*parent
= GetParent();
67 wxButton
*btnOldDefault
= NULL
;
70 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
72 parent
->SetDefaultItem(this);
76 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
79 ::SetControlData( (ControlHandle
) btnOldDefault
->m_macControl
, kControlButtonPart
,
80 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
82 if ( (ControlHandle
) m_macControl
)
85 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
,
86 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
90 wxSize
wxButton::DoGetBestSize() const
92 wxSize sz
= GetDefaultSize() ;
94 int wBtn
= m_label
.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder
;
96 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
101 wxSize
wxButton::GetDefaultSize()
106 if ( UMAHasAquaLayout() )
108 wBtn
+= 2 * kMacOSXHorizontalBorder
;
109 hBtn
+= 2 * kMacOSXVerticalBorder
;
112 return wxSize(wBtn
, hBtn
);
115 void wxButton::Command (wxCommandEvent
& event
)
117 if ( (ControlHandle
) m_macControl
)
119 HiliteControl( (ControlHandle
) m_macControl
, kControlButtonPart
) ;
120 unsigned long finalTicks
;
121 Delay( 8 , &finalTicks
) ;
122 HiliteControl( (ControlHandle
) m_macControl
, 0 ) ;
124 ProcessCommand (event
);
127 void wxButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
129 if ( controlpart
!= kControlNoPart
)
131 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
132 event
.SetEventObject(this);
133 ProcessCommand(event
);