]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
Rewrite wxExecute() implementation under Unix.
[wxWidgets.git] / src / os2 / stattext.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
d5da0ce7 2// Name: src/os2/stattext.cpp
0e320a79 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
ccdc11bb
WS
15#include "wx/stattext.h"
16
d90895ac 17#ifndef WX_PRECOMP
d5da0ce7
WS
18 #include "wx/event.h"
19 #include "wx/app.h"
20 #include "wx/brush.h"
21 #include "wx/scrolwin.h"
d90895ac 22#endif
0e320a79 23
d90895ac 24#include "wx/os2/private.h"
0e320a79
DW
25#include <stdio.h>
26
d5da0ce7
WS
27bool wxStaticText::Create( wxWindow* pParent,
28 wxWindowID vId,
29 const wxString& rsLabel,
30 const wxPoint& rPos,
31 const wxSize& rSize,
32 long lStyle,
33 const wxString& rsName )
0e320a79 34{
1f3154c8
DW
35 SetName(rsName);
36 if (pParent)
37 pParent->AddChild(this);
d90895ac 38
1f3154c8
DW
39 SetBackgroundColour(pParent->GetBackgroundColour()) ;
40 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 41
d5da0ce7 42 if ( vId == wxID_ANY )
d90895ac
DW
43 m_windowId = (int)NewControlId();
44 else
1f3154c8 45 m_windowId = vId;
0e320a79 46
d5da0ce7
WS
47 int nX = rPos.x;
48 int nY = rPos.y;
49 int nWidth = rSize.x;
50 int nHeight = rSize.y;
0e320a79 51
1f3154c8 52 m_windowStyle = lStyle;
0e320a79 53
d5da0ce7 54 long lSstyle = 0L;
0e320a79 55
61cc6764
SN
56 // Used to have DT_VCENTER but that doesn't work correctly with
57 // multiline strings and DT_WORDBREAK. Accept a reasonable
58 // compromise for now
59 lSstyle = WS_VISIBLE | SS_TEXT | DT_WORDBREAK | 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 66
1f3154c8
DW
67 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
68 ,WC_STATIC // Window class
39bc0347 69 ,NULL // Initial Text
1f3154c8
DW
70 ,(ULONG)lSstyle // Style flags
71 ,0L, 0L, 0L, 0L // Origin -- 0 size
72 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
73 ,HWND_TOP // initial z position
74 ,(ULONG)m_windowId // Window identifier
75 ,NULL // no control data
76 ,NULL // no Presentation parameters
77 );
78
d5da0ce7 79 wxCHECK_MSG(m_hWnd, false, wxT("Failed to create static ctrl"));
3c299c3a 80
d5da0ce7 81 LONG lColor = (LONG)wxBLACK->GetPixel();
3c299c3a
DW
82
83 ::WinSetPresParam( m_hWnd
84 ,PP_FOREGROUNDCOLOR
85 ,sizeof(LONG)
86 ,(PVOID)&lColor
87 );
7993e67c
DW
88 lColor = (LONG)m_backgroundColour.GetPixel();
89
90 ::WinSetPresParam( m_hWnd
91 ,PP_BACKGROUNDCOLOR
92 ,sizeof(LONG)
93 ,(PVOID)&lColor
94 );
3c299c3a 95
1f3154c8 96 SubclassWin(m_hWnd);
b720b24d
DW
97 SetFont(*wxSMALL_FONT);
98 SetXComp(0);
99 SetYComp(0);
d5da0ce7
WS
100 SetSize( nX, nY, nWidth, nHeight );
101
39bc0347
VZ
102 SetLabel(rsLabel);
103
d5da0ce7 104 return true;
1f3154c8 105} // end of wxStaticText::Create
0e320a79 106
e78c4d50 107wxSize wxStaticText::DoGetBestSize() const
0e320a79 108{
39bc0347 109 wxString sText(GetLabel());
d5da0ce7
WS
110 int nWidthTextMax = 0;
111 int nWidthLine = 0;
112 int nHeightTextTotal = 0;
113 int nHeightLineDefault = 0;
114 int nHeightLine = 0;
115 wxString sCurLine;
116 bool bLastWasTilde = false;
1f3154c8 117
3c299c3a 118 for (const wxChar *pc = sText; ; pc++)
1f3154c8
DW
119 {
120 if ( *pc == wxT('\n') || *pc == wxT('\0') )
121 {
122 if (!sCurLine )
123 {
124 //
125 // We can't use GetTextExtent - it will return 0 for both width
e78c4d50
DW
126 // and height and an empty line should count in height
127 // calculation
1f3154c8
DW
128 //
129 if (!nHeightLineDefault)
130 nHeightLineDefault = nHeightLine;
131 if (!nHeightLineDefault)
9a83f860 132 GetTextExtent(wxT("W"), NULL, &nHeightLineDefault);
1f3154c8 133 nHeightTextTotal += nHeightLineDefault;
e78c4d50 134 }
1f3154c8
DW
135 else
136 {
137 GetTextExtent( sCurLine
138 ,&nWidthLine
139 ,&nHeightLine
140 );
141 if (nWidthLine > nWidthTextMax)
142 nWidthTextMax = nWidthLine;
143 nHeightTextTotal += nHeightLine;
e78c4d50 144 }
d90895ac 145
1f3154c8
DW
146 if ( *pc == wxT('\n') )
147 {
148 sCurLine.Empty();
d90895ac 149 }
1f3154c8
DW
150 else
151 {
d90895ac
DW
152 break;
153 }
154 }
1f3154c8
DW
155 else
156 {
6e348b12 157 //
e94d504d 158 // We shouldn't take into account the '~' which just introduces the
6e348b12 159 // mnemonic characters and so are not shown on the screen -- except
e94d504d
SN
160 // when it is preceded by another '~' in which case it stands for a
161 // literal tilde
6e348b12 162 //
9a83f860 163 if (*pc == wxT('~'))
6e348b12 164 {
e94d504d 165 if (!bLastWasTilde)
6e348b12 166 {
d5da0ce7 167 bLastWasTilde = true;
6e348b12
DW
168
169 //
170 // Skip the statement adding pc to curLine below
171 //
172 continue;
173 }
174
175 //
e94d504d 176 // It is a literal tilde
6e348b12 177 //
d5da0ce7 178 bLastWasTilde = false;
6e348b12 179 }
1f3154c8 180 sCurLine += *pc;
d90895ac
DW
181 }
182 }
1f3154c8
DW
183 return wxSize( nWidthTextMax
184 ,nHeightTextTotal
185 );
186} // end of wxStaticText::DoGetBestSize
187
7993e67c
DW
188void wxStaticText::DoSetSize(
189 int nX
190, int nY
191, int nWidth
192, int nHeight
193, int nSizeFlags
194)
195{
196 //
197 // We need to refresh the window after changing its size as the standard
198 // control doesn't always update itself properly.
199 //
200 wxStaticTextBase::DoSetSize( nX
201 ,nY
202 ,nWidth
203 ,nHeight
204 ,nSizeFlags
205 );
39bc0347
VZ
206
207 // eventually update label (if ellipsizing is on):
208 UpdateLabel();
209
7993e67c
DW
210 Refresh();
211} // end of wxStaticText::DoSetSize
212
3c299c3a
DW
213bool wxStaticText::SetFont(
214 const wxFont& rFont
1f3154c8 215)
0e320a79 216{
3c299c3a 217 bool bRet = wxControl::SetFont(rFont);
1f3154c8
DW
218
219 //
220 // Adjust the size of the window to fit to the label unless autoresizing is
221 // disabled
222 //
3c299c3a 223 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
1f3154c8
DW
224 {
225 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
226 }
3c299c3a
DW
227 return bRet;
228} // end of wxStaticText::SetFont
d90895ac 229
3c299c3a
DW
230void wxStaticText::SetLabel(
231 const wxString& rsLabel
1f3154c8 232)
d90895ac 233{
39bc0347
VZ
234 m_labelOrig = rsLabel; // save original label
235
3da9cffc
VZ
236 // OS/2 does not support ellipsized labels in static text:
237 DoSetLabel(GetEllipsizedLabel());
1f3154c8
DW
238
239 //
240 // Adjust the size of the window to fit to the label unless autoresizing is
241 // disabled
242 //
39bc0347
VZ
243 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
244 !IsEllipsized())
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
39bc0347
VZ
271
272
273// for wxST_ELLIPSIZE_* support:
274
275void wxStaticText::DoSetLabel(const wxString& str)
276{
277 wxString sLabel = ::wxPMTextToLabel(str);
a8988cb3 278 ::WinSetWindowText(GetHwnd(), sLabel.c_str());
39bc0347
VZ
279}
280
281wxString wxStaticText::DoGetLabel() const
282{
79f45cf7 283 return wxGetWindowText(GetHwnd());
39bc0347
VZ
284}
285