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 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") , (ControlRef
*) &m_macControl
) ) ;
48 ControlButtonContentInfo info
;
49 info
.contentType
= kControlNoContent
;
50 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,CFSTR(""),
51 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , (ControlRef
*) &m_macControl
) ) ;
53 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
55 MacPostControlCreate(pos
,size
) ;
60 void wxButton::SetDefault()
62 wxWindow
*parent
= GetParent();
63 wxButton
*btnOldDefault
= NULL
;
66 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
68 parent
->SetDefaultItem(this);
72 if ( btnOldDefault
&& btnOldDefault
->m_macControl
)
75 ::SetControlData( (ControlRef
) btnOldDefault
->m_macControl
, kControlButtonPart
,
76 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
78 if ( (ControlRef
) m_macControl
)
81 ::SetControlData( (ControlRef
) m_macControl
, kControlButtonPart
,
82 kControlPushButtonDefaultTag
, sizeof( Boolean
) , (char*)(&inData
) ) ;
86 wxSize
wxButton::DoGetBestSize() const
88 wxSize sz
= GetDefaultSize() ;
91 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
96 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
101 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
107 int wBtn
= m_label
.Length() * charspace
+ 12 ;
109 if (wBtn
> sz
.x
) sz
.x
= wBtn
;
114 wxSize
wxButton::GetDefaultSize()
119 return wxSize(wBtn
, hBtn
);
122 void wxButton::Command (wxCommandEvent
& event
)
124 if ( (ControlRef
) m_macControl
)
126 HiliteControl( (ControlRef
) m_macControl
, kControlButtonPart
) ;
127 unsigned long finalTicks
;
128 Delay( 8 , &finalTicks
) ;
129 HiliteControl( (ControlRef
) m_macControl
, 0 ) ;
131 ProcessCommand (event
);
134 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
136 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
137 event
.SetEventObject(this);
138 ProcessCommand(event
);