Exemple #1
0
static void
e_minicard_label_realize (GnomeCanvasItem *item)
{
	EMinicardLabel *e_minicard_label;
	GnomeCanvasGroup *group;

	e_minicard_label = E_MINICARD_LABEL (item);
	group = GNOME_CANVAS_GROUP ( item );

	if (GNOME_CANVAS_ITEM_CLASS ( parent_class )->realize)
		(* GNOME_CANVAS_ITEM_CLASS ( parent_class )->realize) (item);

	e_canvas_item_request_reflow (item);

	e_minicard_label->rect =
	  gnome_canvas_item_new ( group,
				 gnome_canvas_rect_get_type (),
				 "x1", (double) 0,
				 "y1", (double) 0,
				 "x2", (double) e_minicard_label->width - 1,
				 "y2", (double) e_minicard_label->height - 1,
				 "outline_color", NULL,
				 NULL );
	e_minicard_label->fieldname =
	  gnome_canvas_item_new ( group,
				 e_text_get_type (),
				 "clip_width", (double) ( e_minicard_label->width / 2 - 4 ),
				 "clip", TRUE,
				 "use_ellipsis", TRUE,
				 "fill_color", "black",
				 "draw_background", FALSE,
				 "im_context", E_CANVAS (item->canvas)->im_context,
				 NULL );
	e_canvas_item_move_absolute (e_minicard_label->fieldname, 2, 1);

	e_minicard_label->field =
	  gnome_canvas_item_new ( group,
				 e_text_get_type (),
				 "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ),
				 "clip", TRUE,
				 "use_ellipsis", TRUE,
				 "fill_color", "black",
				 "editable", FALSE, /* e_minicard_label->editable, */
				 "draw_background", FALSE,
				 "im_context", E_CANVAS (item->canvas)->im_context,
				 NULL );
	e_canvas_item_move_absolute (e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);

	set_colors (e_minicard_label);

	e_canvas_item_request_reflow (item);
}
Exemple #2
0
static void
set_empty(EReflow *reflow)
{
	if (reflow->count == 0) {
		if (reflow->empty_text) {
			if (reflow->empty_message) {
				gnome_canvas_item_set(reflow->empty_text,
						      "width", reflow->minimum_width,
						      "text", reflow->empty_message,
						      NULL);
				e_canvas_item_move_absolute(reflow->empty_text,
							    reflow->minimum_width / 2,
							    0);
			} else {
				gtk_object_destroy(GTK_OBJECT(reflow->empty_text));
				reflow->empty_text = NULL;
			}
		} else {
			if (reflow->empty_message) {
				reflow->empty_text =
					gnome_canvas_item_new(GNOME_CANVAS_GROUP(reflow),
							      e_text_get_type(),
							      "anchor", GTK_ANCHOR_N,
							      "width", reflow->minimum_width,
							      "clip", TRUE,
							      "use_ellipsis", TRUE,
							      "justification", GTK_JUSTIFY_CENTER,
							      "text", reflow->empty_message,
							      "draw_background", FALSE,
							      NULL);
				e_canvas_item_move_absolute(reflow->empty_text,
							    reflow->minimum_width / 2,
							    0);
			}
		}
	} else {
		if (reflow->empty_text) {
			gtk_object_destroy(GTK_OBJECT(reflow->empty_text));
			reflow->empty_text = NULL;
		}
	}
}
Exemple #3
0
static void
etcta_realize (GnomeCanvasItem *item)
{
	ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item);

	create_rect_and_text (etcta);
	e_canvas_item_move_absolute (etcta->text, 2, 2);

	if (GNOME_CANVAS_ITEM_CLASS (e_table_click_to_add_parent_class)->realize)
		(*GNOME_CANVAS_ITEM_CLASS (e_table_click_to_add_parent_class)->realize)(item);

	e_canvas_item_request_reflow (item);
}
Exemple #4
0
static void
e_reflow_reflow( GnomeCanvasItem *item, int flags )
{
	EReflow *reflow = E_REFLOW(item);
	gdouble old_width;
	gdouble running_width;
	gdouble running_height;
	int next_column;
	int i;

	if (! (GTK_OBJECT_FLAGS (reflow) & GNOME_CANVAS_ITEM_REALIZED))
		return;

	if (reflow->need_reflow_columns) {
		reflow_columns (reflow);
	}

	old_width = reflow->width;

	running_width = E_REFLOW_BORDER_WIDTH;
	running_height = E_REFLOW_BORDER_WIDTH;

	next_column = 1;

	for (i = 0; i < reflow->count; i++) {
		int unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i);
		if (next_column < reflow->column_count && i == reflow->columns[next_column]) {
			running_height = E_REFLOW_BORDER_WIDTH;
			running_width += reflow->column_width + E_REFLOW_FULL_GUTTER;
			next_column ++;
		}

		if (unsorted >= 0 && reflow->items[unsorted]) {
			e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(reflow->items[unsorted]),
						    (double) running_width,
						    (double) running_height);
			running_height += reflow->heights[unsorted] + E_REFLOW_BORDER_WIDTH;
		}
	}
	reflow->width = running_width + reflow->column_width + E_REFLOW_BORDER_WIDTH;
	if ( reflow->width < reflow->minimum_width )
		reflow->width = reflow->minimum_width;
	if (old_width != reflow->width)
		e_canvas_item_request_parent_reflow(item);
}
Exemple #5
0
static void
e_minicard_label_reflow (GnomeCanvasItem *item,
                         gint flags)
{
	EMinicardLabel *e_minicard_label = E_MINICARD_LABEL (item);

	gint old_height;
	gdouble text_height;
	gdouble left_width;

	old_height = e_minicard_label->height;

	g_object_get (e_minicard_label->fieldname,
		     "text_height", &text_height,
		     NULL);

	e_minicard_label->height = text_height;

	g_object_get (e_minicard_label->field,
		     "text_height", &text_height,
		     NULL);

	if (e_minicard_label->height < text_height)
		e_minicard_label->height = text_height;
	e_minicard_label->height += 3;

	gnome_canvas_item_set ( e_minicard_label->rect,
			       "x2", (double) e_minicard_label->width - 1,
			       "y2", (double) e_minicard_label->height - 1,
			       NULL );

	gnome_canvas_item_set ( e_minicard_label->fieldname,
			       "clip_height", (double) e_minicard_label->height - 3,
			       NULL );

	if (e_minicard_label->max_field_name_length != -1 && ((e_minicard_label->width / 2) - 4 > e_minicard_label->max_field_name_length))
		left_width = e_minicard_label->max_field_name_length;
	else
		left_width = e_minicard_label->width / 2 - 4;

	e_canvas_item_move_absolute (e_minicard_label->field, left_width + 6, 1);

	if (old_height != e_minicard_label->height)
		e_canvas_item_request_parent_reflow (item);
}
Exemple #6
0
/* Handles the events on the ETableClickToAdd, particularly
 * it creates the ETableItem and passes in some events. */
