wxwidgets/src/mac/carbon/stattext.cpp
Robin Dunn fe161a2685 Controls will readjust their size and minsize when SetLabel or SetFont
are called.  Fixed up wxStaticText to blend the wxST_NO_AUTOSIZE with
this new functionality.  Made SetBestSize public under the
SetBestFittingSize name.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2004-06-19 01:35:10 +00:00

100 lines
3 KiB
C++

/////////////////////////////////////////////////////////////////////////////
// Name: stattext.cpp
// Purpose: wxStaticText
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "stattext.h"
#endif
#include "wx/app.h"
#include "wx/stattext.h"
#include "wx/notebook.h"
#include "wx/tabctrl.h"
#include "wx/dc.h"
#include "wx/dcclient.h"
#include "wx/utils.h"
#include "wx/settings.h"
#include <stdio.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
#endif
#include "wx/mac/uma.h"
bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
m_macIsUserPane = FALSE ;
m_label = wxStripMenuCodes(label) ;
if ( !wxControl::Create( parent, id, pos, size, style,
wxDefaultValidator , name ) )
{
return false;
}
Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
m_peer = new wxMacControl() ;
verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str ,
NULL , *m_peer ) ) ;
MacPostControlCreate(pos,size) ;
return true;
}
wxSize wxStaticText::DoGetBestSize() const
{
ControlFontStyleRec controlFont ;
Size outSize ;
verify_noerr( GetControlData( *m_peer , kControlEntireControl , kControlFontStyleTag , sizeof(controlFont) , &controlFont , &outSize ) ) ;
Point bounds ;
SInt16 baseline ;
wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ;
if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ;
else
{
wxMacWindowStateSaver sv( this ) ;
::TextFont( m_font.MacGetFontNum() ) ;
::TextSize( (short)( m_font.MacGetFontSize()) ) ;
::TextFace( m_font.MacGetFontStyle() ) ;
verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , kThemeCurrentPortFont , kThemeStateActive , false , &bounds , &baseline ) ) ;
}
if ( m_label.Length() == 0 )
bounds.h = 0 ;
return wxSize(bounds.h, bounds.v);
}
void wxStaticText::SetLabel(const wxString& st )
{
m_label = wxStripMenuCodes(st) ;
wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
CFStringRef ref = str ;
SetControlData( *m_peer, kControlEntireControl , kControlStaticTextCFStringTag, sizeof( CFStringRef ),
&ref );
if (GetAdjustMinSizeFlag())
SetBestSize(wxDefaultSize);
Update() ;
}