1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "stattext.h"
16 #include "wx/wxprec.h"
21 #include "wx/stattext.h"
22 #include "wx/notebook.h"
23 #include "wx/tabctrl.h"
25 #include "wx/dcclient.h"
27 #include "wx/settings.h"
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
35 #include "wx/mac/uma.h"
37 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
38 const wxString
& label
,
44 m_macIsUserPane
= FALSE
;
46 m_label
= wxStripMenuCodes(label
) ;
48 if ( !wxControl::Create( parent
, id
, pos
, size
, style
,
49 wxDefaultValidator
, name
) )
54 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
55 wxMacCFStringHolder
str(m_label
,m_font
.GetEncoding() ) ;
56 m_peer
= new wxMacControl(this) ;
57 verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),&bounds
, str
,
58 NULL
, m_peer
->GetControlRefAddr() ) ) ;
60 MacPostControlCreate(pos
,size
) ;
65 wxSize
wxStaticText::DoGetBestSize() const
67 ControlFontStyleRec controlFont
;
68 verify_noerr( m_peer
->GetData
<ControlFontStyleRec
>(kControlEntireControl
, kControlFontStyleTag
, &controlFont
) ) ;
72 wxMacCFStringHolder
str(m_label
, m_font
.GetEncoding() ) ;
73 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
74 verify_noerr( GetThemeTextDimensions( (m_label
.Length() > 0 ? ((CFStringRef
) str
) : CFSTR(" ") ) , m_font
.MacGetThemeFontID() , kThemeStateActive
, false , &bounds
, &baseline
) ) ;
77 wxMacWindowStateSaver
sv( this ) ;
78 ::TextFont( m_font
.MacGetFontNum() ) ;
79 ::TextSize( (short)( m_font
.MacGetFontSize()) ) ;
80 ::TextFace( m_font
.MacGetFontStyle() ) ;
81 verify_noerr( GetThemeTextDimensions( (m_label
.Length() > 0 ? ((CFStringRef
) str
) : CFSTR(" ") ) , kThemeCurrentPortFont
, kThemeStateActive
, false , &bounds
, &baseline
) ) ;
83 if ( m_label
.Length() == 0 )
86 bounds
.h
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
87 bounds
.v
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
88 return wxSize(bounds
.h
, bounds
.v
);
91 void wxStaticText::SetLabel(const wxString
& st
)
94 m_label
= wxStripMenuCodes(st
) ;
96 wxMacCFStringHolder
str(m_label
,m_font
.GetEncoding() ) ;
97 CFStringRef ref
= str
;
98 verify_noerr( m_peer
->SetData
<CFStringRef
>(kControlEntireControl
, kControlStaticTextCFStringTag
, ref
) ) ;
100 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
102 InvalidateBestSize();
103 SetSize( GetBestSize() ) ;
109 bool wxStaticText::SetFont(const wxFont
& font
)
111 bool ret
= wxControl::SetFont(font
);
115 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
117 InvalidateBestSize();
118 SetSize( GetBestSize() );
125 #endif //if wxUSE_STATTEXT