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 if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
44 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, "\p" , true , 0 , 0 , 1,
45 kControlPushButtonProc
, (long) this ) ;
49 ControlButtonContentInfo info
;
50 info
.contentType
= kControlNoContent
;
51 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,CFSTR(""),
52 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , (ControlRef
*) &m_macControl
) ) ;
54 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
56 MacPostControlCreate(pos
,size
) ;
61 void wxButton::SetDefault()
63 wxWindow
*parent
= GetParent();
64 wxButton
*btnOldDefault
= NULL
;
67 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
69 parent
->SetDefaultItem(this);
73 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
76 ::SetControlData( (ControlRef
) btnOldDefault
->m_macControl
, kControlButtonPart
,
77 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
79 if ( (ControlRef
) m_macControl
)
82 ::SetControlData( (ControlRef
) m_macControl
, kControlButtonPart
,
83 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
87 wxSize
wxButton::DoGetBestSize() const
89 wxSize sz
= GetDefaultSize() ;
92 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
97 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
102 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
108 int wBtn
= m_label
.Length() * charspace
+ 12 ;
110 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
115 wxSize
wxButton::GetDefaultSize()
120 return wxSize(wBtn
, hBtn
);
123 void wxButton::Command (wxCommandEvent
& event
)
125 if ( (ControlRef
) m_macControl
)
127 HiliteControl( (ControlRef
) m_macControl
, kControlButtonPart
) ;
128 unsigned long finalTicks
;
129 Delay( 8 , &finalTicks
) ;
130 HiliteControl( (ControlRef
) m_macControl
, 0 ) ;
132 ProcessCommand (event
);
135 void wxButton::MacHandleControlClick( WXWidget
WXUNUSED(control
) , wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
) )
137 if ( controlpart
!= kControlNoPart
)
139 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
140 event
.SetEventObject(this);
141 ProcessCommand(event
);