/* This takes source rows. */ static gint etsu_compare (ETableModel *source, ETableSortInfo *sort_info, ETableHeader *full_header, gint row1, gint row2, gpointer cmp_cache) { gint j; gint sort_count = e_table_sort_info_sorting_get_count (sort_info); gint comp_val = 0; GtkSortType sort_type = GTK_SORT_ASCENDING; for (j = 0; j < sort_count; j++) { ETableColumnSpecification *spec; ETableCol *col; gpointer value1, value2; spec = e_table_sort_info_sorting_get_nth ( sort_info, j, &sort_type); col = e_table_header_get_column_by_spec (full_header, spec); if (col == NULL) { gint last = e_table_header_count (full_header) - 1; col = e_table_header_get_column (full_header, last); } value1 = e_table_model_value_at (source, col->spec->compare_col, row1); value2 = e_table_model_value_at (source, col->spec->compare_col, row2); comp_val = (*col->compare) (value1, value2, cmp_cache); e_table_model_free_value (source, col->spec->compare_col, value1); e_table_model_free_value (source, col->spec->compare_col, value2); if (comp_val != 0) break; } if (comp_val == 0) { if (row1 < row2) comp_val = -1; if (row1 > row2) comp_val = 1; } if (sort_type == GTK_SORT_DESCENDING) comp_val = -comp_val; return comp_val; }
static void one_dispose (GObject *object) { ETableOne *one = E_TABLE_ONE (object); if (one->data) { int i; int col_count; if (one->source) { col_count = e_table_model_column_count(one->source); for (i = 0; i < col_count; i++) e_table_model_free_value(one->source, i, one->data[i]); } g_free (one->data); } one->data = NULL; if (one->source) g_object_unref(one->source); one->source = NULL; G_OBJECT_CLASS (e_table_one_parent_class)->dispose (object); }
static void one_free_value (ETableModel *etm, int col, void *value) { ETableOne *one = E_TABLE_ONE(etm); if (one->source) e_table_model_free_value(one->source, col, value); }
static void etss_free_value (ETableModel *etm, gint col, gpointer value) { ETableSubset *etss = (ETableSubset *) etm; e_table_model_free_value (etss->source, col, value); }
static void one_set_value_at (ETableModel *etm, int col, int row, const void *val) { ETableOne *one = E_TABLE_ONE(etm); if (one->data && one->source) { e_table_model_free_value(one->source, col, one->data[col]); one->data[col] = e_table_model_duplicate_value(one->source, col, val); } }
static void e_table_group_container_child_node_free (ETableGroupContainer *etgc, ETableGroupContainerChildNode *child_node) { ETableGroup *etg = E_TABLE_GROUP (etgc); ETableGroup *child = child_node->child; gtk_object_destroy (GTK_OBJECT (child)); e_table_model_free_value (etg->model, etgc->ecol->col_idx, child_node->key); g_free(child_node->string); gtk_object_destroy (GTK_OBJECT (child_node->text)); gtk_object_destroy (GTK_OBJECT (child_node->rect)); }
static void table_sorter_sort (ETableSorter *table_sorter) { gint rows; gint i; gint j; gint cols; gint group_cols; struct qsort_data qd; if (table_sorter->sorted) return; rows = e_table_model_row_count (table_sorter->source); group_cols = e_table_sort_info_grouping_get_count (table_sorter->sort_info); cols = e_table_sort_info_sorting_get_count (table_sorter->sort_info) + group_cols; table_sorter->sorted = g_new (int, rows); for (i = 0; i < rows; i++) table_sorter->sorted[i] = i; qd.cols = cols; qd.table_sorter = table_sorter; qd.vals = g_new (gpointer , rows * cols); qd.ascending = g_new (int, cols); qd.compare = g_new (GCompareDataFunc, cols); qd.cmp_cache = e_table_sorting_utils_create_cmp_cache (); for (j = 0; j < cols; j++) { ETableColumnSpecification *spec; ETableCol *col; GtkSortType sort_type; if (j < group_cols) spec = e_table_sort_info_grouping_get_nth ( table_sorter->sort_info, j, &sort_type); else spec = e_table_sort_info_sorting_get_nth ( table_sorter->sort_info, j - group_cols, &sort_type); col = e_table_header_get_column_by_spec ( table_sorter->full_header, spec); if (col == NULL) { gint last = e_table_header_count ( table_sorter->full_header) - 1; col = e_table_header_get_column ( table_sorter->full_header, last); } for (i = 0; i < rows; i++) { qd.vals[i * cols + j] = e_table_model_value_at ( table_sorter->source, col->spec->model_col, i); } qd.compare[j] = col->compare; qd.ascending[j] = (sort_type == GTK_SORT_ASCENDING); } g_qsort_with_data (table_sorter->sorted, rows, sizeof (gint), qsort_callback, &qd); for (j = 0; j < cols; j++) { ETableColumnSpecification *spec; ETableCol *col; GtkSortType sort_type; if (j < group_cols) spec = e_table_sort_info_grouping_get_nth ( table_sorter->sort_info, j, &sort_type); else spec = e_table_sort_info_sorting_get_nth ( table_sorter->sort_info, j - group_cols, &sort_type); col = e_table_header_get_column_by_spec ( table_sorter->full_header, spec); if (col == NULL) { gint last = e_table_header_count ( table_sorter->full_header) - 1; col = e_table_header_get_column ( table_sorter->full_header, last); } for (i = 0; i < rows; i++) { e_table_model_free_value (table_sorter->source, col->spec->model_col, qd.vals[i * cols + j]); } } g_free (qd.vals); g_free (qd.ascending); g_free (qd.compare); e_table_sorting_utils_free_cmp_cache (qd.cmp_cache); }
void e_table_sorting_utils_sort (ETableModel *source, ETableSortInfo *sort_info, ETableHeader *full_header, gint *map_table, gint rows) { gint total_rows; gint i; gint j; gint cols; ETableSortClosure closure; g_return_if_fail (E_IS_TABLE_MODEL (source)); g_return_if_fail (E_IS_TABLE_SORT_INFO (sort_info)); g_return_if_fail (E_IS_TABLE_HEADER (full_header)); total_rows = e_table_model_row_count (source); cols = e_table_sort_info_sorting_get_count (sort_info); closure.cols = cols; closure.vals = g_new (gpointer, total_rows * cols); closure.sort_type = g_new (GtkSortType, cols); closure.compare = g_new (GCompareDataFunc, cols); closure.cmp_cache = e_table_sorting_utils_create_cmp_cache (); for (j = 0; j < cols; j++) { ETableColumnSpecification *spec; ETableCol *col; spec = e_table_sort_info_sorting_get_nth ( sort_info, j, &closure.sort_type[j]); col = e_table_header_get_column_by_spec (full_header, spec); if (col == NULL) { gint last = e_table_header_count (full_header) - 1; col = e_table_header_get_column (full_header, last); } for (i = 0; i < rows; i++) { closure.vals[map_table[i] * cols + j] = e_table_model_value_at (source, col->spec->compare_col, map_table[i]); } closure.compare[j] = col->compare; } g_qsort_with_data ( map_table, rows, sizeof (gint), e_sort_callback, &closure); for (j = 0; j < cols; j++) { ETableColumnSpecification *spec; ETableCol *col; spec = e_table_sort_info_sorting_get_nth ( sort_info, j, &closure.sort_type[j]); col = e_table_header_get_column_by_spec (full_header, spec); if (col == NULL) { gint last = e_table_header_count (full_header) - 1; col = e_table_header_get_column (full_header, last); } for (i = 0; i < rows; i++) { e_table_model_free_value (source, col->spec->compare_col, closure.vals[map_table[i] * cols + j]); } } g_free (closure.vals); g_free (closure.sort_type); g_free (closure.compare); e_table_sorting_utils_free_cmp_cache (closure.cmp_cache); }