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 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
98 const wxString& label,
104 NSView* sv = (wxpeer->GetParent()->GetHandle() );
106 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
107 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
112 [v setDrawsBackground:NO];
114 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
115 [v setImplementation:c];
118 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
120 wxMacControl* peer = new wxMacControl( wxpeer );
121 OSStatus err = CreateStaticTextControl(
122 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
123 &bounds, NULL, NULL, peer->GetControlRefAddr() );
126 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
128 TruncCode tCode = truncEnd;
129 if ( style & wxST_ELLIPSIZE_MIDDLE )
132 err = peer->SetData( kControlStaticTextTruncTag, tCode );
133 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
139 #endif //if wxUSE_STATTEXT