1 /////////////////////////////////////////////////////////////////////////////
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 MacPostControlCreate( pos
, size
);
61 wxSize
wxStaticText::DoGetBestSize() const
63 ControlFontStyleRec controlFont
;
64 OSStatus err
= m_peer
->GetData
<ControlFontStyleRec
>( kControlEntireControl
, kControlFontStyleTag
, &controlFont
);
69 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
71 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
73 err
= GetThemeTextDimensions(
74 (m_label
.Length() > 0 ? (CFStringRef
)str
: CFSTR(" ")),
75 m_font
.MacGetThemeFontID(), kThemeStateActive
, false, &bounds
, &baseline
);
80 wxMacWindowStateSaver
sv( this );
81 ::TextFont( m_font
.MacGetFontNum() );
82 ::TextSize( (short)(m_font
.MacGetFontSize()) );
83 ::TextFace( m_font
.MacGetFontStyle() );
85 err
= GetThemeTextDimensions(
86 (m_label
.Length() > 0 ? (CFStringRef
)str
: CFSTR(" ")),
87 kThemeCurrentPortFont
, kThemeStateActive
, false, &bounds
, &baseline
);
91 if ( m_label
.Length() == 0 )
94 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize();
95 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize();
97 return wxSize( bounds
.h
, bounds
.v
);
100 void wxStaticText::SetLabel( const wxString
& st
)
102 m_label
= wxStripMenuCodes( st
);
104 wxMacCFStringHolder
str( m_label
, m_font
.GetEncoding() );
105 CFStringRef ref
= str
;
106 OSStatus err
= m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
);
109 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
111 InvalidateBestSize();
112 SetSize( GetBestSize() );
117 // we shouldn't need forced updates
121 bool wxStaticText::SetFont(const wxFont
& font
)
123 bool ret
= wxControl::SetFont( font
);
127 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
129 InvalidateBestSize();
130 SetSize( GetBestSize() );
137 #endif //if wxUSE_STATTEXT