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 ( GetBitmapLabel().IsOk() )
58 sz
.x
= bestsize
.right
- bestsize
.left
;
59 sz
.y
= bestsize
.bottom
- bestsize
.top
;
60 sz
.x
= sz
.x
+ MacGetLeftBorderSize() +
61 MacGetRightBorderSize();
62 sz
.y
= sz
.y
+ MacGetTopBorderSize() +
63 MacGetBottomBorderSize();
66 else if ( EmptyRect( &bestsize
) || ( GetWindowStyle() & wxBU_EXACTFIT
) )
70 ControlFontStyleRec controlFont
;
71 OSStatus err
= GetPeer()->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
74 // GetThemeTextDimensions will cache strings and the documentation
75 // says not to use the NoCopy string creation calls.
76 // This also means that we can't use CFSTR without
77 // -fno-constant-cfstrings if the library might be unloaded,
78 // as GetThemeTextDimensions may cache a pointer to our
80 wxCFStringRef
str( !m_label
.empty() ? m_label
: wxString(" "),
81 GetFont().GetEncoding() );
83 #if wxOSX_USE_ATSU_TEXT
85 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
87 err
= GetThemeTextDimensions(
89 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
95 wxClientDC
dc(const_cast<wxAnyButton
*>(this));
96 wxCoord width
, height
;
97 dc
.GetTextExtent( m_label
, &width
, &height
);
102 wBtn
= bounds
.h
+ sz
.y
;
106 wBtn
= bestsize
.right
- bestsize
.left
;
107 // non 'normal' window variants don't return the correct height
108 // sz.y = bestsize.bottom - bestsize.top ;
110 if ((wBtn
> sz
.x
) || ( GetWindowStyle() & wxBU_EXACTFIT
))
117 wxSize
wxAnyButton::GetDefaultSize()
122 return wxSize(wBtn
, hBtn
);