]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
Don't assert if the path is not absolute in wxFileDialog::SetPath().
[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
0e320a79 27IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
0e320a79 28
d5da0ce7
WS
29bool wxStaticText::Create( wxWindow* pParent,
30 wxWindowID vId,
31 const wxString& rsLabel,
32 const wxPoint& rPos,
33 const wxSize& rSize,
34 long lStyle,
35 const wxString& rsName )
0e320a79 36{
1f3154c8
DW
37 SetName(rsName);
38 if (pParent)
39 pParent->AddChild(this);
d90895ac 40
1f3154c8
DW
41 SetBackgroundColour(pParent->GetBackgroundColour()) ;
42 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 43
d5da0ce7 44 if ( vId == wxID_ANY )
d90895ac
DW
45 m_windowId = (int)NewControlId();
46 else
1f3154c8 47 m_windowId = vId;
0e320a79 48
d5da0ce7
WS
49 int nX = rPos.x;
50 int nY = rPos.y;
51 int nWidth = rSize.x;
52 int nHeight = rSize.y;
0e320a79 53
1f3154c8 54 m_windowStyle = lStyle;
0e320a79 55
d5da0ce7 56 long lSstyle = 0L;
0e320a79 57
61cc6764
SN
58 // Used to have DT_VCENTER but that doesn't work correctly with
59 // multiline strings and DT_WORDBREAK. Accept a reasonable
60 // compromise for now
61 lSstyle = WS_VISIBLE | SS_TEXT | DT_WORDBREAK | DT_MNEMONIC;
1f3154c8
DW
62 if (m_windowStyle & wxALIGN_CENTRE)
63 lSstyle |= DT_CENTER;
64 else if (m_windowStyle & wxALIGN_RIGHT)
65 lSstyle |= DT_RIGHT;
66 else
67 lSstyle |= DT_LEFT;
e94d504d 68
1f3154c8
DW
69 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
70 ,WC_STATIC // Window class
39bc0347 71 ,NULL // 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
d5da0ce7 81 wxCHECK_MSG(m_hWnd, false, wxT("Failed to create static ctrl"));
3c299c3a 82
d5da0ce7 83 LONG lColor = (LONG)wxBLACK->GetPixel();
3c299c3a
DW
84
85 ::WinSetPresParam( m_hWnd
86 ,PP_FOREGROUNDCOLOR
87 ,sizeof(LONG)
88 ,(PVOID)&lColor
89 );
7993e67c
DW
90 lColor = (LONG)m_backgroundColour.GetPixel();
91
92 ::WinSetPresParam( m_hWnd
93 ,PP_BACKGROUNDCOLOR
94 ,sizeof(LONG)
95 ,(PVOID)&lColor
96 );
3c299c3a 97
1f3154c8 98 SubclassWin(m_hWnd);
b720b24d
DW
99 SetFont(*wxSMALL_FONT);
100 SetXComp(0);
101 SetYComp(0);
d5da0ce7
WS
102 SetSize( nX, nY, nWidth, nHeight );
103
39bc0347
VZ
104 SetLabel(rsLabel);
105
d5da0ce7 106 return true;
1f3154c8 107} // end of wxStaticText::Create
0e320a79 108
e78c4d50 109wxSize wxStaticText::DoGetBestSize() const
0e320a79 110{
39bc0347 111 wxString sText(GetLabel());
d5da0ce7
WS
112 int nWidthTextMax = 0;
113 int nWidthLine = 0;
114 int nHeightTextTotal = 0;
115 int nHeightLineDefault = 0;
116 int nHeightLine = 0;
117 wxString sCurLine;
118 bool bLastWasTilde = false;
1f3154c8 119
3c299c3a 120 for (const wxChar *pc = sText; ; pc++)
1f3154c8
DW
121 {
122 if ( *pc == wxT('\n') || *pc == wxT('\0') )
123 {
124 if (!sCurLine )
125 {
126 //
127 // We can't use GetTextExtent - it will return 0 for both width
e78c4d50
DW
128 // and height and an empty line should count in height
129 // calculation
1f3154c8
DW
130 //
131 if (!nHeightLineDefault)
132 nHeightLineDefault = nHeightLine;
133 if (!nHeightLineDefault)
9a83f860 134 GetTextExtent(wxT("W"), NULL, &nHeightLineDefault);
1f3154c8 135 nHeightTextTotal += nHeightLineDefault;
e78c4d50 136 }
1f3154c8
DW
137 else
138 {
139 GetTextExtent( sCurLine
140 ,&nWidthLine
141 ,&nHeightLine
142 );
143 if (nWidthLine > nWidthTextMax)
144 nWidthTextMax = nWidthLine;
145 nHeightTextTotal += nHeightLine;
e78c4d50 146 }
d90895ac 147
1f3154c8
DW
148 if ( *pc == wxT('\n') )
149 {
150 sCurLine.Empty();
d90895ac 151 }
1f3154c8
DW
152 else
153 {
d90895ac
DW
154 break;
155 }
156 }
1f3154c8
DW
157 else
158 {
6e348b12 159 //
e94d504d 160 // We shouldn't take into account the '~' which just introduces the
6e348b12 161 // mnemonic characters and so are not shown on the screen -- except
e94d504d
SN
162 // when it is preceded by another '~' in which case it stands for a
163 // literal tilde
6e348b12 164 //
9a83f860 165 if (*pc == wxT('~'))
6e348b12 166 {
e94d504d 167 if (!bLastWasTilde)
6e348b12 168 {
d5da0ce7 169 bLastWasTilde = true;
6e348b12
DW
170
171 //
172 // Skip the statement adding pc to curLine below
173 //
174 continue;
175 }
176
177 //
e94d504d 178 // It is a literal tilde
6e348b12 179 //
d5da0ce7 180 bLastWasTilde = false;
6e348b12 181 }
1f3154c8 182 sCurLine += *pc;
d90895ac
DW
183 }
184 }
1f3154c8
DW
185 return wxSize( nWidthTextMax
186 ,nHeightTextTotal
187 );
188} // end of wxStaticText::DoGetBestSize
189
7993e67c
DW
190void wxStaticText::DoSetSize(
191 int nX
192, int nY
193, int nWidth
194, int nHeight
195, int nSizeFlags
196)
197{
198 //
199 // We need to refresh the window after changing its size as the standard
200 // control doesn't always update itself properly.
201 //
202 wxStaticTextBase::DoSetSize( nX
203 ,nY
204 ,nWidth
205 ,nHeight
206 ,nSizeFlags
207 );
39bc0347
VZ
208
209 // eventually update label (if ellipsizing is on):
210 UpdateLabel();
211
7993e67c
DW
212 Refresh();
213} // end of wxStaticText::DoSetSize
214
3c299c3a
DW
215bool wxStaticText::SetFont(
216 const wxFont& rFont
1f3154c8 217)
0e320a79 218{
3c299c3a 219 bool bRet = wxControl::SetFont(rFont);
1f3154c8
DW
220
221 //
222 // Adjust the size of the window to fit to the label unless autoresizing is
223 // disabled
224 //
3c299c3a 225 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
1f3154c8
DW
226 {
227 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
228 }
3c299c3a
DW
229 return bRet;
230} // end of wxStaticText::SetFont
d90895ac 231
3c299c3a
DW
232void wxStaticText::SetLabel(
233 const wxString& rsLabel
1f3154c8 234)
d90895ac 235{
39bc0347
VZ
236 m_labelOrig = rsLabel; // save original label
237
238 // OS/2 does not support neither ellipsize nor markup in static text:
a8988cb3
SN
239 DoSetLabel(rsLabel);
240 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
1f3154c8
DW
241
242 //
243 // Adjust the size of the window to fit to the label unless autoresizing is
244 // disabled
245 //
39bc0347
VZ
246 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
247 !IsEllipsized())
1f3154c8 248 {
b720b24d
DW
249 wxCoord vX;
250 wxCoord vY;
251 wxCoord vWidth;
252 wxCoord vHeight;
253
254 GetPosition(&vX, &vY);
255 GetSize(&vWidth, &vHeight);
256 if (!(vX == -1 && vY == -1 && vWidth == -1 && vHeight == -1))
257 DoSetSize(vX, vY, vWidth, vHeight, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
258 else
259 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
1f3154c8 260 }
3c299c3a 261} // end of wxStaticText::SetLabel
1f3154c8
DW
262
263MRESULT wxStaticText::OS2WindowProc(
264 WXUINT uMsg
265, WXWPARAM wParam
266, WXLPARAM lParam
267)
d90895ac 268{
1f3154c8
DW
269 return wxWindow::OS2WindowProc( uMsg
270 ,wParam
271 ,lParam
272 );
273} // end of wxStaticText::OS2WindowProc
39bc0347
VZ
274
275
276// for wxST_ELLIPSIZE_* support:
277
278void wxStaticText::DoSetLabel(const wxString& str)
279{
280 wxString sLabel = ::wxPMTextToLabel(str);
a8988cb3 281 ::WinSetWindowText(GetHwnd(), sLabel.c_str());
39bc0347
VZ
282}
283
284wxString wxStaticText::DoGetLabel() const
285{
79f45cf7 286 return wxGetWindowText(GetHwnd());
39bc0347
VZ
287}
288