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