1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/stattextg.cpp
3 // Purpose: wxGenericStaticText
4 // Author: Marcin Wojdyr
7 // Copyright: Marcin Wojdyr
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
20 #include "wx/dcclient.h"
21 #include "wx/settings.h"
22 #include "wx/validate.h"
25 #include "wx/generic/stattextg.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText
, wxStaticTextBase
)
31 bool wxGenericStaticText::Create(wxWindow
*parent
,
33 const wxString
&label
,
39 if ( !wxControl::Create(parent
, id
, pos
, size
, style
,
40 wxDefaultValidator
, name
) )
45 Connect(wxEVT_PAINT
, wxPaintEventHandler(wxGenericStaticText::OnPaint
));
49 void wxGenericStaticText::OnPaint(wxPaintEvent
& WXUNUSED(event
))
51 if ( m_label
.empty() )
56 wxRect rect
= GetClientRect();
60 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
));
62 else // paint disabled text
64 // draw shadow of the text
66 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT
));
67 wxRect rectShadow
= rect
;
68 rectShadow
.Offset(1, 1);
69 dc
.DrawLabel(m_label
, rectShadow
, GetAlignment(), m_mnemonic
);
71 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
73 dc
.DrawLabel(m_label
, wxNullBitmap
, rect
, GetAlignment(), m_mnemonic
);
77 wxSize
wxGenericStaticText::DoGetBestClientSize() const
79 wxClientDC
dc(wxConstCast(this, wxGenericStaticText
));
80 wxCoord width
, height
;
81 dc
.GetMultiLineTextExtent(GetLabel(), &width
, &height
);
82 return wxSize(width
, height
);
85 wxSize
wxGenericStaticText::DoGetBestSize() const
87 wxSize ret
= DoGetBestClientSize();
93 void wxGenericStaticText::SetLabel(const wxString
& label
)
95 wxControl::SetLabel(label
);
96 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
97 if ( !HasFlag(wxST_NO_AUTORESIZE
) && !IsEllipsized() )
102 void wxGenericStaticText::DoSetLabel(const wxString
& label
)
104 m_mnemonic
= FindAccelIndex(label
, &m_label
);
107 bool wxGenericStaticText::SetFont(const wxFont
&font
)
109 if ( !wxControl::SetFont(font
) )
111 if ( !HasFlag(wxST_NO_AUTORESIZE
) )
112 InvalidateBestSize();
117 void wxGenericStaticText::DoSetSize(int x
, int y
, int width
, int height
,
120 wxStaticTextBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
125 #endif // wxUSE_STATTEXT