]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/stattext.mm
add parentheses for && inside || to fix g++ 4.3 warning
[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 @interface wxNSTextField : NSTextField
96 {
97 wxWidgetImpl* m_impl;
98 }
99
100 - (void)setImplementation: (wxWidgetImpl *) theImplementation;
101 - (wxWidgetImpl*) implementation;
102 - (BOOL) isFlipped;
103
104 @end
105
106 @implementation wxNSTextField
107
108 - (void)setImplementation: (wxWidgetImpl *) theImplementation
109 {
110 m_impl = theImplementation;
111 }
112
113 - (wxWidgetImpl*) implementation
114 {
115 return m_impl;
116 }
117
118 - (BOOL) isFlipped
119 {
120 return YES;
121 }
122
123 // use our common calls
124 - (void) setTitle:(NSString *) title
125 {
126 [self setStringValue: title];
127 }
128
129 @end
130
131
132 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
133 wxWindowMac* parent,
134 wxWindowID id,
135 const wxString& label,
136 const wxPoint& pos,
137 const wxSize& size,
138 long style,
139 long extraStyle)
140 {
141 NSView* sv = (wxpeer->GetParent()->GetHandle() );
142
143 NSRect r = wxToNSRect( sv, wxRect( pos, size) );
144 // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
145 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
146 [sv addSubview:v];
147
148 [v setBezeled:NO];
149 [v setEditable:NO];
150 [v setDrawsBackground:NO];
151
152 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
153 [v setImplementation:c];
154 return c;
155 /*
156 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
157
158 wxMacControl* peer = new wxMacControl( wxpeer );
159 OSStatus err = CreateStaticTextControl(
160 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
161 &bounds, NULL, NULL, peer->GetControlRefAddr() );
162 verify_noerr( err );
163
164 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
165 {
166 TruncCode tCode = truncEnd;
167 if ( style & wxST_ELLIPSIZE_MIDDLE )
168 tCode = truncMiddle;
169
170 err = peer->SetData( kControlStaticTextTruncTag, tCode );
171 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
172 }
173 return peer;
174 */
175 }
176
177 #endif //if wxUSE_STATTEXT