]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
Remove my binary compatibility stuff from HEAD. Patch #1367014 used for reference.
[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 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d90895ac
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
d90895ac
DW
15#ifndef WX_PRECOMP
16#include "wx/event.h"
0e320a79 17#include "wx/app.h"
d90895ac 18#include "wx/brush.h"
a4a16252 19#include "wx/scrolwin.h"
d90895ac 20#endif
0e320a79 21
d90895ac
DW
22#include "wx/stattext.h"
23#include "wx/os2/private.h"
0e320a79
DW
24#include <stdio.h>
25
0e320a79 26IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
0e320a79 27
1f3154c8
DW
28bool wxStaticText::Create(
29 wxWindow* pParent
30, wxWindowID vId
31, const wxString& rsLabel
32, const wxPoint& rPos
33, const wxSize& rSize
34, long lStyle
35, const wxString& rsName
36)
0e320a79 37{
1f3154c8
DW
38 SetName(rsName);
39 if (pParent)
40 pParent->AddChild(this);
d90895ac 41
1f3154c8
DW
42 SetBackgroundColour(pParent->GetBackgroundColour()) ;
43 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 44
f15b4952 45 if ( vId == -1 )
d90895ac
DW
46 m_windowId = (int)NewControlId();
47 else
1f3154c8 48 m_windowId = vId;
0e320a79 49
1f3154c8
DW
50 int nX = rPos.x;
51 int nY = rPos.y;
52 int nWidth = rSize.x;
53 int nHeight = rSize.y;
0e320a79 54
1f3154c8 55 m_windowStyle = lStyle;
0e320a79 56
1f3154c8 57 long lSstyle = 0L;
0e320a79 58
e94d504d 59 lSstyle = WS_VISIBLE | SS_TEXT | DT_VCENTER | DT_MNEMONIC;
1f3154c8
DW
60 if (m_windowStyle & wxALIGN_CENTRE)
61 lSstyle |= DT_CENTER;
62 else if (m_windowStyle & wxALIGN_RIGHT)
63 lSstyle |= DT_RIGHT;
64 else
65 lSstyle |= DT_LEFT;
e94d504d
SN
66
67 wxString sLabel = ::wxPMTextToLabel(rsLabel);
68
1f3154c8
DW
69 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
70 ,WC_STATIC // Window class
e94d504d 71 ,(PSZ)sLabel.c_str() // Initial Text
1f3154c8
DW
72 ,(ULONG)lSstyle // Style flags
73 ,0L, 0L, 0L, 0L // Origin -- 0 size
74 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
75 ,HWND_TOP // initial z position
76 ,(ULONG)m_windowId // Window identifier
77 ,NULL // no control data
78 ,NULL // no Presentation parameters
79 );
80
81 wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl"));
d90895ac 82
3c299c3a
DW
83 wxColour vColour;
84
0fba44b4 85 vColour.Set(wxString(wxT("BLACK")));
3c299c3a
DW
86
87 LONG lColor = (LONG)vColour.GetPixel();
88
89 ::WinSetPresParam( m_hWnd
90 ,PP_FOREGROUNDCOLOR
91 ,sizeof(LONG)
92 ,(PVOID)&lColor
93 );
7993e67c
DW
94 lColor = (LONG)m_backgroundColour.GetPixel();
95
96 ::WinSetPresParam( m_hWnd
97 ,PP_BACKGROUNDCOLOR
98 ,sizeof(LONG)
99 ,(PVOID)&lColor
100 );
3c299c3a 101
1f3154c8 102 SubclassWin(m_hWnd);
b720b24d
DW
103 SetFont(*wxSMALL_FONT);
104 SetXComp(0);
105 SetYComp(0);
3c299c3a
DW
106 SetSize( nX
107 ,nY
108 ,nWidth
109 ,nHeight
110 );
111 return TRUE;
1f3154c8 112} // end of wxStaticText::Create
0e320a79 113
e78c4d50 114wxSize wxStaticText::DoGetBestSize() const
0e320a79 115{
1f3154c8
DW
116 wxString sText(wxGetWindowText(GetHWND()));
117 int nWidthTextMax = 0;
118 int nWidthLine = 0;
119 int nHeightTextTotal = 0;
120 int nHeightLineDefault = 0;
121 int nHeightLine = 0;
122 wxString sCurLine;
e94d504d 123 bool bLastWasTilde = FALSE;
1f3154c8 124
3c299c3a 125 for (const wxChar *pc = sText; ; pc++)
1f3154c8
DW
126 {
127 if ( *pc == wxT('\n') || *pc == wxT('\0') )
128 {
129 if (!sCurLine )
130 {
131 //
132 // We can't use GetTextExtent - it will return 0 for both width
e78c4d50
DW
133 // and height and an empty line should count in height
134 // calculation
1f3154c8
DW
135 //
136 if (!nHeightLineDefault)
137 nHeightLineDefault = nHeightLine;
138 if (!nHeightLineDefault)
139 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
140 nHeightTextTotal += nHeightLineDefault;
e78c4d50 141 }
1f3154c8
DW
142 else
143 {
144 GetTextExtent( sCurLine
145 ,&nWidthLine
146 ,&nHeightLine
147 );
148 if (nWidthLine > nWidthTextMax)
149 nWidthTextMax = nWidthLine;
150 nHeightTextTotal += nHeightLine;
e78c4d50 151 }
d90895ac 152
1f3154c8
DW
153 if ( *pc == wxT('\n') )
154 {
155 sCurLine.Empty();
d90895ac 156 }
1f3154c8
DW
157 else
158 {
d90895ac
DW
159 break;
160 }
161 }
1f3154c8
DW
162 else
163 {
6e348b12 164 //
e94d504d 165 // We shouldn't take into account the '~' which just introduces the
6e348b12 166 // mnemonic characters and so are not shown on the screen -- except
e94d504d
SN
167 // when it is preceded by another '~' in which case it stands for a
168 // literal tilde
6e348b12 169 //
e94d504d 170 if (*pc == _T('~'))
6e348b12 171 {
e94d504d 172 if (!bLastWasTilde)
6e348b12 173 {
e94d504d 174 bLastWasTilde = TRUE;
6e348b12
DW
175
176 //
177 // Skip the statement adding pc to curLine below
178 //
179 continue;
180 }
181
182 //
e94d504d 183 // It is a literal tilde
6e348b12 184 //
e94d504d 185 bLastWasTilde = FALSE;
6e348b12 186 }
1f3154c8 187 sCurLine += *pc;
d90895ac
DW
188 }
189 }
1f3154c8
DW
190 return wxSize( nWidthTextMax
191 ,nHeightTextTotal
192 );
193} // end of wxStaticText::DoGetBestSize
194
7993e67c
DW
195void wxStaticText::DoSetSize(
196 int nX
197, int nY
198, int nWidth
199, int nHeight
200, int nSizeFlags
201)
202{
203 //
204 // We need to refresh the window after changing its size as the standard
205 // control doesn't always update itself properly.
206 //
207 wxStaticTextBase::DoSetSize( nX
208 ,nY
209 ,nWidth
210 ,nHeight
211 ,nSizeFlags
212 );
213 Refresh();
214} // end of wxStaticText::DoSetSize
215
3c299c3a
DW
216bool wxStaticText::SetFont(
217 const wxFont& rFont
1f3154c8 218)
0e320a79 219{
3c299c3a 220 bool bRet = wxControl::SetFont(rFont);
1f3154c8
DW
221
222 //
223 // Adjust the size of the window to fit to the label unless autoresizing is
224 // disabled
225 //
3c299c3a 226 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
1f3154c8
DW
227 {
228 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
229 }
3c299c3a
DW
230 return bRet;
231} // end of wxStaticText::SetFont
d90895ac 232
3c299c3a
DW
233void wxStaticText::SetLabel(
234 const wxString& rsLabel
1f3154c8 235)
d90895ac 236{
e94d504d
SN
237 wxString sLabel = ::wxPMTextToLabel(rsLabel);
238 ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str());
1f3154c8
DW
239
240 //
241 // Adjust the size of the window to fit to the label unless autoresizing is
242 // disabled
243 //
3c299c3a 244 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
1f3154c8 245 {
b720b24d
DW
246 wxCoord vX;
247 wxCoord vY;
248 wxCoord vWidth;
249 wxCoord vHeight;
250
251 GetPosition(&vX, &vY);
252 GetSize(&vWidth, &vHeight);
253 if (!(vX == -1 && vY == -1 && vWidth == -1 && vHeight == -1))
254 DoSetSize(vX, vY, vWidth, vHeight, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
255 else
256 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
1f3154c8 257 }
3c299c3a 258} // end of wxStaticText::SetLabel
1f3154c8
DW
259
260MRESULT wxStaticText::OS2WindowProc(
261 WXUINT uMsg
262, WXWPARAM wParam
263, WXLPARAM lParam
264)
d90895ac 265{
1f3154c8
DW
266 return wxWindow::OS2WindowProc( uMsg
267 ,wParam
268 ,lParam
269 );
270} // end of wxStaticText::OS2WindowProc