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"
17 #include "wx/stattext.h"
18 #include "wx/notebook.h"
19 #include "wx/tabctrl.h"
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
25 #include "wx/mac/uma.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
32 bool wxStaticText::Create( wxWindow
*parent
,
34 const wxString
& label
,
38 const wxString
& name
)
40 m_macIsUserPane
= false;
42 m_label
= wxStripMenuCodes( label
);
44 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
47 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
48 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
50 m_peer
= new wxMacControl( this );
51 OSStatus err
= CreateStaticTextControl(
52 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
53 &bounds
, str
, NULL
, m_peer
->GetControlRefAddr() );
56 if ( ( style
& wxST_DOTS_END
) || ( style
& wxST_DOTS_MIDDLE
) )
58 TruncCode tCode
= truncEnd
;
59 if ( style
& wxST_DOTS_MIDDLE
)
62 err
= m_peer
->SetData( kControlStaticTextTruncTag
, tCode
);
63 err
= m_peer
->SetData( kControlStaticTextIsMultilineTag
, (Boolean
)0 );
66 MacPostControlCreate( pos
, size
);
71 wxSize
wxStaticText::DoGetBestSize() const
73 ControlFontStyleRec controlFont
;
74 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
79 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
81 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
83 err
= GetThemeTextDimensions(
84 (m_label
.Length() > 0 ? (CFStringRef
)str
: CFSTR(" ")),
85 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
90 wxMacWindowStateSaver
sv( this );
91 ::TextFont( m_font
.MacGetFontNum() );
92 ::TextSize( (short)(m_font
.MacGetFontSize()) );
93 ::TextFace( m_font
.MacGetFontStyle() );
95 err
= GetThemeTextDimensions(
96 (m_label
.Length() > 0 ? (CFStringRef
)str
: CFSTR(" ")),
97 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
101 if ( m_label
.Length() == 0 )
104 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
105 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
107 return wxSize( bounds
.h
, bounds
.v
);
110 void wxStaticText::SetLabel( const wxString
& st
)
112 m_label
= wxStripMenuCodes( st
);
114 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
115 CFStringRef ref
= str
;
116 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
);
119 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
121 InvalidateBestSize();
122 SetSize( GetBestSize() );
127 // we shouldn't need forced updates
131 bool wxStaticText::SetFont(const wxFont
& font
)
133 bool ret
= wxControl::SetFont( font
);
137 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
139 InvalidateBestSize();
140 SetSize( GetBestSize() );
147 #endif //if wxUSE_STATTEXT