1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/stattextg.cpp
3 // Purpose: wxGenericStaticText
4 // Author: Marcin Wojdyr
6 // Copyright: Marcin Wojdyr
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
19 #include "wx/dcclient.h"
20 #include "wx/settings.h"
21 #include "wx/validate.h"
24 #include "wx/generic/stattextg.h"
27 #include "wx/generic/private/markuptext.h"
28 #endif // wxUSE_MARKUP
30 IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText
, wxStaticTextBase
)
33 bool wxGenericStaticText::Create(wxWindow
*parent
,
35 const wxString
&label
,
41 if ( !wxControl::Create(parent
, id
, pos
, size
, style
,
42 wxDefaultValidator
, name
) )
47 Connect(wxEVT_PAINT
, wxPaintEventHandler(wxGenericStaticText::OnPaint
));
51 wxGenericStaticText::~wxGenericStaticText()
55 #endif // wxUSE_MARKUP
58 void wxGenericStaticText::DoDrawLabel(wxDC
& dc
, const wxRect
& rect
)
62 m_markupText
->Render(dc
, rect
, wxMarkupText::Render_ShowAccels
);
64 #endif // wxUSE_MARKUP
65 dc
.DrawLabel(m_label
, rect
, GetAlignment(), m_mnemonic
);
68 void wxGenericStaticText::OnPaint(wxPaintEvent
& WXUNUSED(event
))
72 wxRect rect
= GetClientRect();
76 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
));
78 else // paint disabled text
80 // draw shadow of the text
82 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT
));
83 wxRect rectShadow
= rect
;
84 rectShadow
.Offset(1, 1);
85 DoDrawLabel(dc
, rectShadow
);
87 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
89 DoDrawLabel(dc
, rect
);
93 wxSize
wxGenericStaticText::DoGetBestClientSize() const
95 wxClientDC
dc(wxConstCast(this, wxGenericStaticText
));
99 return m_markupText
->Measure(dc
);
100 #endif // wxUSE_MARKUP
102 return dc
.GetMultiLineTextExtent(GetLabel());
105 void wxGenericStaticText::SetLabel(const wxString
& label
)
107 wxControl::SetLabel(label
);
108 DoSetLabel(GetEllipsizedLabel());
109 if ( !HasFlag(wxST_NO_AUTORESIZE
) && !IsEllipsized() )
110 InvalidateBestSize();
118 #endif // wxUSE_MARKUP
123 void wxGenericStaticText::DoSetLabel(const wxString
& label
)
125 m_mnemonic
= FindAccelIndex(label
, &m_label
);
130 bool wxGenericStaticText::DoSetLabelMarkup(const wxString
& markup
)
132 if ( !wxStaticTextBase::DoSetLabelMarkup(markup
) )
136 m_markupText
= new wxMarkupText(markup
);
138 m_markupText
->SetMarkup(markup
);
140 if ( !HasFlag(wxST_NO_AUTORESIZE
) )
141 InvalidateBestSize();
148 #endif // wxUSE_MARKUP
150 bool wxGenericStaticText::SetFont(const wxFont
&font
)
152 if ( !wxControl::SetFont(font
) )
154 if ( !HasFlag(wxST_NO_AUTORESIZE
) )
155 InvalidateBestSize();
160 void wxGenericStaticText::DoSetSize(int x
, int y
, int width
, int height
,
163 wxStaticTextBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
168 #endif // wxUSE_STATTEXT