]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/stattext.cpp
fixing the shrinking embedded controls
[wxWidgets.git] / src / mac / carbon / stattext.cpp
CommitLineData
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 33IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
e9576ca5 34
519cb848 35
43524b15
DS
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 )
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 74wxSize 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
4d7e2cda
SC
98 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
99 {
100 err = GetThemeTextDimensions(
101 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
102 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
103 verify_noerr( err );
104 }
105 else
106 {
107 #if wxMAC_USE_CORE_GRAPHICS
108 wxClientDC dc(const_cast<wxStaticText*>(this));
109 wxCoord width, height ;
110 dc.GetTextExtent( m_label , &width, &height);
111 bounds.h = width;
112 bounds.v = height;
113 #else
114 wxMacWindowStateSaver sv( this );
115 ::TextFont( m_font.MacGetFontNum() );
116 ::TextSize( (short)(m_font.MacGetFontSize()) );
117 ::TextFace( m_font.MacGetFontStyle() );
118
119 err = GetThemeTextDimensions(
120 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
121 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
122 verify_noerr( err );
123 #endif
124 }
125
126 if ( m_label.empty() )
127 bounds.h = 0;
128 }
43524b15
DS
129 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
130 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
131
132 return wxSize( bounds.h, bounds.v );
8208e181
SC
133}
134
39bc0347 135void wxStaticText::SetLabel(const wxString& label)
e9576ca5 136{
39bc0347 137 m_labelOrig = label;
2f1ae414 138
39bc0347
VZ
139 // middle/end ellipsization is handled by the OS:
140 if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) )
141 {
142 // remove markup
143 wxString str(label);
144 if (HasFlag(wxST_MARKUP))
145 str = RemoveMarkup(label);
e9576ca5 146
39bc0347
VZ
147 // and leave ellipsization to the OS
148 DoSetLabel(str);
149 }
150 else // not supported natively
151 {
152 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
153 }
154
155 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
156 !IsEllipsized() ) // don't resize if we adjust to current size
c0e6c051 157 {
9f884528 158 InvalidateBestSize();
43524b15 159 SetSize( GetBestSize() );
c0e6c051 160 }
43524b15
DS
161
162 Refresh();
163
3a0ec6eb 164 // we shouldn't need forced updates
a074f61e 165 // Update();
bb751cf9
RD
166}
167
c0e6c051
RD
168bool wxStaticText::SetFont(const wxFont& font)
169{
43524b15 170 bool ret = wxControl::SetFont( font );
c0e6c051 171
43524b15
DS
172 if ( ret )
173 {
174 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
441b46ac
SC
175 {
176 InvalidateBestSize();
177 SetSize( GetBestSize() );
178 }
43524b15 179 }
c0e6c051
RD
180
181 return ret;
182}
c545950d 183
39bc0347
VZ
184
185// for wxST_ELLIPSIZE_* support:
186
187void wxStaticText::DoSetLabel(const wxString& label)
188{
189 m_label = RemoveMnemonics(label);
190
191 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
192 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, str);
193 verify_noerr( err );
194}
195
196wxString wxStaticText::DoGetLabel() const
197{
198 return m_label;
199}
200
201/*
202 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
203 to allow correct dynamic ellipsizing of the label
204*/
205
c545950d 206#endif //if wxUSE_STATTEXT