r15813 - gnucash/trunk/src - GncDenseCal supports Monday being the start of the week.

Josh Sled jsled at cvs.gnucash.org
Wed Apr 4 20:43:09 EDT 2007


Author: jsled
Date: 2007-04-04 20:43:09 -0400 (Wed, 04 Apr 2007)
New Revision: 15813
Trac: http://svn.gnucash.org/trac/changeset/15813

Modified:
   gnucash/trunk/src/doc/sx.rst
   gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
   gnucash/trunk/src/gnome-utils/gnc-dense-cal.h
Log:
GncDenseCal supports Monday being the start of the week.


Modified: gnucash/trunk/src/doc/sx.rst
===================================================================
--- gnucash/trunk/src/doc/sx.rst	2007-04-05 00:24:38 UTC (rev 15812)
+++ gnucash/trunk/src/doc/sx.rst	2007-04-05 00:43:09 UTC (rev 15813)
@@ -92,8 +92,8 @@
   - [x] {0, 1, 2, 3, 4, 6, 12} month selection for dense calendar
     - [x] conf-save value
   - [ ] code cleanup
-    - [ ] min-size
-  - [ ] start-of-week := {sun,mon} (via locale)
+    - [x] min-size
+  - [/] start-of-week := {sun,mon} (via locale)
   - [ ] change number-of-month properties to display-named properties (width, length)
   - [ ] gconf setting for dense-cal font-size reduction
   - [?] better transient/floating window

Modified: gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-dense-cal.c	2007-04-05 00:24:38 UTC (rev 15812)
+++ gnucash/trunk/src/gnome-utils/gnc-dense-cal.c	2007-04-05 00:43:09 UTC (rev 15813)
@@ -430,6 +430,8 @@
 
     dcal->initialized = TRUE;
 
+    dcal->week_starts_monday = 1;
+
     gtk_widget_pop_composite_child();
 
     gtk_widget_show_all(GTK_WIDGET(dcal));
@@ -769,11 +771,19 @@
 
     g_date_clear(&date, 1);
     g_date_set_dmy(&date, 1, dcal->month, dcal->year);
-    start_week = g_date_get_sunday_week_of_year(&date);
+    start_week = (dcal->week_starts_monday
+                  ? g_date_get_monday_week_of_year(&date)
+                  : g_date_get_sunday_week_of_year(&date));
     g_date_add_months(&date, dcal->numMonths);
-    end_week = g_date_get_sunday_week_of_year(&date);
+    end_week = (dcal->week_starts_monday
+                ? g_date_get_monday_week_of_year(&date)
+                : g_date_get_sunday_week_of_year(&date));
     if (g_date_get_year(&date) != dcal->year)
-        end_week += g_date_get_sunday_weeks_in_year(dcal->year);
+    {
+        end_week += (dcal->week_starts_monday
+                     ? g_date_get_monday_weeks_in_year(dcal->year)
+                     : g_date_get_sunday_weeks_in_year(dcal->year));
+    }
     dcal->num_weeks = end_week - start_week + 1;
 }
 
@@ -968,15 +978,17 @@
             {
                 int day_label_width;
                 gint label_x_offset, label_y_offset;
+                const gchar *day_label_str;
 
-                pango_layout_set_text(layout, day_label(j), -1);
+                day_label_str = day_label((j + dcal->week_starts_monday) % 7);
+                pango_layout_set_text(layout, day_label_str, -1);
                 pango_layout_get_pixel_size(layout, &day_label_width, NULL);
                 label_x_offset = x
                     + (j * day_width(dcal))
                     + (day_width(dcal)/2)
                     - (day_label_width / 2);
                 label_y_offset = y - dcal->dayLabelHeight;
-                pango_layout_set_text(layout, day_label(j), -1);
+                pango_layout_set_text(layout, day_label_str, -1);
                 gdk_draw_layout(GDK_DRAWABLE(dcal->drawbuf), widget->style->fg_gc[widget->state],
                                 label_x_offset, label_y_offset,
                                 layout);
@@ -1282,11 +1294,17 @@
                                        - ((i-1)
                                           * dcal->monthsPerCol))));
         g_date_subtract_days(end, 1);
