From: Andrea Zagli <azagli@libero.it>
Date: Mon, 2 Jul 2007 16:01:05 +0000 (+0000)
Subject: Continuing selection.
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=dbe101649fa44cdb6ed05a82560ae219b43a85d8;p=reptool%2Fgreptool

Continuing selection.
Added CanvasEllipse.


git-svn-id: svn+ssh://saetta.homelinux.org/svn/greptool/trunk@10 76169498-11ee-428b-941f-28d7a79d5cb2
---

diff --git a/src/Makefile.am b/src/Makefile.am
index 2c9caf9..9262dea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,4 +18,5 @@ greptool_SOURCES = \
                    canvasitem.c \
                    canvastext.c \
                    canvasline.c \
-                   canvasrect.c
+                   canvasrect.c \
+                   canvasellipse.c
diff --git a/src/canvas.c b/src/canvas.c
index 5392baa..760053b 100644
--- a/src/canvas.c
+++ b/src/canvas.c
@@ -26,6 +26,7 @@
 #include "canvastext.h"
 #include "canvasline.h"
 #include "canvasrect.h"
+#include "canvasellipse.h"
 
 static void grpt_canvas_class_init (GRptCanvasClass *klass);
 static void grpt_canvas_init (GRptCanvas *canvas);
@@ -115,6 +116,16 @@ grpt_canvas_class_init (GRptCanvasClass *klass)
 	                                                G_TYPE_NONE,
 	                                                1,
 	                                                G_TYPE_POINTER);
+	klass->selection_changed_signal_id = g_signal_new ("selection-changed",
+	                                                   G_TYPE_FROM_CLASS (object_class),
+	                                                   G_SIGNAL_RUN_LAST,
+	                                                   0,
+	                                                   NULL,
+	                                                   NULL,
+	                                                   g_cclosure_marshal_VOID__POINTER,
+	                                                   G_TYPE_NONE,
+	                                                   1,
+	                                                   G_TYPE_POINTER);
 }
 
 static void
@@ -142,6 +153,14 @@ grpt_canvas_add_item (GRptCanvas *grpt_canvas, RptReportSection section, RptObje
 										 RPT_OBJ_TEXT (rpt_object),
 										 NULL);
 		}
