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