コード例 #1
0
/* 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;
}
コード例 #2
0
static void
etgc_add_array (ETableGroup *etg, const int *array, int count)
{
	int i;
	ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg);
	void *lastval = NULL;
	int laststart = 0;
	GCompareFunc comp = etgc->ecol->compare;
	ETableGroupContainerChildNode *child_node;
	ETableGroup *child;

	if (count <= 0)
		return;

	e_table_group_container_list_free (etgc);
	etgc->children = NULL;

	lastval = e_table_model_value_at (etg->model, etgc->ecol->col_idx, array[0]);

	for (i = 1; i < count; i++) {
		void *val = e_table_model_value_at (etg->model, etgc->ecol->col_idx, array[i]);
		int comp_val;

		comp_val = (*comp)(lastval, val);
		if (comp_val != 0) {
			child_node = create_child_node(etgc, lastval);
			child = child_node->child;

			e_table_group_add_array(child, array + laststart, i - laststart);
			child_node->count = i - laststart;

			etgc->children = g_list_append (etgc->children, child_node);
			compute_text (etgc, child_node);
			laststart = i;
			lastval = val;
		}
	}

	child_node = create_child_node(etgc, lastval);
	child = child_node->child;

	e_table_group_add_array(child, array + laststart, i - laststart);
	child_node->count = i - laststart;

	etgc->children = g_list_append (etgc->children, child_node);
	compute_text (etgc, child_node);

	e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc));
}
コード例 #3
0
static gchar *
cell_date_edit_text_get_text (ECellText *cell,
                              ETableModel *model,
                              gint col,
                              gint row)
{
	ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (cell);
	ECellDateEditValue *dv = e_table_model_value_at (model, col, row);
	icaltimezone *timezone;
	struct tm tmp_tm;

	if (!dv)
		return g_strdup ("");

	timezone = e_cell_date_edit_text_get_timezone (ecd);

	/* Note that although the property may be in a different
	 * timezone, we convert it to the current timezone to display
	 * it in the table. If the user actually edits the value,
	 * it will be set to the current timezone. See set_value (). */
	tmp_tm = icaltimetype_to_tm_with_zone (&dv->tt, dv->zone, timezone);

	return e_datetime_format_format_tm (
		"calendar", "table", dv->tt.is_date ?
		DTFormatKindDate : DTFormatKindDateTime, &tmp_tm);
}
コード例 #4
0
/*
 * ECell::event method
 */
static gint
eprog_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions)
{
	ECellProgressView *progress_view = (ECellProgressView *) ecell_view;
	void *_value = e_table_model_value_at (ecell_view->e_table_model, model_col, row);
	const int value = GPOINTER_TO_INT (_value);

#if 0
	if (!(flags & E_CELL_EDITING))
		return FALSE;
#endif

	switch (event->type){
	case GDK_KEY_PRESS:
		if (event->key.keyval != GDK_space)
			return FALSE;
		/* Fall through */
	case GDK_BUTTON_PRESS:
		if (!e_table_model_is_cell_editable(ecell_view->e_table_model, model_col, row))
			return FALSE;

		eprog_set_value (progress_view, model_col, view_col, row, value + 1);
		return TRUE;

	default:
		return FALSE;
	}
}
コード例 #5
0
ファイル: e-cell-pixbuf.c プロジェクト: jdapena/evolution
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;
}
コード例 #6
0
ファイル: e-cell-pixbuf.c プロジェクト: jdapena/evolution
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);
}
コード例 #7
0
static gint
get_source_model_col_index (ETableConfig *config, gint idx)
{
	gint visible_index;
	ETableModel *src_model = E_TABLE_SUBSET (config->available_model)->source;

        visible_index = e_table_subset_view_to_model_row (E_TABLE_SUBSET (config->available_model), idx);

	return GPOINTER_TO_INT (e_table_model_value_at (src_model, 1, visible_index));
}
コード例 #8
0
static void
foreach_name (gint row, gpointer data)
{
	GnoCamCameraSelector *selector;
	ETable *table;

	selector = GNOCAM_CAMERA_SELECTOR (data);
	table = GNOCAM_CAPPLET_TABLE_SCROLLED (selector->priv->table)->table;

	selector->priv->name = e_table_model_value_at (table->model, 0, row);
}
コード例 #9
0
ファイル: e-cell-number.c プロジェクト: jdapena/evolution
static gchar *
ecn_get_text (ECellText *cell,
              ETableModel *model,
              gint col,
              gint row)
{
	gpointer value;

	value = e_table_model_value_at (model, col, row);

	return e_format_number (GPOINTER_TO_INT (value));
}
コード例 #10
0
ファイル: e-table-subset.c プロジェクト: jdapena/evolution
static gpointer
etss_value_at (ETableModel *etm,
               gint col,
               gint row)
{
	ETableSubset *etss = (ETableSubset *) etm;

	g_return_val_if_fail (VALID_ROW (etss, row), NULL);

	etss->last_access = row;
	d(g_print("g) Setting last_access to %d\n", row));
	return e_table_model_value_at (etss->source, col, MAP_ROW (etss, row));
}
コード例 #11
0
ファイル: e-cell-pixbuf.c プロジェクト: jdapena/evolution
static void
pixbuf_draw (ECellView *ecell_view,
             cairo_t *cr,
             gint model_col,
             gint view_col,
             gint row,
             ECellFlags flags,
             gint x1,
             gint y1,
             gint x2,
             gint y2)
{
    GdkPixbuf *cell_pixbuf;
    gint real_x, real_y;
    gint pix_w, pix_h;

    cell_pixbuf = e_table_model_value_at (ecell_view->e_table_model,
							  1, row);

    /* we can't make sure we really got a pixbuf since, well, it's a Gdk thing */

    if (x2 - x1 == 0)
	return;

    if (!cell_pixbuf)
	return;

    pix_w = gdk_pixbuf_get_width (cell_pixbuf);
    pix_h = gdk_pixbuf_get_height (cell_pixbuf);

    /* We center the pixbuf within our allocated space */
    if (x2 - x1 > pix_w) {
	gint diff = (x2 - x1) - pix_w;
	real_x = x1 + diff / 2;
    } else {
	real_x = x1;
    }

    if (y2 - y1 > pix_h) {
	gint diff = (y2 - y1) - pix_h;
	real_y = y1 + diff / 2;
    } else {
	real_y = y1;
    }

    cairo_save (cr);
    gdk_cairo_set_source_pixbuf (cr, cell_pixbuf, real_x, real_y);
    cairo_paint_with_alpha (cr, 1);
    cairo_restore (cr);
}
コード例 #12
0
/*
 * ECell::draw method
 */
