aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/table/e-cell-pixbuf.c4
-rw-r--r--widgets/table/e-table-sorted-variable.c81
-rw-r--r--widgets/table/e-table-sorted.c197
-rw-r--r--widgets/table/e-table-sorting-utils.c168
-rw-r--r--widgets/table/e-table-sorting-utils.h6
-rw-r--r--widgets/table/e-table-subset-variable.c2
-rw-r--r--widgets/table/e-table-subset.c9
-rw-r--r--widgets/table/e-table-subset.h13
8 files changed, 257 insertions, 223 deletions
diff --git a/widgets/table/e-cell-pixbuf.c b/widgets/table/e-cell-pixbuf.c
index 3d0acd3a71..0321474677 100644
--- a/widgets/table/e-cell-pixbuf.c
+++ b/widgets/table/e-cell-pixbuf.c
@@ -146,8 +146,6 @@ pixbuf_event (ECellView *ecell_view, GdkEvent *event,
int model_col, int view_col, int row,
ECellFlags flags, ECellActions *actions)
{
- ECellPixbufView *pixbuf_view = (ECellPixbufView *) ecell_view;
-
/* noop */
return FALSE;
@@ -156,7 +154,6 @@ pixbuf_event (ECellView *ecell_view, GdkEvent *event,
static gint
pixbuf_height (ECellView *ecell_view, int model_col, int view_col, int row)
{
- ECellPixbufView *pixbuf_view = (ECellPixbufView *) ecell_view;
GdkPixbuf *pixbuf;
pixbuf = (GdkPixbuf *) e_table_model_value_at (ecell_view->e_table_model, model_col, row);
@@ -173,7 +170,6 @@ pixbuf_height (ECellView *ecell_view, int model_col, int view_col, int row)
static gint
pixbuf_max_width (ECellView *ecell_view, int model_col, int view_col)
{
- ECellPixbufView *pixbuf_view = (ECellPixbufView *) ecell_view;
gint num_rows, i;
gint max_width = -1;
diff --git a/widgets/table/e-table-sorted-variable.c b/widgets/table/e-table-sorted-variable.c
index 3416e5d9d3..665d5fd1d7 100644
--- a/widgets/table/e-table-sorted-variable.c
+++ b/widgets/table/e-table-sorted-variable.c
@@ -100,39 +100,6 @@ etsv_insert_idle(ETableSortedVariable *etsv)
return FALSE;
}
-/* This takes source rows. */
-static int
-etsv_compare(ETableSortedVariable *etsv, int row1, int row2)
-{
- int j;
- int sort_count = e_table_sort_info_sorting_get_count(etsv->sort_info);
- int comp_val = 0;
- int ascending = 1;
- ETableSubset *etss = E_TABLE_SUBSET(etsv);
-
- for (j = 0; j < sort_count; j++) {
- ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j);
- ETableCol *col;
- col = e_table_header_get_column_by_col_idx(etsv->full_header, column.column);
- if (col == NULL)
- col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1);
- comp_val = (*col->compare)(e_table_model_value_at (etss->source, col->col_idx, row1),
- e_table_model_value_at (etss->source, col->col_idx, row2));
- ascending = column.ascending;
- if (comp_val != 0)
- break;
- }
- if (comp_val == 0) {
- if (row1 < row2)
- comp_val = -1;
- if (row1 > row2)
- comp_val = 1;
- }
- if (!ascending)
- comp_val = -comp_val;
- return comp_val;
-}
-
static void
etsv_add (ETableSubsetVariable *etssv,
@@ -160,53 +127,7 @@ etsv_add (ETableSubsetVariable *etssv,
if (etsv->insert_idle_id == 0) {
etsv->insert_idle_id = g_idle_add_full(40, (GSourceFunc) etsv_insert_idle, etsv, NULL);
}
- i = 0;
- /* handle insertions when we have a 'sort group' */
- if (e_table_model_has_sort_group(etss->source)) {
- /* find the row this row maps to */
- char *group = g_strdup(e_table_model_row_sort_group(etss->source, row));
- const char *newgroup;
- int cmp, grouplen, newgrouplen;
-
- newgroup = strrchr(group, '/');
- grouplen = strlen(group);
- if (newgroup)
- cmp = newgroup-group;
- else
- cmp = grouplen;
-
- /* find first common parent */
- while (i<etss->n_map) {
- newgroup = e_table_model_row_sort_group(etss->source, etss->map_table[i]);
- if (strncmp(newgroup, group, cmp) == 0) {
- break;
- }
- i++;
- }
-
- /* check matching records */
- while (i<etss->n_map) {
- newgroup = e_table_model_row_sort_group(etss->source, etss->map_table[i]);
- newgrouplen = strlen(newgroup);
- if (strncmp(newgroup, group, cmp) == 0) {
- /* common parent, check for same level */
- if (grouplen == newgrouplen) {
- if (etsv_compare(etsv, etss->map_table[i], row) >= 0)
- break;
- } else if (strncmp(newgroup + cmp, group + cmp, grouplen - cmp) == 0)
- /* Found a child of the inserted node. Insert here. */
- break;
- } else {
- /* ran out of common parents, insert here */
- break;
- }
- i++;
- }
- g_free(group);
- } else {
- while (i < etss->n_map && etsv_compare(etsv, etss->map_table[i], row) < 0)
- i++;
- }
+ i = e_table_sorting_utils_insert(etss->source, etsv->sort_info, etsv->full_header, etss->map_table, etss->n_map, row);
memmove(etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof(int));
}
}
diff --git a/widgets/table/e-table-sorted.c b/widgets/table/e-table-sorted.c
index 11c9d62ec0..a876ed385c 100644
--- a/widgets/table/e-table-sorted.c
+++ b/widgets/table/e-table-sorted.c
@@ -99,7 +99,6 @@ ets_sort_idle(ETableSorted *ets)
return FALSE;
}
-#if 0
static gboolean
ets_insert_idle(ETableSorted *ets)
{
@@ -107,125 +106,6 @@ ets_insert_idle(ETableSorted *ets)
ets->insert_idle_id = 0;
return FALSE;
}
-#endif
-
-#if 0
-/* This takes source rows. */
-static int
-ets_compare(ETableSorted *ets, int row1, int row2)
-{
- int j;
- int sort_count = e_table_sort_info_sorting_get_count(ets->sort_info);
- int comp_val = 0;
- int ascending = 1;
- ETableSubset *etss = E_TABLE_SUBSET(ets);
-
- for (j = 0; j < sort_count; j++) {
- ETableSortColumn column = e_table_sort_info_sorting_get_nth(ets->sort_info, j);
- ETableCol *col;
- col = e_table_header_get_column_by_col_idx(ets->full_header, column.column);
- if (col == NULL)
- col = e_table_header_get_column (ets->full_header, e_table_header_count (ets->full_header) - 1);
- comp_val = (*col->compare)(e_table_model_value_at (etss->source, col->col_idx, row1),
- e_table_model_value_at (etss->source, col->col_idx, row2));
- ascending = column.ascending;
- if (comp_val != 0)
- break;
- }
- if (comp_val == 0) {
- if (row1 < row2)
- comp_val = -1;
- if (row1 > row2)
- comp_val = 1;
- }
- if (!ascending)
- comp_val = -comp_val;
- return comp_val;
-}
-
-static void
-ets_add (ETableSorted *ets
- gint row)
-{
- ETableModel *etm = E_TABLE_MODEL(etssv);
- ETableSubset *etss = E_TABLE_SUBSET(etssv);
- ETableSorted *ets = E_TABLE_SORTED (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));
- }
- i = etss->n_map;
- if (ets->sort_idle_id == 0) {
- /* this is to see if we're inserting a lot of things between idle loops.
- If we are, we're busy, its faster to just append and perform a full sort later */
- ets->insert_count++;
- if (ets->insert_count > ETS_INSERT_MAX) {
- /* schedule a sort, and append instead */
- ets->sort_idle_id = g_idle_add_full(50, (GSourceFunc) ets_sort_idle, ets, NULL);
- } else {
- /* make sure we have an idle handler to reset the count every now and then */
- if (ets->insert_idle_id == 0) {
- ets->insert_idle_id = g_idle_add_full(40, (GSourceFunc) ets_insert_idle, ets, NULL);
- }
- i = 0;
- /* handle insertions when we have a 'sort group' */
- if (e_table_model_has_sort_group(etss->source)) {
- /* find the row this row maps to */
- char *group = g_strdup(e_table_model_row_sort_group(etss->source, row));
- const char *newgroup;
- int cmp, grouplen, newgrouplen;
-
- newgroup = strrchr(group, '/');
- grouplen = strlen(group);
- if (newgroup)
- cmp = newgroup-group;
- else
- cmp = grouplen;
-
- /* find first common parent */
- while (i<etss->n_map) {
- newgroup = e_table_model_row_sort_group(etss->source, etss->map_table[i]);
- if (strncmp(newgroup, group, cmp) == 0) {
- break;
- }
- i++;
- }
-
- /* check matching records */
- while (i<etss->n_map) {
- newgroup = e_table_model_row_sort_group(etss->source, etss->map_table[i]);
- newgrouplen = strlen(newgroup);
- if (strncmp(newgroup, group, cmp) == 0) {
- /* common parent, check for same level */
- if (grouplen == newgrouplen) {
- if (ets_compare(ets, etss->map_table[i], row) >= 0)
- break;
- } else if (strncmp(newgroup + cmp, group + cmp, grouplen - cmp) == 0)
- /* Found a child of the inserted node. Insert here. */
- break;
- } else {
- /* ran out of common parents, insert here */
- break;
- }
- i++;
- }
- g_free(group);
- } else {
- while (i < etss->n_map && ets_compare(ets, etss->map_table[i], row) < 0)
- i++;
- }
- memmove(etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof(int));
- }
- }
- etss->map_table[i] = row;
- etss->n_map++;
-
- e_table_model_row_inserted (etm, i);
-}
-
-#endif
ETableModel *
e_table_sorted_new (ETableModel *source, ETableHeader *full_header, ETableSortInfo *sort_info)
@@ -283,6 +163,9 @@ ets_proxy_model_row_changed (ETableSubset *subset, ETableModel *source, int row)
{
if (!E_TABLE_SORTED(subset)->sort_idle_id)
E_TABLE_SORTED(subset)->sort_idle_id = g_idle_add_full(50, (GSourceFunc) ets_sort_idle, subset, NULL);
+
+ if (ets_parent_class->proxy_model_row_changed)
+ (ets_parent_class->proxy_model_row_changed) (subset, source, row);
}
static void
@@ -290,23 +173,81 @@ ets_proxy_model_cell_changed (ETableSubset *subset, ETableModel *source, int col
{
ETableSorted *ets = E_TABLE_SORTED(subset);
if (e_table_sorting_utils_affects_sort(source, ets->sort_info, ets->full_header, col))
- ets_proxy_model_row_changed(subset, source, row);
- else if (ets_parent_class->proxy_model_cell_changed) {
+ ets_proxy_model_row_changed(subset, source, row);
+ else if (ets_parent_class->proxy_model_cell_changed)
(ets_parent_class->proxy_model_cell_changed) (subset, source, col, row);
- }
-
}
static void
-ets_proxy_model_row_inserted (ETableSubset *subset, ETableModel *source, int row)
+ets_proxy_model_row_inserted (ETableSubset *etss, ETableModel *source, int row)
{
- ets_proxy_model_changed(subset, source);
+ ETableModel *etm = E_TABLE_MODEL(etss);
+ ETableSorted *ets = E_TABLE_SORTED(etss);
+ int i;
+
+ e_table_model_pre_change (etm);
+
+ for (i = 0; i < etss->n_map; i++) {
+ if (etss->map_table[i] >= row)
+ etss->map_table[i] ++;
+ }
+
+ etss->map_table = g_realloc (etss->map_table, (etss->n_map + 1) * sizeof(int));
+
+ i = etss->n_map;
+ if (ets->sort_idle_id == 0) {
+ /* this is to see if we're inserting a lot of things between idle loops.
+ If we are, we're busy, its faster to just append and perform a full sort later */
+ ets->insert_count++;
+ if (ets->insert_count > ETS_INSERT_MAX) {
+ /* schedule a sort, and append instead */
+ ets->sort_idle_id = g_idle_add_full(50, (GSourceFunc) ets_sort_idle, ets, NULL);
+ } else {
+ /* make sure we have an idle handler to reset the count every now and then */
+ if (ets->insert_idle_id == 0) {
+ ets->insert_idle_id = g_idle_add_full(40, (GSourceFunc) ets_insert_idle, ets, NULL);
+ }
+ i = e_table_sorting_utils_insert(etss->source, ets->sort_info, ets->full_header, etss->map_table, etss->n_map, row);
+ memmove(etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof(int));
+ }
+ }
+ etss->map_table[i] = row;
+ etss->n_map++;
+
+ e_table_model_row_inserted (etm, i);
+ d(g_print("inserted row %d", row));
+ d(e_table_subset_print_debugging(etss));
}
static void
-ets_proxy_model_row_deleted (ETableSubset *subset, ETableModel *source, int row)
+ets_proxy_model_row_deleted (ETableSubset *etss, ETableModel *source, int row)
{
- ets_proxy_model_changed(subset, source);
+ ETableModel *etm = E_TABLE_MODEL(etss);
+ int i;
+ gboolean shift;
+
+ shift = row == etss->n_map - 1;
+
+ 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 --;
+ if (shift)
+ e_table_model_row_deleted (etm, i);
+ }
+ }
+ if (!shift) {
+ for (i = 0; i < etss->n_map; i++) {
+ if (etss->map_table[i] >= row)
+ etss->map_table[i] --;
+ }
+
+ e_table_model_changed (etm);
+ }
+
+ d(g_print("deleted row %d", row));
+ d(e_table_subset_print_debugging(etss));
}
static void
diff --git a/widgets/table/e-table-sorting-utils.c b/widgets/table/e-table-sorting-utils.c
index c5f58b8795..364397d17f 100644
--- a/widgets/table/e-table-sorting-utils.c
+++ b/widgets/table/e-table-sorting-utils.c
@@ -5,6 +5,38 @@
#define d(x)
+/* This takes source rows. */
+static int
+etsu_compare(ETableModel *source, ETableSortInfo *sort_info, ETableHeader *full_header, int row1, int row2)
+{
+ int j;
+ int sort_count = e_table_sort_info_sorting_get_count(sort_info);
+ int comp_val = 0;
+ int ascending = 1;
+
+ for (j = 0; j < sort_count; j++) {
+ ETableSortColumn column = e_table_sort_info_sorting_get_nth(sort_info, j);
+ ETableCol *col;
+ col = e_table_header_get_column_by_col_idx(full_header, column.column);
+ if (col == NULL)
+ col = e_table_header_get_column (full_header, e_table_header_count (full_header) - 1);
+ comp_val = (*col->compare)(e_table_model_value_at (source, col->col_idx, row1),
+ e_table_model_value_at (source, col->col_idx, row2));
+ ascending = column.ascending;
+ if (comp_val != 0)
+ break;
+ }
+ if (comp_val == 0) {
+ if (row1 < row2)
+ comp_val = -1;
+ if (row1 > row2)
+ comp_val = 1;
+ }
+ if (!ascending)
+ comp_val = -comp_val;
+ return comp_val;
+}
+
static ETableSortInfo *sort_info_closure;
static void **vals_closure;
@@ -319,12 +351,6 @@ e_table_sorting_utils_sort(ETableModel *source, ETableSortInfo *sort_info, ETabl
if (col == NULL)
col = e_table_header_get_column (full_header, e_table_header_count (full_header) - 1);
for (i = 0; i < rows; i++) {
-#if 0
- if( !(i & 0xff) ) {
- while(gtk_events_pending())
- gtk_main_iteration();
- }
-#endif
vals_closure[map_table[i] * cols + j] = e_table_model_value_at (source, col->col_idx, map_table[i]);
}
compare_closure[j] = col->compare;
@@ -370,3 +396,133 @@ e_table_sorting_utils_affects_sort (ETableModel *source,
}
return FALSE;
}
+
+
+int
+e_table_sorting_utils_insert(ETableModel *source, ETableSortInfo *sort_info, ETableHeader *full_header, int *map_table, int rows, int row)
+{
+ int i;
+
+ i = 0;
+ /* handle insertions when we have a 'sort group' */
+ if (e_table_model_has_sort_group(source)) {
+ /* find the row this row maps to */
+ char *group = g_strdup(e_table_model_row_sort_group(source, row));
+ const char *newgroup;
+ int cmp, grouplen, newgrouplen;
+
+ newgroup = strrchr(group, '/');
+ grouplen = strlen(group);
+ if (newgroup)
+ cmp = newgroup-group;
+ else
+ cmp = grouplen;
+
+ /* find first common parent */
+ while (i < rows) {
+ newgroup = e_table_model_row_sort_group(source, map_table[i]);
+ if (strncmp(newgroup, group, cmp) == 0) {
+ break;
+ }
+ i++;
+ }
+
+ /* check matching records */
+ while (i<row) {
+ newgroup = e_table_model_row_sort_group(source, map_table[i]);
+ newgrouplen = strlen(newgroup);
+ if (strncmp(newgroup, group, cmp) == 0) {
+ /* common parent, check for same level */
+ if (grouplen == newgrouplen) {
+ if (etsu_compare(source, sort_info, full_header, map_table[i], row) >= 0)
+ break;
+ } else if (strncmp(newgroup + cmp, group + cmp, grouplen - cmp) == 0)
+ /* Found a child of the inserted node. Insert here. */
+ break;
+ } else {
+ /* ran out of common parents, insert here */
+ break;
+ }
+ i++;
+ }
+ g_free(group);
+ } else {
+ while (i < rows && etsu_compare(source, sort_info, full_header, map_table[i], row) < 0)
+ i++;
+ }
+
+ return i;
+}
+
+#if 0
+void *bsearch(const void *key, const void *base, size_t nmemb,
+ size_t size, int (*compar)(const void *, const void *, void *), gpointer user_data)
+{
+
+}
+
+int
+e_table_sorting_utils_check_position (ETableModel *source, ETableSortInfo *sort_info, ETableHeader *full_header, int *map_table, int rows, int view_row)
+{
+ int i;
+ int row;
+
+ i = view_row;
+ row = map_table[i];
+ /* handle insertions when we have a 'sort group' */
+ if (e_table_model_has_sort_group(source)) {
+ /* find the row this row maps to */
+ char *group = g_strdup(e_table_model_row_sort_group(source, row));
+ const char *newgroup;
+ int cmp, grouplen, newgrouplen;
+
+ newgroup = strrchr(group, '/');
+ grouplen = strlen(group);
+ if (newgroup)
+ cmp = newgroup-group;
+ else
+ cmp = grouplen;
+
+ /* find first common parent */
+ while (i < rows) {
+ newgroup = e_table_model_row_sort_group(source, map_table[i]);
+ if (strncmp(newgroup, group, cmp) == 0) {
+ break;
+ }
+ i++;
+ }
+
+ /* check matching records */
+ while (i < row) {
+ newgroup = e_table_model_row_sort_group(source, map_table[i]);
+ newgrouplen = strlen(newgroup);
+ if (strncmp(newgroup, group, cmp) == 0) {
+ /* common parent, check for same level */
+ if (grouplen == newgrouplen) {
+ if (etsu_compare(source, sort_info, full_header, map_table[i], row) >= 0)
+ break;
+ } else if (strncmp(newgroup + cmp, group + cmp, grouplen - cmp) == 0)
+ /* Found a child of the inserted node. Insert here. */
+ break;
+ } else {
+ /* ran out of common parents, insert here */
+ break;
+ }
+ i++;
+ }
+ g_free(group);
+ } else {
+ i = view_row;
+ if (i < rows && etsu_compare(source, sort_info, full_header, map_table[i + 1], row) < 0) {
+ i ++;
+ while (i < rows - 1 && etsu_compare(source, sort_info, full_header, map_table[i], row) < 0)
+ i ++;
+ } else if (i > 0 && etsu_compare(source, sort_info, full_header, map_table[i - 1], row) > 0) {
+ i --;
+ while (i > 0 && etsu_compare(source, sort_info, full_header, map_table[i], row) > 0)
+ i --;
+ }
+ }
+ return i;
+}
+#endif
diff --git a/widgets/table/e-table-sorting-utils.h b/widgets/table/e-table-sorting-utils.h
index 7ad9467456..f65f7c49ce 100644
--- a/widgets/table/e-table-sorting-utils.h
+++ b/widgets/table/e-table-sorting-utils.h
@@ -21,6 +21,12 @@ gboolean e_table_sorting_utils_affects_sort (ETableModel *source,
ETableHeader *full_header,
int col);
+int e_table_sorting_utils_insert (ETableModel *source,
+ ETableSortInfo *sort_info,
+ ETableHeader *full_header,
+ int *map_table,
+ int rows,
+ int row);
#ifdef __cplusplus
}
diff --git a/widgets/table/e-table-subset-variable.c b/widgets/table/e-table-subset-variable.c
index 5c2aea35e6..a60aec1ac8 100644
--- a/widgets/table/e-table-subset-variable.c
+++ b/widgets/table/e-table-subset-variable.c
@@ -32,8 +32,8 @@ etssv_add (ETableSubsetVariable *etssv,
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;
+ etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int));
}
etss->map_table[etss->n_map++] = row;
diff --git a/widgets/table/e-table-subset.c b/widgets/table/e-table-subset.c
index bcac5f8dc2..4b3d1e5d3b 100644
--- a/widgets/table/e-table-subset.c
+++ b/widgets/table/e-table-subset.c
@@ -379,3 +379,12 @@ e_table_subset_get_toplevel (ETableSubset *table)
else
return table->source;
}
+
+void
+e_table_subset_print_debugging (ETableSubset *table_model)
+{
+ int i;
+ for (i = 0; i < table_model->n_map; i++) {
+ g_print("%8d\n", table_model->map_table[i]);
+ }
+}
diff --git a/widgets/table/e-table-subset.h b/widgets/table/e-table-subset.h
index bfa6132598..0ab2fa5be7 100644
--- a/widgets/table/e-table-subset.h
+++ b/widgets/table/e-table-subset.h
@@ -43,11 +43,16 @@ typedef struct {
void (*proxy_model_row_deleted) (ETableSubset *etss, ETableModel *etm, int row);
} ETableSubsetClass;
-GtkType e_table_subset_get_type (void);
-ETableModel *e_table_subset_new (ETableModel *etm, int n_vals);
-ETableModel *e_table_subset_construct (ETableSubset *ets, ETableModel *source, int nvals);
+GtkType e_table_subset_get_type (void);
+ETableModel *e_table_subset_new (ETableModel *etm,
+ int n_vals);
+ETableModel *e_table_subset_construct (ETableSubset *ets,
+ ETableModel *source,
+ int nvals);
-ETableModel *e_table_subset_get_toplevel (ETableSubset *table_model);
+ETableModel *e_table_subset_get_toplevel (ETableSubset *table_model);
+
+void e_table_subset_print_debugging (ETableSubset *table_model);
#ifdef __cplusplus
}