1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
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>
29 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
31 const wxSize
& size
, long style
,
32 const wxValidator
& validator
,
38 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
40 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, false , 0 , 0 , 1,
41 kControlPushButtonProc
, (long) this ) ;
42 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
44 MacPostControlCreate() ;
49 void wxButton::SetDefault()
51 wxWindow
*parent
= GetParent();
52 wxButton
*btnOldDefault
= NULL
;
53 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
56 btnOldDefault
= wxDynamicCast(panel
->GetDefaultItem(),
58 panel
->SetDefaultItem(this);
63 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
66 UMASetControlData( btnOldDefault
->m_macControl
, kControlButtonPart
,
67 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
72 UMASetControlData( m_macControl
, kControlButtonPart
,
73 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
76 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
78 UMASetControlData( btnOldDefault
->m_macControl
, kControlButtonPart
,
79 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)((Boolean
)0) ) ;
83 UMASetControlData( m_macControl
, kControlButtonPart
,
84 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)((Boolean
)1) ) ;
89 wxSize
wxButton::DoGetBestSize() const
91 wxSize sz
= GetDefaultSize() ;
93 int wBtn
= m_label
.Length() * 8 + 12 ;
96 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
97 if (hBtn
> sz
.y
) sz
.y
= hBtn
;
102 wxSize
wxButton::GetDefaultSize()
104 int wBtn
= 70 /* + 2 * m_macHorizontalBorder */ ;
105 int hBtn
= 20 /* + 2 * m_macVerticalBorder */ ;
107 return wxSize(wBtn
, hBtn
);
110 void wxButton::Command (wxCommandEvent
& event
)
114 HiliteControl( m_macControl
, kControlButtonPart
) ;
115 unsigned long finalTicks
;
116 Delay( 8 , &finalTicks
) ;
117 HiliteControl( m_macControl
, 0 ) ;
119 ProcessCommand (event
);
122 void wxButton::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
124 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
125 event
.SetEventObject(this);
126 ProcessCommand(event
);