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
= GetPeer()->GetData
<Boolean
>( kControlStaticTextIsMultilineTag
);
52 GetPeer()->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
53 GetPeer()->GetBestRect( &bestsize
) ;
54 GetPeer()->SetData( kControlStaticTextIsMultilineTag
, former
);
56 if ( !EmptyRect( &bestsize
) )
58 bounds
.h
= bestsize
.right
- bestsize
.left
;
59 bounds
.v
= bestsize
.bottom
- bestsize
.top
;
65 ControlFontStyleRec controlFont
;
66 OSStatus err
= GetPeer()->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
69 #if wxOSX_USE_ATSU_TEXT
71 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
73 // GetThemeTextDimensions will cache strings and the documentation
74 // says not to use the NoCopy string creation calls.
75 // This also means that we can't use CFSTR without
76 // -fno-constant-cfstrings if the library might be unloaded,
77 // as GetThemeTextDimensions may cache a pointer to our
79 wxCFStringRef
str( !m_label
.empty() ? m_label
: wxString(" "),
80 GetFont().GetEncoding() );
82 err
= GetThemeTextDimensions(
84 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
91 wxClientDC
dc(const_cast<wxStaticText
*>(this));
92 wxCoord width
, height
;
93 dc
.GetTextExtent( m_label
, &width
, &height
);
98 if ( m_label
.empty() )
101 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
102 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
104 return wxSize( bounds
.h
, bounds
.v
);
108 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
109 to allow correct dynamic ellipsizing of the label
112 wxWidgetImplType
* wxWidgetImpl::CreateStaticText( wxWindowMac
* wxpeer
,
114 wxWindowID
WXUNUSED(id
),
115 const wxString
& WXUNUSED(label
),
119 long WXUNUSED(extraStyle
))
121 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
);
123 wxMacControl
* peer
= new wxMacStaticText( wxpeer
);
124 OSStatus err
= CreateStaticTextControl(
125 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
126 &bounds
, NULL
, NULL
, peer
->GetControlRefAddr() );
129 if ( ( style
& wxST_ELLIPSIZE_END
) || ( style
& wxST_ELLIPSIZE_MIDDLE
) )
131 TruncCode tCode
= truncEnd
;
132 if ( style
& wxST_ELLIPSIZE_MIDDLE
)
135 err
= peer
->SetData( kControlStaticTextTruncTag
, tCode
);
136 err
= peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
141 #endif //if wxUSE_STATTEXT