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