aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/ChangeLog31
-rw-r--r--calendar/Makefile.am1
-rw-r--r--calendar/gnome-cal.c6
-rw-r--r--calendar/gnome-cal.h2
-rw-r--r--calendar/gnome-month-item.c146
-rw-r--r--calendar/gnome-month-item.h52
-rw-r--r--calendar/goto.c117
-rw-r--r--calendar/goto.xpm68
-rw-r--r--calendar/gui/Makefile.am1
-rw-r--r--calendar/gui/gnome-cal.c6
-rw-r--r--calendar/gui/gnome-cal.h2
-rw-r--r--calendar/gui/gnome-month-item.c146
-rw-r--r--calendar/gui/gnome-month-item.h52
-rw-r--r--calendar/gui/goto.c117
-rw-r--r--calendar/gui/main.c5
-rw-r--r--calendar/main.c5
-rw-r--r--calendar/timeutil.c13
-rw-r--r--calendar/timeutil.h3
18 files changed, 659 insertions, 114 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 182cb295d7..22c4a8eb9f 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,34 @@
+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.
+
1998-08-13 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gnome-month-item.c (gnome_month_item_set_arg): Doh. Actually
diff --git a/calendar/Makefile.am b/calendar/Makefile.am
index 039e866306..87225447f6 100644
--- a/calendar/Makefile.am
+++ b/calendar/Makefile.am
@@ -68,6 +68,7 @@ EXTRA_DIST = \
topic.dat \
gnome-cal.html \
bell.xpm \
+ goto.xpm \
recur.xpm
diff --git a/calendar/gnome-cal.c b/calendar/gnome-cal.c
index 234f782fa3..67061dd505 100644
--- a/calendar/gnome-cal.c
+++ b/calendar/gnome-cal.c
@@ -153,6 +153,12 @@ gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time)
}
void
+gnome_calendar_goto_today (GnomeCalendar *gcal)
+{
+ gnome_calendar_goto (gcal, time (NULL));
+}
+
+void
gnome_calendar_set_view (GnomeCalendar *gcal, char *page_name)
{
int page = 0;
diff --git a/calendar/gnome-cal.h b/calendar/gnome-cal.h
index ec1290a652..7f1534714c 100644
--- a/calendar/gnome-cal.h
+++ b/calendar/gnome-cal.h
@@ -52,6 +52,8 @@ void gnome_calendar_goto (GnomeCalendar *gcal,
time_t new_time);
void gnome_calendar_dayjump (GnomeCalendar *gcal,
time_t time);
+/* Jumps to the current day */
+void gnome_calendar_goto_today (GnomeCalendar *gcal);
void gnome_calendar_tag_calendar (GnomeCalendar *cal,
GtkCalendar *gtk_cal);
char *gnome_calendar_get_current_view_name (GnomeCalendar *gcal);
diff --git a/calendar/gnome-month-item.c b/calendar/gnome-month-item.c
index 9b00d4d3c8..045a32d59d 100644
--- a/calendar/gnome-month-item.c
+++ b/calendar/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;
+}
diff --git a/calendar/gnome-month-item.h b/calendar/gnome-month-item.h
index f6523aff94..b1b11f9d01 100644
--- a/calendar/gnome-month-item.h
+++ b/calendar/gnome-month-item.h
@@ -16,6 +16,37 @@
BEGIN_GNOME_DECLS
+/* These values are used to identify the canvas items that make up a complete GnomeMonthItem, which
+ * is made up of the following "pieces":
+ *
+ * Headings line:
+ * - 7 GnomeCanvasGroups:
+ * Each group contains one box (GnomeCanvasRectangle) and one label
+ * (GnomeCanvasText)
+ *
+ * Day slots:
+ * - 42 GnomeCanvasGroups:
+ * Each group contains one box (GnomeCanvasRectangle) and one label
+ * (GnomeCanvasText)
+ *
+ * The headings are organized from left to right. The day slots are organized as a table in
+ * row-major order.
+ *
+ * If you want to access the individual items of the GnomeMonthItem, you can use these numbers with
+ * the gnome_month_item_num2child() function. If you want to convert a number into the
+ * corresponding GnomeCanvasItem, you can use the gnome_month_item_child2num() function.
+ */
+typedef enum {
+ GNOME_MONTH_ITEM_HEAD_GROUP = 0, /* 7 groups for headings */
+ GNOME_MONTH_ITEM_HEAD_BOX = 7, /* 7 boxes for headings */
+ GNOME_MONTH_ITEM_HEAD_LABEL = 14, /* 7 labels for headings */
+ GNOME_MONTH_ITEM_DAY_GROUP = 21, /* 42 groups for days */
+ GNOME_MONTH_ITEM_DAY_BOX = 63, /* 42 boxes for days */
+ GNOME_MONTH_ITEM_DAY_LABEL = 105, /* 42 labels for days */
+ GNOME_MONTH_ITEM_LAST = 147 /* total number of items */
+} GnomeMonthItemChild;
+
+
#define GNOME_TYPE_MONTH_ITEM (gnome_month_item_get_type ())
#define GNOME_MONTH_ITEM(obj) (GTK_CHECK_CAST ((obj), GNOME_TYPE_MONTH_ITEM, GnomeMonthItem))
#define GNOME_MONTH_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_MONTH_ITEM, GnomeMonthItemClass))
@@ -47,6 +78,7 @@ struct _GnomeMonthItem {
GtkAnchorType day_anchor; /* Anchor side for the day number labels */
GnomeCanvasItem **items; /* All the items that make up the calendar */
+ int day_numbers[42]; /* The numbers of the days */
int start_on_monday : 1; /* Start the week on Monday? If false, then start from Sunday */
};
@@ -65,6 +97,26 @@ GnomeCanvasItem *gnome_month_item_new (GnomeCanvasGroup *parent);
/* Constructor function useful for derived classes */
void gnome_month_item_construct (GnomeMonthItem *mitem);
+/* Returns the child item defined by the child number (as specified on the GnomeMonthItemChild
+ * enumeration above).
+ */
+GnomeCanvasItem *gnome_month_item_num2child (GnomeMonthItem *mitem, GnomeMonthItemChild child_num);
+
+/* Returns the number of the specified child item, as defined on the GnomeMonthItemChild enumeration
+ * above. If the specified object is not found, it returns -1.
+ */
+GnomeMonthItemChild gnome_month_item_child2num (GnomeMonthItem *mitem, GnomeCanvasItem *child);
+
+/* Returns the number of the day relevant to the specified child item. Day numbers are 1-based. If
+ * the specified child is outside the range of displayed days, then it returns 0.
+ */
+int gnome_month_item_num2day (GnomeMonthItem *mitem, GnomeMonthItemChild child_num);
+
+/* Returns the index (0-41) of the specified date within the table of days. If the day number is
+ * invalid for the current monthly calendar, then -1 is returned.
+ */
+int gnome_month_item_day2index (GnomeMonthItem *mitem, int day_num);
+
END_GNOME_DECLS
diff --git a/calendar/goto.c b/calendar/goto.c
index a21e162e00..7ba464bd7c 100644
--- a/calendar/goto.c
+++ b/calendar/goto.c
@@ -9,6 +9,7 @@
#include <gnome.h>
#include "gnome-cal.h"
#include "gnome-month-item.h"
+#include "timeutil.h"
static void
@@ -16,13 +17,29 @@ highlight_current_day (GnomeMonthItem *mitem)
{
struct tm *tm;
time_t t;
+ GnomeCanvasItem *label;
+ int i;
t = time (NULL);
tm = localtime (&t);
+ /* First clear all the days to normal */
+
+ for (i = 0; i < 42; i++) {
+ label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
+ gnome_canvas_item_set (label,
+ "fill_color", "black",
+ NULL);
+ }
+
+ /* Highlight the current day, if appropriate */
+
if ((mitem->year == (tm->tm_year + 1900)) && (mitem->month == tm->tm_mon)) {
- ;
- /* FIXME */
+ i = gnome_month_item_day2index (mitem, tm->tm_mday);
+ label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
+ gnome_canvas_item_set (label,
+ "fill_color", "blue",
+ NULL);
}
}
@@ -147,12 +164,66 @@ set_scroll_region (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
allocation->width, allocation->height);
}
+/* Event handler for day groups in the month item. A button press makes the calendar jump to the
+ * selected day and destroys the Go-to dialog box. Days are prelighted as appropriate on
+ * enter_notify and leave_notify events.
+ */
+static gint
+day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+ GtkWidget *dialog;
+ GnomeCalendar *gcal;
+ GnomeMonthItem *mitem;
+ GnomeCanvasItem *box;
+ int child_num, day;
+
+ dialog = GTK_WIDGET (data);
+ gcal = gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar");
+ mitem = gtk_object_get_data (GTK_OBJECT (dialog), "month_item");
+
+ child_num = gnome_month_item_child2num (mitem, item);
+ day = gnome_month_item_num2day (mitem, child_num);
+
+ if (day == 0)
+ return FALSE;
+
+ switch (event->type) {
+ case GDK_BUTTON_PRESS:
+ if ((event->button.button == 1) && (day != 0)) {
+ gnome_calendar_goto (gcal, time_from_day (mitem->year, mitem->month, day));
+ gtk_widget_destroy (dialog);
+ }
+ break;
+
+ case GDK_ENTER_NOTIFY:
+ box = gnome_month_item_num2child (mitem, child_num - GNOME_MONTH_ITEM_DAY_GROUP + GNOME_MONTH_ITEM_DAY_BOX);
+ gnome_canvas_item_set (box,
+ "fill_color", "#ea60ea60ea60",
+ NULL);
+ break;
+
+ case GDK_LEAVE_NOTIFY:
+ box = gnome_month_item_num2child (mitem, child_num - GNOME_MONTH_ITEM_DAY_GROUP + GNOME_MONTH_ITEM_DAY_BOX);
+ gnome_canvas_item_set (box,
+ "fill_color", "#d6d6d6d6d6d6",
+ NULL);
+ break;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
/* Creates the canvas with the month item for selecting days */
static GtkWidget *
create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int year)
{
GtkWidget *canvas;
GnomeCanvasItem *mitem;
+ int i;
+ GnomeCanvasItem *day_group;
canvas = gnome_canvas_new ();
gnome_canvas_set_size (GNOME_CANVAS (canvas), 150, 120);
@@ -174,15 +245,38 @@ create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int yea
(GtkSignalFunc) set_scroll_region,
mitem);
+ /* Bind the day groups to our event handler */
+
+ for (i = 0; i < 42; i++) {
+ day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), i + GNOME_MONTH_ITEM_DAY_GROUP);
+ gtk_signal_connect (GTK_OBJECT (day_group), "event",
+ (GtkSignalFunc) day_event,
+ dialog);
+ }
+
return canvas;
}
+static void
+goto_today (GtkWidget *widget, gpointer data)
+{
+ GtkWidget *dialog;
+ GnomeCalendar *gcal;
+
+ dialog = GTK_WIDGET (data);
+ gcal = gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar");
+
+ gnome_calendar_goto_today (gcal);
+ gtk_widget_destroy (dialog);
+}
+
/* Creates a "goto date" dialog and runs it */
void
goto_dialog (GnomeCalendar *gcal)
{
GtkWidget *dialog;
GtkWidget *vbox;
+ GtkWidget *hbox;
GtkWidget *w;
struct tm *tm;
@@ -191,6 +285,7 @@ goto_dialog (GnomeCalendar *gcal)
dialog = gnome_dialog_new (_("Go to date"),
GNOME_STOCK_BUTTON_CANCEL,
NULL);
+ gtk_object_set_data (GTK_OBJECT (dialog), "gnome_calendar", gcal);
vbox = GNOME_DIALOG (dialog)->vbox;
@@ -222,9 +317,23 @@ goto_dialog (GnomeCalendar *gcal)
gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0);
gtk_widget_show (w);
+ /* Today button */
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
+ w = gtk_button_new_with_label (_("Go to today"));
+ gtk_signal_connect (GTK_OBJECT (w), "clicked",
+ (GtkSignalFunc) goto_today,
+ dialog);
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+
/* Run! */
gnome_dialog_set_modal (GNOME_DIALOG (dialog));
-
- printf ("el dialogo regreso %d\n", gnome_dialog_run_and_destroy (GNOME_DIALOG (dialog)));
+ gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
+ gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (gcal));
+ gtk_widget_show (dialog);
}
diff --git a/calendar/goto.xpm b/calendar/goto.xpm
new file mode 100644
index 0000000000..c7173b4388
--- /dev/null
+++ b/calendar/goto.xpm
@@ -0,0 +1,68 @@
+/* XPM */
+static char * goto_xpm[] = {
+"24 24 41 1",
+" c None",
+". c #212121",
+"+ c #EAD4CB",
+"@ c #E3C5BA",
+"# c #DBB4A4",
+"$ c #EEDED7",
+"% c #FAF7F5",
+"& c #F2E5E1",
+"* c #D2AC99",
+"= c #000000",
+"- c #8D9E7C",
+"; c #CDD9C2",
+"> c #DEE6D7",
+", c #DAE2D1",
+"' c #9BAD89",
+") c #B79382",
+"! c #707D63",
+"~ c #B4C6A2",
+"{ c #ACC098",
+"] c #636E57",
+"^ c #AB8A7A",
+"/ c #E4E9DD",
+"( c #657158",
+"_ c #C49F8D",
+": c #C3D1B5",
+"< c #808F70",
+"[ c #4C5442",
+"} c #58634E",
+"| c #E6EBE0",
+"1 c #D4DDC9",
+"2 c #CAD7BE",
+"3 c #90A17F",
+"4 c #5F6A53",
+"5 c #535C49",
+"6 c #E9EDE4",
+"7 c #616D56",
+"8 c #A8BC95",
+"9 c #7C8B6E",
+"0 c #4C5443",
+"a c #B6C2AA",
+"b c #5E6953",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ... ",
+" ..+@#.. ",
+" .$%&@*. ",
+" =======+#**. ",
+" =-;>,'=###). ",
+" =!~{]=##*^. ",
+" ==/;{(]=#*_. ",
+" ==/;:{<[}=)).. ",
+" =|12{{34=5=.. ",
+" =6{{{7= == ",
+" =>890= ",
+" =a]= ",
+" =b= ",
+" = ",
+" ",
+" ",
+" ",
+" "};
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 039e866306..87225447f6 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -68,6 +68,7 @@ EXTRA_DIST = \
topic.dat \
gnome-cal.html \
bell.xpm \
+ goto.xpm \
recur.xpm
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index 234f782fa3..67061dd505 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -153,6 +153,12 @@ gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time)
}
void
+gnome_calendar_goto_today (GnomeCalendar *gcal)
+{
+ gnome_calendar_goto (gcal, time (NULL));
+}
+
+void
gnome_calendar_set_view (GnomeCalendar *gcal, char *page_name)
{
int page = 0;
diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h
index ec1290a652..7f1534714c 100644
--- a/calendar/gui/gnome-cal.h
+++ b/calendar/gui/gnome-cal.h
@@ -52,6 +52,8 @@ void gnome_calendar_goto (GnomeCalendar *gcal,
time_t new_time);
void gnome_calendar_dayjump (GnomeCalendar *gcal,
time_t time);
+/* Jumps to the current day */
+void gnome_calendar_goto_today (GnomeCalendar *gcal);
void gnome_calendar_tag_calendar (GnomeCalendar *cal,
GtkCalendar *gtk_cal);
char *gnome_calendar_get_current_view_name (GnomeCalendar *gcal);
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;
+}
diff --git a/calendar/gui/gnome-month-item.h b/calendar/gui/gnome-month-item.h
index f6523aff94..b1b11f9d01 100644
--- a/calendar/gui/gnome-month-item.h
+++ b/calendar/gui/gnome-month-item.h
@@ -16,6 +16,37 @@
BEGIN_GNOME_DECLS
+/* These values are used to identify the canvas items that make up a complete GnomeMonthItem, which
+ * is made up of the following "pieces":
+ *
+ * Headings line:
+ * - 7 GnomeCanvasGroups:
+ * Each group contains one box (GnomeCanvasRectangle) and one label
+ * (GnomeCanvasText)
+ *
+ * Day slots:
+ * - 42 GnomeCanvasGroups:
+ * Each group contains one box (GnomeCanvasRectangle) and one label
+ * (GnomeCanvasText)
+ *
+ * The headings are organized from left to right. The day slots are organized as a table in
+ * row-major order.
+ *
+ * If you want to access the individual items of the GnomeMonthItem, you can use these numbers with
+ * the gnome_month_item_num2child() function. If you want to convert a number into the
+ * corresponding GnomeCanvasItem, you can use the gnome_month_item_child2num() function.
+ */
+typedef enum {
+ GNOME_MONTH_ITEM_HEAD_GROUP = 0, /* 7 groups for headings */
+ GNOME_MONTH_ITEM_HEAD_BOX = 7, /* 7 boxes for headings */
+ GNOME_MONTH_ITEM_HEAD_LABEL = 14, /* 7 labels for headings */
+ GNOME_MONTH_ITEM_DAY_GROUP = 21, /* 42 groups for days */
+ GNOME_MONTH_ITEM_DAY_BOX = 63, /* 42 boxes for days */
+ GNOME_MONTH_ITEM_DAY_LABEL = 105, /* 42 labels for days */
+ GNOME_MONTH_ITEM_LAST = 147 /* total number of items */
+} GnomeMonthItemChild;
+
+
#define GNOME_TYPE_MONTH_ITEM (gnome_month_item_get_type ())
#define GNOME_MONTH_ITEM(obj) (GTK_CHECK_CAST ((obj), GNOME_TYPE_MONTH_ITEM, GnomeMonthItem))
#define GNOME_MONTH_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_MONTH_ITEM, GnomeMonthItemClass))
@@ -47,6 +78,7 @@ struct _GnomeMonthItem {
GtkAnchorType day_anchor; /* Anchor side for the day number labels */
GnomeCanvasItem **items; /* All the items that make up the calendar */
+ int day_numbers[42]; /* The numbers of the days */
int start_on_monday : 1; /* Start the week on Monday? If false, then start from Sunday */
};
@@ -65,6 +97,26 @@ GnomeCanvasItem *gnome_month_item_new (GnomeCanvasGroup *parent);
/* Constructor function useful for derived classes */
void gnome_month_item_construct (GnomeMonthItem *mitem);
+/* Returns the child item defined by the child number (as specified on the GnomeMonthItemChild
+ * enumeration above).
+ */
+GnomeCanvasItem *gnome_month_item_num2child (GnomeMonthItem *mitem, GnomeMonthItemChild child_num);
+
+/* Returns the number of the specified child item, as defined on the GnomeMonthItemChild enumeration
+ * above. If the specified object is not found, it returns -1.
+ */
+GnomeMonthItemChild gnome_month_item_child2num (GnomeMonthItem *mitem, GnomeCanvasItem *child);
+
+/* Returns the number of the day relevant to the specified child item. Day numbers are 1-based. If
+ * the specified child is outside the range of displayed days, then it returns 0.
+ */
+int gnome_month_item_num2day (GnomeMonthItem *mitem, GnomeMonthItemChild child_num);
+
+/* Returns the index (0-41) of the specified date within the table of days. If the day number is
+ * invalid for the current monthly calendar, then -1 is returned.
+ */
+int gnome_month_item_day2index (GnomeMonthItem *mitem, int day_num);
+
END_GNOME_DECLS
diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c
index a21e162e00..7ba464bd7c 100644
--- a/calendar/gui/goto.c
+++ b/calendar/gui/goto.c
@@ -9,6 +9,7 @@
#include <gnome.h>
#include "gnome-cal.h"
#include "gnome-month-item.h"
+#include "timeutil.h"
static void
@@ -16,13 +17,29 @@ highlight_current_day (GnomeMonthItem *mitem)
{
struct tm *tm;
time_t t;
+ GnomeCanvasItem *label;
+ int i;
t = time (NULL);
tm = localtime (&t);
+ /* First clear all the days to normal */
+
+ for (i = 0; i < 42; i++) {
+ label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
+ gnome_canvas_item_set (label,
+ "fill_color", "black",
+ NULL);
+ }
+
+ /* Highlight the current day, if appropriate */
+
if ((mitem->year == (tm->tm_year + 1900)) && (mitem->month == tm->tm_mon)) {
- ;
- /* FIXME */
+ i = gnome_month_item_day2index (mitem, tm->tm_mday);
+ label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
+ gnome_canvas_item_set (label,
+ "fill_color", "blue",
+ NULL);
}
}
@@ -147,12 +164,66 @@ set_scroll_region (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
allocation->width, allocation->height);
}
+/* Event handler for day groups in the month item. A button press makes the calendar jump to the
+ * selected day and destroys the Go-to dialog box. Days are prelighted as appropriate on
+ * enter_notify and leave_notify events.
+ */
+static gint
+day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+ GtkWidget *dialog;
+ GnomeCalendar *gcal;
+ GnomeMonthItem *mitem;
+ GnomeCanvasItem *box;
+ int child_num, day;
+
+ dialog = GTK_WIDGET (data);
+ gcal = gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar");
+ mitem = gtk_object_get_data (GTK_OBJECT (dialog), "month_item");
+
+ child_num = gnome_month_item_child2num (mitem, item);
+ day = gnome_month_item_num2day (mitem, child_num);
+
+ if (day == 0)
+ return FALSE;
+
+ switch (event->type) {
+ case GDK_BUTTON_PRESS:
+ if ((event->button.button == 1) && (day != 0)) {
+ gnome_calendar_goto (gcal, time_from_day (mitem->year, mitem->month, day));
+ gtk_widget_destroy (dialog);
+ }
+ break;
+
+ case GDK_ENTER_NOTIFY:
+ box = gnome_month_item_num2child (mitem, child_num - GNOME_MONTH_ITEM_DAY_GROUP + GNOME_MONTH_ITEM_DAY_BOX);
+ gnome_canvas_item_set (box,
+ "fill_color", "#ea60ea60ea60",
+ NULL);
+ break;
+
+ case GDK_LEAVE_NOTIFY:
+ box = gnome_month_item_num2child (mitem, child_num - GNOME_MONTH_ITEM_DAY_GROUP + GNOME_MONTH_ITEM_DAY_BOX);
+ gnome_canvas_item_set (box,
+ "fill_color", "#d6d6d6d6d6d6",
+ NULL);
+ break;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
/* Creates the canvas with the month item for selecting days */
static GtkWidget *
create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int year)
{
GtkWidget *canvas;
GnomeCanvasItem *mitem;
+ int i;
+ GnomeCanvasItem *day_group;
canvas = gnome_canvas_new ();
gnome_canvas_set_size (GNOME_CANVAS (canvas), 150, 120);
@@ -174,15 +245,38 @@ create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int yea
(GtkSignalFunc) set_scroll_region,
mitem);
+ /* Bind the day groups to our event handler */
+
+ for (i = 0; i < 42; i++) {
+ day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), i + GNOME_MONTH_ITEM_DAY_GROUP);
+ gtk_signal_connect (GTK_OBJECT (day_group), "event",
+ (GtkSignalFunc) day_event,
+ dialog);
+ }
+
return canvas;
}
+static void
+goto_today (GtkWidget *widget, gpointer data)
+{
+ GtkWidget *dialog;
+ GnomeCalendar *gcal;
+
+ dialog = GTK_WIDGET (data);
+ gcal = gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar");
+
+ gnome_calendar_goto_today (gcal);
+ gtk_widget_destroy (dialog);
+}
+
/* Creates a "goto date" dialog and runs it */
void
goto_dialog (GnomeCalendar *gcal)
{
GtkWidget *dialog;
GtkWidget *vbox;
+ GtkWidget *hbox;
GtkWidget *w;
struct tm *tm;
@@ -191,6 +285,7 @@ goto_dialog (GnomeCalendar *gcal)
dialog = gnome_dialog_new (_("Go to date"),
GNOME_STOCK_BUTTON_CANCEL,
NULL);
+ gtk_object_set_data (GTK_OBJECT (dialog), "gnome_calendar", gcal);
vbox = GNOME_DIALOG (dialog)->vbox;
@@ -222,9 +317,23 @@ goto_dialog (GnomeCalendar *gcal)
gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0);
gtk_widget_show (w);
+ /* Today button */
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
+ w = gtk_button_new_with_label (_("Go to today"));
+ gtk_signal_connect (GTK_OBJECT (w), "clicked",
+ (GtkSignalFunc) goto_today,
+ dialog);
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+
/* Run! */
gnome_dialog_set_modal (GNOME_DIALOG (dialog));
-
- printf ("el dialogo regreso %d\n", gnome_dialog_run_and_destroy (GNOME_DIALOG (dialog)));
+ gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
+ gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (gcal));
+ gtk_widget_show (dialog);
}
diff --git a/calendar/gui/main.c b/calendar/gui/main.c
index ebb008927f..9240acdfc1 100644
--- a/calendar/gui/main.c
+++ b/calendar/gui/main.c
@@ -19,6 +19,7 @@
#include "gnome-cal.h"
#include "main.h"
#include "timeutil.h"
+#include "goto.xpm"
#define COOKIE_USER_HOME_DIR ((char *) -1)
@@ -223,7 +224,7 @@ next_clicked (GtkWidget *widget, GnomeCalendar *gcal)
static void
today_clicked (GtkWidget *widget, GnomeCalendar *gcal)
{
- gnome_calendar_goto (gcal, time (NULL));
+ gnome_calendar_goto_today (gcal);
}
static void
@@ -386,7 +387,7 @@ static GnomeUIInfo gnome_toolbar [] = {
GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_ITEM_STOCK (N_("Go to"), N_("Go to a specific date"), goto_clicked, GNOME_STOCK_PIXMAP_STOP),
+ GNOMEUIINFO_ITEM (N_("Go to"), N_("Go to a specific date"), goto_clicked, goto_xpm),
GNOMEUIINFO_END
};
diff --git a/calendar/main.c b/calendar/main.c
index ebb008927f..9240acdfc1 100644
--- a/calendar/main.c
+++ b/calendar/main.c
@@ -19,6 +19,7 @@
#include "gnome-cal.h"
#include "main.h"
#include "timeutil.h"
+#include "goto.xpm"
#define COOKIE_USER_HOME_DIR ((char *) -1)
@@ -223,7 +224,7 @@ next_clicked (GtkWidget *widget, GnomeCalendar *gcal)
static void
today_clicked (GtkWidget *widget, GnomeCalendar *gcal)
{
- gnome_calendar_goto (gcal, time (NULL));
+ gnome_calendar_goto_today (gcal);
}
static void
@@ -386,7 +387,7 @@ static GnomeUIInfo gnome_toolbar [] = {
GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_ITEM_STOCK (N_("Go to"), N_("Go to a specific date"), goto_clicked, GNOME_STOCK_PIXMAP_STOP),
+ GNOMEUIINFO_ITEM (N_("Go to"), N_("Go to a specific date"), goto_clicked, goto_xpm),
GNOMEUIINFO_END
};
diff --git a/calendar/timeutil.c b/calendar/timeutil.c
index f23277ce37..c27a8dbd45 100644
--- a/calendar/timeutil.c
+++ b/calendar/timeutil.c
@@ -148,6 +148,19 @@ time_day_hour (time_t t, int hour)
time_t
+time_from_day (int year, int month, int day)
+{
+ struct tm tm;
+
+ memset (&tm, 0, sizeof (tm));
+ tm.tm_year = year - 1900;
+ tm.tm_mon = month;
+ tm.tm_mday = day;
+
+ return mktime (&tm);
+}
+
+time_t
time_start_of_day (time_t t)
{
struct tm tm;
diff --git a/calendar/timeutil.h b/calendar/timeutil.h
index a5a6d7b2d7..dc0aa522bf 100644
--- a/calendar/timeutil.h
+++ b/calendar/timeutil.h
@@ -32,6 +32,9 @@ time_t time_add_year (time_t time, int years);
*/
char *format_simple_hour (int hour, int use_am_pm);
+/* Converts the specified date to a time_t at the start of the specified day */
+time_t time_from_day (int year, int month, int day);
+
time_t time_start_of_day (time_t t);
time_t time_end_of_day (time_t t);
time_t time_day_hour (time_t t, int hour);