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