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 ( id
== wxID_HELP
)
45 ControlButtonContentInfo info
;
46 info
.contentType
= kControlContentIconRef
;
47 GetIconRef(kOnSystemDisk
, kSystemIconsCreator
, kHelpIcon
, &info
.u
.iconRef
);
48 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, kControlRoundButtonNormalSize
,
49 &info
, m_peer
->GetControlRefAddr() ) );
51 else if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
53 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") , m_peer
->GetControlRefAddr() ) );
57 ControlButtonContentInfo info
;
58 info
.contentType
= kControlNoContent
;
59 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,CFSTR(""),
60 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
63 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
65 MacPostControlCreate(pos
,size
) ;
70 void wxButton::SetDefault()
72 wxWindow
*parent
= GetParent();
73 wxButton
*btnOldDefault
= NULL
;
76 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
78 parent
->SetDefaultItem(this);
82 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
83 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
86 wxSize
wxButton::DoGetBestSize() const
88 if ( GetId() == wxID_HELP
)
89 return wxSize( 20 , 20 ) ;
91 wxSize sz
= GetDefaultSize() ;
94 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
99 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
104 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
110 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
111 m_peer
->GetBestRect( &bestsize
) ;
114 if ( EmptyRect( &bestsize
) )
116 wBtn
= m_label
.Length() * charspace
+ 12 ;
120 wBtn
= bestsize
.right
- bestsize
.left
;
121 sz
.y
= bestsize
.bottom
- bestsize
.top
;
124 if (wBtn
> sz
.x
|| ( GetWindowStyle() & wxBU_EXACTFIT
) )
130 wxSize
wxButton::GetDefaultSize()
135 return wxSize(wBtn
, hBtn
);
138 void wxButton::Command (wxCommandEvent
& event
)
140 m_peer
->Flash(kControlButtonPart
) ;
141 ProcessCommand (event
);
144 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
146 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
147 event
.SetEventObject(this);
148 ProcessCommand(event
);