Update Korean translations.
[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     HTHEME theme = GetWindowTheme (hwnd);
103     GetClientRect (hwnd, rect);
104     if (!theme)
105         InflateRect(rect, -1, -1);
106     else
107     {
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);
111     }
112 }
113
114 /* Compute the extend of the bar */
115 static inline int get_bar_size( LONG style, const RECT* rect )
116 {
117     if (style & PBS_VERTICAL)
118         return rect->bottom - rect->top;
119     else
120         return rect->right - rect->left;
121 }
122
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 )
126 {
127     return MulDiv (value - infoPtr->MinVal, get_bar_size (style, rect),
128                       infoPtr->MaxVal - infoPtr->MinVal);
129 }
130
131 /***********************************************************************
132  * PROGRESS_Invalidate
133  *
134  * Invalide the range between old and new pos.
135  */
136 static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new )
137 {
138     LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
139     RECT rect;
140     int oldPos, newPos;
141     BOOL barSmooth = (style & PBS_SMOOTH) && !GetWindowTheme (infoPtr->Self);
142
143     get_client_rect( infoPtr->Self, &rect );
144
145     oldPos = get_bar_position( infoPtr, style, &rect, old );
146     newPos = get_bar_position( infoPtr, style, &rect, new );
147
148     if (style & PBS_VERTICAL)
149     {
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);
154     }
155     else
156     {
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);
161     }
162     InvalidateRect( infoPtr->Self, &rect, oldPos > newPos );
163 }
164
165 /* Information for a progress bar drawing helper */
166 typedef struct tagProgressDrawInfo
167 {
168     HDC hdc;
169     RECT rect;
170     HBRUSH hbrBar;
171     HBRUSH hbrBk;
172     int ledW, ledGap;
173     HTHEME theme;
174     RECT bgRect;
175 } ProgressDrawInfo;
176
177 typedef void (*ProgressDrawProc)(const ProgressDrawInfo* di, int start, int end);
178
179 /* draw solid horizontal bar from 'start' to 'end' */
180 static void draw_solid_bar_H (const ProgressDrawInfo* di, int start, int end)
181 {
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);
188 }
189
190 /* draw solid horizontal background from 'start' to 'end' */
191 static void draw_solid_bkg_H (const ProgressDrawInfo* di, int start, int end)
192 {
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);
199 }
200
201 /* draw solid vertical bar from 'start' to 'end' */
202 static void draw_solid_bar_V (const ProgressDrawInfo* di, int start, int end)
203 {
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);
210 }
211
212 /* draw solid vertical background from 'start' to 'end' */
213 static void draw_solid_bkg_V (const ProgressDrawInfo* di, int start, int end)
214 {
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);
221 }
222
223 /* draw chunky horizontal bar from 'start' to 'end' */
224 static void draw_chunk_bar_H (const ProgressDrawInfo* di, int start, int end)
225 {
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)
232     {
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;
239     }
240 }
241
242 /* draw chunky vertical bar from 'start' to 'end' */
243 static void draw_chunk_bar_V (const ProgressDrawInfo* di, int start, int end)
244 {
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)
251     {
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;
258     }
259 }
260
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,
273 };
274
275 /* draw themed horizontal bar from 'start' to 'end' */
276 static void draw_theme_bar_H (const ProgressDrawInfo* di, int start, int end)
277 {
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)
284     {
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;
291     }
292 }
293
294 /* draw themed horizontal bar from 'start' to 'end' */
295 static void draw_theme_bar_V (const ProgressDrawInfo* di, int start, int end)
296 {
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)
303     {
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;
310     }
311 }
312
313 /* draw themed horizontal background from 'start' to 'end' */
314 static void draw_theme_bkg_H (const ProgressDrawInfo* di, int start, int end)
315 {
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);
322 }
323
324 /* draw themed vertical background from 'start' to 'end' */
325 static void draw_theme_bkg_V (const ProgressDrawInfo* di, int start, int end)
326 {
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);
333 }
334
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,
347 };
348
349 /***********************************************************************
350  * PROGRESS_Draw
351  * Draws the progress bar.
352  */
353 static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
354 {
355     int barSize;
356     DWORD dwStyle;
357     BOOL barSmooth;
358     const ProgressDrawProc* drawProcs;
359     ProgressDrawInfo pdi;
360
361     TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc);
362
363     pdi.hdc = hdc;
364     pdi.theme = GetWindowTheme (infoPtr->Self);
365
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);
371
372     if (infoPtr->ColorBk == CLR_DEFAULT)
373         pdi.hbrBk = GetSysColorBrush(COLOR_3DFACE);
374     else
375         pdi.hbrBk = CreateSolidBrush(infoPtr->ColorBk);
376
377     /* get the window style */
378     dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
379
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);
385     }
386     else
387     {
388         RECT cntRect;
389         int part = (dwStyle & PBS_VERTICAL) ? PP_BARVERT : PP_BAR;
390         
391         GetThemeBackgroundContentRect (pdi.theme, hdc, part, 0, &pdi.rect, 
392             &cntRect);
393         
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);
402     }
403
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)
410     {
411         GetWindowRect( infoPtr->Self, &pdi.bgRect );
412         ScreenToClient( infoPtr->Self, (POINT*)&pdi.bgRect );
413         ScreenToClient( infoPtr->Self, (POINT*)&pdi.bgRect.right );
414     }
415
416     if (!barSmooth)
417         pdi.ledW = get_led_size( infoPtr, dwStyle, &pdi.rect);
418     pdi.ledGap = get_led_gap( infoPtr );
419
420     if (dwStyle & PBS_MARQUEE)
421     {
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;
425
426         if (ledMEnd > leds)
427         {
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);
432
433             drawProcs[0]( &pdi, 0, gapStart);
434             drawProcs[1]( &pdi, gapStart, gapEnd);
435             drawProcs[0]( &pdi, gapEnd, barSize);
436         }
437         else
438         {
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);
442
443             drawProcs[1]( &pdi, 0, barStart);
444             drawProcs[0]( &pdi, barStart, barEnd);
445             drawProcs[1]( &pdi, barEnd, barSize);
446         }
447     }
448     else
449     {
450         int barEnd = get_bar_position( infoPtr, dwStyle, &pdi.rect,
451             infoPtr->CurVal);
452         if (!barSmooth)
453         {
454             const int ledW = pdi.ledW + pdi.ledGap;
455             barEnd = min (((barEnd + ledW - 1) / ledW) * ledW, barSize);
456         }
457         drawProcs[0]( &pdi, 0, barEnd);
458         drawProcs[1]( &pdi, barEnd, barSize);
459     }
460
461     /* delete bar brush */
462     if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (pdi.hbrBar);
463     if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (pdi.hbrBk);
464
465     return 0;
466 }
467
468 /***********************************************************************
469  * PROGRESS_Paint
470  * Draw the progress bar. The background need not be erased.
471  * If dc!=0, it draws on it
472  */
473 static LRESULT PROGRESS_Paint (PROGRESS_INFO *infoPtr, HDC hdc)
474 {
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;
481 }
482
483
484 /***********************************************************************
485  * PROGRESS_Timer
486  * Handle the marquee timer messages
487  */
488 static LRESULT PROGRESS_Timer (PROGRESS_INFO *infoPtr, INT idTimer)
489 {
490     if(idTimer == ID_MARQUEE_TIMER)
491     {
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;
497
498         get_client_rect (infoPtr->Self, &rect);
499
500         if(!barSmooth)
501             ledWidth = get_led_size( infoPtr, style, &rect ) + 
502                 get_led_gap( infoPtr );
503         else
504             ledWidth = 1;
505
506         leds = (get_bar_size( style, &rect ) + ledWidth - 1) / 
507             ledWidth;
508
509         /* increment the marquee progress */
510         if(++infoPtr->MarqueePos >= leds)
511         {
512             infoPtr->MarqueePos = 0;
513         }
514
515         InvalidateRect(infoPtr->Self, &rect, FALSE);
516         UpdateWindow(infoPtr->Self);
517     }
518     return 0;
519 }
520
521
522 /***********************************************************************
523  *           PROGRESS_CoercePos
524  * Makes sure the current position (CurVal) is within bounds.
525  */
526 static void PROGRESS_CoercePos(PROGRESS_INFO *infoPtr)
527 {
528     if(infoPtr->CurVal < infoPtr->MinVal)
529         infoPtr->CurVal = infoPtr->MinVal;
530     if(infoPtr->CurVal > infoPtr->MaxVal)
531         infoPtr->CurVal = infoPtr->MaxVal;
532 }
533
534
535 /***********************************************************************
536  *           PROGRESS_SetFont
537  * Set new Font for progress bar
538  */
539 static HFONT PROGRESS_SetFont (PROGRESS_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
540 {
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;
545 }
546
547 static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high)
548 {
549     DWORD res = MAKELONG(LOWORD(infoPtr->MinVal), LOWORD(infoPtr->MaxVal));
550
551     /* if nothing changes, simply return */
552     if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res;
553
554     infoPtr->MinVal = low;
555     infoPtr->MaxVal = high;
556     PROGRESS_CoercePos(infoPtr);
557     InvalidateRect(infoPtr->Self, NULL, TRUE);
558     return res;
559 }
560
561 /***********************************************************************
562  *           ProgressWindowProc
563  */
564 static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
565                                          WPARAM wParam, LPARAM lParam)
566 {
567     PROGRESS_INFO *infoPtr;
568     static const WCHAR themeClass[] = {'P','r','o','g','r','e','s','s',0};
569     HTHEME theme;
570
571     TRACE("hwnd=%p msg=%04x wparam=%x lParam=%lx\n", hwnd, message, wParam, lParam);
572
573     infoPtr = (PROGRESS_INFO *)GetWindowLongPtrW(hwnd, 0);
574
575     if (!infoPtr && message != WM_CREATE)
576         return DefWindowProcW( hwnd, message, wParam, lParam );
577
578     switch(message) {
579     case WM_CREATE:
580     {
581         DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
582         
583         theme = OpenThemeData (hwnd, themeClass);
584
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);
591
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);
596
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;
608
609         TRACE("Progress Ctrl creation, hwnd=%p\n", hwnd);
610         return 0;
611     }
612
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;
620
621     case WM_ERASEBKGND:
622         return 1;
623
624     case WM_GETFONT:
625         return (LRESULT)infoPtr->Font;
626
627     case WM_SETFONT:
628         return (LRESULT)PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
629
630     case WM_PRINTCLIENT:
631     case WM_PAINT:
632         return PROGRESS_Paint (infoPtr, (HDC)wParam);
633
634     case WM_TIMER:
635         return PROGRESS_Timer (infoPtr, (INT)wParam);
636
637     case WM_THEMECHANGED:
638     {
639         DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
640         
641         theme = GetWindowTheme (hwnd);
642         CloseThemeData (theme);
643         theme = OpenThemeData (hwnd, themeClass);
644         
645         /* WS_EX_STATICEDGE disappears when the control is themed */
646         if (theme)
647             dwExStyle &= ~WS_EX_STATICEDGE;
648         else
649             dwExStyle |= WS_EX_STATICEDGE;
650         SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
651         
652         InvalidateRect (hwnd, NULL, FALSE);
653         return 0;
654     }
655
656     case PBM_DELTAPOS:
657     {
658         INT oldVal;
659         oldVal = infoPtr->CurVal;
660         if(wParam != 0) {
661             infoPtr->CurVal += (INT)wParam;
662             PROGRESS_CoercePos (infoPtr);
663             TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
664             PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
665             UpdateWindow( infoPtr->Self );
666         }
667         return oldVal;
668     }
669
670     case PBM_SETPOS:
671     {
672         UINT oldVal;
673         oldVal = infoPtr->CurVal;
674         if(oldVal != wParam) {
675             infoPtr->CurVal = (INT)wParam;
676             PROGRESS_CoercePos(infoPtr);
677             TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
678             PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
679             UpdateWindow( infoPtr->Self );
680         }
681         return oldVal;
682     }
683
684     case PBM_SETRANGE:
685         return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam));
686
687     case PBM_SETSTEP:
688     {
689         INT oldStep;
690         oldStep = infoPtr->Step;
691         infoPtr->Step = (INT)wParam;
692         return oldStep;
693     }
694
695     case PBM_STEPIT:
696     {
697         INT oldVal;
698         oldVal = infoPtr->CurVal;
699         infoPtr->CurVal += infoPtr->Step;
700         if(infoPtr->CurVal > infoPtr->MaxVal)
701             infoPtr->CurVal = infoPtr->MinVal;
702         if(oldVal != infoPtr->CurVal)
703         {
704             TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
705             PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
706             UpdateWindow( infoPtr->Self );
707         }
708         return oldVal;
709     }
710
711     case PBM_SETRANGE32:
712         return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam);
713
714     case PBM_GETRANGE:
715         if (lParam) {
716             ((PPBRANGE)lParam)->iLow = infoPtr->MinVal;
717             ((PPBRANGE)lParam)->iHigh = infoPtr->MaxVal;
718         }
719         return wParam ? infoPtr->MinVal : infoPtr->MaxVal;
720
721     case PBM_GETPOS:
722         return infoPtr->CurVal;
723
724     case PBM_SETBARCOLOR:
725         infoPtr->ColorBar = (COLORREF)lParam;
726         InvalidateRect(hwnd, NULL, TRUE);
727         return 0;
728
729     case PBM_SETBKCOLOR:
730         infoPtr->ColorBk = (COLORREF)lParam;
731         InvalidateRect(hwnd, NULL, TRUE);
732         return 0;
733
734     case PBM_SETMARQUEE:
735         if(wParam != 0)
736         {
737             infoPtr->Marquee = TRUE;
738             SetTimer(infoPtr->Self, ID_MARQUEE_TIMER, (UINT)lParam, NULL);
739         }
740         else
741         {
742             infoPtr->Marquee = FALSE;
743             KillTimer(infoPtr->Self, ID_MARQUEE_TIMER);
744         }
745         return infoPtr->Marquee;
746
747     default:
748         if ((message >= WM_USER) && (message < WM_APP))
749             ERR("unknown msg %04x wp=%04x lp=%08lx\n", message, wParam, lParam );
750         return DefWindowProcW( hwnd, message, wParam, lParam );
751     }
752 }
753
754
755 /***********************************************************************
756  * PROGRESS_Register [Internal]
757  *
758  * Registers the progress bar window class.
759  */
760 void PROGRESS_Register (void)
761 {
762     WNDCLASSW wndClass;
763
764     ZeroMemory (&wndClass, sizeof(wndClass));
765     wndClass.style         = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
766     wndClass.lpfnWndProc   = (WNDPROC)ProgressWindowProc;
767     wndClass.cbClsExtra    = 0;
768     wndClass.cbWndExtra    = sizeof (PROGRESS_INFO *);
769     wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
770     wndClass.lpszClassName = PROGRESS_CLASSW;
771
772     RegisterClassW (&wndClass);
773 }
774
775
776 /***********************************************************************
777  * PROGRESS_Unregister [Internal]
778  *
779  * Unregisters the progress bar window class.
780  */
781 void PROGRESS_Unregister (void)
782 {
783     UnregisterClassW (PROGRESS_CLASSW, NULL);
784 }