From 33b0ab0d0f19c405445315446fd584748538a1ed Mon Sep 17 00:00:00 2001 From: Arturo Espinosa Date: Thu, 2 Apr 1998 07:45:48 +0000 Subject: Oops, forgot these - Federico svn path=/trunk/; revision=92 --- calendar/gui/view-utils.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++ calendar/gui/view-utils.h | 26 +++++++++++ calendar/view-utils.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++ calendar/view-utils.h | 26 +++++++++++ 4 files changed, 278 insertions(+) create mode 100644 calendar/gui/view-utils.c create mode 100644 calendar/gui/view-utils.h create mode 100644 calendar/view-utils.c create mode 100644 calendar/view-utils.h (limited to 'calendar') diff --git a/calendar/gui/view-utils.c b/calendar/gui/view-utils.c new file mode 100644 index 0000000000..6b317fd70e --- /dev/null +++ b/calendar/gui/view-utils.c @@ -0,0 +1,113 @@ +/* Miscellaneous utility functions for the calendar view widgets + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena + */ + +#include +#include "view-utils.h" + + +/* FIXME: remove this function later */ + +static GList * +calendar_get_events_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) +{ + static iCalObject objs[24]; + static int ready = 0; + int i; + GList *list; + + if (!ready) { + struct tm tm; + time_t tim; + + ready = 1; + + for (i = 0; i < 24; i++) { + tim = time (NULL); + tm = *localtime (&tim); + + tm.tm_hour = i; + tm.tm_min = 0; + tm.tm_sec = 0; + objs[i].dtstart = mktime (&tm); + + tm.tm_hour = i; + tm.tm_min = 30; + tm.tm_sec = 0; + objs[i].dtend = mktime (&tm); + + objs[i].summary = "Ir a chingar a tu madre"; + } + } + + list = NULL; + + for (i = 0; i < 8; i++) + list = g_list_append (list, &objs[i]); + + return list; +} + +void +view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, + int flags, Calendar *calendar, time_t start, time_t end) +{ + int font_height; + int x, y, max_y; + char buf[512]; + int len; + struct tm tm_start, tm_end; + char *str; + iCalObject *ico; + GList *the_list, *list; + + gdk_gc_set_clip_rectangle (gc, area); + + font_height = widget->style->font->ascent + widget->style->font->descent; + + max_y = area->y + area->height - font_height * ((flags & VIEW_UTILS_DRAW_SPLIT) ? 2 : 1); + + the_list = calendar_get_events_in_range (calendar, start, end, calendar_compare_by_dtstart); + + for (y = area->y, list = the_list; (y < max_y) && list; y += font_height, list = list->next) { + ico = list->data; + + tm_start = *localtime (&ico->dtstart); + tm_end = *localtime (&ico->dtend); + str = ico->summary; + + if (flags & VIEW_UTILS_DRAW_END) { + strftime (buf, 512, "%X - ", &tm_start); + len = strlen (buf); + strftime (buf + len, 512 - len, "%X ", &tm_end); + } else + strftime (buf, 512, "%X ", &tm_start); + + gdk_draw_string (window, + widget->style->font, + gc, + area->x, + y + widget->style->font->ascent, + buf); + + if (flags & VIEW_UTILS_DRAW_SPLIT) { + y += font_height; + x = widget->style->font->ascent; /* some indentation */ + } else + x = gdk_string_width (widget->style->font, buf); + + gdk_draw_string (window, + widget->style->font, + gc, + x, + y + widget->style->font->ascent, + str); + } + + g_list_free (the_list); + + gdk_gc_set_clip_rectangle (gc, NULL); +} diff --git a/calendar/gui/view-utils.h b/calendar/gui/view-utils.h new file mode 100644 index 0000000000..c334bbd6d3 --- /dev/null +++ b/calendar/gui/view-utils.h @@ -0,0 +1,26 @@ +/* Miscellaneous utility functions for the calendar view widgets + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena + */ + +#ifndef VIEW_UTILS_H +#define VIEW_UTILS_H + + +#include +#include "calendar.h" + + +enum { + VIEW_UTILS_DRAW_END = 1 << 0, + VIEW_UTILS_DRAW_SPLIT = 1 << 1 +}; + + +void view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, + int flags, Calendar *calendar, time_t start, time_t end); + + +#endif diff --git a/calendar/view-utils.c b/calendar/view-utils.c new file mode 100644 index 0000000000..6b317fd70e --- /dev/null +++ b/calendar/view-utils.c @@ -0,0 +1,113 @@ +/* Miscellaneous utility functions for the calendar view widgets + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena + */ + +#include +#include "view-utils.h" + + +/* FIXME: remove this function later */ + +static GList * +calendar_get_events_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) +{ + static iCalObject objs[24]; + static int ready = 0; + int i; + GList *list; + + if (!ready) { + struct tm tm; + time_t tim; + + ready = 1; + + for (i = 0; i < 24; i++) { + tim = time (NULL); + tm = *localtime (&tim); + + tm.tm_hour = i; + tm.tm_min = 0; + tm.tm_sec = 0; + objs[i].dtstart = mktime (&tm); + + tm.tm_hour = i; + tm.tm_min = 30; + tm.tm_sec = 0; + objs[i].dtend = mktime (&tm); + + objs[i].summary = "Ir a chingar a tu madre"; + } + } + + list = NULL; + + for (i = 0; i < 8; i++) + list = g_list_append (list, &objs[i]); + + return list; +} + +void +view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, + int flags, Calendar *calendar, time_t start, time_t end) +{ + int font_height; + int x, y, max_y; + char buf[512]; + int len; + struct tm tm_start, tm_end; + char *str; + iCalObject *ico; + GList *the_list, *list; + + gdk_gc_set_clip_rectangle (gc, area); + + font_height = widget->style->font->ascent + widget->style->font->descent; + + max_y = area->y + area->height - font_height * ((flags & VIEW_UTILS_DRAW_SPLIT) ? 2 : 1); + + the_list = calendar_get_events_in_range (calendar, start, end, calendar_compare_by_dtstart); + + for (y = area->y, list = the_list; (y < max_y) && list; y += font_height, list = list->next) { + ico = list->data; + + tm_start = *localtime (&ico->dtstart); + tm_end = *localtime (&ico->dtend); + str = ico->summary; + + if (flags & VIEW_UTILS_DRAW_END) { + strftime (buf, 512, "%X - ", &tm_start); + len = strlen (buf); + strftime (buf + len, 512 - len, "%X ", &tm_end); + } else + strftime (buf, 512, "%X ", &tm_start); + + gdk_draw_string (window, + widget->style->font, + gc, + area->x, + y + widget->style->font->ascent, + buf); + + if (flags & VIEW_UTILS_DRAW_SPLIT) { + y += font_height; + x = widget->style->font->ascent; /* some indentation */ + } else + x = gdk_string_width (widget->style->font, buf); + + gdk_draw_string (window, + widget->style->font, + gc, + x, + y + widget->style->font->ascent, + str); + } + + g_list_free (the_list); + + gdk_gc_set_clip_rectangle (gc, NULL); +} diff --git a/calendar/view-utils.h b/calendar/view-utils.h new file mode 100644 index 0000000000..c334bbd6d3 --- /dev/null +++ b/calendar/view-utils.h @@ -0,0 +1,26 @@ +/* Miscellaneous utility functions for the calendar view widgets + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena + */ + +#ifndef VIEW_UTILS_H +#define VIEW_UTILS_H + + +#include +#include "calendar.h" + + +enum { + VIEW_UTILS_DRAW_END = 1 << 0, + VIEW_UTILS_DRAW_SPLIT = 1 << 1 +}; + + +void view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, + int flags, Calendar *calendar, time_t start, time_t end); + + +#endif -- cgit v1.2.3