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