static void
eprog_draw (ECellView *ecell_view, GdkDrawable *drawable,
	  int model_col, int view_col, int row, ECellFlags flags,
	  int x1, int y1, int x2, int y2)
{
	ECellProgress *progress = E_CELL_PROGRESS (ecell_view->ecell);
	int x, y;

	const int value = GPOINTER_TO_INT (
		 e_table_model_value_at (ecell_view->e_table_model, model_col, row));

	if ((value > progress->max)||(value < progress->min)){
		g_warning ("Value from the table model is %d, the states we support are [%d..%d]\n",
			   value, progress->min, progress->max);
		return;
	}

	if ((x2 - x1) < progress->width){
		x = x1;
	} else {
		x = x1 + ((x2 - x1) - progress->width) / 2;
	}

	if ((y2 - y1) < progress->height){
		y = y1;
	} else {
		y = y1 + ((y2 - y1) - progress->height) / 2;
	}

	eprog_clear(progress);

	eprog_draw_border(progress, progress->red, progress->green, progress->blue);

	eprog_draw_bar(progress, progress->red, progress->green, progress->blue, value);

	gdk_draw_pixbuf (drawable,
			 NULL,
			 progress->image,
			 0, 0,
			 x, y,
			 progress->width, progress->height,
			 GDK_RGB_DITHER_NORMAL,
			 x, y);
}
コード例 #13
0
static void
ecc_print (ECellView *ecell_view, GtkPrintContext *context,
	    int model_col, int view_col, int row,
	    double width, double height)
{
	cairo_t *cr = gtk_print_context_get_cairo_context (context);
	const int value = GPOINTER_TO_INT (
			  e_table_model_value_at (ecell_view->e_table_model, model_col, row));
	cairo_save (cr);

	if ( value == 1) {

		cairo_set_line_width (cr, 2);
		cairo_move_to (cr, 3, 11);
		cairo_line_to (cr, 7, 14);
		cairo_line_to (cr, 11, 5);
		cairo_stroke (cr);
	}
	cairo_restore (cr);
}
コード例 #14
0
ファイル: e-cell-percent.c プロジェクト: jdapena/evolution
static gchar *
ecp_get_text (ECellText *cell,
              ETableModel *model,
              gint col,
              gint row)
{
	gint percent;
	static gchar buffer[8];

	percent = GPOINTER_TO_INT (e_table_model_value_at (model, col, row));

	/* A -ve value means the property is not set. */
	if (percent < 0) {
		buffer[0] = '\0';
	} else {
		g_snprintf (buffer, sizeof (buffer), "%i%%", percent);
	}

	return buffer;
}
コード例 #15
0
ファイル: e-cell-size.c プロジェクト: Distrotech/evolution
static gchar *
ecd_get_text (ECellText *cell,
              ETableModel *model,
              gint col,
              gint row)
{
	gint size = GPOINTER_TO_INT (e_table_model_value_at (model, col, row));
	gfloat fsize;

	if (size < 1024) {
		return g_strdup_printf ("%d bytes", size);
	} else {
		fsize = ((gfloat) size) / 1024.0;
		if (fsize < 1024.0) {
			return g_strdup_printf ("%d K", (gint) fsize);
		} else {
			fsize /= 1024.0;
			return g_strdup_printf ("%.1f MB", fsize);
		}
	}
}
コード例 #16
0
static void
etgc_add (ETableGroup *etg, gint row)
{
	ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg);
	void *val = e_table_model_value_at (etg->model, etgc->ecol->col_idx, row);
	GCompareFunc comp = etgc->ecol->compare;
	GList *list = etgc->children;
	ETableGroup *child;
	ETableGroupContainerChildNode *child_node;
	int i = 0;

	for (; list; list = g_list_next (list), i++){
		int comp_val;

		child_node = list->data;
		comp_val = (*comp)(child_node->key, val);
		if (comp_val == 0) {
			child = child_node->child;
			child_node->count ++;
			e_table_group_add (child, row);
			compute_text (etgc, child_node);
			return;
		}
		if ((comp_val > 0 && etgc->ascending) ||
		    (comp_val < 0 && (!etgc->ascending)))
			break;
	}
	child_node = create_child_node (etgc, val);
	child = child_node->child;
	child_node->count = 1;
	e_table_group_add (child, row);

	if (list)
		etgc->children = g_list_insert (etgc->children, child_node, i);
	else
		etgc->children = g_list_append (etgc->children, child_node);

	compute_text (etgc, child_node);
	e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc));
}
コード例 #17
0
ファイル: e-cell-date.c プロジェクト: jdapena/evolution
static gchar *
ecd_get_text (ECellText *cell,
              ETableModel *model,
              gint col,
              gint row)
{
	time_t date = GPOINTER_TO_INT (e_table_model_value_at (model, col, row));
	const gchar *fmt_component, *fmt_part = NULL;

	if (date == 0) {
		return g_strdup (_("?"));
	}

	fmt_component = g_object_get_data ((GObject *) cell, "fmt-component");
	if (!fmt_component || !*fmt_component)
		fmt_component = "Default";
	else
		fmt_part = "table";

	return e_datetime_format_format (
		fmt_component, fmt_part, DTFormatKindDateTime, date);
}
コード例 #18
0
ファイル: e-cell-pixbuf.c プロジェクト: jdapena/evolution
/*
 * ECell::print method
 */
