]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/stattext.cpp
docopydocs is not needed for this script.
[wxWidgets.git] / src / msw / stattext.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/stattext.cpp
3// Purpose: wxStaticText
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#if wxUSE_STATTEXT
20
21#ifndef WX_PRECOMP
22 #include "wx/event.h"
23 #include "wx/app.h"
24 #include "wx/brush.h"
25 #include "wx/dcclient.h"
26 #include "wx/settings.h"
27#endif
28
29#include "wx/stattext.h"
30#include "wx/msw/private.h"
31
32#if wxUSE_EXTENDED_RTTI
33WX_DEFINE_FLAGS( wxStaticTextStyle )
34
35wxBEGIN_FLAGS( wxStaticTextStyle )
36 // new style border flags, we put them first to
37 // use them for streaming out
38 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
39 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
40 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
41 wxFLAGS_MEMBER(wxBORDER_RAISED)
42 wxFLAGS_MEMBER(wxBORDER_STATIC)
43 wxFLAGS_MEMBER(wxBORDER_NONE)
44
45 // old style border flags
46 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
47 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
48 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
49 wxFLAGS_MEMBER(wxRAISED_BORDER)
50 wxFLAGS_MEMBER(wxSTATIC_BORDER)
51 wxFLAGS_MEMBER(wxBORDER)
52
53 // standard window styles
54 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
55 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
56 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
57 wxFLAGS_MEMBER(wxWANTS_CHARS)
58 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
59 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
60 wxFLAGS_MEMBER(wxVSCROLL)
61 wxFLAGS_MEMBER(wxHSCROLL)
62
63 wxFLAGS_MEMBER(wxST_NO_AUTORESIZE)
64 wxFLAGS_MEMBER(wxALIGN_LEFT)
65 wxFLAGS_MEMBER(wxALIGN_RIGHT)
66 wxFLAGS_MEMBER(wxALIGN_CENTRE)
67
68wxEND_FLAGS( wxStaticTextStyle )
69
70IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticText, wxControl,"wx/stattext.h")
71
72wxBEGIN_PROPERTIES_TABLE(wxStaticText)
73 wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
74 wxPROPERTY_FLAGS( WindowStyle , wxStaticTextStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
75wxEND_PROPERTIES_TABLE()
76
77wxBEGIN_HANDLERS_TABLE(wxStaticText)
78wxEND_HANDLERS_TABLE()
79
80wxCONSTRUCTOR_6( wxStaticText , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
81#else
82IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
83#endif
84
85bool wxStaticText::Create(wxWindow *parent,
86 wxWindowID id,
87 const wxString& label,
88 const wxPoint& pos,
89 const wxSize& size,
90 long style,
91 const wxString& name)
92{
93 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
94 return false;
95
96 if ( !MSWCreateControl(wxT("STATIC"), label, pos, size) )
97 return false;
98
99 return true;
100}
101
102wxBorder wxStaticText::GetDefaultBorder() const
103{
104 return wxBORDER_NONE;
105}
106
107WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const
108{
109 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
110
111 // translate the alignment flags to the Windows ones
112 //
113 // note that both wxALIGN_LEFT and SS_LEFT are equal to 0 so we shouldn't
114 // test for them using & operator
115 if ( style & wxALIGN_CENTRE )
116 msStyle |= SS_CENTER;
117 else if ( style & wxALIGN_RIGHT )
118 msStyle |= SS_RIGHT;
119 else
120 msStyle |= SS_LEFT;
121
122 // this style is necessary to receive mouse events
123 msStyle |= SS_NOTIFY;
124
125 return msStyle;
126}
127
128wxSize wxStaticText::DoGetBestSize() const
129{
130 wxClientDC dc(wx_const_cast(wxStaticText *, this));
131 wxFont font(GetFont());
132 if (!font.Ok())
133 font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
134
135 dc.SetFont(font);
136
137 wxCoord widthTextMax, heightTextTotal;
138 dc.GetMultiLineTextExtent(::wxStripMenuCodes(GetLabel()),
139 &widthTextMax, &heightTextTotal);
140
141#ifdef __WXWINCE__
142 if ( widthTextMax )
143 widthTextMax += 2;
144#endif // __WXWINCE__
145
146 // border takes extra space
147 //
148 // TODO: this is probably not wxStaticText-specific and should be moved
149 wxCoord border;
150 switch ( GetBorder() )
151 {
152 case wxBORDER_STATIC:
153 case wxBORDER_SIMPLE:
154 border = 1;
155 break;
156
157 case wxBORDER_SUNKEN:
158 border = 2;
159 break;
160
161 case wxBORDER_RAISED:
162 case wxBORDER_DOUBLE:
163 border = 3;
164 break;
165
166 default:
167 wxFAIL_MSG( _T("unknown border style") );
168 // fall through
169
170 case wxBORDER_NONE:
171 border = 0;
172 }
173
174 widthTextMax += 2*border;
175 heightTextTotal += 2*border;
176
177 wxSize best(widthTextMax, heightTextTotal);
178 CacheBestSize(best);
179 return best;
180}
181
182void wxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags)
183{
184 // we need to refresh the window after changing its size as the standard
185 // control doesn't always update itself properly
186 wxStaticTextBase::DoSetSize(x, y, w, h, sizeFlags);
187
188 Refresh();
189}
190
191void wxStaticText::SetLabel(const wxString& label)
192{
193 wxStaticTextBase::SetLabel(label);
194
195 // adjust the size of the window to fit to the label unless autoresizing is
196 // disabled
197 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
198 {
199 InvalidateBestSize();
200 DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
201 wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
202 }
203}
204
205
206bool wxStaticText::SetFont(const wxFont& font)
207{
208 bool ret = wxControl::SetFont(font);
209
210 // adjust the size of the window to fit to the label unless autoresizing is
211 // disabled
212 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
213 {
214 InvalidateBestSize();
215 DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
216 wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
217 }
218
219 return ret;
220}
221
222#endif // wxUSE_STATTEXT