]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/stattext.mm
fixing compiles under certain flags
[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/notebook.h"
27 #include "wx/tabctrl.h"
28
29 #include "wx/osx/private.h"
30
31 #include <stdio.h>
32
33 wxSize 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
95 wxWidgetImplType* 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 {
104 NSView* sv = (wxpeer->GetParent()->GetHandle() );
105
106 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
107 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
108 [sv addSubview:v];
109
110 [v setBezeled:NO];
111 [v setEditable:NO];
112 [v setDrawsBackground:NO];
113
114 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
115 [v setImplementation:c];
116 return c;
117 /*
118 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
119
120 wxMacControl* peer = new wxMacControl( wxpeer );
121 OSStatus err = CreateStaticTextControl(
122 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
123 &bounds, NULL, NULL, peer->GetControlRefAddr() );
124 verify_noerr( err );
125
126 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
127 {
128 TruncCode tCode = truncEnd;
129 if ( style & wxST_ELLIPSIZE_MIDDLE )
130 tCode = truncMiddle;
131
132 err = peer->SetData( kControlStaticTextTruncTag, tCode );
133 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
134 }
135 return peer;
136 */
137 }
138
139 #endif //if wxUSE_STATTEXT