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
/////////////////////////////////////////////////////////////////////////////
10
#include "wx/wxprec.h"
12
#include "wx/anybutton.h"
16
#include "wx/toplevel.h"
17
#include "wx/dcclient.h"
20
#include "wx/stockitem.h"
22
#include "wx/osx/private.h"
24
wxSize wxAnyButton::DoGetBestSize() const
26
if ( GetId() == wxID_HELP )
27
return wxSize( 20 , 20 ) ;
29
wxSize sz = GetDefaultSize() ;
31
switch (GetWindowVariant())
33
case wxWINDOW_VARIANT_NORMAL:
34
case wxWINDOW_VARIANT_LARGE:
38
case wxWINDOW_VARIANT_SMALL:
42
case wxWINDOW_VARIANT_MINI:
51
Rect bestsize = { 0 , 0 , 0 , 0 } ;
52
GetPeer()->GetBestRect( &bestsize ) ;
55
if ( GetBitmapLabel().IsOk() )
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();
65
else if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) )
69
ControlFontStyleRec controlFont;
70
OSStatus err = GetPeer()->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
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
79
wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "),
80
GetFont().GetEncoding() );
82
#if wxOSX_USE_ATSU_TEXT
84
if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
86
err = GetThemeTextDimensions(
88
m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
94
wxClientDC dc(const_cast<wxAnyButton*>(this));
95
wxCoord width, height ;
96
dc.GetTextExtent( m_label , &width, &height);
101
wBtn = bounds.h + sz.y;
105
wBtn = bestsize.right - bestsize.left ;
106
// non 'normal' window variants don't return the correct height
107
// sz.y = bestsize.bottom - bestsize.top ;
109
if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
116
wxSize wxAnyButton::GetDefaultSize()
121
return wxSize(wBtn, hBtn);