]>
Commit | Line | Data |
---|---|---|
b4354db1 VZ |
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; | |
93be446f VZ |
56 | if ( GetBitmapLabel().IsOk() ) |
57 | { | |
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(); | |
64 | wBtn = sz.x; | |
65 | } | |
66 | else if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) ) | |
b4354db1 VZ |
67 | { |
68 | Point bounds; | |
69 | ||
70 | ControlFontStyleRec controlFont; | |
71 | OSStatus err = GetPeer()->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); | |
72 | verify_noerr( err ); | |
73 | ||
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 | |
79 | // unloaded segment. | |
80 | wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "), | |
81 | GetFont().GetEncoding() ); | |
82 | ||
83 | #if wxOSX_USE_ATSU_TEXT | |
84 | SInt16 baseline; | |
85 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
86 | { | |
87 | err = GetThemeTextDimensions( | |
88 | (CFStringRef)str, | |
89 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); | |
90 | verify_noerr( err ); | |
91 | } | |
92 | else | |
93 | #endif | |
94 | { | |
95 | wxClientDC dc(const_cast<wxAnyButton*>(this)); | |
96 | wxCoord width, height ; | |
97 | dc.GetTextExtent( m_label , &width, &height); | |
98 | bounds.h = width; | |
99 | bounds.v = height; | |
100 | } | |
101 | ||
102 | wBtn = bounds.h + sz.y; | |
103 | } | |
104 | else | |
105 | { | |
106 | wBtn = bestsize.right - bestsize.left ; | |
107 | // non 'normal' window variants don't return the correct height | |
108 | // sz.y = bestsize.bottom - bestsize.top ; | |
109 | } | |
110 | if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT)) | |
111 | sz.x = wBtn; | |
112 | #endif | |
113 | ||
114 | return sz ; | |
115 | } | |
116 | ||
117 | wxSize wxAnyButton::GetDefaultSize() | |
118 | { | |
119 | int wBtn = 70 ; | |
120 | int hBtn = 20 ; | |
121 | ||
122 | return wxSize(wBtn, hBtn); | |
123 | } |