diff --git a/src/doc/sx.rst b/src/doc/sx.rst index 892c6a412b..03d2d31f05 100644 --- a/src/doc/sx.rst +++ b/src/doc/sx.rst @@ -92,8 +92,8 @@ TODO - [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 diff --git a/src/gnome-utils/gnc-dense-cal.c b/src/gnome-utils/gnc-dense-cal.c index 3ecdc522d6..6c8ccaaf21 100644 --- a/src/gnome-utils/gnc-dense-cal.c +++ b/src/gnome-utils/gnc-dense-cal.c @@ -430,6 +430,8 @@ gnc_dense_cal_init(GncDenseCal *dcal) dcal->initialized = TRUE; + dcal->week_starts_monday = 1; + gtk_widget_pop_composite_child(); gtk_widget_show_all(GTK_WIDGET(dcal)); @@ -769,11 +771,19 @@ recompute_extents(GncDenseCal *dcal) 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 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) { 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 @@ int num_weeks_per_col(GncDenseCal *dcal) - ((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 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList) ((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 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList) 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 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList) { 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; ix = dcal->leftPadding @@ -1397,6 +1425,14 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList) /* 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 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList) + 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 @@ doc_coords(GncDenseCal *dcal, int dayOfCal, 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 @@ wheres_this(GncDenseCal *dcal, int x, int y) 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) diff --git a/src/gnome-utils/gnc-dense-cal.h b/src/gnome-utils/gnc-dense-cal.h index aa5a125437..73568135ad 100644 --- a/src/gnome-utils/gnc-dense-cal.h +++ b/src/gnome-utils/gnc-dense-cal.h @@ -94,6 +94,8 @@ struct _GncDenseCal guint lastMarkTag; + gint week_starts_monday; + /** * A GList of gdc_mark_data structs, one for each active/valid markTag. **/