aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-06-21 08:11:50 +0800
committerChris Lahey <clahey@src.gnome.org>2000-06-21 08:11:50 +0800
commit6d460ba3fe4d476c11423ae7c1639922b6ea1eac (patch)
tree039ffa2f71db29d0028b2384281a7fa78839e885
parent5d477147b7b0725c28a09a037e101266c2f8ed3f (diff)
downloadgsoc2013-evolution-6d460ba3fe4d476c11423ae7c1639922b6ea1eac.tar
gsoc2013-evolution-6d460ba3fe4d476c11423ae7c1639922b6ea1eac.tar.gz
gsoc2013-evolution-6d460ba3fe4d476c11423ae7c1639922b6ea1eac.tar.bz2
gsoc2013-evolution-6d460ba3fe4d476c11423ae7c1639922b6ea1eac.tar.lz
gsoc2013-evolution-6d460ba3fe4d476c11423ae7c1639922b6ea1eac.tar.xz
gsoc2013-evolution-6d460ba3fe4d476c11423ae7c1639922b6ea1eac.tar.zst
gsoc2013-evolution-6d460ba3fe4d476c11423ae7c1639922b6ea1eac.zip
Built a system for doing selections and/or a cursor in canvas.
2000-06-20 Christopher James Lahey <clahey@helixcode.com> * e-canvas.c, e-canvas.h: Built a system for doing selections and/or a cursor in canvas. svn path=/trunk/; revision=3655
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-canvas.c129
-rw-r--r--e-util/e-canvas.h33
-rw-r--r--widgets/misc/e-canvas.c129
-rw-r--r--widgets/misc/e-canvas.h33
5 files changed, 323 insertions, 6 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index d225599501..7c6cd01616 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,8 @@
+2000-06-20 Christopher James Lahey <clahey@helixcode.com>
+
+ * e-canvas.c, e-canvas.h: Built a system for doing selections
+ and/or a cursor in canvas.
+
2000-06-13 Christopher James Lahey <clahey@helixcode.com>
* e-util.c, e-util.h: Changed the needed e_marshal functions.
diff --git a/e-util/e-canvas.c b/e-util/e-canvas.c
index 534e3fb1e8..230d5a72ea 100644
--- a/e-util/e-canvas.c
+++ b/e-util/e-canvas.c
@@ -45,6 +45,11 @@ enum {
static guint e_canvas_signals [LAST_SIGNAL] = { 0, };
+typedef struct {
+ GnomeCanvasItem *item;
+ gpointer id;
+} ECanvasSelectionInfo;
+
GtkType
e_canvas_get_type (void)
{
@@ -107,6 +112,7 @@ e_canvas_class_init (ECanvasClass *klass)
static void
e_canvas_init (ECanvas *canvas)
{
+ canvas->selection = NULL;
}
static void
@@ -458,3 +464,126 @@ e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, ECanvasItemReflowFunc
{
gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::reflow_callback", (gpointer) func);
}
+
+
+void
+e_canvas_item_set_selection_callback (GnomeCanvasItem *item, ECanvasItemSelectionFunc func)
+{
+ gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::selection_callback", (gpointer) func);
+}
+
+void
+e_canvas_item_set_selection_compare_callback (GnomeCanvasItem *item, ECanvasItemSelectionCompareFunc func)
+{
+ gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::selection_compare_callback", (gpointer) func);
+}
+
+void
+e_canvas_item_set_cursor (GnomeCanvasItem *item, gpointer id)
+{
+ GList *list;
+ int flags;
+ ECanvas *canvas;
+ ECanvasSelectionInfo *info;
+ ECanvasItemSelectionFunc func;
+
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(GNOME_IS_CANVAS_ITEM(item));
+ g_return_if_fail(item->canvas != NULL);
+ g_return_if_fail(E_IS_CANVAS(item->canvas));
+
+ canvas = E_CANVAS(item->canvas);
+ flags = E_CANVAS_ITEM_SELECTION_DELETE_DATA;
+
+ for (list = canvas->selection; list; list = g_list_next(list)) {
+ info = list->data;
+
+ func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_callback");
+ if (func)
+ func(info->item, flags, info->id);
+ g_free(info);
+ }
+ g_list_free(canvas->selection);
+
+ canvas->selection = NULL;
+
+ info = g_new(ECanvasSelectionInfo, 1);
+ info->item = item;
+ info->id = id;
+
+ flags = E_CANVAS_ITEM_SELECTION_SELECT | E_CANVAS_ITEM_SELECTION_CURSOR;
+ func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::selection_callback");
+ if (func)
+ func(item, flags, id);
+
+ canvas->selection = g_list_prepend(canvas->selection, info);
+}
+
+void
+e_canvas_item_set_cursor_end (GnomeCanvasItem *item, gpointer id)
+{
+}
+
+void
+e_canvas_item_add_selection (GnomeCanvasItem *item, gpointer id)
+{
+ int flags;
+ ECanvas *canvas;
+ ECanvasSelectionInfo *info;
+ ECanvasItemSelectionFunc func;
+
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(GNOME_IS_CANVAS_ITEM(item));
+ g_return_if_fail(item->canvas != NULL);
+ g_return_if_fail(E_IS_CANVAS(item->canvas));
+
+ flags = E_CANVAS_ITEM_SELECTION_SELECT | E_CANVAS_ITEM_SELECTION_CURSOR;
+ canvas = E_CANVAS(item->canvas);
+
+ info = g_new(ECanvasSelectionInfo, 1);
+ info->item = item;
+ info->id = id;
+
+ func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::selection_callback");
+ if (func)
+ func(item, flags, id);
+
+ canvas->selection = g_list_prepend(canvas->selection, info);
+}
+
+void
+e_canvas_item_remove_selection (GnomeCanvasItem *item, gpointer id)
+{
+ int flags;
+ ECanvas *canvas;
+ ECanvasSelectionInfo *info;
+ GList *list;
+
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(GNOME_IS_CANVAS_ITEM(item));
+ g_return_if_fail(item->canvas != NULL);
+ g_return_if_fail(E_IS_CANVAS(item->canvas));
+
+ flags = E_CANVAS_ITEM_SELECTION_DELETE_DATA;
+ canvas = E_CANVAS(item->canvas);
+
+ for (list = canvas->selection; list; list = g_list_next(list)) {
+ info = list->data;
+
+ if (info->item == item) {
+ ECanvasItemSelectionCompareFunc compare_func;
+ compare_func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_compare_callback");
+ if (compare_func(info->item, info->id, id, 0) == 0) {
+ ECanvasItemSelectionFunc func;
+ func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_callback");
+ if (func)
+ func(info->item, flags, info->id);
+ canvas->selection = g_list_remove_link(canvas->selection, list);
+ g_free(info);
+ g_list_free_1(list);
+ break;
+ }
+ }
+ }
+}
+
diff --git a/e-util/e-canvas.h b/e-util/e-canvas.h
index f1ff1195c9..9e572a1179 100644
--- a/e-util/e-canvas.h
+++ b/e-util/e-canvas.h
@@ -41,6 +41,16 @@ extern "C" {
typedef void (*ECanvasItemReflowFunc) (GnomeCanvasItem *item,
gint flags);
+typedef void (*ECanvasItemSelectionFunc) (GnomeCanvasItem *item,
+ gint flags,
+ gpointer user_data);
+/* Returns the same as strcmp does. */
+typedef gint (*ECanvasItemSelectionCompareFunc) (GnomeCanvasItem *item,
+ gpointer data1,
+ gpointer data2,
+ gint flags);
+
+
typedef struct _ECanvas ECanvas;
typedef struct _ECanvasClass ECanvasClass;
@@ -50,11 +60,18 @@ enum {
E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW = 1 << 14
};
+enum {
+ E_CANVAS_ITEM_SELECTION_SELECT = 1 << 0, /* TRUE = select. FALSE = unselect. */
+ E_CANVAS_ITEM_SELECTION_CURSOR = 1 << 1, /* TRUE = has become cursor. FALSE = not cursor. */
+ E_CANVAS_ITEM_SELECTION_DELETE_DATA = 1 << 2,
+};
+
struct _ECanvas
{
- GnomeCanvas parent;
-
- int idle_id;
+ GnomeCanvas parent;
+
+ int idle_id;
+ GList *selection;
};
struct _ECanvasClass
@@ -76,6 +93,16 @@ void e_canvas_item_request_reflow (GnomeCanvasItem *item);
void e_canvas_item_request_parent_reflow (GnomeCanvasItem *item);
void e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, ECanvasItemReflowFunc func);
+void e_canvas_item_set_selection_callback (GnomeCanvasItem *item, ECanvasItemSelectionFunc func);
+void e_canvas_item_set_selection_compare_callback (GnomeCanvasItem *item, ECanvasItemSelectionCompareFunc func);
+
+void e_canvas_item_set_cursor (GnomeCanvasItem *item, gpointer id);
+void e_canvas_item_add_selection (GnomeCanvasItem *item, gpointer id);
+void e_canvas_item_remove_selection (GnomeCanvasItem *item, gpointer id);
+
+/* Not implemented yet. */
+void e_canvas_item_set_cursor_end (GnomeCanvasItem *item, gpointer id);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/widgets/misc/e-canvas.c b/widgets/misc/e-canvas.c
index 534e3fb1e8..230d5a72ea 100644
--- a/widgets/misc/e-canvas.c
+++ b/widgets/misc/e-canvas.c
@@ -45,6 +45,11 @@ enum {
static guint e_canvas_signals [LAST_SIGNAL] = { 0, };
+typedef struct {
+ GnomeCanvasItem *item;
+ gpointer id;
+} ECanvasSelectionInfo;
+
GtkType
e_canvas_get_type (void)
{
@@ -107,6 +112,7 @@ e_canvas_class_init (ECanvasClass *klass)
static void
e_canvas_init (ECanvas *canvas)
{
+ canvas->selection = NULL;
}
static void
@@ -458,3 +464,126 @@ e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, ECanvasItemReflowFunc
{
gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::reflow_callback", (gpointer) func);
}
+
+
+void
+e_canvas_item_set_selection_callback (GnomeCanvasItem *item, ECanvasItemSelectionFunc func)
+{
+ gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::selection_callback", (gpointer) func);
+}
+
+void
+e_canvas_item_set_selection_compare_callback (GnomeCanvasItem *item, ECanvasItemSelectionCompareFunc func)
+{
+ gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::selection_compare_callback", (gpointer) func);
+}
+
+void
+e_canvas_item_set_cursor (GnomeCanvasItem *item, gpointer id)
+{
+ GList *list;
+ int flags;
+ ECanvas *canvas;
+ ECanvasSelectionInfo *info;
+ ECanvasItemSelectionFunc func;
+
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(GNOME_IS_CANVAS_ITEM(item));
+ g_return_if_fail(item->canvas != NULL);
+ g_return_if_fail(E_IS_CANVAS(item->canvas));
+
+ canvas = E_CANVAS(item->canvas);
+ flags = E_CANVAS_ITEM_SELECTION_DELETE_DATA;
+
+ for (list = canvas->selection; list; list = g_list_next(list)) {
+ info = list->data;
+
+ func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_callback");
+ if (func)
+ func(info->item, flags, info->id);
+ g_free(info);
+ }
+ g_list_free(canvas->selection);
+
+ canvas->selection = NULL;
+
+ info = g_new(ECanvasSelectionInfo, 1);
+ info->item = item;
+ info->id = id;
+
+ flags = E_CANVAS_ITEM_SELECTION_SELECT | E_CANVAS_ITEM_SELECTION_CURSOR;
+ func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::selection_callback");
+ if (func)
+ func(item, flags, id);
+
+ canvas->selection = g_list_prepend(canvas->selection, info);
+}
+
+void
+e_canvas_item_set_cursor_end (GnomeCanvasItem *item, gpointer id)
+{
+}
+
+void
+e_canvas_item_add_selection (GnomeCanvasItem *item, gpointer id)
+{
+ int flags;
+ ECanvas *canvas;
+ ECanvasSelectionInfo *info;
+ ECanvasItemSelectionFunc func;
+
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(GNOME_IS_CANVAS_ITEM(item));
+ g_return_if_fail(item->canvas != NULL);
+ g_return_if_fail(E_IS_CANVAS(item->canvas));
+
+ flags = E_CANVAS_ITEM_SELECTION_SELECT | E_CANVAS_ITEM_SELECTION_CURSOR;
+ canvas = E_CANVAS(item->canvas);
+
+ info = g_new(ECanvasSelectionInfo, 1);
+ info->item = item;
+ info->id = id;
+
+ func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::selection_callback");
+ if (func)
+ func(item, flags, id);
+
+ canvas->selection = g_list_prepend(canvas->selection, info);
+}
+
+void
+e_canvas_item_remove_selection (GnomeCanvasItem *item, gpointer id)
+{
+ int flags;
+ ECanvas *canvas;
+ ECanvasSelectionInfo *info;
+ GList *list;
+
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(GNOME_IS_CANVAS_ITEM(item));
+ g_return_if_fail(item->canvas != NULL);
+ g_return_if_fail(E_IS_CANVAS(item->canvas));
+
+ flags = E_CANVAS_ITEM_SELECTION_DELETE_DATA;
+ canvas = E_CANVAS(item->canvas);
+
+ for (list = canvas->selection; list; list = g_list_next(list)) {
+ info = list->data;
+
+ if (info->item == item) {
+ ECanvasItemSelectionCompareFunc compare_func;
+ compare_func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_compare_callback");
+ if (compare_func(info->item, info->id, id, 0) == 0) {
+ ECanvasItemSelectionFunc func;
+ func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_callback");
+ if (func)
+ func(info->item, flags, info->id);
+ canvas->selection = g_list_remove_link(canvas->selection, list);
+ g_free(info);
+ g_list_free_1(list);
+ break;
+ }
+ }
+ }
+}
+
diff --git a/widgets/misc/e-canvas.h b/widgets/misc/e-canvas.h
index f1ff1195c9..9e572a1179 100644
--- a/widgets/misc/e-canvas.h
+++ b/widgets/misc/e-canvas.h
@@ -41,6 +41,16 @@ extern "C" {
typedef void (*ECanvasItemReflowFunc) (GnomeCanvasItem *item,
gint flags);
+typedef void (*ECanvasItemSelectionFunc) (GnomeCanvasItem *item,
+ gint flags,
+ gpointer user_data);
+/* Returns the same as strcmp does. */
+typedef gint (*ECanvasItemSelectionCompareFunc) (GnomeCanvasItem *item,
+ gpointer data1,
+ gpointer data2,
+ gint flags);
+
+
typedef struct _ECanvas ECanvas;
typedef struct _ECanvasClass ECanvasClass;
@@ -50,11 +60,18 @@ enum {
E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW = 1 << 14
};
+enum {
+ E_CANVAS_ITEM_SELECTION_SELECT = 1 << 0, /* TRUE = select. FALSE = unselect. */
+ E_CANVAS_ITEM_SELECTION_CURSOR = 1 << 1, /* TRUE = has become cursor. FALSE = not cursor. */
+ E_CANVAS_ITEM_SELECTION_DELETE_DATA = 1 << 2,
+};
+
struct _ECanvas
{
- GnomeCanvas parent;
-
- int idle_id;
+ GnomeCanvas parent;
+
+ int idle_id;
+ GList *selection;
};
struct _ECanvasClass
@@ -76,6 +93,16 @@ void e_canvas_item_request_reflow (GnomeCanvasItem *item);
void e_canvas_item_request_parent_reflow (GnomeCanvasItem *item);
void e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, ECanvasItemReflowFunc func);
+void e_canvas_item_set_selection_callback (GnomeCanvasItem *item, ECanvasItemSelectionFunc func);
+void e_canvas_item_set_selection_compare_callback (GnomeCanvasItem *item, ECanvasItemSelectionCompareFunc func);
+
+void e_canvas_item_set_cursor (GnomeCanvasItem *item, gpointer id);
+void e_canvas_item_add_selection (GnomeCanvasItem *item, gpointer id);
+void e_canvas_item_remove_selection (GnomeCanvasItem *item, gpointer id);
+
+/* Not implemented yet. */
+void e_canvas_item_set_cursor_end (GnomeCanvasItem *item, gpointer id);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */