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