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 wxCFStringRef
str( m_label
, GetFont().GetEncoding() );
71 #if wxOSX_USE_ATSU_TEXT
73 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
75 err
= GetThemeTextDimensions(
76 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
77 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
83 wxClientDC
dc(const_cast<wxButton
*>(this));
84 wxCoord width
, height
;
85 dc
.GetTextExtent( m_label
, &width
, &height
);
90 wBtn
= bounds
.h
+ sz
.y
;
94 wBtn
= bestsize
.right
- bestsize
.left
;
95 // non 'normal' window variants don't return the correct height
96 // sz.y = bestsize.bottom - bestsize.top ;
98 if ((wBtn
> sz
.x
) || ( GetWindowStyle() & wxBU_EXACTFIT
))
105 wxSize
wxButton::GetDefaultSize()
110 return wxSize(wBtn
, hBtn
);
113 wxWidgetImplType
* wxWidgetImpl::CreateButton( wxWindowMac
* wxpeer
,
116 const wxString
& label
,
123 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
) ;
124 wxMacControl
* peer
= new wxMacControl(wxpeer
) ;
125 if ( id
== wxID_HELP
)
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() );
135 else if ( label
.Find('\n' ) == wxNOT_FOUND
&& label
.Find('\r' ) == wxNOT_FOUND
)
137 // Button height is static in Mac, can't be changed, so we need to force it here
139 switch (wxpeer
->GetWindowVariant() )
141 case wxWINDOW_VARIANT_NORMAL
:
142 case wxWINDOW_VARIANT_LARGE
:
145 case wxWINDOW_VARIANT_SMALL
:
147 case wxWINDOW_VARIANT_MINI
:
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() );
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() );
171 void wxMacControl::SetDefaultButton( bool isDefault
)
173 SetData(kControlButtonPart
, kControlPushButtonDefaultTag
, (Boolean
) isDefault
) ;
176 wxWidgetImplType
* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
179 const wxString
& label
,
185 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
) ;
186 wxMacControl
* peer
= new wxMacControl(wxpeer
) ;
188 OSStatus err
= CreateDisclosureTriangleControl(
189 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
190 kControlDisclosureTrianglePointDefault
,
191 wxCFStringRef( label
),
194 TRUE
, // auto toggle back and forth
195 peer
->GetControlRefAddr() );