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