-        startWeek = g_date_get_sunday_week_of_year(start);
-        endWeek = g_date_get_sunday_week_of_year(end);
+        startWeek = (dcal->week_starts_monday
+                     ? g_date_get_monday_week_of_year(start)
+                     : g_date_get_sunday_week_of_year(start));
+        endWeek = (dcal->week_starts_monday
+                   ? g_date_get_monday_week_of_year(end)
+                   : g_date_get_sunday_week_of_year(end));
         if (endWeek < startWeek)
         {
-            endWeek += g_date_get_sunday_weeks_in_year(g_date_get_year(start));
+            endWeek += (dcal->week_starts_monday
+                        ? g_date_get_monday_weeks_in_year(g_date_get_year(start))
+                        : g_date_get_sunday_weeks_in_year(g_date_get_year(start)));
         }
         num_weeks_toRet = MAX(num_weeks_toRet, (endWeek - startWeek)+1);
     }
@@ -1327,20 +1345,26 @@
                        ((dcal->month - 1 + monthOffset) % 12) + 1,
                        dcal->year + floor((dcal->month-1+monthOffset)/12));
         /* get the week of the top of the column */
-        startWk = g_date_get_sunday_week_of_year(startD);
+        startWk = (dcal->week_starts_monday
+                   ? g_date_get_monday_week_of_year(startD)
+                   : g_date_get_sunday_week_of_year(startD));
         /* get the week of the end of the previous months */
         *endD = *startD;
         g_date_add_months(endD, previousMonthsInCol);
         g_date_subtract_days(endD, 1);
-        endWk = g_date_get_sunday_week_of_year(endD);
+        endWk = (dcal->week_starts_monday
+                 ? g_date_get_monday_week_of_year(endD)
+                 : g_date_get_sunday_week_of_year(endD));
         if (endWk < startWk)
         {
-            endWk += g_date_get_sunday_weeks_in_year(g_date_get_year(startD));
+            endWk += (dcal->week_starts_monday
+                      ? g_date_get_monday_weeks_in_year(g_date_get_year(startD))
+                      : g_date_get_sunday_weeks_in_year(g_date_get_year(startD)));
         }
         /* determine how many weeks are before the month we're
          * interested in. */
         weekRow = endWk - startWk;
-        if (g_date_get_weekday(endD) == G_DATE_SATURDAY)
+        if (g_date_get_weekday(endD) == (dcal->week_starts_monday ? G_DATE_SUNDAY : G_DATE_SATURDAY))
         {
             weekRow++;
         }
