]>
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 | 95 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); |
43524b15 | 96 | |
8b534a7b SC |
97 | #if wxMAC_USE_ATSU_TEXT |
98 | SInt16 baseline; | |
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 | 108 | { |
4d7e2cda SC |
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; | |
4d7e2cda SC |
114 | } |
115 | ||
116 | if ( m_label.empty() ) | |
117 | bounds.h = 0; | |
118 | } | |
43524b15 DS |
119 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); |
120 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
121 | ||
122 | return wxSize( bounds.h, bounds.v ); | |
8208e181 SC |
123 | } |
124 | ||
39bc0347 | 125 | void wxStaticText::SetLabel(const wxString& label) |
e9576ca5 | 126 | { |
39bc0347 | 127 | m_labelOrig = label; |
2f1ae414 | 128 | |
39bc0347 VZ |
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); | |
e9576ca5 | 136 | |
39bc0347 VZ |
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 | |
c0e6c051 | 147 | { |
9f884528 | 148 | InvalidateBestSize(); |
43524b15 | 149 | SetSize( GetBestSize() ); |
c0e6c051 | 150 | } |
43524b15 DS |
151 | |
152 | Refresh(); | |
153 | ||
3a0ec6eb | 154 | // we shouldn't need forced updates |
a074f61e | 155 | // Update(); |
bb751cf9 RD |
156 | } |
157 | ||
c0e6c051 RD |
158 | bool wxStaticText::SetFont(const wxFont& font) |
159 | { | |
43524b15 | 160 | bool ret = wxControl::SetFont( font ); |
c0e6c051 | 161 | |
43524b15 DS |
162 | if ( ret ) |
163 | { | |
164 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
441b46ac SC |
165 | { |
166 | InvalidateBestSize(); | |
167 | SetSize( GetBestSize() ); | |
168 | } | |
43524b15 | 169 | } |
c0e6c051 RD |
170 | |
171 | return ret; | |
172 | } | |
c545950d | 173 | |
39bc0347 VZ |
174 | |
175 | // for wxST_ELLIPSIZE_* support: | |
176 | ||
177 | void wxStaticText::DoSetLabel(const wxString& label) | |
178 | { | |
ab0f37b9 | 179 | m_labelOrig = label; |
39bc0347 VZ |
180 | m_label = RemoveMnemonics(label); |
181 | ||
182 | wxMacCFStringHolder str( m_label, m_font.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 | ||
c545950d | 197 | #endif //if wxUSE_STATTEXT |