]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
a074f61e | 2 | // Name: src/mac/carbon/stattext.cpp |
e9576ca5 | 3 | // Purpose: wxStaticText |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
c545950d RN |
14 | #if wxUSE_STATTEXT |
15 | ||
e9576ca5 | 16 | #include "wx/stattext.h" |
670f9935 WS |
17 | |
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/app.h" | |
de6185e2 | 20 | #include "wx/utils.h" |
da80ae71 | 21 | #include "wx/dc.h" |
ed4b0fdc | 22 | #include "wx/dcclient.h" |
9eddec69 | 23 | #include "wx/settings.h" |
670f9935 WS |
24 | #endif // WX_PRECOMP |
25 | ||
bedaf53e SC |
26 | #include "wx/notebook.h" |
27 | #include "wx/tabctrl.h" | |
e9576ca5 | 28 | |
43524b15 DS |
29 | #include "wx/mac/uma.h" |
30 | ||
e9576ca5 SC |
31 | #include <stdio.h> |
32 | ||
90b959ae | 33 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
e9576ca5 | 34 | |
519cb848 | 35 | |
43524b15 DS |
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 ) | |
8208e181 | 43 | { |
43524b15 | 44 | m_macIsUserPane = false; |
8208e181 | 45 | |
43524b15 | 46 | if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) |
b45ed7a2 | 47 | return false; |
b45ed7a2 | 48 | |
43524b15 | 49 | Rect bounds = wxMacGetBoundsForControl( this, pos, size ); |
43524b15 DS |
50 | |
51 | m_peer = new wxMacControl( this ); | |
52 | OSStatus err = CreateStaticTextControl( | |
53 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
39bc0347 | 54 | &bounds, NULL, NULL, m_peer->GetControlRefAddr() ); |
43524b15 | 55 | verify_noerr( err ); |
b8c140b8 | 56 | |
39bc0347 | 57 | if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) |
14132857 | 58 | { |
a074f61e | 59 | TruncCode tCode = truncEnd; |
39bc0347 | 60 | if ( style & wxST_ELLIPSIZE_MIDDLE ) |
a074f61e DS |
61 | tCode = truncMiddle; |
62 | ||
63 | err = m_peer->SetData( kControlStaticTextTruncTag, tCode ); | |
64 | err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
14132857 | 65 | } |
a074f61e | 66 | |
43524b15 | 67 | MacPostControlCreate( pos, size ); |
7595f381 | 68 | |
39bc0347 VZ |
69 | SetLabel(label); |
70 | ||
facd6764 | 71 | return true; |
9714ffa0 SC |
72 | } |
73 | ||
facd6764 | 74 | wxSize wxStaticText::DoGetBestSize() const |
8208e181 | 75 | { |
4d7e2cda | 76 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
43524b15 | 77 | Point bounds; |
4d7e2cda SC |
78 | |
79 | // try the built-in best size if available | |
4b6930c8 SC |
80 | Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag); |
81 | m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
4d7e2cda | 82 | m_peer->GetBestRect( &bestsize ) ; |
4b6930c8 | 83 | m_peer->SetData( kControlStaticTextIsMultilineTag, former ); |
4d7e2cda | 84 | if ( !EmptyRect( &bestsize ) ) |
43524b15 | 85 | { |
4d7e2cda SC |
86 | bounds.h = bestsize.right - bestsize.left ; |
87 | bounds.v = bestsize.bottom - bestsize.top ; | |
43524b15 | 88 | } |
943b730f SC |
89 | else |
90 | { | |
4d7e2cda SC |
91 | ControlFontStyleRec controlFont; |
92 | OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); | |
43524b15 | 93 | verify_noerr( err ); |
43524b15 | 94 | |
4d7e2cda SC |
95 | SInt16 baseline; |
96 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
43524b15 | 97 | |
6239ee05 | 98 | #ifndef __LP64__ |
4d7e2cda SC |
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 | |
6239ee05 | 107 | #endif |
4d7e2cda SC |
108 | { |
109 | #if wxMAC_USE_CORE_GRAPHICS | |
110 | wxClientDC dc(const_cast<wxStaticText*>(this)); | |
111 | wxCoord width, height ; | |
112 | dc.GetTextExtent( m_label , &width, &height); | |
113 | bounds.h = width; | |
114 | bounds.v = height; | |
115 | #else | |
116 | wxMacWindowStateSaver sv( this ); | |
117 | ::TextFont( m_font.MacGetFontNum() ); | |
118 | ::TextSize( (short)(m_font.MacGetFontSize()) ); | |
119 | ::TextFace( m_font.MacGetFontStyle() ); | |
120 | ||
121 | err = GetThemeTextDimensions( | |
122 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
123 | kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); | |
124 | verify_noerr( err ); | |
125 | #endif | |
126 | } | |
127 | ||
128 | if ( m_label.empty() ) | |
129 | bounds.h = 0; | |
130 | } | |
43524b15 DS |
131 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); |
132 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
133 | ||
134 | return wxSize( bounds.h, bounds.v ); | |
8208e181 SC |
135 | } |
136 | ||
39bc0347 | 137 | void wxStaticText::SetLabel(const wxString& label) |
e9576ca5 | 138 | { |
39bc0347 | 139 | m_labelOrig = label; |
2f1ae414 | 140 | |
39bc0347 VZ |
141 | // middle/end ellipsization is handled by the OS: |
142 | if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) ) | |
143 | { | |
144 | // remove markup | |
145 | wxString str(label); | |
146 | if (HasFlag(wxST_MARKUP)) | |
147 | str = RemoveMarkup(label); | |
e9576ca5 | 148 | |
39bc0347 VZ |
149 | // and leave ellipsization to the OS |
150 | DoSetLabel(str); | |
151 | } | |
152 | else // not supported natively | |
153 | { | |
154 | DoSetLabel(GetEllipsizedLabelWithoutMarkup()); | |
155 | } | |
156 | ||
157 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) && | |
158 | !IsEllipsized() ) // don't resize if we adjust to current size | |
c0e6c051 | 159 | { |
9f884528 | 160 | InvalidateBestSize(); |
43524b15 | 161 | SetSize( GetBestSize() ); |
c0e6c051 | 162 | } |
43524b15 DS |
163 | |
164 | Refresh(); | |
165 | ||
3a0ec6eb | 166 | // we shouldn't need forced updates |
a074f61e | 167 | // Update(); |
bb751cf9 RD |
168 | } |
169 | ||
c0e6c051 RD |
170 | bool wxStaticText::SetFont(const wxFont& font) |
171 | { | |
43524b15 | 172 | bool ret = wxControl::SetFont( font ); |
c0e6c051 | 173 | |
43524b15 DS |
174 | if ( ret ) |
175 | { | |
176 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
441b46ac SC |
177 | { |
178 | InvalidateBestSize(); | |
179 | SetSize( GetBestSize() ); | |
180 | } | |
43524b15 | 181 | } |
c0e6c051 RD |
182 | |
183 | return ret; | |
184 | } | |
c545950d | 185 | |
39bc0347 VZ |
186 | |
187 | // for wxST_ELLIPSIZE_* support: | |
188 | ||
189 | void wxStaticText::DoSetLabel(const wxString& label) | |
190 | { | |
ab0f37b9 | 191 | m_labelOrig = label; |
39bc0347 VZ |
192 | m_label = RemoveMnemonics(label); |
193 | ||
194 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
195 | OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, str); | |
196 | verify_noerr( err ); | |
197 | } | |
198 | ||
199 | wxString wxStaticText::DoGetLabel() const | |
200 | { | |
201 | return m_label; | |
202 | } | |
203 | ||
204 | /* | |
205 | FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set | |
206 | to allow correct dynamic ellipsizing of the label | |
207 | */ | |
208 | ||
c545950d | 209 | #endif //if wxUSE_STATTEXT |