]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/button.cpp
New implementation for printing circles and epllipses.
[wxWidgets.git] / src / mac / carbon / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose: wxButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/button.h"
15 #include "wx/panel.h"
16 #include "wx/stockitem.h"
17
18 #include "wx/mac/uma.h"
19
20 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
21
22
23 bool wxButton::Create(wxWindow *parent,
24 wxWindowID id,
25 const wxString& lbl,
26 const wxPoint& pos,
27 const wxSize& size,
28 long style,
29 const wxValidator& validator,
30 const wxString& name)
31 {
32 wxString label(lbl);
33 if (label.empty() && wxIsStockID(id))
34 label = wxGetStockLabel(id);
35
36 m_macIsUserPane = false ;
37
38 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
39 return false;
40
41 m_label = label ;
42
43 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
44 m_peer = new wxMacControl(this) ;
45 if ( id == wxID_HELP )
46 {
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() ) );
52 }
53 else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
54 {
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 )
58 {
59 bounds.bottom = bounds.top + 20 ;
60 m_maxHeight = 20 ;
61 }
62 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
63 {
64 bounds.bottom = bounds.top + 17 ;
65 m_maxHeight = 17 ;
66 }
67 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
68 {
69 bounds.bottom = bounds.top + 15 ;
70 m_maxHeight = 15 ;
71 }
72 #endif
73
74 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , m_peer->GetControlRefAddr() ) );
75 }
76 else
77 {
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() ) );
82 }
83
84 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid Mac control") ) ;
85
86 MacPostControlCreate(pos, size) ;
87
88 return true;
89 }
90
91 void wxButton::SetDefault()
92 {
93 wxWindow *parent = GetParent();
94 wxButton *btnOldDefault = NULL;
95
96 if ( parent )
97 {
98 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(), wxButton);
99 parent->SetDefaultItem(this);
100 }
101
102 if ( btnOldDefault )
103 btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ;
104
105 m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ;
106 }
107
108 wxSize wxButton::DoGetBestSize() const
109 {
110 if ( GetId() == wxID_HELP )
111 return wxSize( 20 , 20 ) ;
112
113 wxSize sz = GetDefaultSize() ;
114 int charspace = 8 ;
115
116 switch (GetWindowVariant())
117 {
118 case wxWINDOW_VARIANT_NORMAL:
119 case wxWINDOW_VARIANT_LARGE:
120 sz.y = 20 ;
121 charspace = 10 ;
122 break;
123
124 case wxWINDOW_VARIANT_SMALL:
125 sz.y = 17 ;
126 break;
127
128 case wxWINDOW_VARIANT_MINI:
129 sz.y = 15 ;
130 break;
131
132 default:
133 break;
134 }
135
136 Rect bestsize = { 0 , 0 , 0 , 0 } ;
137 m_peer->GetBestRect( &bestsize ) ;
138
139 int wBtn;
140 if ( EmptyRect( &bestsize ) )
141 {
142 wBtn = m_label.Length() * charspace + 12 ;
143 }
144 else
145 {
146 wBtn = bestsize.right - bestsize.left ;
147 sz.y = bestsize.bottom - bestsize.top ;
148 }
149
150 if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
151 sz.x = wBtn;
152
153 return sz ;
154 }
155
156 wxSize wxButton::GetDefaultSize()
157 {
158 int wBtn = 70 ;
159 int hBtn = 20 ;
160
161 return wxSize(wBtn, hBtn);
162 }
163
164 void wxButton::Command (wxCommandEvent & event)
165 {
166 m_peer->Flash(kControlButtonPart) ;
167 ProcessCommand(event);
168 }
169
170 wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
171 {
172 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
173 event.SetEventObject(this);
174 ProcessCommand(event);
175
176 return noErr;
177 }
178