[cairo-commit] goocanvas/src goocanvasatk.c, 1.3, 1.4 goocanvasview.c, 1.20, 1.21 goocanvasview.h, 1.7, 1.8

Damon Chaplin commit at pdx.freedesktop.org
Mon Apr 24 08:14:35 PDT 2006


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv28410/src

Modified Files:
	goocanvasatk.c goocanvasview.c goocanvasview.h 
Log Message:
2006-04-24  Damon Chaplin  <damon at gnome.org>

	* Released GooCanvas 0.3

2006-04-24  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasview.c: added "model", "scale", "anchor", "x1", "y1",
	"x2", "y2" properties, and goo_canvas_view_get_bounds() and
	goo_canvas_view_get_scale() accessors.
	Removed goo_canvas_view_set_anchor() as the property should be enough.
	(I think we should only have accessor functions for major properties.)



Index: goocanvasatk.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasatk.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- goocanvasatk.c	24 Apr 2006 13:53:42 -0000	1.3
+++ goocanvasatk.c	24 Apr 2006 15:14:33 -0000	1.4
@@ -1,8 +1,11 @@
 /*
  * GooCanvas. Copyright (C) 2005-6 Damon Chaplin.
+ * Copyright 2001 Sun Microsystems Inc.
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
  * Released under the GNU LGPL license. See COPYING for details.
  *
- * goocanvasatk.c - the accessibility code.
+ * goocanvasatk.c - the accessibility code. Most of this has been ported from
+ *                  the gail/libgnomecanvas & foocanvas code.
  */
 #include <config.h>
 #include <math.h>

Index: goocanvasview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasview.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- goocanvasview.c	24 Apr 2006 13:53:42 -0000	1.20
+++ goocanvasview.c	24 Apr 2006 15:14:33 -0000	1.21
@@ -122,6 +122,7 @@
  */
 #include <config.h>
 #include <math.h>
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 #include "goocanvasatk.h"
 #include "goocanvasview.h"
@@ -131,6 +132,18 @@
 
 
 enum {
+  PROP_0,
+
+  PROP_MODEL,
+  PROP_SCALE,
+  PROP_ANCHOR,
+  PROP_X1,
+  PROP_Y1,
+  PROP_X2,
+  PROP_Y2
+};
+
+enum {
   ITEM_VIEW_CREATED,
 
   LAST_SIGNAL
@@ -171,11 +184,22 @@
 						 GdkEventFocus    *event);
 static gboolean goo_canvas_view_grab_broken     (GtkWidget        *widget,
 						 GdkEventGrabBroken *event);
+static void     goo_canvas_view_get_property    (GObject            *object,
+						 guint               prop_id,
+						 GValue             *value,
+						 GParamSpec         *pspec);
+static void     goo_canvas_view_set_property    (GObject            *object,
+						 guint               prop_id,
+						 const GValue       *value,
+						 GParamSpec         *pspec);
 
 static void     set_item_view_pointer           (GooCanvasItemView **view,
 						 GooCanvasItemView  *new_view);
 static void     update_pointer_item_view        (GooCanvasView    *view,
 						 GdkEvent         *event);
+static void     reconfigure_canvas		(GooCanvasView    *view,
+						 gboolean          redraw_if_needed);
+
 
 G_DEFINE_TYPE (GooCanvasView, goo_canvas_view, GTK_TYPE_CONTAINER);
 
@@ -188,7 +212,9 @@
   GObjectClass *gobject_class = (GObjectClass*) klass;
   GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
 
-  gobject_class->finalize = goo_canvas_view_finalize;
+  gobject_class->finalize	     = goo_canvas_view_finalize;
+  gobject_class->get_property	     = goo_canvas_view_get_property;
+  gobject_class->set_property	     = goo_canvas_view_set_property;
 
   widget_class->realize              = goo_canvas_view_realize;
   widget_class->unrealize            = goo_canvas_view_unrealize;
@@ -214,6 +240,62 @@
 				 GOO_TYPE_CANVAS_VIEW,
 				 goo_canvas_view_accessible_factory_get_type ());
 
