]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/button.cpp
exclude SWIG generated files from being checked
[wxWidgets.git] / src / osx / carbon / button.cpp
CommitLineData
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
30wxSize 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
03647350
VZ
69 // GetThemeTextDimensions will cache strings and the documentation
70 // says not to use the NoCopy string creation calls.
71 // This also means that we can't use CFSTR without
72 // -fno-constant-cfstrings if the library might be unloaded,
73 // as GetThemeTextDimensions may cache a pointer to our
74 // unloaded segment.
75 wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "),
6fd21e16 76 GetFont().GetEncoding() );
489468fe 77
292e5e1f 78#if wxOSX_USE_ATSU_TEXT
489468fe
SC
79 SInt16 baseline;
80 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
81 {
82 err = GetThemeTextDimensions(
6fd21e16 83 (CFStringRef)str,
489468fe
SC
84 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
85 verify_noerr( err );
86 }
87 else
88#endif
89 {
90 wxClientDC dc(const_cast<wxButton*>(this));
91 wxCoord width, height ;
92 dc.GetTextExtent( m_label , &width, &height);
93 bounds.h = width;
94 bounds.v = height;
95 }
96
97 wBtn = bounds.h + sz.y;
98 }
99 else
100 {
101 wBtn = bestsize.right - bestsize.left ;
102 // non 'normal' window variants don't return the correct height
103 // sz.y = bestsize.bottom - bestsize.top ;
104 }
489468fe
SC
105 if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
106 sz.x = wBtn;
524c47aa 107#endif
489468fe
SC
108
109 return sz ;
110}
111
112wxSize wxButton::GetDefaultSize()
113{
114 int wBtn = 70 ;
115 int hBtn = 20 ;
116
117 return wxSize(wBtn, hBtn);
118}
119
ca910e1a
VZ
120wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
121 wxWindowMac* parent,
122 wxWindowID id,
524c47aa 123 const wxString& label,
ca910e1a 124 const wxPoint& pos,
524c47aa 125 const wxSize& size,
ca910e1a
VZ
126 long WXUNUSED(style),
127 long WXUNUSED(extraStyle))
489468fe 128{
524c47aa
SC
129 OSStatus err;
130 Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
131 wxMacControl* peer = new wxMacControl(wxpeer) ;
132 if ( id == wxID_HELP )
133 {
134 ControlButtonContentInfo info ;
135 info.contentType = kControlContentIconRef ;
136 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef);
137 err = CreateRoundButtonControl(
138 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
139 &bounds, kControlRoundButtonNormalSize,
140 &info, peer->GetControlRefAddr() );
141 }
142 else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
143 {
144 // Button height is static in Mac, can't be changed, so we need to force it here
145 int maxHeight;
ca910e1a 146 switch (wxpeer->GetWindowVariant() )
524c47aa 147 {
ca910e1a
VZ
148 default:
149 wxFAIL_MSG( "unknown window variant" );
150 // fall through
151
524c47aa
SC
152 case wxWINDOW_VARIANT_NORMAL:
153 case wxWINDOW_VARIANT_LARGE:
154 maxHeight = 20 ;
155 break;
156 case wxWINDOW_VARIANT_SMALL:
157 maxHeight = 17;
158 case wxWINDOW_VARIANT_MINI:
159 maxHeight = 15;
524c47aa
SC
160 }
161 bounds.bottom = bounds.top + maxHeight ;
162 wxpeer->SetMaxSize( wxSize( wxpeer->GetMaxWidth() , maxHeight ));
163 err = CreatePushButtonControl(
164 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
165 &bounds, CFSTR(""), peer->GetControlRefAddr() );
166 }
167 else
168 {
169 ControlButtonContentInfo info ;
170 info.contentType = kControlNoContent ;
171 err = CreateBevelButtonControl(
172 MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, CFSTR(""),
173 kControlBevelButtonLargeBevel, kControlBehaviorPushbutton,
174 &info, 0, 0, 0, peer->GetControlRefAddr() );
175 }
176 verify_noerr( err );
177 return peer;
489468fe
SC
178}
179
524c47aa 180void wxMacControl::SetDefaultButton( bool isDefault )
ca910e1a 181{
524c47aa 182 SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) isDefault ) ;
489468fe
SC
183}
184
ca910e1a
VZ
185wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer,
186 wxWindowMac* parent,
187 wxWindowID WXUNUSED(id),
524c47aa 188 const wxString& label,
ca910e1a 189 const wxPoint& pos,
524c47aa 190 const wxSize& size,
ca910e1a
VZ
191 long WXUNUSED(style),
192 long WXUNUSED(extraStyle))
489468fe 193{
524c47aa
SC
194 Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
195 wxMacControl* peer = new wxMacControl(wxpeer) ;
489468fe
SC
196
197 OSStatus err = CreateDisclosureTriangleControl(
ca910e1a 198 MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,
489468fe
SC
199 kControlDisclosureTrianglePointDefault,
200 wxCFStringRef( label ),
201 0, // closed
202 TRUE, // draw title
203 TRUE, // auto toggle back and forth
524c47aa 204 peer->GetControlRefAddr() );
ca910e1a 205
489468fe 206 verify_noerr( err );
524c47aa 207 return peer;
489468fe 208}
ca910e1a 209
489468fe 210