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 #if TARGET_API_MAC_OSX
54 //Button height is static in Mac, can't be changed, so we need to force it here
55 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
57 bounds
.bottom
= bounds
.top
+ 20 ;
60 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
62 bounds
.bottom
= bounds
.top
+ 17 ;
65 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
67 bounds
.bottom
= bounds
.top
+ 15 ;
71 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") , m_peer
->GetControlRefAddr() ) );
75 ControlButtonContentInfo info
;
76 info
.contentType
= kControlNoContent
;
77 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,CFSTR(""),
78 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
81 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
83 MacPostControlCreate(pos
,size
) ;
88 void wxButton::SetDefault()
90 wxWindow
*parent
= GetParent();
91 wxButton
*btnOldDefault
= NULL
;
94 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
96 parent
->SetDefaultItem(this);
100 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
101 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
104 wxSize
wxButton::DoGetBestSize() const
106 if ( GetId() == wxID_HELP
)
107 return wxSize( 20 , 20 ) ;
109 wxSize sz
= GetDefaultSize() ;
112 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
117 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
122 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
128 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
129 m_peer
->GetBestRect( &bestsize
) ;
132 if ( EmptyRect( &bestsize
) )
134 wBtn
= m_label
.Length() * charspace
+ 12 ;
138 wBtn
= bestsize
.right
- bestsize
.left
;
139 sz
.y
= bestsize
.bottom
- bestsize
.top
;
142 if (wBtn
> sz
.x
|| ( GetWindowStyle() & wxBU_EXACTFIT
) )
148 wxSize
wxButton::GetDefaultSize()
153 return wxSize(wBtn
, hBtn
);
156 void wxButton::Command (wxCommandEvent
& event
)
158 m_peer
->Flash(kControlButtonPart
) ;
159 ProcessCommand (event
);
162 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
164 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
165 event
.SetEventObject(this);
166 ProcessCommand(event
);