]> git.saurik.com Git - wxWidgets.git/blame - src/generic/stattextg.cpp
Remove superfluous mouse capturing in wxGrid row/column labels windows.
[wxWidgets.git] / src / generic / stattextg.cpp
CommitLineData
916eabe6
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/stattextg.cpp
3// Purpose: wxGenericStaticText
4// Author: Marcin Wojdyr
5// Created: 2008-06-26
916eabe6
VZ
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
456e28d2
VZ
19 #include "wx/dcclient.h"
20 #include "wx/settings.h"
916eabe6
VZ
21 #include "wx/validate.h"
22#endif
23
24#include "wx/generic/stattextg.h"
25
2814e718
VZ
26#if wxUSE_MARKUP
27 #include "wx/generic/private/markuptext.h"
28#endif // wxUSE_MARKUP
916eabe6
VZ
29
30IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText, wxStaticTextBase)
31
32
33bool 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
2814e718
VZ
51wxGenericStaticText::~wxGenericStaticText()
52{
53#if wxUSE_MARKUP
54 delete m_markupText;
55#endif // wxUSE_MARKUP
56}
57
58void 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
916eabe6
VZ
68void wxGenericStaticText::OnPaint(wxPaintEvent& WXUNUSED(event))
69{
916eabe6 70 wxPaintDC dc(this);
916eabe6
VZ
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);
2814e718 85 DoDrawLabel(dc, rectShadow);
916eabe6
VZ
86 dc.SetTextForeground(
87 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
88 }
2814e718 89 DoDrawLabel(dc, rect);
916eabe6
VZ
90}
91
92
93wxSize wxGenericStaticText::DoGetBestClientSize() const
94{
95 wxClientDC dc(wxConstCast(this, wxGenericStaticText));
2814e718
VZ
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());
916eabe6
VZ
103}
104
916eabe6
VZ
105void wxGenericStaticText::SetLabel(const wxString& label)
106{
107 wxControl::SetLabel(label);
3da9cffc 108 DoSetLabel(GetEllipsizedLabel());
916eabe6
VZ
109 if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
110 InvalidateBestSize();
2814e718
VZ
111
112#if wxUSE_MARKUP
113 if ( m_markupText )
114 {
115 delete m_markupText;
116 m_markupText = NULL;
117 }
118#endif // wxUSE_MARKUP
119
916eabe6
VZ
120 Refresh();
121}
122
123void wxGenericStaticText::DoSetLabel(const wxString& label)
124{
125 m_mnemonic = FindAccelIndex(label, &m_label);
126}
127
2814e718
VZ
128#if wxUSE_MARKUP
129
130bool 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
916eabe6
VZ
150bool 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
160void 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