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