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 GetPeer()->GetBestRect( &bestsize
) ;
61 if ( EmptyRect( &bestsize
) || ( GetWindowStyle() & wxBU_EXACTFIT
) )
65 ControlFontStyleRec controlFont
;
66 OSStatus err
= GetPeer()->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
:
159 case wxWINDOW_VARIANT_MINI
:
162 bounds
.bottom
= bounds
.top
+ maxHeight
;
163 wxpeer
->SetMaxSize( wxSize( wxpeer
->GetMaxWidth() , maxHeight
));
164 err
= CreatePushButtonControl(
165 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
166 &bounds
, CFSTR(""), peer
->GetControlRefAddr() );
170 ControlButtonContentInfo info
;
171 info
.contentType
= kControlNoContent
;
172 err
= CreateBevelButtonControl(
173 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR(""),
174 kControlBevelButtonLargeBevel
, kControlBehaviorPushbutton
,
175 &info
, 0, 0, 0, peer
->GetControlRefAddr() );
181 void wxMacControl::SetDefaultButton( bool isDefault
)
183 SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) isDefault
) ;
186 wxWidgetImplType
* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
188 wxWindowID
WXUNUSED(id
),
189 const wxString
& label
,
192 long WXUNUSED(style
),
193 long WXUNUSED(extraStyle
))
195 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
) ;
196 wxMacControl
* peer
= new wxMacControl(wxpeer
) ;
198 OSStatus err
= CreateDisclosureTriangleControl(
199 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
200 kControlDisclosureTrianglePointDefault
,
201 wxCFStringRef( label
),
204 TRUE
, // auto toggle back and forth
205 peer
->GetControlRefAddr() );