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/osx/private.h"
30 wxSize wxStaticText::DoGetBestSize() const
34 #if wxOSX_USE_ATSU_TEXT
36 wxCFStringRef str( m_label, GetFont().GetEncoding() );
39 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
41 err = GetThemeTextDimensions(
42 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
43 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
49 wxClientDC dc(const_cast<wxStaticText*>(this));
50 wxCoord width, height ;
51 dc.GetMultiLineTextExtent( m_label , &width, &height);
52 // Some labels seem to have their last characters
53 // stripped out. Adding 4 pixels seems to be enough to fix this.
58 if ( m_label.empty() )
61 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
62 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
64 return wxSize( bounds.h, bounds.v );
67 // for wxST_ELLIPSIZE_* support:
70 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
71 to allow correct dynamic ellipsizing of the label
74 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
77 const wxString& label,
83 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
84 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
88 [v setDrawsBackground:NO];
90 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
93 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
95 wxMacControl* peer = new wxMacControl( wxpeer );
96 OSStatus err = CreateStaticTextControl(
97 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
98 &bounds, NULL, NULL, peer->GetControlRefAddr() );
101 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
103 TruncCode tCode = truncEnd;
104 if ( style & wxST_ELLIPSIZE_MIDDLE )
107 err = peer->SetData( kControlStaticTextTruncTag, tCode );
108 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
114 #endif //if wxUSE_STATTEXT