[COMCTL32]
[reactos.git] / reactos / dll / win32 / comctl32 / progress.c
1 /*
2 * Progress control
3 *
4 * Copyright 1997, 2002 Dimitrie O. Paun
5 * Copyright 1998, 1999 Eric Kohl
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * NOTE
22 *
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 9, 2002, by Dimitrie O. Paun.
25 *
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
29 *
30 * TODO:
31 *
32 * Styles:
33 * -- PBS_SMOOTHREVERSE
34 *
35 */
36
37 #include "comctl32.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(progress);
40
41 typedef struct
42 {
43 HWND Self; /* The window handle for this control */
44 INT CurVal; /* Current progress value */
45 INT MinVal; /* Minimum progress value */
46 INT MaxVal; /* Maximum progress value */
47 INT Step; /* Step to use on PMB_STEPIT */
48 INT MarqueePos; /* Marquee animation position */
49 BOOL Marquee; /* Whether the marquee animation is enabled */
50 COLORREF ColorBar; /* Bar color */
51 COLORREF ColorBk; /* Background color */
52 HFONT Font; /* Handle to font (not unused) */
53 } PROGRESS_INFO;
54
55 /* Control configuration constants */
56
57 #define LED_GAP 2
58 #define MARQUEE_LEDS 5
59 #define ID_MARQUEE_TIMER 1
60 #define DEFAULT_MARQUEE_PERIOD 30
61
62 /* Helper to obtain size of a progress bar chunk ("led"). */
63 static inline int get_led_size ( const PROGRESS_INFO *infoPtr, LONG style,
64 const RECT* rect )
65 {
66 HTHEME theme = GetWindowTheme (infoPtr->Self);
67 if (theme)
68 {
69 int chunkSize;
70 if (SUCCEEDED( GetThemeInt( theme, 0, 0, TMT_PROGRESSCHUNKSIZE, &chunkSize )))
71 return chunkSize;
72 }
73
74 if (style & PBS_VERTICAL)
75 return MulDiv (rect->right - rect->left, 2, 3);
76 else
77 return MulDiv (rect->bottom - rect->top, 2, 3);
78 }
79
80 /* Helper to obtain gap between progress bar chunks */
81 static inline int get_led_gap ( const PROGRESS_INFO *infoPtr )
82 {
83 HTHEME theme = GetWindowTheme (infoPtr->Self);
84 if (theme)
85 {
86 int spaceSize;
87 if (SUCCEEDED( GetThemeInt( theme, 0, 0, TMT_PROGRESSSPACESIZE, &spaceSize )))
88 return spaceSize;
89 }
90
91 return LED_GAP;
92 }
93
94 /* Get client rect. Takes into account that theming needs no adjustment. */
95 static inline void get_client_rect (HWND hwnd, RECT* rect)
96 {
97 HTHEME theme = GetWindowTheme (hwnd);
98 GetClientRect (hwnd, rect);
99 if (!theme)
100 InflateRect(rect, -1, -1);
101 else
102 {
103 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
104 int part = (dwStyle & PBS_VERTICAL) ? PP_BARVERT : PP_BAR;
105 GetThemeBackgroundContentRect (theme, 0, part, 0, rect, rect);
106 }
107 }
108
109 /* Compute the extend of the bar */
110 static inline int get_bar_size( LONG style, const RECT* rect )
111 {
112 if (style & PBS_VERTICAL)
113 return rect->bottom - rect->top;
114 else
115 return rect->right - rect->left;
116 }
117
118 /* Compute the pixel position of a progress value */
119 static inline int get_bar_position( const PROGRESS_INFO *infoPtr, LONG style,
120 const RECT* rect, INT value )
121 {
122 return MulDiv (value - infoPtr->MinVal, get_bar_size (style, rect),
123 infoPtr->MaxVal - infoPtr->MinVal);
124 }
125
126 /***********************************************************************
127 * PROGRESS_Invalidate
128 *
129 * Don't be too clever about invalidating the progress bar.
130 * InstallShield depends on this simple behaviour.
131 */
132 static void PROGRESS_Invalidate( const PROGRESS_INFO *infoPtr, INT old, INT new )
133 {
134 InvalidateRect( infoPtr->Self, NULL, old > new );
135 }
136
137 /* Information for a progress bar drawing helper */
138 typedef struct tagProgressDrawInfo
139 {
140 HDC hdc;
141 RECT rect;
142 HBRUSH hbrBar;
143 HBRUSH hbrBk;
144 int ledW, ledGap;
145 HTHEME theme;
146 RECT bgRect;
147 } ProgressDrawInfo;
148
149 typedef void (*ProgressDrawProc)(const ProgressDrawInfo* di, int start, int end);
150
151 /* draw solid horizontal bar from 'start' to 'end' */
152 static void draw_solid_bar_H (const ProgressDrawInfo* di, int start, int end)
153 {
154 RECT r;
155 r.left = di->rect.left + start;
156 r.top = di->rect.top;
157 r.right = di->rect.left + end;
158 r.bottom = di->rect.bottom;
159 FillRect (di->hdc, &r, di->hbrBar);
160 }
161
162 /* draw solid horizontal background from 'start' to 'end' */
163 static void draw_solid_bkg_H (const ProgressDrawInfo* di, int start, int end)
164 {
165 RECT r;
166 r.left = di->rect.left + start;
167 r.top = di->rect.top;
168 r.right = di->rect.left + end;
169 r.bottom = di->rect.bottom;
170 FillRect (di->hdc, &r, di->hbrBk);
171 }
172
173 /* draw solid vertical bar from 'start' to 'end' */
174 static void draw_solid_bar_V (const ProgressDrawInfo* di, int start, int end)
175 {
176 RECT r;
177 r.left = di->rect.left;
178 r.top = di->rect.bottom - end;
179 r.right = di->rect.right;
180 r.bottom = di->rect.bottom - start;
181 FillRect (di->hdc, &r, di->hbrBar);
182 }
183
184 /* draw solid vertical background from 'start' to 'end' */
185 static void draw_solid_bkg_V (const ProgressDrawInfo* di, int start, int end)
186 {
187 RECT r;
188 r.left = di->rect.left;
189 r.top = di->rect.bottom - end;
190 r.right = di->rect.right;
191 r.bottom = di->rect.bottom - start;
192 FillRect (di->hdc, &r, di->hbrBk);
193 }
194
195 /* draw chunky horizontal bar from 'start' to 'end' */
196 static void draw_chunk_bar_H (const ProgressDrawInfo* di, int start, int end)
197 {
198 RECT r;
199 int right = di->rect.left + end;
200 r.left = di->rect.left + start;
201 r.top = di->rect.top;
202 r.bottom = di->rect.bottom;
203 while (r.left < right)
204 {
205 r.right = min (r.left + di->ledW, right);
206 FillRect (di->hdc, &r, di->hbrBar);
207 r.left = r.right;
208 r.right = min (r.left + di->ledGap, right);
209 FillRect (di->hdc, &r, di->hbrBk);
210 r.left = r.right;
211 }
212 }
213
214 /* draw chunky vertical bar from 'start' to 'end' */
215 static void draw_chunk_bar_V (const ProgressDrawInfo* di, int start, int end)
216 {
217 RECT r;
218 int top = di->rect.bottom - end;
219 r.left = di->rect.left;
220 r.right = di->rect.right;
221 r.bottom = di->rect.bottom - start;
222 while (r.bottom > top)
223 {
224 r.top = max (r.bottom - di->ledW, top);
225 FillRect (di->hdc, &r, di->hbrBar);
226 r.bottom = r.top;
227 r.top = max (r.bottom - di->ledGap, top);
228 FillRect (di->hdc, &r, di->hbrBk);
229 r.bottom = r.top;
230 }
231 }
232
233 /* drawing functions for "classic" style */
234 static const ProgressDrawProc drawProcClassic[8] = {
235 /* Smooth */
236 /* Horizontal */
237 draw_solid_bar_H, draw_solid_bkg_H,
238 /* Vertical */
239 draw_solid_bar_V, draw_solid_bkg_V,
240 /* Chunky */
241 /* Horizontal */
242 draw_chunk_bar_H, draw_solid_bkg_H,
243 /* Vertical */
244 draw_chunk_bar_V, draw_solid_bkg_V,
245 };
246
247 /* draw themed horizontal bar from 'start' to 'end' */
248 static void draw_theme_bar_H (const ProgressDrawInfo* di, int start, int end)
249 {
250 RECT r;
251 r.left = di->rect.left + start;
252 r.top = di->rect.top;
253 r.bottom = di->rect.bottom;
254 r.right = di->rect.left + end;
255 DrawThemeBackground (di->theme, di->hdc, PP_CHUNK, 0, &r, NULL);
256 }
257
258 /* draw themed vertical bar from 'start' to 'end' */
259 static void draw_theme_bar_V (const ProgressDrawInfo* di, int start, int end)
260 {
261 RECT r;
262 r.left = di->rect.left;
263 r.right = di->rect.right;
264 r.bottom = di->rect.bottom - start;
265 r.top = di->rect.bottom - end;
266 DrawThemeBackground (di->theme, di->hdc, PP_CHUNKVERT, 0, &r, NULL);
267 }
268
269 /* draw themed horizontal background from 'start' to 'end' */
270 static void draw_theme_bkg_H (const ProgressDrawInfo* di, int start, int end)
271 {
272 RECT r;
273 r.left = di->rect.left + start;
274 r.top = di->rect.top;
275 r.right = di->rect.left + end;
276 r.bottom = di->rect.bottom;
277 DrawThemeBackground (di->theme, di->hdc, PP_BAR, 0, &di->bgRect, &r);
278 }
279
280 /* draw themed vertical background from 'start' to 'end' */
281 static void draw_theme_bkg_V (const ProgressDrawInfo* di, int start, int end)
282 {
283 RECT r;
284 r.left = di->rect.left;
285 r.top = di->rect.bottom - end;
286 r.right = di->rect.right;
287 r.bottom = di->rect.bottom - start;
288 DrawThemeBackground (di->theme, di->hdc, PP_BARVERT, 0, &di->bgRect, &r);
289 }
290
291 /* drawing functions for themed style */
292 static const ProgressDrawProc drawProcThemed[8] = {
293 /* Smooth */
294 /* Horizontal */
295 draw_theme_bar_H, draw_theme_bkg_H,
296 /* Vertical */
297 draw_theme_bar_V, draw_theme_bkg_V,
298 /* Chunky */
299 /* Horizontal */
300 draw_theme_bar_H, draw_theme_bkg_H,
301 /* Vertical */
302 draw_theme_bar_V, draw_theme_bkg_V,
303 };
304
305 /***********************************************************************
306 * PROGRESS_Draw
307 * Draws the progress bar.
308 */
309 static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
310 {
311 int barSize;
312 DWORD dwStyle;
313 BOOL barSmooth;
314 const ProgressDrawProc* drawProcs;
315 ProgressDrawInfo pdi;
316
317 TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc);
318
319 pdi.hdc = hdc;
320 pdi.theme = GetWindowTheme (infoPtr->Self);
321
322 /* get the required bar brush */
323 if (infoPtr->ColorBar == CLR_DEFAULT)
324 pdi.hbrBar = GetSysColorBrush(COLOR_HIGHLIGHT);
325 else
326 pdi.hbrBar = CreateSolidBrush (infoPtr->ColorBar);
327
328 if (infoPtr->ColorBk == CLR_DEFAULT)
329 pdi.hbrBk = GetSysColorBrush(COLOR_3DFACE);
330 else
331 pdi.hbrBk = CreateSolidBrush(infoPtr->ColorBk);
332
333 /* get the window style */
334 dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
335
336 /* get client rectangle */
337 GetClientRect (infoPtr->Self, &pdi.rect);
338 if (!pdi.theme) {
339 FrameRect( hdc, &pdi.rect, pdi.hbrBk );
340 InflateRect(&pdi.rect, -1, -1);
341 }
342 else
343 {
344 RECT cntRect;
345 int part = (dwStyle & PBS_VERTICAL) ? PP_BARVERT : PP_BAR;
346
347 GetThemeBackgroundContentRect (pdi.theme, hdc, part, 0, &pdi.rect,
348 &cntRect);
349
350 /* Exclude content rect - content background will be drawn later */
351 ExcludeClipRect (hdc, cntRect.left, cntRect.top,
352 cntRect.right, cntRect.bottom);
353 if (IsThemeBackgroundPartiallyTransparent (pdi.theme, part, 0))
354 DrawThemeParentBackground (infoPtr->Self, hdc, NULL);
355 DrawThemeBackground (pdi.theme, hdc, part, 0, &pdi.rect, NULL);
356 SelectClipRgn (hdc, NULL);
357 CopyRect (&pdi.rect, &cntRect);
358 }
359
360 /* compute some drawing parameters */
361 barSmooth = (dwStyle & PBS_SMOOTH) && !pdi.theme;
362 drawProcs = &((pdi.theme ? drawProcThemed : drawProcClassic)[(barSmooth ? 0 : 4)
363 + ((dwStyle & PBS_VERTICAL) ? 2 : 0)]);
364 barSize = get_bar_size( dwStyle, &pdi.rect );
365 if (pdi.theme)
366 {
367 GetWindowRect( infoPtr->Self, &pdi.bgRect );
368 MapWindowPoints( infoPtr->Self, 0, (POINT*)&pdi.bgRect, 2 );
369 }
370
371 if (!barSmooth)
372 pdi.ledW = get_led_size( infoPtr, dwStyle, &pdi.rect);
373 pdi.ledGap = get_led_gap( infoPtr );
374
375 if (dwStyle & PBS_MARQUEE)
376 {
377 const int ledW = !barSmooth ? (pdi.ledW + pdi.ledGap) : 1;
378 const int leds = (barSize + ledW - 1) / ledW;
379 const int ledMEnd = infoPtr->MarqueePos + MARQUEE_LEDS;
380
381 if (ledMEnd > leds)
382 {
383 /* case 1: the marquee bar extends over the end and wraps around to
384 * the start */
385 const int gapStart = max((ledMEnd - leds) * ledW, 0);
386 const int gapEnd = min(infoPtr->MarqueePos * ledW, barSize);
387
388 drawProcs[0]( &pdi, 0, gapStart);
389 drawProcs[1]( &pdi, gapStart, gapEnd);
390 drawProcs[0]( &pdi, gapEnd, barSize);
391 }
392 else
393 {
394 /* case 2: the marquee bar is between start and end */
395 const int barStart = infoPtr->MarqueePos * ledW;
396 const int barEnd = min (ledMEnd * ledW, barSize);
397
398 drawProcs[1]( &pdi, 0, barStart);
399 drawProcs[0]( &pdi, barStart, barEnd);
400 drawProcs[1]( &pdi, barEnd, barSize);
401 }
402 }
403 else
404 {
405 int barEnd = get_bar_position( infoPtr, dwStyle, &pdi.rect,
406 infoPtr->CurVal);
407 if (!barSmooth)
408 {
409 const int ledW = pdi.ledW + pdi.ledGap;
410 barEnd = min (((barEnd + ledW - 1) / ledW) * ledW, barSize);
411 }
412 drawProcs[0]( &pdi, 0, barEnd);
413 drawProcs[1]( &pdi, barEnd, barSize);
414 }
415
416 /* delete bar brush */
417 if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (pdi.hbrBar);
418 if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (pdi.hbrBk);
419
420 return 0;
421 }
422
423 /***********************************************************************
424 * PROGRESS_Paint
425 * Draw the progress bar. The background need not be erased.
426 * If dc!=0, it draws on it
427 */
428 static LRESULT PROGRESS_Paint (PROGRESS_INFO *infoPtr, HDC hdc)
429 {
430 PAINTSTRUCT ps;
431 if (hdc) return PROGRESS_Draw (infoPtr, hdc);
432 hdc = BeginPaint (infoPtr->Self, &ps);
433 PROGRESS_Draw (infoPtr, hdc);
434 EndPaint (infoPtr->Self, &ps);
435 return 0;
436 }
437
438
439 /***********************************************************************
440 * Advance marquee progress by one step.
441 */
442 static void PROGRESS_UpdateMarquee (PROGRESS_INFO *infoPtr)
443 {
444 LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
445 RECT rect;
446 int ledWidth, leds;
447 HTHEME theme = GetWindowTheme (infoPtr->Self);
448 BOOL smooth = (style & PBS_SMOOTH) && !theme;
449
450 get_client_rect (infoPtr->Self, &rect);
451
452 if (smooth)
453 ledWidth = 1;
454 else
455 ledWidth = get_led_size( infoPtr, style, &rect ) + get_led_gap( infoPtr );
456
457 leds = (get_bar_size( style, &rect ) + ledWidth - 1) /
458 ledWidth;
459
460 /* increment the marquee progress */
461 if (++infoPtr->MarqueePos >= leds)
462 infoPtr->MarqueePos = 0;
463
464 InvalidateRect(infoPtr->Self, &rect, TRUE);
465 UpdateWindow(infoPtr->Self);
466 }
467
468
469 /***********************************************************************
470 * PROGRESS_CoercePos
471 * Makes sure the current position (CurVal) is within bounds.
472 */
473 static void PROGRESS_CoercePos(PROGRESS_INFO *infoPtr)
474 {
475 if(infoPtr->CurVal < infoPtr->MinVal)
476 infoPtr->CurVal = infoPtr->MinVal;
477 if(infoPtr->CurVal > infoPtr->MaxVal)
478 infoPtr->CurVal = infoPtr->MaxVal;
479 }
480
481
482 /***********************************************************************
483 * PROGRESS_SetFont
484 * Set new Font for progress bar
485 */
486 static HFONT PROGRESS_SetFont (PROGRESS_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
487 {
488 HFONT hOldFont = infoPtr->Font;
489 infoPtr->Font = hFont;
490 /* Since infoPtr->Font is not used, there is no need for repaint */
491 return hOldFont;
492 }
493
494 static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high)
495 {
496 DWORD res = MAKELONG(LOWORD(infoPtr->MinVal), LOWORD(infoPtr->MaxVal));
497
498 /* if nothing changes, simply return */
499 if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res;
500
501 infoPtr->MinVal = low;
502 infoPtr->MaxVal = high;
503 PROGRESS_CoercePos(infoPtr);
504 InvalidateRect(infoPtr->Self, NULL, TRUE);
505 return res;
506 }
507
508 static UINT PROGRESS_SetPos (PROGRESS_INFO *infoPtr, INT pos)
509 {
510 DWORD style = GetWindowLongW(infoPtr->Self, GWL_STYLE);
511
512 if (style & PBS_MARQUEE)
513 {
514 PROGRESS_UpdateMarquee(infoPtr);
515 return 1;
516 }
517 else
518 {
519 UINT oldVal;
520 oldVal = infoPtr->CurVal;
521 if (oldVal != pos) {
522 infoPtr->CurVal = pos;
523 PROGRESS_CoercePos(infoPtr);
524 TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
525 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
526 UpdateWindow( infoPtr->Self );
527 }
528 return oldVal;
529 }
530 }
531
532 /***********************************************************************
533 * ProgressWindowProc
534 */
535 static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
536 WPARAM wParam, LPARAM lParam)
537 {
538 PROGRESS_INFO *infoPtr;
539 static const WCHAR themeClass[] = {'P','r','o','g','r','e','s','s',0};
540 HTHEME theme;
541
542 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
543
544 infoPtr = (PROGRESS_INFO *)GetWindowLongPtrW(hwnd, 0);
545
546 if (!infoPtr && message != WM_CREATE)
547 return DefWindowProcW( hwnd, message, wParam, lParam );
548
549 switch(message) {
550 case WM_CREATE:
551 {
552 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
553
554 theme = OpenThemeData (hwnd, themeClass);
555
556 dwExStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE);
557 if (!theme) dwExStyle |= WS_EX_STATICEDGE;
558 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
559 /* Force recalculation of a non-client area */
560 SetWindowPos(hwnd, 0, 0, 0, 0, 0,
561 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
562
563 /* allocate memory for info struct */
564 infoPtr = Alloc (sizeof(PROGRESS_INFO));
565 if (!infoPtr) return -1;
566 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
567
568 /* initialize the info struct */
569 infoPtr->Self = hwnd;
570 infoPtr->MinVal = 0;
571 infoPtr->MaxVal = 100;
572 infoPtr->CurVal = 0;
573 infoPtr->Step = 10;
574 infoPtr->MarqueePos = 0;
575 infoPtr->Marquee = FALSE;
576 infoPtr->ColorBar = CLR_DEFAULT;
577 infoPtr->ColorBk = CLR_DEFAULT;
578 infoPtr->Font = 0;
579
580 TRACE("Progress Ctrl creation, hwnd=%p\n", hwnd);
581 return 0;
582 }
583
584 case WM_DESTROY:
585 TRACE("Progress Ctrl destruction, hwnd=%p\n", hwnd);
586 Free (infoPtr);
587 SetWindowLongPtrW(hwnd, 0, 0);
588 theme = GetWindowTheme (hwnd);
589 CloseThemeData (theme);
590 return 0;
591
592 case WM_ERASEBKGND:
593 return 1;
594
595 case WM_GETFONT:
596 return (LRESULT)infoPtr->Font;
597
598 case WM_SETFONT:
599 return (LRESULT)PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
600
601 case WM_PRINTCLIENT:
602 case WM_PAINT:
603 return PROGRESS_Paint (infoPtr, (HDC)wParam);
604
605 case WM_TIMER:
606 if (wParam == ID_MARQUEE_TIMER)
607 PROGRESS_UpdateMarquee (infoPtr);
608 return 0;
609
610 case WM_THEMECHANGED:
611 {
612 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
613
614 theme = GetWindowTheme (hwnd);
615 CloseThemeData (theme);
616 theme = OpenThemeData (hwnd, themeClass);
617
618 /* WS_EX_STATICEDGE disappears when the control is themed */
619 if (theme)
620 dwExStyle &= ~WS_EX_STATICEDGE;
621 else
622 dwExStyle |= WS_EX_STATICEDGE;
623 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
624
625 InvalidateRect (hwnd, NULL, FALSE);
626 return 0;
627 }
628
629 case PBM_DELTAPOS:
630 {
631 INT oldVal;
632 oldVal = infoPtr->CurVal;
633 if(wParam != 0) {
634 infoPtr->CurVal += (INT)wParam;
635 PROGRESS_CoercePos (infoPtr);
636 TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
637 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
638 UpdateWindow( infoPtr->Self );
639 }
640 return oldVal;
641 }
642
643 case PBM_SETPOS:
644 return PROGRESS_SetPos(infoPtr, wParam);
645
646 case PBM_SETRANGE:
647 return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam));
648
649 case PBM_SETSTEP:
650 {
651 INT oldStep;
652 oldStep = infoPtr->Step;
653 infoPtr->Step = (INT)wParam;
654 return oldStep;
655 }
656
657 case PBM_GETSTEP:
658 return infoPtr->Step;
659
660 case PBM_STEPIT:
661 {
662 INT oldVal;
663 oldVal = infoPtr->CurVal;
664 infoPtr->CurVal += infoPtr->Step;
665 if(infoPtr->CurVal > infoPtr->MaxVal)
666 infoPtr->CurVal = infoPtr->MinVal;
667 if(oldVal != infoPtr->CurVal)
668 {
669 TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
670 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
671 UpdateWindow( infoPtr->Self );
672 }
673 return oldVal;
674 }
675
676 case PBM_SETRANGE32:
677 return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam);
678
679 case PBM_GETRANGE:
680 if (lParam) {
681 ((PPBRANGE)lParam)->iLow = infoPtr->MinVal;
682 ((PPBRANGE)lParam)->iHigh = infoPtr->MaxVal;
683 }
684 return wParam ? infoPtr->MinVal : infoPtr->MaxVal;
685
686 case PBM_GETPOS:
687 return infoPtr->CurVal;
688
689 case PBM_SETBARCOLOR:
690 {
691 COLORREF clr = infoPtr->ColorBar;
692
693 infoPtr->ColorBar = (COLORREF)lParam;
694 InvalidateRect(hwnd, NULL, TRUE);
695 return clr;
696 }
697
698 case PBM_GETBARCOLOR:
699 return infoPtr->ColorBar;
700
701 case PBM_SETBKCOLOR:
702 {
703 COLORREF clr = infoPtr->ColorBk;
704
705 infoPtr->ColorBk = (COLORREF)lParam;
706 InvalidateRect(hwnd, NULL, TRUE);
707 return clr;
708 }
709
710 case PBM_GETBKCOLOR:
711 return infoPtr->ColorBk;
712
713 case PBM_SETSTATE:
714 if(wParam != PBST_NORMAL)
715 FIXME("state %04lx not yet handled\n", wParam);
716 return PBST_NORMAL;
717
718 case PBM_GETSTATE:
719 return PBST_NORMAL;
720
721 case PBM_SETMARQUEE:
722 if(wParam != 0)
723 {
724 UINT period = lParam ? (UINT)lParam : DEFAULT_MARQUEE_PERIOD;
725 infoPtr->Marquee = TRUE;
726 SetTimer(infoPtr->Self, ID_MARQUEE_TIMER, period, NULL);
727 }
728 else
729 {
730 infoPtr->Marquee = FALSE;
731 KillTimer(infoPtr->Self, ID_MARQUEE_TIMER);
732 }
733 return infoPtr->Marquee;
734
735 default:
736 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
737 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
738 return DefWindowProcW( hwnd, message, wParam, lParam );
739 }
740 }
741
742
743 /***********************************************************************
744 * PROGRESS_Register [Internal]
745 *
746 * Registers the progress bar window class.
747 */
748 void PROGRESS_Register (void)
749 {
750 WNDCLASSW wndClass;
751
752 ZeroMemory (&wndClass, sizeof(wndClass));
753 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
754 wndClass.lpfnWndProc = ProgressWindowProc;
755 wndClass.cbClsExtra = 0;
756 wndClass.cbWndExtra = sizeof (PROGRESS_INFO *);
757 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
758 wndClass.lpszClassName = PROGRESS_CLASSW;
759
760 RegisterClassW (&wndClass);
761 }
762
763
764 /***********************************************************************
765 * PROGRESS_Unregister [Internal]
766 *
767 * Unregisters the progress bar window class.
768 */
769 void PROGRESS_Unregister (void)
770 {
771 UnregisterClassW (PROGRESS_CLASSW, NULL);
772 }