]> git.saurik.com Git - wxWidgets.git/blame - src/generic/stattextg.cpp
suppress harmless gcc warning about not handling all enum values in a switch
[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
27
28IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText, wxStaticTextBase)
29
30
31bool wxGenericStaticText::Create(wxWindow *parent,
32 wxWindowID id,
33 const wxString &label,
34 const wxPoint &pos,
35 const wxSize &size,
36 long style,
37 const wxString &name)
38{
39 if ( !wxControl::Create(parent, id, pos, size, style,
40 wxDefaultValidator, name) )
41 return false;
42
43 SetLabel(label);
44 SetInitialSize(size);
45 Connect(wxEVT_PAINT, wxPaintEventHandler(wxGenericStaticText::OnPaint));
46 return true;
47}
48
49void wxGenericStaticText::OnPaint(wxPaintEvent& WXUNUSED(event))
50{
51 if ( m_label.empty() )
52 return;
53 wxPaintDC dc(this);
54 PrepareDC(dc);
55
56 wxRect rect = GetClientRect();
57 if ( IsEnabled() )
58 {
59 dc.SetTextForeground(
60 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
61 }
62 else // paint disabled text
63 {
64 // draw shadow of the text
65 dc.SetTextForeground(
66 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT));
67 wxRect rectShadow = rect;
68 rectShadow.Offset(1, 1);
69 dc.DrawLabel(m_label, rectShadow, GetAlignment(), m_mnemonic);
70 dc.SetTextForeground(
71 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
72 }
73 dc.DrawLabel(m_label, wxNullBitmap, rect, GetAlignment(), m_mnemonic);
74}
75
76
77wxSize wxGenericStaticText::DoGetBestClientSize() const
78{
79 wxClientDC dc(wxConstCast(this, wxGenericStaticText));
80 wxCoord width, height;
81 dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
82 return wxSize(width, height);
83}
84
85wxSize wxGenericStaticText::DoGetBestSize() const
86{
87 wxSize ret = DoGetBestClientSize();
88 CacheBestSize(ret);
89 return ret;
90}
91
92
93void wxGenericStaticText::SetLabel(const wxString& label)
94{
95 wxControl::SetLabel(label);
96 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
97 if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
98 InvalidateBestSize();
99 Refresh();
100}
101
102void wxGenericStaticText::DoSetLabel(const wxString& label)
103{
104 m_mnemonic = FindAccelIndex(label, &m_label);
105}
106
107bool wxGenericStaticText::SetFont(const wxFont &font)
108{
109 if ( !wxControl::SetFont(font) )
110 return false;
111 if ( !HasFlag(wxST_NO_AUTORESIZE) )
112 InvalidateBestSize();
113 Refresh();
114 return true;
115}
116
117void wxGenericStaticText::DoSetSize(int x, int y, int width, int height,
118 int sizeFlags)
119{
120 wxStaticTextBase::DoSetSize(x, y, width, height, sizeFlags);
121 UpdateLabel();
122}
123
124
125#endif // wxUSE_STATTEXT