]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/stattext.cpp
Added wxSearchCtrl::[Get|Set]DescriptiveText
[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
32cd189d 46 m_label = GetLabelText( label );
43524b15
DS
47
48 if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
b45ed7a2 49 return false;
b45ed7a2 50
43524b15
DS
51 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
52 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
53
54 m_peer = new wxMacControl( this );
55 OSStatus err = CreateStaticTextControl(
56 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
57 &bounds, str, NULL, m_peer->GetControlRefAddr() );
58 verify_noerr( err );
b8c140b8 59
a074f61e 60 if ( ( style & wxST_DOTS_END ) || ( style & wxST_DOTS_MIDDLE ) )
14132857 61 {
a074f61e 62 TruncCode tCode = truncEnd;
14132857 63 if ( style & wxST_DOTS_MIDDLE )
a074f61e
DS
64 tCode = truncMiddle;
65
66 err = m_peer->SetData( kControlStaticTextTruncTag, tCode );
67 err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
14132857 68 }
a074f61e 69
43524b15 70 MacPostControlCreate( pos, size );
7595f381 71
facd6764 72 return true;
9714ffa0
SC
73}
74
facd6764 75wxSize wxStaticText::DoGetBestSize() const
8208e181 76{
4d7e2cda 77 Rect bestsize = { 0 , 0 , 0 , 0 } ;
43524b15 78 Point bounds;
4d7e2cda
SC
79
80 // try the built-in best size if available
4b6930c8
SC
81 Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag);
82 m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
4d7e2cda 83 m_peer->GetBestRect( &bestsize ) ;
4b6930c8 84 m_peer->SetData( kControlStaticTextIsMultilineTag, former );
4d7e2cda 85 if ( !EmptyRect( &bestsize ) )
43524b15 86 {
4d7e2cda
SC
87 bounds.h = bestsize.right - bestsize.left ;
88 bounds.v = bestsize.bottom - bestsize.top ;
43524b15 89 }
943b730f
SC
90 else
91 {
4d7e2cda
SC
92 ControlFontStyleRec controlFont;
93 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
43524b15 94 verify_noerr( err );
43524b15 95
4d7e2cda
SC
96 SInt16 baseline;
97 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
43524b15 98
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
107 {
108 #if wxMAC_USE_CORE_GRAPHICS
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 #else
115 wxMacWindowStateSaver sv( this );
116 ::TextFont( m_font.MacGetFontNum() );
117 ::TextSize( (short)(m_font.MacGetFontSize()) );
118 ::TextFace( m_font.MacGetFontStyle() );
119
120 err = GetThemeTextDimensions(
121 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
122 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
123 verify_noerr( err );
124 #endif
125 }
126
127 if ( m_label.empty() )
128 bounds.h = 0;
129 }
43524b15
DS
130 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
131 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
132
133 return wxSize( bounds.h, bounds.v );
8208e181
SC
134}
135
43524b15 136void wxStaticText::SetLabel( const wxString& st )
e9576ca5 137{
32cd189d 138 m_label = GetLabelText( st );
2f1ae414 139
43524b15
DS
140 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
141 CFStringRef ref = str;
142 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
143 verify_noerr( err );
e9576ca5 144
c0e6c051
RD
145 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
146 {
9f884528 147 InvalidateBestSize();
43524b15 148 SetSize( GetBestSize() );
c0e6c051 149 }
43524b15
DS
150
151 Refresh();
152
3a0ec6eb 153 // we shouldn't need forced updates
a074f61e 154 // Update();
bb751cf9
RD
155}
156
c0e6c051
RD
157bool wxStaticText::SetFont(const wxFont& font)
158{
43524b15 159 bool ret = wxControl::SetFont( font );
c0e6c051 160
43524b15
DS
161 if ( ret )
162 {
163 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
441b46ac
SC
164 {
165 InvalidateBestSize();
166 SetSize( GetBestSize() );
167 }
43524b15 168 }
c0e6c051
RD
169
170 return ret;
171}
c545950d
RN
172
173#endif //if wxUSE_STATTEXT