static gint
etcta_event (GnomeCanvasItem *item,
             GdkEvent *e)
{
	ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item);

	switch (e->type) {
	case GDK_FOCUS_CHANGE:
		if (!e->focus_change.in)
			return TRUE;
		/* coverity[fallthrough] */

	case GDK_BUTTON_PRESS:
		if (etcta->text) {
			g_object_run_dispose (G_OBJECT (etcta->text));
			etcta->text = NULL;
		}
		if (etcta->rect) {
			g_object_run_dispose (G_OBJECT (etcta->rect));
			etcta->rect = NULL;
		}
		if (!etcta->row) {
			ETableModel *one;

			one = e_table_one_new (etcta->model);
			etcta_add_one (etcta, one);
			g_object_unref (one);

			e_selection_model_clear (E_SELECTION_MODEL (etcta->selection));

			etcta->row = gnome_canvas_item_new (
				GNOME_CANVAS_GROUP (item),
				e_table_item_get_type (),
				"ETableHeader", etcta->eth,
				"ETableModel", etcta->one,
				"minimum_width", etcta->width,
				"horizontal_draw_grid", TRUE,
				"vertical_draw_grid", TRUE,
				"selection_model", etcta->selection,
				"cursor_mode", E_CURSOR_SPREADSHEET,
				NULL);

			g_signal_connect (
				etcta->row, "key_press",
				G_CALLBACK (item_key_press), etcta);

			e_signal_connect_notify (
				etcta->row, "notify::is-editing",
				G_CALLBACK (table_click_to_add_row_is_editing_changed_cb), etcta);

			e_canvas_item_grab_focus (GNOME_CANVAS_ITEM (etcta->row), TRUE);

			set_initial_selection (etcta);

			g_object_notify (G_OBJECT (etcta), "is-editing");
		}
		break;

	case GDK_KEY_PRESS:
		switch (e->key.keyval) {
		case GDK_KEY_Tab:
		case GDK_KEY_KP_Tab:
		case GDK_KEY_ISO_Left_Tab:
			finish_editing (etcta);
			break;
		default:
			return FALSE;
		case GDK_KEY_Escape:
			if (etcta->row) {
				e_table_item_leave_edit (E_TABLE_ITEM (etcta->row));
				etcta_drop_one (etcta);
				g_object_run_dispose (G_OBJECT (etcta->row));
				etcta->row = NULL;
				create_rect_and_text (etcta);
				e_canvas_item_move_absolute (etcta->text, 3, 3);
			}
			break;
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
static void
etgc_reflow (GnomeCanvasItem *item, gint flags)
{
	ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(item);
	gboolean frozen;

        g_object_get (etgc,
		      "frozen", &frozen,
		      NULL);

	if (frozen)
		return;


	if (GTK_OBJECT_FLAGS(etgc)& GNOME_CANVAS_ITEM_REALIZED){
		gdouble running_height = 0;
		gdouble running_width = 0;
		gdouble old_height;
		gdouble old_width;

		old_height = etgc->height;
		old_width = etgc->width;
		if (etgc->children == NULL){
		} else {
			GList *list;
			gdouble extra_height = 0;
			gdouble item_height = 0;
			gdouble item_width = 0;

			if (etgc->font_desc) {
				PangoContext *context;
				PangoFontMetrics *metrics;

				context = gtk_widget_get_pango_context (GTK_WIDGET (item->canvas));
				metrics = pango_context_get_metrics (context, etgc->font_desc, NULL);
				extra_height +=
					PANGO_PIXELS (pango_font_metrics_get_ascent (metrics)) +
					PANGO_PIXELS (pango_font_metrics_get_descent (metrics)) +
					BUTTON_PADDING * 2;
				pango_font_metrics_unref (metrics);
			}

			extra_height = MAX(extra_height, BUTTON_HEIGHT + BUTTON_PADDING * 2);

			running_height = extra_height;

			for ( list = etgc->children; list; list = g_list_next (list)){
				ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data;
				ETableGroup *child = child_node->child;

				g_object_get (child,
					      "width", &item_width,
					      NULL);

				if (item_width > running_width)
					running_width = item_width;
			}
			for ( list = etgc->children; list; list = g_list_next (list)){
				ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data;
				ETableGroup *child = child_node->child;
				g_object_get (child,
					      "height", &item_height,
					      NULL);

				e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child_node->text),
							    GROUP_INDENT,
							    running_height - BUTTON_PADDING);

				e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child),
							    GROUP_INDENT,
							    running_height);

				gnome_canvas_item_set (GNOME_CANVAS_ITEM(child_node->rect),
						      "x1", (double) 0,
						      "x2", (double) running_width + GROUP_INDENT,
						      "y1", (double) running_height - extra_height,
						      "y2", (double) running_height + item_height,
						      NULL);

				running_height += item_height + extra_height;
			}
			running_height -= extra_height;
		}
		if (running_height != old_height || running_width != old_width) {
			etgc->height = running_height;
			etgc->width = running_width;
			e_canvas_item_request_parent_reflow (item);
		}
	}
}
Exemple #8
0
void
multi_cols_test (void)
{
	GtkWidget *canvas, *window;
	ETableModel *e_table_model;
	ETableHeader *e_table_header, *e_table_header_multiple;
	ETableCol *col_0, *col_1;
	ECell *cell_left_just, *cell_image_toggle;
	GnomeCanvasItem *item;

	gtk_widget_push_colormap (gdk_rgb_get_cmap ());

	e_table_model = e_table_simple_new (
		col_count, row_count, value_at,
		set_value_at, is_cell_editable,
		duplicate_value, free_value,
		initialize_value, value_is_empty,
		value_to_string,
		NULL);

	/*
	 * Header
	 */
	e_table_header = e_table_header_new ();

	cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT);

	{
		GdkPixbuf **images = g_new (GdkPixbuf *, 3);
		int i;

		images [0] = gdk_pixbuf_new_from_file ("image1.png");
		images [1] = gdk_pixbuf_new_from_file ("image2.png");
		images [2] = gdk_pixbuf_new_from_file ("image3.png");

		cell_image_toggle = e_cell_toggle_new (0, 3, images);

		for (i = 0; i < 3; i++)
			gdk_pixbuf_unref (images [i]);

		g_free (images);
	}

	col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, e_str_compare, TRUE);
	e_table_header_add_column (e_table_header, col_1, 0);

	col_0 = e_table_col_new (0, "A", 0.0, 48, cell_image_toggle, e_int_compare, TRUE);
	e_table_header_add_column (e_table_header, col_0, 1);

	/*
	 * Second test
	 */
	e_table_header_multiple = e_table_header_new ();
	e_table_header_add_column (e_table_header_multiple, col_0, 0);
	e_table_header_add_column (e_table_header_multiple, col_1, 1);
	e_table_header_add_column (e_table_header_multiple, col_1, 2);

	/*
	 * GUI
	 */
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	canvas = e_canvas_new ();

	g_signal_connect (canvas, "size_allocate",
			  G_CALLBACK (set_canvas_size), NULL);

	gtk_container_add (GTK_CONTAINER (window), canvas);
	gtk_widget_show_all (window);

	gnome_canvas_item_new (
		gnome_canvas_root (GNOME_CANVAS (canvas)),
		e_table_header_item_get_type (),
		"ETableHeader", e_table_header,
		NULL);

	item = gnome_canvas_item_new (
		gnome_canvas_root (GNOME_CANVAS (canvas)),
		e_table_item_get_type (),
		"ETableHeader", e_table_header,
		"ETableModel", e_table_model,
		"drawgrid", TRUE,
		"drawfocus", TRUE,
		"cursor_mode", E_TABLE_CURSOR_SIMPLE,
#if 0
		"spreadsheet", TRUE,
#endif
		NULL);

	e_canvas_item_move_absolute (item, 0, 30);

	gnome_canvas_item_new (
		gnome_canvas_root (GNOME_CANVAS (canvas)),
		e_table_header_item_get_type (),
		"ETableHeader", e_table_header_multiple,
		NULL);
	item = gnome_canvas_item_new (
		gnome_canvas_root (GNOME_CANVAS (canvas)),
		e_table_item_get_type (),
		"ETableHeader", e_table_header_multiple,
		"ETableModel", e_table_model,
		"drawgrid", TRUE,
		"drawfocus", TRUE,
#if 0
		"spreadsheet", TRUE,
#endif
		"cursor_mode", E_TABLE_CURSOR_SIMPLE,
		NULL);
	e_canvas_item_move_absolute (item, 300, 30);
}