aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/ChangeLog5
-rw-r--r--calendar/Makefile.am29
-rw-r--r--calendar/cal-util/calobj.c2
-rw-r--r--calendar/cal-util/calobj.h6
-rw-r--r--calendar/calendar.c16
-rw-r--r--calendar/calendar.h2
-rw-r--r--calendar/calobj.c2
-rw-r--r--calendar/calobj.h6
-rw-r--r--calendar/gncal-day-view.c254
-rw-r--r--calendar/gncal-day-view.h52
-rw-r--r--calendar/gui/Makefile.am29
-rw-r--r--calendar/gui/calendar.c16
-rw-r--r--calendar/gui/calendar.h2
-rw-r--r--calendar/gui/gncal-day-view.c254
-rw-r--r--calendar/gui/gncal-day-view.h52
-rw-r--r--calendar/pcs/calobj.c2
-rw-r--r--calendar/pcs/calobj.h6
17 files changed, 686 insertions, 49 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index e5aa6d0de2..8dc5fd0a12 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,5 +1,10 @@
1998-03-31 Federico Mena Quintero <federico@nuclecu.unam.mx>
+ * gncal.c: Removed #include "gtkcalendar.h", because it now comes
+ from libgnomeui.
+
+ * Makefile.am (gncal_SOURCES): Added new source files to the rules.
+
* timeutil.c (format_simple_hour): New function, formats an
hour/am_pm pair into a string of the form "3am", "12pm", "05h",
"19h", etc. It is used by the day view widget for its labels.
diff --git a/calendar/Makefile.am b/calendar/Makefile.am
index 529b9cca23..9a1f4c4778 100644
--- a/calendar/Makefile.am
+++ b/calendar/Makefile.am
@@ -3,27 +3,30 @@ INCLUDES = \
$(GNOME_INCLUDEDIR) \
-I../../gcalendar
-bin_PROGRAMS = gncal objedit
-
-objedit_SOURCES = objedit.c
+bin_PROGRAMS = gncal
gncal_SOURCES = \
- gncal.c \
- gncal.h \
- calcs.c \
- calcs.h \
- clist.c \
- clist.h
+ gncal.c \
+ gncal.h \
+ calcs.c \
+ calcs.h \
+ clist.c \
+ clist.h \
+ calendar.c \
+ calendar.h \
+ calobj.c \
+ calobj.h \
+ gncal-day-view.c \
+ gncal-day-view.h \
+ timeutil.c \
+ timeutil.h
LINK_FLAGS = \
$(GNOME_LIBDIR) \
$(GNOMEUI_LIBS) \
- $(INTLLIBS) \
- ../../gcalendar/gtkcalendar.o \
- ../../gcalendar/lib_date.o
+ $(INTLLIBS)
gncal_LDADD = $(LINK_FLAGS)
-objedit_LDADD = $(LINK_FLAGS)
EXTRA_DIST = \
gncal.desktop
diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c
index 87dd8db78d..fcdfb7e59d 100644
--- a/calendar/cal-util/calobj.c
+++ b/calendar/cal-util/calobj.c
@@ -13,7 +13,7 @@ ical_object_new (void)
{
iCalObject *ico;
- ico = g_new0 (iCalObject);
+ ico = g_new0 (iCalObject, 1);
ico->seq = -1;
ico->dtstamp = time (NULL);
diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h
index fda3a1e4b5..d5f6db0ae0 100644
--- a/calendar/cal-util/calobj.h
+++ b/calendar/cal-util/calobj.h
@@ -7,6 +7,8 @@
#ifndef CALOBJ_H
#define CALOBJ_H
+#include <libgnome/libgnome.h>
+
BEGIN_GNOME_DECLS
typedef struct {
@@ -42,7 +44,7 @@ typedef struct {
typedef enum {
ICAL_OPAQUE,
ICAL_TRANSPARENT
-};
+} iCalTransp;
typedef char NotYet;
@@ -93,8 +95,8 @@ typedef struct {
iCalObject *ical_new (char *comment, char *organizer, char *summary);
iCalObject *ical_object_new (void);
+void ical_object_destroy (iCalObject *ico);
END_GNOME_DECLS
#endif
-
diff --git a/calendar/calendar.c b/calendar/calendar.c
index 8725d96081..b7cf72d47d 100644
--- a/calendar/calendar.c
+++ b/calendar/calendar.c
@@ -11,7 +11,7 @@
* Federico Mena (federico@gimp.org)
*
*/
-#include "calobj.h"
+
#include "calendar.h"
Calendar *
@@ -68,13 +68,13 @@ calendar_remove_object (Calendar *cal, iCalObject *obj)
void
calendar_destroy (Calendar *cal)
{
- g_list_foreach (cal->events, ical_object_destroy, NULL);
+ g_list_foreach (cal->events, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->events);
- g_list_foreach (cal->todo, ical_object_destroy, NULL);
+ g_list_foreach (cal->todo, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->todo);
- g_list_foreach (cal->journal, ical_object_destroy, NULL);
+ g_list_foreach (cal->journal, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->journal);
if (cal->title)
@@ -96,21 +96,23 @@ calendar_get_objects_in_range (GList *objects, time_t start, time_t end)
if ((start <= object->dtstart) && (end >= object->dtend))
new_events = g_list_prepend (new_events, object);
}
+
+ return new_events;
}
GList *
calendar_get_events_in_range (Calendar *cal, time_t start, time_t end)
{
- calendar_get_objects_in_range (cal->events, start, end);
+ return calendar_get_objects_in_range (cal->events, start, end);
}
GList *
calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end)
{
- calendar_get_objects_in_range (cal->todo, start, end);
+ return calendar_get_objects_in_range (cal->todo, start, end);
}
GList *
calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end)
{
- calendar_get_objects_in_range (cal->journal, start, end);
+ return calendar_get_objects_in_range (cal->journal, start, end);
}
diff --git a/calendar/calendar.h b/calendar/calendar.h
index 13aba56590..d10cfe28be 100644
--- a/calendar/calendar.h
+++ b/calendar/calendar.h
@@ -1,6 +1,8 @@
#ifndef CALENDAR_H
#define CALENDAR_H
+#include "calobj.h"
+
BEGIN_GNOME_DECLS
typedef struct {
diff --git a/calendar/calobj.c b/calendar/calobj.c
index 87dd8db78d..fcdfb7e59d 100644
--- a/calendar/calobj.c
+++ b/calendar/calobj.c
@@ -13,7 +13,7 @@ ical_object_new (void)
{
iCalObject *ico;
- ico = g_new0 (iCalObject);
+ ico = g_new0 (iCalObject, 1);
ico->seq = -1;
ico->dtstamp = time (NULL);
diff --git a/calendar/calobj.h b/calendar/calobj.h
index fda3a1e4b5..d5f6db0ae0 100644
--- a/calendar/calobj.h
+++ b/calendar/calobj.h
@@ -7,6 +7,8 @@
#ifndef CALOBJ_H
#define CALOBJ_H
+#include <libgnome/libgnome.h>
+
BEGIN_GNOME_DECLS
typedef struct {
@@ -42,7 +44,7 @@ typedef struct {
typedef enum {
ICAL_OPAQUE,
ICAL_TRANSPARENT
-};
+} iCalTransp;
typedef char NotYet;
@@ -93,8 +95,8 @@ typedef struct {
iCalObject *ical_new (char *comment, char *organizer, char *summary);
iCalObject *ical_object_new (void);
+void ical_object_destroy (iCalObject *ico);
END_GNOME_DECLS
#endif
-
diff --git a/calendar/gncal-day-view.c b/calendar/gncal-day-view.c
new file mode 100644
index 0000000000..e6a511f736
--- /dev/null
+++ b/calendar/gncal-day-view.c
@@ -0,0 +1,254 @@
+/* Day view widget for gncal
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#include "gncal-day-view.h"
+#include "timeutil.h"
+
+
+#define TEXT_BORDER 2
+#define MIN_INFO_WIDTH 50
+
+
+static void gncal_day_view_class_init (GncalDayViewClass *class);
+static void gncal_day_view_init (GncalDayView *dview);
+static void gncal_day_view_realize (GtkWidget *widget);
+static void gncal_day_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static gint gncal_day_view_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+
+
+static GtkWidgetClass *parent_class;
+
+
+guint
+gncal_day_view_get_type (void)
+{
+ static guint day_view_type = 0;
+
+ if (!day_view_type) {
+ GtkTypeInfo day_view_info = {
+ "GncalDayView",
+ sizeof (GncalDayView),
+ sizeof (GncalDayViewClass),
+ (GtkClassInitFunc) gncal_day_view_class_init,
+ (GtkObjectInitFunc) gncal_day_view_init,
+ (GtkArgSetFunc) NULL,
+ (GtkArgGetFunc) NULL
+ };
+
+ day_view_type = gtk_type_unique (gtk_widget_get_type (), &day_view_info);
+ }
+
+ return day_view_type;
+}
+
+static void
+gncal_day_view_class_init (GncalDayViewClass *class)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = (GtkObjectClass *) class;
+ widget_class = (GtkWidgetClass *) class;
+
+ parent_class = gtk_type_class (gtk_widget_get_type ());
+
+ widget_class->realize = gncal_day_view_realize;
+ widget_class->size_request = gncal_day_view_size_request;
+ widget_class->expose_event = gncal_day_view_expose;
+}
+
+static void
+gncal_day_view_init (GncalDayView *dview)
+{
+ GTK_WIDGET_UNSET_FLAGS (dview, GTK_NO_WINDOW);
+
+ dview->calendar = NULL;
+
+ dview->lower = 0;
+ dview->upper = 24;
+ dview->use_am_pm = TRUE;
+}
+
+GtkWidget *
+gncal_day_view_new (Calendar *calendar)
+{
+ GncalDayView *dview;
+
+#if 0
+ g_assert (calendar != NULL);
+#endif
+
+ dview = gtk_type_new (gncal_day_view_get_type ());
+
+ dview->calendar = calendar;
+
+ return GTK_WIDGET (dview);
+}
+
+static void
+gncal_day_view_realize (GtkWidget *widget)
+{
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (widget));
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.x = widget->allocation.x;
+ attributes.y = widget->allocation.y;
+ attributes.width = widget->allocation.width;
+ attributes.height = widget->allocation.height;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.event_mask = (gtk_widget_get_events (widget)
+ | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK);
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+ widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
+ gdk_window_set_user_data (widget->window, widget);
+
+ widget->style = gtk_style_attach (widget->style, widget->window);
+
+ gtk_style_set_background (widget->style, widget->window, GTK_STATE_SELECTED);
+}
+
+static int
+calc_labels_width (GncalDayView *dview)
+{
+ int width, max_width;
+ GdkFont *font;
+ char *buf;
+ int i;
+
+ font = GTK_WIDGET (dview)->style->font;
+
+ max_width = 0;
+
+ for (i = 0; i < 24; i++) {
+ buf = format_simple_hour (i, dview->use_am_pm);
+ width = gdk_string_width (font, buf);
+ if (width > max_width)
+ max_width = width;
+ }
+
+ return width;
+}
+
+static void
+gncal_day_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+ GncalDayView *dview;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (widget));
+ g_return_if_fail (requisition != NULL);
+
+ dview = GNCAL_DAY_VIEW (widget);
+
+ requisition->width = 2 * widget->style->klass->xthickness + 4 * TEXT_BORDER + MIN_INFO_WIDTH;
+ requisition->height = 2 * widget->style->klass->xthickness;
+
+ requisition->width += calc_labels_width (dview);
+ requisition->height += ((dview->upper - dview->lower)
+ * (widget->style->font->ascent + widget->style->font->descent
+ + 2 * TEXT_BORDER));
+}
+
+static gint
+gncal_day_view_expose (GtkWidget *widget, GdkEventExpose *event)
+{
+ GncalDayView *dview;
+ int x1, y1, width, height;
+ int division_x;
+ int row_height;
+ int i;
+
+ g_return_val_if_fail (widget != NULL, FALSE);
+ g_return_val_if_fail (GNCAL_IS_DAY_VIEW (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ if (!GTK_WIDGET_DRAWABLE (widget))
+ return FALSE;
+
+ dview = GNCAL_DAY_VIEW (widget);
+
+ x1 = widget->style->klass->xthickness;
+ y1 = widget->style->klass->ythickness;
+ width = widget->allocation.width - 2 * x1;
+ height = widget->allocation.width - 2 * y1;
+
+ /* Clear and paint frame shadow */
+
+ gdk_window_clear_area (widget->window, event->area.x, event->area.y, event->area.width, event->area.height);
+
+ gtk_draw_shadow (widget->style, widget->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_IN,
+ 0, 0,
+ widget->allocation.width,
+ widget->allocation.height);
+
+ /* Divisions */
+
+ division_x = x1 + 2 * TEXT_BORDER + calc_labels_width (dview);
+
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ division_x, y1,
+ division_x, y1 + height - 1);
+
+ row_height = height / (dview->upper - dview->lower);
+
+ for (i = 0; i < (dview->upper - dview->lower - 1); i++)
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ x1,
+ y1 + (i + 1) * row_height,
+ x1 + width - 1,
+ y1 + (i + 1) * row_height);
+
+ return FALSE;
+}
+
+void
+gncal_day_view_set_bounds (GncalDayView *dview, int lower, int upper)
+{
+ g_return_if_fail (dview != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (dview));
+
+ lower = CLAMP (lower, 0, 23);
+ upper = CLAMP (upper, lower + 1, 24);
+
+ if ((lower != dview->lower) || (upper != dview->upper)) {
+ dview->lower = lower;
+ dview->upper = upper;
+
+ gtk_widget_queue_resize (GTK_WIDGET (dview));
+ }
+}
+
+void
+gncal_day_view_set_format (GncalDayView *dview, int use_am_pm)
+{
+ g_return_if_fail (dview != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (dview));
+
+ use_am_pm = use_am_pm ? TRUE : FALSE;
+
+ if (use_am_pm != dview->use_am_pm) {
+ dview->use_am_pm = use_am_pm;
+
+ gtk_widget_queue_resize (GTK_WIDGET (dview));
+ }
+}
diff --git a/calendar/gncal-day-view.h b/calendar/gncal-day-view.h
new file mode 100644
index 0000000000..ed918e4f37
--- /dev/null
+++ b/calendar/gncal-day-view.h
@@ -0,0 +1,52 @@
+/* Day view widget for gncal
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#ifndef GNCAL_DAY_VIEW_H
+#define GNCAL_DAY_VIEW_H
+
+
+#include <gtk/gtkwidget.h>
+#include <libgnome/gnome-defs.h>
+#include "calendar.h"
+
+
+BEGIN_GNOME_DECLS
+
+
+#define GNCAL_DAY_VIEW(obj) GTK_CHECK_CAST (obj, gncal_day_view_get_type (), GncalDayView)
+#define GNCAL_DAY_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_day_view_get_type (), GncalDayViewClass)
+#define GNCAL_IS_DAY_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_day_view_get_type ())
+
+
+typedef struct _GncalDayView GncalDayView;
+typedef struct _GncalDayViewClass GncalDayViewClass;
+
+struct _GncalDayView {
+ GtkWidget widget;
+
+ Calendar *calendar; /* the calendar we are associated to */
+
+ int lower; /* lower and upper hours of the day to display */
+ int upper;
+ int use_am_pm; /* use am/pm (TRUE) or 24-hour format (FALSE) */
+};
+
+struct _GncalDayViewClass {
+ GtkWidgetClass parent_class;
+};
+
+
+guint gncal_day_view_get_type (void);
+GtkWidget *gncal_day_view_new (Calendar *calendar);
+
+void gncal_day_view_set_bounds (GncalDayView *dview, int lower, int upper);
+void gncal_day_view_set_format (GncalDayView *dview, int use_am_pm);
+
+
+END_GNOME_DECLS
+
+#endif
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 529b9cca23..9a1f4c4778 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -3,27 +3,30 @@ INCLUDES = \
$(GNOME_INCLUDEDIR) \
-I../../gcalendar
-bin_PROGRAMS = gncal objedit
-
-objedit_SOURCES = objedit.c
+bin_PROGRAMS = gncal
gncal_SOURCES = \
- gncal.c \
- gncal.h \
- calcs.c \
- calcs.h \
- clist.c \
- clist.h
+ gncal.c \
+ gncal.h \
+ calcs.c \
+ calcs.h \
+ clist.c \
+ clist.h \
+ calendar.c \
+ calendar.h \
+ calobj.c \
+ calobj.h \
+ gncal-day-view.c \
+ gncal-day-view.h \
+ timeutil.c \
+ timeutil.h
LINK_FLAGS = \
$(GNOME_LIBDIR) \
$(GNOMEUI_LIBS) \
- $(INTLLIBS) \
- ../../gcalendar/gtkcalendar.o \
- ../../gcalendar/lib_date.o
+ $(INTLLIBS)
gncal_LDADD = $(LINK_FLAGS)
-objedit_LDADD = $(LINK_FLAGS)
EXTRA_DIST = \
gncal.desktop
diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c
index 8725d96081..b7cf72d47d 100644
--- a/calendar/gui/calendar.c
+++ b/calendar/gui/calendar.c
@@ -11,7 +11,7 @@
* Federico Mena (federico@gimp.org)
*
*/
-#include "calobj.h"
+
#include "calendar.h"
Calendar *
@@ -68,13 +68,13 @@ calendar_remove_object (Calendar *cal, iCalObject *obj)
void
calendar_destroy (Calendar *cal)
{
- g_list_foreach (cal->events, ical_object_destroy, NULL);
+ g_list_foreach (cal->events, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->events);
- g_list_foreach (cal->todo, ical_object_destroy, NULL);
+ g_list_foreach (cal->todo, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->todo);
- g_list_foreach (cal->journal, ical_object_destroy, NULL);
+ g_list_foreach (cal->journal, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->journal);
if (cal->title)
@@ -96,21 +96,23 @@ calendar_get_objects_in_range (GList *objects, time_t start, time_t end)
if ((start <= object->dtstart) && (end >= object->dtend))
new_events = g_list_prepend (new_events, object);
}
+
+ return new_events;
}
GList *
calendar_get_events_in_range (Calendar *cal, time_t start, time_t end)
{
- calendar_get_objects_in_range (cal->events, start, end);
+ return calendar_get_objects_in_range (cal->events, start, end);
}
GList *
calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end)
{
- calendar_get_objects_in_range (cal->todo, start, end);
+ return calendar_get_objects_in_range (cal->todo, start, end);
}
GList *
calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end)
{
- calendar_get_objects_in_range (cal->journal, start, end);
+ return calendar_get_objects_in_range (cal->journal, start, end);
}
diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h
index 13aba56590..d10cfe28be 100644
--- a/calendar/gui/calendar.h
+++ b/calendar/gui/calendar.h
@@ -1,6 +1,8 @@
#ifndef CALENDAR_H
#define CALENDAR_H
+#include "calobj.h"
+
BEGIN_GNOME_DECLS
typedef struct {
diff --git a/calendar/gui/gncal-day-view.c b/calendar/gui/gncal-day-view.c
new file mode 100644
index 0000000000..e6a511f736
--- /dev/null
+++ b/calendar/gui/gncal-day-view.c
@@ -0,0 +1,254 @@
+/* Day view widget for gncal
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#include "gncal-day-view.h"
+#include "timeutil.h"
+
+
+#define TEXT_BORDER 2
+#define MIN_INFO_WIDTH 50
+
+
+static void gncal_day_view_class_init (GncalDayViewClass *class);
+static void gncal_day_view_init (GncalDayView *dview);
+static void gncal_day_view_realize (GtkWidget *widget);
+static void gncal_day_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static gint gncal_day_view_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+
+
+static GtkWidgetClass *parent_class;
+
+
+guint
+gncal_day_view_get_type (void)
+{
+ static guint day_view_type = 0;
+
+ if (!day_view_type) {
+ GtkTypeInfo day_view_info = {
+ "GncalDayView",
+ sizeof (GncalDayView),
+ sizeof (GncalDayViewClass),
+ (GtkClassInitFunc) gncal_day_view_class_init,
+ (GtkObjectInitFunc) gncal_day_view_init,
+ (GtkArgSetFunc) NULL,
+ (GtkArgGetFunc) NULL
+ };
+
+ day_view_type = gtk_type_unique (gtk_widget_get_type (), &day_view_info);
+ }
+
+ return day_view_type;
+}
+
+static void
+gncal_day_view_class_init (GncalDayViewClass *class)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = (GtkObjectClass *) class;
+ widget_class = (GtkWidgetClass *) class;
+
+ parent_class = gtk_type_class (gtk_widget_get_type ());
+
+ widget_class->realize = gncal_day_view_realize;
+ widget_class->size_request = gncal_day_view_size_request;
+ widget_class->expose_event = gncal_day_view_expose;
+}
+
+static void
+gncal_day_view_init (GncalDayView *dview)
+{
+ GTK_WIDGET_UNSET_FLAGS (dview, GTK_NO_WINDOW);
+
+ dview->calendar = NULL;
+
+ dview->lower = 0;
+ dview->upper = 24;
+ dview->use_am_pm = TRUE;
+}
+
+GtkWidget *
+gncal_day_view_new (Calendar *calendar)
+{
+ GncalDayView *dview;
+
+#if 0
+ g_assert (calendar != NULL);
+#endif
+
+ dview = gtk_type_new (gncal_day_view_get_type ());
+
+ dview->calendar = calendar;
+
+ return GTK_WIDGET (dview);
+}
+
+static void
+gncal_day_view_realize (GtkWidget *widget)
+{
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (widget));
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.x = widget->allocation.x;
+ attributes.y = widget->allocation.y;
+ attributes.width = widget->allocation.width;
+ attributes.height = widget->allocation.height;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.event_mask = (gtk_widget_get_events (widget)
+ | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK);
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+ widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
+ gdk_window_set_user_data (widget->window, widget);
+
+ widget->style = gtk_style_attach (widget->style, widget->window);
+
+ gtk_style_set_background (widget->style, widget->window, GTK_STATE_SELECTED);
+}
+
+static int
+calc_labels_width (GncalDayView *dview)
+{
+ int width, max_width;
+ GdkFont *font;
+ char *buf;
+ int i;
+
+ font = GTK_WIDGET (dview)->style->font;
+
+ max_width = 0;
+
+ for (i = 0; i < 24; i++) {
+ buf = format_simple_hour (i, dview->use_am_pm);
+ width = gdk_string_width (font, buf);
+ if (width > max_width)
+ max_width = width;
+ }
+
+ return width;
+}
+
+static void
+gncal_day_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+ GncalDayView *dview;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (widget));
+ g_return_if_fail (requisition != NULL);
+
+ dview = GNCAL_DAY_VIEW (widget);
+
+ requisition->width = 2 * widget->style->klass->xthickness + 4 * TEXT_BORDER + MIN_INFO_WIDTH;
+ requisition->height = 2 * widget->style->klass->xthickness;
+
+ requisition->width += calc_labels_width (dview);
+ requisition->height += ((dview->upper - dview->lower)
+ * (widget->style->font->ascent + widget->style->font->descent
+ + 2 * TEXT_BORDER));
+}
+
+static gint
+gncal_day_view_expose (GtkWidget *widget, GdkEventExpose *event)
+{
+ GncalDayView *dview;
+ int x1, y1, width, height;
+ int division_x;
+ int row_height;
+ int i;
+
+ g_return_val_if_fail (widget != NULL, FALSE);
+ g_return_val_if_fail (GNCAL_IS_DAY_VIEW (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ if (!GTK_WIDGET_DRAWABLE (widget))
+ return FALSE;
+
+ dview = GNCAL_DAY_VIEW (widget);
+
+ x1 = widget->style->klass->xthickness;
+ y1 = widget->style->klass->ythickness;
+ width = widget->allocation.width - 2 * x1;
+ height = widget->allocation.width - 2 * y1;
+
+ /* Clear and paint frame shadow */
+
+ gdk_window_clear_area (widget->window, event->area.x, event->area.y, event->area.width, event->area.height);
+
+ gtk_draw_shadow (widget->style, widget->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_IN,
+ 0, 0,
+ widget->allocation.width,
+ widget->allocation.height);
+
+ /* Divisions */
+
+ division_x = x1 + 2 * TEXT_BORDER + calc_labels_width (dview);
+
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ division_x, y1,
+ division_x, y1 + height - 1);
+
+ row_height = height / (dview->upper - dview->lower);
+
+ for (i = 0; i < (dview->upper - dview->lower - 1); i++)
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ x1,
+ y1 + (i + 1) * row_height,
+ x1 + width - 1,
+ y1 + (i + 1) * row_height);
+
+ return FALSE;
+}
+
+void
+gncal_day_view_set_bounds (GncalDayView *dview, int lower, int upper)
+{
+ g_return_if_fail (dview != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (dview));
+
+ lower = CLAMP (lower, 0, 23);
+ upper = CLAMP (upper, lower + 1, 24);
+
+ if ((lower != dview->lower) || (upper != dview->upper)) {
+ dview->lower = lower;
+ dview->upper = upper;
+
+ gtk_widget_queue_resize (GTK_WIDGET (dview));
+ }
+}
+
+void
+gncal_day_view_set_format (GncalDayView *dview, int use_am_pm)
+{
+ g_return_if_fail (dview != NULL);
+ g_return_if_fail (GNCAL_IS_DAY_VIEW (dview));
+
+ use_am_pm = use_am_pm ? TRUE : FALSE;
+
+ if (use_am_pm != dview->use_am_pm) {
+ dview->use_am_pm = use_am_pm;
+
+ gtk_widget_queue_resize (GTK_WIDGET (dview));
+ }
+}
diff --git a/calendar/gui/gncal-day-view.h b/calendar/gui/gncal-day-view.h
new file mode 100644
index 0000000000..ed918e4f37
--- /dev/null
+++ b/calendar/gui/gncal-day-view.h
@@ -0,0 +1,52 @@
+/* Day view widget for gncal
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#ifndef GNCAL_DAY_VIEW_H
+#define GNCAL_DAY_VIEW_H
+
+
+#include <gtk/gtkwidget.h>
+#include <libgnome/gnome-defs.h>
+#include "calendar.h"
+
+
+BEGIN_GNOME_DECLS
+
+
+#define GNCAL_DAY_VIEW(obj) GTK_CHECK_CAST (obj, gncal_day_view_get_type (), GncalDayView)
+#define GNCAL_DAY_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_day_view_get_type (), GncalDayViewClass)
+#define GNCAL_IS_DAY_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_day_view_get_type ())
+
+
+typedef struct _GncalDayView GncalDayView;
+typedef struct _GncalDayViewClass GncalDayViewClass;
+
+struct _GncalDayView {
+ GtkWidget widget;
+
+ Calendar *calendar; /* the calendar we are associated to */
+
+ int lower; /* lower and upper hours of the day to display */
+ int upper;
+ int use_am_pm; /* use am/pm (TRUE) or 24-hour format (FALSE) */
+};
+
+struct _GncalDayViewClass {
+ GtkWidgetClass parent_class;
+};
+
+
+guint gncal_day_view_get_type (void);
+GtkWidget *gncal_day_view_new (Calendar *calendar);
+
+void gncal_day_view_set_bounds (GncalDayView *dview, int lower, int upper);
+void gncal_day_view_set_format (GncalDayView *dview, int use_am_pm);
+
+
+END_GNOME_DECLS
+
+#endif
diff --git a/calendar/pcs/calobj.c b/calendar/pcs/calobj.c
index 87dd8db78d..fcdfb7e59d 100644
--- a/calendar/pcs/calobj.c
+++ b/calendar/pcs/calobj.c
@@ -13,7 +13,7 @@ ical_object_new (void)
{
iCalObject *ico;
- ico = g_new0 (iCalObject);
+ ico = g_new0 (iCalObject, 1);
ico->seq = -1;
ico->dtstamp = time (NULL);
diff --git a/calendar/pcs/calobj.h b/calendar/pcs/calobj.h
index fda3a1e4b5..d5f6db0ae0 100644
--- a/calendar/pcs/calobj.h
+++ b/calendar/pcs/calobj.h
@@ -7,6 +7,8 @@
#ifndef CALOBJ_H
#define CALOBJ_H
+#include <libgnome/libgnome.h>
+
BEGIN_GNOME_DECLS
typedef struct {
@@ -42,7 +44,7 @@ typedef struct {
typedef enum {
ICAL_OPAQUE,
ICAL_TRANSPARENT
-};
+} iCalTransp;
typedef char NotYet;
@@ -93,8 +95,8 @@ typedef struct {
iCalObject *ical_new (char *comment, char *organizer, char *summary);
iCalObject *ical_object_new (void);
+void ical_object_destroy (iCalObject *ico);
END_GNOME_DECLS
#endif
-