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