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 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
20 #include "wx/mac/uma.h"
23 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& lbl
,
25 const wxSize
& size
, long style
,
26 const wxValidator
& validator
,
30 if (label
.empty() && wxIsStockID(id
))
31 label
= wxGetStockLabel(id
);
33 m_macIsUserPane
= FALSE
;
35 if ( !wxButtonBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
40 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
41 m_peer
= new wxMacControl(this) ;
42 if ( id
== wxID_HELP
)
44 ControlButtonContentInfo info
;
45 info
.contentType
= kControlContentIconRef
;
46 GetIconRef(kOnSystemDisk
, kSystemIconsCreator
, kHelpIcon
, &info
.u
.iconRef
);
47 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, kControlRoundButtonNormalSize
,
48 &info
, m_peer
->GetControlRefAddr() ) );
50 else if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
52 #if TARGET_API_MAC_OSX
53 //Button height is static in Mac, can't be changed, so we need to force it here
54 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
56 bounds
.bottom
= bounds
.top
+ 20 ;
59 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
61 bounds
.bottom
= bounds
.top
+ 17 ;
64 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
66 bounds
.bottom
= bounds
.top
+ 15 ;
70 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") , m_peer
->GetControlRefAddr() ) );
74 ControlButtonContentInfo info
;
75 info
.contentType
= kControlNoContent
;
76 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,CFSTR(""),
77 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
80 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
82 MacPostControlCreate(pos
,size
) ;
87 void wxButton::SetDefault()
89 wxWindow
*parent
= GetParent();
90 wxButton
*btnOldDefault
= NULL
;
93 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
95 parent
->SetDefaultItem(this);
99 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
100 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
103 wxSize
wxButton::DoGetBestSize() const
105 if ( GetId() == wxID_HELP
)
106 return wxSize( 20 , 20 ) ;
108 wxSize sz
= GetDefaultSize() ;
111 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
116 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
121 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
127 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
128 m_peer
->GetBestRect( &bestsize
) ;
131 if ( EmptyRect( &bestsize
) )
133 wBtn
= m_label
.Length() * charspace
+ 12 ;
137 wBtn
= bestsize
.right
- bestsize
.left
;
138 sz
.y
= bestsize
.bottom
- bestsize
.top
;
141 if (wBtn
> sz
.x
|| ( GetWindowStyle() & wxBU_EXACTFIT
) )
147 wxSize
wxButton::GetDefaultSize()
152 return wxSize(wBtn
, hBtn
);
155 void wxButton::Command (wxCommandEvent
& event
)
157 m_peer
->Flash(kControlButtonPart
) ;
158 ProcessCommand (event
);
161 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
163 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
164 event
.SetEventObject(this);
165 ProcessCommand(event
);