aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/mark.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@nuclecu.unam.mx>1998-10-01 00:44:14 +0800
committerArturo Espinosa <unammx@src.gnome.org>1998-10-01 00:44:14 +0800
commite6ffe37f192876fd256ef29fcbabfbbc009e6c64 (patch)
treeaec1663e19a0fe6b4caf8af8767f669d573aaa97 /calendar/mark.c
parent9e927267cdd157e56c238ea131758ecaadbe6309 (diff)
downloadgsoc2013-evolution-e6ffe37f192876fd256ef29fcbabfbbc009e6c64.tar.gz
gsoc2013-evolution-e6ffe37f192876fd256ef29fcbabfbbc009e6c64.tar.zst
gsoc2013-evolution-e6ffe37f192876fd256ef29fcbabfbbc009e6c64.zip
Stuff that I forgot to commit yesterday.
Stuff that I forgot to commit yesterday. Now the year view has a nifty pop-up view you can activate if you click on a day with mouse button 1. It will display a quick view of the appointments in that day. Also, reworked the marking and coloring code for month items so that the year view is not glacially slow anymore when switching years. It still is slow when first mapping or realizing the year view, I'm not sure why. I will look into that. 1998-09-29 Federico Mena Quintero <federico@nuclecu.unam.mx> * prop.c (fetch_color_spec): Changed name from fetch_prelight_spec and made it conform to the new prelighting mechanism. (fake_mark_days): Set the proper day attributes. (reconfigure_month): Use colorify_month_item(). (fake_mark_days): Use mark_month_item_index(). * mark.c (colorify_month_item): New public function to reset the colors in a month item. (get_attributes): New internal function that creates an array of attributes for the days in a month item. This is the basis of all the new optimizations to month item marking. (unmark_month_item): Now it uses the attributes array to unmark only the days that need unmarking. (mark_event_in_month): Update the day attributes array. (month_item_prepare_prelight): Changed the definition of the prelight color query function. Use the new function. (day_event): Do color changes based on the day attributes array. (mark_month_item_index): New public function to mark a single day by index. (mark_event_in_month): Use mark_month_item_index(). * gnome-month-item.c (gnome_month_item_num2child): Now takes an int, not a GnomeMonthItemChild. (gnome_month_item_child2num): Now returns an int, not a GnomeMonthItemChild. (gnome_month_item_num2day): Now takes an int, not a GnomeMonthItemChild. * goto.c (goto_dialog): Create the days before the year spin button, because the year_changed callback expects the month item to be created. The new semantics of the spin button cause it to emit a value_changed signal on the adjustment upon creation -- is this the behavior we want from it? (goto_dialog): Use gtk_window_set_modal() instead of the deprectaed gnome_dialog_set_modal(). * quick-view.c (quick_view_new): Make it look not as crappy by putting the title inside the frame. (quick_view_do_popup): Fixed the pointer grab and added a cursor. (create_items_for_event): Query the text width/height from the text item using the new object arguments, so that the size of the popup window can be set properly. * year-view.c (do_quick_view_popup): Calculate a nice date string for the popup window. svn path=/trunk/; revision=415
Diffstat (limited to 'calendar/mark.c')
-rw-r--r--calendar/mark.c229
1 files changed, 141 insertions, 88 deletions
diff --git a/calendar/mark.c b/calendar/mark.c
index e081a2174b..274c9efe30 100644
--- a/calendar/mark.c
+++ b/calendar/mark.c
@@ -12,14 +12,72 @@
#include "timeutil.h"
+/* Frees the specified data when an object is destroyed */
+static void
+free_data (GtkObject *object, gpointer data)
+{
+ g_free (data);
+}
+
+/* If the array of "marked" attributes for the days in a a month item has not been created yet, this
+ * function creates the array and clears it. Otherwise, it just returns the existing array.
+ */
+static char *
+get_attributes (GnomeMonthItem *mitem)
+{
+ char *attrs;
+
+ attrs = gtk_object_get_data (GTK_OBJECT (mitem), "day_mark_attributes");
+
+ if (!attrs) {
+ attrs = g_new0 (char, 42);
+ gtk_object_set_data (GTK_OBJECT (mitem), "day_mark_attributes", attrs);
+ gtk_signal_connect (GTK_OBJECT (mitem), "destroy",
+ (GtkSignalFunc) free_data,
+ attrs);
+ }
+
+ return attrs;
+}
+
+void
+colorify_month_item (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data)
+{
+ g_return_if_fail (mitem != NULL);
+ g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
+ g_return_if_fail (func != NULL);
+
+ unmark_month_item (mitem);
+
+ /* We have to do this in several calls to gnome_canvas_item_set(), as color_spec_from_prop()
+ * returns a pointer to a static string -- and we need several values.
+ */
+
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "heading_color", (* func) (COLOR_PROP_HEADING_COLOR, func_data),
+ NULL);
+
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "outline_color", (* func) (COLOR_PROP_OUTLINE_COLOR, func_data),
+ NULL);
+
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "day_box_color", (* func) (COLOR_PROP_EMPTY_DAY_BG, func_data),
+ NULL);
+
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "day_color", (* func) (COLOR_PROP_DAY_FG, func_data),
+ NULL);
+}
+
/* In the month item, marks all the days that are touched by the specified time span. Assumes that
- * the time span is completely contained within the month.
+ * the time span is completely contained within the month. The array of day attributes is modified
+ * accordingly.
*/
static void
mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end)
{
struct tm tm;
- GnomeCanvasItem *item;
int day_index;
tm = *localtime (&start);
@@ -34,10 +92,7 @@ mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end)
/* Mark the day box */
- item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + day_index);
- gnome_canvas_item_set (item,
- "fill_color", color_spec_from_prop (COLOR_PROP_MARK_DAY_BG),
- NULL);
+ mark_month_item_index (mitem, day_index, default_color_func, NULL);
/* Next day */
@@ -73,6 +128,10 @@ mark_month_item (GnomeMonthItem *mitem, Calendar *cal)
GList *list, *l;
CalendarObject *co;
+ g_return_if_fail (mitem != NULL);
+ g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
+ g_return_if_fail (cal != NULL);
+
month_begin = time_month_begin (time_from_day (mitem->year, mitem->month, 1));
month_end = time_month_end (month_begin);
@@ -87,47 +146,54 @@ mark_month_item (GnomeMonthItem *mitem, Calendar *cal)
}
calendar_destroy_event_list (list);
-
- mark_current_day (mitem);
}
void
-unmark_month_item (GnomeMonthItem *mitem)
+mark_month_item_index (GnomeMonthItem *mitem, int index, GetColorFunc func, gpointer func_data)
{
+ char *attrs;
+ GnomeCanvasItem *item;
+
g_return_if_fail (mitem != NULL);
g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
+ g_return_if_fail ((index >= 0) && (index < 42));
+ g_return_if_fail (func != NULL);
- /* We have to do this in several calls to gnome_canvas_item_set(), as color_spec_from_prop()
- * returns a pointer to a static string -- and we need several values.
- */
+ attrs = get_attributes (mitem);
- gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
- "heading_color", color_spec_from_prop (COLOR_PROP_HEADING_COLOR),
- NULL);
+ attrs[index] = TRUE;
- gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
- "outline_color", color_spec_from_prop (COLOR_PROP_OUTLINE_COLOR),
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + index);
+ gnome_canvas_item_set (item,
+ "fill_color", (* func) (COLOR_PROP_MARK_DAY_BG, func_data),
NULL);
+}
- gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
- "day_box_color", color_spec_from_prop (COLOR_PROP_EMPTY_DAY_BG),
- NULL);
+void
+unmark_month_item (GnomeMonthItem *mitem)
+{
+ int i;
+ char *attrs;
+ GnomeCanvasItem *item;
- gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
- "day_color", color_spec_from_prop (COLOR_PROP_DAY_FG),
- NULL);
+ g_return_if_fail (mitem != NULL);
+ g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
- gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
- "day_font", NORMAL_DAY_FONT,
- NULL);
+ attrs = get_attributes (mitem);
-}
+ /* Find marked days and unmark them by turning off their marked attribute flag and changing
+ * the color.
+ */
-/* Frees the prelight information in the month item when it is destroyed */
-static void
-free_prelight_info (GtkObject *object, gpointer data)
-{
- g_free (gtk_object_get_data (object, "prelight_info"));
+ for (i = 0; i < 42; i++)
+ if (attrs[i]) {
+ attrs[i] = FALSE;
+
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + i);
+ gnome_canvas_item_set (item,
+ "fill_color", color_spec_from_prop (COLOR_PROP_EMPTY_DAY_BG),
+ NULL);
+ }
}
/* Handles EnterNotify and LeaveNotify events from the month item's day groups, and performs
@@ -136,102 +202,89 @@ free_prelight_info (GtkObject *object, gpointer data)
static gint
day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
- GnomeCanvasItem *mitem;
+ GnomeMonthItem *mitem;
GnomeCanvasItem *box;
int child_num, day;
- gulong *day_pixels;
- GetPrelightColorFunc func;
+ GetColorFunc func;
gpointer func_data;
- char *spec;
- GdkColor color;
+ char *color;
+ char *attrs;
+
+ /* We only accept enters and leaves */
- mitem = data;
- child_num = gnome_month_item_child2num (GNOME_MONTH_ITEM (mitem), item);
- day = gnome_month_item_num2day (GNOME_MONTH_ITEM (mitem), child_num);
+ if (!((event->type == GDK_ENTER_NOTIFY) || (event->type == GDK_LEAVE_NOTIFY)))
+ return FALSE;
+
+ /* Get index information */
+
+ mitem = GNOME_MONTH_ITEM (data);
+ child_num = gnome_month_item_child2num (mitem, item);
+ day = gnome_month_item_num2day (mitem, child_num);
if (day == 0)
return FALSE; /* it was a day outside the month's range */
child_num -= GNOME_MONTH_ITEM_DAY_GROUP;
- box = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_BOX + child_num);
+ box = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + child_num);
+
+ /* Get colors */
- day_pixels = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_info_pixels");
- func = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_info_func");
- func_data = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_info_data");
+ func = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_color_func");
+ func_data = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_color_data");
+
+ /* Now actually set the proper color in the item */
switch (event->type) {
case GDK_ENTER_NOTIFY:
- spec = (* func) (func_data);
+ color = (* func) (COLOR_PROP_PRELIGHT_DAY_BG, func_data);
gnome_canvas_item_set (box,
- "fill_color", spec,
+ "fill_color", color,
NULL);
break;
case GDK_LEAVE_NOTIFY:
- color.pixel = day_pixels[child_num];
+ attrs = get_attributes (mitem);
+ color = (* func) (attrs[child_num] ? COLOR_PROP_MARK_DAY_BG : COLOR_PROP_EMPTY_DAY_BG,
+ func_data);
gnome_canvas_item_set (box,
- "fill_color_gdk", &color,
+ "fill_color", color,
NULL);
break;
default:
- break;
+ g_assert_not_reached ();
}
- return FALSE;
+ return TRUE;
}
void
-month_item_prepare_prelight (GnomeMonthItem *mitem, GetPrelightColorFunc func, gpointer func_data)
+month_item_prepare_prelight (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data)
{
- gulong *day_pixels;
GnomeCanvasItem *day_group;
- GnomeCanvasItem *box;
- GtkArg arg;
- GdkColor *color;
int i;
- day_pixels = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_info_pixels");
-
- /* Set up the buffer for day background colors and attach it to the month item, if necessary */
-
- if (!day_pixels) {
- /* Create the buffer and attach it */
-
- day_pixels = g_new (gulong, 42);
- gtk_object_set_data (GTK_OBJECT (mitem), "prelight_info_pixels", day_pixels);
- gtk_object_set_data (GTK_OBJECT (mitem), "prelight_info_func", func);
- gtk_object_set_data (GTK_OBJECT (mitem), "prelight_info_data", func_data);
- gtk_signal_connect (GTK_OBJECT (mitem), "destroy",
- (GtkSignalFunc) free_prelight_info,
- NULL);
+ g_return_if_fail (mitem != NULL);
+ g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
+ g_return_if_fail (func != NULL);
- /* Connect the appropriate signals to perform prelighting */
+ /* Store the function in the object data */
- for (i = 0; i < 42; i++) {
- day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i);
- gtk_signal_connect (GTK_OBJECT (day_group), "event",
- (GtkSignalFunc) day_event,
- mitem);
- }
- }
+ gtk_object_set_data (GTK_OBJECT (mitem), "prelight_color_func", func);
+ gtk_object_set_data (GTK_OBJECT (mitem), "prelight_color_data", func_data);
- /* Fetch the background colors from the day boxes and store them in the prelight info */
+ /* Connect the appropriate signals to perform prelighting */
for (i = 0; i < 42; i++) {
- box = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + i);
-
- arg.name = "fill_color_gdk";
- gtk_object_getv (GTK_OBJECT (box), 1, &arg);
-
- color = GTK_VALUE_BOXED (arg);
- day_pixels[i] = color->pixel;
- g_free (color);
+ day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i);
+ gtk_signal_connect (GTK_OBJECT (day_group), "event",
+ (GtkSignalFunc) day_event,
+ mitem);
}
}
char *
-default_prelight_func (gpointer data)
+default_color_func (ColorProp propnum, gpointer data)
{
- return color_spec_from_prop (COLOR_PROP_PRELIGHT_DAY_BG);
+ return color_spec_from_prop (propnum);
}