]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/button.cpp |
489468fe SC |
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 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/panel.h" | |
18 | #include "wx/toplevel.h" | |
19 | #include "wx/dcclient.h" | |
20 | #endif | |
21 | ||
22 | #include "wx/stockitem.h" | |
23 | ||
524c47aa | 24 | #include "wx/osx/private.h" |
489468fe | 25 | |
524c47aa SC |
26 | // |
27 | // | |
28 | // | |
489468fe SC |
29 | |
30 | wxSize wxButton::DoGetBestSize() const | |
31 | { | |
32 | if ( GetId() == wxID_HELP ) | |
33 | return wxSize( 20 , 20 ) ; | |
34 | ||
35 | wxSize sz = GetDefaultSize() ; | |
36 | ||
37 | switch (GetWindowVariant()) | |
38 | { | |
39 | case wxWINDOW_VARIANT_NORMAL: | |
40 | case wxWINDOW_VARIANT_LARGE: | |
41 | sz.y = 20 ; | |
42 | break; | |
43 | ||
44 | case wxWINDOW_VARIANT_SMALL: | |
45 | sz.y = 17 ; | |
46 | break; | |
47 | ||
48 | case wxWINDOW_VARIANT_MINI: | |
49 | sz.y = 15 ; | |
50 | break; | |
51 | ||
52 | default: | |
53 | break; | |
54 | } | |
55 | ||
524c47aa | 56 | #if wxOSX_USE_CARBON |
489468fe SC |
57 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
58 | m_peer->GetBestRect( &bestsize ) ; | |
59 | ||
60 | int wBtn; | |
61 | if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) ) | |
62 | { | |
63 | Point bounds; | |
64 | ||
65 | ControlFontStyleRec controlFont; | |
66 | OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); | |
67 | verify_noerr( err ); | |
68 | ||
69 | wxCFStringRef str( m_label, GetFont().GetEncoding() ); | |
70 | ||
292e5e1f | 71 | #if wxOSX_USE_ATSU_TEXT |
489468fe SC |
72 | SInt16 baseline; |
73 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
74 | { | |
75 | err = GetThemeTextDimensions( | |
76 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
77 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); | |
78 | verify_noerr( err ); | |
79 | } | |
80 | else | |
81 | #endif | |
82 | { | |
83 | wxClientDC dc(const_cast<wxButton*>(this)); | |
84 | wxCoord width, height ; | |
85 | dc.GetTextExtent( m_label , &width, &height); | |
86 | bounds.h = width; | |
87 | bounds.v = height; | |
88 | } | |
89 | ||
90 | wBtn = bounds.h + sz.y; | |
91 | } | |
92 | else | |
93 | { | |
94 | wBtn = bestsize.right - bestsize.left ; | |
95 | // non 'normal' window variants don't return the correct height | |
96 | // sz.y = bestsize.bottom - bestsize.top ; | |
97 | } | |
489468fe SC |
98 | if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT)) |
99 | sz.x = wBtn; | |
524c47aa | 100 | #endif |
489468fe SC |
101 | |
102 | return sz ; | |
103 | } | |
104 | ||
105 | wxSize wxButton::GetDefaultSize() | |
106 | { | |
107 | int wBtn = 70 ; | |
108 | int hBtn = 20 ; | |
109 | ||
110 | return wxSize(wBtn, hBtn); | |
111 | } | |
112 | ||
524c47aa SC |
113 | wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer, |
114 | wxWindowMac* parent, | |
115 | wxWindowID id, | |
116 | const wxString& label, | |
117 | const wxPoint& pos, | |
118 | const wxSize& size, | |
119 | long style, | |
120 | long extraStyle) | |
489468fe | 121 | { |
524c47aa SC |
122 | OSStatus err; |
123 | Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; | |
124 | wxMacControl* peer = new wxMacControl(wxpeer) ; | |
125 | if ( id == wxID_HELP ) | |
126 | { | |
127 | ControlButtonContentInfo info ; | |
128 | info.contentType = kControlContentIconRef ; | |
129 | GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef); | |
130 | err = CreateRoundButtonControl( | |
131 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
132 | &bounds, kControlRoundButtonNormalSize, | |
133 | &info, peer->GetControlRefAddr() ); | |
134 | } | |
135 | else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND) | |
136 | { | |
137 | // Button height is static in Mac, can't be changed, so we need to force it here | |
138 | int maxHeight; | |
139 | switch (wxpeer->GetWindowVariant() ) | |
140 | { | |
141 | case wxWINDOW_VARIANT_NORMAL: | |
142 | case wxWINDOW_VARIANT_LARGE: | |
143 | maxHeight = 20 ; | |
144 | break; | |
145 | case wxWINDOW_VARIANT_SMALL: | |
146 | maxHeight = 17; | |
147 | case wxWINDOW_VARIANT_MINI: | |
148 | maxHeight = 15; | |
149 | default: | |
150 | break; | |
151 | } | |
152 | bounds.bottom = bounds.top + maxHeight ; | |
153 | wxpeer->SetMaxSize( wxSize( wxpeer->GetMaxWidth() , maxHeight )); | |
154 | err = CreatePushButtonControl( | |
155 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
156 | &bounds, CFSTR(""), peer->GetControlRefAddr() ); | |
157 | } | |
158 | else | |
159 | { | |
160 | ControlButtonContentInfo info ; | |
161 | info.contentType = kControlNoContent ; | |
162 | err = CreateBevelButtonControl( | |
163 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, CFSTR(""), | |
164 | kControlBevelButtonLargeBevel, kControlBehaviorPushbutton, | |
165 | &info, 0, 0, 0, peer->GetControlRefAddr() ); | |
166 | } | |
167 | verify_noerr( err ); | |
168 | return peer; | |
489468fe SC |
169 | } |
170 | ||
524c47aa SC |
171 | void wxMacControl::SetDefaultButton( bool isDefault ) |
172 | { | |
173 | SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) isDefault ) ; | |
489468fe SC |
174 | } |
175 | ||
524c47aa SC |
176 | wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer, |
177 | wxWindowMac* parent, | |
178 | wxWindowID id, | |
179 | const wxString& label, | |
180 | const wxPoint& pos, | |
181 | const wxSize& size, | |
182 | long style, | |
183 | long extraStyle) | |
489468fe | 184 | { |
524c47aa SC |
185 | Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; |
186 | wxMacControl* peer = new wxMacControl(wxpeer) ; | |
489468fe SC |
187 | |
188 | OSStatus err = CreateDisclosureTriangleControl( | |
189 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, | |
190 | kControlDisclosureTrianglePointDefault, | |
191 | wxCFStringRef( label ), | |
192 | 0, // closed | |
193 | TRUE, // draw title | |
194 | TRUE, // auto toggle back and forth | |
524c47aa | 195 | peer->GetControlRefAddr() ); |
489468fe SC |
196 | |
197 | verify_noerr( err ); | |
524c47aa | 198 | return peer; |
489468fe | 199 | } |
524c47aa | 200 | |
489468fe | 201 |