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 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
80 // try the built-in best size if available
81 m_peer
->GetBestRect( &bestsize
) ;
82 if ( !EmptyRect( &bestsize
) )
84 bounds
.h
= bestsize
.right
- bestsize
.left
;
85 bounds
.v
= bestsize
.bottom
- bestsize
.top
;
89 ControlFontStyleRec controlFont
;
90 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
94 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
96 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
98 err
= GetThemeTextDimensions(
99 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
100 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
105 #if wxMAC_USE_CORE_GRAPHICS
106 wxClientDC
dc(const_cast<wxStaticText
*>(this));
107 wxCoord width
, height
;
108 dc
.GetTextExtent( m_label
, &width
, &height
);
112 wxMacWindowStateSaver
sv( this );
113 ::TextFont( m_font
.MacGetFontNum() );
114 ::TextSize( (short)(m_font
.MacGetFontSize()) );
115 ::TextFace( m_font
.MacGetFontStyle() );
117 err
= GetThemeTextDimensions(
118 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
119 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
124 if ( m_label
.empty() )
127 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
128 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
130 return wxSize( bounds
.h
, bounds
.v
);
133 void wxStaticText::SetLabel( const wxString
& st
)
135 m_label
= GetLabelText( st
);
137 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
138 CFStringRef ref
= str
;
139 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
);
142 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
144 InvalidateBestSize();
145 SetSize( GetBestSize() );
150 // we shouldn't need forced updates
154 bool wxStaticText::SetFont(const wxFont
& font
)
156 bool ret
= wxControl::SetFont( font
);
160 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
162 InvalidateBestSize();
163 SetSize( GetBestSize() );
170 #endif //if wxUSE_STATTEXT