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