Added add_queue/remove_queue to server object operations.
[wine/testsucceed.git] / dlls / comctl32 / progress.c
blobc7049680521c56e3b58443cd7f4e2734cbb5dfa2
1 /*
2 * Progress control
4 * Copyright 1997 Dimitrie O. Paun
6 * TODO:
7 * - I do not know what to to on WM_[SG]ET_FONT
8 */
10 #include "windows.h"
11 #include "commctrl.h"
12 #include "progress.h"
13 #include "win.h"
14 #include "debug.h"
17 /* Control configuration constants */
19 #define LED_GAP 2
21 /* Work constants */
23 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(progress, \
24 "Unknown parameter(s) for message " #msg \
25 "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
27 #define PROGRESS_GetInfoPtr(wndPtr) ((PROGRESS_INFO *)wndPtr->wExtra[0])
30 /***********************************************************************
31 * PROGRESS_Draw
32 * Draws the progress bar.
34 static void
35 PROGRESS_Draw (WND *wndPtr, HDC32 hdc)
37 PROGRESS_INFO *infoPtr = PROGRESS_GetInfoPtr(wndPtr);
38 HBRUSH32 hbrBar, hbrBk;
39 int rightBar, rightMost, ledWidth;
40 RECT32 rect;
42 TRACE(progress, "refresh pos=%d min=%d, max=%d\n",
43 infoPtr->CurVal, infoPtr->MinVal, infoPtr->MaxVal);
45 /* get the required bar brush */
46 if (infoPtr->ColorBar == CLR_DEFAULT)
47 hbrBar = GetSysColorBrush32(COLOR_HIGHLIGHT);
48 else
49 hbrBar = CreateSolidBrush32 (infoPtr->ColorBar);
51 /* get the required background brush */
52 if (infoPtr->ColorBk == CLR_DEFAULT)
53 hbrBk = GetSysColorBrush32 (COLOR_3DFACE);
54 else
55 hbrBk = CreateSolidBrush32 (infoPtr->ColorBk);
57 /* get client rectangle */
58 GetClientRect32 (wndPtr->hwndSelf, &rect);
60 /* draw the background */
61 FillRect32(hdc, &rect, hbrBk);
63 rect.left++; rect.right--; rect.top++; rect.bottom--;
65 /* compute extent of progress bar */
66 if (wndPtr->dwStyle & PBS_VERTICAL)
68 rightBar = rect.bottom -
69 MulDiv32(infoPtr->CurVal-infoPtr->MinVal,
70 rect.bottom - rect.top,
71 infoPtr->MaxVal-infoPtr->MinVal);
72 ledWidth = MulDiv32 ((rect.right - rect.left), 2, 3);
73 rightMost = rect.top;
75 else
77 rightBar = rect.left +
78 MulDiv32(infoPtr->CurVal-infoPtr->MinVal,
79 rect.right - rect.left,
80 infoPtr->MaxVal-infoPtr->MinVal);
81 ledWidth = MulDiv32 ((rect.bottom - rect.top), 2, 3);
82 rightMost = rect.right;
85 /* now draw the bar */
86 if (wndPtr->dwStyle & PBS_SMOOTH)
88 if (wndPtr->dwStyle & PBS_VERTICAL)
89 rect.top = rightBar;
90 else
91 rect.right = rightBar;
92 FillRect32(hdc, &rect, hbrBar);
94 else
96 if (wndPtr->dwStyle & PBS_VERTICAL)
97 while(rect.bottom > rightBar) {
98 rect.top = rect.bottom-ledWidth;
99 if (rect.top < rightMost)
100 rect.top = rightMost;
101 FillRect32(hdc, &rect, hbrBar);
102 rect.bottom = rect.top-LED_GAP;
104 else
105 while(rect.left < rightBar) {
106 rect.right = rect.left+ledWidth;
107 if (rect.right > rightMost)
108 rect.right = rightMost;
109 FillRect32(hdc, &rect, hbrBar);
110 rect.left = rect.right+LED_GAP;
114 /* delete bar brush */
115 if (infoPtr->ColorBar != CLR_DEFAULT)
116 DeleteObject32 (hbrBar);
118 /* delete background brush */
119 if (infoPtr->ColorBk != CLR_DEFAULT)
120 DeleteObject32 (hbrBk);
123 /***********************************************************************
124 * PROGRESS_Refresh
125 * Draw the progress bar. The background need not be erased.
127 static void
128 PROGRESS_Refresh (WND *wndPtr)
130 HDC32 hdc;
132 hdc = GetDC32 (wndPtr->hwndSelf);
133 PROGRESS_Draw (wndPtr, hdc);
134 ReleaseDC32 (wndPtr->hwndSelf, hdc);
137 /***********************************************************************
138 * PROGRESS_Paint
139 * Draw the progress bar. The background need not be erased.
140 * If dc!=0, it draws on it
142 static void
143 PROGRESS_Paint (WND *wndPtr)
145 PAINTSTRUCT32 ps;
146 HDC32 hdc;
148 hdc = BeginPaint32 (wndPtr->hwndSelf, &ps);
149 PROGRESS_Draw (wndPtr, hdc);
150 EndPaint32 (wndPtr->hwndSelf, &ps);
154 /***********************************************************************
155 * PROGRESS_CoercePos
156 * Makes sure the current position (CUrVal) is within bounds.
158 static void PROGRESS_CoercePos(WND *wndPtr)
160 PROGRESS_INFO *infoPtr = PROGRESS_GetInfoPtr(wndPtr);
162 if(infoPtr->CurVal < infoPtr->MinVal)
163 infoPtr->CurVal = infoPtr->MinVal;
164 if(infoPtr->CurVal > infoPtr->MaxVal)
165 infoPtr->CurVal = infoPtr->MaxVal;
168 /***********************************************************************
169 * ProgressWindowProc
171 LRESULT WINAPI ProgressWindowProc(HWND32 hwnd, UINT32 message,
172 WPARAM32 wParam, LPARAM lParam)
174 WND *wndPtr = WIN_FindWndPtr(hwnd);
175 PROGRESS_INFO *infoPtr = PROGRESS_GetInfoPtr(wndPtr);
176 UINT32 temp;
178 switch(message)
180 case WM_NCCREATE:
181 wndPtr->dwExStyle |= WS_EX_STATICEDGE;
182 return TRUE;
184 case WM_CREATE:
185 /* allocate memory for info struct */
186 infoPtr =
187 (PROGRESS_INFO *)COMCTL32_Alloc (sizeof(PROGRESS_INFO));
188 wndPtr->wExtra[0] = (DWORD)infoPtr;
190 /* initialize the info struct */
191 infoPtr->MinVal=0;
192 infoPtr->MaxVal=100;
193 infoPtr->CurVal=0;
194 infoPtr->Step=10;
195 infoPtr->ColorBar=CLR_DEFAULT;
196 infoPtr->ColorBk=CLR_DEFAULT;
197 TRACE(progress, "Progress Ctrl creation, hwnd=%04x\n", hwnd);
198 break;
200 case WM_DESTROY:
201 TRACE (progress, "Progress Ctrl destruction, hwnd=%04x\n", hwnd);
202 COMCTL32_Free (infoPtr);
203 break;
205 case WM_ERASEBKGND:
206 /* pretend to erase it here, but we will do it in the paint
207 function to avoid flicker */
208 return 1;
210 case WM_GETFONT:
211 FIXME (progress, "WM_GETFONT - empty message!\n");
212 /* FIXME: What do we need to do? */
213 break;
215 case WM_SETFONT:
216 FIXME (progress, "WM_SETFONT - empty message!\n");
217 /* FIXME: What do we need to do? */
218 break;
220 case WM_PAINT:
221 PROGRESS_Paint (wndPtr);
222 break;
224 case PBM_DELTAPOS:
225 if(lParam)
226 UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam);
227 temp = infoPtr->CurVal;
228 if(wParam != 0){
229 infoPtr->CurVal += (UINT16)wParam;
230 PROGRESS_CoercePos(wndPtr);
231 PROGRESS_Refresh (wndPtr);
233 return temp;
235 case PBM_SETPOS:
236 if (lParam)
237 UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam);
238 temp = infoPtr->CurVal;
239 if(temp != wParam){
240 infoPtr->CurVal = (UINT16)wParam;
241 PROGRESS_CoercePos(wndPtr);
242 PROGRESS_Refresh (wndPtr);
244 return temp;
246 case PBM_SETRANGE:
247 if (wParam)
248 UNKNOWN_PARAM(PBM_SETRANGE, wParam, lParam);
249 temp = MAKELONG(infoPtr->MinVal, infoPtr->MaxVal);
250 if(temp != lParam){
251 infoPtr->MinVal = LOWORD(lParam);
252 infoPtr->MaxVal = HIWORD(lParam);
253 if(infoPtr->MaxVal <= infoPtr->MinVal)
254 infoPtr->MaxVal = infoPtr->MinVal+1;
255 PROGRESS_CoercePos(wndPtr);
256 PROGRESS_Refresh (wndPtr);
258 return temp;
260 case PBM_SETSTEP:
261 if (lParam)
262 UNKNOWN_PARAM(PBM_SETSTEP, wParam, lParam);
263 temp = infoPtr->Step;
264 infoPtr->Step = (UINT16)wParam;
265 return temp;
267 case PBM_STEPIT:
268 if (wParam || lParam)
269 UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);
270 temp = infoPtr->CurVal;
271 infoPtr->CurVal += infoPtr->Step;
272 if(infoPtr->CurVal > infoPtr->MaxVal)
273 infoPtr->CurVal = infoPtr->MinVal;
274 if(temp != infoPtr->CurVal)
275 PROGRESS_Refresh (wndPtr);
276 return temp;
278 case PBM_SETRANGE32:
279 temp = MAKELONG(infoPtr->MinVal, infoPtr->MaxVal);
280 if((infoPtr->MinVal != (INT32)wParam) ||
281 (infoPtr->MaxVal != (INT32)lParam)) {
282 infoPtr->MinVal = (INT32)wParam;
283 infoPtr->MaxVal = (INT32)lParam;
284 if(infoPtr->MaxVal <= infoPtr->MinVal)
285 infoPtr->MaxVal = infoPtr->MinVal+1;
286 PROGRESS_CoercePos(wndPtr);
287 PROGRESS_Refresh (wndPtr);
289 return temp;
291 case PBM_GETRANGE:
292 if (lParam){
293 ((PPBRANGE)lParam)->iLow = infoPtr->MinVal;
294 ((PPBRANGE)lParam)->iHigh = infoPtr->MaxVal;
296 return (wParam) ? infoPtr->MinVal : infoPtr->MaxVal;
298 case PBM_GETPOS:
299 if (wParam || lParam)
300 UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);
301 return (infoPtr->CurVal);
303 case PBM_SETBARCOLOR:
304 if (wParam)
305 UNKNOWN_PARAM(PBM_SETBARCOLOR, wParam, lParam);
306 infoPtr->ColorBar = (COLORREF)lParam;
307 PROGRESS_Refresh (wndPtr);
308 break;
310 case PBM_SETBKCOLOR:
311 if (wParam)
312 UNKNOWN_PARAM(PBM_SETBKCOLOR, wParam, lParam);
313 infoPtr->ColorBk = (COLORREF)lParam;
314 PROGRESS_Refresh (wndPtr);
315 break;
317 default:
318 if (message >= WM_USER)
319 ERR(progress, "unknown msg %04x wp=%04x lp=%08lx\n",
320 message, wParam, lParam );
321 return DefWindowProc32A( hwnd, message, wParam, lParam );
324 return 0;
328 /***********************************************************************
329 * PROGRESS_Register [Internal]
331 * Registers the progress bar window class.
334 VOID
335 PROGRESS_Register (VOID)
337 WNDCLASS32A wndClass;
339 if (GlobalFindAtom32A (PROGRESS_CLASS32A)) return;
341 ZeroMemory (&wndClass, sizeof( WNDCLASS32A));
342 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
343 wndClass.lpfnWndProc = (WNDPROC32)ProgressWindowProc;
344 wndClass.cbClsExtra = 0;
345 wndClass.cbWndExtra = sizeof (PROGRESS_INFO *);
346 wndClass.hCursor = LoadCursor32A (0, IDC_ARROW32A);
347 wndClass.lpszClassName = PROGRESS_CLASS32A;
349 RegisterClass32A (&wndClass);
353 /***********************************************************************
354 * PROGRESS_Unregister [Internal]
356 * Unregisters the progress bar window class.
359 VOID
360 PROGRESS_Unregister (VOID)
362 if (GlobalFindAtom32A (PROGRESS_CLASS32A))
363 UnregisterClass32A (PROGRESS_CLASS32A, (HINSTANCE32)NULL);