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"
20 #include "wx/stockitem.h"
22 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
26 #include "wx/mac/uma.h"
29 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& lbl
,
31 const wxSize
& size
, long style
,
32 const wxValidator
& validator
,
36 if (label
.empty() && wxIsStockID(id
))
37 label
= wxGetStockLabel(id
);
39 m_macIsUserPane
= FALSE
;
41 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
46 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
47 m_peer
= new wxMacControl() ;
48 if ( id
== wxID_HELP
)
50 ControlButtonContentInfo info
;
51 info
.contentType
= kControlContentIconRef
;
52 GetIconRef(kOnSystemDisk
, kSystemIconsCreator
, kHelpIcon
, &info
.u
.iconRef
);
53 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &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 ;
76 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") , m_peer
->GetControlRefAddr() ) );
80 ControlButtonContentInfo info
;
81 info
.contentType
= kControlNoContent
;
82 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,CFSTR(""),
83 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
86 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
88 MacPostControlCreate(pos
,size
) ;
93 void wxButton::SetDefault()
95 wxWindow
*parent
= GetParent();
96 wxButton
*btnOldDefault
= NULL
;
99 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
101 parent
->SetDefaultItem(this);
105 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
106 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
109 wxSize
wxButton::DoGetBestSize() const
111 if ( GetId() == wxID_HELP
)
112 return wxSize( 20 , 20 ) ;
114 wxSize sz
= GetDefaultSize() ;
117 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
122 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
127 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
133 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
134 m_peer
->GetBestRect( &bestsize
) ;
137 if ( EmptyRect( &bestsize
) )
139 wBtn
= m_label
.Length() * charspace
+ 12 ;
143 wBtn
= bestsize
.right
- bestsize
.left
;
144 sz
.y
= bestsize
.bottom
- bestsize
.top
;
147 if (wBtn
> sz
.x
|| ( GetWindowStyle() & wxBU_EXACTFIT
) )
153 wxSize
wxButton::GetDefaultSize()
158 return wxSize(wBtn
, hBtn
);
161 void wxButton::Command (wxCommandEvent
& event
)
163 m_peer
->Flash(kControlButtonPart
) ;
164 ProcessCommand (event
);
167 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
169 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
170 event
.SetEventObject(this);
171 ProcessCommand(event
);