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 #include "wx/generic/private/markuptext.h"
29 #endif // wxUSE_MARKUP
31 IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText
, wxStaticTextBase
)
34 bool wxGenericStaticText::Create(wxWindow
*parent
,
36 const wxString
&label
,
42 if ( !wxControl::Create(parent
, id
, pos
, size
, style
,
43 wxDefaultValidator
, name
) )
48 Connect(wxEVT_PAINT
, wxPaintEventHandler(wxGenericStaticText::OnPaint
));
52 wxGenericStaticText::~wxGenericStaticText()
56 #endif // wxUSE_MARKUP
59 void wxGenericStaticText::DoDrawLabel(wxDC
& dc
, const wxRect
& rect
)
63 m_markupText
->Render(dc
, rect
, wxMarkupText::Render_ShowAccels
);
65 #endif // wxUSE_MARKUP
66 dc
.DrawLabel(m_label
, rect
, GetAlignment(), m_mnemonic
);
69 void wxGenericStaticText::OnPaint(wxPaintEvent
& WXUNUSED(event
))
73 wxRect rect
= GetClientRect();
77 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
));
79 else // paint disabled text
81 // draw shadow of the text
83 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT
));
84 wxRect rectShadow
= rect
;
85 rectShadow
.Offset(1, 1);
86 DoDrawLabel(dc
, rectShadow
);
88 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
90 DoDrawLabel(dc
, rect
);
94 wxSize
wxGenericStaticText::DoGetBestClientSize() const
96 wxClientDC
dc(wxConstCast(this, wxGenericStaticText
));
100 return m_markupText
->Measure(dc
);
101 #endif // wxUSE_MARKUP
103 return dc
.GetMultiLineTextExtent(GetLabel());
106 void wxGenericStaticText::SetLabel(const wxString
& label
)
108 wxControl::SetLabel(label
);
109 DoSetLabel(GetEllipsizedLabel());
110 if ( !HasFlag(wxST_NO_AUTORESIZE
) && !IsEllipsized() )
111 InvalidateBestSize();
119 #endif // wxUSE_MARKUP
124 void wxGenericStaticText::DoSetLabel(const wxString
& label
)
126 m_mnemonic
= FindAccelIndex(label
, &m_label
);
131 bool wxGenericStaticText::DoSetLabelMarkup(const wxString
& markup
)
133 if ( !wxStaticTextBase::DoSetLabelMarkup(markup
) )
137 m_markupText
= new wxMarkupText(markup
);
139 m_markupText
->SetMarkup(markup
);
141 if ( !HasFlag(wxST_NO_AUTORESIZE
) )
142 InvalidateBestSize();
149 #endif // wxUSE_MARKUP
151 bool wxGenericStaticText::SetFont(const wxFont
&font
)
153 if ( !wxControl::SetFont(font
) )
155 if ( !HasFlag(wxST_NO_AUTORESIZE
) )
156 InvalidateBestSize();
161 void wxGenericStaticText::DoSetSize(int x
, int y
, int width
, int height
,
164 wxStaticTextBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
169 #endif // wxUSE_STATTEXT