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
);
96 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
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 #if wxMAC_USE_CORE_GRAPHICS
110 wxClientDC
dc(const_cast<wxStaticText
*>(this));
111 wxCoord width
, height
;
112 dc
.GetTextExtent( m_label
, &width
, &height
);
116 wxMacWindowStateSaver
sv( this );
117 ::TextFont( m_font
.MacGetFontNum() );
118 ::TextSize( (short)(m_font
.MacGetFontSize()) );
119 ::TextFace( m_font
.MacGetFontStyle() );
121 err
= GetThemeTextDimensions(
122 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
123 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
128 if ( m_label
.empty() )
131 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
132 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
134 return wxSize( bounds
.h
, bounds
.v
);
137 void wxStaticText::SetLabel(const wxString
& label
)
141 // middle/end ellipsization is handled by the OS:
142 if ( HasFlag(wxST_ELLIPSIZE_END
) || HasFlag(wxST_ELLIPSIZE_MIDDLE
) )
146 if (HasFlag(wxST_MARKUP
))
147 str
= RemoveMarkup(label
);
149 // and leave ellipsization to the OS
152 else // not supported natively
154 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
157 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) &&
158 !IsEllipsized() ) // don't resize if we adjust to current size
160 InvalidateBestSize();
161 SetSize( GetBestSize() );
166 // we shouldn't need forced updates
170 bool wxStaticText::SetFont(const wxFont
& font
)
172 bool ret
= wxControl::SetFont( font
);
176 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
178 InvalidateBestSize();
179 SetSize( GetBestSize() );
187 // for wxST_ELLIPSIZE_* support:
189 void wxStaticText::DoSetLabel(const wxString
& label
)
192 m_label
= RemoveMnemonics(label
);
194 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
195 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, str
);
199 wxString
wxStaticText::DoGetLabel() const
205 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
206 to allow correct dynamic ellipsizing of the label
209 #endif //if wxUSE_STATTEXT