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/notebook.h"
27 #include "wx/tabctrl.h"
29 #include "wx/osx/private.h"
33 class wxMacStaticText
: public wxMacControl
36 wxMacStaticText( wxWindowMac
* peer
) : wxMacControl(peer
)
39 void SetLabel(const wxString
& title
, wxFontEncoding encoding
)
41 wxCFStringRef
str( title
, encoding
);
42 OSStatus err
= SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, str
);
47 wxSize
wxStaticText::DoGetBestSize() const
51 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
53 // try the built-in best size if available
54 Boolean former
= m_peer
->GetData
<Boolean
>( kControlStaticTextIsMultilineTag
);
55 m_peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
56 m_peer
->GetBestRect( &bestsize
) ;
57 m_peer
->SetData( kControlStaticTextIsMultilineTag
, former
);
58 if ( !EmptyRect( &bestsize
) )
60 bounds
.h
= bestsize
.right
- bestsize
.left
;
61 bounds
.v
= bestsize
.bottom
- bestsize
.top
;
67 ControlFontStyleRec controlFont
;
68 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
71 wxCFStringRef
str( m_label
, GetFont().GetEncoding() );
73 #if wxOSX_USE_ATSU_TEXT
75 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
77 err
= GetThemeTextDimensions(
78 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
79 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
86 wxClientDC
dc(const_cast<wxStaticText
*>(this));
87 wxCoord width
, height
;
88 dc
.GetTextExtent( m_label
, &width
, &height
);
93 if ( m_label
.empty() )
96 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
97 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
99 return wxSize( bounds
.h
, bounds
.v
);
103 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
104 to allow correct dynamic ellipsizing of the label
107 wxWidgetImplType
* wxWidgetImpl::CreateStaticText( wxWindowMac
* wxpeer
,
110 const wxString
& label
,
116 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
);
118 wxMacControl
* peer
= new wxMacStaticText( wxpeer
);
119 OSStatus err
= CreateStaticTextControl(
120 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
121 &bounds
, NULL
, NULL
, peer
->GetControlRefAddr() );
124 if ( ( style
& wxST_ELLIPSIZE_END
) || ( style
& wxST_ELLIPSIZE_MIDDLE
) )
126 TruncCode tCode
= truncEnd
;
127 if ( style
& wxST_ELLIPSIZE_MIDDLE
)
130 err
= peer
->SetData( kControlStaticTextTruncTag
, tCode
);
131 err
= peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
136 #endif //if wxUSE_STATTEXT