]>
Commit | Line | Data |
---|---|---|
489468fe SC |
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 | ||
1f0c8f31 | 29 | #include "wx/osx/uma.h" |
489468fe SC |
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 | if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) | |
47 | return false; | |
48 | ||
49 | Rect bounds = wxMacGetBoundsForControl( this, pos, size ); | |
50 | ||
51 | m_peer = new wxMacControl( this ); | |
52 | OSStatus err = CreateStaticTextControl( | |
53 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
54 | &bounds, NULL, NULL, m_peer->GetControlRefAddr() ); | |
55 | verify_noerr( err ); | |
56 | ||
57 | if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) | |
58 | { | |
59 | TruncCode tCode = truncEnd; | |
60 | if ( style & wxST_ELLIPSIZE_MIDDLE ) | |
61 | tCode = truncMiddle; | |
62 | ||
63 | err = m_peer->SetData( kControlStaticTextTruncTag, tCode ); | |
64 | err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
65 | } | |
66 | ||
67 | MacPostControlCreate( pos, size ); | |
68 | ||
69 | SetLabel(label); | |
70 | ||
71 | return true; | |
72 | } | |
73 | ||
74 | wxSize wxStaticText::DoGetBestSize() const | |
75 | { | |
76 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
77 | Point bounds; | |
78 | ||
79 | // try the built-in best size if available | |
80 | Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag); | |
81 | m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
82 | m_peer->GetBestRect( &bestsize ) ; | |
83 | m_peer->SetData( kControlStaticTextIsMultilineTag, former ); | |
84 | if ( !EmptyRect( &bestsize ) ) | |
85 | { | |
86 | bounds.h = bestsize.right - bestsize.left ; | |
87 | bounds.v = bestsize.bottom - bestsize.top ; | |
88 | } | |
89 | else | |
90 | { | |
91 | ControlFontStyleRec controlFont; | |
92 | OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); | |
93 | verify_noerr( err ); | |
94 | ||
95 | wxCFStringRef str( m_label, GetFont().GetEncoding() ); | |
96 | ||
97 | #if wxMAC_USE_ATSU_TEXT | |
98 | SInt16 baseline; | |
99 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
100 | { | |
101 | err = GetThemeTextDimensions( | |
102 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
103 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); | |
104 | verify_noerr( err ); | |
105 | } | |
106 | else | |
107 | #endif | |
108 | { | |
109 | wxClientDC dc(const_cast<wxStaticText*>(this)); | |
110 | wxCoord width, height ; | |
111 | dc.GetTextExtent( m_label , &width, &height); | |
112 | bounds.h = width; | |
113 | bounds.v = height; | |
114 | } | |
115 | ||
116 | if ( m_label.empty() ) | |
117 | bounds.h = 0; | |
118 | } | |
119 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
120 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
121 | ||
122 | return wxSize( bounds.h, bounds.v ); | |
123 | } | |
124 | ||
125 | void wxStaticText::SetLabel(const wxString& label) | |
126 | { | |
127 | m_labelOrig = label; | |
128 | ||
129 | // middle/end ellipsization is handled by the OS: | |
130 | if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) ) | |
131 | { | |
132 | // remove markup | |
133 | wxString str(label); | |
134 | if (HasFlag(wxST_MARKUP)) | |
135 | str = RemoveMarkup(label); | |
136 | ||
137 | // and leave ellipsization to the OS | |
138 | DoSetLabel(str); | |
139 | } | |
140 | else // not supported natively | |
141 | { | |
142 | DoSetLabel(GetEllipsizedLabelWithoutMarkup()); | |
143 | } | |
144 | ||
145 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) && | |
146 | !IsEllipsized() ) // don't resize if we adjust to current size | |
147 | { | |
148 | InvalidateBestSize(); | |
149 | SetSize( GetBestSize() ); | |
150 | } | |
151 | ||
152 | Refresh(); | |
153 | ||
154 | // we shouldn't need forced updates | |
155 | // Update(); | |
156 | } | |
157 | ||
158 | bool wxStaticText::SetFont(const wxFont& font) | |
159 | { | |
160 | bool ret = wxControl::SetFont( font ); | |
161 | ||
162 | if ( ret ) | |
163 | { | |
164 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
165 | { | |
166 | InvalidateBestSize(); | |
167 | SetSize( GetBestSize() ); | |
168 | } | |
169 | } | |
170 | ||
171 | return ret; | |
172 | } | |
173 | ||
174 | ||
175 | // for wxST_ELLIPSIZE_* support: | |
176 | ||
177 | void wxStaticText::DoSetLabel(const wxString& label) | |
178 | { | |
179 | m_labelOrig = label; | |
180 | m_label = RemoveMnemonics(label); | |
181 | ||
182 | wxCFStringRef str( m_label, GetFont().GetEncoding() ); | |
183 | OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, str); | |
184 | verify_noerr( err ); | |
185 | } | |
186 | ||
187 | wxString wxStaticText::DoGetLabel() const | |
188 | { | |
189 | return m_label; | |
190 | } | |
191 | ||
192 | /* | |
193 | FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set | |
194 | to allow correct dynamic ellipsizing of the label | |
195 | */ | |
196 | ||
197 | #endif //if wxUSE_STATTEXT |