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 #if wxOSX_USE_ATSU_TEXT
70 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
72 // GetThemeTextDimensions will cache strings and the documentation
73 // says not to use the NoCopy string creation calls.
74 // This also means that we can't use CFSTR without
75 // -fno-constant-cfstrings if the library might be unloaded,
76 // as GetThemeTextDimensions may cache a pointer to our
78 wxCFStringRef
str( !m_label
.empty() ? m_label
: wxString(" "),
79 GetFont().GetEncoding() );
81 err
= GetThemeTextDimensions(
83 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
90 wxClientDC
dc(const_cast<wxStaticText
*>(this));
91 wxCoord width
, height
;
92 dc
.GetTextExtent( m_label
, &width
, &height
);
97 if ( m_label
.empty() )
100 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
101 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
103 return wxSize( bounds
.h
, bounds
.v
);
107 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
108 to allow correct dynamic ellipsizing of the label
111 wxWidgetImplType
* wxWidgetImpl::CreateStaticText( wxWindowMac
* wxpeer
,
113 wxWindowID
WXUNUSED(id
),
114 const wxString
& WXUNUSED(label
),
118 long WXUNUSED(extraStyle
))
120 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
);
122 wxMacControl
* peer
= new wxMacStaticText( wxpeer
);
123 OSStatus err
= CreateStaticTextControl(
124 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
125 &bounds
, NULL
, NULL
, peer
->GetControlRefAddr() );
128 if ( ( style
& wxST_ELLIPSIZE_END
) || ( style
& wxST_ELLIPSIZE_MIDDLE
) )
130 TruncCode tCode
= truncEnd
;
131 if ( style
& wxST_ELLIPSIZE_MIDDLE
)
134 err
= peer
->SetData( kControlStaticTextTruncTag
, tCode
);
135 err
= peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
140 #endif //if wxUSE_STATTEXT