1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "button.h"
16 #include "wx/button.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
20 #include <wx/mac/uma.h>
24 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
26 const wxSize
& size
, long style
,
27 const wxValidator
& validator
,
32 m_macHorizontalBorder
= 2 ; // additional pixels around the real control
33 m_macVerticalBorder
= 2 ;
35 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
37 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , 0 , 1,
38 kControlPushButtonProc
, (long) this ) ;
39 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
41 MacPostControlCreate() ;
46 void wxButton::SetDefault()
48 wxWindow
*parent
= GetParent();
49 wxButton
*btnOldDefault
= NULL
;
50 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
53 btnOldDefault
= panel
->GetDefaultItem();
54 panel
->SetDefaultItem(this);
57 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
59 UMASetControlData( btnOldDefault
->m_macControl
, kControlButtonPart
, kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)((Boolean
)0) ) ;
63 UMASetControlData( m_macControl
, kControlButtonPart
, kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)((Boolean
)1) ) ;
67 wxSize
wxButton::DoGetBestSize() const
69 int wBtn
= m_label
.Length() * 8 + 12 + 2 * m_macHorizontalBorder
;
70 int hBtn
= 13 + 2 * m_macVerticalBorder
;
72 return wxSize(wBtn
, hBtn
);
75 wxSize
wxButton::GetDefaultSize()
77 int wBtn
= 15 * 8 + 12 + 2 * 2;
78 int hBtn
= 13 + 2 * 2;
80 return wxSize(wBtn
, hBtn
);
83 void wxButton::Command (wxCommandEvent
& event
)
85 ProcessCommand (event
);
88 void wxButton::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
90 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
91 event
.SetEventObject(this);
92 ProcessCommand(event
);