]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/stattext.cpp
changing disclosure triangle to allow for label
[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
51 Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag);
52 m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
53 m_peer->GetBestRect( &bestsize ) ;
54 m_peer->SetData( kControlStaticTextIsMultilineTag, former );
55 if ( !EmptyRect( &bestsize ) )
56 {
57 bounds.h = bestsize.right - bestsize.left ;
58 bounds.v = bestsize.bottom - bestsize.top ;
59 }
60 else
524c47aa 61#endif
489468fe 62 {
524c47aa 63#if wxOSX_USE_CARBON
489468fe
SC
64 ControlFontStyleRec controlFont;
65 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
66 verify_noerr( err );
67
68 wxCFStringRef str( m_label, GetFont().GetEncoding() );
69
292e5e1f 70#if wxOSX_USE_ATSU_TEXT
489468fe
SC
71 SInt16 baseline;
72 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
73 {
74 err = GetThemeTextDimensions(
75 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
76 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
77 verify_noerr( err );
78 }
79 else
524c47aa 80#endif
489468fe
SC
81#endif
82 {
83 wxClientDC dc(const_cast<wxStaticText*>(this));
84 wxCoord width, height ;
85 dc.GetTextExtent( m_label , &width, &height);
86 bounds.h = width;
87 bounds.v = height;
88 }
89
90 if ( m_label.empty() )
91 bounds.h = 0;
92 }
93 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
94 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
95
96 return wxSize( bounds.h, bounds.v );
97}
98
524c47aa
SC
99/*
100 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
101 to allow correct dynamic ellipsizing of the label
102*/
489468fe 103
6e7a89af
FM
104wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
105 wxWindowMac* parent,
a4fec5b4
SC
106 wxWindowID WXUNUSED(id),
107 const wxString& WXUNUSED(label),
6e7a89af 108 const wxPoint& pos,
524c47aa 109 const wxSize& size,
6e7a89af 110 long style,
a4fec5b4 111 long WXUNUSED(extraStyle))
524c47aa
SC
112{
113 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
489468fe 114
524c47aa
SC
115 wxMacControl* peer = new wxMacStaticText( wxpeer );
116 OSStatus err = CreateStaticTextControl(
117 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
118 &bounds, NULL, NULL, peer->GetControlRefAddr() );
119 verify_noerr( err );
489468fe 120
524c47aa 121 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
489468fe 122 {
524c47aa
SC
123 TruncCode tCode = truncEnd;
124 if ( style & wxST_ELLIPSIZE_MIDDLE )
125 tCode = truncMiddle;
489468fe 126
524c47aa
SC
127 err = peer->SetData( kControlStaticTextTruncTag, tCode );
128 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
489468fe 129 }
524c47aa 130 return peer;
489468fe
SC
131}
132
489468fe 133#endif //if wxUSE_STATTEXT