1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/button.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/button.h"
18 #include "wx/toplevel.h"
19 #include "wx/dcclient.h"
22 #include "wx/stockitem.h"
24 #include "wx/osx/private.h"
30 wxSize
wxButton::DoGetBestSize() const
32 if ( GetId() == wxID_HELP
)
33 return wxSize( 20 , 20 ) ;
35 wxSize sz
= GetDefaultSize() ;
37 switch (GetWindowVariant())
39 case wxWINDOW_VARIANT_NORMAL
:
40 case wxWINDOW_VARIANT_LARGE
:
44 case wxWINDOW_VARIANT_SMALL
:
48 case wxWINDOW_VARIANT_MINI
:
57 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
58 m_peer
->GetBestRect( &bestsize
) ;
61 if ( EmptyRect( &bestsize
) || ( GetWindowStyle() & wxBU_EXACTFIT
) )
65 ControlFontStyleRec controlFont
;
66 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
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
75 wxCFStringRef
str( !m_label
.empty() ? m_label
: wxString(" "),
76 GetFont().GetEncoding() );
78 #if wxOSX_USE_ATSU_TEXT
80 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
82 err
= GetThemeTextDimensions(
84 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
90 wxClientDC
dc(const_cast<wxButton
*>(this));
91 wxCoord width
, height
;
92 dc
.GetTextExtent( m_label
, &width
, &height
);
97 wBtn
= bounds
.h
+ sz
.y
;
101 wBtn
= bestsize
.right
- bestsize
.left
;
102 // non 'normal' window variants don't return the correct height
103 // sz.y = bestsize.bottom - bestsize.top ;
105 if ((wBtn
> sz
.x
) || ( GetWindowStyle() & wxBU_EXACTFIT
))
112 wxSize
wxButton::GetDefaultSize()
117 return wxSize(wBtn
, hBtn
);
120 wxWidgetImplType
* wxWidgetImpl::CreateButton( wxWindowMac
* wxpeer
,
123 const wxString
& label
,
126 long WXUNUSED(style
),
127 long WXUNUSED(extraStyle
))
130 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
) ;
131 wxMacControl
* peer
= new wxMacControl(wxpeer
) ;
132 if ( id
== wxID_HELP
)
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() );
142 else if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
144 // Button height is static in Mac, can't be changed, so we need to force it here
146 switch (wxpeer
->GetWindowVariant() )
149 wxFAIL_MSG( "unknown window variant" );
152 case wxWINDOW_VARIANT_NORMAL
:
153 case wxWINDOW_VARIANT_LARGE
:
156 case wxWINDOW_VARIANT_SMALL
:
158 case wxWINDOW_VARIANT_MINI
:
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() );
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() );
180 void wxMacControl::SetDefaultButton( bool isDefault
)
182 SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) isDefault
) ;
185 wxWidgetImplType
* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
187 wxWindowID
WXUNUSED(id
),
188 const wxString
& label
,
191 long WXUNUSED(style
),
192 long WXUNUSED(extraStyle
))
194 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
) ;
195 wxMacControl
* peer
= new wxMacControl(wxpeer
) ;
197 OSStatus err
= CreateDisclosureTriangleControl(
198 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
199 kControlDisclosureTrianglePointDefault
,
200 wxCFStringRef( label
),
203 TRUE
, // auto toggle back and forth
204 peer
->GetControlRefAddr() );