]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/stattext.cpp
Workaround for wxUSE_STL
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "stattext.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #if wxUSE_STATTEXT
19
20 #include "wx/app.h"
21 #include "wx/stattext.h"
22 #include "wx/notebook.h"
23 #include "wx/tabctrl.h"
24 #include "wx/dc.h"
25 #include "wx/dcclient.h"
26 #include "wx/utils.h"
27 #include "wx/settings.h"
28
29 #include <stdio.h>
30
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
33 #endif
34
35 #include "wx/mac/uma.h"
36
37 bool wxStaticText::Create(wxWindow *parent, 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 = wxStripMenuCodes(label) ;
47
48 if ( !wxControl::Create( parent, id, pos, size, style,
49 wxDefaultValidator , name ) )
50 {
51 return false;
52 }
53
54 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
55 wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
56 m_peer = new wxMacControl(this) ;
57 verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str ,
58 NULL , m_peer->GetControlRefAddr() ) ) ;
59
60 MacPostControlCreate(pos,size) ;
61
62 return true;
63 }
64
65 wxSize wxStaticText::DoGetBestSize() const
66 {
67 ControlFontStyleRec controlFont ;
68 verify_noerr( m_peer->GetData<ControlFontStyleRec>(kControlEntireControl , kControlFontStyleTag , &controlFont ) ) ;
69
70 Point bounds ;
71 SInt16 baseline ;
72 wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ;
73 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
74 verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ;
75 else
76 {
77 wxMacWindowStateSaver sv( this ) ;
78 ::TextFont( m_font.MacGetFontNum() ) ;
79 ::TextSize( (short)( m_font.MacGetFontSize()) ) ;
80 ::TextFace( m_font.MacGetFontStyle() ) ;
81 verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , kThemeCurrentPortFont , kThemeStateActive , false , &bounds , &baseline ) ) ;
82 }
83 if ( m_label.Length() == 0 )
84 bounds.h = 0 ;
85
86 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
87 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
88 return wxSize(bounds.h, bounds.v);
89 }
90
91 void wxStaticText::SetLabel(const wxString& st )
92 {
93
94 m_label = wxStripMenuCodes(st) ;
95
96 wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
97 CFStringRef ref = str ;
98 verify_noerr( m_peer->SetData<CFStringRef>(kControlEntireControl , kControlStaticTextCFStringTag, ref ) ) ;
99
100 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
101 {
102 InvalidateBestSize();
103 SetSize( GetBestSize() ) ;
104 }
105 Refresh() ;
106 Update() ;
107 }
108
109 bool wxStaticText::SetFont(const wxFont& font)
110 {
111 bool ret = wxControl::SetFont(font);
112
113 if ( ret )
114 {
115 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
116 {
117 InvalidateBestSize();
118 SetSize( GetBestSize() );
119 }
120 }
121
122 return ret;
123 }
124
125 #endif //if wxUSE_STATTEXT
126