+  g_object_class_install_property (gobject_class, PROP_MODEL,
+                                   g_param_spec_object ("model",
+							_("Model"),
+							_("The model for the canvas view"),
+							GOO_TYPE_CANVAS_MODEL,
+							G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_SCALE,
+				   g_param_spec_double ("scale",
+							_("Scale"),
+							_("The number of pixels to use for each device unit"),
+							0.0, G_MAXDOUBLE, 1.0,
+							G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_ANCHOR,
+				   g_param_spec_enum ("anchor",
+						      _("Anchor"),
+						      _("Where to place the canvas when it is smaller than the widget's allocated area"),
+						      GTK_TYPE_ANCHOR_TYPE,
+						      GTK_ANCHOR_NW,
+						      G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_X1,
+				   g_param_spec_double ("x1",
+							_("X1"),
+							_("The x coordinate of the left edge of the canvas bounds, in device units"),
+							-G_MAXDOUBLE,
+							G_MAXDOUBLE, 0.0,
+							G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_Y1,
+				   g_param_spec_double ("y1",
+							_("Y1"),
+							_("The y coordinate of the top edge of the canvas bounds, in device units"),
+							-G_MAXDOUBLE,
+							G_MAXDOUBLE, 0.0,
+							G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_X2,
+				   g_param_spec_double ("x2",
+							_("X2"),
+							_("The x coordinate of the right edge of the canvas bounds, in device units"),
+							-G_MAXDOUBLE,
+							G_MAXDOUBLE, 1000.0,
+							G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_Y2,
+				   g_param_spec_double ("y2",
+							_("Y2"),
+							_("The y coordinate of the bottom edge of the canvas bounds, in device units"),
+							-G_MAXDOUBLE,
+							G_MAXDOUBLE, 1000.0,
+							G_PARAM_READWRITE));
+
+
+
   /**
    * GooCanvasView::set-scroll-adjustments
    * @hadjustment: the horizontal adjustment.
@@ -325,6 +407,89 @@
 }
 
 
+static void
+goo_canvas_view_get_property    (GObject            *object,
+				 guint               prop_id,
+				 GValue             *value,
+				 GParamSpec         *pspec)
+{
+  GooCanvasView *view = (GooCanvasView*) object;
+
+  switch (prop_id)
+    {
+    case PROP_MODEL:
+      g_value_set_object (value, view->model);
+      break;
+    case PROP_SCALE:
+      g_value_set_double (value, view->scale);
+      break;
+    case PROP_ANCHOR:
+      g_value_set_enum (value, view->anchor);
+      break;
+    case PROP_X1:
+      g_value_set_double (value, view->bounds.x1);
+      break;
+    case PROP_Y1:
+      g_value_set_double (value, view->bounds.y1);
+      break;
+    case PROP_X2:
+      g_value_set_double (value, view->bounds.x2);
+      break;
+    case PROP_Y2:
+      g_value_set_double (value, view->bounds.y2);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+
+static void
+goo_canvas_view_set_property    (GObject            *object,
+				 guint               prop_id,
+				 const GValue       *value,
+				 GParamSpec         *pspec)
+{
+  GooCanvasView *view = (GooCanvasView*) object;
+
+  switch (prop_id)
+    {
+    case PROP_MODEL:
+      goo_canvas_view_set_model (view, g_value_get_object (value));
+      break;
+    case PROP_SCALE:
+      goo_canvas_view_set_scale (view, g_value_get_double (value));
+      break;
+    case PROP_ANCHOR:
+      view->anchor = g_value_get_enum (value);
+      reconfigure_canvas (view, TRUE);
+      break;
+    case PROP_X1:
+      view->bounds.x1 = g_value_get_double (value);
+      reconfigure_canvas (view, TRUE);
+      break;
+    case PROP_Y1:
+      view->bounds.y1 = g_value_get_double (value);
+      reconfigure_canvas (view, TRUE);
+      break;
+    case PROP_X2:
+      view->bounds.x2 = g_value_get_double (value);
+      reconfigure_canvas (view, TRUE);
+      break;
+    case PROP_Y2:
+      view->bounds.y2 = g_value_get_double (value);
+      reconfigure_canvas (view, TRUE);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+
 /**
  * goo_canvas_view_get_model:
  * @view: a #GooCanvasView.
@@ -613,6 +778,12 @@
 
   widget = GTK_WIDGET (view);
 
+  /* Make sure the bounds are sane. */
+  if (view->bounds.x2 < view->bounds.x1)
+    view->bounds.x2 = view->bounds.x1;
+  if (view->bounds.y2 < view->bounds.y1)
+    view->bounds.y2 = view->bounds.y1;
+
   /* This is the natural size of the canvas window in pixels, rounded up to
      the next pixel. */
   width_pixels = ((view->bounds.x2 - view->bounds.x1) * view->scale) + 1;
@@ -854,6 +1025,36 @@
 
 
 /**
+ * goo_canvas_view_get_bounds:
+ * @view: a #GooCanvasView.
+ * @left: a pointer to a #gdouble to return the left edge, or %NULL.
+ * @top: a pointer to a #gdouble to return the top edge, or %NULL.
+ * @right: a pointer to a #gdouble to return the right edge, or %NULL.
+ * @bottom: a pointer to a #gdouble to return the bottom edge, or %NULL.
+ * 
+ * Gets the bounds of the canvas.
+ **/
+void
+goo_canvas_view_get_bounds	(GooCanvasView *view,
+				 gdouble       *left,
+				 gdouble       *top,
+				 gdouble       *right,
+				 gdouble       *bottom)
+{
+  g_return_if_fail (GOO_IS_CANVAS_VIEW (view));
+
+  if (left)
+    *left = view->bounds.x1;
+  if (top)
+    *top = view->bounds.y1;
+  if (right)
+    *right = view->bounds.x2;
+  if (bottom)
+    *bottom = view->bounds.y2;
+}
+
+
+/**
  * goo_canvas_view_set_bounds:
  * @view: a #GooCanvasView.
  * @left: the left edge.
@@ -873,6 +1074,8 @@
 				 gdouble        right,
 				 gdouble        bottom)
 {
+  g_return_if_fail (GOO_IS_CANVAS_VIEW (view));
+
   view->bounds.x1 = left;
   view->bounds.y1 = top;
   view->bounds.x2 = right;
@@ -898,6 +1101,8 @@
 {
   gdouble x = left, y = top;
 
+  g_return_if_fail (GOO_IS_CANVAS_VIEW (view));
+
   /* The scrollbar adjustments use pixel values, so convert to pixels. */
   goo_canvas_view_convert_to_pixels (view, &x, &y);
 
@@ -949,6 +1154,24 @@
 
 
 /**
+ * goo_canvas_view_get_scale:
+ * @view: a #GooCanvasView.
+ * 
+ * Gets the current scale of the canvas, i.e. the number of pixels to use
+ * for each device unit.
+ *
+ * Returns: the current scale setting.
+ **/
+gdouble
+goo_canvas_view_get_scale	(GooCanvasView *view)
+{
+  g_return_val_if_fail (GOO_IS_CANVAS_VIEW (view), 1.0);
+
+  return view->scale;
+}
+
+
+/**
  * goo_canvas_view_set_scale:
  * @view: a #GooCanvasView.
  * @pixels_per_unit: the new scale setting.
@@ -962,6 +1185,8 @@
 {
   gdouble x, y;
 
+  g_return_if_fail (GOO_IS_CANVAS_VIEW (view));
+
   /* Calculate the coords of the current center point in pixels. */
   x = view->hadjustment->value + view->hadjustment->page_size / 2;
   y = view->vadjustment->value + view->vadjustment->page_size / 2;
@@ -1001,27 +1226,6 @@
 
 
 /**
- * goo_canvas_view_set_anchor:
- * @view: a #GooCanvasView.
- * @anchor: the new anchor setting.
- * 
- * Sets the anchor position of the canvas. This is the position that the
- * canvas is placed in if it is smaller than the #GooCanvasView area.
- *
- * For example, if the anchor is set to %GTK_ANCHOR_CENTER, then the canvas
- * will be displayed in the center of the #GooCanvasView widget when it is
- * very small.
- **/
-void
-goo_canvas_view_set_anchor	(GooCanvasView *view,
-				 GtkAnchorType  anchor)
-{
-  view->anchor = anchor;
-  reconfigure_canvas (view, TRUE);
-}
-
-
-/**
  * goo_canvas_view_create_item_view:
  * @view: a #GooCanvasView.
  * @item: the item to create a view for.

Index: goocanvasview.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasview.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- goocanvasview.h	18 Apr 2006 15:43:07 -0000	1.7
+++ goocanvasview.h	24 Apr 2006 15:14:33 -0000	1.8
@@ -127,12 +127,15 @@
 void          goo_canvas_view_set_model	     (GooCanvasView     *view,
 					      GooCanvasModel    *model);
 
+gdouble       goo_canvas_view_get_scale	     (GooCanvasView     *view);
 void          goo_canvas_view_set_scale	     (GooCanvasView     *view,
 					      gdouble            pixels_per_unit);
 
-void	      goo_canvas_view_set_anchor     (GooCanvasView	*view,
-					      GtkAnchorType      anchor);
-
+void          goo_canvas_view_get_bounds     (GooCanvasView     *view,
+					      gdouble           *left,
+					      gdouble           *top,
+					      gdouble           *right,
+					      gdouble           *bottom);
 void          goo_canvas_view_set_bounds     (GooCanvasView     *view,
 					      gdouble            left,
 					      gdouble            top,



More information about the cairo-commit mailing list