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