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