]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/stattext.cpp
wx/log.h belongs to pch system
[wxWidgets.git] / src / mac / carbon / stattext.cpp
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/stattext.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dc.h"
22 #include "wx/dcclient.h"
23 #include "wx/settings.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/notebook.h"
27 #include "wx/tabctrl.h"
28
29 #include "wx/mac/uma.h"
30
31 #include <stdio.h>
32
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
34
35
36 bool 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 )
43 {
44 m_macIsUserPane = false;
45
46 m_label = GetLabelText( label );
47
48 if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
49 return false;
50
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 );
59
60 if ( ( style & wxST_DOTS_END ) || ( style & wxST_DOTS_MIDDLE ) )
61 {
62 TruncCode tCode = truncEnd;
63 if ( style & wxST_DOTS_MIDDLE )
64 tCode = truncMiddle;
65
66 err = m_peer->SetData( kControlStaticTextTruncTag, tCode );
67 err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
68 }
69
70 MacPostControlCreate( pos, size );
71
72 return true;
73 }
74
75 wxSize wxStaticText::DoGetBestSize() const
76 {
77 Rect bestsize = { 0 , 0 , 0 , 0 } ;
78 Point bounds;
79
80 // try the built-in best size if available
81 Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag);
82 m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
83 m_peer->GetBestRect( &bestsize ) ;
84 m_peer->SetData( kControlStaticTextIsMultilineTag, former );
85 if ( !EmptyRect( &bestsize ) )
86 {
87 bounds.h = bestsize.right - bestsize.left ;
88 bounds.v = bestsize.bottom - bestsize.top ;
89 }
90 else
91 {
92 ControlFontStyleRec controlFont;
93 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
94 verify_noerr( err );
95
96 SInt16 baseline;
97 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
98
99 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
100 {
101 err = GetThemeTextDimensions(
102 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
103 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
104 verify_noerr( err );
105 }
106 else
107 {
108 #if wxMAC_USE_CORE_GRAPHICS
109 wxClientDC dc(const_cast<wxStaticText*>(this));
110 wxCoord width, height ;
111 dc.GetTextExtent( m_label , &width, &height);
112 bounds.h = width;
113 bounds.v = height;
114 #else
115 wxMacWindowStateSaver sv( this );
116 ::TextFont( m_font.MacGetFontNum() );
117 ::TextSize( (short)(m_font.MacGetFontSize()) );
118 ::TextFace( m_font.MacGetFontStyle() );
119
120 err = GetThemeTextDimensions(
121 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
122 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
123 verify_noerr( err );
124 #endif
125 }
126
127 if ( m_label.empty() )
128 bounds.h = 0;
129 }
130 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
131 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
132
133 return wxSize( bounds.h, bounds.v );
134 }
135
136 void wxStaticText::SetLabel( const wxString& st )
137 {
138 m_label = GetLabelText( st );
139
140 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
141 CFStringRef ref = str;
142 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
143 verify_noerr( err );
144
145 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
146 {
147 InvalidateBestSize();
148 SetSize( GetBestSize() );
149 }
150
151 Refresh();
152
153 // we shouldn't need forced updates
154 // Update();
155 }
156
157 bool wxStaticText::SetFont(const wxFont& font)
158 {
159 bool ret = wxControl::SetFont( font );
160
161 if ( ret )
162 {
163 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
164 {
165 InvalidateBestSize();
166 SetSize( GetBestSize() );
167 }
168 }
169
170 return ret;
171 }
172
173 #endif //if wxUSE_STATTEXT