]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/stattext.cpp
fixed wxFrame background colour in wxUniv on ports without native wxSYS_COLOUR_APPWOR...
[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 m_peer->GetBestRect( &bestsize ) ;
82 if ( !EmptyRect( &bestsize ) )
83 {
84 bounds.h = bestsize.right - bestsize.left ;
85 bounds.v = bestsize.bottom - bestsize.top ;
86 }
87 else
88 {
89 ControlFontStyleRec controlFont;
90 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
91 verify_noerr( err );
92
93 SInt16 baseline;
94 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
95
96 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
97 {
98 err = GetThemeTextDimensions(
99 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
100 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
101 verify_noerr( err );
102 }
103 else
104 {
105 #if wxMAC_USE_CORE_GRAPHICS
106 wxClientDC dc(const_cast<wxStaticText*>(this));
107 wxCoord width, height ;
108 dc.GetTextExtent( m_label , &width, &height);
109 bounds.h = width;
110 bounds.v = height;
111 #else
112 wxMacWindowStateSaver sv( this );
113 ::TextFont( m_font.MacGetFontNum() );
114 ::TextSize( (short)(m_font.MacGetFontSize()) );
115 ::TextFace( m_font.MacGetFontStyle() );
116
117 err = GetThemeTextDimensions(
118 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
119 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
120 verify_noerr( err );
121 #endif
122 }
123
124 if ( m_label.empty() )
125 bounds.h = 0;
126 }
127 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
128 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
129
130 return wxSize( bounds.h, bounds.v );
131 }
132
133 void wxStaticText::SetLabel( const wxString& st )
134 {
135 m_label = GetLabelText( st );
136
137 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
138 CFStringRef ref = str;
139 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
140 verify_noerr( err );
141
142 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
143 {
144 InvalidateBestSize();
145 SetSize( GetBestSize() );
146 }
147
148 Refresh();
149
150 // we shouldn't need forced updates
151 // Update();
152 }
153
154 bool wxStaticText::SetFont(const wxFont& font)
155 {
156 bool ret = wxControl::SetFont( font );
157
158 if ( ret )
159 {
160 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
161 {
162 InvalidateBestSize();
163 SetSize( GetBestSize() );
164 }
165 }
166
167 return ret;
168 }
169
170 #endif //if wxUSE_STATTEXT