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