1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/button.h"
16 #include "wx/stockitem.h"
18 #include "wx/mac/uma.h"
20 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
23 bool wxButton::Create(wxWindow
*parent
,
29 const wxValidator
& validator
,
33 if (label
.empty() && wxIsStockID(id
))
34 label
= wxGetStockLabel(id
);
36 m_macIsUserPane
= false ;
38 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
43 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
44 m_peer
= new wxMacControl(this) ;
45 if ( id
== wxID_HELP
)
47 ControlButtonContentInfo info
;
48 info
.contentType
= kControlContentIconRef
;
49 GetIconRef(kOnSystemDisk
, kSystemIconsCreator
, kHelpIcon
, &info
.u
.iconRef
);
50 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, kControlRoundButtonNormalSize
,
51 &info
, m_peer
->GetControlRefAddr() ) );
53 else if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
55 #if TARGET_API_MAC_OSX
56 // Button height is static in Mac, can't be changed, so we need to force it here
57 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
59 bounds
.bottom
= bounds
.top
+ 20 ;
62 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
64 bounds
.bottom
= bounds
.top
+ 17 ;
67 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
69 bounds
.bottom
= bounds
.top
+ 15 ;
74 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") , m_peer
->GetControlRefAddr() ) );
78 ControlButtonContentInfo info
;
79 info
.contentType
= kControlNoContent
;
80 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR(""),
81 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
84 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid Mac control") ) ;
86 MacPostControlCreate(pos
, size
) ;
91 void wxButton::SetDefault()
93 wxWindow
*parent
= GetParent();
94 wxButton
*btnOldDefault
= NULL
;
98 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
99 parent
->SetDefaultItem(this);
103 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
105 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
108 wxSize
wxButton::DoGetBestSize() const
110 if ( GetId() == wxID_HELP
)
111 return wxSize( 20 , 20 ) ;
113 wxSize sz
= GetDefaultSize() ;
116 switch (GetWindowVariant())
118 case wxWINDOW_VARIANT_NORMAL
:
119 case wxWINDOW_VARIANT_LARGE
:
124 case wxWINDOW_VARIANT_SMALL
:
128 case wxWINDOW_VARIANT_MINI
:
136 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
137 m_peer
->GetBestRect( &bestsize
) ;
140 if ( EmptyRect( &bestsize
) )
142 wBtn
= m_label
.Length() * charspace
+ 12 ;
146 wBtn
= bestsize
.right
- bestsize
.left
;
147 sz
.y
= bestsize
.bottom
- bestsize
.top
;
150 if ((wBtn
> sz
.x
) || ( GetWindowStyle() & wxBU_EXACTFIT
))
156 wxSize
wxButton::GetDefaultSize()
161 return wxSize(wBtn
, hBtn
);
164 void wxButton::Command (wxCommandEvent
& event
)
166 m_peer
->Flash(kControlButtonPart
) ;
167 ProcessCommand(event
);
170 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
172 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
173 event
.SetEventObject(this);
174 ProcessCommand(event
);