GncDenseCal supports Monday being the start of the week.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15813 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Joshua Sled 2007-04-05 00:43:09 +00:00
parent b0d66bf40d
commit 9abdbc10dc
3 changed files with 73 additions and 24 deletions

View File

@ -92,8 +92,8 @@ TODO
- [x] {0, 1, 2, 3, 4, 6, 12} month selection for dense calendar - [x] {0, 1, 2, 3, 4, 6, 12} month selection for dense calendar
- [x] conf-save value - [x] conf-save value
- [ ] code cleanup - [ ] code cleanup
- [ ] min-size - [x] min-size
- [ ] start-of-week := {sun,mon} (via locale) - [/] start-of-week := {sun,mon} (via locale)
- [ ] change number-of-month properties to display-named properties (width, length) - [ ] change number-of-month properties to display-named properties (width, length)
- [ ] gconf setting for dense-cal font-size reduction - [ ] gconf setting for dense-cal font-size reduction
- [?] better transient/floating window - [?] better transient/floating window

View File

@ -430,6 +430,8 @@ gnc_dense_cal_init(GncDenseCal *dcal)
dcal->initialized = TRUE; dcal->initialized = TRUE;
dcal->week_starts_monday = 1;
gtk_widget_pop_composite_child(); gtk_widget_pop_composite_child();
gtk_widget_show_all(GTK_WIDGET(dcal)); gtk_widget_show_all(GTK_WIDGET(dcal));
@ -769,11 +771,19 @@ recompute_extents(GncDenseCal *dcal)
g_date_clear(&date, 1); g_date_clear(&date, 1);
g_date_set_dmy(&date, 1, dcal->month, dcal->year); 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); 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) 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; dcal->num_weeks = end_week - start_week + 1;
} }
@ -968,15 +978,17 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
{ {
int day_label_width; int day_label_width;
gint label_x_offset, label_y_offset; 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); pango_layout_get_pixel_size(layout, &day_label_width, NULL);
label_x_offset = x label_x_offset = x
+ (j * day_width(dcal)) + (j * day_width(dcal))
+ (day_width(dcal)/2) + (day_width(dcal)/2)
- (day_label_width / 2); - (day_label_width / 2);
label_y_offset = y - dcal->dayLabelHeight; 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], gdk_draw_layout(GDK_DRAWABLE(dcal->drawbuf), widget->style->fg_gc[widget->state],
label_x_offset, label_y_offset, label_x_offset, label_y_offset,
layout); layout);
@ -1282,11 +1294,17 @@ int num_weeks_per_col(GncDenseCal *dcal)
- ((i-1) - ((i-1)
* dcal->monthsPerCol)))); * dcal->monthsPerCol))));
g_date_subtract_days(end, 1); g_date_subtract_days(end, 1);
startWeek = g_date_get_sunday_week_of_year(start); startWeek = (dcal->week_starts_monday
endWeek = g_date_get_sunday_week_of_year(end); ? 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) 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); 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->month - 1 + monthOffset) % 12) + 1,
dcal->year + floor((dcal->month-1+monthOffset)/12)); dcal->year + floor((dcal->month-1+monthOffset)/12));
/* get the week of the top of the column */ /* 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 */ /* get the week of the end of the previous months */
*endD = *startD; *endD = *startD;
g_date_add_months(endD, previousMonthsInCol); g_date_add_months(endD, previousMonthsInCol);
g_date_subtract_days(endD, 1); 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) 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 /* determine how many weeks are before the month we're
* interested in. */ * interested in. */
weekRow = endWk - startWk; 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++; weekRow++;
} }
@ -1354,7 +1378,7 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList)
g_date_subtract_days(endD, 1); g_date_subtract_days(endD, 1);
/* Get the first week. */ /* 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 = g_new0(GdkRectangle, 1);
rect->x = dcal->leftPadding rect->x = dcal->leftPadding
+ MINOR_BORDER_SIZE + MINOR_BORDER_SIZE
@ -1375,8 +1399,12 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList)
{ {
gint i, weekStart, weekEnd; gint i, weekStart, weekEnd;
weekStart = g_date_get_sunday_week_of_year(startD)+1; weekStart = (dcal->week_starts_monday
weekEnd = g_date_get_sunday_week_of_year(endD); ? 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++) { for (i=weekStart; i<weekEnd; i++) {
rect = g_new0(GdkRectangle, 1); rect = g_new0(GdkRectangle, 1);
rect->x = dcal->leftPadding rect->x = dcal->leftPadding
@ -1397,6 +1425,14 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList)
/* Get the last week. */ /* 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 = g_new0(GdkRectangle, 1);
rect->x = dcal->leftPadding rect->x = dcal->leftPadding
+ MINOR_BORDER_SIZE + MINOR_BORDER_SIZE
@ -1406,10 +1442,9 @@ month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList)
+ MINOR_BORDER_SIZE + MINOR_BORDER_SIZE
+ dcal->dayLabelHeight + dcal->dayLabelHeight
+ ((weekRow + ((weekRow
+ (g_date_get_sunday_week_of_year(endD) + (end_week_of_year - start_week_of_year))
- g_date_get_sunday_week_of_year(startD)))
* week_height(dcal)); * 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); rect->height = week_height(dcal);
*outList = g_list_append(*outList, (gpointer)rect); *outList = g_list_append(*outList, (gpointer)rect);
@ -1439,14 +1474,26 @@ doc_coords(GncDenseCal *dcal, int dayOfCal,
docMonth += 12; docMonth += 12;
} }
colNum = floor((float)(docMonth - dcal->month) / (float)dcal->monthsPerCol); 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); 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_set_dmy(&d, 1, dcal->month, dcal->year);
g_date_add_months(&d, (colNum * dcal->monthsPerCol)); 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) 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; 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); g_date_set_dmy(&startD, 1, dcal->month, dcal->year);
d = startD; d = startD;
g_date_add_months(&d, (colNum * dcal->monthsPerCol)); 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 (weekRow == 0)
{ {
if (dayCol < 0) if (dayCol < 0)

View File

@ -94,6 +94,8 @@ struct _GncDenseCal
guint lastMarkTag; guint lastMarkTag;
gint week_starts_monday;
/** /**
* A GList of gdc_mark_data structs, one for each active/valid markTag. * A GList of gdc_mark_data structs, one for each active/valid markTag.
**/ **/