]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
wxFileCtrl::Update was hiding wxWindow::Update
[wxWidgets.git] / src / os2 / stattext.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: stattext.cpp
3// Purpose: wxStaticText
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
aa213887
SN
12#ifdef __GNUG__
13#pragma implementation "stattext.h"
14#endif
15
d90895ac
DW
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
0e320a79 18
d90895ac
DW
19#ifndef WX_PRECOMP
20#include "wx/event.h"
0e320a79 21#include "wx/app.h"
d90895ac 22#include "wx/brush.h"
a4a16252 23#include "wx/scrolwin.h"
d90895ac 24#endif
0e320a79 25
d90895ac
DW
26#include "wx/stattext.h"
27#include "wx/os2/private.h"
0e320a79
DW
28#include <stdio.h>
29
0e320a79 30IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
0e320a79 31
1f3154c8
DW
32bool wxStaticText::Create(
33 wxWindow* pParent
34, wxWindowID vId
35, const wxString& rsLabel
36, const wxPoint& rPos
37, const wxSize& rSize
38, long lStyle
39, const wxString& rsName
40)
0e320a79 41{
1f3154c8
DW
42 SetName(rsName);
43 if (pParent)
44 pParent->AddChild(this);
d90895ac 45
1f3154c8
DW
46 SetBackgroundColour(pParent->GetBackgroundColour()) ;
47 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 48
f15b4952 49 if ( vId == -1 )
d90895ac
DW
50 m_windowId = (int)NewControlId();
51 else
1f3154c8 52 m_windowId = vId;
0e320a79 53
1f3154c8
DW
54 int nX = rPos.x;
55 int nY = rPos.y;
56 int nWidth = rSize.x;
57 int nHeight = rSize.y;
0e320a79 58
1f3154c8 59 m_windowStyle = lStyle;
0e320a79 60
1f3154c8 61 long lSstyle = 0L;
0e320a79 62
1f3154c8
DW
63 lSstyle = WS_VISIBLE | SS_TEXT | DT_VCENTER;
64 if (m_windowStyle & wxALIGN_CENTRE)
65 lSstyle |= DT_CENTER;
66 else if (m_windowStyle & wxALIGN_RIGHT)
67 lSstyle |= DT_RIGHT;
68 else
69 lSstyle |= DT_LEFT;
5d44b24e
DW
70 //
71 // If the parent is a scrolled window the controls must
72 // have this style or they will overlap the scrollbars
73 //
74 if (pParent)
75 if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) ||
76 pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)))
77 lSstyle |= WS_CLIPSIBLINGS;
78
1f3154c8
DW
79 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
80 ,WC_STATIC // Window class
81 ,(PSZ)rsLabel.c_str() // Initial Text
82 ,(ULONG)lSstyle // Style flags
83 ,0L, 0L, 0L, 0L // Origin -- 0 size
84 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
85 ,HWND_TOP // initial z position
86 ,(ULONG)m_windowId // Window identifier
87 ,NULL // no control data
88 ,NULL // no Presentation parameters
89 );
90
91 wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl"));
d90895ac 92
3c299c3a
DW
93 wxColour vColour;
94
95 vColour.Set(wxString("BLACK"));
96
97 LONG lColor = (LONG)vColour.GetPixel();
98
99 ::WinSetPresParam( m_hWnd
100 ,PP_FOREGROUNDCOLOR
101 ,sizeof(LONG)
102 ,(PVOID)&lColor
103 );
7993e67c
DW
104 lColor = (LONG)m_backgroundColour.GetPixel();
105
106 ::WinSetPresParam( m_hWnd
107 ,PP_BACKGROUNDCOLOR
108 ,sizeof(LONG)
109 ,(PVOID)&lColor
110 );
3c299c3a 111
1f3154c8 112 SubclassWin(m_hWnd);
e58dab20 113 wxControl::SetFont(*wxSMALL_FONT);
3c299c3a
DW
114 SetSize( nX
115 ,nY
116 ,nWidth
117 ,nHeight
118 );
119 return TRUE;
1f3154c8 120} // end of wxStaticText::Create
0e320a79 121
e78c4d50 122wxSize wxStaticText::DoGetBestSize() const
0e320a79 123{
1f3154c8
DW
124 wxString sText(wxGetWindowText(GetHWND()));
125 int nWidthTextMax = 0;
126 int nWidthLine = 0;
127 int nHeightTextTotal = 0;
128 int nHeightLineDefault = 0;
129 int nHeightLine = 0;
130 wxString sCurLine;
131
3c299c3a 132 for (const wxChar *pc = sText; ; pc++)
1f3154c8
DW
133 {
134 if ( *pc == wxT('\n') || *pc == wxT('\0') )
135 {
136 if (!sCurLine )
137 {
138 //
139 // We can't use GetTextExtent - it will return 0 for both width
e78c4d50
DW
140 // and height and an empty line should count in height
141 // calculation
1f3154c8
DW
142 //
143 if (!nHeightLineDefault)
144 nHeightLineDefault = nHeightLine;
145 if (!nHeightLineDefault)
146 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
147 nHeightTextTotal += nHeightLineDefault;
e78c4d50 148 }
1f3154c8
DW
149 else
150 {
151 GetTextExtent( sCurLine
152 ,&nWidthLine
153 ,&nHeightLine
154 );
155 if (nWidthLine > nWidthTextMax)
156 nWidthTextMax = nWidthLine;
157 nHeightTextTotal += nHeightLine;
e78c4d50 158 }
d90895ac 159
1f3154c8
DW
160 if ( *pc == wxT('\n') )
161 {
162 sCurLine.Empty();
d90895ac 163 }
1f3154c8
DW
164 else
165 {
d90895ac
DW
166 break;
167 }
168 }
1f3154c8
DW
169 else
170 {
171 sCurLine += *pc;
d90895ac
DW
172 }
173 }
1f3154c8
DW
174 return wxSize( nWidthTextMax
175 ,nHeightTextTotal
176 );
177} // end of wxStaticText::DoGetBestSize
178
7993e67c
DW
179void wxStaticText::DoSetSize(
180 int nX
181, int nY
182, int nWidth
183, int nHeight
184, int nSizeFlags
185)
186{
187 //
188 // We need to refresh the window after changing its size as the standard
189 // control doesn't always update itself properly.
190 //
191 wxStaticTextBase::DoSetSize( nX
192 ,nY
193 ,nWidth
194 ,nHeight
195 ,nSizeFlags
196 );
197 Refresh();
198} // end of wxStaticText::DoSetSize
199
3c299c3a
DW
200bool wxStaticText::SetFont(
201 const wxFont& rFont
1f3154c8 202)
0e320a79 203{
3c299c3a 204 bool bRet = wxControl::SetFont(rFont);
1f3154c8
DW
205
206 //
207 // Adjust the size of the window to fit to the label unless autoresizing is
208 // disabled
209 //
3c299c3a 210 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
1f3154c8
DW
211 {
212 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
213 }
3c299c3a
DW
214 return bRet;
215} // end of wxStaticText::SetFont
d90895ac 216
3c299c3a
DW
217void wxStaticText::SetLabel(
218 const wxString& rsLabel
1f3154c8 219)
d90895ac 220{
3c299c3a 221 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
1f3154c8
DW
222
223 //
224 // Adjust the size of the window to fit to the label unless autoresizing is
225 // disabled
226 //
3c299c3a 227 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
1f3154c8
DW
228 {
229 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
230 }
3c299c3a
DW
231 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
232} // end of wxStaticText::SetLabel
1f3154c8
DW
233
234MRESULT wxStaticText::OS2WindowProc(
235 WXUINT uMsg
236, WXWPARAM wParam
237, WXLPARAM lParam
238)
d90895ac 239{
1f3154c8
DW
240 return wxWindow::OS2WindowProc( uMsg
241 ,wParam
242 ,lParam
243 );
244} // end of wxStaticText::OS2WindowProc