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 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
30 const wxSize
& size
, long style
,
31 const wxValidator
& validator
,
34 m_macIsUserPane
= FALSE
;
36 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
41 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
42 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, "\p" , true , 0 , 0 , 1,
43 kControlPushButtonProc
, (long) this ) ;
44 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
46 MacPostControlCreate(pos
,size
) ;
51 void wxButton::SetDefault()
53 wxWindow
*parent
= GetParent();
54 wxButton
*btnOldDefault
= NULL
;
57 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
59 parent
->SetDefaultItem(this);
63 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
66 ::SetControlData( (ControlRef
) btnOldDefault
->m_macControl
, kControlButtonPart
,
67 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
69 if ( (ControlRef
) m_macControl
)
72 ::SetControlData( (ControlRef
) m_macControl
, kControlButtonPart
,
73 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
77 wxSize
wxButton::DoGetBestSize() const
79 wxSize sz
= GetDefaultSize() ;
82 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
87 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
92 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
98 int wBtn
= m_label
.Length() * charspace
+ 12 ;
100 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
105 wxSize
wxButton::GetDefaultSize()
110 return wxSize(wBtn
, hBtn
);
113 void wxButton::Command (wxCommandEvent
& event
)
115 if ( (ControlRef
) m_macControl
)
117 HiliteControl( (ControlRef
) m_macControl
, kControlButtonPart
) ;
118 unsigned long finalTicks
;
119 Delay( 8 , &finalTicks
) ;
120 HiliteControl( (ControlRef
) m_macControl
, 0 ) ;
122 ProcessCommand (event
);
125 void wxButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
127 if ( controlpart
!= kControlNoPart
)
129 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
130 event
.SetEventObject(this);
131 ProcessCommand(event
);