aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-08-03 00:56:26 +0800
committerChris Lahey <clahey@src.gnome.org>2000-08-03 00:56:26 +0800
commit5fbcc4828efb084344e9c5fd42ebccb288ee492f (patch)
treeba3fe53ec556c7548b6517c24925ada769d3c079 /widgets/table
parent2c7ed49b25b0ab36e003427083b331bd5bc4a61f (diff)
downloadgsoc2013-evolution-5fbcc4828efb084344e9c5fd42ebccb288ee492f.tar.gz
gsoc2013-evolution-5fbcc4828efb084344e9c5fd42ebccb288ee492f.tar.zst
gsoc2013-evolution-5fbcc4828efb084344e9c5fd42ebccb288ee492f.zip
Add a handler for "model_pre_change" and properly stop editing.
2000-08-02 Christopher James Lahey <clahey@helixcode.com> * e-table-item.c, e-table-item.h: Add a handler for "model_pre_change" and properly stop editing. * e-table-model.c, e-table-model.h: Added a "model_pre_change" signal that gets sent before any row numbers are changed. * e-table-sorted-variable.c, e-table-subset-variable.c: Emit "model_pre_change" signals as appropriate. * e-table-subset.c, e-table-subset.h: Proxy "model_pre_changed" signals. svn path=/trunk/; revision=4472
Diffstat (limited to 'widgets/table')
-rw-r--r--widgets/table/e-table-item.c42
-rw-r--r--widgets/table/e-table-item.h1
-rw-r--r--widgets/table/e-table-model.c19
-rw-r--r--widgets/table/e-table-model.h3
-rw-r--r--widgets/table/e-table-sorted-variable.c12
-rw-r--r--widgets/table/e-table-subset-variable.c8
-rw-r--r--widgets/table/e-table-subset.c11
-rw-r--r--widgets/table/e-table-subset.h1
8 files changed, 87 insertions, 10 deletions
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c
index 4eac94ed41..1ecd119133 100644
--- a/widgets/table/e-table-item.c
+++ b/widgets/table/e-table-item.c
@@ -303,6 +303,8 @@ eti_remove_table_model (ETableItem *eti)
return;
gtk_signal_disconnect (GTK_OBJECT (eti->table_model),
+ eti->table_model_pre_change_id);
+ gtk_signal_disconnect (GTK_OBJECT (eti->table_model),
eti->table_model_change_id);
gtk_signal_disconnect (GTK_OBJECT (eti->table_model),
eti->table_model_row_change_id);
@@ -316,6 +318,7 @@ eti_remove_table_model (ETableItem *eti)
if (eti->source_model)
gtk_object_unref (GTK_OBJECT (eti->source_model));
+ eti->table_model_pre_change_id = 0;
eti->table_model_change_id = 0;
eti->table_model_row_change_id = 0;
eti->table_model_cell_change_id = 0;
@@ -559,6 +562,16 @@ eti_item_region_redraw (ETableItem *eti, int x0, int y0, int x1, int y1)
}
/*
+ * Callback routine: invoked before the ETableModel has suffers a change
+ */
+static void
+eti_table_model_pre_change (ETableModel *table_model, ETableItem *eti)
+{
+ if (eti_editing (eti))
+ e_table_item_leave_edit (eti);
+}
+
+/*
* Callback routine: invoked when the ETableModel has suffered a change
*/
static void
@@ -720,7 +733,11 @@ eti_add_table_model (ETableItem *eti, ETableModel *table_model)
eti->table_model = table_model;
gtk_object_ref (GTK_OBJECT (eti->table_model));
-
+
+ eti->table_model_pre_change_id = gtk_signal_connect (
+ GTK_OBJECT (table_model), "model_pre_change",
+ GTK_SIGNAL_FUNC (eti_table_model_pre_change), eti);
+
eti->table_model_change_id = gtk_signal_connect (
GTK_OBJECT (table_model), "model_changed",
GTK_SIGNAL_FUNC (eti_table_model_changed), eti);
@@ -841,12 +858,12 @@ eti_destroy (GtkObject *object)
if (eti->selection)
gtk_object_unref(GTK_OBJECT(eti->selection));
-
+
if (eti->height_cache_idle_id)
g_source_remove(eti->height_cache_idle_id);
-
+
g_free (eti->height_cache);
-
+
if (GTK_OBJECT_CLASS (eti_parent_class)->destroy)
(*GTK_OBJECT_CLASS (eti_parent_class)->destroy) (object);
}
@@ -1033,6 +1050,9 @@ eti_unrealize (GnomeCanvasItem *item)
{
ETableItem *eti = E_TABLE_ITEM (item);
+ if (eti_editing (eti))
+ e_table_item_leave_edit (eti);
+
gdk_gc_unref (eti->fill_gc);
eti->fill_gc = NULL;
gdk_gc_unref (eti->grid_gc);
@@ -1844,18 +1864,26 @@ e_table_item_enter_edit (ETableItem *eti, int col, int row)
void
e_table_item_leave_edit (ETableItem *eti)
{
+ int col, row;
+ void *edit_ctx;
+
g_return_if_fail (eti != NULL);
g_return_if_fail (E_IS_TABLE_ITEM (eti));
if (!eti_editing (eti))
return;
- e_cell_leave_edit (eti->cell_views [eti->editing_col],
- view_to_model_col(eti, eti->editing_col), eti->editing_col, eti->editing_row,
- eti->edit_ctx);
+ col = eti->editing_col;
+ row = eti->editing_row;
+ edit_ctx = eti->edit_ctx;
+
eti->editing_col = -1;
eti->editing_row = -1;
eti->edit_ctx = NULL;
+
+ e_cell_leave_edit (eti->cell_views [col],
+ view_to_model_col(eti, col),
+ col, row, edit_ctx);
}
typedef struct {
diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h
index 7102ef3ef7..b6b441c9d4 100644
--- a/widgets/table/e-table-item.h
+++ b/widgets/table/e-table-item.h
@@ -40,6 +40,7 @@ typedef struct {
*/
int header_dim_change_id;
int header_structure_change_id;
+ int table_model_pre_change_id;
int table_model_change_id;
int table_model_row_change_id;
int table_model_cell_change_id;
diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c
index 7f07bd9787..f47fb7afb2 100644
--- a/widgets/table/e-table-model.c
+++ b/widgets/table/e-table-model.c
@@ -20,6 +20,7 @@ static GtkObjectClass *e_table_model_parent_class;
enum {
MODEL_CHANGED,
+ MODEL_PRE_CHANGE,
MODEL_ROW_CHANGED,
MODEL_CELL_CHANGED,
MODEL_ROW_INSERTED,
@@ -176,6 +177,14 @@ e_table_model_class_init (GtkObjectClass *object_class)
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
+ e_table_model_signals [MODEL_PRE_CHANGE] =
+ gtk_signal_new ("model_pre_change",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETableModelClass, model_pre_change),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
e_table_model_signals [MODEL_ROW_CHANGED] =
gtk_signal_new ("model_row_changed",
GTK_RUN_LAST,
@@ -256,6 +265,16 @@ e_table_model_get_type (void)
}
void
+e_table_model_pre_change (ETableModel *e_table_model)
+{
+ g_return_if_fail (e_table_model != NULL);
+ g_return_if_fail (E_IS_TABLE_MODEL (e_table_model));
+
+ gtk_signal_emit (GTK_OBJECT (e_table_model),
+ e_table_model_signals [MODEL_PRE_CHANGE]);
+}
+
+void
e_table_model_changed (ETableModel *e_table_model)
{
g_return_if_fail (e_table_model != NULL);
diff --git a/widgets/table/e-table-model.h b/widgets/table/e-table-model.h
index 447903c83a..d4fae1659e 100644
--- a/widgets/table/e-table-model.h
+++ b/widgets/table/e-table-model.h
@@ -50,6 +50,8 @@ typedef struct {
* A row inserted: row_inserted
* A row deleted: row_deleted
*/
+ void (*model_pre_change) (ETableModel *etm);
+
void (*model_changed) (ETableModel *etm);
void (*model_row_changed) (ETableModel *etm, int row);
void (*model_cell_changed) (ETableModel *etm, int col, int row);
@@ -76,6 +78,7 @@ char *e_table_model_value_to_string (ETableModel *e_table_model, int col,
/*
* Routines for emitting signals on the e_table
*/
+void e_table_model_pre_change (ETableModel *e_table_model);
void e_table_model_changed (ETableModel *e_table_model);
void e_table_model_row_changed (ETableModel *e_table_model, int row);
void e_table_model_cell_changed (ETableModel *e_table_model, int col, int row);
diff --git a/widgets/table/e-table-sorted-variable.c b/widgets/table/e-table-sorted-variable.c
index a5472d7bce..958daca1de 100644
--- a/widgets/table/e-table-sorted-variable.c
+++ b/widgets/table/e-table-sorted-variable.c
@@ -169,8 +169,12 @@ etsv_add_all (ETableSubsetVariable *etssv)
ETableModel *etm = E_TABLE_MODEL(etssv);
ETableSubset *etss = E_TABLE_SUBSET(etssv);
ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv);
- int rows = e_table_model_row_count(etss->source);
+ int rows;
int i;
+
+ e_table_model_pre_change(etm);
+
+ rows = e_table_model_row_count(etss->source);
if (etss->n_map + rows > etssv->n_vals_allocated){
etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows);
@@ -285,13 +289,17 @@ etsv_sort(ETableSortedVariable *etsv)
ETableSubset *etss = E_TABLE_SUBSET(etsv);
static int reentering = 0;
int rows = E_TABLE_SUBSET(etsv)->n_map;
- int total_rows = e_table_model_row_count(E_TABLE_SUBSET(etsv)->source);
+ int total_rows;
int i;
int j;
int cols;
if (reentering)
return;
reentering = 1;
+
+ e_table_model_pre_change(E_TABLE_MODEL(etsv));
+
+ total_rows = e_table_model_row_count(E_TABLE_SUBSET(etsv)->source);
cols = e_table_sort_info_sorting_get_count(etsv->sort_info);
cols_closure = cols;
etsv_closure = etsv;
diff --git a/widgets/table/e-table-subset-variable.c b/widgets/table/e-table-subset-variable.c
index 377b21c9ae..f418337092 100644
--- a/widgets/table/e-table-subset-variable.c
+++ b/widgets/table/e-table-subset-variable.c
@@ -30,6 +30,8 @@ etssv_add (ETableSubsetVariable *etssv,
ETableSubset *etss = E_TABLE_SUBSET(etssv);
int i;
+ e_table_model_pre_change(etm);
+
if (etss->n_map + 1 > etssv->n_vals_allocated){
etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated + INCREMENT_AMOUNT) * sizeof(int));
etssv->n_vals_allocated += INCREMENT_AMOUNT;
@@ -48,9 +50,12 @@ etssv_add_all (ETableSubsetVariable *etssv)
{
ETableModel *etm = E_TABLE_MODEL(etssv);
ETableSubset *etss = E_TABLE_SUBSET(etssv);
- int rows = e_table_model_row_count(etss->source);
+ int rows;
int i;
+
+ e_table_model_pre_change(etm);
+ rows = e_table_model_row_count(etss->source);
if (etss->n_map + rows > etssv->n_vals_allocated){
etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows);
etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int));
@@ -72,6 +77,7 @@ etssv_remove (ETableSubsetVariable *etssv,
for (i = 0; i < etss->n_map; i++){
if (etss->map_table[i] == row) {
+ e_table_model_pre_change (etm);
memmove (etss->map_table + i, etss->map_table + i + 1, (etss->n_map - i - 1) * sizeof(int));
etss->n_map --;
diff --git a/widgets/table/e-table-subset.c b/widgets/table/e-table-subset.c
index 8ba5ed03e3..1cac0f88ea 100644
--- a/widgets/table/e-table-subset.c
+++ b/widgets/table/e-table-subset.c
@@ -26,12 +26,15 @@ etss_destroy (GtkObject *object)
gtk_object_unref (GTK_OBJECT (etss->source));
gtk_signal_disconnect (GTK_OBJECT (etss->source),
+ etss->table_model_pre_change_id);
+ gtk_signal_disconnect (GTK_OBJECT (etss->source),
etss->table_model_changed_id);
gtk_signal_disconnect (GTK_OBJECT (etss->source),
etss->table_model_row_changed_id);
gtk_signal_disconnect (GTK_OBJECT (etss->source),
etss->table_model_cell_changed_id);
+ etss->table_model_pre_change_id = 0;
etss->table_model_changed_id = 0;
etss->table_model_row_changed_id = 0;
etss->table_model_cell_changed_id = 0;
@@ -153,6 +156,12 @@ etss_class_init (GtkObjectClass *klass)
E_MAKE_TYPE(e_table_subset, "ETableSubset", ETableSubset, etss_class_init, NULL, PARENT_TYPE);
static void
+etss_proxy_model_pre_change (ETableModel *etm, ETableSubset *etss)
+{
+ e_table_model_pre_change (E_TABLE_MODEL (etss));
+}
+
+static void
etss_proxy_model_changed (ETableModel *etm, ETableSubset *etss)
{
e_table_model_changed (E_TABLE_MODEL (etss));
@@ -206,6 +215,8 @@ e_table_subset_construct (ETableSubset *etss, ETableModel *source, int nvals)
for (i = 0; i < nvals; i++)
etss->map_table [i] = i;
+ etss->table_model_pre_change_id = gtk_signal_connect (GTK_OBJECT (source), "model_pre_change",
+ GTK_SIGNAL_FUNC (etss_proxy_model_pre_change), etss);
etss->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed",
GTK_SIGNAL_FUNC (etss_proxy_model_changed), etss);
etss->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed",
diff --git a/widgets/table/e-table-subset.h b/widgets/table/e-table-subset.h
index 074120a410..9e10de7a4b 100644
--- a/widgets/table/e-table-subset.h
+++ b/widgets/table/e-table-subset.h
@@ -18,6 +18,7 @@ typedef struct {
int n_map;
int *map_table;
+ int table_model_pre_change_id;
int table_model_changed_id;
int table_model_row_changed_id;
int table_model_cell_changed_id;