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