comctl32/progress: Use the global HeapAlloc() helpers.
[wine.git] / dlls / comctl32 / progress.c
blob62234b9bac815e13ff69acb82fb7777c2c77eef1
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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.
30 * TODO:
32 * Styles:
33 * -- PBS_SMOOTHREVERSE
37 #include <stdarg.h>
38 #include <string.h>
39 #include "windef.h"
40 #include "winbase.h"
41 #include "wingdi.h"
42 #include "winuser.h"
43 #include "winnls.h"
44 #include "commctrl.h"
45 #include "comctl32.h"
46 #include "uxtheme.h"
47 #include "vssym32.h"
48 #include "wine/debug.h"
49 #include "wine/heap.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(progress);
53 typedef struct
55 HWND Self; /* The window handle for this control */
56 INT CurVal; /* Current progress value */
57 INT MinVal; /* Minimum progress value */
58 INT MaxVal; /* Maximum progress value */
59 INT Step; /* Step to use on PMB_STEPIT */
60 INT MarqueePos; /* Marquee animation position */
61 BOOL Marquee; /* Whether the marquee animation is enabled */
62 COLORREF ColorBar; /* Bar color */
63 COLORREF ColorBk; /* Background color */
64 HFONT Font; /* Handle to font (not unused) */
65 } PROGRESS_INFO;
67 /* Control configuration constants */
69 #define LED_GAP 2
70 #define MARQUEE_LEDS 5
71 #define ID_MARQUEE_TIMER 1
72 #define DEFAULT_MARQUEE_PERIOD 30
74 /* Helper to obtain size of a progress bar chunk ("led"). */
75 static inline int get_led_size ( const PROGRESS_INFO *infoPtr, LONG style,
76 const RECT* rect )
78 HTHEME theme = GetWindowTheme (infoPtr->Self);
79 if (theme)
81 int chunkSize;
82 if (SUCCEEDED( GetThemeInt( theme, 0, 0, TMT_PROGRESSCHUNKSIZE, &chunkSize )))
83 return chunkSize;
86 if (style & PBS_VERTICAL)
87 return MulDiv (rect->right - rect->left, 2, 3);
88 else
89 return MulDiv (rect->bottom - rect->top, 2, 3);
92 /* Helper to obtain gap between progress bar chunks */
93 static inline int get_led_gap ( const PROGRESS_INFO *infoPtr )
95 HTHEME theme = GetWindowTheme (infoPtr->Self);
96 if (theme)
98 int spaceSize;
99 if (SUCCEEDED( GetThemeInt( theme, 0, 0, TMT_PROGRESSSPACESIZE, &spaceSize )))
100 return spaceSize;
103 return LED_GAP;
106 /* Get client rect. Takes into account that theming needs no adjustment. */
107 static inline void get_client_rect (HWND hwnd, RECT* rect)
109 HTHEME theme = GetWindowTheme (hwnd);
110 GetClientRect (hwnd, rect);
111 if (!theme)
112 InflateRect(rect, -1, -1);
113 else
115 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
116 int part = (dwStyle & PBS_VERTICAL) ? PP_BARVERT : PP_BAR;
117 GetThemeBackgroundContentRect (theme, 0, part, 0, rect, rect);
121 /* Compute the extend of the bar */
122 static inline int get_bar_size( LONG style, const RECT* rect )
124 if (style & PBS_VERTICAL)
125 return rect->bottom - rect->top;
126 else
127 return rect->right - rect->left;
130 /* Compute the pixel position of a progress value */
131 static inline int get_bar_position( const PROGRESS_INFO *infoPtr, LONG style,
132 const RECT* rect, INT value )
134 return MulDiv (value - infoPtr->MinVal, get_bar_size (style, rect),
135 infoPtr->MaxVal - infoPtr->MinVal);
138 /***********************************************************************
139 * PROGRESS_Invalidate
141 * Don't be too clever about invalidating the progress bar.
142 * InstallShield depends on this simple behaviour.
144 static void PROGRESS_Invalidate( const PROGRESS_INFO *infoPtr, INT old, INT new )
146 InvalidateRect( infoPtr->Self, NULL, old > new );
149 /* Information for a progress bar drawing helper */
150 typedef struct tagProgressDrawInfo
152 HDC hdc;
153 RECT rect;
154 HBRUSH hbrBar;
155 HBRUSH hbrBk;
156 int ledW, ledGap;
157 HTHEME theme;
158 RECT bgRect;
159 } ProgressDrawInfo;
161 typedef void (*ProgressDrawProc)(const ProgressDrawInfo* di, int start, int end);
163 /* draw solid horizontal bar from 'start' to 'end' */
164 static void draw_solid_bar_H (const ProgressDrawInfo* di, int start, int end)
166 RECT r;
167 SetRect(&r, di->rect.left + start, di->rect.top, di->rect.left + end, di->rect.bottom);
168 FillRect (di->hdc, &r, di->hbrBar);
171 /* draw solid horizontal background from 'start' to 'end' */
172 static void draw_solid_bkg_H (const ProgressDrawInfo* di, int start, int end)
174 RECT r;
175 SetRect(&r, di->rect.left + start, di->rect.top, di->rect.left + end, di->rect.bottom);
176 FillRect (di->hdc, &r, di->hbrBk);
179 /* draw solid vertical bar from 'start' to 'end' */
180 static void draw_solid_bar_V (const ProgressDrawInfo* di, int start, int end)
182 RECT r;
183 SetRect(&r, di->rect.left, di->rect.bottom - end, di->rect.right, di->rect.bottom - start);
184 FillRect (di->hdc, &r, di->hbrBar);
187 /* draw solid vertical background from 'start' to 'end' */
188 static void draw_solid_bkg_V (const ProgressDrawInfo* di, int start, int end)
190 RECT r;
191 SetRect(&r, di->rect.left, di->rect.bottom - end, di->rect.right, di->rect.bottom - start);
192 FillRect (di->hdc, &r, di->hbrBk);
195 /* draw chunky horizontal bar from 'start' to 'end' */
196 static void draw_chunk_bar_H (const ProgressDrawInfo* di, int start, int end)
198 RECT r;
199 int right = di->rect.left + end;
200 r.left = di->rect.left + start;
201 r.top = di->rect.top;
202 r.bottom = di->rect.bottom;
203 while (r.left < right)
205 r.right = min (r.left + di->ledW, right);
206 FillRect (di->hdc, &r, di->hbrBar);
207 r.left = r.right;
208 r.right = min (r.left + di->ledGap, right);
209 FillRect (di->hdc, &r, di->hbrBk);
210 r.left = r.right;
214 /* draw chunky vertical bar from 'start' to 'end' */
215 static void draw_chunk_bar_V (const ProgressDrawInfo* di, int start, int end)
217 RECT r;
218 int top = di->rect.bottom - end;
219 r.left = di->rect.left;
220 r.right = di->rect.right;
221 r.bottom = di->rect.bottom - start;
222 while (r.bottom > top)
224 r.top = max (r.bottom - di->ledW, top);
225 FillRect (di->hdc, &r, di->hbrBar);
226 r.bottom = r.top;
227 r.top = max (r.bottom - di->ledGap, top);
228 FillRect (di->hdc, &r, di->hbrBk);
229 r.bottom = r.top;
233 /* drawing functions for "classic" style */
234 static const ProgressDrawProc drawProcClassic[8] = {
235 /* Smooth */
236 /* Horizontal */
237 draw_solid_bar_H, draw_solid_bkg_H,
238 /* Vertical */
239 draw_solid_bar_V, draw_solid_bkg_V,
240 /* Chunky */
241 /* Horizontal */
242 draw_chunk_bar_H, draw_solid_bkg_H,
243 /* Vertical */
244 draw_chunk_bar_V, draw_solid_bkg_V,
247 /* draw themed horizontal bar from 'start' to 'end' */
248 static void draw_theme_bar_H (const ProgressDrawInfo* di, int start, int end)
250 RECT r;
251 r.left = di->rect.left + start;
252 r.top = di->rect.top;
253 r.bottom = di->rect.bottom;
254 r.right = di->rect.left + end;
255 DrawThemeBackground (di->theme, di->hdc, PP_CHUNK, 0, &r, NULL);
258 /* draw themed vertical bar from 'start' to 'end' */
259 static void draw_theme_bar_V (const ProgressDrawInfo* di, int start, int end)
261 RECT r;
262 r.left = di->rect.left;
263 r.right = di->rect.right;
264 r.bottom = di->rect.bottom - start;
265 r.top = di->rect.bottom - end;
266 DrawThemeBackground (di->theme, di->hdc, PP_CHUNKVERT, 0, &r, NULL);
269 /* draw themed horizontal background from 'start' to 'end' */
270 static void draw_theme_bkg_H (const ProgressDrawInfo* di, int start, int end)
272 RECT bgrect, r;
274 SetRect(&r, di->rect.left + start, di->rect.top, di->rect.left + end, di->rect.bottom);
275 bgrect = di->bgRect;
276 OffsetRect(&bgrect, -bgrect.left, -bgrect.top);
278 DrawThemeBackground (di->theme, di->hdc, PP_BAR, 0, &bgrect, &r);
281 /* draw themed vertical background from 'start' to 'end' */
282 static void draw_theme_bkg_V (const ProgressDrawInfo* di, int start, int end)
284 RECT bgrect, r;
286 SetRect(&r, di->rect.left, di->rect.bottom - end, di->rect.right, di->rect.bottom - start);
287 bgrect = di->bgRect;
288 OffsetRect(&bgrect, -bgrect.left, -bgrect.top);
290 DrawThemeBackground (di->theme, di->hdc, PP_BARVERT, 0, &bgrect, &r);
293 /* drawing functions for themed style */
294 static const ProgressDrawProc drawProcThemed[8] = {
295 /* Smooth */
296 /* Horizontal */
297 draw_theme_bar_H, draw_theme_bkg_H,
298 /* Vertical */
299 draw_theme_bar_V, draw_theme_bkg_V,
300 /* Chunky */
301 /* Horizontal */
302 draw_theme_bar_H, draw_theme_bkg_H,
303 /* Vertical */
304 draw_theme_bar_V, draw_theme_bkg_V,
307 /***********************************************************************
308 * PROGRESS_Draw
309 * Draws the progress bar.
311 static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
313 int barSize;
314 DWORD dwStyle;
315 BOOL barSmooth;
316 const ProgressDrawProc* drawProcs;
317 ProgressDrawInfo pdi;
319 TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc);
321 pdi.hdc = hdc;
322 pdi.theme = GetWindowTheme (infoPtr->Self);
324 /* get the required bar brush */
325 if (infoPtr->ColorBar == CLR_DEFAULT)
326 pdi.hbrBar = GetSysColorBrush(COLOR_HIGHLIGHT);
327 else
328 pdi.hbrBar = CreateSolidBrush (infoPtr->ColorBar);
330 if (infoPtr->ColorBk == CLR_DEFAULT)
331 pdi.hbrBk = GetSysColorBrush(COLOR_3DFACE);
332 else
333 pdi.hbrBk = CreateSolidBrush(infoPtr->ColorBk);
335 /* get the window style */
336 dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
338 /* get client rectangle */
339 GetClientRect (infoPtr->Self, &pdi.rect);
340 if (!pdi.theme) {
341 FrameRect( hdc, &pdi.rect, pdi.hbrBk );
342 InflateRect(&pdi.rect, -1, -1);
344 else
346 RECT cntRect;
347 int part = (dwStyle & PBS_VERTICAL) ? PP_BARVERT : PP_BAR;
349 GetThemeBackgroundContentRect (pdi.theme, hdc, part, 0, &pdi.rect,
350 &cntRect);
352 /* Exclude content rect - content background will be drawn later */
353 ExcludeClipRect (hdc, cntRect.left, cntRect.top,
354 cntRect.right, cntRect.bottom);
355 if (IsThemeBackgroundPartiallyTransparent (pdi.theme, part, 0))
356 DrawThemeParentBackground (infoPtr->Self, hdc, NULL);
357 DrawThemeBackground (pdi.theme, hdc, part, 0, &pdi.rect, NULL);
358 SelectClipRgn (hdc, NULL);
359 pdi.rect = cntRect;
362 /* compute some drawing parameters */
363 barSmooth = (dwStyle & PBS_SMOOTH) && !pdi.theme;
364 drawProcs = &((pdi.theme ? drawProcThemed : drawProcClassic)[(barSmooth ? 0 : 4)
365 + ((dwStyle & PBS_VERTICAL) ? 2 : 0)]);
366 barSize = get_bar_size( dwStyle, &pdi.rect );
367 if (pdi.theme)
369 GetWindowRect( infoPtr->Self, &pdi.bgRect );
370 MapWindowPoints( infoPtr->Self, 0, (POINT*)&pdi.bgRect, 2 );
373 if (!barSmooth)
374 pdi.ledW = get_led_size( infoPtr, dwStyle, &pdi.rect);
375 pdi.ledGap = get_led_gap( infoPtr );
377 if (dwStyle & PBS_MARQUEE)
379 const int ledW = !barSmooth ? (pdi.ledW + pdi.ledGap) : 1;
380 const int leds = (barSize + ledW - 1) / ledW;
381 const int ledMEnd = infoPtr->MarqueePos + MARQUEE_LEDS;
383 if (ledMEnd > leds)
385 /* case 1: the marquee bar extends over the end and wraps around to
386 * the start */
387 const int gapStart = max((ledMEnd - leds) * ledW, 0);
388 const int gapEnd = min(infoPtr->MarqueePos * ledW, barSize);
390 drawProcs[0]( &pdi, 0, gapStart);
391 drawProcs[1]( &pdi, gapStart, gapEnd);
392 drawProcs[0]( &pdi, gapEnd, barSize);
394 else
396 /* case 2: the marquee bar is between start and end */
397 const int barStart = infoPtr->MarqueePos * ledW;
398 const int barEnd = min (ledMEnd * ledW, barSize);
400 drawProcs[1]( &pdi, 0, barStart);
401 drawProcs[0]( &pdi, barStart, barEnd);
402 drawProcs[1]( &pdi, barEnd, barSize);
405 else
407 int barEnd = get_bar_position( infoPtr, dwStyle, &pdi.rect,
408 infoPtr->CurVal);
409 if (!barSmooth)
411 const int ledW = pdi.ledW + pdi.ledGap;
412 barEnd = min (((barEnd + ledW - 1) / ledW) * ledW, barSize);
414 drawProcs[0]( &pdi, 0, barEnd);
415 drawProcs[1]( &pdi, barEnd, barSize);
418 /* delete bar brush */
419 if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (pdi.hbrBar);
420 if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (pdi.hbrBk);
422 return 0;
425 /***********************************************************************
426 * PROGRESS_Paint
427 * Draw the progress bar. The background need not be erased.
428 * If dc!=0, it draws on it
430 static LRESULT PROGRESS_Paint (PROGRESS_INFO *infoPtr, HDC hdc)
432 PAINTSTRUCT ps;
433 if (hdc) return PROGRESS_Draw (infoPtr, hdc);
434 hdc = BeginPaint (infoPtr->Self, &ps);
435 PROGRESS_Draw (infoPtr, hdc);
436 EndPaint (infoPtr->Self, &ps);
437 return 0;
441 /***********************************************************************
442 * Advance marquee progress by one step.
444 static void PROGRESS_UpdateMarquee (PROGRESS_INFO *infoPtr)
446 LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
447 RECT rect;
448 int ledWidth, leds;
449 HTHEME theme = GetWindowTheme (infoPtr->Self);
450 BOOL smooth = (style & PBS_SMOOTH) && !theme;
452 get_client_rect (infoPtr->Self, &rect);
454 if (smooth)
455 ledWidth = 1;
456 else
457 ledWidth = get_led_size( infoPtr, style, &rect ) + get_led_gap( infoPtr );
459 leds = (get_bar_size( style, &rect ) + ledWidth - 1) /
460 ledWidth;
462 /* increment the marquee progress */
463 if (++infoPtr->MarqueePos >= leds)
464 infoPtr->MarqueePos = 0;
466 InvalidateRect(infoPtr->Self, &rect, TRUE);
467 UpdateWindow(infoPtr->Self);
471 /***********************************************************************
472 * PROGRESS_CoercePos
473 * Makes sure the current position (CurVal) is within bounds.
475 static void PROGRESS_CoercePos(PROGRESS_INFO *infoPtr)
477 if(infoPtr->CurVal < infoPtr->MinVal)
478 infoPtr->CurVal = infoPtr->MinVal;
479 if(infoPtr->CurVal > infoPtr->MaxVal)
480 infoPtr->CurVal = infoPtr->MaxVal;
484 /***********************************************************************
485 * PROGRESS_SetFont
486 * Set new Font for progress bar
488 static HFONT PROGRESS_SetFont (PROGRESS_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
490 HFONT hOldFont = infoPtr->Font;
491 infoPtr->Font = hFont;
492 /* Since infoPtr->Font is not used, there is no need for repaint */
493 return hOldFont;
496 static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high)
498 DWORD res = MAKELONG(LOWORD(infoPtr->MinVal), LOWORD(infoPtr->MaxVal));
500 /* if nothing changes, simply return */
501 if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res;
503 infoPtr->MinVal = low;
504 infoPtr->MaxVal = high;
505 PROGRESS_CoercePos(infoPtr);
506 InvalidateRect(infoPtr->Self, NULL, TRUE);
507 return res;
510 static UINT PROGRESS_SetPos (PROGRESS_INFO *infoPtr, INT pos)
512 DWORD style = GetWindowLongW(infoPtr->Self, GWL_STYLE);
514 if (style & PBS_MARQUEE)
516 PROGRESS_UpdateMarquee(infoPtr);
517 return 1;
519 else
521 UINT oldVal;
522 oldVal = infoPtr->CurVal;
523 if (oldVal != pos) {
524 infoPtr->CurVal = pos;
525 PROGRESS_CoercePos(infoPtr);
526 TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
527 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
528 UpdateWindow( infoPtr->Self );
530 return oldVal;
534 /***********************************************************************
535 * ProgressWindowProc
537 static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
538 WPARAM wParam, LPARAM lParam)
540 PROGRESS_INFO *infoPtr;
541 static const WCHAR themeClass[] = {'P','r','o','g','r','e','s','s',0};
542 HTHEME theme;
544 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
546 infoPtr = (PROGRESS_INFO *)GetWindowLongPtrW(hwnd, 0);
548 if (!infoPtr && message != WM_CREATE)
549 return DefWindowProcW( hwnd, message, wParam, lParam );
551 switch(message) {
552 case WM_CREATE:
554 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
556 theme = OpenThemeData (hwnd, themeClass);
558 dwExStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE);
559 if (!theme) dwExStyle |= WS_EX_STATICEDGE;
560 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
561 /* Force recalculation of a non-client area */
562 SetWindowPos(hwnd, 0, 0, 0, 0, 0,
563 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
565 /* allocate memory for info struct */
566 infoPtr = heap_alloc_zero (sizeof(*infoPtr));
567 if (!infoPtr) return -1;
568 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
570 /* initialize the info struct */
571 infoPtr->Self = hwnd;
572 infoPtr->MinVal = 0;
573 infoPtr->MaxVal = 100;
574 infoPtr->CurVal = 0;
575 infoPtr->Step = 10;
576 infoPtr->MarqueePos = 0;
577 infoPtr->Marquee = FALSE;
578 infoPtr->ColorBar = CLR_DEFAULT;
579 infoPtr->ColorBk = CLR_DEFAULT;
580 infoPtr->Font = 0;
582 TRACE("Progress Ctrl creation, hwnd=%p\n", hwnd);
583 return 0;
586 case WM_DESTROY:
587 TRACE("Progress Ctrl destruction, hwnd=%p\n", hwnd);
588 heap_free (infoPtr);
589 SetWindowLongPtrW(hwnd, 0, 0);
590 theme = GetWindowTheme (hwnd);
591 CloseThemeData (theme);
592 return 0;
594 case WM_ERASEBKGND:
595 return 1;
597 case WM_GETFONT:
598 return (LRESULT)infoPtr->Font;
600 case WM_SETFONT:
601 return (LRESULT)PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
603 case WM_PRINTCLIENT:
604 case WM_PAINT:
605 return PROGRESS_Paint (infoPtr, (HDC)wParam);
607 case WM_TIMER:
608 if (wParam == ID_MARQUEE_TIMER)
609 PROGRESS_UpdateMarquee (infoPtr);
610 return 0;
612 case WM_THEMECHANGED:
614 DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
616 theme = GetWindowTheme (hwnd);
617 CloseThemeData (theme);
618 theme = OpenThemeData (hwnd, themeClass);
620 /* WS_EX_STATICEDGE disappears when the control is themed */
621 if (theme)
622 dwExStyle &= ~WS_EX_STATICEDGE;
623 else
624 dwExStyle |= WS_EX_STATICEDGE;
625 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
627 InvalidateRect (hwnd, NULL, FALSE);
628 return 0;
631 case PBM_DELTAPOS:
633 INT oldVal;
634 oldVal = infoPtr->CurVal;
635 if(wParam != 0) {
636 infoPtr->CurVal += (INT)wParam;
637 PROGRESS_CoercePos (infoPtr);
638 TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
639 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
640 UpdateWindow( infoPtr->Self );
642 return oldVal;
645 case PBM_SETPOS:
646 return PROGRESS_SetPos(infoPtr, wParam);
648 case PBM_SETRANGE:
649 return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam));
651 case PBM_SETSTEP:
653 INT oldStep;
654 oldStep = infoPtr->Step;
655 infoPtr->Step = (INT)wParam;
656 return oldStep;
659 case PBM_GETSTEP:
660 return infoPtr->Step;
662 case PBM_STEPIT:
664 INT oldVal;
665 oldVal = infoPtr->CurVal;
666 infoPtr->CurVal += infoPtr->Step;
667 if(infoPtr->CurVal > infoPtr->MaxVal)
668 infoPtr->CurVal = infoPtr->MinVal;
669 if(oldVal != infoPtr->CurVal)
671 TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
672 PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
673 UpdateWindow( infoPtr->Self );
675 return oldVal;
678 case PBM_SETRANGE32:
679 return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam);
681 case PBM_GETRANGE:
682 if (lParam) {
683 ((PPBRANGE)lParam)->iLow = infoPtr->MinVal;
684 ((PPBRANGE)lParam)->iHigh = infoPtr->MaxVal;
686 return wParam ? infoPtr->MinVal : infoPtr->MaxVal;
688 case PBM_GETPOS:
689 return infoPtr->CurVal;
691 case PBM_SETBARCOLOR:
693 COLORREF clr = infoPtr->ColorBar;
695 infoPtr->ColorBar = (COLORREF)lParam;
696 InvalidateRect(hwnd, NULL, TRUE);
697 return clr;
700 case PBM_GETBARCOLOR:
701 return infoPtr->ColorBar;
703 case PBM_SETBKCOLOR:
705 COLORREF clr = infoPtr->ColorBk;
707 infoPtr->ColorBk = (COLORREF)lParam;
708 InvalidateRect(hwnd, NULL, TRUE);
709 return clr;
712 case PBM_GETBKCOLOR:
713 return infoPtr->ColorBk;
715 case PBM_SETSTATE:
716 if(wParam != PBST_NORMAL)
717 FIXME("state %04lx not yet handled\n", wParam);
718 return PBST_NORMAL;
720 case PBM_GETSTATE:
721 return PBST_NORMAL;
723 case PBM_SETMARQUEE:
724 if(wParam != 0)
726 UINT period = lParam ? (UINT)lParam : DEFAULT_MARQUEE_PERIOD;
727 infoPtr->Marquee = TRUE;
728 SetTimer(infoPtr->Self, ID_MARQUEE_TIMER, period, NULL);
730 else
732 infoPtr->Marquee = FALSE;
733 KillTimer(infoPtr->Self, ID_MARQUEE_TIMER);
735 return infoPtr->Marquee;
737 default:
738 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
739 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
740 return DefWindowProcW( hwnd, message, wParam, lParam );
745 /***********************************************************************
746 * PROGRESS_Register [Internal]
748 * Registers the progress bar window class.
750 void PROGRESS_Register (void)
752 WNDCLASSW wndClass;
754 ZeroMemory (&wndClass, sizeof(wndClass));
755 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
756 wndClass.lpfnWndProc = ProgressWindowProc;
757 wndClass.cbClsExtra = 0;
758 wndClass.cbWndExtra = sizeof (PROGRESS_INFO *);
759 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
760 wndClass.lpszClassName = PROGRESS_CLASSW;
762 RegisterClassW (&wndClass);
766 /***********************************************************************
767 * PROGRESS_Unregister [Internal]
769 * Unregisters the progress bar window class.
771 void PROGRESS_Unregister (void)
773 UnregisterClassW (PROGRESS_CLASSW, NULL);