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 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
33 const wxSize
& size
, long style
,
34 const wxValidator
& validator
,
37 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
43 if ( UMAHasAquaLayout() )
45 m_macHorizontalBorder
= kMacOSXHorizontalBorder
;
46 m_macVerticalBorder
= kMacOSXVerticalBorder
;
49 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
51 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , 0 , 1,
52 kControlPushButtonProc
, (long) this ) ;
53 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
55 MacPostControlCreate() ;
60 void wxButton::SetDefault()
62 wxWindow
*parent
= GetParent();
63 wxButton
*btnOldDefault
= NULL
;
66 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
68 parent
->SetDefaultItem(this);
72 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
75 ::SetControlData( (ControlHandle
) btnOldDefault
->m_macControl
, kControlButtonPart
,
76 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
78 if ( (ControlHandle
) m_macControl
)
81 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
,
82 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
86 wxSize
wxButton::DoGetBestSize() const
88 wxSize sz
= GetDefaultSize() ;
90 int wBtn
= m_label
.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder
;
92 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
97 wxSize
wxButton::GetDefaultSize()
102 if ( UMAHasAquaLayout() )
104 wBtn
+= 2 * kMacOSXHorizontalBorder
;
105 hBtn
+= 2 * kMacOSXVerticalBorder
;
108 return wxSize(wBtn
, hBtn
);
111 void wxButton::Command (wxCommandEvent
& event
)
113 if ( (ControlHandle
) m_macControl
)
115 HiliteControl( (ControlHandle
) m_macControl
, kControlButtonPart
) ;
116 unsigned long finalTicks
;
117 Delay( 8 , &finalTicks
) ;
118 HiliteControl( (ControlHandle
) m_macControl
, 0 ) ;
120 ProcessCommand (event
);
123 void wxButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
125 if ( controlpart
!= kControlNoPart
)
127 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
128 event
.SetEventObject(this);
129 ProcessCommand(event
);