]> git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
Replaced wcslen with wxWcslen
[wxWidgets.git] / src / os2 / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gauge.cpp
3 // Purpose: wxGauge class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/06/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifndef WX_PRECOMP
15 #include "wx/defs.h"
16 #include "wx/utils.h"
17 #include "wx/scrolwin.h"
18 #endif
19
20 #include "wx/os2/private.h"
21 #include "wx/gauge.h"
22
23 static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL;
24 extern void wxAssociateWinWithHandle( HWND hWnd
25 ,wxWindowOS2* pWin
26 );
27
28 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
29
30 MRESULT EXPENTRY wxGaugeWndProc(
31 HWND hWnd
32 , UINT uMessage
33 , MPARAM wParam
34 , MPARAM lParam
35 )
36 {
37 wxGauge* pGauge = (wxGauge *)::WinQueryWindowULong( hWnd
38 ,QWL_USER
39 );
40 wxWindowOS2* pWindow = NULL;
41 MRESULT rc = (MRESULT)0;
42 bool bProcessed = FALSE;
43 HPS hPS;
44 RECTL vRect;
45 RECTL vRect2;
46 RECTL vRect3;
47 double dPixelToRange = 0.0;
48 double dRange = 0.0;
49
50 switch (uMessage )
51 {
52 case WM_PAINT:
53 hPS = ::WinBeginPaint( hWnd
54 ,NULLHANDLE
55 ,&vRect
56 );
57 if(hPS)
58 {
59 ::WinQueryWindowRect(hWnd, &vRect);
60 ::GpiCreateLogColorTable( hPS
61 ,0L
62 ,LCOLF_CONSECRGB
63 ,0L
64 ,(LONG)wxTheColourDatabase->m_nSize
65 ,(PLONG)wxTheColourDatabase->m_palTable
66 );
67 ::GpiCreateLogColorTable( hPS
68 ,0L
69 ,LCOLF_RGB
70 ,0L
71 ,0L
72 ,NULL
73 );
74 //
75 // Draw the guage box
76 //
77 LONG lColor = 0x00FFFFFF; // White
78 POINTL vPoint = {vRect.xLeft + 1, vRect.yBottom + 1};
79
80 ::GpiSetColor(hPS, lColor);
81 ::GpiMove(hPS, &vPoint);
82 vPoint.x = vRect.xRight - 1;
83 ::GpiLine(hPS, &vPoint);
84 vPoint.y = vRect.yTop - 1;
85 ::GpiLine(hPS, &vPoint);
86 lColor = 0x000C0C0C; // Darkish Grey to give depth feel
87 ::GpiSetColor(hPS, lColor);
88 vPoint.x = vRect.xLeft + 1;
89 ::GpiLine(hPS, &vPoint);
90 vPoint.y = vRect.yBottom + 1;
91 ::GpiLine(hPS, &vPoint);
92 vRect3.xLeft = vRect.xLeft + 2;
93 vRect3.xRight = vRect.xRight - 2;
94 vRect3.yTop = vRect.yTop - 2;
95 vRect3.yBottom = vRect.yBottom + 2;
96
97 if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL)
98 {
99 dRange = (double)(vRect3.yTop - vRect3.yBottom);
100 dPixelToRange = dRange/(double)pGauge->GetRange();
101 vRect2.yTop = (int)(pGauge->GetValue() * dPixelToRange);
102 vRect2.yBottom = vRect3.yBottom;
103 vRect2.xLeft = vRect3.xLeft;
104 vRect2.xRight = vRect3.xRight;
105 vRect3.yBottom = vRect2.yTop;
106 if (vRect3.yBottom <= 1)
107 vRect3.yBottom = 2;
108 ::WinFillRect(hPS, &vRect3, pGauge->GetBackgroundColour().GetPixel());
109 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
110 }
111 else
112 {
113 dRange = (double)(vRect3.xRight - vRect3.xLeft);
114 dPixelToRange = dRange/(double)pGauge->GetRange();
115 vRect2.yTop = vRect3.yTop;
116 vRect2.yBottom = vRect3.yBottom;
117 vRect2.xLeft = vRect3.xLeft;
118 vRect2.xRight = (int)(pGauge->GetValue() * dPixelToRange);
119 vRect3.xLeft = vRect2.xRight;
120 if (vRect3.xLeft <= 1)
121 vRect3.xLeft = 2;
122 ::WinFillRect(hPS, &vRect3, pGauge->GetBackgroundColour().GetPixel());
123 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
124 }
125 ::WinEndPaint(hPS);
126 }
127 }
128 return (fnWndProcGauge( hWnd
129 ,(ULONG)uMessage
130 ,(MPARAM)wParam
131 ,(MPARAM)lParam
132 )
133 );
134 } // end of wxGaugeWndProc
135
136 bool wxGauge::Create(
137 wxWindowOS2* pParent
138 , wxWindowID vId
139 , int nRange
140 , const wxPoint& rPos
141 , const wxSize& rSize
142 , long lStyle
143 #if wxUSE_VALIDATORS
144 , const wxValidator& rValidator
145 #endif
146 , const wxString& rsName
147 )
148 {
149 int nX = rPos.x;
150 int nY = rPos.y;
151 int nWidth = rSize.x;
152 int nHeight = rSize.y;
153 long lMsStyle = 0L;
154 SWP vSwp;
155
156 SetName(rsName);
157 #if wxUSE_VALIDATORS
158 SetValidator(rValidator);
159 #endif
160 if (pParent)
161 pParent->AddChild(this);
162 m_backgroundColour.Set(wxString("LIGHT GREY"));
163 m_foregroundColour.Set(wxString("NAVY"));
164
165 m_nRangeMax = nRange;
166 m_nGaugePos = 0;
167 m_windowStyle = lStyle;
168
169 if (vId == -1)
170 m_windowId = (int)NewControlId();
171 else
172 m_windowId = vId;
173
174 if (m_windowStyle & wxCLIP_SIBLINGS )
175 lMsStyle |= WS_CLIPSIBLINGS;
176
177 //
178 // OS/2 will use an edit control for this, since there is not a native gauge
179 // Other choices include using an armless slider but they are more difficult
180 // to control and manipulate
181 //
182
183 lMsStyle = WS_VISIBLE | ES_MARGIN | ES_LEFT | ES_READONLY;
184 if (m_windowStyle & wxCLIP_SIBLINGS)
185 lMsStyle |= WS_CLIPSIBLINGS;
186
187 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
188 ,WC_ENTRYFIELD // Window class
189 ,(PSZ)NULL // Initial Text
190 ,(ULONG)lMsStyle // Style flags
191 ,0L, 0L, 0L, 0L // Origin -- 0 size
192 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
193 ,HWND_TOP // initial z position
194 ,(HMENU)m_windowId // Window identifier
195 ,NULL // Slider control data
196 ,NULL // no Presentation parameters
197 );
198
199 wxAssociateWinWithHandle( m_hWnd
200 ,(wxWindowOS2*)this
201 );
202 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
203 fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc);
204 ::WinQueryWindowPos(m_hWnd, &vSwp);
205 SetXComp(vSwp.x);
206 SetYComp(vSwp.y);
207 wxFont* pTextFont = new wxFont( 10
208 ,wxMODERN
209 ,wxNORMAL
210 ,wxNORMAL
211 );
212 SetFont(*pTextFont);
213 if (nWidth == -1L)
214 nWidth = 50L;
215 if (nHeight == -1L)
216 nHeight = 28L;
217 SetSize( nX
218 ,nY
219 ,nWidth
220 ,nHeight
221 );
222 ::WinShowWindow((HWND)GetHWND(), TRUE);
223 delete pTextFont;
224 return TRUE;
225 } // end of wxGauge::Create
226
227 int wxGauge::GetBezelFace() const
228 {
229 return 0;
230 } // end of wxGauge::GetBezelFace
231
232 int wxGauge::GetRange() const
233 {
234 return m_nRangeMax;
235 } // end of wxGauge::GetRange
236
237 int wxGauge::GetShadowWidth() const
238 {
239 return 0;
240 } // end of wxGauge::GetShadowWidth
241
242 int wxGauge::GetValue() const
243 {
244 return m_nGaugePos;
245 } // end of wxGauge::GetValue
246
247 bool wxGauge::SetBackgroundColour(
248 const wxColour& rColour
249 )
250 {
251 if (!wxControl::SetBackgroundColour(rColour))
252 return FALSE;
253
254 LONG lColor = (LONG)rColour.GetPixel();
255
256 ::WinSetPresParam( GetHwnd()
257 ,PP_BACKGROUNDCOLOR
258 ,sizeof(LONG)
259 ,(PVOID)&lColor
260 );
261 return TRUE;
262 } // end of wxGauge::SetBackgroundColour
263
264 void wxGauge::SetBezelFace(
265 int WXUNUSED(nWidth)
266 )
267 {
268 } // end of wxGauge::SetBezelFace
269
270 bool wxGauge::SetForegroundColour(
271 const wxColour& rColour
272 )
273 {
274 if (!wxControl::SetForegroundColour(rColour))
275 return FALSE;
276
277 LONG lColor = (LONG)rColour.GetPixel();
278
279 ::WinSetPresParam( GetHwnd()
280 ,PP_FOREGROUNDCOLOR
281 ,sizeof(LONG)
282 ,(PVOID)&lColor
283 );
284
285 return TRUE;
286 } // end of wxGauge::SetForegroundColour
287
288 void wxGauge::SetRange(
289 int nRange
290 )
291 {
292 m_nRangeMax = nRange;
293 } // end of wxGauge::SetRange
294
295 void wxGauge::SetShadowWidth(
296 int WXUNUSED(nWidth)
297 )
298 {
299 } // end of wxGauge::SetShadowWidth
300
301 void wxGauge::SetValue(
302 int nPos
303 )
304 {
305 RECT vRect;
306
307 m_nGaugePos = nPos;
308 ::WinQueryWindowRect(GetHwnd(), &vRect);
309 ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
310 } // end of wxGauge::SetValue
311
312