aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/table/e-table-memory-callbacks.c254
-rw-r--r--widgets/table/e-table-memory-callbacks.h72
-rw-r--r--widgets/table/e-table-memory.c258
-rw-r--r--widgets/table/e-table-memory.h57
4 files changed, 641 insertions, 0 deletions
diff --git a/widgets/table/e-table-memory-callbacks.c b/widgets/table/e-table-memory-callbacks.c
new file mode 100644
index 0000000000..c1089b5f28
--- /dev/null
+++ b/widgets/table/e-table-memory-callbacks.c
@@ -0,0 +1,254 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * e-table-memory-callbacks.c: a simple table model implementation
+ * that uses function pointers to simplify the creation of new, exotic
+ * and colorful tables in no time.
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnu.org)
+ *
+ * (C) 1999, 2000 Ximian, Inc.
+ */
+
+#include <config.h>
+#include "e-table-memory-callbacks.h"
+
+enum {
+ ARG_0,
+ ARG_APPEND_ROW,
+};
+
+#define PARENT_TYPE e_table_memory_get_type ()
+
+static int
+etmc_column_count (ETableModel *etm)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->col_count)
+ return etmc->col_count (etm, etmc->data);
+ else
+ return 0;
+}
+
+static void *
+etmc_value_at (ETableModel *etm, int col, int row)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->value_at)
+ return etmc->value_at (etm, col, row, etmc->data);
+ else
+ return NULL;
+}
+
+static void
+etmc_set_value_at (ETableModel *etm, int col, int row, const void *val)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->set_value_at)
+ etmc->set_value_at (etm, col, row, val, etmc->data);
+}
+
+static gboolean
+etmc_is_cell_editable (ETableModel *etm, int col, int row)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->is_cell_editable)
+ return etmc->is_cell_editable (etm, col, row, etmc->data);
+ else
+ return FALSE;
+}
+
+/* The default for etmc_duplicate_value is to return the raw value. */
+static void *
+etmc_duplicate_value (ETableModel *etm, int col, const void *value)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->duplicate_value)
+ return etmc->duplicate_value (etm, col, value, etmc->data);
+ else
+ return (void *)value;
+}
+
+static void
+etmc_free_value (ETableModel *etm, int col, void *value)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->free_value)
+ etmc->free_value (etm, col, value, etmc->data);
+}
+
+static void *
+etmc_initialize_value (ETableModel *etm, int col)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->initialize_value)
+ return etmc->initialize_value (etm, col, etmc->data);
+ else
+ return NULL;
+}
+
+static gboolean
+etmc_value_is_empty (ETableModel *etm, int col, const void *value)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->value_is_empty)
+ return etmc->value_is_empty (etm, col, value, etmc->data);
+ else
+ return FALSE;
+}
+
+static char *
+etmc_value_to_string (ETableModel *etm, int col, const void *value)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->value_to_string)
+ return etmc->value_to_string (etm, col, value, etmc->data);
+ else
+ return g_strdup ("");
+}
+
+static void
+etmc_append_row (ETableModel *etm, ETableModel *source, int row)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS(etm);
+
+ if (etmc->append_row)
+ etmc->append_row (etm, source, row, etmc->data);
+}
+
+static void
+etmc_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS (o);
+
+ switch (arg_id){
+ case ARG_APPEND_ROW:
+ GTK_VALUE_POINTER(*arg) = etmc->append_row;
+ break;
+ }
+}
+
+static void
+etmc_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
+{
+ ETableMemoryCalbacks *etmc = E_TABLE_MEMORY_CALLBACKS (o);
+
+ switch (arg_id){
+ case ARG_APPEND_ROW:
+ etmc->append_row = GTK_VALUE_POINTER(*arg);
+ break;
+ default:
+ arg->type = GTK_TYPE_INVALID;
+ }
+}
+
+static void
+e_table_memory_callbacks_class_init (GtkObjectClass *object_class)
+{
+ ETableModelClass *model_class = (ETableModelClass *) object_class;
+
+ object_class->set_arg = etmc_set_arg;
+ object_class->get_arg = etmc_get_arg;
+
+ model_class->column_count = etmc_column_count;
+ model_class->value_at = etmc_value_at;
+ model_class->set_value_at = etmc_set_value_at;
+ model_class->is_cell_editable = etmc_is_cell_editable;
+ model_class->duplicate_value = etmc_duplicate_value;
+ model_class->free_value = etmc_free_value;
+ model_class->initialize_value = etmc_initialize_value;
+ model_class->value_is_empty = etmc_value_is_empty;
+ model_class->value_to_string = etmc_value_to_string;
+ model_class->append_row = etmc_append_row;
+
+ gtk_object_add_arg_type ("ETableMemoryCalbacks::append_row", GTK_TYPE_POINTER,
+ GTK_ARG_READWRITE, ARG_APPEND_ROW);
+}
+
+GtkType
+e_table_memory_callbacks_get_type (void)
+{
+ static GtkType type = 0;
+
+ if (!type){
+ GtkTypeInfo info = {
+ "ETableMemoryCalbacks",
+ sizeof (ETableMemoryCalbacks),
+ sizeof (ETableMemoryCalbacksClass),
+ (GtkClassInitFunc) e_table_memory_callbacks_class_init,
+ (GtkObjectInitFunc) NULL,
+ NULL, /* reserved 1 */
+ NULL, /* reserved 2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ type = gtk_type_unique (PARENT_TYPE, &info);
+ }
+
+ return type;
+}
+
+/**
+ * e_table_memory_callbacks_new:
+ * @col_count:
+ * @value_at:
+ * @set_value_at:
+ * @is_cell_editable:
+ * @duplicate_value:
+ * @free_value:
+ * @initialize_value:
+ * @value_is_empty:
+ * @value_to_string:
+ * @data: closure pointer.
+ *
+ * This initializes a new ETableMemoryCalbacksModel object. ETableMemoryCalbacksModel is
+ * an implementaiton of the abstract class ETableModel. The ETableMemoryCalbacksModel
+ * is designed to allow people to easily create ETableModels without having
+ * to create a new GtkType derived from ETableModel every time they need one.
+ *
+ * Instead, ETableMemoryCalbacksModel uses a setup based in callback functions, every
+ * callback function signature mimics the signature of each ETableModel method
+ * and passes the extra @data pointer to each one of the method to provide them
+ * with any context they might want to use.
+ *
+ * Returns: An ETableMemoryCalbacksModel object (which is also an ETableModel
+ * object).
+ */
+ETableModel *
+e_table_memory_callbacks_new (ETableMemoryCalbacksColumnCountFn col_count,
+ ETableMemoryCalbacksValueAtFn value_at,
+ ETableMemoryCalbacksSetValueAtFn set_value_at,
+ ETableMemoryCalbacksIsCellEditableFn is_cell_editable,
+ ETableMemoryCalbacksDuplicateValueFn duplicate_value,
+ ETableMemoryCalbacksFreeValueFn free_value,
+ ETableMemoryCalbacksInitializeValueFn initialize_value,
+ ETableMemoryCalbacksValueIsEmptyFn value_is_empty,
+ ETableMemoryCalbacksValueToStringFn value_to_string,
+ void *data)
+{
+ ETableMemoryCalbacks *et;
+
+ et = gtk_type_new (e_table_memory_callbacks_get_type ());
+
+ et->col_count = col_count;
+ et->value_at = value_at;
+ et->set_value_at = set_value_at;
+ et->is_cell_editable = is_cell_editable;
+ et->duplicate_value = duplicate_value;
+ et->free_value = free_value;
+ et->initialize_value = initialize_value;
+ et->value_is_empty = value_is_empty;
+ et->value_to_string = value_to_string;
+ et->data = data;
+
+ return (ETableModel *) et;
+ }
diff --git a/widgets/table/e-table-memory-callbacks.h b/widgets/table/e-table-memory-callbacks.h
new file mode 100644
index 0000000000..72f637f764
--- /dev/null
+++ b/widgets/table/e-table-memory-callbacks.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef _E_TABLE_MEMORY_CALLBACKS_H_
+#define _E_TABLE_MEMORY_CALLBACKS_H_
+
+#include <gal/e-table/e-table-memory.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define E_TABLE_MEMORY_CALLBACKS_TYPE (e_table_memory_callbacks_get_type ())
+#define E_TABLE_MEMORY_CALLBACKS(o) (GTK_CHECK_CAST ((o), E_TABLE_MEMORY_CALLBACKS_TYPE, ETableMemoryCalbacks))
+#define E_TABLE_MEMORY_CALLBACKS_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_MEMORY_CALLBACKS_TYPE, ETableMemoryCalbacksClass))
+#define E_IS_TABLE_MEMORY_CALLBACKS(o) (GTK_CHECK_TYPE ((o), E_TABLE_MEMORY_CALLBACKS_TYPE))
+#define E_IS_TABLE_MEMORY_CALLBACKS_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_MEMORY_CALLBACKS_TYPE))
+
+typedef int (*ETableMemoryCalbacksColumnCountFn) (ETableModel *etm, void *data);
+typedef void (*ETableMemoryCalbacksAppendRowFn) (ETableModel *etm, ETableModel *model, int row, void *data);
+
+typedef void *(*ETableMemoryCalbacksValueAtFn) (ETableModel *etm, int col, int row, void *data);
+typedef void (*ETableMemoryCalbacksSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data);
+typedef gboolean (*ETableMemoryCalbacksIsCellEditableFn) (ETableModel *etm, int col, int row, void *data);
+
+typedef void *(*ETableMemoryCalbacksDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data);
+typedef void (*ETableMemoryCalbacksFreeValueFn) (ETableModel *etm, int col, void *val, void *data);
+typedef void *(*ETableMemoryCalbacksInitializeValueFn) (ETableModel *etm, int col, void *data);
+typedef gboolean (*ETableMemoryCalbacksValueIsEmptyFn) (ETableModel *etm, int col, const void *val, void *data);
+typedef char *(*ETableMemoryCalbacksValueToStringFn) (ETableModel *etm, int col, const void *val, void *data);
+
+typedef struct {
+ ETableMemory parent;
+
+ ETableMemoryCalbacksColumnCountFn col_count;
+ ETableMemoryCalbacksAppendRowFn append_row;
+
+ ETableMemoryCalbacksValueAtFn value_at;
+ ETableMemoryCalbacksSetValueAtFn set_value_at;
+ ETableMemoryCalbacksIsCellEditableFn is_cell_editable;
+
+ ETableMemoryCalbacksDuplicateValueFn duplicate_value;
+ ETableMemoryCalbacksFreeValueFn free_value;
+ ETableMemoryCalbacksInitializeValueFn initialize_value;
+ ETableMemoryCalbacksValueIsEmptyFn value_is_empty;
+ ETableMemoryCalbacksValueToStringFn value_to_string;
+ void *data;
+} ETableMemoryCalbacks;
+
+typedef struct {
+ ETableMemoryClass parent_class;
+} ETableMemoryCalbacksClass;
+
+GtkType e_table_memory_callbacks_get_type (void);
+
+ETableModel *e_table_memory_callbacks_new (ETableMemoryCalbacksColumnCountFn col_count,
+
+ ETableMemoryCalbacksValueAtFn value_at,
+ ETableMemoryCalbacksSetValueAtFn set_value_at,
+ ETableMemoryCalbacksIsCellEditableFn is_cell_editable,
+
+ ETableMemoryCalbacksDuplicateValueFn duplicate_value,
+ ETableMemoryCalbacksFreeValueFn free_value,
+ ETableMemoryCalbacksInitializeValueFn initialize_value,
+ ETableMemoryCalbacksValueIsEmptyFn value_is_empty,
+ ETableMemoryCalbacksValueToStringFn value_to_string,
+ void *data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _E_TABLE_MEMORY_CALLBACKS_H_ */
+
diff --git a/widgets/table/e-table-memory.c b/widgets/table/e-table-memory.c
new file mode 100644
index 0000000000..87e8121294
--- /dev/null
+++ b/widgets/table/e-table-memory.c
@@ -0,0 +1,258 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * e-table-memory.c: a Table Model implementation that the programmer builds in memory.
+ *
+ * Author:
+ * Chris Toshok (toshok@ximian.com)
+ * Chris Lahey <clahey@ximian.com>
+ *
+ * Adapted from the gtable code and ETableModel.
+ *
+ * (C) 2000, 2001 Ximian, Inc.
+ */
+#include <config.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <gnome-xml/parser.h>
+#include <gnome-xml/xmlmemory.h>
+
+#include <gtk/gtksignal.h>
+#include <stdlib.h>
+#include "gal/util/e-util.h"
+#include "gal/util/e-xml-utils.h"
+#include "e-table-memory.h"
+
+#define PARENT_TYPE E_TABLE_MODEL_TYPE
+
+static ETableModel *parent_class;
+
+struct ETableMemoryPriv {
+ gpointer *data;
+ int num_rows;
+ gint frozen;
+};
+
+
+/* virtual methods */
+
+static void
+etmm_destroy (GtkObject *object)
+{
+ ETableMemory *etmm = E_TABLE_MEMORY (object);
+ ETableMemoryPriv *priv = etmm->priv;
+
+ /* XXX lots of stuff to free here */
+
+ g_free (priv->data);
+ g_free (priv);
+
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
+}
+
+static int
+etmm_row_count (ETableModel *etm)
+{
+ ETableMemory *etmm = E_TABLE_MEMORY (etm);
+
+ return etmm->priv->num_rows;
+}
+
+
+static void
+e_table_memory_class_init (GtkObjectClass *klass)
+{
+ ETableModelClass *table_class = (ETableModelClass *) klass;
+
+ parent_class = gtk_type_class (PARENT_TYPE);
+
+ klass->destroy = etmm_destroy;
+
+ table_class->row_count = etmm_row_count;
+}
+
+static void
+e_table_memory_init (GtkObject *object)
+{
+ ETableMemory *etmm = (ETableMemory *)object;
+
+ ETableMemoryPriv *priv;
+
+ priv = g_new0 (ETableMemoryPriv, 1);
+ etmm->priv = priv;
+
+ priv->data = NULL;
+ priv->num_rows = 0;
+ priv->frozen = 0;
+}
+
+E_MAKE_TYPE(e_table_memory, "ETableMemory", ETableMemory, e_table_memory_class_init, e_table_memory_init, PARENT_TYPE)
+
+
+
+/**
+ * e_table_memory_construct:
+ * @etable:
+ *
+ *
+ **/
+void
+e_table_memory_construct (ETableMemory *etmm)
+{
+}
+
+/**
+ * e_table_memory_new
+ *
+ * XXX docs here.
+ *
+ * return values: a newly constructed ETableMemory.
+ */
+ETableMemory *
+e_table_memory_new (void)
+{
+ ETableMemory *etmm;
+
+ etmm = gtk_type_new (e_table_memory_get_type ());
+
+ e_table_memory_construct(etmm);
+
+ return etmm;
+}
+
+/**
+ * e_table_memory_node_get_data:
+ * @etmm:
+ * @node:
+ *
+ *
+ *
+ * Return value:
+ **/
+gpointer
+e_table_memory_get_data (ETableMemory *etmm, int row)
+{
+ g_return_val_if_fail(row < 0, NULL);
+ g_return_val_if_fail(row >= etmm->priv->num_rows, NULL);
+
+ return etmm->priv->data[row];
+}
+
+/**
+ * e_table_memory_node_set_data:
+ * @etmm:
+ * @node:
+ * @node_data:
+ *
+ *
+ **/
+void
+e_table_memory_set_data (ETableMemory *etmm, int row, gpointer node_data)
+{
+ g_return_if_fail(row < 0);
+ g_return_if_fail(row > etmm->priv->num_rows);
+
+ etmm->priv->data[row] = node_data;
+}
+
+/**
+ * e_table_memory_node_insert:
+ * @table_model:
+ * @parent_path:
+ * @position:
+ * @node_data:
+ *
+ *
+ *
+ * Return value:
+ **/
+void
+e_table_memory_node_insert (ETableMemory *etmm,
+ int row,
+ gpointer node_data)
+{
+ g_return_if_fail(row < 0);
+ g_return_if_fail(row > etmm->priv->num_rows);
+
+ if (!etmm->priv->frozen)
+ e_table_model_pre_change(E_TABLE_MODEL(etmm));
+ etmm->priv->data = g_renew(gpointer, etmm->priv->data, etmm->priv->num_rows + 1);
+ memmove(etmm->priv->data + row + 1, etmm->priv->data + row, (etmm->priv->num_rows - row) * sizeof (gpointer));
+ etmm->priv->data[row] = node_data;
+ etmm->priv->num_rows ++;
+ if (!etmm->priv->frozen)
+ e_table_model_row_inserted(E_TABLE_MODEL(etmm), row);
+}
+
+
+
+/**
+ * e_table_memory_node_remove:
+ * @etable:
+ * @path:
+ *
+ *
+ *
+ * Return value:
+ **/
+gpointer
+e_table_memory_node_remove (ETableMemory *etmm, int row)
+{
+ gpointer ret;
+
+ g_return_val_if_fail(row < 0, NULL);
+ g_return_val_if_fail(row >= etmm->priv->num_rows, NULL);
+
+ if (!etmm->priv->frozen)
+ e_table_model_pre_change(E_TABLE_MODEL(etmm));
+ ret = etmm->priv->data[row];
+ memmove(etmm->priv->data + row, etmm->priv->data + row + 1, (etmm->priv->num_rows - row - 1) * sizeof (gpointer));
+ etmm->priv->num_rows --;
+ if (!etmm->priv->frozen)
+ e_table_model_row_deleted(E_TABLE_MODEL(etmm), row);
+ return ret;
+}
+
+/**
+ * e_table_memory_freeze:
+ * @etmm: the ETableModel to freeze.
+ *
+ * This function prepares an ETableModel for a period of much change.
+ * All signals regarding changes to the table are deferred until we
+ * thaw the table.
+ *
+ **/
+void
+e_table_memory_freeze(ETableMemory *etmm)
+{
+ ETableMemoryPriv *priv = etmm->priv;
+
+ if (priv->frozen == 0)
+ e_table_model_pre_change(E_TABLE_MODEL(etmm));
+
+ priv->frozen ++;
+}
+
+/**
+ * e_table_memory_thaw:
+ * @etmm: the ETableMemory to thaw.
+ *
+ * This function thaws an ETableMemory. All the defered signals can add
+ * up to a lot, we don't know - so we just emit a model_changed
+ * signal.
+ *
+ **/
+void
+e_table_memory_thaw(ETableMemory *etmm)
+{
+ ETableMemoryPriv *priv = etmm->priv;
+
+ if (priv->frozen > 0)
+ priv->frozen --;
+ if (priv->frozen == 0) {
+ e_table_model_changed(E_TABLE_MODEL(etmm));
+ }
+}
diff --git a/widgets/table/e-table-memory.h b/widgets/table/e-table-memory.h
new file mode 100644
index 0000000000..e1c7558dc4
--- /dev/null
+++ b/widgets/table/e-table-memory.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef _E_TABLE_MEMORY_H_
+#define _E_TABLE_MEMORY_H_
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gal/e-table/e-table-model.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+#define E_TABLE_MEMORY_TYPE (e_table_memory_get_type ())
+#define E_TABLE_MEMORY(o) (GTK_CHECK_CAST ((o), E_TABLE_MEMORY_TYPE, ETableMemory))
+#define E_TABLE_MEMORY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_MEMORY_TYPE, ETableMemoryClass))
+#define E_IS_TABLE_MEMORY(o) (GTK_CHECK_TYPE ((o), E_TABLE_MEMORY_TYPE))
+#define E_IS_TABLE_MEMORY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_MEMORY_TYPE))
+
+typedef struct ETableMemory ETableMemory;
+typedef struct ETableMemoryPriv ETableMemoryPriv;
+typedef struct ETableMemoryClass ETableMemoryClass;
+
+struct ETableMemory {
+ ETableModel base;
+ ETableMemoryPriv *priv;
+};
+
+struct ETableMemoryClass {
+ ETableModelClass parent_class;
+};
+
+
+GtkType e_table_memory_get_type (void);
+void e_table_memory_construct (ETableMemory *etable);
+ETableMemory *e_table_memory_new (void);
+
+/* node operations */
+void e_table_memory_node_insert (ETableMemory *etable,
+ int row,
+ gpointer node_data);
+gpointer e_table_memory_node_remove (ETableMemory *etable,
+ int row);
+
+/* Freeze and thaw */
+void e_table_memory_freeze (ETableMemory *etable);
+void e_table_memory_thaw (ETableMemory *etable);
+gpointer e_table_memory_get_data (ETableMemory *etm,
+ int row);
+void e_table_memory_set_data (ETableMemory *etm,
+ int row,
+ gpointer node_data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _E_TABLE_MEMORY_H */