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