diff options
author | Christopher James Lahey <clahey@ximian.com> | 2001-03-21 07:18:47 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2001-03-21 07:18:47 +0800 |
commit | 13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd (patch) | |
tree | d48d36c995d4aeb98da1baae5203ec3779d2a744 /widgets/table/e-table-memory.c | |
parent | ad0bbfd8a0e705c48b8ed4d7a027426d18f275a3 (diff) | |
download | gsoc2013-evolution-13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd.tar gsoc2013-evolution-13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd.tar.gz gsoc2013-evolution-13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd.tar.bz2 gsoc2013-evolution-13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd.tar.lz gsoc2013-evolution-13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd.tar.xz gsoc2013-evolution-13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd.tar.zst gsoc2013-evolution-13cabd9ef2c63cfd947f1f4604dd0a5eac165ecd.zip |
Added these classes.
2001-03-20 Christopher James Lahey <clahey@ximian.com>
* e-table-memory-callbacks.c, e-table-memory-callbacks.h,
e-table-memory.c, e-table-memory.h: Added these classes.
* Makefile.am: Added e-table-memory-callbacks.c,
e-table-memory-callbacks.h, e-table-memory.c, and
e-table-memory.h.
svn path=/trunk/; revision=8857
Diffstat (limited to 'widgets/table/e-table-memory.c')
-rw-r--r-- | widgets/table/e-table-memory.c | 258 |
1 files changed, 258 insertions, 0 deletions
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)); + } +} |