1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/stattext.mm
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/stattext.h"
22 #include "wx/dcclient.h"
23 #include "wx/settings.h"
26 #include "wx/notebook.h"
27 #include "wx/tabctrl.h"
29 #include "wx/osx/private.h"
33 wxSize wxStaticText::DoGetBestSize() const
37 Rect bestsize = { 0 , 0 , 0 , 0 } ;
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 ) )
46 bounds.h = bestsize.right - bestsize.left ;
47 bounds.v = bestsize.bottom - bestsize.top ;
53 ControlFontStyleRec controlFont;
54 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
57 wxCFStringRef str( m_label, GetFont().GetEncoding() );
59 #if wxOSX_USE_ATSU_TEXT
61 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
63 err = GetThemeTextDimensions(
64 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
65 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
72 wxClientDC dc(const_cast<wxStaticText*>(this));
73 wxCoord width, height ;
74 dc.GetTextExtent( m_label , &width, &height);
79 if ( m_label.empty() )
82 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
83 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
85 return wxSize( bounds.h, bounds.v );
88 // for wxST_ELLIPSIZE_* support:
91 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
92 to allow correct dynamic ellipsizing of the label
95 @interface wxNSTextField : NSTextField
100 - (void)setImplementation: (wxWidgetImpl *) theImplementation;
101 - (wxWidgetImpl*) implementation;
106 @implementation wxNSTextField
108 - (void)setImplementation: (wxWidgetImpl *) theImplementation
110 m_impl = theImplementation;
113 - (wxWidgetImpl*) implementation
123 // use our common calls
124 - (void) setTitle:(NSString *) title
126 [self setStringValue: title];
132 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
135 const wxString& label,
141 NSView* sv = (wxpeer->GetParent()->GetHandle() );
143 NSRect r = wxToNSRect( sv, wxRect( pos, size) );
144 // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
145 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
150 [v setDrawsBackground:NO];
152 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
153 [v setImplementation:c];
156 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
158 wxMacControl* peer = new wxMacControl( wxpeer );
159 OSStatus err = CreateStaticTextControl(
160 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
161 &bounds, NULL, NULL, peer->GetControlRefAddr() );
164 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
166 TruncCode tCode = truncEnd;
167 if ( style & wxST_ELLIPSIZE_MIDDLE )
170 err = peer->SetData( kControlStaticTextTruncTag, tCode );
171 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
177 #endif //if wxUSE_STATTEXT