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 Boolean former
= m_peer
->GetData
<Boolean
>( kControlStaticTextIsMultilineTag
);
82 m_peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
83 m_peer
->GetBestRect( &bestsize
) ;
84 m_peer
->SetData( kControlStaticTextIsMultilineTag
, former
);
85 if ( !EmptyRect( &bestsize
) )
87 bounds
.h
= bestsize
.right
- bestsize
.left
;
88 bounds
.v
= bestsize
.bottom
- bestsize
.top
;
92 ControlFontStyleRec controlFont
;
93 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
97 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
);
108 #if wxMAC_USE_CORE_GRAPHICS
109 wxClientDC
dc(const_cast<wxStaticText
*>(this));
110 wxCoord width
, height
;
111 dc
.GetTextExtent( m_label
, &width
, &height
);
115 wxMacWindowStateSaver
sv( this );
116 ::TextFont( m_font
.MacGetFontNum() );
117 ::TextSize( (short)(m_font
.MacGetFontSize()) );
118 ::TextFace( m_font
.MacGetFontStyle() );
120 err
= GetThemeTextDimensions(
121 (!m_label
.empty() ? (CFStringRef
)str
: CFSTR(" ")),
122 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
127 if ( m_label
.empty() )
130 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
131 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
133 return wxSize( bounds
.h
, bounds
.v
);
136 void wxStaticText::SetLabel( const wxString
& st
)
138 m_label
= GetLabelText( st
);
140 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
141 CFStringRef ref
= str
;
142 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
);
145 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
147 InvalidateBestSize();
148 SetSize( GetBestSize() );
153 // we shouldn't need forced updates
157 bool wxStaticText::SetFont(const wxFont
& font
)
159 bool ret
= wxControl::SetFont( font
);
163 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
165 InvalidateBestSize();
166 SetSize( GetBestSize() );
173 #endif //if wxUSE_STATTEXT