1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "button.h"
16 #include "wx/wxprec.h"
18 #include "wx/button.h"
20 #include "wx/stockitem.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
24 #include "wx/mac/uma.h"
27 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& lbl
,
29 const wxSize
& size
, long style
,
30 const wxValidator
& validator
,
34 if (label
.empty() && wxIsStockID(id
))
35 label
= wxGetStockLabel(id
);
37 m_macIsUserPane
= FALSE
;
39 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 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, kControlRoundButtonNormalSize
,
52 &info
, m_peer
->GetControlRefAddr() ) );
54 else if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
56 #if TARGET_API_MAC_OSX
57 //Button height is static in Mac, can't be changed, so we need to force it here
58 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
60 bounds
.bottom
= bounds
.top
+ 20 ;
63 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
65 bounds
.bottom
= bounds
.top
+ 17 ;
68 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
70 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
;
97 btnOldDefault
= wxDynamicCast(parent
->GetDefaultItem(),
99 parent
->SetDefaultItem(this);
103 btnOldDefault
->m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 0 ) ;
104 m_peer
->SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) 1 ) ;
107 wxSize
wxButton::DoGetBestSize() const
109 if ( GetId() == wxID_HELP
)
110 return wxSize( 20 , 20 ) ;
112 wxSize sz
= GetDefaultSize() ;
115 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
|| GetWindowVariant() == wxWINDOW_VARIANT_LARGE
)
120 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
)
125 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
131 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
132 m_peer
->GetBestRect( &bestsize
) ;
135 if ( EmptyRect( &bestsize
) )
137 wBtn
= m_label
.Length() * charspace
+ 12 ;
141 wBtn
= bestsize
.right
- bestsize
.left
;
142 sz
.y
= bestsize
.bottom
- bestsize
.top
;
145 if (wBtn
> sz
.x
|| ( GetWindowStyle() & wxBU_EXACTFIT
) )
151 wxSize
wxButton::GetDefaultSize()
156 return wxSize(wBtn
, hBtn
);
159 void wxButton::Command (wxCommandEvent
& event
)
161 m_peer
->Flash(kControlButtonPart
) ;
162 ProcessCommand (event
);
165 wxInt32
wxButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
167 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_windowId
);
168 event
.SetEventObject(this);
169 ProcessCommand(event
);