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