]> git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
docopydocs is not needed for this script.
[wxWidgets.git] / src / os2 / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/gauge.cpp
3 // Purpose: wxGauge class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/06/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifndef WX_PRECOMP
15 #include "wx/utils.h"
16 #include "wx/scrolwin.h"
17 #endif
18
19 #include "wx/os2/private.h"
20 #include "wx/gauge.h"
21
22 static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL;
23 extern void wxAssociateWinWithHandle( HWND hWnd
24 ,wxWindowOS2* pWin
25 );
26
27 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
28
29 MRESULT EXPENTRY wxGaugeWndProc(
30 HWND hWnd
31 , UINT uMessage
32 , MPARAM wParam
33 , MPARAM lParam
34 )
35 {
36 wxGauge* pGauge = (wxGauge *)::WinQueryWindowULong( hWnd
37 ,QWL_USER
38 );
39 HPS hPS;
40 RECTL vRect;
41 RECTL vRect2;
42 RECTL vRect3;
43 double dPixelToRange = 0.0;
44 double dRange = 0.0;
45
46 switch (uMessage )
47 {
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 );
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
93 if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL)
94 {
95 dRange = (double)(vRect3.yTop - vRect3.yBottom);
96 dPixelToRange = dRange/(double)pGauge->GetRange();
97 vRect2.yTop = (int)(pGauge->GetValue() * dPixelToRange);
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());
105 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
106 }
107 else
108 {
109 dRange = (double)(vRect3.xRight - vRect3.xLeft);
110 dPixelToRange = dRange/(double)pGauge->GetRange();
111 vRect2.yTop = vRect3.yTop;
112 vRect2.yBottom = vRect3.yBottom;
113 vRect2.xLeft = vRect3.xLeft;
114 vRect2.xRight = (int)(pGauge->GetValue() * dPixelToRange);
115 vRect3.xLeft = vRect2.xRight;
116 if (vRect3.xLeft <= 1)
117 vRect3.xLeft = 2;
118 ::WinFillRect(hPS, &vRect3, pGauge->GetBackgroundColour().GetPixel());
119 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
120 }
121 ::WinEndPaint(hPS);
122 }
123 }
124 return (fnWndProcGauge( hWnd
125 ,(ULONG)uMessage
126 ,(MPARAM)wParam
127 ,(MPARAM)lParam
128 )
129 );
130 } // end of wxGaugeWndProc
131
132 bool wxGauge::Create(
133 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
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;
148 SWP vSwp;
149
150 SetName(rsName);
151 #if wxUSE_VALIDATORS
152 SetValidator(rValidator);
153 #endif
154 if (pParent)
155 pParent->AddChild(this);
156 m_backgroundColour.Set(wxString(wxT("LIGHT GREY")));
157 m_foregroundColour.Set(wxString(wxT("NAVY")));
158
159 m_nRangeMax = nRange;
160 m_nGaugePos = 0;
161 m_windowStyle = lStyle;
162
163 if (vId == -1)
164 m_windowId = (int)NewControlId();
165 else
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
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);
198 ::WinQueryWindowPos(m_hWnd, &vSwp);
199 SetXComp(vSwp.x);
200 SetYComp(vSwp.y);
201 wxFont* pTextFont = new wxFont( 10
202 ,wxMODERN
203 ,wxNORMAL
204 ,wxNORMAL
205 );
206 SetFont(*pTextFont);
207 if (nWidth == -1L)
208 nWidth = 50L;
209 if (nHeight == -1L)
210 nHeight = 28L;
211 SetSize( nX
212 ,nY
213 ,nWidth
214 ,nHeight
215 );
216 m_nWidth = nWidth; // Save for GetBestSize
217 m_nHeight = nHeight;
218 ::WinShowWindow((HWND)GetHWND(), TRUE);
219 delete pTextFont;
220 return TRUE;
221 } // end of wxGauge::Create
222
223 int wxGauge::GetBezelFace() const
224 {
225 return 0;
226 } // end of wxGauge::GetBezelFace
227
228 int wxGauge::GetRange() const
229 {
230 return m_nRangeMax;
231 } // end of wxGauge::GetRange
232
233 int wxGauge::GetShadowWidth() const
234 {
235 return 0;
236 } // end of wxGauge::GetShadowWidth
237
238 int wxGauge::GetValue() const
239 {
240 return m_nGaugePos;
241 } // end of wxGauge::GetValue
242
243 bool wxGauge::SetBackgroundColour( const wxColour& rColour )
244 {
245 if (!wxControl::SetBackgroundColour(rColour))
246 return false;
247
248 LONG lColor = (LONG)rColour.GetPixel();
249
250 ::WinSetPresParam( GetHwnd()
251 ,PP_BACKGROUNDCOLOR
252 ,sizeof(LONG)
253 ,(PVOID)&lColor
254 );
255 return true;
256 } // end of wxGauge::SetBackgroundColour
257
258 void wxGauge::SetBezelFace(
259 int WXUNUSED(nWidth)
260 )
261 {
262 } // end of wxGauge::SetBezelFace
263
264 bool wxGauge::SetForegroundColour( const wxColour& rColour )
265 {
266 if (!wxControl::SetForegroundColour(rColour))
267 return false;
268
269 LONG lColor = (LONG)rColour.GetPixel();
270
271 ::WinSetPresParam( GetHwnd()
272 ,PP_FOREGROUNDCOLOR
273 ,sizeof(LONG)
274 ,(PVOID)&lColor
275 );
276
277 return true;
278 } // end of wxGauge::SetForegroundColour
279
280 void wxGauge::SetRange(
281 int nRange
282 )
283 {
284 m_nRangeMax = nRange;
285 } // end of wxGauge::SetRange
286
287 void wxGauge::SetShadowWidth(
288 int WXUNUSED(nWidth)
289 )
290 {
291 } // end of wxGauge::SetShadowWidth
292
293 void wxGauge::SetValue(
294 int nPos
295 )
296 {
297 RECT vRect;
298
299 m_nGaugePos = nPos;
300 ::WinQueryWindowRect(GetHwnd(), &vRect);
301 ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
302 } // end of wxGauge::SetValue
303
304 wxSize wxGauge::DoGetBestSize() const
305 {
306 return wxSize(m_nWidth,m_nHeight);
307 }