@@ -1354,7 +1378,7 @@
     g_date_subtract_days(endD, 1);
     /* Get the first week. */
     {
-        start = g_date_get_weekday(startD) % 7;
+        start = (g_date_get_weekday(startD) - dcal->week_starts_monday) % 7;
         rect = g_new0(GdkRectangle, 1);
         rect->x = dcal->leftPadding
             + MINOR_BORDER_SIZE
@@ -1375,8 +1399,12 @@
     {
         gint i, weekStart, weekEnd;
 
-        weekStart = g_date_get_sunday_week_of_year(startD)+1;
-        weekEnd = g_date_get_sunday_week_of_year(endD);
+        weekStart = (dcal->week_starts_monday
+                     ? g_date_get_monday_week_of_year(startD)
+                     : g_date_get_sunday_week_of_year(startD))+1;
+        weekEnd = (dcal->week_starts_monday
+                   ? g_date_get_monday_week_of_year(endD)
+                   : g_date_get_sunday_week_of_year(endD));
         for (i=weekStart; i<weekEnd; i++) {
             rect = g_new0(GdkRectangle, 1);
             rect->x = dcal->leftPadding
@@ -1397,6 +1425,14 @@
         
     /* Get the last week. */
     {
+        gint end_week_of_year = g_date_get_sunday_week_of_year(endD);
+        gint start_week_of_year = g_date_get_sunday_week_of_year(startD);
+        if (dcal->week_starts_monday == 1)
+        {
+            end_week_of_year = g_date_get_monday_week_of_year(endD);
+            start_week_of_year = g_date_get_monday_week_of_year(startD);
+        }
+
         rect = g_new0(GdkRectangle, 1);
         rect->x = dcal->leftPadding
             + MINOR_BORDER_SIZE
@@ -1406,10 +1442,9 @@
             + MINOR_BORDER_SIZE
             + dcal->dayLabelHeight
             + ((weekRow
-                + (g_date_get_sunday_week_of_year(endD)
-                   - g_date_get_sunday_week_of_year(startD)))
+                + (end_week_of_year - start_week_of_year))
                * week_height(dcal));
-        rect->width = ((g_date_get_weekday(endD) % 7)+1) * day_width(dcal);
+        rect->width = (((g_date_get_weekday(endD) - dcal->week_starts_monday) % 7)+1) * day_width(dcal);
         rect->height = week_height(dcal);
 
         *outList = g_list_append(*outList, (gpointer)rect);
@@ -1439,14 +1474,26 @@
         docMonth += 12;
     }
     colNum  = floor((float)(docMonth - dcal->month) / (float)dcal->monthsPerCol);
-    dayCol  = g_date_get_weekday(&d) % 7;
+    dayCol  = (g_date_get_weekday(&d) - dcal->week_starts_monday) % 7;
     d_week_of_cal = g_date_get_sunday_week_of_year(&d);
+    if (dcal->week_starts_monday == 1)
+    {
+        d_week_of_cal = g_date_get_monday_week_of_year(&d);
+    }
     g_date_set_dmy(&d, 1, dcal->month, dcal->year);
     g_date_add_months(&d, (colNum * dcal->monthsPerCol));
-    top_of_col_week_of_cal = g_date_get_sunday_week_of_year(&d);
+    top_of_col_week_of_cal = (dcal->week_starts_monday
+                              ? g_date_get_monday_week_of_year(&d)
+                              : g_date_get_sunday_week_of_year(&d));
     if (d_week_of_cal < top_of_col_week_of_cal)
     {
-        d_week_of_cal += g_date_get_sunday_weeks_in_year(dcal->year);
+        gint week_offset;
+        week_offset = g_date_get_sunday_weeks_in_year(dcal->year);
+        if (dcal->week_starts_monday == 1)
+        {
+            week_offset = g_date_get_monday_weeks_in_year(dcal->year);
+        }
+        d_week_of_cal += week_offset;
     }
     weekRow = d_week_of_cal - top_of_col_week_of_cal;
 
@@ -1528,7 +1575,7 @@
     g_date_set_dmy(&startD, 1, dcal->month, dcal->year);
     d = startD;
     g_date_add_months(&d, (colNum * dcal->monthsPerCol));
-    dayCol -= (g_date_get_weekday(&d) % 7);
+    dayCol -= ((g_date_get_weekday(&d) - dcal->week_starts_monday) % 7);
     if (weekRow == 0)
     {
         if (dayCol < 0)

Modified: gnucash/trunk/src/gnome-utils/gnc-dense-cal.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-dense-cal.h	2007-04-05 00:24:38 UTC (rev 15812)
+++ gnucash/trunk/src/gnome-utils/gnc-dense-cal.h	2007-04-05 00:43:09 UTC (rev 15813)
@@ -94,6 +94,8 @@
 
     guint lastMarkTag;
 
+    gint week_starts_monday;
+
     /**
      * A GList of gdc_mark_data structs, one for each active/valid markTag.
      **/



More information about the gnucash-changes mailing list