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