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
->GetControlRefAddr() ) );
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
->GetControlRefAddr() ) );
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 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
100 m_peer
->GetBestRect( &bestsize
) ;
103 if ( EmptyRect( &bestsize
) )
105 int wBtn
= m_label
.Length() * charspace
+ 12 ;
109 wBtn
= bestsize
.right
- bestsize
.left
;
110 sz
.y
= bestsize
.bottom
- bestsize
.top
;
113 if (wBtn
> sz
.x
|| ( GetWindowStyle() & wxBU_EXACTFIT
) )
119 wxSize
wxButton::GetDefaultSize()
124 return wxSize(wBtn
, hBtn
);
127 void wxButton::Command (wxCommandEvent
& event
)
129 m_peer
->Flash(kControlButtonPart
) ;
130 ProcessCommand (event
);
133 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
135 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
136 event
.SetEventObject(this);
137 ProcessCommand(event
);