+	else if (IS_RPT_OBJ_ELLIPSE (rpt_object))
+		{
+			item = grpt_canvas_ellipse_new (priv->root,
+										    x, y,
+										    width, height,
+										    RPT_OBJ_ELLIPSE (rpt_object),
+										    NULL);
+		}
 	else if (IS_RPT_OBJ_RECT (rpt_object))
 		{
 			item = grpt_canvas_rect_new (priv->root,
@@ -177,7 +196,10 @@ grpt_canvas_on_button_press_event (GtkWidget *widget,
                                    GdkEventButton *event,
                                    gpointer user_data)
 {
-	GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE ((GRptCanvas *)user_data);
+	GRptCanvas *grpt_canvas = (GRptCanvas *)user_data;
+
+	GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas);
+	GRptCanvasClass *klass = GRPT_CANVAS_GET_CLASS (grpt_canvas);
 
 	if (event->button == 1)
 		{
@@ -193,7 +215,15 @@ grpt_canvas_on_button_press_event (GtkWidget *widget,
 						{
 							if (!grpt_canvas_item_is_selected (GRPT_CANVAS_ITEM (item)))
 								{
+									GList *sel = NULL;
+								
 									grpt_canvas_item_set_selected (GRPT_CANVAS_ITEM (item), TRUE);
+
+									sel = g_list_append (sel, item);
+									g_signal_emit (grpt_canvas, klass->selection_changed_signal_id, 0,
+									               sel);
+
+									g_list_free (sel);
 								}
 
 							priv->in_selection = FALSE;
@@ -247,7 +277,9 @@ grpt_canvas_on_button_release_event (GtkWidget *widget,
 	RptPoint position;
 
 	GRptCanvas *grpt_canvas = (GRptCanvas *)user_data;
+
 	GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas);
+	GRptCanvasClass *klass = GRPT_CANVAS_GET_CLASS (grpt_canvas);
 
 	if (event->button == 1)
 		{
@@ -298,6 +330,10 @@ grpt_canvas_on_button_release_event (GtkWidget *widget,
 									case TOOL_RECT:
 										rpt_object = rpt_obj_rect_new (get_new_object_name (priv->tool), position);
 										break;
+
+									case TOOL_ELLIPSE:
+										rpt_object = rpt_obj_ellipse_new (get_new_object_name (priv->tool), position);
+										break;
 								}
 							if (rpt_object != NULL)
 								{
@@ -335,6 +371,11 @@ grpt_canvas_on_button_release_event (GtkWidget *widget,
 		
 									objects = g_list_next (objects);
 								}
+
+							objects = g_list_first (objects);
+							g_signal_emit (grpt_canvas, klass->selection_changed_signal_id, 0,
+							               objects);
+
 							g_list_free (objects);
 						}
 					else
@@ -760,6 +801,8 @@ GList
 void
 grpt_canvas_remove_item (GRptCanvas *grpt_canvas, GRptCanvasItem *grpt_canvas_item)
 {
+	RptObject *rpt_obj;
+
 	RptReportSection section = grpt_canvas_item_get_section (grpt_canvas_item);
 
 	GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas);
@@ -784,6 +827,10 @@ grpt_canvas_remove_item (GRptCanvas *grpt_canvas, GRptCanvasItem *grpt_canvas_it
 				break;
 		}
 
+	rpt_obj = grpt_canvas_item_get_rpt_object (grpt_canvas_item);
+	rpt_report_remove_object (priv->rpt_report, rpt_obj);
+	g_object_unref (rpt_obj);
+	
 	g_signal_emit (grpt_canvas, klass->object_removed_signal_id, 0,
 	               grpt_canvas_item);
 
diff --git a/src/canvasellipse.c b/src/canvasellipse.c
new file mode 100644
index 0000000..7e10459
--- /dev/null
+++ b/src/canvasellipse.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2007 Andrea Zagli <azagli@inwind.it>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "canvasellipse.h"
+
+
+static void grpt_canvas_ellipse_class_init (GRptCanvasEllipseClass *klass);
+static void grpt_canvas_ellipse_init (GRptCanvasEllipse *grpt_canvas_ellipse);
+
+
+static void grpt_canvas_ellipse_paint (GooCanvasItemSimple *simple,
+                                       cairo_t *cr,
+							           const GooCanvasBounds *bounds);
+
+static RptObject *grpt_canvas_ellipse_get_rpt_object (GRptCanvasItem *grpt_canvas_item);
+
+
+#define GRPT_CANVAS_ELLIPSE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipsePrivate))
+
+
+typedef struct _GRptCanvasEllipsePrivate GRptCanvasEllipsePrivate;
+struct _GRptCanvasEllipsePrivate
+	{
+		RptObjEllipse *rpt_object_ellipse;
+	};
+
+GType
+grpt_canvas_ellipse_get_type (void)
+{
+	static GType grpt_canvas_ellipse_type = 0;
+
+	if (!grpt_canvas_ellipse_type)
+		{
+			static const GTypeInfo grpt_canvas_ellipse_info =
+			{
+				sizeof (GRptCanvasEllipseClass),
+				NULL,	/* base_init */
+				NULL,	/* base_finalize */
+				(GClassInitFunc) grpt_canvas_ellipse_class_init,
+				NULL,	/* class_finalize */
+				NULL,	/* class_data */
+				sizeof (GRptCanvasEllipse),
+				0,	/* n_preallocs */
+				(GInstanceInitFunc) grpt_canvas_ellipse_init,
+				NULL
+			};
+
+			grpt_canvas_ellipse_type = g_type_register_static (GRPT_TYPE_CANVAS_ITEM, "GRptCanvasEllipse",
+			                                                   &grpt_canvas_ellipse_info, 0);
+		}
+
+	return grpt_canvas_ellipse_type;
+}
+
+static void
+grpt_canvas_ellipse_class_init (GRptCanvasEllipseClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GRptCanvasItemClass *canvas_item_class = GRPT_CANVAS_ITEM_CLASS (klass);
+	GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass *)klass;
+
+	g_type_class_add_private (object_class, sizeof (GRptCanvasEllipsePrivate));
+
+	canvas_item_class->paint = grpt_canvas_ellipse_paint;
+	canvas_item_class->get_rpt_object = grpt_canvas_ellipse_get_rpt_object;
+}
+
+static void
+grpt_canvas_ellipse_init (GRptCanvasEllipse *grpt_canvas_ellipse)
+{
+}
+
+GRptCanvasItem
+*grpt_canvas_ellipse_new (GooCanvasItem *parent, gdouble x, gdouble y, gdouble width, gdouble height, RptObjEllipse *rpt_object_ellipse, ...)
+{
+	GRptCanvasItem *item;
+	GRptCanvasEllipse *grpt_canvas_ellipse;
+
+	RptPoint position;
+	RptSize size;
+
+	const char *first_property;
+	va_list var_args;
+	GRptCanvasEllipsePrivate *priv;
+
+	item = g_object_new (GRPT_TYPE_CANVAS_ELLIPSE, NULL);
+
+	grpt_canvas_ellipse = (GRptCanvasEllipse *)item;
+
+	priv = GRPT_CANVAS_ELLIPSE_GET_PRIVATE (grpt_canvas_ellipse);
+	priv->rpt_object_ellipse = g_object_ref (rpt_object_ellipse);
+
+	va_start (var_args, rpt_object_ellipse);
+	first_property = va_arg (var_args, char*);
+	if (first_property)
+		{
+			g_object_set_valist ((GObject *)item, first_property, var_args);
+		}
+	va_end (var_args);
+
+	if (parent)
+		{
+			goo_canvas_item_add_child (parent, GOO_CANVAS_ITEM (item), -1);
+			g_object_unref (item);
+		}
+
+	position.x = x;
+	position.y = y;
+	grpt_canvas_item_set_position (item, position);
+
+	size.width = width;
+	size.height = height;
+	grpt_canvas_item_set_size (item, size);
+
+	return item;
+}
+
+static void
+grpt_canvas_ellipse_paint (GooCanvasItemSimple *simple, cairo_t *cr, const GooCanvasBounds *bounds)
+{
+	RptPoint *position = NULL;
+	RptSize *size = NULL;
+	RptRotation *rotation = NULL;
+	RptStroke *stroke = NULL;
+	RptColor *fill_color = NULL;
+
+	GRptCanvasEllipse *grpt_canvas_ellipse = (GRptCanvasEllipse *)simple;
+
+	GRptCanvasItem *grpt_canvas_item = (GRptCanvasItem *)simple;
+
+	GRptCanvasEllipsePrivate *priv = GRPT_CANVAS_ELLIPSE_GET_PRIVATE (grpt_canvas_ellipse);
+
+	g_object_get (G_OBJECT (priv->rpt_object_ellipse),
+	              "position", &position,
+	              "size", &size,
+				  "rotation", &rotation,
+				  "stroke", &stroke,
+				  "fill-color", &fill_color,
+				  NULL);
+
+	if (position == NULL || size == NULL)
+		{
+			return;
+		}
+	if (stroke == NULL)
+		{
+			stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke));
+			stroke->width = 1.0;
+			stroke->color = (RptColor *)g_malloc0 (sizeof (RptColor));
+			stroke->color->a = 1.0;
+			stroke->style = NULL;
+		}
+
+	if (rotation != NULL)
+		{
+			/* TO DO */
+			/*rpt_print_rotate (rpt_print, position, size, rotation->angle);*/
+		}
+
+	/* TO DO */
+	/*cairo_set_line_width (priv->cr, stroke.width);*/
+	cairo_rectangle (cr, position->x, position->y, size->width, size->height);
+
+	if (fill_color != NULL)
+		{
+			cairo_set_source_rgba (cr, fill_color->r, fill_color->g, fill_color->b, fill_color->a);
+			cairo_fill_preserve (cr);
+		}
+
+	if (stroke->style != NULL)
+		{
+			gdouble *dash = rpt_common_style_to_array (stroke->style);
+			cairo_set_dash (cr, dash, stroke->style->len, 0.0);
+		}
+
+	cairo_set_source_rgba (cr, stroke->color->r, stroke->color->g, stroke->color->b, stroke->color->a);
+	cairo_stroke (cr);
+}
+
+static RptObject
+*grpt_canvas_ellipse_get_rpt_object (GRptCanvasItem *grpt_canvas_item)
+{
+	GRptCanvasEllipsePrivate *priv = GRPT_CANVAS_ELLIPSE_GET_PRIVATE (GRPT_CANVAS_ELLIPSE (grpt_canvas_item));
+
+	return RPT_OBJECT (priv->rpt_object_ellipse);
+}
diff --git a/src/canvasellipse.h b/src/canvasellipse.h
new file mode 100644
index 0000000..8935480
--- /dev/null
+++ b/src/canvasellipse.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2007 Andrea Zagli <azagli@inwind.it>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GRPT_CANVAS_ELLIPSE_H__
+#define __GRPT_CANVAS_ELLIPSE_H__
+
+#include <gtk/gtk.h>
+#include <libreptool.h>
+
+#include "canvasitem.h"
+
+
+G_BEGIN_DECLS
+
+
+#define GRPT_TYPE_CANVAS_ELLIPSE            (grpt_canvas_ellipse_get_type ())
+#define GRPT_CANVAS_ELLIPSE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipse))
+#define GRPT_CANVAS_ELLIPSE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipseClass))
+#define GRPT_IS_CANVAS_ELLIPSE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRPT_TYPE_CANVAS_ELLIPSE))
+#define GRPT_IS_CANVAS_ELLIPSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRPT_TYPE_CANVAS_ELLIPSE))
+#define GRPT_CANVAS_ELLIPSE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipseClass))
+
+
+typedef struct _GRptCanvasEllipse GRptCanvasEllipse;
+typedef struct _GRptCanvasEllipseClass GRptCanvasEllipseClass;
+  
+struct _GRptCanvasEllipse
+{
+	GRptCanvasItem parent;
+};
+
+struct _GRptCanvasEllipseClass
+{
+	GRptCanvasItemClass parent_class;
+};
+
+GType grpt_canvas_ellipse_get_type (void) G_GNUC_CONST;
+
+GRptCanvasItem *grpt_canvas_ellipse_new (GooCanvasItem *parent,
+                                         gdouble x,
+                                         gdouble y,
+                                         gdouble width,
+                                         gdouble height,
+                                         RptObjEllipse *rpt_object_ellipse,
+                                         ...);
+
+
+G_END_DECLS
+
+
+#endif /* __GRPT_CANVAS_ELLIPSE_H__ */
diff --git a/src/main.c b/src/main.c
index e525fac..b14ac28 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,9 @@ void report_on_canvas_object_added (GRptCanvas *grpt_canvas,
 void report_on_canvas_object_removed (GRptCanvas *grpt_canvas,
                                       GRptCanvasItem *item,
                                       gpointer user_data);
+void report_on_canvas_selection_changed (GRptCanvas *grpt_canvas,
+                                         GList *items,
+                                         gpointer user_data);
 
 
 static gchar *report_filename;
@@ -164,6 +167,7 @@ report_new ()
 
 	g_signal_connect (grpt_canvas, "object-added", G_CALLBACK (report_on_canvas_object_added), NULL);
 	g_signal_connect (grpt_canvas, "object-removed", G_CALLBACK (report_on_canvas_object_removed), NULL);
+	g_signal_connect (grpt_canvas, "selection-changed", G_CALLBACK (report_on_canvas_selection_changed), NULL);
 
 	gtk_container_add (GTK_CONTAINER (vbox), canvas_widget);
 	gtk_box_reorder_child (GTK_BOX (vbox), canvas_widget, 3);
@@ -201,6 +205,7 @@ report_open_from_file (const gchar *filename)
 
 	g_signal_connect (grpt_canvas, "object-added", G_CALLBACK (report_on_canvas_object_added), NULL);
 	g_signal_connect (grpt_canvas, "object-removed", G_CALLBACK (report_on_canvas_object_removed), NULL);
+	g_signal_connect (grpt_canvas, "selection-changed", G_CALLBACK (report_on_canvas_selection_changed), NULL);
 
 	gtk_container_add (GTK_CONTAINER (vbox), canvas_widget);
 	gtk_box_reorder_child (GTK_BOX (vbox), canvas_widget, 3);
@@ -421,6 +426,14 @@ report_on_canvas_object_removed (GRptCanvas *grpt_canvas,
 	grpt_objects_tree_remove_item (objects_tree, item);
 }
 
+void
+report_on_canvas_selection_changed (GRptCanvas *grpt_canvas,
+                                    GList *items,
+                                    gpointer user_data)
+{
+	g_fprintf(stderr,"selection changed\n");
+}
+
 /* PUBLIC */
 Tool
 get_current_tool ()