]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/stattext.cpp
cleanup
[wxWidgets.git] / src / mac / carbon / stattext.cpp
... / ...
CommitLineData
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
33IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
34
35
36bool 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
74wxSize 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 SInt16 baseline;
96 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
97
98#ifndef __LP64__
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 #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 }
131 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
132 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
133
134 return wxSize( bounds.h, bounds.v );
135}
136
137void wxStaticText::SetLabel(const wxString& label)
138{
139 m_labelOrig = label;
140
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);
148
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
159 {
160 InvalidateBestSize();
161 SetSize( GetBestSize() );
162 }
163
164 Refresh();
165
166 // we shouldn't need forced updates
167 // Update();
168}
169
170bool wxStaticText::SetFont(const wxFont& font)
171{
172 bool ret = wxControl::SetFont( font );
173
174 if ( ret )
175 {
176 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
177 {
178 InvalidateBestSize();
179 SetSize( GetBestSize() );
180 }
181 }
182
183 return ret;
184}
185
186
187// for wxST_ELLIPSIZE_* support:
188
189void wxStaticText::DoSetLabel(const wxString& label)
190{
191 m_labelOrig = label;
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
199wxString 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
209#endif //if wxUSE_STATTEXT