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