1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/anybutton.cpp
3 // Purpose: wxAnyButton
4 // Author: Stefan Csomor
5 // Created: 1998-01-01 (extracted from button.cpp)
6 // RCS-ID: $Id: anybutton.cpp 67230 2011-03-18 14:20:12Z SC $
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/anybutton.h"
17 #include "wx/toplevel.h"
18 #include "wx/dcclient.h"
21 #include "wx/stockitem.h"
23 #include "wx/osx/private.h"
25 wxSize
wxAnyButton::DoGetBestSize() const
27 if ( GetId() == wxID_HELP
)
28 return wxSize( 20 , 20 ) ;
30 wxSize sz
= GetDefaultSize() ;
32 switch (GetWindowVariant())
34 case wxWINDOW_VARIANT_NORMAL
:
35 case wxWINDOW_VARIANT_LARGE
:
39 case wxWINDOW_VARIANT_SMALL
:
43 case wxWINDOW_VARIANT_MINI
:
52 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
53 GetPeer()->GetBestRect( &bestsize
) ;
56 if ( EmptyRect( &bestsize
) || ( GetWindowStyle() & wxBU_EXACTFIT
) )
60 ControlFontStyleRec controlFont
;
61 OSStatus err
= GetPeer()->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
64 // GetThemeTextDimensions will cache strings and the documentation
65 // says not to use the NoCopy string creation calls.
66 // This also means that we can't use CFSTR without
67 // -fno-constant-cfstrings if the library might be unloaded,
68 // as GetThemeTextDimensions may cache a pointer to our
70 wxCFStringRef
str( !m_label
.empty() ? m_label
: wxString(" "),
71 GetFont().GetEncoding() );
73 #if wxOSX_USE_ATSU_TEXT
75 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
77 err
= GetThemeTextDimensions(
79 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
85 wxClientDC
dc(const_cast<wxAnyButton
*>(this));
86 wxCoord width
, height
;
87 dc
.GetTextExtent( m_label
, &width
, &height
);
92 wBtn
= bounds
.h
+ sz
.y
;
96 wBtn
= bestsize
.right
- bestsize
.left
;
97 // non 'normal' window variants don't return the correct height
98 // sz.y = bestsize.bottom - bestsize.top ;
100 if ((wBtn
> sz
.x
) || ( GetWindowStyle() & wxBU_EXACTFIT
))
107 wxSize
wxAnyButton::GetDefaultSize()
112 return wxSize(wBtn
, hBtn
);