]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/anybutton.cpp
Set missing Language: headers in PO files.
[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 // Copyright: (c) Stefan Csomor
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/wxprec.h"
11
12 #include "wx/anybutton.h"
13
14 #ifndef WX_PRECOMP
15 #include "wx/panel.h"
16 #include "wx/toplevel.h"
17 #include "wx/dcclient.h"
18 #endif
19
20 #include "wx/stockitem.h"
21
22 #include "wx/osx/private.h"
23
24 wxSize wxAnyButton::DoGetBestSize() const
25 {
26 if ( GetId() == wxID_HELP )
27 return wxSize( 20 , 20 ) ;
28
29 wxSize sz = GetDefaultSize() ;
30
31 switch (GetWindowVariant())
32 {
33 case wxWINDOW_VARIANT_NORMAL:
34 case wxWINDOW_VARIANT_LARGE:
35 sz.y = 20 ;
36 break;
37
38 case wxWINDOW_VARIANT_SMALL:
39 sz.y = 17 ;
40 break;
41
42 case wxWINDOW_VARIANT_MINI:
43 sz.y = 15 ;
44 break;
45
46 default:
47 break;
48 }
49
50 #if wxOSX_USE_CARBON
51 Rect bestsize = { 0 , 0 , 0 , 0 } ;
52 GetPeer()->GetBestRect( &bestsize ) ;
53
54 int wBtn;
55 if ( GetBitmapLabel().IsOk() )
56 {
57 sz.x = bestsize.right - bestsize.left ;
58 sz.y = bestsize.bottom - bestsize.top ;
59 sz.x = sz.x + MacGetLeftBorderSize() +
60 MacGetRightBorderSize();
61 sz.y = sz.y + MacGetTopBorderSize() +
62 MacGetBottomBorderSize();
63 wBtn = sz.x;
64 }
65 else if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) )
66 {
67 Point bounds;
68
69 ControlFontStyleRec controlFont;
70 OSStatus err = GetPeer()->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
71 verify_noerr( err );
72
73 // GetThemeTextDimensions will cache strings and the documentation
74 // says not to use the NoCopy string creation calls.
75 // This also means that we can't use CFSTR without
76 // -fno-constant-cfstrings if the library might be unloaded,
77 // as GetThemeTextDimensions may cache a pointer to our
78 // unloaded segment.
79 wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "),
80 GetFont().GetEncoding() );
81
82 #if wxOSX_USE_ATSU_TEXT
83 SInt16 baseline;
84 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
85 {
86 err = GetThemeTextDimensions(
87 (CFStringRef)str,
88 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
89 verify_noerr( err );
90 }
91 else
92 #endif
93 {
94 wxClientDC dc(const_cast<wxAnyButton*>(this));
95 wxCoord width, height ;
96 dc.GetTextExtent( m_label , &width, &height);
97 bounds.h = width;
98 bounds.v = height;
99 }
100
101 wBtn = bounds.h + sz.y;
102 }
103 else
104 {
105 wBtn = bestsize.right - bestsize.left ;
106 // non 'normal' window variants don't return the correct height
107 // sz.y = bestsize.bottom - bestsize.top ;
108 }
109 if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
110 sz.x = wBtn;
111 #endif
112
113 return sz ;
114 }
115
116 wxSize wxAnyButton::GetDefaultSize()
117 {
118 int wBtn = 70 ;
119 int hBtn = 20 ;
120
121 return wxSize(wBtn, hBtn);
122 }