>From d97453c4a980fb6c1cc2d21f6d56fc5891e348d2 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Mon, 19 Sep 2011 11:16:43 +0400
Subject: [PATCH 3/3] Fix MCM_SETSELRANGE for multiple calendars case

---
 dlls/comctl32/monthcal.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/dlls/comctl32/monthcal.c b/dlls/comctl32/monthcal.c
index d757c31..8fcdf28 100644
--- a/dlls/comctl32/monthcal.c
+++ b/dlls/comctl32/monthcal.c
@@ -1564,6 +1564,7 @@ static LRESULT
 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
 {
   SYSTEMTIME old_range[2];
+  INT diff;
 
   TRACE("%p\n", range);
 
@@ -1590,7 +1591,21 @@ MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
     infoPtr->minSel = range[1];
     infoPtr->maxSel = range[0];
   }
-  infoPtr->calendars[0].month = infoPtr->minSel;
+
+  diff = MONTHCAL_MonthDiff(&infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month, &infoPtr->maxSel);
+  if (diff < 0)
+  {
+    diff = MONTHCAL_MonthDiff(&infoPtr->calendars[0].month, &infoPtr->maxSel);
+    if (diff > 0) diff = 0;
+  }
+
+  if (diff != 0)
+  {
+    INT i;
+
+    for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
+      MONTHCAL_GetMonth(&infoPtr->calendars[i].month, diff);
+  }
 
   /* update day of week */
   MONTHCAL_CalculateDayOfWeek(&infoPtr->minSel, TRUE);
-- 
1.5.6.5


