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
) )
44 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
45 m_peer
= new wxMacControl(this) ;
46 if ( id
== wxID_HELP
)
48 ControlButtonContentInfo info
;
49 info
.contentType
= kControlContentIconRef
;
50 GetIconRef(kOnSystemDisk
, kSystemIconsCreator
, kHelpIcon
, &info
.u
.iconRef
);
51 err
= CreateRoundButtonControl(
52 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
53 &bounds
, kControlRoundButtonNormalSize
,
54 &info
, m_peer
->GetControlRefAddr() );
56 else if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
58 #if TARGET_API_MAC_OSX
59 // Button height is static in Mac, can't be changed, so we need to force it here
60 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
62 bounds
.bottom
= bounds
.top
+ 20 ;
65 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
67 bounds
.bottom
= bounds
.top
+ 17 ;
70 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
72 bounds
.bottom
= bounds
.top
+ 15 ;
77 err
= CreatePushButtonControl(
78 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
79 &bounds
, CFSTR(""), m_peer
->GetControlRefAddr() );
83 ControlButtonContentInfo info
;
84 info
.contentType
= kControlNoContent
;
85 err
= CreateBevelButtonControl(
86 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR(""),
87 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
,
88 &info
, 0, 0, 0, m_peer
->GetControlRefAddr() );
92 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid Mac control") ) ;
94 MacPostControlCreate( pos
, size
);
99 void wxButton::SetDefault()
101 wxWindow
*parent
= GetParent();
102 wxButton
*btnOldDefault
= NULL
;
106 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
107 parent
->SetDefaultItem(this);
111 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
113 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
116 wxSize
wxButton::DoGetBestSize() const
118 if ( GetId() == wxID_HELP
)
119 return wxSize( 20 , 20 ) ;
121 wxSize sz
= GetDefaultSize() ;
124 switch (GetWindowVariant())
126 case wxWINDOW_VARIANT_NORMAL
:
127 case wxWINDOW_VARIANT_LARGE
:
132 case wxWINDOW_VARIANT_SMALL
:
136 case wxWINDOW_VARIANT_MINI
:
144 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
145 m_peer
->GetBestRect( &bestsize
) ;
148 if ( EmptyRect( &bestsize
) )
150 wBtn
= m_label
.Length() * charspace
+ 12 ;
154 wBtn
= bestsize
.right
- bestsize
.left
;
155 sz
.y
= bestsize
.bottom
- bestsize
.top
;
158 if ((wBtn
> sz
.x
) || ( GetWindowStyle() & wxBU_EXACTFIT
))
164 wxSize
wxButton::GetDefaultSize()
169 return wxSize(wBtn
, hBtn
);
172 void wxButton::Command (wxCommandEvent
& event
)
174 m_peer
->Flash(kControlButtonPart
) ;
175 ProcessCommand(event
);
178 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
180 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
181 event
.SetEventObject(this);
182 ProcessCommand(event
);