[cairo-commit] goocanvas/demo Makefile.am, 1.2, 1.3 demo-focus.c, NONE, 1.1 demo.c, 1.3, 1.4

Damon Chaplin commit at pdx.freedesktop.org
Sat Apr 22 12:17:29 PDT 2006


Committed by: damon

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

Modified Files:
	Makefile.am demo.c 
Added Files:
	demo-focus.c 
Log Message:
2006-04-22  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasview.c: added support for keyboard focus navigation.
	(I still need to make it scroll to show the focused item if needed.)

	* demo/demo-focus.c: new demo page to test keyboard focus navigation.

	* src/goocanvasitemview.c: added "focus-in-event" & "focus-out-event"
	signals.

	* src/goocanvasitemsimple.c (goo_canvas_item_simple_get_path_bounds): 
	make sure we do min/max over all points of bounds.

	* src/goocanvasview.c (goo_canvas_view_focus_out): emit
	"focus_out_event", not "focus_in_event".



Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile.am	16 Apr 2006 21:00:54 -0000	1.2
+++ Makefile.am	22 Apr 2006 19:17:28 -0000	1.3
@@ -11,7 +11,8 @@
 
 demo_SOURCES = \
 	demo.c demo-fifteen.c demo-scalability.c demo-grabs.c \
-	demo-arrowhead.c demo-features.c demo-events.c demo-paths.c
+	demo-arrowhead.c demo-features.c demo-events.c demo-paths.c \
+	demo-focus.c
 
 demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 

--- NEW FILE: demo-focus.c ---
#include <config.h>
#include <string.h>
#include <gtk/gtk.h>
#include <goocanvas.h>


static gboolean
on_focus_in (GooCanvasItemView *view,
	     GooCanvasItemView *target,
	     GdkEventFocus *event,
	     gpointer data)
{
  GooCanvasItem *item;
  gchar *id;

  item = goo_canvas_item_view_get_item (view);
  id = g_object_get_data (G_OBJECT (item), "id");

  g_print ("%s received focus-in event\n", id ? id : "unknown");

  /* Note that this is only for testing. Setting item properties to indicate
     focus isn't a good idea for real apps, as there may be multiple views. */
  g_object_set (item, "stroke-color", "black", NULL);

  return FALSE;
}


static gboolean
on_focus_out (GooCanvasItemView *view,
	      GooCanvasItemView *target,
	      GdkEventFocus *event,
	      gpointer data)
{
  GooCanvasItem *item;
  gchar *id;

  item = goo_canvas_item_view_get_item (view);
  id = g_object_get_data (G_OBJECT (item), "id");

  g_print ("%s received focus-out event\n", id ? id : "unknown");

  /* Note that this is only for testing. Setting item properties to indicate
     focus isn't a good idea for real apps, as there may be multiple views. */
  g_object_set (item, "stroke-pattern", NULL, NULL);

  return FALSE;
}


static gboolean
on_button_press (GooCanvasItemView *view,
		 GooCanvasItemView *target,
		 GdkEventButton *event,
		 gpointer data)
{
  GooCanvasItem *item;
  GooCanvasView *canvas_view;
  gchar *id;

  item = goo_canvas_item_view_get_item (view);
  id = g_object_get_data (G_OBJECT (item), "id");

  g_print ("%s received button-press event\n", id ? id : "unknown");

  canvas_view = goo_canvas_item_view_get_canvas_view (view);
  goo_canvas_view_grab_focus (canvas_view, view);

  return TRUE;
}


static gboolean
on_key_press (GooCanvasItemView *view,
	      GooCanvasItemView *target,
	      GdkEventKey *event,
	      gpointer data)
{
  GooCanvasItem *item;
  gchar *id;

  item = goo_canvas_item_view_get_item (view);
  id = g_object_get_data (G_OBJECT (item), "id");

  g_print ("%s received key-press event\n", id ? id : "unknown");

  return FALSE;
}


