* Sync up to trunk head (r64377).
[reactos.git] / dll / win32 / comctl32 / progress.c
index 1c52316..18aa4c9 100644 (file)
@@ -57,6 +57,7 @@ typedef struct
 #define LED_GAP           2
 #define MARQUEE_LEDS      5
 #define ID_MARQUEE_TIMER  1
+#define DEFAULT_MARQUEE_PERIOD 30
 
 /* Helper to obtain size of a progress bar chunk ("led"). */
 static inline int get_led_size ( const PROGRESS_INFO *infoPtr, LONG style,
@@ -436,40 +437,32 @@ static LRESULT PROGRESS_Paint (PROGRESS_INFO *infoPtr, HDC hdc)
 
 
 /***********************************************************************
- * PROGRESS_Timer
- * Handle the marquee timer messages
+ * Advance marquee progress by one step.
  */
-static LRESULT PROGRESS_Timer (PROGRESS_INFO *infoPtr, INT idTimer)
+static void PROGRESS_UpdateMarquee (PROGRESS_INFO *infoPtr)
 {
-    if(idTimer == ID_MARQUEE_TIMER)
-    {
-        LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
-        RECT rect;
-        int ledWidth, leds;
-        HTHEME theme = GetWindowTheme (infoPtr->Self);
-        BOOL barSmooth = (style & PBS_SMOOTH) && !theme;
+    LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
+    RECT rect;
+    int ledWidth, leds;
+    HTHEME theme = GetWindowTheme (infoPtr->Self);
+    BOOL smooth = (style & PBS_SMOOTH) && !theme;
 
-        get_client_rect (infoPtr->Self, &rect);
+    get_client_rect (infoPtr->Self, &rect);
 
-        if(!barSmooth)
-            ledWidth = get_led_size( infoPtr, style, &rect ) + 
-                get_led_gap( infoPtr );
-        else
-            ledWidth = 1;
+    if (smooth)
+        ledWidth = 1;
+    else
+        ledWidth = get_led_size( infoPtr, style, &rect ) + get_led_gap( infoPtr );
 
-        leds = (get_bar_size( style, &rect ) + ledWidth - 1) / 
-            ledWidth;
+    leds = (get_bar_size( style, &rect ) + ledWidth - 1) /
+        ledWidth;
 
-        /* increment the marquee progress */
-        if(++infoPtr->MarqueePos >= leds)
-        {
-            infoPtr->MarqueePos = 0;
-        }
+    /* increment the marquee progress */
+    if (++infoPtr->MarqueePos >= leds)
+        infoPtr->MarqueePos = 0;
 
-        InvalidateRect(infoPtr->Self, &rect, FALSE);
-        UpdateWindow(infoPtr->Self);
-    }
-    return 0;
+    InvalidateRect(infoPtr->Self, &rect, TRUE);
+    UpdateWindow(infoPtr->Self);
 }
 
 
@@ -512,6 +505,30 @@ static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high)
     return res;
 }
 
+static UINT PROGRESS_SetPos (PROGRESS_INFO *infoPtr, INT pos)
+{
+    DWORD style = GetWindowLongW(infoPtr->Self, GWL_STYLE);
+
+    if (style & PBS_MARQUEE)
+    {
+        PROGRESS_UpdateMarquee(infoPtr);
+        return 1;
+    }
+    else
+    {
+        UINT oldVal;
+        oldVal = infoPtr->CurVal;
+        if (oldVal != pos) {
+           infoPtr->CurVal = pos;
+           PROGRESS_CoercePos(infoPtr);
+           TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
+            PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
+            UpdateWindow( infoPtr->Self );
+        }
+        return oldVal;
+    }
+}
+
 /***********************************************************************
  *           ProgressWindowProc
  */
@@ -586,7 +603,9 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
         return PROGRESS_Paint (infoPtr, (HDC)wParam);
 
     case WM_TIMER:
-        return PROGRESS_Timer (infoPtr, (INT)wParam);
+        if (wParam == ID_MARQUEE_TIMER)
+            PROGRESS_UpdateMarquee (infoPtr);
+        return 0;
 
     case WM_THEMECHANGED:
     {
@@ -622,18 +641,7 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
     }
 
     case PBM_SETPOS:
-    {
-        UINT oldVal;
-        oldVal = infoPtr->CurVal;
-        if(oldVal != wParam) {
-           infoPtr->CurVal = (INT)wParam;
-           PROGRESS_CoercePos(infoPtr);
-           TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
-            PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
-            UpdateWindow( infoPtr->Self );
-        }
-        return oldVal;
-    }
+        return PROGRESS_SetPos(infoPtr, wParam);
 
     case PBM_SETRANGE:
         return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam));
@@ -713,8 +721,9 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
     case PBM_SETMARQUEE:
        if(wParam != 0)
         {
+            UINT period = lParam ? (UINT)lParam : DEFAULT_MARQUEE_PERIOD;
             infoPtr->Marquee = TRUE;
-            SetTimer(infoPtr->Self, ID_MARQUEE_TIMER, (UINT)lParam, NULL);
+            SetTimer(infoPtr->Self, ID_MARQUEE_TIMER, period, NULL);
         }
         else
         {