aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog14
-rw-r--r--calendar/Makefile.am6
-rw-r--r--calendar/gnome-cal.c10
-rw-r--r--calendar/gui/Makefile.am6
-rw-r--r--calendar/gui/gnome-cal.c10
-rw-r--r--calendar/gui/month-view.c6
-rw-r--r--calendar/gui/year-view.c288
-rw-r--r--calendar/gui/year-view.h63
-rw-r--r--calendar/month-view.c6
-rw-r--r--calendar/year-view.c288
-rw-r--r--calendar/year-view.h63
11 files changed, 672 insertions, 88 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index f0efda99f5..498ca2d484 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,17 @@
+1998-08-26 Federico Mena Quintero <federico@nuclecu.unam.mx>
+
+ * year-view.c: Beginning of the new year view. Sizing and event
+ marking needs to be finished.
+
+ * gnome-cal.c: Updated for year-view.
+ (gnome_calendar_time_format_changed): Use year_view_time_format_changed().
+
+ * year-view.[ch]: Renamed the gncal-year-view.[ch] files to
+ year-view.[ch].
+
+ * Makefile.am (gnomecal_SOURCES): Updated year-view.[ch] in the
+ list of source files.
+
1998-08-25 Federico Mena Quintero <federico@nuclecu.unam.mx>
* goto.c (create_days): Set the heading color of the month item.
diff --git a/calendar/Makefile.am b/calendar/Makefile.am
index 993cdf58b7..dfd034e433 100644
--- a/calendar/Makefile.am
+++ b/calendar/Makefile.am
@@ -31,8 +31,6 @@ gnomecal_SOURCES = \
gncal-week-view.h \
gncal-todo.c \
gncal-todo.h \
- gncal-year-view.c \
- gncal-year-view.h \
gnome-month-item.c \
gnome-month-item.h \
gnome-cal.c \
@@ -48,7 +46,9 @@ gnomecal_SOURCES = \
timeutil.c \
timeutil.h \
view-utils.h \
- view-utils.c
+ view-utils.c \
+ year-view.c \
+ year-view.h
LINK_FLAGS = \
$(GNOME_LIBDIR) \
diff --git a/calendar/gnome-cal.c b/calendar/gnome-cal.c
index c9c62101b9..cf9dbefcc7 100644
--- a/calendar/gnome-cal.c
+++ b/calendar/gnome-cal.c
@@ -14,8 +14,8 @@
#include "gnome-cal.h"
#include "gncal-day-panel.h"
#include "gncal-week-view.h"
-#include "gncal-year-view.h"
#include "month-view.h"
+#include "year-view.h"
#include "timeutil.h"
#include "main.h"
@@ -52,7 +52,7 @@ setup_widgets (GnomeCalendar *gcal)
gcal->day_view = gncal_day_panel_new (gcal, now);
gcal->week_view = gncal_week_view_new (gcal, now);
gcal->month_view = month_view_new (gcal, now);
- gcal->year_view = gncal_year_view_new (gcal, now);
+ gcal->year_view = year_view_new (gcal, now);
gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->day_view, gtk_label_new (_("Day View")));
gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->week_view, gtk_label_new (_("Week View")));
@@ -104,7 +104,7 @@ gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time)
else if (current == gcal->month_view)
month_view_set (MONTH_VIEW (gcal->month_view), new_time);
else if (current == gcal->year_view)
- gncal_year_view_set (GNCAL_YEAR_VIEW (gcal->year_view), new_time);
+ year_view_set (YEAR_VIEW (gcal->year_view), new_time);
else {
g_warning ("My penguin is gone!");
g_assert_not_reached ();
@@ -205,7 +205,7 @@ gnome_calendar_update_all (GnomeCalendar *cal, iCalObject *object, int flags)
gncal_day_panel_update (GNCAL_DAY_PANEL (cal->day_view), object, flags);
gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), object, flags);
month_view_update (MONTH_VIEW (cal->month_view), object, flags);
- gncal_year_view_update (GNCAL_YEAR_VIEW (cal->year_view), object, flags);
+ year_view_update (YEAR_VIEW (cal->year_view), object, flags);
}
int
@@ -438,5 +438,5 @@ gnome_calendar_time_format_changed (GnomeCalendar *gcal)
gtk_widget_queue_resize (gcal->day_view);
gtk_widget_queue_resize (gcal->week_view);
month_view_time_format_changed (MONTH_VIEW (gcal->month_view));
- gtk_widget_queue_resize (gcal->year_view);
+ year_view_time_format_changed (YEAR_VIEW (gcal->year_view));
}
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 993cdf58b7..dfd034e433 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -31,8 +31,6 @@ gnomecal_SOURCES = \
gncal-week-view.h \
gncal-todo.c \
gncal-todo.h \
- gncal-year-view.c \
- gncal-year-view.h \
gnome-month-item.c \
gnome-month-item.h \
gnome-cal.c \
@@ -48,7 +46,9 @@ gnomecal_SOURCES = \
timeutil.c \
timeutil.h \
view-utils.h \
- view-utils.c
+ view-utils.c \
+ year-view.c \
+ year-view.h
LINK_FLAGS = \
$(GNOME_LIBDIR) \
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index c9c62101b9..cf9dbefcc7 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -14,8 +14,8 @@
#include "gnome-cal.h"
#include "gncal-day-panel.h"
#include "gncal-week-view.h"
-#include "gncal-year-view.h"
#include "month-view.h"
+#include "year-view.h"
#include "timeutil.h"
#include "main.h"
@@ -52,7 +52,7 @@ setup_widgets (GnomeCalendar *gcal)
gcal->day_view = gncal_day_panel_new (gcal, now);
gcal->week_view = gncal_week_view_new (gcal, now);
gcal->month_view = month_view_new (gcal, now);
- gcal->year_view = gncal_year_view_new (gcal, now);
+ gcal->year_view = year_view_new (gcal, now);
gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->day_view, gtk_label_new (_("Day View")));
gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->week_view, gtk_label_new (_("Week View")));
@@ -104,7 +104,7 @@ gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time)
else if (current == gcal->month_view)
month_view_set (MONTH_VIEW (gcal->month_view), new_time);
else if (current == gcal->year_view)
- gncal_year_view_set (GNCAL_YEAR_VIEW (gcal->year_view), new_time);
+ year_view_set (YEAR_VIEW (gcal->year_view), new_time);
else {
g_warning ("My penguin is gone!");
g_assert_not_reached ();
@@ -205,7 +205,7 @@ gnome_calendar_update_all (GnomeCalendar *cal, iCalObject *object, int flags)
gncal_day_panel_update (GNCAL_DAY_PANEL (cal->day_view), object, flags);
gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), object, flags);
month_view_update (MONTH_VIEW (cal->month_view), object, flags);
- gncal_year_view_update (GNCAL_YEAR_VIEW (cal->year_view), object, flags);
+ year_view_update (YEAR_VIEW (cal->year_view), object, flags);
}
int
@@ -438,5 +438,5 @@ gnome_calendar_time_format_changed (GnomeCalendar *gcal)
gtk_widget_queue_resize (gcal->day_view);
gtk_widget_queue_resize (gcal->week_view);
month_view_time_format_changed (MONTH_VIEW (gcal->month_view));
- gtk_widget_queue_resize (gcal->year_view);
+ year_view_time_format_changed (YEAR_VIEW (gcal->year_view));
}
diff --git a/calendar/gui/month-view.c b/calendar/gui/month-view.c
index 01d4391b25..16e6c72e8a 100644
--- a/calendar/gui/month-view.c
+++ b/calendar/gui/month-view.c
@@ -93,12 +93,12 @@ month_view_new (GnomeCalendar *calendar, time_t month)
MonthView *mv;
g_return_val_if_fail (calendar != NULL, NULL);
+ g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL);
mv = gtk_type_new (month_view_get_type ());
mv->calendar = calendar;
month_view_set (mv, month);
-
return GTK_WIDGET (mv);
}
@@ -106,7 +106,7 @@ static void
month_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (IS_MONTH_VIEW (widget));
g_return_if_fail (requisition != NULL);
if (GTK_WIDGET_CLASS (parent_class)->size_request)
@@ -125,7 +125,7 @@ month_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
int y;
g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (IS_MONTH_VIEW (widget));
g_return_if_fail (allocation != NULL);
mv = MONTH_VIEW (widget);
diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c
index 0a104f25a3..8a5bedc038 100644
--- a/calendar/gui/year-view.c
+++ b/calendar/gui/year-view.c
@@ -1,13 +1,289 @@
-/* Week view composite widget for gncal
+/* Year view display for gncal
*
* Copyright (C) 1998 The Free Software Foundation
*
- * Author: Arturo Espinosa <arturo@nuclecu.unam.mx>
- *
- * Heavily based on Federico Mena's week view.
- *
+ * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx>
+ * Federico Mena <federico@nuclecu.unam.mx>
*/
+#include <config.h>
+#include <libgnomeui/gnome-canvas-text.h>
+#include "year-view.h"
+#include "main.h"
+
+
+#define HEAD_SPACING 4 /* Spacing between year heading and months */
+#define TITLE_SPACING 2 /* Spacing between title and calendar */
+#define SPACING 4 /* Spacing between months */
+
+
+static void year_view_class_init (YearViewClass *class);
+static void year_view_init (YearView *yv);
+static void year_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void year_view_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+
+
+static GnomeCanvas *parent_class;
+
+
+GtkType
+year_view_get_type (void)
+{
+ static GtkType year_view_type = 0;
+
+ if (!year_view_type) {
+ GtkTypeInfo year_view_info = {
+ "YearView",
+ sizeof (YearView),
+ sizeof (YearViewClass),
+ (GtkClassInitFunc) year_view_class_init,
+ (GtkObjectInitFunc) year_view_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ year_view_type = gtk_type_unique (gnome_canvas_get_type (), &year_view_info);
+ }
+
+ return year_view_type;
+}
+
+static void
+year_view_class_init (YearViewClass *class)
+{
+ GtkWidgetClass *widget_class;
+
+ widget_class = (GtkWidgetClass *) class;
+
+ parent_class = gtk_type_class (gnome_canvas_get_type ());
+
+ widget_class->size_request = year_view_size_request;
+ widget_class->size_allocate = year_view_size_allocate;
+}
+
+static void
+year_view_init (YearView *yv)
+{
+ int i;
+ char buf[100];
+ struct tm tm;
+
+ memset (&tm, 0, sizeof (tm));
+
+ /* Heading */
+
+ yv->heading = gnome_canvas_item_new (GNOME_CANVAS_GROUP (yv->canvas.root),
+ gnome_canvas_text_get_type (),
+ "anchor", GTK_ANCHOR_N,
+ "font", "-*-helvetica-bold-r-normal--14-*-*-*-*-*-iso8859-1",
+ "fill_color", "black",
+ NULL);
+
+ /* Months */
+
+ for (i = 0; i < 12; i++) {
+ /* Title */
+
+ strftime (buf, 100, "%B", &tm);
+ tm.tm_mon++;
+
+ yv->titles[i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (yv->canvas.root),
+ gnome_canvas_text_get_type (),
+ "text", buf,
+ "anchor", GTK_ANCHOR_N,
+ "font", "-*-helvetica-bold-r-normal--12-*-*-*-*-*-iso8859-1",
+ "fill_color", "black",
+ NULL);
+
+ /* Month item */
+
+ yv->mitems[i] = gnome_month_item_new (GNOME_CANVAS_GROUP (yv->canvas.root));
+ gnome_canvas_item_set (yv->mitems[i],
+ "anchor", GTK_ANCHOR_NW,
+ "start_on_monday", week_starts_on_monday,
+ "heading_color", "white",
+ NULL);
+ }
+}
+
+GtkWidget *
+year_view_new (GnomeCalendar *calendar, time_t year)
+{
+ YearView *yv;
+
+ g_return_val_if_fail (calendar != NULL, NULL);
+ g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL);
+
+ yv = gtk_type_new (year_view_get_type ());
+ yv->calendar = calendar;
+
+ year_view_set (yv, year);
+ return GTK_WIDGET (yv);
+}
+
+static void
+year_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+ YearView *yv;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (widget));
+ g_return_if_fail (requisition != NULL);
+
+ yv = YEAR_VIEW (widget);
+
+ if (GTK_WIDGET_CLASS (parent_class)->size_request)
+ (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition);
+
+ requisition->width = 200;
+ requisition->height = 150;
+}
+
+static void
+year_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ YearView *yv;
+ double width, height;
+ double mwidth, mheight;
+ double h_yofs;
+ double m_yofs;
+ double x, y;
+ int i;
+ GtkArg arg;
+ GdkFont *head_font, *title_font;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (widget));
+ g_return_if_fail (allocation != NULL);
+
+ yv = YEAR_VIEW (widget);
+
+ if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
+ (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS (yv), 0, 0, allocation->width, allocation->height);
+
+ arg.name = "font_gdk";
+ gtk_object_getv (GTK_OBJECT (yv->heading), 1, &arg);
+ head_font = GTK_VALUE_BOXED (arg);
+
+ arg.name = "font_gdk";
+ gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &arg);
+ title_font = GTK_VALUE_BOXED (arg);
+
+ /* Adjust heading */
+
+ gnome_canvas_item_set (yv->heading,
+ "x", (double) allocation->width / 2.0,
+ "y", (double) HEAD_SPACING,
+ NULL);
+
+ /* Adjust months */
+
+ h_yofs = 2 * HEAD_SPACING + head_font->ascent + head_font->descent;
+ m_yofs = SPACING + title_font->ascent + title_font->descent;
+
+ width = (allocation->width + SPACING) / 3.0;
+ height = (allocation->height - h_yofs + SPACING) / 4.0;
+
+ mwidth = (allocation->width - 2 * SPACING) / 3.0;
+ mheight = (allocation->height - h_yofs - 3 * SPACING - 4 * m_yofs) / 4.0;
+
+ for (i = 0; i < 12; i++) {
+ x = (i % 3) * width;
+ y = (i / 3) * height + h_yofs;
+
+ /* Title */
+
+ gnome_canvas_item_set (yv->titles[i],
+ "x", x + width / 2.0,
+ "y", y,
+ NULL);
+
+ /* Month item */
+
+ gnome_canvas_item_set (yv->mitems[i],
+ "x", x,
+ "y", y + m_yofs,
+ "width", mwidth,
+ "height", mheight,
+ NULL);
+ }
+}
+
+void
+year_view_update (YearView *yv, iCalObject *object, int flags)
+{
+ g_return_if_fail (yv != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (yv));
+
+ /* FIXME */
+}
+
+void
+year_view_set (YearView *yv, time_t year)
+{
+ struct tm tm;
+ int i;
+ char buf[100];
+
+ g_return_if_fail (yv != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (yv));
+
+ tm = *localtime (&year);
+
+ /* Heading */
+
+ sprintf (buf, "%d", tm.tm_year + 1900);
+ gnome_canvas_item_set (yv->heading,
+ "text", buf,
+ NULL);
+
+ /* Months */
+
+ for (i = 0; i < 12; i++)
+ gnome_canvas_item_set (yv->mitems[i],
+ "year", tm.tm_year + 1900,
+ "month", i,
+ NULL);
+
+ /* FIXME: update events */
+}
+
+void
+year_view_time_format_changed (YearView *yv)
+{
+ int i;
+
+ g_return_if_fail (yv != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (yv));
+
+ for (i = 0; i < 12; i++)
+ gnome_canvas_item_set (yv->mitems[i],
+ "start_on_monday", week_starts_on_monday,
+ NULL);
+
+ /* FIXME: update events */
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+
#include "gncal-year-view.h"
#include "calendar.h"
#include "timeutil.h"
@@ -243,3 +519,5 @@ gncal_year_view_update (GncalYearView *yview, iCalObject *ico, int flags)
gncal_year_view_set_year (yview, yview->year);
}
+
+#endif
diff --git a/calendar/gui/year-view.h b/calendar/gui/year-view.h
index f31d5ae4a3..0638698fb4 100644
--- a/calendar/gui/year-view.h
+++ b/calendar/gui/year-view.h
@@ -1,54 +1,61 @@
-/* Week view composite widget for gncal
+/* Year view display for gncal
*
* Copyright (C) 1998 The Free Software Foundation
*
- * Author: Arturo Espinosa <arturo@nuclecu.unam.mx>
- *
- * Heavily based on Federico Mena's week view.
- *
+ * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx>
+ * Federico Mena <federico@nuclecu.unam.mx>
*/
#ifndef YEAR_VIEW_H
#define YEAR_VIEW_H
-#include <time.h>
-#include <gtk/gtktable.h>
#include <libgnome/gnome-defs.h>
-#include <libgnomeui/gtkcalendar.h>
-
#include "gnome-cal.h"
+#include "gnome-month-item.h"
+
BEGIN_GNOME_DECLS
-#define GNCAL_YEAR_VIEW(obj) GTK_CHECK_CAST (obj, gncal_year_view_get_type (), GncalYearView)
-#define GNCAL_YEAR_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_year_view_get_type (), GncalYearViewClass)
-#define GNCAL_IS_YEAR_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_year_view_get_type ())
+#define TYPE_YEAR_VIEW (year_view_get_type ())
+#define YEAR_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_YEAR_VIEW, YearView))
+#define YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_YEAR_VIEW, YearViewClass))
+#define IS_YEAR_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_YEAR_VIEW))
+#define IS_YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_YEAR_VIEW))
-typedef struct _GncalYearView GncalYearView;
-typedef struct _GncalYearViewClass GncalYearViewClass;
+typedef struct _YearView YearView;
+typedef struct _YearViewClass YearViewClass;
-struct _GncalYearView {
- GtkTable table;
+struct _YearView {
+ GnomeCanvas canvas;
- GnomeCalendar *gcal; /* The calendar we are associated to */
- GtkWidget *calendar[12]; /* one calendar per month */
- guint handler[12]; /* for (un)blocking the calendars */
-
- GtkWidget *year_label;
- gint year;
+ GnomeCalendar *calendar; /* The calendar we are associated to */
+
+ GnomeCanvasItem *heading; /* Big heading with year */
+ GnomeCanvasItem *titles[12]; /* Titles for months */
+ GnomeCanvasItem *mitems[12]; /* Month items */
};
-struct _GncalYearViewClass {
- GtkTableClass parent_class;
+struct _YearViewClass {
+ GnomeCanvasClass parent_class;
};
-guint gncal_year_view_get_type (void);
-GtkWidget *gncal_year_view_new (GnomeCalendar *calendar, time_t date);
-void gncal_year_view_set (GncalYearView *yview, time_t date);
-void gncal_year_view_update (GncalYearView *yview, iCalObject *ico, int flags);
+/* Standard Gtk function */
+GtkType year_view_get_type (void);
+
+/* Creates a new year view widget associated to the specified calendar */
+GtkWidget *year_view_new (GnomeCalendar *calendar, time_t year);
+
+/* Notifies the year view that a calendar object has changed */
+void year_view_update (YearView *yv, iCalObject *ico, int flags);
+
+/* Notifies the year view about a change of date */
+void year_view_set (YearView *yv, time_t year);
+
+/* Notifies the year view that the time format has changed */
+void year_view_time_format_changed (YearView *yv);
END_GNOME_DECLS
diff --git a/calendar/month-view.c b/calendar/month-view.c
index 01d4391b25..16e6c72e8a 100644
--- a/calendar/month-view.c
+++ b/calendar/month-view.c
@@ -93,12 +93,12 @@ month_view_new (GnomeCalendar *calendar, time_t month)
MonthView *mv;
g_return_val_if_fail (calendar != NULL, NULL);
+ g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL);
mv = gtk_type_new (month_view_get_type ());
mv->calendar = calendar;
month_view_set (mv, month);
-
return GTK_WIDGET (mv);
}
@@ -106,7 +106,7 @@ static void
month_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (IS_MONTH_VIEW (widget));
g_return_if_fail (requisition != NULL);
if (GTK_WIDGET_CLASS (parent_class)->size_request)
@@ -125,7 +125,7 @@ month_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
int y;
g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (IS_MONTH_VIEW (widget));
g_return_if_fail (allocation != NULL);
mv = MONTH_VIEW (widget);
diff --git a/calendar/year-view.c b/calendar/year-view.c
index 0a104f25a3..8a5bedc038 100644
--- a/calendar/year-view.c
+++ b/calendar/year-view.c
@@ -1,13 +1,289 @@
-/* Week view composite widget for gncal
+/* Year view display for gncal
*
* Copyright (C) 1998 The Free Software Foundation
*
- * Author: Arturo Espinosa <arturo@nuclecu.unam.mx>
- *
- * Heavily based on Federico Mena's week view.
- *
+ * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx>
+ * Federico Mena <federico@nuclecu.unam.mx>
*/
+#include <config.h>
+#include <libgnomeui/gnome-canvas-text.h>
+#include "year-view.h"
+#include "main.h"
+
+
+#define HEAD_SPACING 4 /* Spacing between year heading and months */
+#define TITLE_SPACING 2 /* Spacing between title and calendar */
+#define SPACING 4 /* Spacing between months */
+
+
+static void year_view_class_init (YearViewClass *class);
+static void year_view_init (YearView *yv);
+static void year_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void year_view_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+
+
+static GnomeCanvas *parent_class;
+
+
+GtkType
+year_view_get_type (void)
+{
+ static GtkType year_view_type = 0;
+
+ if (!year_view_type) {
+ GtkTypeInfo year_view_info = {
+ "YearView",
+ sizeof (YearView),
+ sizeof (YearViewClass),
+ (GtkClassInitFunc) year_view_class_init,
+ (GtkObjectInitFunc) year_view_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ year_view_type = gtk_type_unique (gnome_canvas_get_type (), &year_view_info);
+ }
+
+ return year_view_type;
+}
+
+static void
+year_view_class_init (YearViewClass *class)
+{
+ GtkWidgetClass *widget_class;
+
+ widget_class = (GtkWidgetClass *) class;
+
+ parent_class = gtk_type_class (gnome_canvas_get_type ());
+
+ widget_class->size_request = year_view_size_request;
+ widget_class->size_allocate = year_view_size_allocate;
+}
+
+static void
+year_view_init (YearView *yv)
+{
+ int i;
+ char buf[100];
+ struct tm tm;
+
+ memset (&tm, 0, sizeof (tm));
+
+ /* Heading */
+
+ yv->heading = gnome_canvas_item_new (GNOME_CANVAS_GROUP (yv->canvas.root),
+ gnome_canvas_text_get_type (),
+ "anchor", GTK_ANCHOR_N,
+ "font", "-*-helvetica-bold-r-normal--14-*-*-*-*-*-iso8859-1",
+ "fill_color", "black",
+ NULL);
+
+ /* Months */
+
+ for (i = 0; i < 12; i++) {
+ /* Title */
+
+ strftime (buf, 100, "%B", &tm);
+ tm.tm_mon++;
+
+ yv->titles[i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (yv->canvas.root),
+ gnome_canvas_text_get_type (),
+ "text", buf,
+ "anchor", GTK_ANCHOR_N,
+ "font", "-*-helvetica-bold-r-normal--12-*-*-*-*-*-iso8859-1",
+ "fill_color", "black",
+ NULL);
+
+ /* Month item */
+
+ yv->mitems[i] = gnome_month_item_new (GNOME_CANVAS_GROUP (yv->canvas.root));
+ gnome_canvas_item_set (yv->mitems[i],
+ "anchor", GTK_ANCHOR_NW,
+ "start_on_monday", week_starts_on_monday,
+ "heading_color", "white",
+ NULL);
+ }
+}
+
+GtkWidget *
+year_view_new (GnomeCalendar *calendar, time_t year)
+{
+ YearView *yv;
+
+ g_return_val_if_fail (calendar != NULL, NULL);
+ g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL);
+
+ yv = gtk_type_new (year_view_get_type ());
+ yv->calendar = calendar;
+
+ year_view_set (yv, year);
+ return GTK_WIDGET (yv);
+}
+
+static void
+year_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+ YearView *yv;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (widget));
+ g_return_if_fail (requisition != NULL);
+
+ yv = YEAR_VIEW (widget);
+
+ if (GTK_WIDGET_CLASS (parent_class)->size_request)
+ (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition);
+
+ requisition->width = 200;
+ requisition->height = 150;
+}
+
+static void
+year_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ YearView *yv;
+ double width, height;
+ double mwidth, mheight;
+ double h_yofs;
+ double m_yofs;
+ double x, y;
+ int i;
+ GtkArg arg;
+ GdkFont *head_font, *title_font;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (widget));
+ g_return_if_fail (allocation != NULL);
+
+ yv = YEAR_VIEW (widget);
+
+ if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
+ (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS (yv), 0, 0, allocation->width, allocation->height);
+
+ arg.name = "font_gdk";
+ gtk_object_getv (GTK_OBJECT (yv->heading), 1, &arg);
+ head_font = GTK_VALUE_BOXED (arg);
+
+ arg.name = "font_gdk";
+ gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &arg);
+ title_font = GTK_VALUE_BOXED (arg);
+
+ /* Adjust heading */
+
+ gnome_canvas_item_set (yv->heading,
+ "x", (double) allocation->width / 2.0,
+ "y", (double) HEAD_SPACING,
+ NULL);
+
+ /* Adjust months */
+
+ h_yofs = 2 * HEAD_SPACING + head_font->ascent + head_font->descent;
+ m_yofs = SPACING + title_font->ascent + title_font->descent;
+
+ width = (allocation->width + SPACING) / 3.0;
+ height = (allocation->height - h_yofs + SPACING) / 4.0;
+
+ mwidth = (allocation->width - 2 * SPACING) / 3.0;
+ mheight = (allocation->height - h_yofs - 3 * SPACING - 4 * m_yofs) / 4.0;
+
+ for (i = 0; i < 12; i++) {
+ x = (i % 3) * width;
+ y = (i / 3) * height + h_yofs;
+
+ /* Title */
+
+ gnome_canvas_item_set (yv->titles[i],
+ "x", x + width / 2.0,
+ "y", y,
+ NULL);
+
+ /* Month item */
+
+ gnome_canvas_item_set (yv->mitems[i],
+ "x", x,
+ "y", y + m_yofs,
+ "width", mwidth,
+ "height", mheight,
+ NULL);
+ }
+}
+
+void
+year_view_update (YearView *yv, iCalObject *object, int flags)
+{
+ g_return_if_fail (yv != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (yv));
+
+ /* FIXME */
+}
+
+void
+year_view_set (YearView *yv, time_t year)
+{
+ struct tm tm;
+ int i;
+ char buf[100];
+
+ g_return_if_fail (yv != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (yv));
+
+ tm = *localtime (&year);
+
+ /* Heading */
+
+ sprintf (buf, "%d", tm.tm_year + 1900);
+ gnome_canvas_item_set (yv->heading,
+ "text", buf,
+ NULL);
+
+ /* Months */
+
+ for (i = 0; i < 12; i++)
+ gnome_canvas_item_set (yv->mitems[i],
+ "year", tm.tm_year + 1900,
+ "month", i,
+ NULL);
+
+ /* FIXME: update events */
+}
+
+void
+year_view_time_format_changed (YearView *yv)
+{
+ int i;
+
+ g_return_if_fail (yv != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (yv));
+
+ for (i = 0; i < 12; i++)
+ gnome_canvas_item_set (yv->mitems[i],
+ "start_on_monday", week_starts_on_monday,
+ NULL);
+
+ /* FIXME: update events */
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+
#include "gncal-year-view.h"
#include "calendar.h"
#include "timeutil.h"
@@ -243,3 +519,5 @@ gncal_year_view_update (GncalYearView *yview, iCalObject *ico, int flags)
gncal_year_view_set_year (yview, yview->year);
}
+
+#endif
diff --git a/calendar/year-view.h b/calendar/year-view.h
index f31d5ae4a3..0638698fb4 100644
--- a/calendar/year-view.h
+++ b/calendar/year-view.h
@@ -1,54 +1,61 @@
-/* Week view composite widget for gncal
+/* Year view display for gncal
*
* Copyright (C) 1998 The Free Software Foundation
*
- * Author: Arturo Espinosa <arturo@nuclecu.unam.mx>
- *
- * Heavily based on Federico Mena's week view.
- *
+ * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx>
+ * Federico Mena <federico@nuclecu.unam.mx>
*/
#ifndef YEAR_VIEW_H
#define YEAR_VIEW_H
-#include <time.h>
-#include <gtk/gtktable.h>
#include <libgnome/gnome-defs.h>
-#include <libgnomeui/gtkcalendar.h>
-
#include "gnome-cal.h"
+#include "gnome-month-item.h"
+
BEGIN_GNOME_DECLS
-#define GNCAL_YEAR_VIEW(obj) GTK_CHECK_CAST (obj, gncal_year_view_get_type (), GncalYearView)
-#define GNCAL_YEAR_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_year_view_get_type (), GncalYearViewClass)
-#define GNCAL_IS_YEAR_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_year_view_get_type ())
+#define TYPE_YEAR_VIEW (year_view_get_type ())
+#define YEAR_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_YEAR_VIEW, YearView))
+#define YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_YEAR_VIEW, YearViewClass))
+#define IS_YEAR_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_YEAR_VIEW))
+#define IS_YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_YEAR_VIEW))
-typedef struct _GncalYearView GncalYearView;
-typedef struct _GncalYearViewClass GncalYearViewClass;
+typedef struct _YearView YearView;
+typedef struct _YearViewClass YearViewClass;
-struct _GncalYearView {
- GtkTable table;
+struct _YearView {
+ GnomeCanvas canvas;
- GnomeCalendar *gcal; /* The calendar we are associated to */
- GtkWidget *calendar[12]; /* one calendar per month */
- guint handler[12]; /* for (un)blocking the calendars */
-
- GtkWidget *year_label;
- gint year;
+ GnomeCalendar *calendar; /* The calendar we are associated to */
+
+ GnomeCanvasItem *heading; /* Big heading with year */
+ GnomeCanvasItem *titles[12]; /* Titles for months */
+ GnomeCanvasItem *mitems[12]; /* Month items */
};
-struct _GncalYearViewClass {
- GtkTableClass parent_class;
+struct _YearViewClass {
+ GnomeCanvasClass parent_class;
};
-guint gncal_year_view_get_type (void);
-GtkWidget *gncal_year_view_new (GnomeCalendar *calendar, time_t date);
-void gncal_year_view_set (GncalYearView *yview, time_t date);
-void gncal_year_view_update (GncalYearView *yview, iCalObject *ico, int flags);
+/* Standard Gtk function */
+GtkType year_view_get_type (void);
+
+/* Creates a new year view widget associated to the specified calendar */
+GtkWidget *year_view_new (GnomeCalendar *calendar, time_t year);
+
+/* Notifies the year view that a calendar object has changed */
+void year_view_update (YearView *yv, iCalObject *ico, int flags);
+
+/* Notifies the year view about a change of date */
+void year_view_set (YearView *yv, time_t year);
+
+/* Notifies the year view that the time format has changed */
+void year_view_time_format_changed (YearView *yv);
END_GNOME_DECLS