]> git.saurik.com Git - wxWidgets.git/blame - src/msw/stattext.cpp
added configtool, helpview and emulator makefiles
[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
JS
8// Copyright: (c) Julian Smart
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
SC
35#if wxUSE_EXTENDED_RTTI
36IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticText, wxControl,"wx/stattext.h")
37
38WX_BEGIN_PROPERTIES_TABLE(wxStaticText)
39 WX_PROPERTY_SET_BY_REF( Label,wxString, SetLabel, GetLabel, wxT("") )
40WX_END_PROPERTIES_TABLE()
41
42WX_BEGIN_HANDLERS_TABLE(wxStaticText)
43WX_END_HANDLERS_TABLE()
44
45WX_CONSTRUCTOR_6( wxStaticText , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
46#else
2bda0e17 47IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
51741307 48#endif
2bda0e17 49
6dd16e4f
VZ
50bool wxStaticText::Create(wxWindow *parent,
51 wxWindowID id,
52 const wxString& label,
53 const wxPoint& pos,
54 const wxSize& size,
55 long style,
56 const wxString& name)
2bda0e17 57{
6dd16e4f
VZ
58 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
59 return FALSE;
2bda0e17 60
6dd16e4f
VZ
61 if ( !MSWCreateControl(wxT("STATIC"), label, pos, size) )
62 return FALSE;
2bda0e17 63
6dd16e4f
VZ
64 return TRUE;
65}
c085e333 66
65bc172c
VZ
67wxBorder wxStaticText::GetDefaultBorder() const
68{
69 return wxBORDER_NONE;
70}
71
6dd16e4f
VZ
72WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const
73{
74 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
75
76 // translate the alignment flags to the Windows ones
77 //
78 // note that both wxALIGN_LEFT and SS_LEFT are equal to 0 so we shouldn't
79 // test for them using & operator
80 if ( style & wxALIGN_CENTRE )
81 msStyle |= SS_CENTER;
82 else if ( style & wxALIGN_RIGHT )
83 msStyle |= SS_RIGHT;
84 else
85 msStyle |= SS_LEFT;
86
87 return msStyle;
2bda0e17
KB
88}
89
f68586e5 90wxSize wxStaticText::DoGetBestSize() const
2bda0e17 91{
4b5d9823
VZ
92 wxString text(wxGetWindowText(GetHWND()));
93
94 int widthTextMax = 0, widthLine,
4fe5383d 95 heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
4b5d9823 96
b826684e
VZ
97 bool lastWasAmpersand = FALSE;
98
4b5d9823 99 wxString curLine;
b826684e
VZ
100 for ( const wxChar *pc = text; ; pc++ )
101 {
102 if ( *pc == wxT('\n') || *pc == wxT('\0') )
103 {
104 if ( !curLine )
105 {
4fe5383d
VZ
106 // we can't use GetTextExtent - it will return 0 for both width
107 // and height and an empty line should count in height
108 // calculation
109 if ( !heightLineDefault )
110 heightLineDefault = heightLine;
111 if ( !heightLineDefault )
112 GetTextExtent(_T("W"), NULL, &heightLineDefault);
113
114 heightTextTotal += heightLineDefault;
115 }
b826684e
VZ
116 else
117 {
4fe5383d
VZ
118 GetTextExtent(curLine, &widthLine, &heightLine);
119 if ( widthLine > widthTextMax )
120 widthTextMax = widthLine;
121 heightTextTotal += heightLine;
122 }
4b5d9823 123
b826684e
VZ
124 if ( *pc == wxT('\n') )
125 {
4b5d9823
VZ
126 curLine.Empty();
127 }
b826684e
VZ
128 else
129 {
4b5d9823
VZ
130 // the end of string
131 break;
132 }
133 }
b826684e
VZ
134 else
135 {
136 // we shouldn't take into account the '&' which just introduces the
137 // mnemonic characters and so are not shown on the screen -- except
138 // when it is preceded by another '&' in which case it stands for a
139 // literal ampersand
140 if ( *pc == _T('&') )
141 {
142 if ( !lastWasAmpersand )
143 {
144 lastWasAmpersand = TRUE;
145
146 // skip the statement adding pc to curLine below
147 continue;
148 }
149
150 // it is a literal ampersand
151 lastWasAmpersand = FALSE;
152 }
153
154 curLine += *pc;
4b5d9823
VZ
155 }
156 }
157
4438caf4 158 return wxSize(widthTextMax, heightTextTotal);
2bda0e17
KB
159}
160
1e3a888e
VZ
161void wxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags)
162{
163 // we need to refresh the window after changing its size as the standard
164 // control doesn't always update itself properly
165 wxStaticTextBase::DoSetSize(x, y, w, h, sizeFlags);
166
167 Refresh();
168}
169
2bda0e17
KB
170void wxStaticText::SetLabel(const wxString& label)
171{
1e3a888e 172 wxStaticTextBase::SetLabel(label);
2bda0e17 173
185fa6bf
VZ
174 // adjust the size of the window to fit to the label unless autoresizing is
175 // disabled
176 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
177 {
178 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
179 }
2bda0e17
KB
180}
181
486fd225
RD
182
183bool wxStaticText::SetFont(const wxFont& font)
184{
185 bool ret = wxControl::SetFont(font);
186
187 // adjust the size of the window to fit to the label unless autoresizing is
188 // disabled
189 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
190 {
191 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
192 }
193
194 return ret;
195}
196
1e6feb95 197#endif // wxUSE_STATTEXT