]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/stattext.cpp
cleanup - reformat
[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 <stdio.h>
26
27 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
28
29 #include "wx/mac/uma.h"
30
31 bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
32 const wxString& label,
33 const wxPoint& pos,
34 const wxSize& size,
35 long style,
36 const wxString& name)
37 {
38 m_macIsUserPane = FALSE ;
39
40 m_label = wxStripMenuCodes(label) ;
41
42 if ( !wxControl::Create( parent, id, pos, size, style,
43 wxDefaultValidator , name ) )
44 {
45 return false;
46 }
47
48 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
49 wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
50 m_peer = new wxMacControl(this) ;
51 verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str ,
52 NULL , m_peer->GetControlRefAddr() ) ) ;
53
54 MacPostControlCreate(pos,size) ;
55
56 return true;
57 }
58
59 wxSize wxStaticText::DoGetBestSize() const
60 {
61 ControlFontStyleRec controlFont ;
62 verify_noerr( m_peer->GetData<ControlFontStyleRec>(kControlEntireControl , kControlFontStyleTag , &controlFont ) ) ;
63
64 Point bounds ;
65 SInt16 baseline ;
66 wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ;
67 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
68 verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ;
69 else
70 {
71 wxMacWindowStateSaver sv( this ) ;
72 ::TextFont( m_font.MacGetFontNum() ) ;
73 ::TextSize( (short)( m_font.MacGetFontSize()) ) ;
74 ::TextFace( m_font.MacGetFontStyle() ) ;
75 verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , kThemeCurrentPortFont , kThemeStateActive , false , &bounds , &baseline ) ) ;
76 }
77 if ( m_label.Length() == 0 )
78 bounds.h = 0 ;
79
80 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
81 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
82 return wxSize(bounds.h, bounds.v);
83 }
84
85 void wxStaticText::SetLabel(const wxString& st )
86 {
87
88 m_label = wxStripMenuCodes(st) ;
89
90 wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
91 CFStringRef ref = str ;
92 verify_noerr( m_peer->SetData<CFStringRef>(kControlEntireControl , kControlStaticTextCFStringTag, ref ) ) ;
93
94 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
95 {
96 InvalidateBestSize();
97 SetSize( GetBestSize() ) ;
98 }
99 Refresh() ;
100 // we shouldn't need forced updates
101 // Update() ;
102 }
103
104 bool wxStaticText::SetFont(const wxFont& font)
105 {
106 bool ret = wxControl::SetFont(font);
107
108 if ( ret )
109 {
110 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
111 {
112 InvalidateBestSize();
113 SetSize( GetBestSize() );
114 }
115 }
116
117 return ret;
118 }
119
120 #endif //if wxUSE_STATTEXT
121