diff options
author | Federico Mena Quintero <federico@nuclecu.unam.mx> | 1998-08-19 08:31:04 +0800 |
---|---|---|
committer | Arturo Espinosa <unammx@src.gnome.org> | 1998-08-19 08:31:04 +0800 |
commit | 6158ea365fc20a777a444011e92713fa3168bdda (patch) | |
tree | f51458f962ea8aee3deb0ed465738f96f094f5a0 /calendar/gui/gnome-month-item.c | |
parent | b7c9e891f64f19f1cda1294e1816898518be3ed9 (diff) | |
download | gsoc2013-evolution-6158ea365fc20a777a444011e92713fa3168bdda.tar gsoc2013-evolution-6158ea365fc20a777a444011e92713fa3168bdda.tar.gz gsoc2013-evolution-6158ea365fc20a777a444011e92713fa3168bdda.tar.bz2 gsoc2013-evolution-6158ea365fc20a777a444011e92713fa3168bdda.tar.lz gsoc2013-evolution-6158ea365fc20a777a444011e92713fa3168bdda.tar.xz gsoc2013-evolution-6158ea365fc20a777a444011e92713fa3168bdda.tar.zst gsoc2013-evolution-6158ea365fc20a777a444011e92713fa3168bdda.zip |
We now have a nice generic monthly calendar item for the canvas. We
also have a convenient "Go To" dialog, just like in the PalmPilot.
Next step is a pretty month view - Federico
1998-08-18 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gnome-month-item.c (gnome_month_item_day2index): New public
function to get the displayed day index of the specified date.
* gnome-cal.c (gnome_calendar_goto_today): New public function to
jump to the current day.
* goto.c (day_event): Jump to the selected day when the user
clicks the mouse, and prelight days as appropriate.
* timeutil.c (time_from_day): New public function to build a
time_t from a year/month/day triplet.
* gnome-month-item.c (gnome_month_item_num2child):
(gnome_month_item_child2num): New public functions to convert an
index into a child and vice-versa, respectively.
(gnome_month_item_num2day): New public function to convert a child
number into a displayed day number.
* goto.c (goto_dialog): Doh, use gnome-dialog properly :-)
* gnome-month-item.c (create_items): Use g_strdup()ed day names
from the start.
1998-08-17 Federico Mena Quintero <federico@nuclecu.unam.mx>
* main.c (gnome_toolbar): Made it use goto.xpm.
* Makefile.am (EXTRA_DIST): Added goto.xpm to the list of files.
svn path=/trunk/; revision=326
Diffstat (limited to 'calendar/gui/gnome-month-item.c')
-rw-r--r-- | calendar/gui/gnome-month-item.c | 146 |
1 files changed, 95 insertions, 51 deletions
diff --git a/calendar/gui/gnome-month-item.c b/calendar/gui/gnome-month-item.c index 9b00d4d3c8..045a32d59d 100644 --- a/calendar/gui/gnome-month-item.c +++ b/calendar/gui/gnome-month-item.c @@ -12,15 +12,6 @@ #include "gnome-month-item.h" -/* These are indices into the items array of a GnomeMonthItem structure */ -enum { - ITEM_HEAD_GROUP = 0, /* 7 groups */ - ITEM_HEAD_BOX = 7, /* 7 boxes */ - ITEM_HEAD_LABEL = 14, /* 7 labels */ - ITEM_DAY_GROUP = 21, /* 42 groups */ - ITEM_DAY_BOX = 63, /* 42 boxes */ - ITEM_DAY_LABEL = 105 /* 42 labels */ -}; /* Number of days in a month, for normal and leap years */ @@ -196,13 +187,13 @@ reshape_headings (GnomeMonthItem *mitem) for (i = 0; i < 7; i++) { /* Group */ - gnome_canvas_item_set (mitem->items[ITEM_HEAD_GROUP + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i], "x", width * i, "y", 0.0, NULL); /* Box */ - gnome_canvas_item_set (mitem->items[ITEM_HEAD_BOX + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i], "x1", 0.0, "y1", 0.0, "x2", width, @@ -217,7 +208,7 @@ reshape_headings (GnomeMonthItem *mitem) mitem->head_height - mitem->head_padding, &x, &y); - gnome_canvas_item_set (mitem->items[ITEM_HEAD_LABEL + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], "x", x, "y", y, "anchor", mitem->head_anchor, @@ -242,13 +233,13 @@ reshape_days (GnomeMonthItem *mitem) for (row = 0; row < 6; row++) for (col = 0; col < 7; col++) { /* Group */ - gnome_canvas_item_set (mitem->items[ITEM_DAY_GROUP + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i], "x", width * col, "y", mitem->head_height + height * row, NULL); /* Box */ - gnome_canvas_item_set (mitem->items[ITEM_DAY_BOX + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i], "x1", 0.0, "y1", 0.0, "x2", width, @@ -263,7 +254,7 @@ reshape_days (GnomeMonthItem *mitem) height - mitem->day_padding, &x, &y); - gnome_canvas_item_set (mitem->items[ITEM_DAY_LABEL + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], "x", x, "y", y, "anchor", mitem->day_anchor, @@ -293,21 +284,21 @@ create_headings (GnomeMonthItem *mitem) for (i = 0; i < 7; i++) { /* Group */ - mitem->items[ITEM_HEAD_GROUP + i] = + mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem), gnome_canvas_group_get_type (), NULL); /* Box */ - mitem->items[ITEM_HEAD_BOX + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[ITEM_HEAD_GROUP + i]), + mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i] = + gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i]), gnome_canvas_rect_get_type (), "fill_color", "black", NULL); /* Label */ - mitem->items[ITEM_HEAD_LABEL + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[ITEM_HEAD_GROUP + i]), + mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i] = + gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i]), gnome_canvas_text_get_type (), "fill_color", "white", "font", "-adobe-helvetica-medium-r-normal--10-*-72-72-p-*-iso8859-1", @@ -412,11 +403,10 @@ static void set_days (GnomeMonthItem *mitem) { int i, ofs; - int days[42]; int start, end; char buf[100]; - build_month (mitem->month, mitem->year, days, &start, &end); + build_month (mitem->month, mitem->year, mitem->day_numbers, &start, &end); if (mitem->start_on_monday) ofs = (start + 6) % 7; @@ -426,15 +416,15 @@ set_days (GnomeMonthItem *mitem) /* Clear days before start of month */ for (i = 0; i < ofs; i++) - gnome_canvas_item_set (mitem->items[ITEM_DAY_LABEL + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], "text", NULL, NULL); /* Set days of month */ for (; start <= end; start++, i++) { - sprintf (buf, "%d", days[start]); - gnome_canvas_item_set (mitem->items[ITEM_DAY_LABEL + i], + sprintf (buf, "%d", mitem->day_numbers[start]); + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], "text", buf, NULL); } @@ -442,7 +432,7 @@ set_days (GnomeMonthItem *mitem) /* Clear days after end of month */ for (; i < 42; i++) - gnome_canvas_item_set (mitem->items[ITEM_DAY_LABEL + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], "text", NULL, NULL); } @@ -457,22 +447,22 @@ create_days (GnomeMonthItem *mitem) for (i = 0; i < 42; i++) { /* Group */ - mitem->items[ITEM_DAY_GROUP + i] = + mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem), gnome_canvas_group_get_type (), NULL); /* Box */ - mitem->items[ITEM_DAY_BOX + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[ITEM_DAY_GROUP + i]), + mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i] = + gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i]), gnome_canvas_rect_get_type (), "outline_color", "black", - "fill_color", "#d6d6d6", + "fill_color", "#d6d6d6d6d6d6", NULL); /* Label */ - mitem->items[ITEM_DAY_LABEL + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[ITEM_DAY_GROUP + i]), + mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i] = + gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i]), gnome_canvas_text_get_type (), "fill_color", "black", "font", "-adobe-helvetica-medium-r-normal--10-*-72-72-p-*-iso8859-1", @@ -489,7 +479,7 @@ set_day_names (GnomeMonthItem *mitem) int i; for (i = 0; i < 7; i++) - gnome_canvas_item_set (mitem->items[ITEM_HEAD_LABEL + i], + gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], "text", mitem->day_names[mitem->start_on_monday ? ((i + 1) % 7) : i], NULL); } @@ -498,30 +488,20 @@ set_day_names (GnomeMonthItem *mitem) static void create_items (GnomeMonthItem *mitem) { - /* 7 heading groups - * 7 heading boxes - * 7 heading labels - * 42 day groups - * 42 day boxes - * 42 day labels - * ------------------ - * 147 items total - */ - - mitem->items = g_new (GnomeCanvasItem *, 147); + mitem->items = g_new (GnomeCanvasItem *, GNOME_MONTH_ITEM_LAST); create_headings (mitem); create_days (mitem); /* Initialize by default to three-letter day names */ - mitem->day_names[0] = _("Sun"); - mitem->day_names[1] = _("Mon"); - mitem->day_names[2] = _("Tue"); - mitem->day_names[3] = _("Wed"); - mitem->day_names[4] = _("Thu"); - mitem->day_names[5] = _("Fri"); - mitem->day_names[6] = _("Sat"); + mitem->day_names[0] = g_strdup (_("Sun")); + mitem->day_names[1] = g_strdup (_("Mon")); + mitem->day_names[2] = g_strdup (_("Tue")); + mitem->day_names[3] = g_strdup (_("Wed")); + mitem->day_names[4] = g_strdup (_("Thu")); + mitem->day_names[5] = g_strdup (_("Fri")); + mitem->day_names[6] = g_strdup (_("Sat")); set_day_names (mitem); reshape (mitem); @@ -830,3 +810,67 @@ gnome_month_item_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) break; } } + +GnomeCanvasItem * +gnome_month_item_num2child (GnomeMonthItem *mitem, GnomeMonthItemChild child_num) +{ + g_return_val_if_fail (mitem != NULL, NULL); + g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), NULL); + + return mitem->items[child_num]; +} + +GnomeMonthItemChild +gnome_month_item_child2num (GnomeMonthItem *mitem, GnomeCanvasItem *child) +{ + int i; + + g_return_val_if_fail (mitem != NULL, -1); + g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), -1); + g_return_val_if_fail (child != NULL, -1); + g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (child), -1); + + for (i = 0; i < GNOME_MONTH_ITEM_LAST; i++) + if (mitem->items[i] == child) + return i; + + return -1; +} + +int +gnome_month_item_num2day (GnomeMonthItem *mitem, GnomeMonthItemChild child_num) +{ + g_return_val_if_fail (mitem != NULL, 0); + g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), 0); + + if ((child_num >= GNOME_MONTH_ITEM_DAY_GROUP) && (child_num < GNOME_MONTH_ITEM_LAST)) { + child_num = (child_num - GNOME_MONTH_ITEM_DAY_GROUP) % 42; + return mitem->day_numbers[child_num]; + } else + return 0; +} + +int +gnome_month_item_day2index (GnomeMonthItem *mitem, int day_num) +{ + int i; + + g_return_val_if_fail (mitem != NULL, -1); + g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), -1); + g_return_val_if_fail (day_num >= 1, -1); + + /* Find first day of month */ + + for (i = 0; mitem->day_numbers[i] == 0; i++) + ; + + /* Find the specified day */ + + for (; (mitem->day_numbers[i] != 0) && (i < 42); i++) + if (mitem->day_numbers[i] == day_num) + return i; + + /* Bail out */ + + return -1; +} |