static void
pixbuf_print (ECellView *ecell_view,
              GtkPrintContext *context,
              gint model_col,
              gint view_col,
              gint row,
              gdouble width,
              gdouble height)
{
	GdkPixbuf *pixbuf;
	gint scale;
	cairo_t *cr = gtk_print_context_get_cairo_context (context);

	pixbuf = (GdkPixbuf *) e_table_model_value_at (ecell_view->e_table_model, 1, row);
	if (pixbuf == NULL)
		return;

	scale = gdk_pixbuf_get_height (pixbuf);
	cairo_save (cr);
	cairo_translate (cr, 0, (gdouble)(height - scale) / (gdouble) 2);
	gdk_cairo_set_source_pixbuf (cr, pixbuf, (gdouble) scale, (gdouble) scale);
	cairo_paint (cr);
	cairo_restore (cr);
}
コード例 #19
0
ファイル: e-cell-tree.c プロジェクト: Oliver-Luo/evolution
static ETreeTableAdapter *
e_cell_tree_get_tree_table_adapter (ETableModel *table_model,
                                    gint row)
{
	return e_table_model_value_at (table_model, -3, row);
}
コード例 #20
0
ファイル: e-cell-tree.c プロジェクト: Oliver-Luo/evolution
static ETreeModel *
e_cell_tree_get_tree_model (ETableModel *table_model,
                            gint row)
{
	return e_table_model_value_at (table_model, -2, row);
}
コード例 #21
0
ファイル: e-cell-tree.c プロジェクト: Oliver-Luo/evolution
static ETreePath
e_cell_tree_get_node (ETableModel *table_model,
                      gint row)
{
	return e_table_model_value_at (table_model, -1, row);
}
コード例 #22
0
ファイル: e-table-sorter.c プロジェクト: Distrotech/evolution
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);
}
コード例 #23
0
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);
}