1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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/mac/uma.h"
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
36 bool wxStaticText::Create( wxWindow
*parent
,
38 const wxString
& label
,
42 const wxString
& name
)
44 m_macIsUserPane
= false;
46 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
49 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
51 m_peer
= new wxMacControl( this );
52 OSStatus err
= CreateStaticTextControl(
53 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
54 &bounds
, NULL
, NULL
, m_peer
->GetControlRefAddr() );
57 if ( ( style
& wxST_ELLIPSIZE_END
) || ( style
& wxST_ELLIPSIZE_MIDDLE
) )
59 TruncCode tCode
= truncEnd
;
60 if ( style
& wxST_ELLIPSIZE_MIDDLE
)
63 err
= m_peer
->SetData( kControlStaticTextTruncTag
, tCode
);
64 err
= m_peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
67 MacPostControlCreate( pos
, size
);
74 wxSize
wxStaticText::DoGetBestSize() const
76 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
79 // try the built-in best size if available
80 Boolean former
= m_peer
->GetData
<Boolean
>( kControlStaticTextIsMultilineTag
);
81 m_peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
82 m_peer
->GetBestRect( &bestsize
) ;
83 m_peer
->SetData( kControlStaticTextIsMultilineTag
, former
);
84 if ( !EmptyRect( &bestsize
) )
86 bounds
.h
= bestsize
.right
- bestsize
.left
;
87 bounds
.v
= bestsize
.bottom
- bestsize
.top
;
91 ControlFontStyleRec controlFont
;
92 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
95 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
97 #if wxMAC_USE_ATSU_TEXT
99 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
101 err
= GetThemeTextDimensions(
102 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
103 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
109 wxClientDC
dc(const_cast<wxStaticText
*>(this));
110 wxCoord width
, height
;
111 dc
.GetTextExtent( m_label
, &width
, &height
);
116 if ( m_label
.empty() )
119 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
120 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
122 return wxSize( bounds
.h
, bounds
.v
);
125 void wxStaticText::SetLabel(const wxString
& label
)
129 // middle/end ellipsization is handled by the OS:
130 if ( HasFlag(wxST_ELLIPSIZE_END
) || HasFlag(wxST_ELLIPSIZE_MIDDLE
) )
134 if (HasFlag(wxST_MARKUP
))
135 str
= RemoveMarkup(label
);
137 // and leave ellipsization to the OS
140 else // not supported natively
142 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
145 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) &&
146 !IsEllipsized() ) // don't resize if we adjust to current size
148 InvalidateBestSize();
149 SetSize( GetBestSize() );
154 // we shouldn't need forced updates
158 bool wxStaticText::SetFont(const wxFont
& font
)
160 bool ret
= wxControl::SetFont( font
);
164 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
166 InvalidateBestSize();
167 SetSize( GetBestSize() );
175 // for wxST_ELLIPSIZE_* support:
177 void wxStaticText::DoSetLabel(const wxString
& label
)
180 m_label
= RemoveMnemonics(label
);
182 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
183 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, str
);
187 wxString
wxStaticText::DoGetLabel() const
193 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
194 to allow correct dynamic ellipsizing of the label
197 #endif //if wxUSE_STATTEXT