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_peer
= new wxMacControl() ;
43 if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
45 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") , *m_peer
) );
49 ControlButtonContentInfo info
;
50 info
.contentType
= kControlNoContent
;
51 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,CFSTR(""),
52 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , *m_peer
) );
55 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
57 MacPostControlCreate(pos
,size
) ;
62 void wxButton::SetDefault()
64 wxWindow
*parent
= GetParent();
65 wxButton
*btnOldDefault
= NULL
;
68 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
70 parent
->SetDefaultItem(this);
74 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
75 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
78 wxSize
wxButton::DoGetBestSize() const
80 wxSize sz
= GetDefaultSize() ;
83 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
88 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
93 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
99 int wBtn
= m_label
.Length() * charspace
+ 12 ;
101 if (wBtn
> sz
.x
|| ( GetWindowStyle() & wxBU_EXACTFIT
) )
107 wxSize
wxButton::GetDefaultSize()
112 return wxSize(wBtn
, hBtn
);
115 void wxButton::Command (wxCommandEvent
& event
)
117 m_peer
->Flash(kControlButtonPart
) ;
118 ProcessCommand (event
);
121 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
123 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
124 event
.SetEventObject(this);
125 ProcessCommand(event
);