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
= 1 ;
29 static const int kMacOSXVerticalBorder
= 1 ;
31 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
33 const wxSize
& size
, long style
,
34 const wxValidator
& validator
,
40 if ( UMAHasAquaLayout() )
42 m_macHorizontalBorder
= kMacOSXHorizontalBorder
;
43 m_macVerticalBorder
= kMacOSXVerticalBorder
;
46 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
48 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , 0 , 1,
49 kControlPushButtonProc
, (long) this ) ;
50 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
52 MacPostControlCreate() ;
57 void wxButton::SetDefault()
59 wxWindow
*parent
= GetParent();
60 wxButton
*btnOldDefault
= NULL
;
63 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
65 parent
->SetDefaultItem(this);
69 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
72 ::SetControlData( (ControlHandle
) btnOldDefault
->m_macControl
, kControlButtonPart
,
73 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
75 if ( (ControlHandle
) m_macControl
)
78 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
,
79 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
83 wxSize
wxButton::DoGetBestSize() const
85 wxSize sz
= GetDefaultSize() ;
87 int wBtn
= m_label
.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder
;
89 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
94 wxSize
wxButton::GetDefaultSize()
99 if ( UMAHasAquaLayout() )
101 wBtn
+= 2 * kMacOSXHorizontalBorder
;
102 hBtn
+= 2 * kMacOSXVerticalBorder
;
105 return wxSize(wBtn
, hBtn
);
108 void wxButton::Command (wxCommandEvent
& event
)
110 if ( (ControlHandle
) m_macControl
)
112 HiliteControl( (ControlHandle
) m_macControl
, kControlButtonPart
) ;
113 unsigned long finalTicks
;
114 Delay( 8 , &finalTicks
) ;
115 HiliteControl( (ControlHandle
) m_macControl
, 0 ) ;
117 ProcessCommand (event
);
120 void wxButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
122 if ( controlpart
!= kControlNoPart
)
124 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
125 event
.SetEventObject(this);
126 ProcessCommand(event
);