static gpointer cal_model_calendar_value_at (ETableModel *etm, gint col, gint row) { ECalModelComponent *comp_data; ECalModelCalendar *model = (ECalModelCalendar *) etm; g_return_val_if_fail (E_IS_CAL_MODEL_CALENDAR (model), NULL); g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_CALENDAR_FIELD_LAST, NULL); g_return_val_if_fail (row >= 0 && row < e_table_model_row_count (etm), NULL); if (col < E_CAL_MODEL_FIELD_LAST) return table_model_parent_interface->value_at (etm, col, row); comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), row); if (!comp_data) return (gpointer) ""; switch (col) { case E_CAL_MODEL_CALENDAR_FIELD_DTEND : return get_dtend (model, comp_data); case E_CAL_MODEL_CALENDAR_FIELD_LOCATION : return get_location (comp_data); case E_CAL_MODEL_CALENDAR_FIELD_TRANSPARENCY : return get_transparency (comp_data); } return (gpointer) ""; }
static gdouble pixbuf_print_height (ECellView *ecell_view, GtkPrintContext *context, gint model_col, gint view_col, gint row, gdouble width) { GdkPixbuf *pixbuf; if (row == -1) { if (e_table_model_row_count (ecell_view->e_table_model) > 0) { row = 0; } else { return 6; } } pixbuf = (GdkPixbuf *) e_table_model_value_at (ecell_view->e_table_model, 1, row); if (!pixbuf) return 0; /* We give ourselves 3 pixels of padding on either side */ return gdk_pixbuf_get_height (pixbuf); }
static gboolean cal_model_calendar_is_cell_editable (ETableModel *etm, gint col, gint row) { ECalModelCalendar *model = (ECalModelCalendar *) etm; g_return_val_if_fail (E_IS_CAL_MODEL_CALENDAR (model), FALSE); g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_CALENDAR_FIELD_LAST, FALSE); g_return_val_if_fail (row >= -1 || (row >= 0 && row < e_table_model_row_count (etm)), FALSE); if (col < E_CAL_MODEL_FIELD_LAST) return table_model_parent_interface->is_cell_editable (etm, col, row); if (!e_cal_model_test_row_editable (E_CAL_MODEL (etm), row)) return FALSE; switch (col) { case E_CAL_MODEL_CALENDAR_FIELD_DTEND : case E_CAL_MODEL_CALENDAR_FIELD_LOCATION : case E_CAL_MODEL_CALENDAR_FIELD_TRANSPARENCY : return TRUE; } return FALSE; }
static gint tree_selection_model_row_count (ESelectionModel *selection) { ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); return e_table_model_row_count (E_TABLE_MODEL (etsm->priv->etta)); }
static void etssv_add_all (ETableSubsetVariable *etssv) { ETableModel *etm = E_TABLE_MODEL (etssv); ETableSubset *etss = E_TABLE_SUBSET (etssv); ETableModel *source_model; gint rows; gint i; e_table_model_pre_change (etm); source_model = e_table_subset_get_source_model (etss); rows = e_table_model_row_count (source_model); if (etss->n_map + rows > etssv->n_vals_allocated) { etssv->n_vals_allocated += MAX (INCREMENT_AMOUNT, rows); etss->map_table = g_realloc ( etss->map_table, etssv->n_vals_allocated * sizeof (gint)); } for (i = 0; i < rows; i++) etss->map_table[etss->n_map++] = i; e_table_model_changed (etm); }
static gint pixbuf_max_width (ECellView *ecell_view, gint model_col, gint view_col) { gint pw; gint num_rows, i; gint max_width = -1; if (model_col == 0) { num_rows = e_table_model_row_count (ecell_view->e_table_model); for (i = 0; i <= num_rows; i++) { GdkPixbuf *pixbuf = (GdkPixbuf *) e_table_model_value_at (ecell_view->e_table_model, 1, i); if (!pixbuf) continue; pw = gdk_pixbuf_get_width (pixbuf); if (max_width < pw) max_width = pw; } } else { return -1; } return max_width; }
static gint etgl_row_count (ETableGroup *etg) { ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); return e_table_model_row_count (E_TABLE_MODEL (etgl->ets)); }
static void etsv_add_all (ETableSubsetVariable *etssv) { ETableModel *etm = E_TABLE_MODEL(etssv); ETableSubset *etss = E_TABLE_SUBSET(etssv); ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); int rows; int i; e_table_model_pre_change(etm); rows = e_table_model_row_count(etss->source); if (etss->n_map + rows > etssv->n_vals_allocated){ etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows); etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int)); } for (i = 0; i < rows; i++) etss->map_table[etss->n_map++] = i; if (etsv->sort_idle_id == 0) { etsv->sort_idle_id = g_idle_add_full(50, (GSourceFunc) etsv_sort_idle, etsv, NULL); } e_table_model_changed (etm); }
/* * ECell::max_width method */ static gint ect_max_width (ECellView *ecell_view, gint model_col, gint view_col) { ECellTreeView *tree_view = (ECellTreeView *) ecell_view; gint row; gint number_of_rows; gint max_width = 0; gint width = 0; gint subcell_max_width = 0; gboolean per_row = e_cell_max_width_by_row_implemented (tree_view->subcell_view); number_of_rows = e_table_model_row_count (ecell_view->e_table_model); if (!per_row) subcell_max_width = e_cell_max_width (tree_view->subcell_view, model_col, view_col); for (row = 0; row < number_of_rows; row++) { gint offset, subcell_offset; #if 0 gboolean expanded, expandable; ETreeTableAdapter *tree_table_adapter = e_cell_tree_get_tree_table_adapter (ecell_view->e_table_model, row); #endif offset = offset_of_node (ecell_view->e_table_model, row); subcell_offset = offset; width = subcell_offset; if (per_row) width += e_cell_max_width_by_row (tree_view->subcell_view, model_col, view_col, row); else width += subcell_max_width; #if 0 expandable = e_tree_model_node_is_expandable (tree_model, node); expanded = e_tree_table_adapter_node_is_expanded (tree_table_adapter, node); /* This is unnecessary since this is already handled * by the offset_of_node function. If that changes, * this will have to change too. */ if (expandable) { GdkPixbuf *image; image = (expanded ? E_CELL_TREE (tree_view->cell_view.ecell)->open_pixbuf : E_CELL_TREE (tree_view->cell_view.ecell)->closed_pixbuf); width += gdk_pixbuf_get_width (image); } #endif max_width = MAX (max_width, width); } return max_width; }
static void cal_model_calendar_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value) { ECalModelComponent *comp_data; ECalObjModType mod = E_CAL_OBJ_MOD_ALL; ECalComponent *comp; ECalModelCalendar *model = (ECalModelCalendar *) etm; g_return_if_fail (E_IS_CAL_MODEL_CALENDAR (model)); g_return_if_fail (col >= 0 && col < E_CAL_MODEL_CALENDAR_FIELD_LAST); g_return_if_fail (row >= 0 && row < e_table_model_row_count (etm)); if (col < E_CAL_MODEL_FIELD_LAST) { table_model_parent_interface->set_value_at (etm, col, row, value); return; } comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), row); if (!comp_data) return; comp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (comp_data->icalcomp)); if (!comp) { return; } /* ask about mod type */ if (e_cal_component_is_instance (comp)) { if (!e_cal_dialogs_recur_component (comp_data->client, comp, &mod, NULL, FALSE)) { g_object_unref (comp); return; } } switch (col) { case E_CAL_MODEL_CALENDAR_FIELD_DTEND : set_dtend ((ECalModel *) model, comp_data, value); break; case E_CAL_MODEL_CALENDAR_FIELD_LOCATION : set_location (comp_data, value); break; case E_CAL_MODEL_CALENDAR_FIELD_TRANSPARENCY : set_transparency (comp_data, value); break; } e_cal_model_modify_component (E_CAL_MODEL (model), comp_data, mod); g_object_unref (comp); }
static void etgl_set_focus (ETableGroup *etg, EFocus direction, gint view_col) { ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); if (direction == E_FOCUS_END) { e_table_item_set_cursor ( etgl->item, view_col, e_table_model_row_count (E_TABLE_MODEL (etgl->ets)) - 1); } else { e_table_item_set_cursor (etgl->item, view_col, 0); } }
static void table_sorter_get_sorted_to_model_array (ESorter *sorter, gint **array, gint *count) { ETableSorter *table_sorter = E_TABLE_SORTER (sorter); if (array || count) { table_sorter_sort (table_sorter); if (array) *array = table_sorter->sorted; if (count) *count = e_table_model_row_count(table_sorter->source); } }
static void table_sorter_backsort (ETableSorter *table_sorter) { gint i, rows; if (table_sorter->backsorted) return; table_sorter_sort (table_sorter); rows = e_table_model_row_count (table_sorter->source); table_sorter->backsorted = g_new0 (int, rows); for (i = 0; i < rows; i++) { table_sorter->backsorted[table_sorter->sorted[i]] = i; } }
static gint table_sorter_sorted_to_model (ESorter *sorter, gint row) { ETableSorter *table_sorter = E_TABLE_SORTER (sorter); gint rows = e_table_model_row_count (table_sorter->source); g_return_val_if_fail (row >= 0, -1); g_return_val_if_fail (row < rows, -1); if (e_sorter_needs_sorting (sorter)) table_sorter_sort (table_sorter); if (table_sorter->sorted) return table_sorter->sorted[row]; else return row; }
static void tree_selection_model_change_one_row (ESelectionModel *selection, gint row, gboolean grow) { ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); ETreePath path; g_return_if_fail ( row < e_table_model_row_count ( E_TABLE_MODEL (etsm->priv->etta))); g_return_if_fail (row >= 0); g_return_if_fail (selection != NULL); path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row); if (!path) return; change_one_path (etsm, path, grow); }
static gint model_changed_idle (ETableSelectionModel *etsm) { ETableModel *etm = etsm->model; e_selection_model_clear (E_SELECTION_MODEL (etsm)); if (etsm->cursor_id && etm && e_table_model_has_save_id (etm)) { gint row_count = e_table_model_row_count (etm); gint cursor_row = -1; gint cursor_col = -1; gint i; e_selection_model_array_confirm_row_count (E_SELECTION_MODEL_ARRAY (etsm)); for (i = 0; i < row_count; i++) { gchar *save_id = e_table_model_get_save_id (etm, i); if (g_hash_table_lookup (etsm->hash, save_id)) e_selection_model_change_one_row (E_SELECTION_MODEL (etsm), i, TRUE); if (etsm->cursor_id && !strcmp (etsm->cursor_id, save_id)) { cursor_row = i; cursor_col = e_selection_model_cursor_col (E_SELECTION_MODEL (etsm)); if (cursor_col == -1) { if (etsm->eth) { cursor_col = e_table_header_prioritized_column (etsm->eth); } else cursor_col = 0; } e_selection_model_change_cursor (E_SELECTION_MODEL (etsm), cursor_row, cursor_col); g_free (etsm->cursor_id); etsm->cursor_id = NULL; } g_free (save_id); } free_hash (etsm); e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), cursor_row, cursor_col); e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); } etsm->model_changed_idle_id = 0; return FALSE; }
void e_task_shell_view_update_sidebar (ETaskShellView *task_shell_view) { ETaskShellContent *task_shell_content; EShellView *shell_view; EShellSidebar *shell_sidebar; ETaskTable *task_table; ECalModel *model; GString *string; const gchar *format; gint n_rows; gint n_selected; shell_view = E_SHELL_VIEW (task_shell_view); shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); task_shell_content = task_shell_view->priv->task_shell_content; task_table = e_task_shell_content_get_task_table (task_shell_content); model = e_task_table_get_model (task_table); n_rows = e_table_model_row_count (E_TABLE_MODEL (model)); n_selected = e_table_selected_count (E_TABLE (task_table)); string = g_string_sized_new (64); format = ngettext ("%d task", "%d tasks", n_rows); g_string_append_printf (string, format, n_rows); if (n_selected > 0) { format = _("%d selected"); g_string_append_len (string, ", ", 2); g_string_append_printf (string, format, n_selected); } e_shell_sidebar_set_secondary_text (shell_sidebar, string->str); g_string_free (string, TRUE); }
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); }