]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/anybutton.cpp
Merge in from trunk r67662 to r64801
[wxWidgets.git] / src / osx / carbon / anybutton.cpp
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 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #include "wx/anybutton.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/panel.h"
17 #include "wx/toplevel.h"
18 #include "wx/dcclient.h"
19 #endif
20
21 #include "wx/stockitem.h"
22
23 #include "wx/osx/private.h"
24
25 wxSize wxAnyButton::DoGetBestSize() const
26 {
27 if ( GetId() == wxID_HELP )
28 return wxSize( 20 , 20 ) ;
29
30 wxSize sz = GetDefaultSize() ;
31
32 switch (GetWindowVariant())
33 {
34 case wxWINDOW_VARIANT_NORMAL:
35 case wxWINDOW_VARIANT_LARGE:
36 sz.y = 20 ;
37 break;
38
39 case wxWINDOW_VARIANT_SMALL:
40 sz.y = 17 ;
41 break;
42
43 case wxWINDOW_VARIANT_MINI:
44 sz.y = 15 ;
45 break;
46
47 default:
48 break;
49 }
50
51 #if wxOSX_USE_CARBON
52 Rect bestsize = { 0 , 0 , 0 , 0 } ;
53 GetPeer()->GetBestRect( &bestsize ) ;
54
55 int wBtn;
56 if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) )
57 {
58 Point bounds;
59
60 ControlFontStyleRec controlFont;
61 OSStatus err = GetPeer()->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
62 verify_noerr( err );
63
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
69 // unloaded segment.
70 wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "),
71 GetFont().GetEncoding() );
72
73 #if wxOSX_USE_ATSU_TEXT
74 SInt16 baseline;
75 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
76 {
77 err = GetThemeTextDimensions(
78 (CFStringRef)str,
79 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
80 verify_noerr( err );
81 }
82 else
83 #endif
84 {
85 wxClientDC dc(const_cast<wxAnyButton*>(this));
86 wxCoord width, height ;
87 dc.GetTextExtent( m_label , &width, &height);
88 bounds.h = width;
89 bounds.v = height;
90 }
91
92 wBtn = bounds.h + sz.y;
93 }
94 else
95 {
96 wBtn = bestsize.right - bestsize.left ;
97 // non 'normal' window variants don't return the correct height
98 // sz.y = bestsize.bottom - bestsize.top ;
99 }
100 if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
101 sz.x = wBtn;
102 #endif
103
104 return sz ;
105 }
106
107 wxSize wxAnyButton::GetDefaultSize()
108 {
109 int wBtn = 70 ;
110 int hBtn = 20 ;
111
112 return wxSize(wBtn, hBtn);
113 }