static void
on_item_view_created (GooCanvasView     *view,
		      GooCanvasItemView *item_view,
		      GooCanvasItem     *item,
		      gpointer           data)
{
  if (GOO_IS_CANVAS_RECT (item))
    {
      g_object_set (item_view, "can-focus", TRUE, NULL);

      g_signal_connect (item_view, "focus_in_event",
			(GtkSignalFunc) on_focus_in, NULL);
      g_signal_connect (item_view, "focus_out_event",
			(GtkSignalFunc) on_focus_out, NULL);

      g_signal_connect (item_view, "button_press_event",
			(GtkSignalFunc) on_button_press, NULL);

      g_signal_connect (item_view, "key_press_event",
			(GtkSignalFunc) on_key_press, NULL);
    }
}


static GooCanvasModelSimple*
create_canvas_model (void)
{
  GooCanvasModelSimple *canvas_model;
  GooCanvasItem *root, *item;

  canvas_model = goo_canvas_model_simple_new ();

  root = goo_canvas_model_get_root_item (GOO_CANVAS_MODEL (canvas_model));

  item = goo_canvas_rect_new (root, 110, 80, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "red",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "red");

  item = goo_canvas_rect_new (root, 300, 160, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "orange",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "orange");

  item = goo_canvas_rect_new (root, 500, 50, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "yellow",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "yellow");

  item = goo_canvas_rect_new (root, 70, 400, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "blue",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "blue");

  item = goo_canvas_rect_new (root, 130, 200, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "magenta",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "magenta");

  item = goo_canvas_rect_new (root, 200, 160, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "green",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "green");

  item = goo_canvas_rect_new (root, 450, 450, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "cyan",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "cyan");

  item = goo_canvas_rect_new (root, 300, 350, 50, 30,
			      "stroke-pattern", NULL,
			      "fill-color", "grey",
			      "line-width", 5.0,
			      NULL);
  g_object_set_data (G_OBJECT (item), "id", "grey");

  return canvas_model;
}


GtkWidget *
create_focus_page (void)
{
  GtkWidget *vbox, *label, *scrolled_win, *canvas;
  GooCanvasModelSimple *canvas_model;

  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_widget_show (vbox);

  label = gtk_label_new ("Use Tab, Shift+Tab or the arrow keys to move the keyboard focus between the canvas items.");
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
				       GTK_SHADOW_IN);
  gtk_widget_show (scrolled_win);
  gtk_container_add (GTK_CONTAINER (vbox), scrolled_win);

  canvas = goo_canvas_view_new ();
  GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS);
  gtk_widget_set_size_request (canvas, 600, 450);
  goo_canvas_view_set_bounds (GOO_CANVAS_VIEW (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  g_signal_connect (canvas, "item_view_created",
		    (GtkSignalFunc) on_item_view_created,
		    NULL);

  canvas_model = create_canvas_model ();
  goo_canvas_view_set_model (GOO_CANVAS_VIEW (canvas),
			     GOO_CANVAS_MODEL (canvas_model));
  g_object_unref (canvas_model);

  return vbox;
}

Index: demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- demo.c	18 Apr 2006 23:40:44 -0000	1.3
+++ demo.c	22 Apr 2006 19:17:28 -0000	1.4
@@ -25,6 +25,7 @@
 GtkWidget *create_grabs_page (void);
 GtkWidget *create_events_page (void);
 GtkWidget *create_paths_page (void);
+GtkWidget *create_focus_page (void);
 
 
 static void
@@ -164,7 +165,8 @@
 #if 1
   goo_canvas_item_animate (ellipse2, 100, 100, 1, 90, 1000, 40,
 			   GOO_CANVAS_ANIMATE_BOUNCE);
-#else
+#endif
+#if 0
   goo_canvas_item_animate (textitem, -300, -200, 1, 90, 1000, 40,
 			   GOO_CANVAS_ANIMATE_BOUNCE);
 #endif
@@ -1261,6 +1263,11 @@
 			    create_paths_page (),
 			    gtk_label_new ("Paths"));
 #endif
+#if 1
+  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+			    create_focus_page (),
+			    gtk_label_new ("Focus"));
+#endif
 
   return window;
 }



More information about the cairo-commit mailing list