]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
Added files for GnomeVFS backend (currently useful
[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
61cc6764
SN
59 // Used to have DT_VCENTER but that doesn't work correctly with
60 // multiline strings and DT_WORDBREAK. Accept a reasonable
61 // compromise for now
62 lSstyle = WS_VISIBLE | SS_TEXT | DT_WORDBREAK | DT_MNEMONIC;
1f3154c8
DW
63 if (m_windowStyle & wxALIGN_CENTRE)
64 lSstyle |= DT_CENTER;
65 else if (m_windowStyle & wxALIGN_RIGHT)
66 lSstyle |= DT_RIGHT;
67 else
68 lSstyle |= DT_LEFT;
e94d504d
SN
69
70 wxString sLabel = ::wxPMTextToLabel(rsLabel);
71
1f3154c8
DW
72 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
73 ,WC_STATIC // Window class
e94d504d 74 ,(PSZ)sLabel.c_str() // Initial Text
1f3154c8
DW
75 ,(ULONG)lSstyle // Style flags
76 ,0L, 0L, 0L, 0L // Origin -- 0 size
77 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
78 ,HWND_TOP // initial z position
79 ,(ULONG)m_windowId // Window identifier
80 ,NULL // no control data
81 ,NULL // no Presentation parameters
82 );
83
84 wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl"));
d90895ac 85
3c299c3a
DW
86 wxColour vColour;
87
0fba44b4 88 vColour.Set(wxString(wxT("BLACK")));
3c299c3a
DW
89
90 LONG lColor = (LONG)vColour.GetPixel();
91
92 ::WinSetPresParam( m_hWnd
93 ,PP_FOREGROUNDCOLOR
94 ,sizeof(LONG)
95 ,(PVOID)&lColor
96 );
7993e67c
DW
97 lColor = (LONG)m_backgroundColour.GetPixel();
98
99 ::WinSetPresParam( m_hWnd
100 ,PP_BACKGROUNDCOLOR
101 ,sizeof(LONG)
102 ,(PVOID)&lColor
103 );
3c299c3a 104
1f3154c8 105 SubclassWin(m_hWnd);
b720b24d
DW
106 SetFont(*wxSMALL_FONT);
107 SetXComp(0);
108 SetYComp(0);
3c299c3a
DW
109 SetSize( nX
110 ,nY
111 ,nWidth
112 ,nHeight
113 );
114 return TRUE;
1f3154c8 115} // end of wxStaticText::Create
0e320a79 116
e78c4d50 117wxSize wxStaticText::DoGetBestSize() const
0e320a79 118{
1f3154c8
DW
119 wxString sText(wxGetWindowText(GetHWND()));
120 int nWidthTextMax = 0;
121 int nWidthLine = 0;
122 int nHeightTextTotal = 0;
123 int nHeightLineDefault = 0;
124 int nHeightLine = 0;
125 wxString sCurLine;
e94d504d 126 bool bLastWasTilde = FALSE;
1f3154c8 127
3c299c3a 128 for (const wxChar *pc = sText; ; pc++)
1f3154c8
DW
129 {
130 if ( *pc == wxT('\n') || *pc == wxT('\0') )
131 {
132 if (!sCurLine )
133 {
134 //
135 // We can't use GetTextExtent - it will return 0 for both width
e78c4d50
DW
136 // and height and an empty line should count in height
137 // calculation
1f3154c8
DW
138 //
139 if (!nHeightLineDefault)
140 nHeightLineDefault = nHeightLine;
141 if (!nHeightLineDefault)
142 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
143 nHeightTextTotal += nHeightLineDefault;
e78c4d50 144 }
1f3154c8
DW
145 else
146 {
147 GetTextExtent( sCurLine
148 ,&nWidthLine
149 ,&nHeightLine
150 );
151 if (nWidthLine > nWidthTextMax)
152 nWidthTextMax = nWidthLine;
153 nHeightTextTotal += nHeightLine;
e78c4d50 154 }
d90895ac 155
1f3154c8
DW
156 if ( *pc == wxT('\n') )
157 {
158 sCurLine.Empty();
d90895ac 159 }
1f3154c8
DW
160 else
161 {
d90895ac
DW
162 break;
163 }
164 }
1f3154c8
DW
165 else
166 {
6e348b12 167 //
e94d504d 168 // We shouldn't take into account the '~' which just introduces the
6e348b12 169 // mnemonic characters and so are not shown on the screen -- except
e94d504d
SN
170 // when it is preceded by another '~' in which case it stands for a
171 // literal tilde
6e348b12 172 //
e94d504d 173 if (*pc == _T('~'))
6e348b12 174 {
e94d504d 175 if (!bLastWasTilde)
6e348b12 176 {
e94d504d 177 bLastWasTilde = TRUE;
6e348b12
DW
178
179 //
180 // Skip the statement adding pc to curLine below
181 //
182 continue;
183 }
184
185 //
e94d504d 186 // It is a literal tilde
6e348b12 187 //
e94d504d 188 bLastWasTilde = FALSE;
6e348b12 189 }
1f3154c8 190 sCurLine += *pc;
d90895ac
DW
191 }
192 }
1f3154c8
DW
193 return wxSize( nWidthTextMax
194 ,nHeightTextTotal
195 );
196} // end of wxStaticText::DoGetBestSize
197
7993e67c
DW
198void wxStaticText::DoSetSize(
199 int nX
200, int nY
201, int nWidth
202, int nHeight
203, int nSizeFlags
204)
205{
206 //
207 // We need to refresh the window after changing its size as the standard
208 // control doesn't always update itself properly.
209 //
210 wxStaticTextBase::DoSetSize( nX
211 ,nY
212 ,nWidth
213 ,nHeight
214 ,nSizeFlags
215 );
216 Refresh();
217} // end of wxStaticText::DoSetSize
218
3c299c3a
DW
219bool wxStaticText::SetFont(
220 const wxFont& rFont
1f3154c8 221)
0e320a79 222{
3c299c3a 223 bool bRet = wxControl::SetFont(rFont);
1f3154c8
DW
224
225 //
226 // Adjust the size of the window to fit to the label unless autoresizing is
227 // disabled
228 //
3c299c3a 229 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
1f3154c8
DW
230 {
231 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
232 }
3c299c3a
DW
233 return bRet;
234} // end of wxStaticText::SetFont
d90895ac 235
3c299c3a
DW
236void wxStaticText::SetLabel(
237 const wxString& rsLabel
1f3154c8 238)
d90895ac 239{
e94d504d
SN
240 wxString sLabel = ::wxPMTextToLabel(rsLabel);
241 ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str());
1f3154c8
DW
242
243 //
244 // Adjust the size of the window to fit to the label unless autoresizing is
245 // disabled
246 //
3c299c3a 247 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
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