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"
27 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
29 #include "wx/mac/uma.h"
31 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
32 const wxString
& label
,
38 m_macIsUserPane
= FALSE
;
40 m_label
= wxStripMenuCodes(label
) ;
42 if ( !wxControl::Create( parent
, id
, pos
, size
, style
,
43 wxDefaultValidator
, name
) )
48 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
49 wxMacCFStringHolder
str(m_label
,m_font
.GetEncoding() ) ;
50 m_peer
= new wxMacControl(this) ;
51 verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),&bounds
, str
,
52 NULL
, m_peer
->GetControlRefAddr() ) ) ;
54 MacPostControlCreate(pos
,size
) ;
59 wxSize
wxStaticText::DoGetBestSize() const
61 ControlFontStyleRec controlFont
;
62 verify_noerr( m_peer
->GetData
<ControlFontStyleRec
>(kControlEntireControl
, kControlFontStyleTag
, &controlFont
) ) ;
66 wxMacCFStringHolder
str(m_label
, m_font
.GetEncoding() ) ;
67 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
68 verify_noerr( GetThemeTextDimensions( (m_label
.Length() > 0 ? ((CFStringRef
) str
) : CFSTR(" ") ) , m_font
.MacGetThemeFontID() , kThemeStateActive
, false , &bounds
, &baseline
) ) ;
71 wxMacWindowStateSaver
sv( this ) ;
72 ::TextFont( m_font
.MacGetFontNum() ) ;
73 ::TextSize( (short)( m_font
.MacGetFontSize()) ) ;
74 ::TextFace( m_font
.MacGetFontStyle() ) ;
75 verify_noerr( GetThemeTextDimensions( (m_label
.Length() > 0 ? ((CFStringRef
) str
) : CFSTR(" ") ) , kThemeCurrentPortFont
, kThemeStateActive
, false , &bounds
, &baseline
) ) ;
77 if ( m_label
.Length() == 0 )
80 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
81 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
82 return wxSize(bounds
.h
, bounds
.v
);
85 void wxStaticText::SetLabel(const wxString
& st
)
88 m_label
= wxStripMenuCodes(st
) ;
90 wxMacCFStringHolder
str(m_label
,m_font
.GetEncoding() ) ;
91 CFStringRef ref
= str
;
92 verify_noerr( m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
) ) ;
94 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
97 SetSize( GetBestSize() ) ;
100 // we shouldn't need forced updates
104 bool wxStaticText::SetFont(const wxFont
& font
)
106 bool ret
= wxControl::SetFont(font
);
110 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
112 InvalidateBestSize();
113 SetSize( GetBestSize() );
120 #endif //if wxUSE_STATTEXT