]> git.saurik.com Git - wxWidgets.git/blob - src/generic/stattextg.cpp
Fix for #15224: wxRichTextTable: Setting a cell's text colour affects subsequent...
[wxWidgets.git] / src / generic / stattextg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/stattextg.cpp
3 // Purpose: wxGenericStaticText
4 // Author: Marcin Wojdyr
5 // Created: 2008-06-26
6 // Copyright: Marcin Wojdyr
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/wxprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #if wxUSE_STATTEXT
17
18 #ifndef WX_PRECOMP
19 #include "wx/dcclient.h"
20 #include "wx/settings.h"
21 #include "wx/validate.h"
22 #endif
23
24 #include "wx/generic/stattextg.h"
25
26 #if wxUSE_MARKUP
27 #include "wx/generic/private/markuptext.h"
28 #endif // wxUSE_MARKUP
29
30 IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText, wxStaticTextBase)
31
32
33 bool wxGenericStaticText::Create(wxWindow *parent,
34 wxWindowID id,
35 const wxString &label,
36 const wxPoint &pos,
37 const wxSize &size,
38 long style,
39 const wxString &name)
40 {
41 if ( !wxControl::Create(parent, id, pos, size, style,
42 wxDefaultValidator, name) )
43 return false;
44
45 SetLabel(label);
46 SetInitialSize(size);
47 Connect(wxEVT_PAINT, wxPaintEventHandler(wxGenericStaticText::OnPaint));
48 return true;
49 }
50
51 wxGenericStaticText::~wxGenericStaticText()
52 {
53 #if wxUSE_MARKUP
54 delete m_markupText;
55 #endif // wxUSE_MARKUP
56 }
57
58 void wxGenericStaticText::DoDrawLabel(wxDC& dc, const wxRect& rect)
59 {
60 #if wxUSE_MARKUP
61 if ( m_markupText )
62 m_markupText->Render(dc, rect, wxMarkupText::Render_ShowAccels);
63 else
64 #endif // wxUSE_MARKUP
65 dc.DrawLabel(m_label, rect, GetAlignment(), m_mnemonic);
66 }
67
68 void wxGenericStaticText::OnPaint(wxPaintEvent& WXUNUSED(event))
69 {
70 wxPaintDC dc(this);
71
72 wxRect rect = GetClientRect();
73 if ( IsEnabled() )
74 {
75 dc.SetTextForeground(
76 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
77 }
78 else // paint disabled text
79 {
80 // draw shadow of the text
81 dc.SetTextForeground(
82 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT));
83 wxRect rectShadow = rect;
84 rectShadow.Offset(1, 1);
85 DoDrawLabel(dc, rectShadow);
86 dc.SetTextForeground(
87 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
88 }
89 DoDrawLabel(dc, rect);
90 }
91
92
93 wxSize wxGenericStaticText::DoGetBestClientSize() const
94 {
95 wxClientDC dc(wxConstCast(this, wxGenericStaticText));
96
97 #if wxUSE_MARKUP
98 if ( m_markupText )
99 return m_markupText->Measure(dc);
100 #endif // wxUSE_MARKUP
101
102 return dc.GetMultiLineTextExtent(GetLabel());
103 }
104
105 void wxGenericStaticText::SetLabel(const wxString& label)
106 {
107 wxControl::SetLabel(label);
108 DoSetLabel(GetEllipsizedLabel());
109 if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
110 InvalidateBestSize();
111
112 #if wxUSE_MARKUP
113 if ( m_markupText )
114 {
115 delete m_markupText;
116 m_markupText = NULL;
117 }
118 #endif // wxUSE_MARKUP
119
120 Refresh();
121 }
122
123 void wxGenericStaticText::DoSetLabel(const wxString& label)
124 {
125 m_mnemonic = FindAccelIndex(label, &m_label);
126 }
127
128 #if wxUSE_MARKUP
129
130 bool wxGenericStaticText::DoSetLabelMarkup(const wxString& markup)
131 {
132 if ( !wxStaticTextBase::DoSetLabelMarkup(markup) )
133 return false;
134
135 if ( !m_markupText )
136 m_markupText = new wxMarkupText(markup);
137 else
138 m_markupText->SetMarkup(markup);
139
140 if ( !HasFlag(wxST_NO_AUTORESIZE) )
141 InvalidateBestSize();
142
143 Refresh();
144
145 return true;
146 }
147
148 #endif // wxUSE_MARKUP
149
150 bool wxGenericStaticText::SetFont(const wxFont &font)
151 {
152 if ( !wxControl::SetFont(font) )
153 return false;
154 if ( !HasFlag(wxST_NO_AUTORESIZE) )
155 InvalidateBestSize();
156 Refresh();
157 return true;
158 }
159
160 void wxGenericStaticText::DoSetSize(int x, int y, int width, int height,
161 int sizeFlags)
162 {
163 wxStaticTextBase::DoSetSize(x, y, width, height, sizeFlags);
164 UpdateLabel();
165 }
166
167
168 #endif // wxUSE_STATTEXT