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 wxMacWindowStateSaver
sv( this );
95 ::TextFont( m_font
.MacGetFontNum() );
96 ::TextSize( (short)(m_font
.MacGetFontSize()) );
97 ::TextFace( m_font
.MacGetFontStyle() );
99 err
= GetThemeTextDimensions(
100 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
101 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
105 if ( m_label
.empty() )
108 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
109 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
111 return wxSize( bounds
.h
, bounds
.v
);
114 void wxStaticText::SetLabel( const wxString
& st
)
116 m_label
= GetLabelText( st
);
118 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
119 CFStringRef ref
= str
;
120 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
);
123 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
125 InvalidateBestSize();
126 SetSize( GetBestSize() );
131 // we shouldn't need forced updates
135 bool wxStaticText::SetFont(const wxFont
& font
)
137 bool ret
= wxControl::SetFont( font
);
141 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
143 InvalidateBestSize();
144 SetSize( GetBestSize() );
151 #endif //if wxUSE_STATTEXT