]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/stattext.cpp
using new API (no visual difference)
[wxWidgets.git] / src / mac / carbon / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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
29 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
30
31
32 bool 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 MacPostControlCreate( pos, size );
57
58 return true;
59 }
60
61 wxSize wxStaticText::DoGetBestSize() const
62 {
63 ControlFontStyleRec controlFont;
64 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
65 verify_noerr( err );
66
67 Point bounds;
68 SInt16 baseline;
69 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
70
71 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
72 {
73 err = GetThemeTextDimensions(
74 (m_label.Length() > 0 ? (CFStringRef)str : CFSTR(" ")),
75 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
76 verify_noerr( err );
77 }
78 else
79 {
80 wxMacWindowStateSaver sv( this );
81 ::TextFont( m_font.MacGetFontNum() );
82 ::TextSize( (short)(m_font.MacGetFontSize()) );
83 ::TextFace( m_font.MacGetFontStyle() );
84
85 err = GetThemeTextDimensions(
86 (m_label.Length() > 0 ? (CFStringRef)str : CFSTR(" ")),
87 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
88 verify_noerr( err );
89 }
90
91 if ( m_label.Length() == 0 )
92 bounds.h = 0 ;
93
94 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
95 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
96
97 return wxSize( bounds.h, bounds.v );
98 }
99
100 void wxStaticText::SetLabel( const wxString& st )
101 {
102 m_label = wxStripMenuCodes( st );
103
104 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
105 CFStringRef ref = str;
106 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
107 verify_noerr( err );
108
109 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
110 {
111 InvalidateBestSize();
112 SetSize( GetBestSize() );
113 }
114
115 Refresh();
116
117 // we shouldn't need forced updates
118 // Update() ;
119 }
120
121 bool wxStaticText::SetFont(const wxFont& font)
122 {
123 bool ret = wxControl::SetFont( font );
124
125 if ( ret )
126 {
127 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
128 {
129 InvalidateBestSize();
130 SetSize( GetBestSize() );
131 }
132 }
133
134 return ret;
135 }
136
137 #endif //if wxUSE_STATTEXT
138