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 Rect bestsize = { 0 , 0 , 0 , 0 } ;
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 ) )
43 bounds.h = bestsize.right - bestsize.left ;
44 bounds.v = bestsize.bottom - bestsize.top ;
50 ControlFontStyleRec controlFont;
51 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
54 wxCFStringRef str( m_label, GetFont().GetEncoding() );
56 #if wxOSX_USE_ATSU_TEXT
58 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
60 err = GetThemeTextDimensions(
61 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
62 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
69 wxClientDC dc(const_cast<wxStaticText*>(this));
70 wxCoord width, height ;
71 dc.GetTextExtent( m_label , &width, &height);
76 if ( m_label.empty() )
79 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
80 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
82 return wxSize( bounds.h, bounds.v );
85 // for wxST_ELLIPSIZE_* support:
88 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
89 to allow correct dynamic ellipsizing of the label
92 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
95 const wxString& label,
101 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
102 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
106 [v setDrawsBackground:NO];
108 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
109 [v setImplementation:c];
112 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
114 wxMacControl* peer = new wxMacControl( wxpeer );
115 OSStatus err = CreateStaticTextControl(
116 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
117 &bounds, NULL, NULL, peer->GetControlRefAddr() );
120 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
122 TruncCode tCode = truncEnd;
123 if ( style & wxST_ELLIPSIZE_MIDDLE )
126 err = peer->SetData( kControlStaticTextTruncTag, tCode );
127 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
133 #endif //if wxUSE_STATTEXT