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 m_label
= GetLabelText( label
);
48 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
51 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
52 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
54 m_peer
= new wxMacControl( this );
55 OSStatus err
= CreateStaticTextControl(
56 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
57 &bounds
, str
, NULL
, m_peer
->GetControlRefAddr() );
60 if ( ( style
& wxST_DOTS_END
) || ( style
& wxST_DOTS_MIDDLE
) )
62 TruncCode tCode
= truncEnd
;
63 if ( style
& wxST_DOTS_MIDDLE
)
66 err
= m_peer
->SetData( kControlStaticTextTruncTag
, tCode
);
67 err
= m_peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
70 MacPostControlCreate( pos
, size
);
75 wxSize
wxStaticText::DoGetBestSize() const
77 ControlFontStyleRec controlFont
;
78 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
83 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
85 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
87 err
= GetThemeTextDimensions(
88 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
89 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
94 #if wxMAC_USE_CORE_GRAPHICS
95 wxClientDC
dc(const_cast<wxStaticText
*>(this));
96 wxCoord width
, height
;
97 dc
.GetTextExtent( m_label
, &width
, &height
);
101 wxMacWindowStateSaver
sv( this );
102 ::TextFont( m_font
.MacGetFontNum() );
103 ::TextSize( (short)(m_font
.MacGetFontSize()) );
104 ::TextFace( m_font
.MacGetFontStyle() );
106 err
= GetThemeTextDimensions(
107 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
108 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
113 if ( m_label
.empty() )
116 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
117 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
119 return wxSize( bounds
.h
, bounds
.v
);
122 void wxStaticText::SetLabel( const wxString
& st
)
124 m_label
= GetLabelText( st
);
126 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
127 CFStringRef ref
= str
;
128 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
);
131 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
133 InvalidateBestSize();
134 SetSize( GetBestSize() );
139 // we shouldn't need forced updates
143 bool wxStaticText::SetFont(const wxFont
& font
)
145 bool ret
= wxControl::SetFont( font
);
149 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
151 InvalidateBestSize();
152 SetSize( GetBestSize() );
159 #endif //if wxUSE_STATTEXT