diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-05-08 04:49:02 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-05-08 04:49:02 +0800 |
commit | 56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff (patch) | |
tree | 1b90f791be6fcb52dc21e44c44b45099317df91d /widgets/table | |
parent | 271cb81264219225420332375135c74857e035e7 (diff) | |
download | gsoc2013-evolution-56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff.tar gsoc2013-evolution-56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff.tar.gz gsoc2013-evolution-56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff.tar.bz2 gsoc2013-evolution-56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff.tar.lz gsoc2013-evolution-56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff.tar.xz gsoc2013-evolution-56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff.tar.zst gsoc2013-evolution-56f9196ac4e30fd0f5e0bd79bab0dcfc9856c8ff.zip |
Handle row_inserted and row_deleted signals properly.
2000-05-07 Christopher James Lahey <clahey@helixcode.com>
* e-table-item.c, e-table-item.h, e-table.c, e-table.h: Handle
row_inserted and row_deleted signals properly.
* e-table-model.c, e-table-model.h: Created the row_inserted and
row_deleted signals.
* e-table-sorted-variable.c, e-table-subset-variable.c: Emit the
row_inserted and row_deleted signals as appropriate.
svn path=/trunk/; revision=2879
Diffstat (limited to 'widgets/table')
-rw-r--r-- | widgets/table/e-table-item.c | 33 | ||||
-rw-r--r-- | widgets/table/e-table-item.h | 2 | ||||
-rw-r--r-- | widgets/table/e-table-model.c | 38 | ||||
-rw-r--r-- | widgets/table/e-table-model.h | 7 | ||||
-rw-r--r-- | widgets/table/e-table-sorted-variable.c | 11 | ||||
-rw-r--r-- | widgets/table/e-table-subset-variable.c | 7 | ||||
-rw-r--r-- | widgets/table/e-table.c | 60 | ||||
-rw-r--r-- | widgets/table/e-table.h | 5 |
8 files changed, 126 insertions, 37 deletions
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c index cae22ec081..13699e1d91 100644 --- a/widgets/table/e-table-item.c +++ b/widgets/table/e-table-item.c @@ -49,6 +49,7 @@ enum { static int eti_get_height (ETableItem *eti); static int eti_row_height (ETableItem *eti, int row); +#define ETI_ROW_HEIGHT(eti,row) ((eti)->height_cache && (eti)->height_cache[(row)] != -1 ? (eti)->height_cache[(row)] : eti_row_height((eti),(row))) static gboolean eti_editing (ETableItem *eti) @@ -235,11 +236,17 @@ eti_remove_table_model (ETableItem *eti) eti->table_model_row_change_id); gtk_signal_disconnect (GTK_OBJECT (eti->table_model), eti->table_model_cell_change_id); + gtk_signal_disconnect (GTK_OBJECT (eti->table_model), + eti->table_model_row_inserted_id); + gtk_signal_disconnect (GTK_OBJECT (eti->table_model), + eti->table_model_row_deleted_id); gtk_object_unref (GTK_OBJECT (eti->table_model)); eti->table_model_change_id = 0; eti->table_model_row_change_id = 0; eti->table_model_cell_change_id = 0; + eti->table_model_row_inserted_id = 0; + eti->table_model_row_deleted_id = 0; eti->table_model = NULL; } @@ -545,6 +552,18 @@ eti_table_model_cell_changed (ETableModel *table_model, int col, int row, ETable eti_request_region_redraw (eti, 0, row, eti->cols, row, 0); } +static void +eti_table_model_row_inserted (ETableModel *table_model, int row, ETableItem *eti) +{ + eti_table_model_changed (table_model, eti); +} + +static void +eti_table_model_row_deleted (ETableModel *table_model, int row, ETableItem *eti) +{ + eti_table_model_changed (table_model, eti); +} + void e_table_item_redraw_range (ETableItem *eti, int start_col, int start_row, @@ -586,6 +605,14 @@ eti_add_table_model (ETableItem *eti, ETableModel *table_model) GTK_OBJECT (table_model), "model_cell_changed", GTK_SIGNAL_FUNC (eti_table_model_cell_changed), eti); + eti->table_model_row_inserted_id = gtk_signal_connect ( + GTK_OBJECT (table_model), "model_row_inserted", + GTK_SIGNAL_FUNC (eti_table_model_row_inserted), eti); + + eti->table_model_row_deleted_id = gtk_signal_connect ( + GTK_OBJECT (table_model), "model_row_deleted", + GTK_SIGNAL_FUNC (eti_table_model_row_deleted), eti); + if (eti->header) { eti_detach_cell_views (eti); eti_attach_cell_views (eti); @@ -893,7 +920,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, y1 = y2 = floor (eti_base.y) + 1; for (row = 0; row < rows; row++, y1 = y2){ - y2 += eti_row_height (eti, row) + 1; + y2 += ETI_ROW_HEIGHT (eti, row) + 1; if (y1 > y + height) break; @@ -929,7 +956,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int xd, height; gboolean selected; - height = eti_row_height (eti, row); + height = ETI_ROW_HEIGHT (eti, row); xd = x_offset; /* printf ("paint: %d %d\n", yd, yd + height); */ @@ -1037,7 +1064,7 @@ find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res, doub if (y < y1) return FALSE; - y2 += eti_row_height (eti, row) + 1; + y2 += ETI_ROW_HEIGHT (eti, row) + 1; if (y > y2) continue; diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h index 696bf465e6..daa436db88 100644 --- a/widgets/table/e-table-item.h +++ b/widgets/table/e-table-item.h @@ -30,6 +30,8 @@ typedef struct { int table_model_change_id; int table_model_row_change_id; int table_model_cell_change_id; + int table_model_row_inserted_id; + int table_model_row_deleted_id; GdkGC *fill_gc; GdkGC *grid_gc; diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c index d75554f2d0..3ea01c05e1 100644 --- a/widgets/table/e-table-model.c +++ b/widgets/table/e-table-model.c @@ -22,6 +22,8 @@ enum { MODEL_CHANGED, MODEL_ROW_CHANGED, MODEL_CELL_CHANGED, + MODEL_ROW_INSERTED, + MODEL_ROW_DELETED, ROW_SELECTION, LAST_SIGNAL }; @@ -143,6 +145,22 @@ e_table_model_class_init (GtkObjectClass *object_class) gtk_marshal_NONE__INT_INT, GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); + e_table_model_signals [MODEL_ROW_INSERTED] = + gtk_signal_new ("model_row_inserted", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETableModelClass, model_row_inserted), + gtk_marshal_NONE__INT, + GTK_TYPE_NONE, 1, GTK_TYPE_INT); + + e_table_model_signals [MODEL_ROW_DELETED] = + gtk_signal_new ("model_row_deleted", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETableModelClass, model_row_deleted), + gtk_marshal_NONE__INT, + GTK_TYPE_NONE, 1, GTK_TYPE_INT); + gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); } @@ -203,6 +221,26 @@ e_table_model_cell_changed (ETableModel *e_table_model, int col, int row) } void +e_table_model_row_inserted (ETableModel *e_table_model, int row) +{ + 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_ROW_INSERTED], row); +} + +void +e_table_model_row_deleted (ETableModel *e_table_model, int row) +{ + 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_ROW_DELETED], row); +} + +void e_table_model_freeze (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 ceca8e348f..e542754f22 100644 --- a/widgets/table/e-table-model.h +++ b/widgets/table/e-table-model.h @@ -37,13 +37,18 @@ typedef struct { */ /* + * These all come after the change has been made. * Major structural changes: model_changed * Changes only in a row: row_changed * Only changes in a cell: cell_changed + * A row inserted: row_inserted + * A row deleted: row_deleted */ void (*model_changed) (ETableModel *etm); void (*model_row_changed) (ETableModel *etm, int row); void (*model_cell_changed) (ETableModel *etm, int col, int row); + void (*model_row_inserted) (ETableModel *etm, int row); + void (*model_row_deleted) (ETableModel *etm, int row); } ETableModelClass; GtkType e_table_model_get_type (void); @@ -67,5 +72,7 @@ void e_table_model_thaw (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); +void e_table_model_row_inserted (ETableModel *e_table_model, int row); +void e_table_model_row_deleted (ETableModel *e_table_model, int row); #endif /* _E_TABLE_MODEL_H_ */ diff --git a/widgets/table/e-table-sorted-variable.c b/widgets/table/e-table-sorted-variable.c index bf571c9f95..5d11e03d6f 100644 --- a/widgets/table/e-table-sorted-variable.c +++ b/widgets/table/e-table-sorted-variable.c @@ -91,8 +91,10 @@ E_MAKE_TYPE(e_table_sorted_variable, "ETableSortedVariable", ETableSortedVariabl static gboolean etsv_sort_idle(ETableSortedVariable *etsv) { + gtk_object_ref(GTK_OBJECT(etsv)); etsv_sort(etsv); etsv->sort_idle_id = 0; + gtk_object_unref(GTK_OBJECT(etsv)); return FALSE; } @@ -103,18 +105,23 @@ etsv_add (ETableSubsetVariable *etssv, ETableModel *etm = E_TABLE_MODEL(etssv); ETableSubset *etss = E_TABLE_SUBSET(etssv); ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); + int i; if (etss->n_map + 1 > etssv->n_vals_allocated){ etssv->n_vals_allocated += INCREMENT_AMOUNT; etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated) * sizeof(int)); } + if (row < e_table_model_row_count(etss->source) - 1) + for ( i = 0; i < etss->n_map; i++ ) + if (etss->map_table[i] >= row) + etss->map_table[i] ++; etss->map_table[etss->n_map] = row; etss->n_map++; if (etsv->sort_idle_id == 0) { etsv->sort_idle_id = g_idle_add_full(50, (GSourceFunc) etsv_sort_idle, etsv, NULL); } if (!etm->frozen) - e_table_model_changed (etm); + e_table_model_row_inserted (etm, etss->n_map - 1); } static void @@ -264,10 +271,12 @@ etsv_sort(ETableSortedVariable *etsv) else col = e_table_header_get_column (etsv->full_header, column.column); for (i = 0; i < rows; i++) { +#if 0 if( !(i & 0xff) ) { while(gtk_events_pending()) gtk_main_iteration(); } +#endif vals_closure[i * cols + j] = e_table_model_value_at (etss->source, col->col_idx, i); } compare_closure[j] = col->compare; diff --git a/widgets/table/e-table-subset-variable.c b/widgets/table/e-table-subset-variable.c index bd96d5360c..c42d53842b 100644 --- a/widgets/table/e-table-subset-variable.c +++ b/widgets/table/e-table-subset-variable.c @@ -28,14 +28,19 @@ etssv_add (ETableSubsetVariable *etssv, { ETableModel *etm = E_TABLE_MODEL(etssv); ETableSubset *etss = E_TABLE_SUBSET(etssv); + int i; 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; } + if (row < e_table_model_row_count(etss->source) - 1) + for ( i = 0; i < etss->n_map; i++ ) + if (etss->map_table[i] >= row) + etss->map_table[i] ++; etss->map_table[etss->n_map++] = row; if (!etm->frozen) - e_table_model_changed (etm); + e_table_model_row_inserted (etm, etss->n_map - 1); } static void diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c index 83296c9cba..adb76216ce 100644 --- a/widgets/table/e-table.c +++ b/widgets/table/e-table.c @@ -65,6 +65,10 @@ et_destroy (GtkObject *object) et->table_row_change_id); gtk_signal_disconnect (GTK_OBJECT (et->model), et->table_cell_change_id); + gtk_signal_disconnect (GTK_OBJECT (et->model), + et->table_row_inserted_id); + gtk_signal_disconnect (GTK_OBJECT (et->model), + et->table_row_deleted_id); if (et->group_info_change_id) gtk_signal_disconnect (GTK_OBJECT (et->sort_info), et->group_info_change_id); @@ -100,8 +104,6 @@ e_table_init (GtkObject *object) e_table->spreadsheet = 1; e_table->need_rebuild = 0; - e_table->need_row_changes = 0; - e_table->row_changes_list = NULL; e_table->rebuild_idle_id = 0; } @@ -172,16 +174,6 @@ table_canvas_reflow (GnomeCanvas *canvas, ETable *e_table) } static void -change_row (gpointer key, gpointer value, gpointer data) -{ - ETable *et = E_TABLE (data); - gint row = GPOINTER_TO_INT (key); - - if (e_table_group_remove (et->group, row)) - e_table_group_add (et->group, row); -} - -static void group_row_selection (ETableGroup *etg, int row, gboolean selected, ETable *et) { gtk_signal_emit (GTK_OBJECT (et), @@ -209,14 +201,9 @@ changed_idle (gpointer data) gtk_object_set (GTK_OBJECT (et->group), "width", (double) GTK_WIDGET (et->table_canvas)->allocation.width, NULL); - } else if (et->need_row_changes) - g_hash_table_foreach (et->row_changes_list, change_row, et); + } et->need_rebuild = 0; - et->need_row_changes = 0; - if (et->row_changes_list) - g_hash_table_destroy (et->row_changes_list); - et->row_changes_list = NULL; et->rebuild_idle_id = 0; return FALSE; @@ -234,18 +221,9 @@ static void et_table_row_changed (ETableModel *table_model, int row, ETable *et) { if (!et->need_rebuild) { - if (!et->need_row_changes) { - et->need_row_changes = 1; - et->row_changes_list = g_hash_table_new (g_direct_hash, g_direct_equal); - } - if (!g_hash_table_lookup (et->row_changes_list, GINT_TO_POINTER (row))) { - g_hash_table_insert (et->row_changes_list, GINT_TO_POINTER (row), - GINT_TO_POINTER (row + 1)); - } + if (e_table_group_remove (et->group, row)) + e_table_group_add (et->group, row); } - - if (!et->rebuild_idle_id) - et->rebuild_idle_id = g_idle_add (changed_idle, et); } static void @@ -255,6 +233,22 @@ et_table_cell_changed (ETableModel *table_model, int view_col, int row, ETable * } static void +et_table_row_inserted (ETableModel *table_model, int row, ETable *et) +{ + if (!et->need_rebuild) { + e_table_group_add (et->group, row); + } +} + +static void +et_table_row_deleted (ETableModel *table_model, int row, ETable *et) +{ + if (!et->need_rebuild) { + e_table_group_remove (et->group, row); + } +} + +static void e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *header, ETableModel *model) { @@ -287,6 +281,14 @@ e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *h e_table->table_cell_change_id = gtk_signal_connect ( GTK_OBJECT (model), "model_cell_changed", GTK_SIGNAL_FUNC (et_table_cell_changed), e_table); + + e_table->table_row_inserted_id = gtk_signal_connect ( + GTK_OBJECT (model), "model_row_inserted", + GTK_SIGNAL_FUNC (et_table_row_inserted), e_table); + + e_table->table_row_deleted_id = gtk_signal_connect ( + GTK_OBJECT (model), "model_row_deleted", + GTK_SIGNAL_FUNC (et_table_row_deleted), e_table); } static void diff --git a/widgets/table/e-table.h b/widgets/table/e-table.h index 35b9cd0002..ff03caf00d 100644 --- a/widgets/table/e-table.h +++ b/widgets/table/e-table.h @@ -32,6 +32,8 @@ typedef struct { int table_model_change_id; int table_row_change_id; int table_cell_change_id; + int table_row_inserted_id; + int table_row_deleted_id; int group_info_change_id; @@ -40,9 +42,6 @@ typedef struct { GnomeCanvasItem *header_item, *root; guint need_rebuild:1; - guint need_row_changes:1; - - GHashTable *row_changes_list; gint rebuild_idle_id; /* |