]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/stattext.cpp
wxSYS_COLOUR_WINDOW is better for window backgrounds on PPC/Smartphone
[wxWidgets.git] / src / mac / carbon / stattext.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: stattext.cpp
3// Purpose: wxStaticText
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "stattext.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
c545950d
RN
18#if wxUSE_STATTEXT
19
e9576ca5
SC
20#include "wx/app.h"
21#include "wx/stattext.h"
bedaf53e
SC
22#include "wx/notebook.h"
23#include "wx/tabctrl.h"
03e11df5
GD
24#include "wx/dc.h"
25#include "wx/dcclient.h"
00500f40 26#include "wx/utils.h"
f7035880 27#include "wx/settings.h"
e9576ca5
SC
28
29#include <stdio.h>
30
2f1ae414 31#if !USE_SHARED_LIBRARY
90b959ae 32IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
2f1ae414 33#endif
e9576ca5 34
d497dca4 35#include "wx/mac/uma.h"
519cb848 36
8208e181
SC
37bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
38 const wxString& label,
39 const wxPoint& pos,
40 const wxSize& size,
41 long style,
42 const wxString& name)
43{
facd6764
SC
44 m_macIsUserPane = FALSE ;
45
28c98a77 46 m_label = wxStripMenuCodes(label) ;
8208e181 47
b45ed7a2
VZ
48 if ( !wxControl::Create( parent, id, pos, size, style,
49 wxDefaultValidator , name ) )
50 {
51 return false;
52 }
53
facd6764
SC
54 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
55 wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
b905d6cc 56 m_peer = new wxMacControl(this) ;
facd6764 57 verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str ,
5ca0d812 58 NULL , m_peer->GetControlRefAddr() ) ) ;
b8c140b8 59
facd6764 60 MacPostControlCreate(pos,size) ;
7595f381 61
facd6764 62 return true;
9714ffa0
SC
63}
64
facd6764 65wxSize wxStaticText::DoGetBestSize() const
8208e181 66{
facd6764 67 ControlFontStyleRec controlFont ;
5ca0d812 68 verify_noerr( m_peer->GetData<ControlFontStyleRec>(kControlEntireControl , kControlFontStyleTag , &controlFont ) ) ;
e40298d5 69
facd6764
SC
70 Point bounds ;
71 SInt16 baseline ;
72 wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ;
943b730f
SC
73 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
74 verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ;
75 else
76 {
77 wxMacWindowStateSaver sv( this ) ;
78 ::TextFont( m_font.MacGetFontNum() ) ;
79 ::TextSize( (short)( m_font.MacGetFontSize()) ) ;
80 ::TextFace( m_font.MacGetFontStyle() ) ;
81 verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , kThemeCurrentPortFont , kThemeStateActive , false , &bounds , &baseline ) ) ;
82 }
b1d7de5a
SC
83 if ( m_label.Length() == 0 )
84 bounds.h = 0 ;
d5375d25
SC
85
86 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
87 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
facd6764 88 return wxSize(bounds.h, bounds.v);
8208e181
SC
89}
90
facd6764 91void wxStaticText::SetLabel(const wxString& st )
e9576ca5 92{
2f1ae414 93
facd6764
SC
94 m_label = wxStripMenuCodes(st) ;
95
96 wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
97 CFStringRef ref = str ;
5ca0d812 98 verify_noerr( m_peer->SetData<CFStringRef>(kControlEntireControl , kControlStaticTextCFStringTag, ref ) ) ;
e9576ca5 99
c0e6c051
RD
100 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
101 {
9f884528 102 InvalidateBestSize();
c0e6c051 103 SetSize( GetBestSize() ) ;
c0e6c051 104 }
441b46ac 105 Refresh() ;
bb751cf9
RD
106 Update() ;
107}
108
c0e6c051
RD
109bool wxStaticText::SetFont(const wxFont& font)
110{
111 bool ret = wxControl::SetFont(font);
112
113 if ( ret )
114 {
115 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
441b46ac
SC
116 {
117 InvalidateBestSize();
118 SetSize( GetBestSize() );
119 }
c0e6c051
RD
120 }
121
122 return ret;
123}
c545950d
RN
124
125#endif //if wxUSE_STATTEXT
126