]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/stattext.cpp
Simplify wxWinCE #ifdefs.
[wxWidgets.git] / src / mac / carbon / stattext.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
a074f61e 2// Name: src/mac/carbon/stattext.cpp
e9576ca5 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 24
43524b15
DS
25#include "wx/mac/uma.h"
26
e9576ca5
SC
27#include <stdio.h>
28
90b959ae 29IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
e9576ca5 30
519cb848 31
43524b15
DS
32bool wxStaticText::Create( wxWindow *parent,
33 wxWindowID id,
34 const wxString& label,
35 const wxPoint& pos,
36 const wxSize& size,
37 long style,
38 const wxString& name )
8208e181 39{
43524b15 40 m_macIsUserPane = false;
8208e181 41
43524b15
DS
42 m_label = wxStripMenuCodes( label );
43
44 if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
b45ed7a2 45 return false;
b45ed7a2 46
43524b15
DS
47 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
48 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
49
50 m_peer = new wxMacControl( this );
51 OSStatus err = CreateStaticTextControl(
52 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
53 &bounds, str, NULL, m_peer->GetControlRefAddr() );
54 verify_noerr( err );
b8c140b8 55
a074f61e 56 if ( ( style & wxST_DOTS_END ) || ( style & wxST_DOTS_MIDDLE ) )
14132857 57 {
a074f61e 58 TruncCode tCode = truncEnd;
14132857 59 if ( style & wxST_DOTS_MIDDLE )
a074f61e
DS
60 tCode = truncMiddle;
61
62 err = m_peer->SetData( kControlStaticTextTruncTag, tCode );
63 err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
14132857 64 }
a074f61e 65
43524b15 66 MacPostControlCreate( pos, size );
7595f381 67
facd6764 68 return true;
9714ffa0
SC
69}
70
facd6764 71wxSize wxStaticText::DoGetBestSize() const
8208e181 72{
43524b15
DS
73 ControlFontStyleRec controlFont;
74 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
75 verify_noerr( err );
76
77 Point bounds;
78 SInt16 baseline;
79 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
80
943b730f 81 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
43524b15
DS
82 {
83 err = GetThemeTextDimensions(
84 (m_label.Length() > 0 ? (CFStringRef)str : CFSTR(" ")),
85 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
86 verify_noerr( err );
87 }
943b730f
SC
88 else
89 {
43524b15
DS
90 wxMacWindowStateSaver sv( this );
91 ::TextFont( m_font.MacGetFontNum() );
92 ::TextSize( (short)(m_font.MacGetFontSize()) );
93 ::TextFace( m_font.MacGetFontStyle() );
94
95 err = GetThemeTextDimensions(
96 (m_label.Length() > 0 ? (CFStringRef)str : CFSTR(" ")),
97 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
98 verify_noerr( err );
943b730f 99 }
43524b15 100
b1d7de5a 101 if ( m_label.Length() == 0 )
a074f61e 102 bounds.h = 0;
43524b15
DS
103
104 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
105 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
106
107 return wxSize( bounds.h, bounds.v );
8208e181
SC
108}
109
43524b15 110void wxStaticText::SetLabel( const wxString& st )
e9576ca5 111{
43524b15 112 m_label = wxStripMenuCodes( st );
2f1ae414 113
43524b15
DS
114 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
115 CFStringRef ref = str;
116 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
117 verify_noerr( err );
e9576ca5 118
c0e6c051
RD
119 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
120 {
9f884528 121 InvalidateBestSize();
43524b15 122 SetSize( GetBestSize() );
c0e6c051 123 }
43524b15
DS
124
125 Refresh();
126
3a0ec6eb 127 // we shouldn't need forced updates
a074f61e 128 // Update();
bb751cf9
RD
129}
130
c0e6c051
RD
131bool wxStaticText::SetFont(const wxFont& font)
132{
43524b15 133 bool ret = wxControl::SetFont( font );
c0e6c051 134
43524b15
DS
135 if ( ret )
136 {
137 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
441b46ac
SC
138 {
139 InvalidateBestSize();
140 SetSize( GetBestSize() );
141 }
43524b15 142 }
c0e6c051
RD
143
144 return ret;
145}
c545950d
RN
146
147#endif //if wxUSE_STATTEXT
148