1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/button.h"
16 #include "wx/stockitem.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
20 #include "wx/mac/uma.h"
23 static const int kMacOSXHorizontalBorder
= 2 ;
24 static const int kMacOSXVerticalBorder
= 4 ;
26 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& lbl
,
28 const wxSize
& size
, long style
,
29 const wxValidator
& validator
,
33 if (label
.empty() && wxIsStockID(id
))
34 label
= wxGetStockLabel(id
);
36 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
42 if ( UMAHasAquaLayout() )
44 m_macHorizontalBorder
= kMacOSXHorizontalBorder
;
45 m_macVerticalBorder
= kMacOSXVerticalBorder
;
48 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
50 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , 0 , 1,
51 kControlPushButtonProc
, (long) this ) ;
52 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
54 MacPostControlCreate() ;
59 void wxButton::SetDefault()
61 wxWindow
*parent
= GetParent();
62 wxButton
*btnOldDefault
= NULL
;
65 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
67 parent
->SetDefaultItem(this);
71 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
74 ::SetControlData( (ControlHandle
) btnOldDefault
->m_macControl
, kControlButtonPart
,
75 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
77 if ( (ControlHandle
) m_macControl
)
80 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
,
81 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
85 wxSize
wxButton::DoGetBestSize() const
87 wxSize sz
= GetDefaultSize() ;
89 int wBtn
= m_label
.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder
;
91 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
96 wxSize
wxButton::GetDefaultSize()
101 if ( UMAHasAquaLayout() )
103 wBtn
+= 2 * kMacOSXHorizontalBorder
;
104 hBtn
+= 2 * kMacOSXVerticalBorder
;
107 return wxSize(wBtn
, hBtn
);
110 void wxButton::Command (wxCommandEvent
& event
)
112 if ( (ControlHandle
) m_macControl
)
114 HiliteControl( (ControlHandle
) m_macControl
, kControlButtonPart
) ;
115 unsigned long finalTicks
;
116 Delay( 8 , &finalTicks
) ;
117 HiliteControl( (ControlHandle
) m_macControl
, 0 ) ;
119 ProcessCommand (event
);
122 void wxButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
124 if ( controlpart
!= kControlNoPart
)
126 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
127 event
.SetEventObject(this);
128 ProcessCommand(event
);