]>
Commit | Line | Data |
---|---|---|
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 | ControlFontStyleRec controlFont; | |
78 | OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); | |
79 | verify_noerr( err ); | |
80 | ||
81 | Point bounds; | |
82 | SInt16 baseline; | |
83 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
84 | ||
85 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
86 | { | |
87 | err = GetThemeTextDimensions( | |
88 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
89 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); | |
90 | verify_noerr( err ); | |
91 | } | |
92 | else | |
93 | { | |
94 | #if wxMAC_USE_CORE_GRAPHICS | |
95 | wxClientDC dc(const_cast<wxStaticText*>(this)); | |
96 | wxCoord width, height ; | |
97 | dc.GetTextExtent( m_label , &width, &height); | |
98 | bounds.h = width; | |
99 | bounds.v = height; | |
100 | #else | |
101 | wxMacWindowStateSaver sv( this ); | |
102 | ::TextFont( m_font.MacGetFontNum() ); | |
103 | ::TextSize( (short)(m_font.MacGetFontSize()) ); | |
104 | ::TextFace( m_font.MacGetFontStyle() ); | |
105 | ||
106 | err = GetThemeTextDimensions( | |
107 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
108 | kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); | |
109 | verify_noerr( err ); | |
110 | #endif | |
111 | } | |
112 | ||
113 | if ( m_label.empty() ) | |
114 | bounds.h = 0; | |
115 | ||
116 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
117 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
118 | ||
119 | return wxSize( bounds.h, bounds.v ); | |
120 | } | |
121 | ||
122 | void wxStaticText::SetLabel( const wxString& st ) | |
123 | { | |
124 | m_label = GetLabelText( st ); | |
125 | ||
126 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
127 | CFStringRef ref = str; | |
128 | OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref ); | |
129 | verify_noerr( err ); | |
130 | ||
131 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
132 | { | |
133 | InvalidateBestSize(); | |
134 | SetSize( GetBestSize() ); | |
135 | } | |
136 | ||
137 | Refresh(); | |
138 | ||
139 | // we shouldn't need forced updates | |
140 | // Update(); | |
141 | } | |
142 | ||
143 | bool wxStaticText::SetFont(const wxFont& font) | |
144 | { | |
145 | bool ret = wxControl::SetFont( font ); | |
146 | ||
147 | if ( ret ) | |
148 | { | |
149 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
150 | { | |
151 | InvalidateBestSize(); | |
152 | SetSize( GetBestSize() ); | |
153 | } | |
154 | } | |
155 | ||
156 | return ret; | |
157 | } | |
158 | ||
159 | #endif //if wxUSE_STATTEXT |