[cairo-commit] goocanvas/demo demo.c, 1.10, 1.11 table-demo.c, 1.1, 1.2

Damon Chaplin commit at pdx.freedesktop.org
Wed Jan 31 17:19:10 PST 2007


Committed by: damon

Update of /cvs/cairo/goocanvas/demo
In directory kemper:/tmp/cvs-serv7119/demo

Modified Files:
	demo.c table-demo.c 
Log Message:
2007-02-01  Damon Chaplin  <damon at gnome.org>

	* src/goocanvastable.c: finished table item. I think the only API
	breakage this introduces is that GooCanvasItemSimple subclasses that
	override the update() class method must now return the bounds in user
	space rather than device space. (This is needed to do the table
	layout.)

	* demo/table-demo.c: added more test tables with various transforms
	and settings.

	* src/goocanvasitem.c (goo_canvas_item_get_requested_area) 
	(goo_canvas_item_allocate_area)
	(goo_canvas_item_get_transform_for_child) : new functions and interface
	methods to support GooCanvasTable and other layout containers.

	* src/goocanvasitemsimple.c: added support for GOO_CANVAS_ITEM_HIDDEN,
	initialized the model's visibility setting to GOO_CANVAS_ITEM_VISIBLE.
	(goo_canvas_item_simple_update): split part of it out into
	goo_canvas_item_simple_update_internal and updated slightly.
	(goo_canvas_item_simple_get_requested_area) 
	(goo_canvas_item_simple_allocate_area): new functions to support
	GooCanvasTable and other layout containers.
	(goo_canvas_item_simple_get_path_bounds): don't convert to device space
	as some code needs the bounds in user space.

	* src/goocanvas.c (goo_canvas_convert_to_item_space) 
	(goo_canvas_convert_from_item_space): used the new
	goo_canvas_item_get_transform_for_child() function to get the transform
	for each item.

	* src/goocanvasutils.h: added GOO_CANVAS_ITEM_HIDDEN visibility setting
	which is used for items which are invisible and not allocated any space
	in containter items like GooCanvasTable.

	* src/goocanvasgroup.c (goo_canvas_group_get_item_at) 
	(goo_canvas_group_paint): support GOO_CANVAS_ITEM_HIDDEN.

	* src/goocanvaspolyline.c (goo_canvas_polyline_compute_bounds):
	* src/goocanvasimage.c (goo_canvas_image_update): leave bounds in user
	space.

	* src/goocanvaswidget.c: updated to override the GooCanvasItemSimple
	update, paint & get_item_at methods instead of the interface methods,
	added support for GOO_CANVAS_ITEM_HIDDEN, and added
	goo_canvas_widget_allocate_area() implementation.

	* src/goocanvastext.c (goo_canvas_text_get_item_at): fixed bug that
	meant it didn't work for text items with no fill color/pattern set.



Index: demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- demo.c	29 Nov 2006 20:44:58 -0000	1.10
+++ demo.c	1 Feb 2007 01:19:05 -0000	1.11
@@ -693,11 +693,13 @@
     0, 0, 0, 0,     0, 0, 0, 255
   };
 
+#if 1
   ellipse1 = goo_canvas_ellipse_new (root, 245, 45, 25, 15,
 				     "stroke-color", "goldenrod",
 				     "line-width", 8.0,
 				     NULL);
   setup_item_signals (ellipse1);
+#endif
 
   ellipse2 = goo_canvas_ellipse_new (root, 335, 70, 45, 30,
 				     "fill-color", "wheat",
@@ -706,10 +708,11 @@
 				     "title", "An ellipse",
 				     NULL);
 #if 0
-  goo_canvas_item_rotate (ellipse2, 45, 335, 70);
+  goo_canvas_item_rotate (ellipse2, 30, 0, 0);
 #endif
   setup_item_signals (ellipse2);
 
+#if 1
   pattern = create_stipple ("cadetblue", stipple_data);
   ellipse3 = goo_canvas_ellipse_new (root, 245, 110, 35, 30,
 				     "fill-pattern", pattern,
@@ -718,13 +721,6 @@
 				     NULL);
   cairo_pattern_destroy (pattern);
   setup_item_signals (ellipse3);
-
-
-#if 0
- {
-   GooCanvasItem *clone = goo_canvas_clone_new (root, ellipse1);
-   goo_canvas_item_translate (clone, 100, 100);
- }
 #endif
 }
 

Index: table-demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/table-demo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- table-demo.c	9 Dec 2006 12:08:38 -0000	1.1
+++ table-demo.c	1 Feb 2007 01:19:05 -0000	1.2
@@ -7,6 +7,10 @@
 int num_added_widgets = 0;
 GList *added_widget_items;
 
