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