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() );
98 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
100 err
= GetThemeTextDimensions(
101 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
102 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
107 #if wxMAC_USE_CORE_GRAPHICS
108 wxClientDC
dc(const_cast<wxStaticText
*>(this));
109 wxCoord width
, height
;
110 dc
.GetTextExtent( m_label
, &width
, &height
);
114 wxMacWindowStateSaver
sv( this );
115 ::TextFont( m_font
.MacGetFontNum() );
116 ::TextSize( (short)(m_font
.MacGetFontSize()) );
117 ::TextFace( m_font
.MacGetFontStyle() );
119 err
= GetThemeTextDimensions(
120 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
121 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
126 if ( m_label
.empty() )
129 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
130 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
132 return wxSize( bounds
.h
, bounds
.v
);
135 void wxStaticText::SetLabel(const wxString
& label
)
139 // middle/end ellipsization is handled by the OS:
140 if ( HasFlag(wxST_ELLIPSIZE_END
) || HasFlag(wxST_ELLIPSIZE_MIDDLE
) )
144 if (HasFlag(wxST_MARKUP
))
145 str
= RemoveMarkup(label
);
147 // and leave ellipsization to the OS
150 else // not supported natively
152 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
155 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) &&
156 !IsEllipsized() ) // don't resize if we adjust to current size
158 InvalidateBestSize();
159 SetSize( GetBestSize() );
164 // we shouldn't need forced updates
168 bool wxStaticText::SetFont(const wxFont
& font
)
170 bool ret
= wxControl::SetFont( font
);
174 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
176 InvalidateBestSize();
177 SetSize( GetBestSize() );
185 // for wxST_ELLIPSIZE_* support:
187 void wxStaticText::DoSetLabel(const wxString
& label
)
190 m_label
= RemoveMnemonics(label
);
192 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
193 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, str
);
197 wxString
wxStaticText::DoGetLabel() const
203 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
204 to allow correct dynamic ellipsizing of the label
207 #endif //if wxUSE_STATTEXT