]> git.saurik.com Git - wxWidgets.git/blame - src/os2/gauge.cpp
wxFileCtrl::Update was hiding wxWindow::Update
[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;
46 double dPixelToRange = 0.0;
47 double dRange = 0.0;
48
49 switch (uMessage )
0371a691 50 {
3c299c3a
DW
51 case WM_PAINT:
52 hPS = ::WinBeginPaint( hWnd
53 ,NULLHANDLE
54 ,&vRect
55 );
56 if(hPS)
57 {
58 ::WinQueryWindowRect(hWnd, &vRect);
59 ::GpiCreateLogColorTable( hPS
60 ,0L
61 ,LCOLF_CONSECRGB
62 ,0L
63 ,(LONG)wxTheColourDatabase->m_nSize
64 ,(PLONG)wxTheColourDatabase->m_palTable
65 );
66 ::GpiCreateLogColorTable( hPS
67 ,0L
68 ,LCOLF_RGB
69 ,0L
70 ,0L
71 ,NULL
72 );
73 if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL)
74 {
75 dRange = (double)(vRect.yTop - vRect.yBottom);
76 dPixelToRange = dRange/(double)pGauge->GetRange();
77 vRect2.yTop = (int)(pGauge->GetValue() * dPixelToRange);
78 vRect2.yBottom = vRect.yBottom;
79 vRect2.xLeft = vRect.xLeft;
80 vRect2.xRight = vRect.xRight;
81 vRect.yBottom = vRect2.yTop;
82 ::WinFillRect(hPS, &vRect, pGauge->GetBackgroundColour().GetPixel());
83 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
84 }
85 else
86 {
87 dRange = (double)(vRect.xRight - vRect.xLeft);
88 dPixelToRange = dRange/(double)pGauge->GetRange();
89 vRect2.yTop = vRect.yTop;
90 vRect2.yBottom = vRect.yBottom;
91 vRect2.xLeft = vRect.xLeft;
92 vRect2.xRight = (int)(pGauge->GetValue() * dPixelToRange);
93 vRect.xLeft = vRect2.xRight;
94 ::WinFillRect(hPS, &vRect, pGauge->GetBackgroundColour().GetPixel());
95 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
96 }
97 ::WinEndPaint(hPS);
98 }
0371a691 99 }
3c299c3a
DW
100 return (fnWndProcGauge( hWnd
101 ,(ULONG)uMessage
102 ,(MPARAM)wParam
103 ,(MPARAM)lParam
104 )
105 );
106} // end of wxGaugeWndProc
107
108bool wxGauge::Create(
109 wxWindowOS2* pParent
110, wxWindowID vId
111, int nRange
112, const wxPoint& rPos
113, const wxSize& rSize
114, long lStyle
115#if wxUSE_VALIDATORS
116, const wxValidator& rValidator
117#endif
118, const wxString& rsName
119)
120{
121 int nX = rPos.x;
122 int nY = rPos.y;
123 int nWidth = rSize.x;
124 int nHeight = rSize.y;
125 long lMsStyle = 0L;
d8a3f66c 126 SWP vSwp;
0371a691 127
3c299c3a 128 SetName(rsName);
5d4b632b 129#if wxUSE_VALIDATORS
3c299c3a 130 SetValidator(rValidator);
5d4b632b 131#endif
3c299c3a
DW
132 if (pParent)
133 pParent->AddChild(this);
134 SetBackgroundColour(pParent->GetBackgroundColour()) ;
135 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 136
3c299c3a
DW
137 m_nRangeMax = nRange;
138 m_nGaugePos = 0;
139 m_windowStyle = lStyle;
0e320a79 140
3c299c3a
DW
141 if (vId == -1)
142 m_windowId = (int)NewControlId();
0e320a79 143 else
3c299c3a
DW
144 m_windowId = vId;
145
146 if (m_windowStyle & wxCLIP_SIBLINGS )
147 lMsStyle |= WS_CLIPSIBLINGS;
148
149 //
150 // OS/2 will use an edit control for this, since there is not a native gauge
151 // Other choices include using an armless slider but they are more difficult
152 // to control and manipulate
153 //
154
155 lMsStyle = WS_VISIBLE | ES_MARGIN | ES_LEFT | ES_READONLY;
156 if (m_windowStyle & wxCLIP_SIBLINGS)
157 lMsStyle |= WS_CLIPSIBLINGS;
158
5d44b24e
DW
159 //
160 // If the parent is a scrolled window the controls must
161 // have this style or they will overlap the scrollbars
162 //
163 if (pParent)
164 if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) ||
165 pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)))
166 lMsStyle |= WS_CLIPSIBLINGS;
3c299c3a
DW
167
168 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
169 ,WC_ENTRYFIELD // Window class
170 ,(PSZ)NULL // Initial Text
171 ,(ULONG)lMsStyle // Style flags
172 ,0L, 0L, 0L, 0L // Origin -- 0 size
173 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
174 ,HWND_TOP // initial z position
175 ,(HMENU)m_windowId // Window identifier
176 ,NULL // Slider control data
177 ,NULL // no Presentation parameters
178 );
179
180 wxAssociateWinWithHandle( m_hWnd
181 ,(wxWindowOS2*)this
182 );
183 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
184 fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc);
d8a3f66c
DW
185 ::WinQueryWindowPos(m_hWnd, &vSwp);
186 SetXComp(vSwp.x);
187 SetYComp(vSwp.y);
3c299c3a
DW
188 SetFont(pParent->GetFont());
189 if (nWidth == -1L)
190 nWidth = 50L;
191 if (nHeight == -1L)
192 nHeight = 28L;
193 SetSize( nX
194 ,nY
195 ,nWidth
196 ,nHeight
197 );
198 ::WinShowWindow((HWND)GetHWND(), TRUE);
199 return TRUE;
200} // end of wxGauge::Create
0e320a79 201
3c299c3a 202int wxGauge::GetBezelFace() const
0e320a79 203{
3c299c3a
DW
204 return 0;
205} // end of wxGauge::GetBezelFace
0e320a79 206
3c299c3a 207int wxGauge::GetRange() const
0e320a79 208{
3c299c3a
DW
209 return m_nRangeMax;
210} // end of wxGauge::GetRange
0e320a79
DW
211
212int wxGauge::GetShadowWidth() const
213{
0e320a79 214 return 0;
3c299c3a 215} // end of wxGauge::GetShadowWidth
0e320a79
DW
216
217int wxGauge::GetValue() const
218{
3c299c3a
DW
219 return m_nGaugePos;
220} // end of wxGauge::GetValue
0e320a79 221
3c299c3a
DW
222bool wxGauge::SetBackgroundColour(
223 const wxColour& rColour
224)
0371a691 225{
3c299c3a 226 if (!wxControl::SetBackgroundColour(rColour))
0371a691
DW
227 return FALSE;
228
3c299c3a 229 LONG lColor = (LONG)rColour.GetPixel();
0371a691 230
3c299c3a
DW
231 ::WinSetPresParam( GetHwnd()
232 ,PP_BACKGROUNDCOLOR
233 ,sizeof(LONG)
234 ,(PVOID)&lColor
235 );
0371a691 236 return TRUE;
3c299c3a 237} // end of wxGauge::SetBackgroundColour
0371a691 238
3c299c3a
DW
239void wxGauge::SetBezelFace(
240 int WXUNUSED(nWidth)
241)
0371a691 242{
3c299c3a 243} // end of wxGauge::SetBezelFace
0371a691 244
3c299c3a
DW
245bool wxGauge::SetForegroundColour(
246 const wxColour& rColour
247)
248{
249 if (!wxControl::SetForegroundColour(rColour))
250 return FALSE;
0371a691 251
3c299c3a 252 LONG lColor = (LONG)rColour.GetPixel();
0371a691 253
3c299c3a
DW
254 ::WinSetPresParam( GetHwnd()
255 ,PP_FOREGROUNDCOLOR
256 ,sizeof(LONG)
257 ,(PVOID)&lColor
258 );
0371a691 259
3c299c3a
DW
260 return TRUE;
261} // end of wxGauge::SetForegroundColour
0371a691 262
3c299c3a
DW
263void wxGauge::SetRange(
264 int nRange
265)
266{
267 m_nRangeMax = nRange;
268} // end of wxGauge::SetRange
0371a691 269
3c299c3a
DW
270void wxGauge::SetShadowWidth(
271 int WXUNUSED(nWidth)
272)
273{
274} // end of wxGauge::SetShadowWidth
0371a691 275
3c299c3a
DW
276void wxGauge::SetValue(
277 int nPos
278)
279{
280 RECT vRect;
0371a691 281
3c299c3a
DW
282 m_nGaugePos = nPos;
283 ::WinQueryWindowRect(GetHwnd(), &vRect);
284 ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
285} // end of wxGauge::SetValue
0371a691
DW
286
287