+#define DEMO_RECT_ITEM 0
+#define DEMO_TEXT_ITEM 1
+#define DEMO_WIDGET_ITEM 2
+
 static gboolean
 on_delete_event (GtkWidget *window,
 		 GdkEvent  *event,
@@ -16,13 +20,144 @@
 }
 
 
+static gboolean
+on_button_press (GooCanvasItem *item,
+		 GooCanvasItem *target,
+		 GdkEventButton *event,
+		 gpointer data)
+{
+  gchar *id = g_object_get_data (G_OBJECT (item), "id");
+
+  g_print ("%s received 'button-press' signal at %g, %g (root: %g, %g)\n",
+	   id ? id : "unknown", event->x, event->y,
+	   event->x_root, event->y_root);
+
+  return TRUE;
+}
+
+
+static void
+create_demo_item (GooCanvasItem *table,
+		  gint           demo_item_type,
+		  gint           row,
+		  gint           column,
+		  gint           rows,
+		  gint           columns,
+		  gchar         *text)
+{
+  GooCanvasItem *item;
+  GtkWidget *widget;
+
+  switch (demo_item_type)
+    {
+    case DEMO_RECT_ITEM:
+      item = goo_canvas_rect_new (table, 0, 0, 38, 19,
+				  "fill-color", "red",
+				  NULL);
+      break;
+    case DEMO_TEXT_ITEM:
+      item = goo_canvas_text_new (table, text, 0, 0, -1, GTK_ANCHOR_NW, NULL);
+      break;
+    case DEMO_WIDGET_ITEM:
+      widget = gtk_button_new_with_label (text);
+      item = goo_canvas_widget_new (table, widget, 0, 0, -1, -1, NULL);
+      break;
+    }
+
+  goo_canvas_item_set_child_properties (table, item,
+					"row", row,
+					"column", column,
+					"rows", rows,
+					"columns", columns,
+#if 1
+					"x-expand", TRUE,
+					"x-fill", TRUE,
+					"y-expand", TRUE,
+					"y-fill", TRUE,
+#endif
+					NULL);
+
+  g_object_set_data (G_OBJECT (item), "id", text);
+  g_signal_connect (item, "button_press_event",
+		    (GtkSignalFunc) on_button_press, NULL);
+}
+
+
+static GooCanvasItem*
+create_table (GooCanvasItem *parent,
+	      gint           row,
+	      gint           column,
+	      gint           embedding_level,
+	      gdouble        x,
+	      gdouble        y,
+	      gdouble        rotation,
+	      gdouble        scale,
+	      gint           demo_item_type)
+{
+  GooCanvasItem *table;
+
+  /* Add a few simple items. */
+  table = goo_canvas_table_new (parent,
+				"row-spacing", 4.0,
+				"column-spacing", 4.0,
+				NULL);
+  goo_canvas_item_translate (table, x, y);
+#if 1
+  goo_canvas_item_rotate (table, rotation, 0, 0);
+#endif
+#if 1
+  goo_canvas_item_scale (table, scale, scale);
+#endif
+
+  if (row != -1)
+    goo_canvas_item_set_child_properties (parent, table,
+					  "row", row,
+					  "column", column,
+#if 1
+					  "x-expand", TRUE,
+					  "x-fill", TRUE,
+#endif
+#if 0
+					  "y-expand", TRUE,
+					  "y-fill", TRUE,
+#endif
+					  NULL);
+
+  if (embedding_level)
+    {
+      gint level = embedding_level - 1;
+      create_table (table, 0, 0, level, 50, 50, 0, 0.7, demo_item_type);
+      create_table (table, 0, 1, level, 50, 50, 45, 1.0, demo_item_type);
+      create_table (table, 0, 2, level, 50, 50, 90, 1.0, demo_item_type);
+      create_table (table, 1, 0, level, 50, 50, 135, 1.0, demo_item_type);
+      create_table (table, 1, 1, level, 50, 50, 180, 1.5, demo_item_type);
+      create_table (table, 1, 2, level, 50, 50, 225, 1.0, demo_item_type);
+      create_table (table, 2, 0, level, 50, 50, 270, 1.0, demo_item_type);
+      create_table (table, 2, 1, level, 50, 50, 315, 1.0, demo_item_type);
+      create_table (table, 2, 2, level, 50, 50, 360, 2.0, demo_item_type);
+    }
+  else
+    {
+      create_demo_item (table, demo_item_type, 0, 0, 1, 1, "(0,0)");
+      create_demo_item (table, demo_item_type, 0, 1, 1, 1, "(1,0)");
+      create_demo_item (table, demo_item_type, 0, 2, 1, 1, "(2,0)");
+      create_demo_item (table, demo_item_type, 1, 0, 1, 1, "(0,1)");
+      create_demo_item (table, demo_item_type, 1, 1, 1, 1, "(1,1)");
+      create_demo_item (table, demo_item_type, 1, 2, 1, 1, "(2,1)");
+      create_demo_item (table, demo_item_type, 2, 0, 1, 1, "(0,2)");
+      create_demo_item (table, demo_item_type, 2, 1, 1, 1, "(1,2)");
+      create_demo_item (table, demo_item_type, 2, 2, 1, 1, "(2,2)");
+    }
+
+  return table;
+}
+
+
 int
 main (int argc, char *argv[])
 {
   GtkWidget *window, *vbox, *hbox, *scrolled_win;
-  GtkWidget *label, *entry, *textview;
-  GtkTextBuffer *buffer;
-  GooCanvasItem *root, *table, *witem, *item;
+  GooCanvasItem *root, *table;
 
   /* Initialize GTK+. */
   gtk_set_locale ();
@@ -65,60 +200,26 @@
 
   root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
 
-  /* Add a few simple items. */
-  table = goo_canvas_table_new (root, NULL);
-
-  item = goo_canvas_rect_new (table, 100, 100, 50, 50, NULL);
-  goo_canvas_item_set_child_properties (table, item,
-					"row", 1,
-					"column", 2,
-					"x-align", 1.0,
-					"y-align", 1.0,
-					NULL);
-
-  label = gtk_label_new ("Hello World");
-  witem = goo_canvas_widget_new (table, label, 50, 50, 200, 100, NULL);
-
-  entry = gtk_entry_new ();
-  gtk_entry_set_text (GTK_ENTRY (entry), "Entry 1");
-  witem = goo_canvas_widget_new (table, entry, 50, 300, -1, -1, NULL);
-
-  entry = gtk_entry_new ();
-  gtk_entry_set_text (GTK_ENTRY (entry), "Entry 2");
-  witem = goo_canvas_widget_new (table, entry, 50, 350, 100, -1, NULL);
-
-  /* Use a textview so we can see the width & height of the widget. */
-  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
-  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
-				       GTK_SHADOW_IN);
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
-				  GTK_POLICY_NEVER, GTK_POLICY_NEVER);
-  textview = gtk_text_view_new ();
-  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
-  gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), "Textview", -1);
-  gtk_widget_show (textview);
-  gtk_container_add (GTK_CONTAINER (scrolled_win), textview);
-  gtk_widget_set_size_request (scrolled_win, 160, 50);
-  witem = goo_canvas_widget_new (table, scrolled_win, 50, 400, -1, 100, NULL);
-
-  /* Create a vbox item with several child entry widgets to check focus
-     traversal.*/
-  vbox = gtk_vbox_new (FALSE, 4);
-
-  entry = gtk_entry_new ();
-  gtk_widget_show (entry);
-  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
-
-  entry = gtk_entry_new ();
-  gtk_widget_show (entry);
-  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+#if 1
+  create_table (root, -1, -1, 0, 10, 10, 0, 1.0, DEMO_TEXT_ITEM);
+  create_table (root, -1, -1, 0, 180, 10, 30, 1.0, DEMO_TEXT_ITEM);
+  create_table (root, -1, -1, 0, 350, 10, 60, 1.0, DEMO_TEXT_ITEM);
+  create_table (root, -1, -1, 0, 500, 10, 90, 1.0, DEMO_TEXT_ITEM);
+#endif
 
-  entry = gtk_entry_new ();
-  gtk_widget_show (entry);
-  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+#if 1
+  table = create_table (root, -1, -1, 0, 30, 150, 0, 1.0, DEMO_TEXT_ITEM);
+  g_object_set (table, "width", 300.0, "height", 100.0, NULL);
+#endif
 
-  witem = goo_canvas_widget_new (table, vbox, 50, 600, -1, -1, NULL);
+#if 1
+  create_table (root, -1, -1, 1, 200, 200, 30, 0.8, DEMO_TEXT_ITEM);
+#endif
 
+#if 1
+  table = create_table (root, -1, -1, 0, 10, 700, 0, 1.0, DEMO_WIDGET_ITEM);
+  g_object_set (table, "width", 300.0, "height", 200.0, NULL);
+#endif
 
   gtk_widget_show (canvas);
 



More information about the cairo-commit mailing list