]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/stattext.cpp
new file added
[wxWidgets.git] / src / osx / carbon / stattext.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/stattext.cpp
489468fe
SC
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
524c47aa 26#include "wx/osx/private.h"
489468fe
SC
27
28#include <stdio.h>
29
524c47aa 30class wxMacStaticText : public wxMacControl
489468fe 31{
524c47aa
SC
32public:
33 wxMacStaticText( wxWindowMac* peer ) : wxMacControl(peer)
489468fe 34 {
489468fe 35 }
524c47aa
SC
36 void SetLabel(const wxString& title, wxFontEncoding encoding)
37 {
38 wxCFStringRef str( title, encoding );
39 OSStatus err = SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, str);
40 verify_noerr( err );
41 }
42};
489468fe
SC
43
44wxSize wxStaticText::DoGetBestSize() const
45{
489468fe 46 Point bounds;
524c47aa
SC
47#if wxOSX_USE_CARBON
48 Rect bestsize = { 0 , 0 , 0 , 0 } ;
489468fe
SC
49
50 // try the built-in best size if available
22756322
SC
51 Boolean former = GetPeer()->GetData<Boolean>( kControlStaticTextIsMultilineTag);
52 GetPeer()->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
53 GetPeer()->GetBestRect( &bestsize ) ;
54 GetPeer()->SetData( kControlStaticTextIsMultilineTag, former );
d15694e8 55
489468fe
SC
56 if ( !EmptyRect( &bestsize ) )
57 {
58 bounds.h = bestsize.right - bestsize.left ;
59 bounds.v = bestsize.bottom - bestsize.top ;
60 }
61 else
524c47aa 62#endif
489468fe 63 {
524c47aa 64#if wxOSX_USE_CARBON
489468fe 65 ControlFontStyleRec controlFont;
22756322 66 OSStatus err = GetPeer()->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
489468fe
SC
67 verify_noerr( err );
68
292e5e1f 69#if wxOSX_USE_ATSU_TEXT
489468fe
SC
70 SInt16 baseline;
71 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
72 {
03647350
VZ
73 // GetThemeTextDimensions will cache strings and the documentation
74 // says not to use the NoCopy string creation calls.
75 // This also means that we can't use CFSTR without
76 // -fno-constant-cfstrings if the library might be unloaded,
77 // as GetThemeTextDimensions may cache a pointer to our
78 // unloaded segment.
79 wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "),
6fd21e16 80 GetFont().GetEncoding() );
03647350 81
489468fe 82 err = GetThemeTextDimensions(
6fd21e16 83 (CFStringRef)str,
489468fe
SC
84 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
85 verify_noerr( err );
86 }
87 else
524c47aa 88#endif
489468fe
SC
89#endif
90 {
91 wxClientDC dc(const_cast<wxStaticText*>(this));
92 wxCoord width, height ;
93 dc.GetTextExtent( m_label , &width, &height);
94 bounds.h = width;
95 bounds.v = height;
96 }
97
98 if ( m_label.empty() )
99 bounds.h = 0;
100 }
101 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
102 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
103
104 return wxSize( bounds.h, bounds.v );
105}
106
524c47aa
SC
107/*
108 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
109 to allow correct dynamic ellipsizing of the label
110*/
489468fe 111
6e7a89af
FM
112wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
113 wxWindowMac* parent,
a4fec5b4
SC
114 wxWindowID WXUNUSED(id),
115 const wxString& WXUNUSED(label),
6e7a89af 116 const wxPoint& pos,
524c47aa 117 const wxSize& size,
6e7a89af 118 long style,
a4fec5b4 119 long WXUNUSED(extraStyle))
524c47aa
SC
120{
121 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
489468fe 122
524c47aa
SC
123 wxMacControl* peer = new wxMacStaticText( wxpeer );
124 OSStatus err = CreateStaticTextControl(
125 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
126 &bounds, NULL, NULL, peer->GetControlRefAddr() );
127 verify_noerr( err );
489468fe 128
524c47aa 129 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
489468fe 130 {
524c47aa
SC
131 TruncCode tCode = truncEnd;
132 if ( style & wxST_ELLIPSIZE_MIDDLE )
133 tCode = truncMiddle;
489468fe 134
524c47aa
SC
135 err = peer->SetData( kControlStaticTextTruncTag, tCode );
136 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
489468fe 137 }
524c47aa 138 return peer;
489468fe
SC
139}
140
489468fe 141#endif //if wxUSE_STATTEXT