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"
20 #include "wx/stockitem.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
24 #include "wx/mac/uma.h"
27 static const int kMacOSXHorizontalBorder
= 2 ;
28 static const int kMacOSXVerticalBorder
= 4 ;
30 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& lbl
,
32 const wxSize
& size
, long style
,
33 const wxValidator
& validator
,
37 if (label
.empty() && wxIsStockID(id
))
38 label
= wxGetStockLabel(id
);
40 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
46 if ( UMAHasAquaLayout() )
48 m_macHorizontalBorder
= kMacOSXHorizontalBorder
;
49 m_macVerticalBorder
= kMacOSXVerticalBorder
;
52 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
54 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , 0 , 1,
55 kControlPushButtonProc
, (long) this ) ;
56 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
58 MacPostControlCreate() ;
63 void wxButton::SetDefault()
65 wxWindow
*parent
= GetParent();
66 wxButton
*btnOldDefault
= NULL
;
69 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
71 parent
->SetDefaultItem(this);
75 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
78 ::SetControlData( (ControlHandle
) btnOldDefault
->m_macControl
, kControlButtonPart
,
79 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
81 if ( (ControlHandle
) m_macControl
)
84 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
,
85 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
89 wxSize
wxButton::DoGetBestSize() const
91 wxSize sz
= GetDefaultSize() ;
93 int wBtn
= m_label
.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder
;
95 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
100 wxSize
wxButton::GetDefaultSize()
105 if ( UMAHasAquaLayout() )
107 wBtn
+= 2 * kMacOSXHorizontalBorder
;
108 hBtn
+= 2 * kMacOSXVerticalBorder
;
111 return wxSize(wBtn
, hBtn
);
114 void wxButton::Command (wxCommandEvent
& event
)
116 if ( (ControlHandle
) m_macControl
)
118 HiliteControl( (ControlHandle
) m_macControl
, kControlButtonPart
) ;
119 unsigned long finalTicks
;
120 Delay( 8 , &finalTicks
) ;
121 HiliteControl( (ControlHandle
) m_macControl
, 0 ) ;
123 ProcessCommand (event
);
126 void wxButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
128 if ( controlpart
!= kControlNoPart
)
130 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
131 event
.SetEventObject(this);
132 ProcessCommand(event
);