]> git.saurik.com Git - wxWidgets.git/blame - src/msw/stattext.cpp
Missing define.
[wxWidgets.git] / src / msw / stattext.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e3a888e 2// Name: src/msw/stattext.cpp
2bda0e17
KB
3// Purpose: wxStaticText
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
2bda0e17
KB
13#pragma implementation "stattext.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
1e6feb95
VZ
23#if wxUSE_STATTEXT
24
2bda0e17 25#ifndef WX_PRECOMP
2432b92d 26#include "wx/event.h"
2bda0e17 27#include "wx/app.h"
2432b92d 28#include "wx/brush.h"
2bda0e17
KB
29#endif
30
31#include "wx/stattext.h"
32#include "wx/msw/private.h"
33#include <stdio.h>
34
51741307 35#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
36WX_DEFINE_FLAGS( wxStaticTextStyle )
37
3ff066a4 38wxBEGIN_FLAGS( wxStaticTextStyle )
bc9fb572
JS
39 // new style border flags, we put them first to
40 // use them for streaming out
3ff066a4
SC
41 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
42 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
43 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
44 wxFLAGS_MEMBER(wxBORDER_RAISED)
45 wxFLAGS_MEMBER(wxBORDER_STATIC)
46 wxFLAGS_MEMBER(wxBORDER_NONE)
57f4f925 47
bc9fb572 48 // old style border flags
3ff066a4
SC
49 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
50 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
51 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
52 wxFLAGS_MEMBER(wxRAISED_BORDER)
53 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 54 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
55
56 // standard window styles
3ff066a4
SC
57 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
58 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
59 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
60 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 61 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
62 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
63 wxFLAGS_MEMBER(wxVSCROLL)
64 wxFLAGS_MEMBER(wxHSCROLL)
65
66 wxFLAGS_MEMBER(wxST_NO_AUTORESIZE)
67 wxFLAGS_MEMBER(wxALIGN_LEFT)
68 wxFLAGS_MEMBER(wxALIGN_RIGHT)
69 wxFLAGS_MEMBER(wxALIGN_CENTRE)
70
71wxEND_FLAGS( wxStaticTextStyle )
bc9fb572 72
51741307
SC
73IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticText, wxControl,"wx/stattext.h")
74
3ff066a4 75wxBEGIN_PROPERTIES_TABLE(wxStaticText)
57f4f925 76 wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
af498247 77 wxPROPERTY_FLAGS( WindowStyle , wxStaticTextStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 78wxEND_PROPERTIES_TABLE()
51741307 79
3ff066a4
SC
80wxBEGIN_HANDLERS_TABLE(wxStaticText)
81wxEND_HANDLERS_TABLE()
51741307 82
57f4f925 83wxCONSTRUCTOR_6( wxStaticText , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
51741307 84#else
2bda0e17 85IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
51741307 86#endif
2bda0e17 87
6dd16e4f
VZ
88bool wxStaticText::Create(wxWindow *parent,
89 wxWindowID id,
90 const wxString& label,
91 const wxPoint& pos,
92 const wxSize& size,
93 long style,
94 const wxString& name)
2bda0e17 95{
6dd16e4f 96 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
57f4f925 97 return false;
2bda0e17 98
6dd16e4f 99 if ( !MSWCreateControl(wxT("STATIC"), label, pos, size) )
57f4f925 100 return false;
2bda0e17 101
57f4f925 102 return true;
6dd16e4f 103}
c085e333 104
65bc172c
VZ
105wxBorder wxStaticText::GetDefaultBorder() const
106{
107 return wxBORDER_NONE;
108}
109
6dd16e4f
VZ
110WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const
111{
112 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
113
114 // translate the alignment flags to the Windows ones
115 //
116 // note that both wxALIGN_LEFT and SS_LEFT are equal to 0 so we shouldn't
117 // test for them using & operator
118 if ( style & wxALIGN_CENTRE )
119 msStyle |= SS_CENTER;
120 else if ( style & wxALIGN_RIGHT )
121 msStyle |= SS_RIGHT;
122 else
123 msStyle |= SS_LEFT;
124
125 return msStyle;
2bda0e17
KB
126}
127
f68586e5 128wxSize wxStaticText::DoGetBestSize() const
2bda0e17 129{
4b5d9823
VZ
130 wxString text(wxGetWindowText(GetHWND()));
131
132 int widthTextMax = 0, widthLine,
4fe5383d 133 heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
4b5d9823 134
57f4f925 135 bool lastWasAmpersand = false;
b826684e 136
4b5d9823 137 wxString curLine;
b826684e
VZ
138 for ( const wxChar *pc = text; ; pc++ )
139 {
140 if ( *pc == wxT('\n') || *pc == wxT('\0') )
141 {
142 if ( !curLine )
143 {
4fe5383d
VZ
144 // we can't use GetTextExtent - it will return 0 for both width
145 // and height and an empty line should count in height
146 // calculation
147 if ( !heightLineDefault )
148 heightLineDefault = heightLine;
149 if ( !heightLineDefault )
150 GetTextExtent(_T("W"), NULL, &heightLineDefault);
151
152 heightTextTotal += heightLineDefault;
153 }
b826684e
VZ
154 else
155 {
4fe5383d
VZ
156 GetTextExtent(curLine, &widthLine, &heightLine);
157 if ( widthLine > widthTextMax )
158 widthTextMax = widthLine;
159 heightTextTotal += heightLine;
160 }
4b5d9823 161
b826684e
VZ
162 if ( *pc == wxT('\n') )
163 {
4b5d9823
VZ
164 curLine.Empty();
165 }
b826684e
VZ
166 else
167 {
4b5d9823
VZ
168 // the end of string
169 break;
170 }
171 }
b826684e
VZ
172 else
173 {
174 // we shouldn't take into account the '&' which just introduces the
175 // mnemonic characters and so are not shown on the screen -- except
176 // when it is preceded by another '&' in which case it stands for a
177 // literal ampersand
178 if ( *pc == _T('&') )
179 {
180 if ( !lastWasAmpersand )
181 {
57f4f925 182 lastWasAmpersand = true;
b826684e
VZ
183
184 // skip the statement adding pc to curLine below
185 continue;
186 }
187
188 // it is a literal ampersand
57f4f925 189 lastWasAmpersand = false;
b826684e
VZ
190 }
191
192 curLine += *pc;
4b5d9823
VZ
193 }
194 }
37b53d2a
JS
195#ifdef __WXWINCE__
196 if(widthTextMax) widthTextMax += 2;
197#endif
4438caf4 198 return wxSize(widthTextMax, heightTextTotal);
2bda0e17
KB
199}
200
1e3a888e
VZ
201void wxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags)
202{
203 // we need to refresh the window after changing its size as the standard
204 // control doesn't always update itself properly
205 wxStaticTextBase::DoSetSize(x, y, w, h, sizeFlags);
206
207 Refresh();
208}
209
c0e6c051
RD
210void wxStaticText::SetLabel(const wxString& label)
211{
212 wxStaticTextBase::SetLabel(label);
213
214 // adjust the size of the window to fit to the label unless autoresizing is
215 // disabled
216 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
217 {
9f884528 218 InvalidateBestSize();
57f4f925
WS
219 DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
220 wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
c0e6c051
RD
221 }
222}
223
224
225bool wxStaticText::SetFont(const wxFont& font)
226{
227 bool ret = wxControl::SetFont(font);
228
229 // adjust the size of the window to fit to the label unless autoresizing is
230 // disabled
231 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
232 {
9f884528 233 InvalidateBestSize();
57f4f925
WS
234 DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
235 wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
c0e6c051
RD
236 }
237
238 return ret;
239}
486fd225 240
1e6feb95 241#endif // wxUSE_STATTEXT