1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/stattext.cpp
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
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 class wxMacStaticText
: public wxMacControl
33 wxMacStaticText( wxWindowMac
* peer
) : wxMacControl(peer
)
36 void SetLabel(const wxString
& title
, wxFontEncoding encoding
)
38 wxCFStringRef
str( title
, encoding
);
39 OSStatus err
= SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, str
);
44 wxSize
wxStaticText::DoGetBestSize() const
48 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
50 // try the built-in best size if available
51 Boolean former
= m_peer
->GetData
<Boolean
>( kControlStaticTextIsMultilineTag
);
52 m_peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
53 m_peer
->GetBestRect( &bestsize
) ;
54 m_peer
->SetData( kControlStaticTextIsMultilineTag
, former
);
55 if ( !EmptyRect( &bestsize
) )
57 bounds
.h
= bestsize
.right
- bestsize
.left
;
58 bounds
.v
= bestsize
.bottom
- bestsize
.top
;
64 ControlFontStyleRec controlFont
;
65 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
68 wxCFStringRef
str( m_label
, GetFont().GetEncoding() );
70 #if wxOSX_USE_ATSU_TEXT
72 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
74 err
= GetThemeTextDimensions(
75 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
76 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
83 wxClientDC
dc(const_cast<wxStaticText
*>(this));
84 wxCoord width
, height
;
85 dc
.GetTextExtent( m_label
, &width
, &height
);
90 if ( m_label
.empty() )
93 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
94 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
96 return wxSize( bounds
.h
, bounds
.v
);
100 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
101 to allow correct dynamic ellipsizing of the label
104 wxWidgetImplType
* wxWidgetImpl::CreateStaticText( wxWindowMac
* wxpeer
,
107 const wxString
& label
,
113 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
);
115 wxMacControl
* peer
= new wxMacStaticText( wxpeer
);
116 OSStatus err
= CreateStaticTextControl(
117 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
118 &bounds
, NULL
, NULL
, peer
->GetControlRefAddr() );
121 if ( ( style
& wxST_ELLIPSIZE_END
) || ( style
& wxST_ELLIPSIZE_MIDDLE
) )
123 TruncCode tCode
= truncEnd
;
124 if ( style
& wxST_ELLIPSIZE_MIDDLE
)
127 err
= peer
->SetData( kControlStaticTextTruncTag
, tCode
);
128 err
= peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
133 #endif //if wxUSE_STATTEXT