]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/stattext.cpp
Explicitly forward non-command events along to the native control first.
[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{
43524b15
DS
77 ControlFontStyleRec controlFont;
78 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
79 verify_noerr( err );
80
81 Point bounds;
82 SInt16 baseline;
83 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
84
943b730f 85 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
43524b15
DS
86 {
87 err = GetThemeTextDimensions(
670f9935 88 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
43524b15
DS
89 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
90 verify_noerr( err );
91 }
943b730f
SC
92 else
93 {
7cd7bc23
SC
94#if wxMAC_USE_CORE_GRAPHICS
95 wxClientDC dc(const_cast<wxStaticText*>(this));
96 wxCoord width, height ;
97 dc.GetTextExtent( m_label , &width, &height);
98 bounds.h = width;
99 bounds.v = height;
100#else
43524b15
DS
101 wxMacWindowStateSaver sv( this );
102 ::TextFont( m_font.MacGetFontNum() );
103 ::TextSize( (short)(m_font.MacGetFontSize()) );
104 ::TextFace( m_font.MacGetFontStyle() );
105
106 err = GetThemeTextDimensions(
670f9935 107 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
43524b15
DS
108 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
109 verify_noerr( err );
7cd7bc23 110#endif
943b730f 111 }
43524b15 112
670f9935 113 if ( m_label.empty() )
a074f61e 114 bounds.h = 0;
43524b15
DS
115
116 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
117 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
118
119 return wxSize( bounds.h, bounds.v );
8208e181
SC
120}
121
43524b15 122void wxStaticText::SetLabel( const wxString& st )
e9576ca5 123{
32cd189d 124 m_label = GetLabelText( st );
2f1ae414 125
43524b15
DS
126 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
127 CFStringRef ref = str;
128 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
129 verify_noerr( err );
e9576ca5 130
c0e6c051
RD
131 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
132 {
9f884528 133 InvalidateBestSize();
43524b15 134 SetSize( GetBestSize() );
c0e6c051 135 }
43524b15
DS
136
137 Refresh();
138
3a0ec6eb 139 // we shouldn't need forced updates
a074f61e 140 // Update();
bb751cf9
RD
141}
142
c0e6c051
RD
143bool wxStaticText::SetFont(const wxFont& font)
144{
43524b15 145 bool ret = wxControl::SetFont( font );
c0e6c051 146
43524b15
DS
147 if ( ret )
148 {
149 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
441b46ac
SC
150 {
151 InvalidateBestSize();
152 SetSize( GetBestSize() );
153 }
43524b15 154 }
c0e6c051
RD
155
156 return ret;
157}
c545950d
RN
158
159#endif //if wxUSE_STATTEXT