diff options
author | Mike Kestner <mkestner@ximian.com> | 2003-02-05 14:03:05 +0800 |
---|---|---|
committer | Mike Kestner <mkestner@src.gnome.org> | 2003-02-05 14:03:05 +0800 |
commit | 3fd666240121bd4264f71e045ee40f6a861abb9e (patch) | |
tree | b49bbbeaa48284116f86bc106689a9fd3dda8e93 /widgets | |
parent | 0d7462802f639ce49576f996927b308e9f856ac5 (diff) | |
download | gsoc2013-evolution-3fd666240121bd4264f71e045ee40f6a861abb9e.tar gsoc2013-evolution-3fd666240121bd4264f71e045ee40f6a861abb9e.tar.gz gsoc2013-evolution-3fd666240121bd4264f71e045ee40f6a861abb9e.tar.bz2 gsoc2013-evolution-3fd666240121bd4264f71e045ee40f6a861abb9e.tar.lz gsoc2013-evolution-3fd666240121bd4264f71e045ee40f6a861abb9e.tar.xz gsoc2013-evolution-3fd666240121bd4264f71e045ee40f6a861abb9e.tar.zst gsoc2013-evolution-3fd666240121bd4264f71e045ee40f6a861abb9e.zip |
make GAL_LIBS use -lgal-2.0 remove extraneous GTK_LIBS reference update to
2003-02-03 Mike Kestner <mkestner@ximian.com>
* configure.in : make GAL_LIBS use -lgal-2.0
* gal/Makefile.am : remove extraneous GTK_LIBS reference
* tests/test-tree-3.c : update to new etta API
gal/e-table/ChangeLog
2003-02-03 Mike Kestner <mkestner@ximian.com>
* e-tree-selection-model.c : remove e-tree-sorted usage
* e-tree-table-adapter.* : rewrite to perform sorting
* e-tree.c : remove e-tree-sorted usage
svn path=/trunk/; revision=19755
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/table/e-table-item.c | 4 | ||||
-rw-r--r-- | widgets/table/e-tree-selection-model.c | 176 | ||||
-rw-r--r-- | widgets/table/e-tree-table-adapter.c | 1193 | ||||
-rw-r--r-- | widgets/table/e-tree-table-adapter.h | 13 | ||||
-rw-r--r-- | widgets/table/e-tree.c | 101 |
5 files changed, 613 insertions, 874 deletions
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c index a8a80248e6..ac73bc1f9a 100644 --- a/widgets/table/e-table-item.c +++ b/widgets/table/e-table-item.c @@ -897,9 +897,13 @@ eti_show_cursor (ETableItem *eti, int delay) return; } +#if 0 g_object_get(eti->selection, "cursor_row", &cursor_row, NULL); +#else + cursor_row = e_selection_model_cursor_row (eti->selection); +#endif d(g_print ("%s: cursor row: %d\n", __FUNCTION__, cursor_row)); diff --git a/widgets/table/e-tree-selection-model.c b/widgets/table/e-tree-selection-model.c index cbd47bcdec..c3639d7ed7 100644 --- a/widgets/table/e-tree-selection-model.c +++ b/widgets/table/e-tree-selection-model.c @@ -30,7 +30,6 @@ #include <gal/util/e-i18n.h> #include <gal/util/e-util.h> #include <gdk/gdkkeysyms.h> -#include <gal/e-table/e-tree-sorted.h> #include <gal/e-table/e-tree-table-adapter.h> #define PARENT_TYPE e_selection_model_get_type () @@ -43,7 +42,6 @@ enum { PROP_CURSOR_COL, PROP_MODEL, PROP_ETTA, - PROP_ETS }; typedef struct ETreeSelectionModelNode { @@ -58,7 +56,6 @@ typedef struct ETreeSelectionModelNode { struct ETreeSelectionModelPriv { ETreeTableAdapter *etta; - ETreeSorted *ets; ETreeModel *model; ETreeSelectionModelNode *root; @@ -80,8 +77,6 @@ struct ETreeSelectionModelPriv { int tree_model_node_removed_id; int tree_model_node_deleted_id; - int sorted_model_node_resorted_id; - /* Anything other than -1 means that the selection is a single * row. This being -1 does not impart any information. */ int selected_row; @@ -114,7 +109,10 @@ static void e_tree_selection_model_node_fill_children(ETreeSelectionModel *etsm, ETreePath path, ETreeSelectionModelNode *selection_node) { int i; - selection_node->num_children = e_tree_sorted_node_num_children(etsm->priv->ets, path); + for (selection_node->num_children = 0, path = e_tree_model_node_get_first_child(etsm->priv->model, path); + path; + path = e_tree_model_node_get_next(etsm->priv->model, path)) + selection_node->num_children++; selection_node->children = g_new(ETreeSelectionModelNode *, selection_node->num_children); for (i = 0; i < selection_node->num_children; i++) { selection_node->children[i] = NULL; @@ -151,17 +149,12 @@ etsm_node_at_row(ETreeSelectionModel *etsm, int row) path = e_tree_table_adapter_node_at_row(etsm->priv->etta, row); - if (path) - path = e_tree_sorted_view_to_model_path(etsm->priv->ets, path); - return path; } static int etsm_row_of_node(ETreeSelectionModel *etsm, ETreePath path) { - path = e_tree_sorted_model_to_view_path(etsm->priv->ets, path); - if (path) return e_tree_table_adapter_row_of_node(etsm->priv->etta, path); else @@ -186,21 +179,38 @@ etsm_real_clear (ETreeSelectionModel *etsm) } } + +static gint +etsm_orig_position(ETreeModel *etm, ETreePath path) +{ + ETreePath parent, p; + gint pos; + + parent = e_tree_model_node_get_parent(etm, path); + for (pos = 0, p = e_tree_model_node_get_first_child(etm, parent); + p && (p != path); + p = e_tree_model_node_get_next(etm, p), pos++); + + if (p) + return pos; + + return -1; +} + static ETreeSelectionModelNode * etsm_find_node_unless_equals (ETreeSelectionModel *etsm, ETreePath path, gboolean grow) { ETreeSelectionModelNode *selection_node; - ETreeSorted *ets = etsm->priv->ets; ETreePath parent; - parent = e_tree_model_node_get_parent(E_TREE_MODEL(ets), path); + parent = e_tree_model_node_get_parent(etsm->priv->model, path); if (parent) { selection_node = etsm_find_node_unless_equals(etsm, parent, grow); if (selection_node) { - int position = e_tree_sorted_orig_position(ets, path); + int position = etsm_orig_position(etsm->priv->model, path); if (selection_node->all_children_selected && grow) return NULL; if (!(selection_node->any_children_selected || grow)) @@ -225,45 +235,11 @@ etsm_find_node_unless_equals (ETreeSelectionModel *etsm, } } -#if 0 -static ETreeSelectionModelNode * -find_or_create_node (ETreeSelectionModel *etsm, - ETreePath path) -{ - ETreeSelectionModelNode *selection_node; - ETreeSelectionModelNode **place = NULL; - ETreeSorted *ets = etsm->priv->ets; - ETreePath parent; - - parent = e_tree_model_node_get_parent(E_TREE_MODEL(ets), path); - - if (parent) { - selection_node = find_or_create_node(etsm, parent); - if (selection_node) { - int position = e_tree_sorted_orig_position(ets, path); - if (!selection_node->children) { - e_tree_selection_model_node_fill_children(etsm, parent, selection_node); - } - if (!selection_node->children[position]) - slection_node->children[position] = e_tree_selection_model_node_new(); - - return selection_node->children[position]; - } else - return NULL; - } else { - if (!etsm->priv->root) - etsm->priv->root = e_tree_selection_model_node_new(); - return etsm->priv->root; - } -} -#endif - static void update_parents (ETreeSelectionModel *etsm, ETreePath path) { int i; int depth; - ETreeSorted *ets = etsm->priv->ets; int *orig_position_sequence; ETreeSelectionModelNode **node_sequence; ETreePath parents; @@ -271,7 +247,7 @@ update_parents (ETreeSelectionModel *etsm, ETreePath path) if (!etsm->priv->root) return; - depth = e_tree_model_node_depth (E_TREE_MODEL(ets), path); + depth = e_tree_model_node_depth (etsm->priv->model, path); orig_position_sequence = g_new(int, depth + 1); node_sequence = g_new(ETreeSelectionModelNode *, depth + 1); @@ -284,8 +260,8 @@ update_parents (ETreeSelectionModel *etsm, ETreePath path) g_free(node_sequence); return; } - orig_position_sequence[i] = e_tree_sorted_orig_position(etsm->priv->ets, parents); - parents = e_tree_model_node_get_parent(E_TREE_MODEL(etsm->priv->ets), parents); + orig_position_sequence[i] = etsm_orig_position(etsm->priv->model, parents); + parents = e_tree_model_node_get_parent(etsm->priv->model, parents); } node_sequence[0] = etsm->priv->root; @@ -359,11 +335,6 @@ etsm_change_one_path(ETreeSelectionModel *etsm, ETreePath path, gboolean grow) if (!path) return; - path = e_tree_sorted_model_to_view_path(etsm->priv->ets, path); - - if (!path) - return; - node = etsm_find_node_unless_equals (etsm, path, grow); if (node) { @@ -480,22 +451,6 @@ etsm_node_inserted (ETreeModel *etm, ETreePath parent, ETreePath child, ETreeSel { clear_tree (etsm, etm); etsm_unfreeze (etsm); -#if 0 - ETreeSelectionModelNode *node; - ETreePath path; - - path = e_tree_sorted_model_to_view_path(etsm->priv->ets, parent); - - if (!path) - return; - - node = etsm_find_node_unless_equals (etsm, path, FALSE); - - if (node) { - node->selected = FALSE; - update_parents(etsm, path); - } -#endif } static void @@ -512,21 +467,6 @@ etsm_node_deleted (ETreeModel *etm, ETreePath child, ETreeSelectionModel *etsm) static void -etsm_sorted_node_resorted (ETreeModel *etm, ETreePath node, ETreeSelectionModel *etsm) -{ - int cursor_row = etsm_cursor_row_real (etsm); - - etsm->priv->selected_row = -1; - etsm->priv->selected_range_end = -1; - e_selection_model_selection_changed(E_SELECTION_MODEL(etsm)); - - if (cursor_row != -1) - e_selection_model_cursor_changed(E_SELECTION_MODEL(etsm), cursor_row, etsm->priv->cursor_col); - else - e_selection_model_cursor_changed(E_SELECTION_MODEL(etsm), -1, -1); -} - -static void add_model(ETreeSelectionModel *etsm, ETreeModel *model) { ETreeSelectionModelPriv *priv = etsm->priv; @@ -594,38 +534,6 @@ drop_model(ETreeSelectionModel *etsm) } -static void -add_ets(ETreeSelectionModel *etsm, ETreeSorted *ets) -{ - ETreeSelectionModelPriv *priv = etsm->priv; - - priv->ets = ets; - - if (!priv->ets) - return; - - g_object_ref(priv->ets); - priv->sorted_model_node_resorted_id = g_signal_connect (G_OBJECT (priv->ets), "node_resorted", - G_CALLBACK (etsm_sorted_node_resorted), etsm); -} - -static void -drop_ets(ETreeSelectionModel *etsm) -{ - ETreeSelectionModelPriv *priv = etsm->priv; - - if (!priv->ets) - return; - - g_signal_handler_disconnect (G_OBJECT (priv->ets), - priv->sorted_model_node_resorted_id); - - g_object_unref (priv->ets); - priv->ets = NULL; - - priv->sorted_model_node_resorted_id = 0; -} - /* Virtual functions */ static void etsm_dispose (GObject *object) @@ -639,7 +547,6 @@ etsm_dispose (GObject *object) etsm->priv->cursor_path = NULL; drop_model(etsm); - drop_ets(etsm); g_free (etsm->priv->cursor_save_id); etsm->priv->cursor_save_id = NULL; @@ -673,10 +580,6 @@ etsm_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *ps case PROP_ETTA: g_value_set_object (value, etsm->priv->etta); break; - - case PROP_ETS: - g_value_set_object (value, etsm->priv->ets); - break; } } @@ -703,11 +606,6 @@ etsm_set_property (GObject *object, guint prop_id, const GValue *value, GParamSp case PROP_ETTA: etsm->priv->etta = E_TREE_TABLE_ADAPTER (g_value_get_object (value)); break; - - case PROP_ETS: - drop_ets(etsm); - add_ets(etsm, E_TREE_SORTED (g_value_get_object (value))); - break; } } @@ -717,15 +615,14 @@ etsm_recurse_is_path_selected (ETreeSelectionModel *etsm, gboolean *is_selected) { ETreeSelectionModelNode *selection_node; - ETreeSorted *ets = etsm->priv->ets; ETreePath parent; - parent = e_tree_model_node_get_parent(E_TREE_MODEL(ets), path); + parent = e_tree_model_node_get_parent(etsm->priv->model, path); if (parent) { selection_node = etsm_recurse_is_path_selected (etsm, parent, is_selected); if (selection_node) { - int position = e_tree_sorted_orig_position(ets, path); + int position = etsm_orig_position(etsm->priv->model, path); if (position < 0 || position >= selection_node->num_children) { *is_selected = FALSE; return NULL; @@ -770,6 +667,9 @@ etsm_is_path_selected (ETreeSelectionModel *etsm, ETreeSelectionModelNode *selection_node; gboolean ret_val; + if (!path) + return FALSE; + selection_node = etsm_recurse_is_path_selected (etsm, path, &ret_val); if (selection_node) @@ -927,7 +827,7 @@ etsm_selected_count (ESelectionModel *selection) ETreePath model_root; model_root = e_tree_model_get_root(etsm->priv->model); etsm_selected_count_recurse(etsm, etsm->priv->root, model_root, &count); - if (!e_tree_table_adapter_root_node_is_visible (etsm->priv->etta) && etsm_is_path_selected (etsm, e_tree_model_get_root(E_TREE_MODEL (etsm->priv->ets)))) { + if (!e_tree_table_adapter_root_node_is_visible (etsm->priv->etta) && etsm_is_path_selected (etsm, e_tree_model_get_root(etsm->priv->model))) { count --; } } @@ -947,7 +847,7 @@ etsm_select_all (ESelectionModel *selection) ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL(selection); ETreePath root; - root = e_tree_model_get_root(E_TREE_MODEL(etsm->priv->ets)); + root = e_tree_model_get_root(etsm->priv->model); if (root == NULL) return; @@ -1316,7 +1216,6 @@ e_tree_selection_model_init (ETreeSelectionModel *etsm) etsm->priv = priv; priv->etta = NULL; - priv->ets = NULL; priv->model = NULL; priv->root = NULL; @@ -1341,7 +1240,6 @@ e_tree_selection_model_init (ETreeSelectionModel *etsm) priv->tree_model_node_removed_id = 0; priv->tree_model_node_deleted_id = 0; - priv->sorted_model_node_resorted_id = 0; priv->selected_row = -1; priv->selected_range_end = -1; } @@ -1407,12 +1305,6 @@ e_tree_selection_model_class_init (ETreeSelectionModelClass *klass) E_TREE_TABLE_ADAPTER_TYPE, G_PARAM_READWRITE)); - g_object_class_install_property (object_class, PROP_ETS, - g_param_spec_object ("ets", - _("ETS"), - /*_( */"XXX blurb" /*)*/, - E_TREE_SORTED_TYPE, - G_PARAM_READWRITE)); } ESelectionModel * diff --git a/widgets/table/e-tree-table-adapter.c b/widgets/table/e-tree-table-adapter.c index 42366ebd21..16411c19ec 100644 --- a/widgets/table/e-tree-table-adapter.c +++ b/widgets/table/e-tree-table-adapter.c @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* +/* * e-tree-table-adapter.c * Copyright 2000, 2001, Ximian, Inc. * @@ -35,367 +35,416 @@ #include "gal/util/e-util.h" #include "gal/util/e-xml-utils.h" #include "e-tree-table-adapter.h" +#include "e-table-sorting-utils.h" +#define PARENT_TYPE E_TABLE_MODEL_TYPE #define d(x) #define INCREMENT_AMOUNT 100 static ETableModelClass *parent_class; +typedef struct { + ETreePath path; + guint32 num_visible_children; + guint32 index; + + guint expanded : 1; + guint expandable : 1; + guint expandable_set : 1; +} node_t; struct ETreeTableAdapterPriv { - ETreeModel *source; + ETreeModel *source; + ETableSortInfo *sort_info; + ETableHeader *header; + int n_map; int n_vals_allocated; - ETreePath *map_table; - GHashTable *attributes; + node_t **map_table; + GHashTable *nodes; + GNode *root; guint root_visible : 1; + guint remap_needed : 1; int last_access; - int tree_model_pre_change_id; - int tree_model_no_change_id; - int tree_model_node_changed_id; - int tree_model_node_data_changed_id; - int tree_model_node_col_changed_id; - int tree_model_node_inserted_id; - int tree_model_node_removed_id; - int tree_model_node_request_collapse_id; + int pre_change_id; + int no_change_id; + int node_changed_id; + int node_data_changed_id; + int node_col_changed_id; + int node_inserted_id; + int node_removed_id; + int node_request_collapse_id; + int sort_info_changed_id; }; -typedef struct ETreeTableAdapterNode { - guint expanded : 1; - guint expandable : 1; - guint expandable_set : 1; - - /* parent/child/sibling pointers */ - guint32 num_visible_children; -} ETreeTableAdapterNode; - -static ETreeTableAdapterNode * -find_node(ETreeTableAdapter *adapter, ETreePath path) +static GNode * +lookup_gnode(ETreeTableAdapter *etta, ETreePath path) { - ETreeTableAdapterNode *node; + GNode *gnode; - if (path == NULL) + if (!path) return NULL; - if (e_tree_model_has_save_id(adapter->priv->source)) { - char *save_id; - save_id = e_tree_model_get_save_id(adapter->priv->source, path); - node = g_hash_table_lookup(adapter->priv->attributes, save_id); - g_free(save_id); - } else { - node = g_hash_table_lookup(adapter->priv->attributes, path); - } - if (node && !node->expandable_set) { - node->expandable = e_tree_model_node_is_expandable(adapter->priv->source, path); - node->expandable_set = 1; - } + gnode = g_hash_table_lookup(etta->priv->nodes, path); - return node; + return gnode; } -static ETreeTableAdapterNode * -find_or_create_node(ETreeTableAdapter *etta, ETreePath path) +static void +resize_map(ETreeTableAdapter *etta, int size) { - ETreeTableAdapterNode *node; - - node = find_node(etta, path); + if (size > etta->priv->n_vals_allocated) { + etta->priv->n_vals_allocated = MAX(etta->priv->n_vals_allocated + INCREMENT_AMOUNT, size); + etta->priv->map_table = g_renew (node_t *, etta->priv->map_table, etta->priv->n_vals_allocated); + } - if (!node) { - node = g_new(ETreeTableAdapterNode, 1); - if (e_tree_model_node_is_root(etta->priv->source, path)) - node->expanded = TRUE; - else - node->expanded = e_tree_model_get_expanded_default(etta->priv->source); - node->expandable = e_tree_model_node_is_expandable(etta->priv->source, path); - node->expandable_set = 1; - node->num_visible_children = 0; - - if (e_tree_model_has_save_id(etta->priv->source)) { - char *save_id; - save_id = e_tree_model_get_save_id(etta->priv->source, path); - g_hash_table_insert(etta->priv->attributes, save_id, node); - } else { - g_hash_table_insert(etta->priv->attributes, path, node); - } - } + etta->priv->n_map = size; +} - return node; +static void +move_map_elements(ETreeTableAdapter *etta, int to, int from, int count) +{ + if (count <= 0 || from >= etta->priv->n_map) + return; + memmove(etta->priv->map_table + to, etta->priv->map_table + from, count * sizeof (node_t *)); } -static gboolean -e_tree_table_adapter_node_would_be_expanded (ETreeTableAdapter *etta, ETreePath path) +static gint +fill_map(ETreeTableAdapter *etta, gint index, GNode *gnode) { - ETreeTableAdapterNode *node; - - if (e_tree_model_node_is_root(etta->priv->source, path) && - !etta->priv->root_visible) - return TRUE; - - node = find_node (etta, path); - if (node) - return node->expanded; - else { - if (e_tree_model_node_is_root(etta->priv->source, path)) - return TRUE; - else - return e_tree_model_get_expanded_default(etta->priv->source); - } + GNode *p; + + if ((gnode != etta->priv->root) || etta->priv->root_visible) + etta->priv->map_table[index++] = gnode->data; + + for (p = gnode->children; p; p = p->next) + index = fill_map(etta, index, p); + + etta->priv->remap_needed = TRUE; + return index; } static void -add_expanded_node(ETreeTableAdapter *etta, char *save_id, gboolean expanded) +remap_indices(ETreeTableAdapter *etta) { - ETreeTableAdapterNode *node; + int i; + for (i = 0; i < etta->priv->n_map; i++) + etta->priv->map_table[i]->index = i; + etta->priv->remap_needed = FALSE; +} - node = g_hash_table_lookup(etta->priv->attributes, save_id); +static void +resort_node(ETreeTableAdapter *etta, GNode *gnode, gboolean recurse) +{ + node_t *node = (node_t *)gnode->data; + ETreePath *paths, path; + GNode *prev, *curr; + int i; - if (node) { - node->expandable_set = 0; - node->expanded = expanded; + if (node->num_visible_children == 0 || !gnode->children) + return; + else if (node->num_visible_children == 1 && recurse) { + resort_node(etta, gnode->children, recurse); return; } - node = g_new(ETreeTableAdapterNode, 1); + paths = g_new0(ETreePath, node->num_visible_children); + + g_return_if_fail(paths != NULL); - node->expanded = expanded; - node->expandable = 0; - node->expandable_set = 0; - node->num_visible_children = 0; + for (i = 0, path = e_tree_model_node_get_first_child(etta->priv->source, node->path); path; + path = e_tree_model_node_get_next(etta->priv->source, path), i++) + paths[i] = path; - g_hash_table_insert(etta->priv->attributes, save_id, node); -} + if (etta->priv->sort_info && e_table_sort_info_sorting_get_count > 0) + e_table_sorting_utils_tree_sort(etta->priv->source, etta->priv->sort_info, etta->priv->header, paths, node->num_visible_children); -static void -etta_expand_to(ETreeTableAdapter *etta, int size) -{ - if (size > etta->priv->n_vals_allocated) { - etta->priv->n_vals_allocated = MAX(etta->priv->n_vals_allocated + INCREMENT_AMOUNT, size); - etta->priv->map_table = g_renew (ETreePath, etta->priv->map_table, etta->priv->n_vals_allocated); + prev = NULL; + for (i = 0; paths[i]; i++) { + curr = lookup_gnode(etta, paths[i]); + if (!curr) + continue; + + if (prev) + prev->next = curr; + else + gnode->children = curr; + + curr->prev = prev; + curr->next = NULL; + prev = curr; + if (recurse) + resort_node(etta, curr, recurse); } + g_free(paths); } -static void -etta_update_parent_child_counts(ETreeTableAdapter *etta, ETreePath path, int change) +static node_t * +get_node(ETreeTableAdapter *etta, ETreePath path) { - for (path = e_tree_model_node_get_parent(etta->priv->source, path); - path; - path = e_tree_model_node_get_parent(etta->priv->source, path)) { - ETreeTableAdapterNode *node = find_or_create_node(etta, path); - node->num_visible_children += change; - } - etta->priv->n_map += change; + GNode *gnode = lookup_gnode(etta, path); + + if (!gnode) + return NULL; + + return (node_t *)gnode->data; } -static int -find_next_node_maybe_deleted(ETreeTableAdapter *adapter, int row) +static gint +get_row(ETreeTableAdapter *etta, ETreePath path) { - ETreePath path = adapter->priv->map_table[row]; - if (path) { - ETreeTableAdapterNode *current = find_node (adapter, path); - - row += (current ? current->num_visible_children : 0) + 1; - if (row >= adapter->priv->n_map) - return -1; - return row; - } else + node_t *node = get_node(etta, path); + if (!node) return -1; + + if (etta->priv->remap_needed) + remap_indices(etta); + + return node->index; } -static int -find_first_child_node_maybe_deleted(ETreeTableAdapter *adapter, int row) +static ETreePath +get_path (ETreeTableAdapter *etta, int row) { - if (row != -1) { - ETreePath path = adapter->priv->map_table[row]; - if (e_tree_table_adapter_node_would_be_expanded (adapter, path)) { - row ++; - if (row >= adapter->priv->n_map) - return -1; - return row; - } else - return -1; - } else - return 0; + if (row == -1 && etta->priv->n_map > 0) + row = etta->priv->n_map - 1; + else if (row < 0 || row >= etta->priv->n_map) + return NULL; + + return etta->priv->map_table [row]->path; } -static int -find_next_node(ETreeTableAdapter *adapter, int row) +static void +kill_gnode(GNode *node, ETreeTableAdapter *etta) { - ETreePath path = adapter->priv->map_table[row]; - if (path) { - ETreePath next_sibling = e_tree_model_node_get_next(adapter->priv->source, path); - ETreeTableAdapterNode *current = find_node (adapter, path); - if (next_sibling) { - row += (current ? current->num_visible_children : 0) + 1; - if (row > adapter->priv->n_map) - return -1; - return row; - } else - return -1; - } else - return -1; + g_hash_table_remove(etta->priv->nodes, ((node_t *)node->data)->path); + + while (node->children) { + GNode *next = node->children->next; + kill_gnode(node->children, etta); + node->children = next; + } + + g_free(node->data); + g_node_destroy(node); } -static int -find_first_child_node(ETreeTableAdapter *adapter, int row) +static void +update_child_counts(GNode *gnode, gint delta) { - if (row != -1) { - ETreePath path = adapter->priv->map_table[row]; - ETreePath first_child = e_tree_model_node_get_first_child(adapter->priv->source, path); - if (first_child && e_tree_table_adapter_node_is_expanded (adapter, path)) { - row ++; - if (row > adapter->priv->n_map) - return -1; - return row; - } else - return -1; - } else - return 0; + while (gnode) { + node_t *node = (node_t *) gnode->data; + node->num_visible_children += delta; + gnode = gnode->parent; + } } static int -find_child_row_num_maybe_deleted(ETreeTableAdapter *etta, int row, ETreePath path) +delete_children(ETreeTableAdapter *etta, GNode *gnode) { - row = find_first_child_node_maybe_deleted(etta, row); + node_t *node = (node_t *)gnode->data; + int to_remove = node ? node->num_visible_children : 0; - while (row != -1 && path != etta->priv->map_table[row]) { - row = find_next_node_maybe_deleted(etta, row); + if (to_remove == 0) + return 0; + + while (gnode->children) { + GNode *next = gnode->children->next; + kill_gnode(gnode->children, etta); + gnode->children = next; } - return row; + return to_remove; } -static int -find_row_num(ETreeTableAdapter *etta, ETreePath path) +static void +delete_node(ETreeTableAdapter *etta, ETreePath parent, ETreePath path) { - int depth; - ETreePath *sequence; - int i; - int row; - - if (etta->priv->map_table == NULL) - return -1; - if (etta->priv->n_map == 0) - return -1; + int to_remove = 1; + int parent_row = get_row(etta, parent); + int row = get_row(etta, path); + GNode *gnode = lookup_gnode(etta, path); - if (path == NULL) - return -1; + e_table_model_pre_change(E_TABLE_MODEL(etta)); - if (etta->priv->last_access != -1) { - int end = MIN(etta->priv->n_map, etta->priv->last_access + 10); - int start = MAX(0, etta->priv->last_access - 10); - int initial = MAX (MIN (etta->priv->last_access, end), start); - for (i = initial; i < end; i++) { - if(etta->priv->map_table[i] == path) { - d(g_print("Found last access %d at row %d. (find_row_num)\n", etta->priv->last_access, i)); - return i; - } - } - for (i = initial - 1; i >= start; i--) { - if(etta->priv->map_table[i] == path) { - d(g_print("Found last access %d at row %d. (find_row_num)\n", etta->priv->last_access, i)); - return i; - } - } + if (row == -1) { + e_table_model_no_change(E_TABLE_MODEL(etta)); + return; } + to_remove += delete_children(etta, gnode); + kill_gnode(gnode, etta); - depth = e_tree_model_node_depth(etta->priv->source, path); - - sequence = g_new(ETreePath, depth + 1); - - sequence[0] = path; + move_map_elements(etta, row, row + to_remove, etta->priv->n_map - row - to_remove); + resize_map(etta, etta->priv->n_map - to_remove); - for (i = 0; i < depth; i++) { - sequence[i + 1] = e_tree_model_node_get_parent(etta->priv->source, sequence[i]); - - if (!e_tree_table_adapter_node_is_expanded (etta, sequence[i + 1])) { - g_free(sequence); - return -1; + if (parent_row != -1) { + node_t *parent_node = etta->priv->map_table[parent_row]; + GNode *parent_gnode = lookup_gnode(etta, parent); + gboolean expandable = e_tree_model_node_is_expandable(etta->priv->source, parent); + update_child_counts(parent_gnode, - to_remove); + if (parent_node->expandable != expandable) { + e_table_model_pre_change(E_TABLE_MODEL(etta)); + parent_node->expandable = expandable; + e_table_model_row_changed(E_TABLE_MODEL(etta), parent_row); } } - row = 0; - - for (i = depth; i >= 0; i --) { - while (row != -1 && row < etta->priv->n_map && sequence[i] != etta->priv->map_table[row]) { - row = find_next_node(etta, row); - } - if (row >= etta->priv->n_map) - break; - if (row == -1) - break; - if (i == 0) - break; - row = find_first_child_node(etta, row); - } - g_free (sequence); + e_table_model_rows_deleted(E_TABLE_MODEL(etta), row, to_remove); +} - if (row >= etta->priv->n_map) - row = -1; +static GNode * +create_gnode(ETreeTableAdapter *etta, ETreePath path) +{ + GNode *gnode; + node_t *node; + + node = g_new0(node_t, 1); + node->path = path; + node->index = -1; + node->expanded = e_tree_model_get_expanded_default(etta->priv->source); + node->expandable = e_tree_model_node_is_expandable(etta->priv->source, path); + node->expandable_set = 1; + node->num_visible_children = 0; + gnode = g_node_new(node); + g_hash_table_insert(etta->priv->nodes, path, gnode); + return gnode; +} - d(g_print("Didn't find last access %d. Setting to %d. (find_row_num)\n", etta->priv->last_access, row)); - etta->priv->last_access = row; - return row; +static gint +insert_children(ETreeTableAdapter *etta, GNode *gnode) +{ + ETreePath path, tmp; + int count = 0; + + path = ((node_t *)gnode->data)->path; + for (tmp = e_tree_model_node_get_first_child(etta->priv->source, path); + tmp; + tmp = e_tree_model_node_get_next(etta->priv->source, tmp)) { + GNode *child = create_gnode(etta, tmp); + node_t *node = (node_t *) child->data; + if (node->expanded) + node->num_visible_children = insert_children(etta, child); + g_node_append(gnode, child); + count += node->num_visible_children + 1; + } + return count; } -static int -array_size_from_path(ETreeTableAdapter *etta, ETreePath path) +static void +generate_tree(ETreeTableAdapter *etta, ETreePath path) { - int size = 1; + GNode *gnode; + node_t *node; + int size; - if (e_tree_table_adapter_node_is_expanded (etta, path)) { - ETreePath children; + e_table_model_pre_change(E_TABLE_MODEL(etta)); - for (children = e_tree_model_node_get_first_child(etta->priv->source, path); - children; - children = e_tree_model_node_get_next(etta->priv->source, children)) { - size += array_size_from_path(etta, children); - } - } + g_assert(e_tree_model_node_is_root(etta->priv->source, path)); + + if (etta->priv->root) + kill_gnode(etta->priv->root, etta); + + gnode = create_gnode(etta, path); + node = (node_t *) gnode->data; + node->expanded = TRUE; + node->num_visible_children = insert_children(etta, gnode); + if (etta->priv->sort_info && e_table_sort_info_sorting_get_count(etta->priv->sort_info) > 0) + resort_node(etta, gnode, TRUE); - return size; + etta->priv->root = gnode; + size = etta->priv->root_visible ? node->num_visible_children + 1 : node->num_visible_children; + resize_map(etta, size); + fill_map(etta, 0, gnode); + e_table_model_changed(E_TABLE_MODEL(etta)); } -static int -fill_array_from_path(ETreeTableAdapter *etta, ETreePath *array, ETreePath path) +static void +insert_node(ETreeTableAdapter *etta, ETreePath parent, ETreePath path) { - ETreeTableAdapterNode *node = NULL; - int index = 0; + GNode *gnode, *parent_gnode; + node_t *node, *parent_node; + gboolean expandable; + int size, row; - array[index] = path; + e_table_model_pre_change(E_TABLE_MODEL(etta)); - index ++; + if (get_node(etta, path)) { + e_table_model_no_change(E_TABLE_MODEL(etta)); + return; + } - node = find_node(etta, path); + parent_gnode = lookup_gnode(etta, parent); - if (e_tree_table_adapter_node_is_expanded (etta, path)) { - ETreePath children; + g_return_if_fail(parent_gnode != NULL); - if (!node) - node = find_or_create_node(etta, path); + parent_node = (node_t *) parent_gnode->data; + expandable = e_tree_model_node_is_expandable(etta->priv->source, parent); + if (parent_node->expandable != expandable) { + e_table_model_pre_change(E_TABLE_MODEL(etta)); + parent_node->expandable = expandable; + parent_node->expandable_set = 1; + e_table_model_row_changed(E_TABLE_MODEL(etta), parent_node->index); + } - for (children = e_tree_model_node_get_first_child(etta->priv->source, path); - children; - children = e_tree_model_node_get_next(etta->priv->source, children)) { - index += fill_array_from_path(etta, array + index, children); - } + if (!e_tree_table_adapter_node_is_expanded (etta, parent)) { + e_table_model_no_change(E_TABLE_MODEL(etta)); + return; } - if (node) - node->num_visible_children = index - 1; + gnode = create_gnode(etta, path); + node = (node_t *) gnode->data; - return index; + if (node->expanded) + node->num_visible_children = insert_children(etta, gnode); + + row = parent_node->index + parent_node->num_visible_children + 1; + g_node_append(parent_gnode, gnode); + update_child_counts(parent_gnode, node->num_visible_children + 1); + if (etta->priv->sort_info && e_table_sort_info_sorting_get_count(etta->priv->sort_info) > 0) + resort_node(etta, parent_gnode, TRUE); + size = node->num_visible_children + 1; + + resize_map(etta, etta->priv->n_map + size); + if (etta->priv->n_map > 0) + move_map_elements(etta, row + size, row, etta->priv->n_map - row - size); + fill_map(etta, row, gnode); + e_table_model_rows_inserted(E_TABLE_MODEL(etta), row, size); } static void -free_string (gpointer key, gpointer value, gpointer data) +update_node(ETreeTableAdapter *etta, ETreePath path) { - g_free(key); + ETreePath parent = e_tree_model_node_get_parent(etta->priv->source, path); + delete_node(etta, parent, path); + if (e_tree_model_node_is_root(etta->priv->source, path)) + generate_tree(etta, path); + else + insert_node(etta, parent, path); +} + +static void +etta_finalize (GObject *object) +{ + ETreeTableAdapter *etta = E_TREE_TABLE_ADAPTER (object); + + if (etta->priv->root) { + kill_gnode(etta->priv->root, etta); + etta->priv->root = NULL; + } + + g_hash_table_destroy (etta->priv->nodes); + + g_free (etta->priv->map_table); + + g_free (etta->priv); + + G_OBJECT_CLASS (parent_class)->finalize (object); } static void @@ -403,57 +452,43 @@ etta_dispose (GObject *object) { ETreeTableAdapter *etta = E_TREE_TABLE_ADAPTER (object); - if (etta->priv->source) { - if (e_tree_model_has_save_id(etta->priv->source)) - g_hash_table_foreach(etta->priv->attributes, free_string, NULL); + if (etta->priv->sort_info) { + g_signal_handler_disconnect(G_OBJECT (etta->priv->sort_info), + etta->priv->sort_info_changed_id); + g_object_unref(etta->priv->sort_info); + etta->priv->sort_info = NULL; + } + if (etta->priv->header) { + g_object_unref(etta->priv->header); + etta->priv->header = NULL; + } + + if (etta->priv->source) { g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_pre_change_id); + etta->priv->pre_change_id); g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_no_change_id); + etta->priv->no_change_id); g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_node_changed_id); + etta->priv->node_changed_id); g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_node_data_changed_id); + etta->priv->node_data_changed_id); g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_node_col_changed_id); + etta->priv->node_col_changed_id); g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_node_inserted_id); + etta->priv->node_inserted_id); g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_node_removed_id); + etta->priv->node_removed_id); g_signal_handler_disconnect (G_OBJECT (etta->priv->source), - etta->priv->tree_model_node_request_collapse_id); + etta->priv->node_request_collapse_id); g_object_unref (etta->priv->source); etta->priv->source = NULL; - - etta->priv->tree_model_pre_change_id = 0; - etta->priv->tree_model_no_change_id = 0; - etta->priv->tree_model_node_changed_id = 0; - etta->priv->tree_model_node_data_changed_id = 0; - etta->priv->tree_model_node_col_changed_id = 0; - etta->priv->tree_model_node_inserted_id = 0; - etta->priv->tree_model_node_removed_id = 0; - etta->priv->tree_model_node_request_collapse_id = 0; } G_OBJECT_CLASS (parent_class)->dispose (object); } -static void -etta_finalize (GObject *object) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) object; - - g_hash_table_destroy (etta->priv->attributes); - g_free (etta->priv->map_table); - - g_free (etta->priv); - etta->priv = NULL; - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - static int etta_column_count (ETableModel *etm) { @@ -475,10 +510,7 @@ etta_get_save_id (ETableModel *etm, int row) { ETreeTableAdapter *etta = (ETreeTableAdapter *)etm; - if (etta->priv->root_visible) - return e_tree_model_get_save_id (etta->priv->source, etta->priv->map_table [row]); - else - return e_tree_model_get_save_id (etta->priv->source, etta->priv->map_table [row + 1]); + return e_tree_model_get_save_id (etta->priv->source, get_path(etta, row)); } static gboolean @@ -495,14 +527,7 @@ etta_row_count (ETableModel *etm) { ETreeTableAdapter *etta = (ETreeTableAdapter *)etm; - if (etta->priv->root_visible) - return etta->priv->n_map; - else { - if (etta->priv->n_map > 0) - return etta->priv->n_map - 1; - else - return 0; - } + return etta->priv->n_map; } static void * @@ -512,19 +537,15 @@ etta_value_at (ETableModel *etm, int col, int row) switch (col) { case -1: - if (etta->priv->root_visible) - return etta->priv->map_table [row]; - else - return etta->priv->map_table [row + 1]; + if (row == -1) + return NULL; + return get_path (etta, row); case -2: return etta->priv->source; case -3: return etta; default: - if (etta->priv->root_visible) - return e_tree_model_value_at (etta->priv->source, etta->priv->map_table [row], col); - else - return e_tree_model_value_at (etta->priv->source, etta->priv->map_table [row + 1], col); + return e_tree_model_value_at (etta->priv->source, get_path (etta, row), col); } } @@ -533,12 +554,7 @@ etta_set_value_at (ETableModel *etm, int col, int row, const void *val) { ETreeTableAdapter *etta = (ETreeTableAdapter *)etm; - etta->priv->last_access = row; - d(g_print("h) Setting last_access to %d\n", row)); - if (etta->priv->root_visible) - e_tree_model_set_value_at (etta->priv->source, etta->priv->map_table [row], col, val); - else - e_tree_model_set_value_at (etta->priv->source, etta->priv->map_table [row + 1], col, val); + e_tree_model_set_value_at (etta->priv->source, get_path (etta, row), col, val); } static gboolean @@ -546,19 +562,12 @@ etta_is_cell_editable (ETableModel *etm, int col, int row) { ETreeTableAdapter *etta = (ETreeTableAdapter *)etm; - if (etta->priv->root_visible) - return e_tree_model_node_is_editable (etta->priv->source, etta->priv->map_table [row], col); - else - return e_tree_model_node_is_editable (etta->priv->source, etta->priv->map_table [row + 1], col); + return e_tree_model_node_is_editable (etta->priv->source, get_path (etta, row), col); } static void etta_append_row (ETableModel *etm, ETableModel *source, int row) { -#if 0 - ETreeTableAdapter *etta = (ETreeTableAdapter *)etm; - e_table_model_append_row (etta->priv->source, source, row); -#endif } static void * @@ -634,30 +643,31 @@ etta_class_init (ETreeTableAdapterClass *klass) static void etta_init (ETreeTableAdapter *etta) { - etta->priv = g_new(ETreeTableAdapterPriv, 1); - - etta->priv->source = NULL; - - etta->priv->n_map = 0; - etta->priv->n_vals_allocated = 0; - etta->priv->map_table = NULL; - etta->priv->attributes = NULL; - - etta->priv->root_visible = TRUE; - - etta->priv->last_access = 0; - - etta->priv->tree_model_pre_change_id = 0; - etta->priv->tree_model_no_change_id = 0; - etta->priv->tree_model_node_changed_id = 0; - etta->priv->tree_model_node_data_changed_id = 0; - etta->priv->tree_model_node_col_changed_id = 0; - etta->priv->tree_model_node_inserted_id = 0; - etta->priv->tree_model_node_removed_id = 0; - etta->priv->tree_model_node_request_collapse_id = 0; + etta->priv = g_new(ETreeTableAdapterPriv, 1); + + etta->priv->source = NULL; + etta->priv->sort_info = NULL; + + etta->priv->n_map = 0; + etta->priv->n_vals_allocated = 0; + etta->priv->map_table = NULL; + etta->priv->nodes = NULL; + etta->priv->root = NULL; + + etta->priv->root_visible = TRUE; + etta->priv->remap_needed = TRUE; + + etta->priv->pre_change_id = 0; + etta->priv->no_change_id = 0; + etta->priv->node_changed_id = 0; + etta->priv->node_data_changed_id = 0; + etta->priv->node_col_changed_id = 0; + etta->priv->node_inserted_id = 0; + etta->priv->node_removed_id = 0; + etta->priv->node_request_collapse_id = 0; } -E_MAKE_TYPE(e_tree_table_adapter, "ETreeTableAdapter", ETreeTableAdapter, etta_class_init, etta_init, E_TABLE_MODEL_TYPE) +E_MAKE_TYPE(e_tree_table_adapter, "ETreeTableAdapter", ETreeTableAdapter, etta_class_init, etta_init, PARENT_TYPE) static void etta_proxy_pre_change (ETreeModel *etm, ETreeTableAdapter *etta) @@ -674,40 +684,7 @@ etta_proxy_no_change (ETreeModel *etm, ETreeTableAdapter *etta) static void etta_proxy_node_changed (ETreeModel *etm, ETreePath path, ETreeTableAdapter *etta) { - if (e_tree_model_node_is_root(etm, path)) { - int size; - - size = array_size_from_path(etta, path); - etta_expand_to(etta, size); - etta->priv->n_map = size; - fill_array_from_path(etta, etta->priv->map_table, path); - } else { - int row = find_row_num(etta, path); - int size; - int old_size; - ETreeTableAdapterNode *node; - - if (row == -1) { - e_table_model_no_change(E_TABLE_MODEL(etta)); - return; - } - - size = array_size_from_path(etta, path); - - node = find_node(etta, path); - if (node) - old_size = node->num_visible_children + 1; - else - old_size = 1; - - etta_expand_to(etta, etta->priv->n_map + size - old_size); - - memmove(etta->priv->map_table + row + size, - etta->priv->map_table + row + old_size, - (etta->priv->n_map - row - old_size) * sizeof (ETreePath)); - fill_array_from_path(etta, etta->priv->map_table + row, path); - etta_update_parent_child_counts(etta, path, size - old_size); - } + update_node(etta, path); e_table_model_changed(E_TABLE_MODEL(etta)); } @@ -715,145 +692,38 @@ etta_proxy_node_changed (ETreeModel *etm, ETreePath path, ETreeTableAdapter *ett static void etta_proxy_node_data_changed (ETreeModel *etm, ETreePath path, ETreeTableAdapter *etta) { - int row = find_row_num(etta, path); - if (row != -1) { - if (etta->priv->root_visible) - e_table_model_row_changed(E_TABLE_MODEL(etta), row); - else if (row != 0) - e_table_model_row_changed(E_TABLE_MODEL(etta), row - 1); - else - e_table_model_no_change(E_TABLE_MODEL(etta)); - } else + int row = get_row(etta, path); + + if (row == -1) e_table_model_no_change(E_TABLE_MODEL(etta)); + + e_table_model_row_changed(E_TABLE_MODEL(etta), row); } static void etta_proxy_node_col_changed (ETreeModel *etm, ETreePath path, int col, ETreeTableAdapter *etta) { - int row = find_row_num(etta, path); - if (row != -1) { - if (etta->priv->root_visible) - e_table_model_cell_changed(E_TABLE_MODEL(etta), col, row); - else if (row != 0) - e_table_model_cell_changed(E_TABLE_MODEL(etta), col, row - 1); - else - e_table_model_no_change(E_TABLE_MODEL(etta)); - } else + int row = get_row(etta, path); + + if (row == -1) e_table_model_no_change(E_TABLE_MODEL(etta)); + + e_table_model_cell_changed(E_TABLE_MODEL(etta), col, row); } static void etta_proxy_node_inserted (ETreeModel *etm, ETreePath parent, ETreePath child, ETreeTableAdapter *etta) { - int row; - - if (e_tree_model_node_is_root(etm, child)) { - row = 0; - } else { - ETreePath children; - int parent_row; - ETreeTableAdapterNode *parent_node; - - parent_row = find_row_num(etta, parent); - if (parent_row == -1) { - e_table_model_no_change(E_TABLE_MODEL(etta)); - return; - } - - parent_node = find_or_create_node(etta, parent); - if (parent_node->expandable != e_tree_model_node_is_expandable(etta->priv->source, parent)) { - e_table_model_pre_change(E_TABLE_MODEL(etta)); - parent_node->expandable = e_tree_model_node_is_expandable(etta->priv->source, parent); - parent_node->expandable_set = 1; - if (etta->priv->root_visible) - e_table_model_row_changed(E_TABLE_MODEL(etta), parent_row); - else if (parent_row != 0) - e_table_model_row_changed(E_TABLE_MODEL(etta), parent_row - 1); - else - e_table_model_no_change(E_TABLE_MODEL(etta)); - } - - if (!e_tree_table_adapter_node_is_expanded (etta, parent)) { - e_table_model_no_change(E_TABLE_MODEL(etta)); - return; - } - - row = find_first_child_node(etta, parent_row); - children = e_tree_model_node_get_first_child(etta->priv->source, parent); - - while (row != -1 && - row <= parent_row + parent_node->num_visible_children && - children != NULL && - children == etta->priv->map_table[row]) { - children = e_tree_model_node_get_next(etta->priv->source, children); - row = find_next_node(etta, row); - } - } - - if (row != -1) { - int size; - - size = array_size_from_path(etta, child); - - etta_expand_to(etta, etta->priv->n_map + size); - - memmove(etta->priv->map_table + row + size, - etta->priv->map_table + row, - (etta->priv->n_map - row) * sizeof (ETreePath)); - - fill_array_from_path(etta, etta->priv->map_table + row, child); - etta_update_parent_child_counts(etta, child, size); - - if (etta->priv->root_visible) - e_table_model_rows_inserted(E_TABLE_MODEL(etta), row, size); - else if (row != 0) - e_table_model_rows_inserted(E_TABLE_MODEL(etta), row - 1, size); - else - e_table_model_rows_inserted(E_TABLE_MODEL(etta), 0, size - 1); - } else - e_table_model_no_change(E_TABLE_MODEL(etta)); + if (e_tree_model_node_is_root(etm, child)) + generate_tree(etta, child); + else + insert_node(etta, parent, child); } static void etta_proxy_node_removed (ETreeModel *etm, ETreePath parent, ETreePath child, int old_position, ETreeTableAdapter *etta) { - int parent_row = find_row_num(etta, parent); - int row = find_child_row_num_maybe_deleted(etta, parent_row, child); - ETreeTableAdapterNode *parent_node = find_node(etta, parent); - if (parent_row != -1 && parent_node) { - if (parent_node->expandable != e_tree_model_node_is_expandable(etta->priv->source, parent)) { - e_table_model_pre_change(E_TABLE_MODEL(etta)); - parent_node->expandable = e_tree_model_node_is_expandable(etta->priv->source, parent); - if (etta->priv->root_visible) - e_table_model_row_changed(E_TABLE_MODEL(etta), parent_row); - else if (parent_row != 0) - e_table_model_row_changed(E_TABLE_MODEL(etta), parent_row - 1); - else - e_table_model_no_change(E_TABLE_MODEL(etta)); - } - } - - if (row != -1) { - ETreeTableAdapterNode *node = find_node(etta, child); - int to_remove = (node ? node->num_visible_children : 0) + 1; - - memmove(etta->priv->map_table + row, - etta->priv->map_table + row + to_remove, - (etta->priv->n_map - row - to_remove) * sizeof (ETreePath)); - - if (parent_node) - parent_node->num_visible_children -= to_remove; - if (parent) - etta_update_parent_child_counts(etta, parent, - to_remove); - - if (etta->priv->root_visible) - e_table_model_rows_deleted(E_TABLE_MODEL(etta), row, to_remove); - else if (row != 0) - e_table_model_rows_deleted(E_TABLE_MODEL(etta), row - 1, to_remove); - else - e_table_model_rows_deleted(E_TABLE_MODEL(etta), 0, to_remove - 1); - } else - e_table_model_no_change(E_TABLE_MODEL(etta)); + delete_node(etta, parent, child); } static void @@ -862,154 +732,174 @@ etta_proxy_node_request_collapse (ETreeModel *etm, ETreePath node, ETreeTableAda e_tree_table_adapter_node_set_expanded(etta, node, FALSE); } +static void +etta_sort_info_changed (ETableSortInfo *sort_info, ETreeTableAdapter *etta) +{ + e_table_model_pre_change(E_TABLE_MODEL(etta)); + resort_node(etta, etta->priv->root, TRUE); + fill_map(etta, 0, etta->priv->root); + e_table_model_changed(E_TABLE_MODEL(etta)); +} + ETableModel * -e_tree_table_adapter_construct (ETreeTableAdapter *etta, ETreeModel *source) +e_tree_table_adapter_construct (ETreeTableAdapter *etta, ETreeModel *source, ETableSortInfo *sort_info, ETableHeader *header) { ETreePath root; etta->priv->source = source; g_object_ref (source); - if (e_tree_model_has_save_id(source)) - etta->priv->attributes = g_hash_table_new(g_str_hash, g_str_equal); - else - etta->priv->attributes = g_hash_table_new(NULL, NULL); + etta->priv->sort_info = sort_info; + if (sort_info) { + g_object_ref(sort_info); + etta->priv->sort_info_changed_id = g_signal_connect (G_OBJECT (sort_info), "sort_info_changed", + G_CALLBACK (etta_sort_info_changed), etta); + } - root = e_tree_model_get_root (source); + etta->priv->header = header; + if (header) + g_object_ref(header); - if (root) { - etta->priv->n_map = array_size_from_path(etta, root); - etta->priv->n_vals_allocated = etta->priv->n_map; - etta->priv->map_table = g_new(ETreePath, etta->priv->n_map); - fill_array_from_path(etta, etta->priv->map_table, root); - } + etta->priv->nodes = g_hash_table_new(NULL, NULL); - etta->priv->tree_model_pre_change_id = g_signal_connect (G_OBJECT (source), "pre_change", - G_CALLBACK (etta_proxy_pre_change), etta); - etta->priv->tree_model_no_change_id = g_signal_connect (G_OBJECT (source), "no_change", - G_CALLBACK (etta_proxy_no_change), etta); - etta->priv->tree_model_node_changed_id = g_signal_connect (G_OBJECT (source), "node_changed", - G_CALLBACK (etta_proxy_node_changed), etta); - etta->priv->tree_model_node_data_changed_id = g_signal_connect (G_OBJECT (source), "node_data_changed", - G_CALLBACK (etta_proxy_node_data_changed), etta); - etta->priv->tree_model_node_col_changed_id = g_signal_connect (G_OBJECT (source), "node_col_changed", - G_CALLBACK (etta_proxy_node_col_changed), etta); - etta->priv->tree_model_node_inserted_id = g_signal_connect (G_OBJECT (source), "node_inserted", - G_CALLBACK (etta_proxy_node_inserted), etta); - etta->priv->tree_model_node_removed_id = g_signal_connect (G_OBJECT (source), "node_removed", - G_CALLBACK (etta_proxy_node_removed), etta); - etta->priv->tree_model_node_request_collapse_id = g_signal_connect (G_OBJECT (source), "node_request_collapse", - G_CALLBACK (etta_proxy_node_request_collapse), etta); + root = e_tree_model_get_root (source); + + if (root) + generate_tree(etta, root); + + etta->priv->pre_change_id = g_signal_connect(G_OBJECT(source), "pre_change", + G_CALLBACK (etta_proxy_pre_change), etta); + etta->priv->no_change_id = g_signal_connect (G_OBJECT (source), "no_change", + G_CALLBACK (etta_proxy_no_change), etta); + etta->priv->node_changed_id = g_signal_connect (G_OBJECT (source), "node_changed", + G_CALLBACK (etta_proxy_node_changed), etta); + etta->priv->node_data_changed_id = g_signal_connect (G_OBJECT (source), "node_data_changed", + G_CALLBACK (etta_proxy_node_data_changed), etta); + etta->priv->node_col_changed_id = g_signal_connect (G_OBJECT (source), "node_col_changed", + G_CALLBACK (etta_proxy_node_col_changed), etta); + etta->priv->node_inserted_id = g_signal_connect (G_OBJECT (source), "node_inserted", + G_CALLBACK (etta_proxy_node_inserted), etta); + etta->priv->node_removed_id = g_signal_connect (G_OBJECT (source), "node_removed", + G_CALLBACK (etta_proxy_node_removed), etta); + etta->priv->node_request_collapse_id = g_signal_connect (G_OBJECT (source), "node_request_collapse", + G_CALLBACK (etta_proxy_node_request_collapse), etta); return E_TABLE_MODEL (etta); } ETableModel * -e_tree_table_adapter_new (ETreeModel *source) +e_tree_table_adapter_new (ETreeModel *source, ETableSortInfo *sort_info, ETableHeader *header) { ETreeTableAdapter *etta = g_object_new (E_TREE_TABLE_ADAPTER_TYPE, NULL); - e_tree_table_adapter_construct (etta, source); + e_tree_table_adapter_construct (etta, source, sort_info, header); return (ETableModel *) etta; } typedef struct { xmlNode *root; - ETreeModel *tree; + gboolean expanded_default; + ETreeModel *model; } TreeAndRoot; static void save_expanded_state_func (gpointer keyp, gpointer value, gpointer data) { - gchar *key = keyp; - ETreeTableAdapterNode *node = value; + ETreePath path = keyp; + node_t *node = ((GNode *)value)->data; TreeAndRoot *tar = data; - xmlNode *root = tar->root; - ETreeModel *etm = tar->tree; xmlNode *xmlnode; - if (node->expanded != e_tree_model_get_expanded_default(etm)) { - xmlnode = xmlNewChild (root, NULL, "node", NULL); - e_xml_set_string_prop_by_name(xmlnode, "id", key); + if (node->expanded != tar->expanded_default) { + gchar *save_id = e_tree_model_get_save_id(tar->model, path); + xmlnode = xmlNewChild (tar->root, NULL, "node", NULL); + e_xml_set_string_prop_by_name(xmlnode, "id", save_id); + g_free(save_id); } } void e_tree_table_adapter_save_expanded_state (ETreeTableAdapter *etta, const char *filename) { - ETreeTableAdapterPriv *priv; TreeAndRoot tar; xmlDocPtr doc; xmlNode *root; g_return_if_fail(etta != NULL); - priv = etta->priv; - doc = xmlNewDoc ("1.0"); - root = xmlNewDocNode (doc, NULL, - (xmlChar *) "expanded_state", - NULL); + root = xmlNewDocNode (doc, NULL, (xmlChar *) "expanded_state", NULL); xmlDocSetRootElement (doc, root); - e_xml_set_integer_prop_by_name (root, "vers", 2); - e_xml_set_bool_prop_by_name (root, "default", e_tree_model_get_expanded_default (priv->source)); - + tar.model = etta->priv->source; tar.root = root; - tar.tree = etta->priv->source; + tar.expanded_default = e_tree_model_get_expanded_default(etta->priv->source); - g_hash_table_foreach (priv->attributes, - save_expanded_state_func, - &tar); + e_xml_set_integer_prop_by_name (root, "vers", 2); + e_xml_set_bool_prop_by_name (root, "default", tar.expanded_default); + + g_hash_table_foreach (etta->priv->nodes, save_expanded_state_func, &tar); e_xml_save_file (filename, doc); - xmlFreeDoc (doc); } -void -e_tree_table_adapter_load_expanded_state (ETreeTableAdapter *etta, const char *filename) +static xmlDoc * +open_file (ETreeTableAdapter *etta, const char *filename) { - ETreeTableAdapterPriv *priv; xmlDoc *doc; xmlNode *root; - xmlNode *child; int vers; gboolean model_default, saved_default; - int size; - ETreePath path; - - g_return_if_fail(etta != NULL); - - priv = etta->priv; doc = xmlParseFile (filename); if (!doc) - return; + return NULL; root = xmlDocGetRootElement (doc); if (root == NULL || strcmp (root->name, "expanded_state")) { xmlFreeDoc (doc); - return; + return NULL; } vers = e_xml_get_integer_prop_by_name_with_default (root, "vers", 0); if (vers > 2) { xmlFreeDoc (doc); - return; + return NULL; } - model_default = e_tree_model_get_expanded_default (priv->source); + model_default = e_tree_model_get_expanded_default (etta->priv->source); saved_default = e_xml_get_bool_prop_by_name_with_default (root, "default", !model_default); if (saved_default != model_default) { xmlFreeDoc (doc); - return; + return NULL; } + return doc; +} + +void +e_tree_table_adapter_load_expanded_state (ETreeTableAdapter *etta, const char *filename) +{ + xmlDoc *doc; + xmlNode *root, *child; + gboolean model_default; + + g_return_if_fail(etta != NULL); + + doc = open_file(etta, filename); + if (!doc) + return; + + root = xmlDocGetRootElement (doc); + e_table_model_pre_change(E_TABLE_MODEL(etta)); + model_default = e_tree_model_get_expanded_default(etta->priv->source); + for (child = root->xmlChildrenNode; child; child = child->next) { char *id; + ETreePath path; if (strcmp (child->name, "node")) { d(g_warning ("unknown node '%s' in %s", child->name, filename)); @@ -1023,23 +913,22 @@ e_tree_table_adapter_load_expanded_state (ETreeTableAdapter *etta, const char *f continue; } - add_expanded_node(etta, id, !model_default); + path = e_tree_model_get_node_by_id(etta->priv->source, id); + e_tree_table_adapter_node_set_expanded(etta, path, !model_default); } - xmlFreeDoc (doc); - path = e_tree_model_get_root (etta->priv->source); - size = array_size_from_path(etta, path); - etta_expand_to(etta, size); - etta->priv->n_map = size; - fill_array_from_path(etta, etta->priv->map_table, path); + update_node(etta, e_tree_model_get_root (etta->priv->source)); e_table_model_changed (E_TABLE_MODEL (etta)); } -void e_tree_table_adapter_root_node_set_visible (ETreeTableAdapter *etta, gboolean visible) +void +e_tree_table_adapter_root_node_set_visible (ETreeTableAdapter *etta, gboolean visible) { + int size; + if (etta->priv->root_visible == visible) return; @@ -1051,71 +940,68 @@ void e_tree_table_adapter_root_node_set_visible (ETreeTableAdapter *etta if (root) e_tree_table_adapter_node_set_expanded(etta, root, TRUE); } + size = (visible ? 1 : 0) + (etta->priv->root ? ((node_t *)etta->priv->root->data)->num_visible_children : 0); + resize_map(etta, size); + if (etta->priv->root) + fill_map(etta, 0, etta->priv->root); e_table_model_changed(E_TABLE_MODEL(etta)); } -void e_tree_table_adapter_node_set_expanded (ETreeTableAdapter *etta, ETreePath path, gboolean expanded) +void +e_tree_table_adapter_node_set_expanded (ETreeTableAdapter *etta, ETreePath path, gboolean expanded) { - ETreeTableAdapterNode *node; + GNode *gnode = lookup_gnode(etta, path); + node_t *node; int row; if (!expanded && e_tree_model_node_is_root (etta->priv->source, path) && !etta->priv->root_visible) return; - node = find_or_create_node(etta, path); + g_return_if_fail(gnode != NULL); + + node = (node_t *) gnode->data; if (expanded == node->expanded) return; node->expanded = expanded; - row = find_row_num(etta, path); - if (row != -1) { - e_table_model_pre_change (E_TABLE_MODEL(etta)); - - if (etta->priv->root_visible) { - e_table_model_pre_change (E_TABLE_MODEL(etta)); - e_table_model_row_changed(E_TABLE_MODEL(etta), row); - } else if (row != 0) { - e_table_model_pre_change (E_TABLE_MODEL(etta)); - e_table_model_row_changed(E_TABLE_MODEL(etta), row - 1); - } + row = get_row(etta, path); + if (row == -1) + return; - if (expanded) { - int num_children = array_size_from_path(etta, path) - 1; - etta_expand_to(etta, etta->priv->n_map + num_children); - memmove(etta->priv->map_table + row + 1 + num_children, - etta->priv->map_table + row + 1, - (etta->priv->n_map - row - 1) * sizeof (ETreePath)); - fill_array_from_path(etta, etta->priv->map_table + row, path); - etta_update_parent_child_counts(etta, path, num_children); - if (num_children != 0) { - if (etta->priv->root_visible) - e_table_model_rows_inserted(E_TABLE_MODEL(etta), row + 1, num_children); - else - e_table_model_rows_inserted(E_TABLE_MODEL(etta), row, num_children); - } else - e_table_model_no_change(E_TABLE_MODEL(etta)); - } else { - int num_children = node->num_visible_children; - g_assert (etta->priv->n_map >= row + 1 + num_children); - memmove(etta->priv->map_table + row + 1, - etta->priv->map_table + row + 1 + num_children, - (etta->priv->n_map - row - 1 - num_children) * sizeof (ETreePath)); - node->num_visible_children = 0; - etta_update_parent_child_counts(etta, path, - num_children); - if (num_children != 0) { - if (etta->priv->root_visible) - e_table_model_rows_deleted(E_TABLE_MODEL(etta), row + 1, num_children); - else - e_table_model_rows_deleted(E_TABLE_MODEL(etta), row, num_children); - } else - e_table_model_no_change(E_TABLE_MODEL(etta)); + e_table_model_pre_change (E_TABLE_MODEL(etta)); + e_table_model_pre_change (E_TABLE_MODEL(etta)); + e_table_model_row_changed(E_TABLE_MODEL(etta), row); + + + if (expanded) { + int num_children = insert_children(etta, gnode); + update_child_counts(gnode, num_children); + if (etta->priv->sort_info && e_table_sort_info_sorting_get_count(etta->priv->sort_info) > 0) + resort_node(etta, gnode, TRUE); + resize_map(etta, etta->priv->n_map + num_children); + move_map_elements(etta, row + 1 + num_children, row + 1, etta->priv->n_map - row - 1 - num_children); + fill_map(etta, row, gnode); + if (num_children != 0) { + e_table_model_rows_inserted(E_TABLE_MODEL(etta), row + 1, num_children); + } else + e_table_model_no_change(E_TABLE_MODEL(etta)); + } else { + int num_children = delete_children(etta, gnode); + if (num_children == 0) { + e_table_model_no_change(E_TABLE_MODEL(etta)); + return; } + move_map_elements(etta, row + 1, row + 1 + num_children, etta->priv->n_map - row - 1 - num_children); + update_child_counts(gnode, - num_children); + resize_map(etta, etta->priv->n_map - num_children); + e_table_model_rows_deleted(E_TABLE_MODEL(etta), row + 1, num_children); } } -void e_tree_table_adapter_node_set_expanded_recurse (ETreeTableAdapter *etta, ETreePath path, gboolean expanded) +void +e_tree_table_adapter_node_set_expanded_recurse (ETreeTableAdapter *etta, ETreePath path, gboolean expanded) { ETreePath children; @@ -1128,39 +1014,26 @@ void e_tree_table_adapter_node_set_expanded_recurse (ETreeTableAdapter * } } -ETreePath e_tree_table_adapter_node_at_row (ETreeTableAdapter *etta, int row) +ETreePath +e_tree_table_adapter_node_at_row (ETreeTableAdapter *etta, int row) { - if (row < 0) - return NULL; - if (etta->priv->root_visible) { - if (row < etta->priv->n_map) - return etta->priv->map_table[row]; - } else { - if (row + 1 < etta->priv->n_map) - return etta->priv->map_table[row + 1]; - } - return NULL; + return get_path(etta, row); } -int e_tree_table_adapter_row_of_node (ETreeTableAdapter *etta, ETreePath path) +int +e_tree_table_adapter_row_of_node (ETreeTableAdapter *etta, ETreePath path) { - if (etta->priv->root_visible) - return find_row_num(etta, path); - else { - int row_num = find_row_num (etta, path); - if (row_num != -1) - return row_num - 1; - else - return row_num; - } + return get_row(etta, path); } -gboolean e_tree_table_adapter_root_node_is_visible(ETreeTableAdapter *etta) +gboolean +e_tree_table_adapter_root_node_is_visible(ETreeTableAdapter *etta) { return etta->priv->root_visible; } -void e_tree_table_adapter_show_node (ETreeTableAdapter *etta, ETreePath path) +void +e_tree_table_adapter_show_node (ETreeTableAdapter *etta, ETreePath path) { ETreePath parent; @@ -1172,10 +1045,32 @@ void e_tree_table_adapter_show_node (ETreeTableAdapter *etta, ETreePath } } -gboolean e_tree_table_adapter_node_is_expanded (ETreeTableAdapter *etta, ETreePath path) +gboolean +e_tree_table_adapter_node_is_expanded (ETreeTableAdapter *etta, ETreePath path) { if (!e_tree_model_node_is_expandable (etta->priv->source, path)) return FALSE; - return e_tree_table_adapter_node_would_be_expanded (etta, path); + return get_node(etta, path)->expanded; +} + +void +e_tree_table_adapter_set_sort_info (ETreeTableAdapter *etta, ETableSortInfo *sort_info) +{ + if (etta->priv->sort_info) { + g_signal_handler_disconnect(G_OBJECT(etta->priv->sort_info), + etta->priv->sort_info_changed_id); + g_object_unref(etta->priv->sort_info); + } + + etta->priv->sort_info = sort_info; + if (sort_info) { + g_object_ref(sort_info); + etta->priv->sort_info_changed_id = g_signal_connect(G_OBJECT(sort_info), "sort_info_changed", + G_CALLBACK(etta_sort_info_changed), etta); + } + e_table_model_pre_change(E_TABLE_MODEL(etta)); + resort_node(etta, etta->priv->root, TRUE); + fill_map(etta, 0, etta->priv->root); + e_table_model_changed(E_TABLE_MODEL(etta)); } diff --git a/widgets/table/e-tree-table-adapter.h b/widgets/table/e-tree-table-adapter.h index 72ea66694a..a856489a40 100644 --- a/widgets/table/e-tree-table-adapter.h +++ b/widgets/table/e-tree-table-adapter.h @@ -28,6 +28,8 @@ #include <glib-object.h> #include <gal/e-table/e-table-model.h> #include <gal/e-table/e-tree-model.h> +#include <gal/e-table/e-table-sort-info.h> +#include <gal/e-table/e-table-header.h> G_BEGIN_DECLS @@ -51,9 +53,13 @@ typedef struct { } ETreeTableAdapterClass; GType e_tree_table_adapter_get_type (void); -ETableModel *e_tree_table_adapter_new (ETreeModel *source); +ETableModel *e_tree_table_adapter_new (ETreeModel *source, + ETableSortInfo *sort_info, + ETableHeader *header); ETableModel *e_tree_table_adapter_construct (ETreeTableAdapter *ets, - ETreeModel *source); + ETreeModel *source, + ETableSortInfo *sort_info, + ETableHeader *header); gboolean e_tree_table_adapter_node_is_expanded (ETreeTableAdapter *etta, ETreePath path); @@ -79,6 +85,9 @@ void e_tree_table_adapter_save_expanded_state (ETreeTableAdapter void e_tree_table_adapter_load_expanded_state (ETreeTableAdapter *etta, const char *filename); +void e_tree_table_adapter_set_sort_info (ETreeTableAdapter *etta, + ETableSortInfo *sort_info); + G_END_DECLS #endif /* _E_TREE_TABLE_ADAPTER_H_ */ diff --git a/widgets/table/e-tree.c b/widgets/table/e-tree.c index 2456c373ec..06effbf90a 100644 --- a/widgets/table/e-tree.c +++ b/widgets/table/e-tree.c @@ -49,7 +49,6 @@ #include <gal/e-table/e-table-selection-model.h> #endif -#include <gal/e-table/e-tree-sorted.h> #include <gal/e-table/e-tree-table-adapter.h> #include "e-tree.h" @@ -114,7 +113,6 @@ enum { struct ETreePriv { ETreeModel *model; - ETreeSorted *sorted; ETreeTableAdapter *etta; ETableHeader *full_header, *header; @@ -406,7 +404,6 @@ et_dispose (GObject *object) g_object_unref (et->priv->etta); g_object_unref (et->priv->model); - g_object_unref (et->priv->sorted); g_object_unref (et->priv->full_header); disconnect_header (et); g_object_unref (et->priv->selection); @@ -477,21 +474,20 @@ et_search_search (ETableSearch *search, char *string, ETableSearchFlags flags, E cb_data.string = string; cursor = e_tree_get_cursor (et); - cursor = e_tree_sorted_model_to_view_path (et->priv->sorted, cursor); if (flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST) { const void *value; - value = e_tree_model_value_at (E_TREE_MODEL (et->priv->sorted), cursor, col->col_idx); + value = e_tree_model_value_at (et->priv->model, cursor, col->col_idx); if (col->search (value, string)) { return TRUE; } } - found = e_tree_model_node_find (E_TREE_MODEL (et->priv->sorted), cursor, NULL, E_TREE_FIND_NEXT_FORWARD, search_search_callback, &cb_data); + found = e_tree_model_node_find (et->priv->model, cursor, NULL, E_TREE_FIND_NEXT_FORWARD, search_search_callback, &cb_data); if (found == NULL) - found = e_tree_model_node_find (E_TREE_MODEL (et->priv->sorted), NULL, cursor, E_TREE_FIND_NEXT_FORWARD, search_search_callback, &cb_data); + found = e_tree_model_node_find (et->priv->model, NULL, cursor, E_TREE_FIND_NEXT_FORWARD, search_search_callback, &cb_data); if (found && found != cursor) { int model_row; @@ -499,14 +495,14 @@ et_search_search (ETableSearch *search, char *string, ETableSearchFlags flags, E e_tree_table_adapter_show_node (et->priv->etta, found); model_row = e_tree_table_adapter_row_of_node (et->priv->etta, found); - cursor = e_tree_sorted_view_to_model_path (et->priv->sorted, found); + cursor = found; e_selection_model_select_as_key_press(E_SELECTION_MODEL (et->priv->selection), model_row, col->col_idx, GDK_CONTROL_MASK); return TRUE; } else if (!(flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST)) { const void *value; - value = e_tree_model_value_at (E_TREE_MODEL (et->priv->sorted), cursor, col->col_idx); + value = e_tree_model_value_at (et->priv->model, cursor, col->col_idx); return col->search (value, string); } else @@ -541,7 +537,6 @@ e_tree_init (GtkObject *object) e_tree->priv = g_new(ETreePriv, 1); e_tree->priv->model = NULL; - e_tree->priv->sorted = NULL; e_tree->priv->etta = NULL; e_tree->priv->full_header = NULL; @@ -784,7 +779,6 @@ static void item_cursor_change (ETableItem *eti, int row, ETree *et) { ETreePath path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [CURSOR_CHANGE], 0, row, path); @@ -794,8 +788,6 @@ static void item_cursor_activated (ETableItem *eti, int row, ETree *et) { ETreePath path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - if (path) - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [CURSOR_ACTIVATED], 0, row, path); @@ -806,7 +798,6 @@ static void item_double_click (ETableItem *eti, int row, int col, GdkEvent *event, ETree *et) { ETreePath path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [DOUBLE_CLICK], 0, row, path, col, event); @@ -817,7 +808,6 @@ item_right_click (ETableItem *eti, int row, int col, GdkEvent *event, ETree *et) { int return_val = 0; ETreePath path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [RIGHT_CLICK], 0, row, path, col, event, &return_val); @@ -829,7 +819,6 @@ item_click (ETableItem *eti, int row, int col, GdkEvent *event, ETree *et) { int return_val = 0; ETreePath path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [CLICK], 0, row, path, col, event, &return_val); @@ -916,7 +905,6 @@ item_key_press (ETableItem *eti, int row, int col, GdkEvent *event, ETree *et) e_table_search_input_character (et->priv->search, key->keyval); } path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [KEY_PRESS], 0, row, path, col, event, &return_val); @@ -932,7 +920,6 @@ item_start_drag (ETableItem *eti, int row, int col, GdkEvent *event, ETree *et) gint return_val = 0; path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [START_DRAG], 0, @@ -1163,8 +1150,8 @@ e_tree_set_state_object(ETree *e_tree, ETableState *state) "ETableHeader", e_tree->priv->header, NULL); - if (e_tree->priv->sorted) - e_tree_sorted_set_sort_info (e_tree->priv->sorted, e_tree->priv->sort_info); + if (e_tree->priv->etta) + e_tree_table_adapter_set_sort_info (e_tree->priv->etta, e_tree->priv->sort_info); e_tree_state_change (e_tree); } @@ -1396,9 +1383,7 @@ et_real_construct (ETree *e_tree, ETreeModel *etm, ETableExtras *ete, e_tree->priv->model = etm; g_object_ref (etm); - e_tree->priv->sorted = e_tree_sorted_new(etm, e_tree->priv->full_header, e_tree->priv->sort_info); - - e_tree->priv->etta = E_TREE_TABLE_ADAPTER(e_tree_table_adapter_new(E_TREE_MODEL(e_tree->priv->sorted))); + e_tree->priv->etta = E_TREE_TABLE_ADAPTER(e_tree_table_adapter_new(e_tree->priv->model, e_tree->priv->sort_info, e_tree->priv->full_header)); et_connect_to_etta (e_tree); @@ -1410,7 +1395,6 @@ et_real_construct (ETree *e_tree, ETreeModel *etm, ETableExtras *ete, "sorter", e_tree->priv->sorter, #ifdef E_TREE_USE_TREE_SELECTION "model", e_tree->priv->model, - "ets", e_tree->priv->sorted, "etta", e_tree->priv->etta, #else "model", e_tree->priv->etta, @@ -1665,8 +1649,6 @@ e_tree_set_cursor (ETree *e_tree, ETreePath path) e_tree_selection_model_select_single_path (E_TREE_SELECTION_MODEL(e_tree->priv->selection), path); e_tree_selection_model_change_cursor (E_TREE_SELECTION_MODEL(e_tree->priv->selection), path); #else - path = e_tree_sorted_model_to_view_path(e_tree->priv->sorted, path); - row = e_tree_table_adapter_row_of_node(E_TREE_TABLE_ADAPTER(e_tree->priv->etta), path); if (row == -1) @@ -1695,7 +1677,6 @@ e_tree_get_cursor (ETree *e_tree) if (row == -1) return NULL; path = e_tree_table_adapter_node_at_row(E_TREE_TABLE_ADAPTER(e_tree->priv->etta), row); - path = e_tree_sorted_view_to_model_path(e_tree->priv->sorted, path); return path; #endif } @@ -1962,8 +1943,6 @@ e_tree_view_to_model_row (ETree *e_tree, gboolean e_tree_node_is_expanded (ETree *et, ETreePath path) { - path = e_tree_sorted_model_to_view_path(et->priv->sorted, path); - g_return_val_if_fail(path, FALSE); return e_tree_table_adapter_node_is_expanded (et->priv->etta, path); @@ -1975,8 +1954,6 @@ e_tree_node_set_expanded (ETree *et, ETreePath path, gboolean expanded) g_return_if_fail (et != NULL); g_return_if_fail (E_IS_TREE(et)); - path = e_tree_sorted_model_to_view_path(et->priv->sorted, path); - e_tree_table_adapter_node_set_expanded (et->priv->etta, path, expanded); } @@ -1986,8 +1963,6 @@ e_tree_node_set_expanded_recurse (ETree *et, ETreePath path, gboolean expanded) g_return_if_fail (et != NULL); g_return_if_fail (E_IS_TREE(et)); - path = e_tree_sorted_model_to_view_path(et->priv->sorted, path); - e_tree_table_adapter_node_set_expanded_recurse (et->priv->etta, path, expanded); } @@ -2006,7 +1981,6 @@ e_tree_node_at_row (ETree *et, int row) ETreePath path; path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); return path; } @@ -2014,7 +1988,6 @@ e_tree_node_at_row (ETree *et, int row) int e_tree_row_of_node (ETree *et, ETreePath path) { - path = e_tree_sorted_model_to_view_path(et->priv->sorted, path); return e_tree_table_adapter_row_of_node (et->priv->etta, path); } @@ -2030,8 +2003,6 @@ e_tree_show_node (ETree *et, ETreePath path) g_return_if_fail (et != NULL); g_return_if_fail (E_IS_TREE(et)); - path = e_tree_sorted_model_to_view_path(et->priv->sorted, path); - e_tree_table_adapter_show_node (et->priv->etta, path); } @@ -2074,8 +2045,6 @@ find_next_callback (ETreeModel *model, ETreePath path, gpointer data) FindNextCallback *cb_data = data; ETree *et = cb_data->et; - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); - return cb_data->func (et->priv->model, path, cb_data->data); } @@ -2091,23 +2060,22 @@ e_tree_find_next (ETree *et, ETreeFindNextParams params, ETreePathFunc func, gpo cb_data.et = et; cursor = e_tree_get_cursor (et); - cursor = e_tree_sorted_model_to_view_path (et->priv->sorted, cursor); - found = e_tree_model_node_find (E_TREE_MODEL (et->priv->sorted), cursor, NULL, params & E_TREE_FIND_NEXT_FORWARD, find_next_callback, &cb_data); + found = e_tree_model_node_find (et->priv->model, cursor, NULL, params & E_TREE_FIND_NEXT_FORWARD, find_next_callback, &cb_data); if (found) { e_tree_table_adapter_show_node (et->priv->etta, found); - cursor = e_tree_sorted_view_to_model_path (et->priv->sorted, found); + cursor = found; e_tree_set_cursor (et, cursor); return TRUE; } if (params & E_TREE_FIND_NEXT_WRAP) { - found = e_tree_model_node_find (E_TREE_MODEL (et->priv->sorted), NULL, cursor, params & E_TREE_FIND_NEXT_FORWARD, find_next_callback, &cb_data); + found = e_tree_model_node_find (et->priv->model, NULL, cursor, params & E_TREE_FIND_NEXT_FORWARD, find_next_callback, &cb_data); if (found && found != cursor) { e_tree_table_adapter_show_node (et->priv->etta, found); - cursor = e_tree_sorted_view_to_model_path (et->priv->sorted, found); + cursor = found; e_tree_set_cursor (et, cursor); return TRUE; } @@ -2257,7 +2225,6 @@ e_tree_drag_get_data (ETree *tree, g_return_if_fail(E_IS_TREE(tree)); path = e_tree_table_adapter_node_at_row(tree->priv->etta, row); - path = e_tree_sorted_view_to_model_path(tree->priv->sorted, path); gtk_drag_get_data(GTK_WIDGET(tree), context, @@ -2266,29 +2233,6 @@ e_tree_drag_get_data (ETree *tree, } -#if 0 -static void -e_tree_request_hightlight_redraw (ETree *tree) -{ - int row = tree->drop_highlight_row; - int col = tree->drop_highlight_col; - - if (row != -1) { - int x, y, width, height; - if (col == -1) { - e_tree_get_cell_geometry (tree, row, 0, &x, &y, &width, &height); - x = 0; - width = tree->allocation.width; - } else { - e_tree_get_cell_geometry (tree, row, col, &x, &y, &width, &height); - x += GTK_LAYOUT(tree->priv->table_canvas)->hadjustment->value; - } - y += GTK_LAYOUT(tree->priv->table_canvas)->vadjustment->value; - gnome_canvas_request_redraw (tree->priv->table_canvas, x, y, x + width - 1, y + height - 1); - } -} -#endif - /** * e_tree_drag_highlight: * @tree: @@ -2509,7 +2453,6 @@ e_tree_drag_begin (ETree *tree, g_return_val_if_fail (E_IS_TREE(tree), NULL); path = e_tree_table_adapter_node_at_row(tree->priv->etta, row); - path = e_tree_sorted_view_to_model_path(tree->priv->sorted, path); tree->priv->drag_row = row; tree->priv->drag_path = path; @@ -2680,7 +2623,6 @@ do_drag_motion(ETree *et, } path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); et->priv->drop_row = row; et->priv->drop_path = path; @@ -2777,10 +2719,10 @@ hover_timeout (gpointer data) &col); path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - if (path && e_tree_model_node_is_expandable (E_TREE_MODEL (et->priv->sorted), path)) { + if (path && e_tree_model_node_is_expandable (et->priv->model, path)) { if (!e_tree_table_adapter_node_is_expanded (et->priv->etta, path)) { - if (e_tree_model_has_save_id (E_TREE_MODEL (et->priv->sorted)) && e_tree_model_has_get_node_by_id (E_TREE_MODEL (et->priv->sorted))) - et->priv->expanded_list = g_list_prepend (et->priv->expanded_list, e_tree_model_get_save_id (E_TREE_MODEL (et->priv->sorted), path)); + if (e_tree_model_has_save_id (et->priv->model) && e_tree_model_has_get_node_by_id (et->priv->model)) + et->priv->expanded_list = g_list_prepend (et->priv->expanded_list, e_tree_model_get_save_id (et->priv->model, path)); e_tree_table_adapter_node_set_expanded (et->priv->etta, path, TRUE); } } @@ -2814,19 +2756,19 @@ collapse_drag (ETree *et, ETreePath drop) /* We only want to leave open parents of the node dropped in. Not the node itself. */ if (drop) { - drop = e_tree_model_node_get_parent (E_TREE_MODEL (et->priv->sorted), drop); + drop = e_tree_model_node_get_parent (et->priv->model, drop); } for (list = et->priv->expanded_list; list; list = list->next) { char *save_id = list->data; ETreePath path; - path = e_tree_model_get_node_by_id (E_TREE_MODEL (et->priv->sorted), save_id); + path = e_tree_model_get_node_by_id (et->priv->model, save_id); if (path) { ETreePath search; gboolean found = FALSE; - for (search = drop; search; search = e_tree_model_node_get_parent (E_TREE_MODEL (et->priv->sorted), search)) { + for (search = drop; search; search = e_tree_model_node_get_parent (et->priv->model, search)) { if (path == search) { found = TRUE; break; @@ -2950,7 +2892,6 @@ et_drag_drop(GtkWidget *widget, gboolean ret_val = FALSE; int row, col; ETreePath path; - ETreePath sorted_path; y -= widget->allocation.y; x -= widget->allocation.x; e_tree_get_cell_at(et, @@ -2958,8 +2899,7 @@ et_drag_drop(GtkWidget *widget, y, &row, &col); - sorted_path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, sorted_path); + path = e_tree_table_adapter_node_at_row(et->priv->etta, row); if (row != et->priv->drop_row && col != et->priv->drop_row) { g_signal_emit (et, @@ -2999,7 +2939,7 @@ et_drag_drop(GtkWidget *widget, et->priv->drop_path = NULL; et->priv->drop_col = -1; - collapse_drag (et, sorted_path); + collapse_drag (et, path); scroll_off (et); return ret_val; @@ -3025,7 +2965,6 @@ et_drag_data_received(GtkWidget *widget, &row, &col); path = e_tree_table_adapter_node_at_row(et->priv->etta, row); - path = e_tree_sorted_view_to_model_path(et->priv->sorted, path); g_signal_emit (et, et_signals [TREE_DRAG_DATA_RECEIVED], 0, row, |