- Redraw immediately upon PBM_SETPOS, PBM_DELTAPOS, PBM_STEPIT.
[wine/dcerpc.git] / dlls / comctl32 / progress.c
bloba6e20e5e9ccd03d5778dfd1068ea678f6fa272cc
1 /*
2 * Progress control
4 * Copyright 1997, 2002 Dimitrie O. Paun
5 * Copyright 1998, 1999 Eric Kohl
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * NOTE
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.
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.
32 #include <stdarg.h>
33 #include <string.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37 #include "winuser.h"
38 #include "winnls.h"
39 #include "commctrl.h"
40 #include "comctl32.h"
41 #include "uxtheme.h"
42 #include "tmschema.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(progress);
47 typedef struct
49 HWND Self; /* The window handle for this control */
50 INT CurVal; /* Current progress value */
51 INT MinVal; /* Minimum progress value */
52 INT MaxVal; /* Maximum progress value */
53 INT Step; /* Step to use on PMB_STEPIT */
54 INT MarqueePos; /* Marquee animation position */
55 BOOL Marquee; /* Whether the marquee animation is enabled */
56 COLORREF ColorBar; /* Bar color */
57 COLORREF ColorBk; /* Background color */
58 HFONT Font; /* Handle to font (not unused) */
59 } PROGRESS_INFO;
61 /* Control configuration constants */
63 #define LED_GAP 2
64 #define MARQUEE_LEDS 5
65 #define ID_MARQUEE_TIMER 1
67 /* Helper to obtain size of a progress bar chunk ("led"). */
68 static inline int get_led_size ( PROGRESS_INFO *infoPtr, LONG style,
69 const RECT* rect )
71 HTHEME theme = GetWindowTheme (infoPtr->Self);
72 if (theme)
74 int chunkSize;
75 if (SUCCEEDED( GetThemeInt( theme, 0, 0, TMT_PROGRESSCHUNKSIZE, &chunkSize )))
76 return chunkSize;
79 if (style & PBS_VERTICAL)
80 return MulDiv (rect->right - rect->left, 2, 3);
81 else
82 return MulDiv (rect->bottom - rect->top, 2, 3);
85 /* Helper to obtain gap between progress bar chunks */
86 static inline int get_led_gap ( PROGRESS_INFO *infoPtr )
88 HTHEME theme = GetWindowTheme (infoPtr->Self);
89 if (theme)
91 int spaceSize;
92 if (SUCCEEDED( GetThemeInt( theme, 0, 0, TMT_PROGRESSSPACESIZE, &spaceSize )))
93 return spaceSize;
96 return LED_GAP;
99 /* Get client rect. Takes into account that theming needs no adjustment. */
100 static inline void get_client_rect (HWND hwnd, RECT* rect)
102 HTHEME theme = GetWindowTheme (hwnd);
103 GetClientRect (hwnd, rect);
104 if (!theme)
105 InflateRect(rect, -1, -1);
106 else
108 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
109 int part = (dwStyle & PBS_VERTICAL) ? PP_BARVERT : PP_BAR;
110 GetThemeBackgroundContentRect (theme, 0, part, 0, rect, rect);
114 /* Compute the extend of the bar */
115 static inline int get_bar_size( LONG style, const RECT* rect )
117 if (style & PBS_VERTICAL)
118 return rect->bottom - rect->top;
119 else
120 return rect->right - rect->left;
123 /* Compute the pixel position of a progress value */
124 static inline int get_bar_position( PROGRESS_INFO *infoPtr, LONG style,
125 const RECT* rect, INT value )
127 return MulDiv (value - infoPtr->MinVal, get_bar_size (style, rect),
128 infoPtr->MaxVal - infoPtr->MinVal);
131 /***********************************************************************
132 * PROGRESS_Invalidate
134 * Invalide the range between old and new pos.
136 static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new )
138 LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
139 RECT rect;
140 int oldPos, newPos;
141 BOOL barSmooth = (style & PBS_SMOOTH) && !GetWindowTheme (infoPtr->Self);
143 get_client_rect( infoPtr->Self, &rect );
145 oldPos = get_bar_position( infoPtr, style, &rect, old );
146 newPos = get_bar_position( infoPtr, style, &rect, new );
148 if (style & PBS_VERTICAL)
150 rect.top = rect.bottom - max( oldPos, newPos );
151 rect.bottom = rect.bottom - min( oldPos, newPos );
152 if (!barSmooth) rect.top -=
153 get_led_size (infoPtr, style, &rect) + get_led_gap (infoPtr);
155 else
157 rect.left = min( oldPos, newPos );
158 rect.right = max( oldPos, newPos );
159 if (!barSmooth) rect.right +=
160 get_led_size (infoPtr, style, &rect) + get_led_gap (infoPtr);
162 InvalidateRect( infoPtr->Self, &rect, oldPos > newPos );
165 /* Information for a progress bar drawing helper */
166 typedef struct tagProgressDrawInfo
168 HDC hdc;
169 RECT rect;
170 HBRUSH hbrBar;
171 HBRUSH hbrBk;
172 int ledW, ledGap;
173 HTHEME theme;
174 RECT bgRect;
175 } ProgressDrawInfo;
177 typedef void (*ProgressDrawProc)(const ProgressDrawInfo* di, int start, int end);
179 /* draw solid horizontal bar from 'start' to 'end' */
180 static void draw_solid_bar_H (const ProgressDrawInfo* di, int start, int end)
182 RECT r;
183 r.left = di->rect.left + start;
184 r.top = di->rect.top;
185 r.right = di->rect.left + end;
186 r.bottom = di->rect.bottom;
187 FillRect (di->hdc, &r, di->hbrBar);
190 /* draw solid horizontal background from 'start' to 'end' */
191 static void draw_solid_bkg_H (const ProgressDrawInfo* di, int start, int end)
193 RECT r;
194 r.left = di->rect.left + start;
195 r.top = di->rect.top;
196 r.right = di->rect.left + end;
197 r.bottom = di->rect.bottom;
198 FillRect (di->hdc, &r, di->hbrBk);
201 /* draw solid vertical bar from 'start' to 'end' */
202 static void draw_solid_bar_V (const ProgressDrawInfo* di, int start, int end)
204 RECT r;
205 r.left = di->rect.left;
206 r.top = di->rect.bottom - end;
207 r.right = di->rect.right;
208 r.bottom = di->rect.bottom - start;
209 FillRect (di->hdc, &r, di->hbrBar);
212 /* draw solid vertical background from 'start' to 'end' */
213 static void draw_solid_bkg_V (const ProgressDrawInfo* di, int start, int end)
215 RECT r;
216 r.left = di->rect.left;
217 r.top = di->rect.bottom - end;
218 r.right = di->rect.right;
219 r.bottom = di->rect.bottom - start;
220 FillRect (di->hdc, &r, di->hbrBk);
223 /* draw chunky horizontal bar from 'start' to 'end' */
224 static void draw_chunk_bar_H (const ProgressDrawInfo* di, int start, int end)
226 RECT r;
227 int right = di->rect.left + end;
228 r.left = di->rect.left + start;
229 r.top = di->rect.top;
230 r.bottom = di->rect.bottom;
231 while (r.left < right)
233 r.right = min (r.left + di->ledW, right);
234 FillRect (di->hdc, &r, di->hbrBar);
235 r.left = r.right;
236 r.right = min (r.left + di->ledGap, right);
237 FillRect (di->hdc, &r, di->hbrBk);
238 r.left = r.right;
242 /* draw chunky vertical bar from 'start' to 'end' */
243 static void draw_chunk_bar_V (const ProgressDrawInfo* di, int start, int end)
245 RECT r;
246 int top = di->rect.bottom - end;
247 r.left = di->rect.left;
248 r.right = di->rect.right;
249 r.bottom = di->rect.bottom - start;
250 while (r.bottom > top)
252 r.top = max (r.bottom - di->ledW, top);
253 FillRect (di->hdc, &r, di->hbrBar);
254 r.bottom = r.top;
255 r.top = max (r.bottom - di->ledGap, top);
256 FillRect (di->hdc, &r, di->hbrBk);
257 r.bottom = r.top;
261 /* drawing functions for "classic" style */
262 static const ProgressDrawProc drawProcClassic[8] = {
263 /* Smooth */
264 /* Horizontal */
265 draw_solid_bar_H, draw_solid_bkg_H,
266 /* Vertical */
267 draw_solid_bar_V, draw_solid_bkg_V,
268 /* Chunky */
269 /* Horizontal */
270 draw_chunk_bar_H, draw_solid_bkg_H,
271 /* Vertical */
272 draw_chunk_bar_V, draw_solid_bkg_V,
275 /* draw themed horizontal bar from 'start' to 'end' */
276 static void draw_theme_bar_H (const ProgressDrawInfo* di, int start, int end)
278 RECT r;
279 int right = di->rect.left + end;
280 r.left = di->rect.left + start;
281 r.top = di->rect.top;
282 r.bottom = di->rect.bottom;
283 while (r.left < right)
285 r.right = min (r.left + di->ledW, right);
286 DrawThemeBackground (di->theme, di->hdc, PP_CHUNK, 0, &r, NULL);
287 r.left = r.right;
288 r.right = min (r.left + di->ledGap, right);
289 DrawThemeBackground (di->theme, di->hdc, PP_BAR, 0, &di->bgRect, &r);
290 r.left = r.right;
294 /* draw themed horizontal bar from 'start' to 'end' */
295 static void draw_theme_bar_V (const ProgressDrawInfo* di, int start, int end)
297 RECT r;
298 int top = di->rect.bottom - end;
299 r.left = di->rect.left;
300 r.right = di->rect.right;
301 r.bottom = di->rect.bottom - start;
302 while (r.bottom > top)
304 r.top = max (r.bottom - di->ledW, top);
305 DrawThemeBackground (di->theme, di->hdc, PP_CHUNKVERT, 0, &r, NULL);
306 r.bottom = r.top;
307 r.top = max (r.bottom - di->ledGap, top);
308 DrawThemeBackground (di->theme, di->hdc, PP_BARVERT, 0, &di->bgRect, &r);
309 r.bottom = r.top;
313 /* draw themed horizontal background from 'start' to 'end' */
314 static void draw_theme_bkg_H (const ProgressDrawInfo* di, int start, int end)
316 RECT r;
317 r.left = di->rect.left + start;
318 r.top = di->rect.top;
319 r.right = di->rect.left + end;
320 r.bottom = di->rect.bottom;
321 DrawThemeBackground (di->theme, di->hdc, PP_BAR, 0, &di->bgRect, &r);
324 /* draw themed vertical background from 'start' to 'end' */
325 static void draw_theme_bkg_V (const ProgressDrawInfo* di, int start, int end)
327 RECT r;
328 r.left = di->rect.left;
329 r.top = di->rect.bottom - end;
330 r.right = di->rect.right;
331 r.bottom = di->rect.bottom - start;
332 DrawThemeBackground (di->theme, di->hdc, PP_BARVERT, 0, &di->bgRect, &r);
335 /* drawing functions for themed style */
336 static const ProgressDrawProc drawProcThemed[8] = {
337 /* Smooth */
338 /* Horizontal */
339 draw_theme_bar_H, draw_theme_bkg_H,
340 /* Vertical */
341 draw_theme_bar_V, draw_theme_bkg_V,
342 /* Chunky */
343 /* Horizontal */
344 draw_theme_bar_H, draw_theme_bkg_H,
345 /* Vertical */
346 draw_theme_bar_V, draw_theme_bkg_V,
349 /***********************************************************************
350 * PROGRESS_Draw
351 * Draws the progress bar.
353 static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
355 int barSize;
356 DWORD dwStyle;
357 BOOL barSmooth;
358 const ProgressDrawProc* drawProcs;
359 ProgressDrawInfo pdi;
361 TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc);
363 pdi.hdc = hdc;
364 pdi.theme = GetWindowTheme (infoPtr->Self);
366 /* get the required bar brush */
367 if (infoPtr->ColorBar == CLR_DEFAULT)
368 pdi.hbrBar = GetSysColorBrush(COLOR_HIGHLIGHT);
369 else
370 pdi.hbrBar = CreateSolidBrush (infoPtr->ColorBar);
372 if (infoPtr->ColorBk == CLR_DEFAULT)
373 pdi.hbrBk = GetSysColorBrush(COLOR_3DFACE);
374 else
375 pdi.hbrBk = CreateSolidBrush(infoPtr->ColorBk);
377 /* get the window style */
378 dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
380 /* get client rectangle */
381 GetClientRect (infoPtr->Self, &pdi.rect);
382 if (!pdi.theme) {
383 FrameRect( hdc, &pdi.rect, pdi.hbrBk );
384 InflateRect(&pdi.rect, -1, -1);
386 else
388 RECT cntRect;
389 int part = (dwStyle & PBS_VERTICAL) ? PP_BARVERT : PP_BAR;
391 GetThemeBackgroundContentRect (pdi.theme, hdc, part, 0, &pdi.rect,
392 &cntRect);
394 /* Exclude content rect - content background will be drawn later */
395 ExcludeClipRect (hdc, cntRect.left, cntRect.top,
396 cntRect.right, cntRect.bottom);
397 if (IsThemeBackgroundPartiallyTransparent (pdi.theme, part, 0))
398 DrawThemeParentBackground (infoPtr->Self, hdc, NULL);
399 DrawThemeBackground (pdi.theme, hdc, part, 0, &pdi.rect, NULL);
400 SelectClipRgn (hdc, NULL);
401 CopyRect (&pdi.rect, &cntRect);
404 /* compute some drawing parameters */
405 barSmooth = (dwStyle & PBS_SMOOTH) && !pdi.theme;
406 drawProcs = &((pdi.theme ? drawProcThemed : drawProcClassic)[(barSmooth ? 0 : 4)
407 + ((dwStyle & PBS_VERTICAL) ? 2 : 0)]);
408 barSize = get_bar_size( dwStyle, &pdi.rect );
409 if (pdi.theme)
411 GetWindowRect( infoPtr->Self, &pdi.bgRect );
412 ScreenToClient( infoPtr->Self, (POINT*)&pdi.bgRect );
413 ScreenToClient( infoPtr->Self, (POINT*)&pdi.bgRect.right );
416 if (!barSmooth)
417 pdi.ledW = get_led_size( infoPtr, dwStyle, &pdi.rect);
418 pdi.ledGap = get_led_gap( infoPtr );
420 if (dwStyle & PBS_MARQUEE)
422 const int ledW = !barSmooth ? (pdi.ledW + pdi.ledGap) : 1;
423 const int leds = (barSize + ledW - 1) / ledW;
424 const int ledMEnd = infoPtr->MarqueePos + MARQUEE_LEDS;
426 if (ledMEnd > leds)
428 /* case 1: the marquee bar extends over the end and wraps around to
429 * the start */
430 const int gapStart = max((ledMEnd - leds) * ledW, 0);
431 const int gapEnd = min(infoPtr->MarqueePos * ledW, barSize);
433 drawProcs[0]( &pdi, 0, gapStart);
434 drawProcs[1]( &pdi, gapStart, gapEnd);
435 drawProcs[0]( &pdi, gapEnd, barSize);
437 else
439 /* case 2: the marquee bar is between start and end */
440 const int barStart = infoPtr->MarqueePos * ledW;
441 const int barEnd = min (ledMEnd * ledW, barSize);
443 drawProcs[1]( &pdi, 0, barStart);
444 drawProcs[0]( &pdi, barStart, barEnd);
445 drawProcs[1]( &pdi, barEnd, barSize);
448 else
450 int barEnd = get_bar_position( infoPtr, dwStyle, &pdi.rect,
451 infoPtr->CurVal);
452 if (!barSmooth)
454 const int ledW = pdi.ledW + pdi.ledGap;
455 barEnd = min (((barEnd + ledW - 1) / ledW) * ledW, barSize);
457 drawProcs[0]( &pdi, 0, barEnd);
458 drawProcs[1]( &pdi, barEnd, barSize);
461 /* delete bar brush */
462 if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (pdi.hbrBar);
463 if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (pdi.hbrBk);
465 return 0;
468 /***********************************************************************
469 * PROGRESS_Paint
470 * Draw the progress bar. The background need not be erased.
471 * If dc!=0, it draws on it
473 static LRESULT PROGRESS_Paint (PROGRESS_INFO *infoPtr, HDC hdc)
475 PAINTSTRUCT ps;
476 if (hdc) return PROGRESS_Draw (infoPtr, hdc);
477 hdc = BeginPaint (infoPtr->Self, &ps);
478 PROGRESS_Draw (infoPtr, hdc);
479 EndPaint (infoPtr->Self, &ps);
480 return 0;
484 /***********************************************************************
485 * PROGRESS_Timer
486 * Handle the marquee timer messages
488 static LRESULT PROGRESS_Timer (PROGRESS_INFO *infoPtr, INT idTimer)
490 if(idTimer == ID_MARQUEE_TIMER)
492 LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
493 RECT rect;
494 int ledWidth, leds;
495 HTHEME theme = GetWindowTheme (infoPtr->Self);
496 BOOL barSmooth = (style & PBS_SMOOTH) && !theme;
498 get_client_rect (infoPtr->Self, &rect);
500 if(!barSmooth)
501 ledWidth = get_led_size( infoPtr, style, &rect ) +
502 get_led_gap( infoPtr );
503 else
504 ledWidth = 1;
506 leds = (get_bar_size( style, &rect ) + ledWidth - 1) /
507 ledWidth;
509 /* increment the marquee progress */
510 if(++infoPtr->MarqueePos >= leds)
512 infoPtr->MarqueePos = 0;
515 InvalidateRect(infoPtr->Self, &rect, FALSE);
516 UpdateWindow(infoPtr->Self);
518 return 0;
522 /***********************************************************************
523 * PROGRESS_CoercePos
524 * Makes sure the current position (CurVal) is within bounds.
526 static void PROGRESS_CoercePos(PROGRESS_INFO *infoPtr)
528 if(infoPtr->CurVal < infoPtr->MinVal)
529 infoPtr->CurVal = infoPtr->MinVal;
530 if(infoPtr->CurVal > infoPtr->MaxVal)
531 infoPtr->CurVal = infoPtr->MaxVal;
535 /***********************************************************************
536 * PROGRESS_SetFont
537 * Set new Font for progress bar
539 static HFONT PROGRESS_SetFont (PROGRESS_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
541 HFONT hOldFont = infoPtr->Font;
542 infoPtr->Font = hFont;
543 /* Since infoPtr->Font is not used, there is no need for repaint */
544 return hOldFont;
547 static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high)
549 DWORD res = MAKELONG(LOWORD(infoPtr->MinVal), LOWORD(infoPtr->MaxVal));
551 /* if nothing changes, simply return */
552 if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res;
554 infoPtr->MinVal = low;
555 infoPtr->MaxVal = high;
556 PROGRESS_CoercePos(infoPtr);
557 InvalidateRect(infoPtr->Self, NULL, TRUE);
558 return res;
561 /***********************************************************************
562 * ProgressWindowProc
564 static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
565 WPARAM wParam, LPARAM lParam)
567 PROGRESS_INFO *infoPtr;
568 static const WCHAR themeClass[] = {'P','r','o','g','r','e','s','s',0};
569 HTHEME theme;
571 TRACE("hwnd=%p msg=%04x wparam=%x lParam=%lx\n", hwnd, message, wParam, lParam);
573 infoPtr = (PROGRESS_INFO *)GetWindowLongPtrW(hwnd, 0);
575 if (!infoPtr && message != WM_CREATE)
576 return DefWindowProcW( hwnd, message, wParam, lParam );
578 switch(message) {
579 case WM_CREATE:
581 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
583 theme = OpenThemeData (hwnd, themeClass);
585 dwExStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE);
586 if (!theme) dwExStyle |= WS_EX_STATICEDGE;
587 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
588 /* Force recalculation of a non-client area */
589 SetWindowPos(hwnd, 0, 0, 0, 0, 0,
590 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
592 /* allocate memory for info struct */
593 infoPtr = (PROGRESS_INFO *)Alloc (sizeof(PROGRESS_INFO));
594 if (!infoPtr) return -1;
595 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
597 /* initialize the info struct */
598 infoPtr->Self = hwnd;
599 infoPtr->MinVal = 0;
600 infoPtr->MaxVal = 100;
601 infoPtr->CurVal = 0;
602 infoPtr->Step = 10;
603 infoPtr->MarqueePos = 0;
604 infoPtr->Marquee = FALSE;
605 infoPtr->ColorBar = CLR_DEFAULT;
606 infoPtr->ColorBk = CLR_DEFAULT;
607 infoPtr->Font = 0;
609 TRACE("Progress Ctrl creation, hwnd=%p\n", hwnd);
610 return 0;
613 case WM_DESTROY:
614 TRACE("Progress Ctrl destruction, hwnd=%p\n", hwnd);
615 Free (infoPtr);
616 SetWindowLongPtrW(hwnd, 0, 0);
617 theme = GetWindowTheme (hwnd);
618 CloseThemeData (theme);
619 return 0;
621 case WM_ERASEBKGND:
622 return 1;
624 case WM_GETFONT:
625 return (LRESULT)infoPtr->Font;
627 case WM_SETFONT:
628 return (LRESULT)PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
630 case WM_PAINT:
631 return PROGRESS_Paint (infoPtr, (HDC)wParam);
633 case WM_TIMER:
634 return PROGRESS_Timer (infoPtr, (INT)wParam);
636 case WM_THEMECHANGED:
638 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
640 theme = GetWindowTheme (hwnd);
641 CloseThemeData (theme);
642 theme = OpenThemeData (hwnd, themeClass);
644 /* WS_EX_STATICEDGE disappears when the control is themed */
645 if (theme)
646 dwExStyle &= ~WS_EX_STATICEDGE;
647 else
648 dwExStyle |= WS_EX_STATICEDGE;
649 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
651 InvalidateRect (hwnd, NULL, FALSE);
652 return 0;
655 case PBM_DELTAPOS:
657 INT oldVal;
658 oldVal = infoPtr->CurVal;
659 if(wParam != 0) {
660 infoPtr->CurVal += (INT)wParam;
661 PROGRESS_CoercePos (infoPtr);
662 TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
663 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
664 UpdateWindow( infoPtr->Self );
666 return oldVal;
669 case PBM_SETPOS:
671 UINT oldVal;
672 oldVal = infoPtr->CurVal;
673 if(oldVal != wParam) {
674 infoPtr->CurVal = (INT)wParam;
675 PROGRESS_CoercePos(infoPtr);
676 TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
677 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
678 UpdateWindow( infoPtr->Self );
680 return oldVal;
683 case PBM_SETRANGE:
684 return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam));
686 case PBM_SETSTEP:
688 INT oldStep;
689 oldStep = infoPtr->Step;
690 infoPtr->Step = (INT)wParam;
691 return oldStep;
694 case PBM_STEPIT:
696 INT oldVal;
697 oldVal = infoPtr->CurVal;
698 infoPtr->CurVal += infoPtr->Step;
699 if(infoPtr->CurVal > infoPtr->MaxVal)
700 infoPtr->CurVal = infoPtr->MinVal;
701 if(oldVal != infoPtr->CurVal)
703 TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
704 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
705 UpdateWindow( infoPtr->Self );
707 return oldVal;
710 case PBM_SETRANGE32:
711 return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam);
713 case PBM_GETRANGE:
714 if (lParam) {
715 ((PPBRANGE)lParam)->iLow = infoPtr->MinVal;
716 ((PPBRANGE)lParam)->iHigh = infoPtr->MaxVal;
718 return wParam ? infoPtr->MinVal : infoPtr->MaxVal;
720 case PBM_GETPOS:
721 return infoPtr->CurVal;
723 case PBM_SETBARCOLOR:
724 infoPtr->ColorBar = (COLORREF)lParam;
725 InvalidateRect(hwnd, NULL, TRUE);
726 return 0;
728 case PBM_SETBKCOLOR:
729 infoPtr->ColorBk = (COLORREF)lParam;
730 InvalidateRect(hwnd, NULL, TRUE);
731 return 0;
733 case PBM_SETMARQUEE:
734 if(wParam != 0)
736 infoPtr->Marquee = TRUE;
737 SetTimer(infoPtr->Self, ID_MARQUEE_TIMER, (UINT)lParam, NULL);
739 else
741 infoPtr->Marquee = FALSE;
742 KillTimer(infoPtr->Self, ID_MARQUEE_TIMER);
744 return infoPtr->Marquee;
746 default:
747 if ((message >= WM_USER) && (message < WM_APP))
748 ERR("unknown msg %04x wp=%04x lp=%08lx\n", message, wParam, lParam );
749 return DefWindowProcW( hwnd, message, wParam, lParam );
754 /***********************************************************************
755 * PROGRESS_Register [Internal]
757 * Registers the progress bar window class.
759 void PROGRESS_Register (void)
761 WNDCLASSW wndClass;
763 ZeroMemory (&wndClass, sizeof(wndClass));
764 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
765 wndClass.lpfnWndProc = (WNDPROC)ProgressWindowProc;
766 wndClass.cbClsExtra = 0;
767 wndClass.cbWndExtra = sizeof (PROGRESS_INFO *);
768 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
769 wndClass.lpszClassName = PROGRESS_CLASSW;
771 RegisterClassW (&wndClass);
775 /***********************************************************************
776 * PROGRESS_Unregister [Internal]
778 * Unregisters the progress bar window class.
780 void PROGRESS_Unregister (void)
782 UnregisterClassW (PROGRESS_CLASSW, NULL);