]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/stattext.cpp
no changes, just corrected the comment for wxConvLocal
[wxWidgets.git] / src / mac / carbon / stattext.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/stattext.cpp
3// Purpose: wxStaticText
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#if wxUSE_STATTEXT
15
16#include "wx/app.h"
17#include "wx/stattext.h"
18#include "wx/notebook.h"
19#include "wx/tabctrl.h"
20#include "wx/dc.h"
21#include "wx/dcclient.h"
22#include "wx/utils.h"
23#include "wx/settings.h"
24
25#include "wx/mac/uma.h"
26
27#include <stdio.h>
28
29IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
30
31
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 )
39{
40 m_macIsUserPane = false;
41
42 m_label = wxStripMenuCodes( label );
43
44 if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
45 return false;
46
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 );
55
56 if ( ( style & wxST_DOTS_END ) || ( style & wxST_DOTS_MIDDLE ) )
57 {
58 TruncCode tCode = truncEnd;
59 if ( style & wxST_DOTS_MIDDLE )
60 tCode = truncMiddle;
61
62 err = m_peer->SetData( kControlStaticTextTruncTag, tCode );
63 err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
64 }
65
66 MacPostControlCreate( pos, size );
67
68 return true;
69}
70
71wxSize wxStaticText::DoGetBestSize() const
72{
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
81 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
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 }
88 else
89 {
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 );
99 }
100
101 if ( m_label.Length() == 0 )
102 bounds.h = 0;
103
104 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
105 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
106
107 return wxSize( bounds.h, bounds.v );
108}
109
110void wxStaticText::SetLabel( const wxString& st )
111{
112 m_label = wxStripMenuCodes( st );
113
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 );
118
119 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
120 {
121 InvalidateBestSize();
122 SetSize( GetBestSize() );
123 }
124
125 Refresh();
126
127 // we shouldn't need forced updates
128 // Update();
129}
130
131bool wxStaticText::SetFont(const wxFont& font)
132{
133 bool ret = wxControl::SetFont( font );
134
135 if ( ret )
136 {
137 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
138 {
139 InvalidateBestSize();
140 SetSize( GetBestSize() );
141 }
142 }
143
144 return ret;
145}
146
147#endif //if wxUSE_STATTEXT
148