]> git.saurik.com Git - wxWidgets.git/blob - src/generic/stattextg.cpp
Always use FVIRTKEY for the accelerators under MSW.
[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 // RCS-ID: $Id$
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
20 #include "wx/dcclient.h"
21 #include "wx/settings.h"
22 #include "wx/validate.h"
23 #endif
24
25 #include "wx/generic/stattextg.h"
26
27
28 IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText, wxStaticTextBase)
29
30
31 bool 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
49 void 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
77 wxSize 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
85 void wxGenericStaticText::SetLabel(const wxString& label)
86 {
87 wxControl::SetLabel(label);
88 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
89 if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
90 InvalidateBestSize();
91 Refresh();
92 }
93
94 void wxGenericStaticText::DoSetLabel(const wxString& label)
95 {
96 m_mnemonic = FindAccelIndex(label, &m_label);
97 }
98
99 bool wxGenericStaticText::SetFont(const wxFont &font)
100 {
101 if ( !wxControl::SetFont(font) )
102 return false;
103 if ( !HasFlag(wxST_NO_AUTORESIZE) )
104 InvalidateBestSize();
105 Refresh();
106 return true;
107 }
108
109 void wxGenericStaticText::DoSetSize(int x, int y, int width, int height,
110 int sizeFlags)
111 {
112 wxStaticTextBase::DoSetSize(x, y, width, height, sizeFlags);
113 UpdateLabel();
114 }
115
116
117 #endif // wxUSE_STATTEXT