From: Andrea Zagli Date: Sun, 3 Jun 2007 13:47:19 +0000 (+0000) Subject: Added Canvas and CanvasLine. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=021ca33e67e8a2aefe2b12ae23052013793a6e40;p=reptool%2Fgreptool Added Canvas and CanvasLine. git-svn-id: svn+ssh://saetta.homelinux.org/svn/greptool/trunk@3 76169498-11ee-428b-941f-28d7a79d5cb2 --- diff --git a/data/greptool/glade/greptool.glade b/data/greptool/glade/greptool.glade index b71d6ae..898f4f4 100644 --- a/data/greptool/glade/greptool.glade +++ b/data/greptool/glade/greptool.glade @@ -10,7 +10,7 @@ - + True @@ -466,40 +466,27 @@ 4 3 - - True - 0 - Provider - - - GTK_FILL - - - - - + True - 0 - Connection String + True + 1 + 2 1 2 - GTK_FILL - + True - 0 - SQL - 2 - 3 + 1 + 2 GTK_FILL - + GTK_FILL @@ -522,26 +509,39 @@ - + True + 0 + SQL - 1 - 2 + 2 + 3 GTK_FILL - GTK_FILL + - + True - True + 0 + Connection String - 1 - 2 1 2 + GTK_FILL + + + + + + True + 0 + Provider + + + GTK_FILL @@ -579,27 +579,18 @@ 3 3 - - True - 0 - Height - - - GTK_FILL - - - - - + True True - 1 1 10000 1 10 10 - 1 - 2 + True + True 1 2 + 1 + 2 + GTK_FILL @@ -617,17 +608,26 @@ - + True True - True - True + 1 1 10000 1 10 10 + 1 + 2 1 2 - 1 - 2 + + + + + + True + 0 + Height + + GTK_FILL @@ -673,27 +673,18 @@ 3 3 - - True - 0 - Height - - - GTK_FILL - - - - - + True True - 1 1 10000 1 10 10 - 1 - 2 + True + True 1 2 + 1 + 2 + GTK_FILL @@ -711,17 +702,26 @@ - + True True - True - True + 1 1 10000 1 10 10 + 1 + 2 1 2 - 1 - 2 + + + + + + True + 0 + Height + + GTK_FILL @@ -822,35 +822,32 @@ 3 3 - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Width + A4 +Custom + - 1 - 2 - GTK_FILL - + 1 + 2 - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 0 - Height + Type - 2 - 3 GTK_FILL - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -860,11 +857,12 @@ 1 2 - 1 + 2 + 3 - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -874,33 +872,35 @@ 1 2 - 2 - 3 + 1 - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 0 - Type + Height + 2 + 3 GTK_FILL - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - A4 -Custom - + 0 + Width - 1 - 2 + 1 + 2 + GTK_FILL + @@ -943,43 +943,61 @@ Custom 3 3 - + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Top + 0 0 10000 1 10 10 + 2 - GTK_FILL - + 1 + 2 + 3 + 4 - + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Right + 0 0 10000 1 10 10 + 2 + 1 + 2 + 2 + 3 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 0 10000 1 10 10 + 2 + + + 1 + 2 1 2 - GTK_FILL - - + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Bottom + 0 0 10000 1 10 10 + 2 - 2 - 3 - GTK_FILL - + 1 + 2 @@ -997,61 +1015,43 @@ Custom - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 0 10000 1 10 10 - 2 + 0 + Bottom - 1 - 2 + 2 + 3 + GTK_FILL + - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 0 10000 1 10 10 - 2 + 0 + Right - 1 - 2 1 2 + GTK_FILL + - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 0 10000 1 10 10 - 2 - - - 1 - 2 - 2 - 3 - - - - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 0 10000 1 10 10 - 2 + 0 + Top - 1 - 2 - 3 - 4 + GTK_FILL + diff --git a/src/Makefile.am b/src/Makefile.am index c1a1e09..f0d19eb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,4 +12,6 @@ greptool_SOURCES = \ main.c \ report_properties.c \ page_properties.c \ - objects_tree.c + objects_tree.c \ + canvas.c \ + canvasline.c diff --git a/src/canvas.c b/src/canvas.c new file mode 100644 index 0000000..36c59b5 --- /dev/null +++ b/src/canvas.c @@ -0,0 +1,322 @@ +/* + * Copyright (C) 2007 Andrea Zagli + * + * 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 +#include + +#include "main.h" +#include "canvas.h" + +static void canvas_class_init (CanvasClass *klass); +static void canvas_init (Canvas *canvas); + + +#define CANVAS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GRPT_TYPE_CANVAS, CanvasPrivate)) + + +typedef struct _CanvasPrivate CanvasPrivate; +struct _CanvasPrivate + { + RptReport *rpt_report; + + GtkWidget *scrolledw; + GtkWidget *canvas; + + GooCanvasItem *root; + GooCanvasItem *selection; + + gdouble sel_x_start; + gdouble sel_y_start; + + Tool tool; + }; + +GType +canvas_get_type (void) +{ + static GType canvas_type = 0; + + if (!canvas_type) + { + static const GTypeInfo canvas_info = + { + sizeof (CanvasClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) canvas_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (Canvas), + 0, /* n_preallocs */ + (GInstanceInitFunc) canvas_init, + NULL + }; + + canvas_type = g_type_register_static (G_TYPE_OBJECT, "Canvas", + &canvas_info, 0); + } + + return canvas_type; +} + +static void +canvas_class_init (CanvasClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (CanvasPrivate)); +} + +static void +canvas_init (Canvas *canvas) +{ +} + +static gboolean +canvas_on_button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + CanvasPrivate *priv = CANVAS_GET_PRIVATE ((Canvas *)user_data); + + if (event->button == 1) + { + priv->tool = get_current_tool (); + + priv->sel_x_start = event->x; + priv->sel_y_start = event->y; + + g_object_set (G_OBJECT (priv->selection), + "x", priv->sel_x_start, + "y", priv->sel_y_start, + "width", 0.0, + "height", 0.0, + "visibility", GOO_CANVAS_ITEM_VISIBLE, + NULL); + } + + return FALSE; +} + +static gboolean +canvas_on_button_release_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + gdouble x; + gdouble y; + gdouble width; + gdouble height; + + CanvasPrivate *priv = CANVAS_GET_PRIVATE ((Canvas *)user_data); + + g_object_set (G_OBJECT (priv->selection), + "visibility", GOO_CANVAS_ITEM_HIDDEN, + NULL); + + if (event->x < priv->sel_x_start) + { + x = event->x; + width = priv->sel_x_start - x; + } + else + { + x = priv->sel_x_start; + width = event->x - x; + } + if (event->y < priv->sel_y_start) + { + y = event->y; + height = priv->sel_y_start - y; + } + else + { + y = priv->sel_y_start; + height = event->y - y; + } + + switch (priv->tool) + { + case TOOL_LINE: + { + RptObject *rpt_object_line; + RptPoint position; + RptSize size; + + position.x = x; + position.y = y; + rpt_object_line = rpt_obj_line_new (get_new_object_name (priv->tool), position); + + size.width = width; + size.height = height; + g_object_set (G_OBJECT (rpt_object_line), + "size", &size, + NULL); + + canvas_line_new (priv->root, + x, y, + width, height, + RPT_OBJ_LINE (rpt_object_line), + NULL); + } + break; + } + + return FALSE; +} + +static gboolean +canvas_on_motion_notify_event (GtkWidget *widget, + GdkEventMotion *event, + gpointer user_data) +{ + gint x; + gint y; + GdkModifierType state; + + CanvasPrivate *priv = CANVAS_GET_PRIVATE ((Canvas *)user_data); + + if (event->is_hint) + { + gdk_window_get_pointer (event->window, &x, &y, &state); + } + else + { + x = event->x; + y = event->y; + state = event->state; + } + + if (state & GDK_BUTTON1_MASK) + { + gdouble width; + gdouble height; + + if (x < priv->sel_x_start) + { + g_object_set (G_OBJECT (priv->selection), + "x", (gdouble)x, + NULL); + width = priv->sel_x_start - x; + } + else + { + g_object_set (G_OBJECT (priv->selection), + "x", priv->sel_x_start, + NULL); + width = x - priv->sel_x_start; + } + if (y < priv->sel_y_start) + { + g_object_set (G_OBJECT (priv->selection), + "y", (gdouble)y, + NULL); + height = priv->sel_y_start - y; + } + else + { + g_object_set (G_OBJECT (priv->selection), + "y", priv->sel_y_start, + NULL); + height = y - priv->sel_y_start; + } + + g_object_set (G_OBJECT (priv->selection), + "width", width, + "height", height, + NULL); + } + + return FALSE; +} + +Canvas +*canvas_new (RptReport *rpt_report) +{ + GtkWidget *viewport; + GtkWidget *fixed; + RptSize *size; + + Canvas *canvas = GRPT_CANVAS (g_object_new (canvas_get_type (), NULL)); + + CanvasPrivate *priv = CANVAS_GET_PRIVATE (canvas); + + priv->rpt_report = rpt_report; + + priv->scrolledw = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolledw), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + viewport = gtk_viewport_new (NULL, NULL); + gtk_container_add (GTK_CONTAINER (priv->scrolledw), viewport); + + fixed = gtk_fixed_new (); + gtk_container_add (GTK_CONTAINER (viewport), fixed); + + priv->canvas = goo_canvas_new (); + gtk_fixed_put (GTK_FIXED (fixed), priv->canvas, 0, 0); + + g_signal_connect (G_OBJECT (priv->canvas), "button-press-event", + G_CALLBACK (canvas_on_button_press_event), (gpointer)canvas); + g_signal_connect (G_OBJECT (priv->canvas), "button-release-event", + G_CALLBACK (canvas_on_button_release_event), (gpointer)canvas); + g_signal_connect (G_OBJECT (priv->canvas), "motion-notify-event", + G_CALLBACK (canvas_on_motion_notify_event), (gpointer)canvas); + + priv->root = goo_canvas_get_root_item (GOO_CANVAS (priv->canvas)); + + /* setting size */ + size = rpt_report_get_page_size (priv->rpt_report); + size->height = rpt_report_get_section_height (priv->rpt_report, RPTREPORT_SECTION_BODY); + canvas_set_size (canvas, *size); + + /* GooCanvasItem that represents the "selection" */ + priv->selection = goo_canvas_rect_new (priv->root, 0, 0, 0, 0, + "stroke-color", "black", + "visibility", GOO_CANVAS_ITEM_HIDDEN, + NULL); + + return canvas; +} + +GtkWidget +*canvas_get_widget (Canvas *canvas) +{ + CanvasPrivate *priv = CANVAS_GET_PRIVATE (canvas); + + return priv->scrolledw; +} + +void +canvas_set_size (Canvas *canvas, RptSize size) +{ + CanvasPrivate *priv = CANVAS_GET_PRIVATE (canvas); + + gtk_widget_set_size_request (priv->canvas, size.width, size.height); + goo_canvas_set_bounds (GOO_CANVAS (priv->canvas), 0, 0, size.width, size.height); +} + +void +canvas_free (Canvas *canvas) +{ + CanvasPrivate *priv = CANVAS_GET_PRIVATE (canvas); + + gtk_widget_destroy (priv->canvas); + gtk_widget_destroy (priv->scrolledw); +} diff --git a/src/canvas.h b/src/canvas.h new file mode 100644 index 0000000..ca5e17c --- /dev/null +++ b/src/canvas.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007 Andrea Zagli + * + * 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 __CANVAS_H__ +#define __CANVAS_H__ + +#include +#include + + +G_BEGIN_DECLS + + +#define GRPT_TYPE_CANVAS (canvas_get_type ()) +#define GRPT_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRPT_TYPE_CANVAS, Canvas)) +#define GRPT_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRPT_TYPE_CANVAS, CanvasClass)) +#define GRPT_IS_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRPT_TYPE_CANVAS)) +#define GRPT_IS_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRPT_TYPE_CANVAS)) +#define GRPT_CANVAS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRPT_TYPE_CANVAS, CanvasClass)) + + +typedef struct _Canvas Canvas; +typedef struct _CanvasClass CanvasClass; + +struct _Canvas +{ + GObject parent; +}; + +struct _CanvasClass +{ + GObjectClass parent_class; +}; + +GType canvas_get_type (void) G_GNUC_CONST; + +Canvas *canvas_new (RptReport *rpt_report); + +GtkWidget *canvas_get_widget (Canvas *canvas); + +void canvas_set_size (Canvas *canvas, RptSize size); + +void canvas_free (Canvas *canvas); + + +G_END_DECLS + + +#endif /* __CANVAS_H__ */ diff --git a/src/canvasline.c b/src/canvasline.c new file mode 100644 index 0000000..ae24f3b --- /dev/null +++ b/src/canvasline.c @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2007 Andrea Zagli + * + * 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 "canvasline.h" + + +static void canvas_line_class_init (CanvasLineClass *klass); +static void canvas_line_init (CanvasLine *canvas_line); + + +static void canvas_line_update (GooCanvasItemSimple *simple, + cairo_t *cr); +static void canvas_line_paint (GooCanvasItemSimple *simple, + cairo_t *cr, + const GooCanvasBounds *bounds); +static gboolean canvas_line_is_item_at (GooCanvasItemSimple *simple, + gdouble x, + gdouble y, + cairo_t *cr, + gboolean is_pointer_event); + +#define GRPT_CANVAS_LINE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GRPT_TYPE_CANVAS_LINE, CanvasLinePrivate)) + + +typedef struct _CanvasLinePrivate CanvasLinePrivate; +struct _CanvasLinePrivate + { + RptObjLine *rpt_object_line; + }; + +GType +canvas_line_get_type (void) +{ + static GType canvas_line_type = 0; + + if (!canvas_line_type) + { + static const GTypeInfo canvas_line_info = + { + sizeof (CanvasLineClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) canvas_line_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (CanvasLine), + 0, /* n_preallocs */ + (GInstanceInitFunc) canvas_line_init, + NULL + }; + + canvas_line_type = g_type_register_static (GOO_TYPE_CANVAS_ITEM_SIMPLE, "CanvasLine", + &canvas_line_info, 0); + } + + return canvas_line_type; +} + +static void +canvas_line_class_init (CanvasLineClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass *)klass; + + g_type_class_add_private (object_class, sizeof (CanvasLinePrivate)); + + simple_class->simple_update = canvas_line_update; + simple_class->simple_paint = canvas_line_paint; + simple_class->simple_is_item_at = canvas_line_is_item_at; +} + +static void +canvas_line_init (CanvasLine *canvas_line) +{ + canvas_line->x = 0.0; + canvas_line->y = 0.0; + canvas_line->width = 0.0; + canvas_line->height = 0.0; +} + +GooCanvasItem +*canvas_line_new (GooCanvasItem *parent, gdouble x, gdouble y, gdouble width, gdouble height, RptObjLine *rpt_object_line, ...) +{ + GooCanvasItem *item; + CanvasLine *canvas_line; + const char *first_property; + va_list var_args; + CanvasLinePrivate *priv; + + item = g_object_new (GRPT_TYPE_CANVAS_LINE, NULL); + + canvas_line = (CanvasLine *)item; + canvas_line->x = x; + canvas_line->y = y; + canvas_line->width = width; + canvas_line->height = height; + + priv = GRPT_CANVAS_LINE_GET_PRIVATE (canvas_line); + priv->rpt_object_line = g_object_ref (rpt_object_line); + + va_start (var_args, rpt_object_line); + 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, item, -1); + g_object_unref (item); + } + + return item; +} + +static void +canvas_line_update (GooCanvasItemSimple *simple, cairo_t *cr) +{ + CanvasLine *canvas_line = (CanvasLine *)simple; + + /* Compute the new bounds. */ + simple->bounds.x1 = canvas_line->x; + simple->bounds.y1 = canvas_line->y; + simple->bounds.x2 = canvas_line->x + canvas_line->width; + simple->bounds.y2 = canvas_line->y + canvas_line->height; +} + +static void +canvas_line_paint (GooCanvasItemSimple *simple, cairo_t *cr, const GooCanvasBounds *bounds) +{ + RptPoint from_p; + RptPoint to_p; + RptRotation *rotation = NULL; + RptStroke *stroke = NULL; + + CanvasLine *canvas_line = (CanvasLine *)simple; + + CanvasLinePrivate *priv = GRPT_CANVAS_LINE_GET_PRIVATE (canvas_line); + + from_p.x = canvas_line->x; + from_p.y = canvas_line->y; + to_p.x = canvas_line->x + canvas_line->width; + to_p.y = canvas_line->y + canvas_line->height; + + g_object_get (G_OBJECT (priv->rpt_object_line), + "rotation", &rotation, + "stroke", &stroke, + NULL); + + if (stroke != NULL) + { + /* TO DO */ + /*cairo_set_line_width (priv->cr, stroke.width);*/ + if (stroke->color != NULL) + { + cairo_set_source_rgba (cr, stroke->color->r, stroke->color->g, stroke->color->b, stroke->color->a); + } + if (stroke->style != NULL) + { + gdouble *dash = rpt_common_style_to_array (stroke->style); + cairo_set_dash (cr, dash, stroke->style->len, 0.0); + } + } + else + { + cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0); + } + + if (rotation != NULL) + { + /*RptSize size; + + size.width = to_p->x - from_p->x; + size.height = to_p->y - from_p->y; + + rpt_print_rotate (rpt_print, from_p, &size, rotation->angle);*/ + } + + cairo_move_to (cr, from_p.x, from_p.y); + cairo_line_to (cr, to_p.x, to_p.y); + cairo_stroke (cr); + + if (stroke != NULL && stroke->style != NULL) + { + cairo_set_dash (cr, NULL, 0, 0.0); + } +} + +static gboolean +canvas_line_is_item_at (GooCanvasItemSimple *simple, gdouble x, gdouble y, cairo_t *cr, gboolean is_pointer_event) +{ + CanvasLine *canvas_line = (CanvasLine *)simple; + + if (x < canvas_line->x || x > canvas_line->x + canvas_line->width + || y < canvas_line->y || y > canvas_line->y + canvas_line->height) + { + return FALSE; + } + + return TRUE; +} diff --git a/src/canvasline.h b/src/canvasline.h new file mode 100644 index 0000000..07532e3 --- /dev/null +++ b/src/canvasline.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007 Andrea Zagli + * + * 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 __CANVAS_LINE_H__ +#define __CANVAS_LINE_H__ + +#include +#include +#include + + +G_BEGIN_DECLS + + +#define GRPT_TYPE_CANVAS_LINE (canvas_line_get_type ()) +#define GRPT_CANVAS_LINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRPT_TYPE_CANVAS_LINE, CanvasLine)) +#define GRPT_CANVAS_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRPT_TYPE_CANVAS_LINE, CanvasLineClass)) +#define GRPT_IS_CANVAS_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRPT_TYPE_CANVAS_LINE)) +#define GRPT_IS_CANVAS_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRPT_TYPE_CANVAS_LINE)) +#define GRPT_CANVAS_LINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRPT_TYPE_CANVAS_LINE, CanvasLineClass)) + + +typedef struct _CanvasLine CanvasLine; +typedef struct _CanvasLineClass CanvasLineClass; + +struct _CanvasLine +{ + GooCanvasItemSimple parent; + + gdouble x, y, width, height; +}; + +struct _CanvasLineClass +{ + GooCanvasItemSimpleClass parent_class; +}; + +GType canvas_line_get_type (void) G_GNUC_CONST; + +GooCanvasItem *canvas_line_new (GooCanvasItem *parent, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + RptObjLine *rpt_object_line, + ...); + + +G_END_DECLS + + +#endif /* __CANVAS_LINE_H__ */ diff --git a/src/main.c b/src/main.c index 0a220f6..41f945c 100644 --- a/src/main.c +++ b/src/main.c @@ -19,16 +19,21 @@ #include #include #include -#include #ifdef HAVE_CONFIG_H #include #endif +#include "main.h" +#include "canvas.h" + static gchar *report_filename; static RptReport *rpt_report; +static gint line_counter = 0; + static GtkWidget *w; +static GtkWidget *vbox; static GtkWidget *mnu_file_save; static GtkWidget *mnu_file_save_as; static GtkWidget *mnu_file_close; @@ -38,7 +43,17 @@ static GtkWidget *tbtn_save; static GtkWidget *tbtn_cut; static GtkWidget *tbtn_copy; static GtkWidget *tbtn_paste; +static GtkWidget *handb_tb_objects; +static GtkWidget *rtbtn_select; +static GtkWidget *rtbtn_text; +static GtkWidget *rtbtn_line; +static GtkWidget *rtbtn_rect; +static GtkWidget *rtbtn_ellipse; +static GtkWidget *rtbtn_image; +static Canvas *canvas; + +/* PRIVATE */ static void menu_toolbar_sensitivity () { @@ -53,11 +68,35 @@ menu_toolbar_sensitivity () gtk_widget_set_sensitive (tbtn_cut, sens); gtk_widget_set_sensitive (tbtn_copy, sens); gtk_widget_set_sensitive (tbtn_paste, sens); + + gtk_widget_set_sensitive (handb_tb_objects, sens); +} + +static void +report_set_defaults () +{ + RptSize size; + + /* TO DO */ + /* add a dialog to set default properties */ + + /* page properties */ + size.width = 595; + size.height = 842; + rpt_report_set_page_size (rpt_report, size); + + /* body height */ + rpt_report_set_section_height (rpt_report, RPTREPORT_SECTION_BODY, 100.0); } static void report_close () { + if (canvas != NULL) + { + canvas_free (canvas); + canvas = NULL; + } if (report_filename != NULL) { g_free (report_filename); @@ -73,6 +112,8 @@ report_close () static void report_new () { + GtkWidget *canvas_widget; + report_close (); RptReport *rptr = rpt_report_new (); @@ -83,14 +124,28 @@ report_new () } rpt_report = rptr; + report_set_defaults (); + menu_toolbar_sensitivity (); - gtk_window_set_title (GTK_WINDOW (w), "GRepTool - [new report]"); + objects_tree_fill_tree (rpt_report); + canvas = canvas_new (rpt_report); + + canvas_widget = canvas_get_widget (canvas); + + gtk_container_add (GTK_CONTAINER (vbox), canvas_widget); + gtk_box_reorder_child (GTK_BOX (vbox), canvas_widget, 3); + + gtk_widget_show_all (canvas_widget); + + gtk_window_set_title (GTK_WINDOW (w), "New Report - GRepTool"); } static void report_open_from_file (const gchar *filename) { + GtkWidget *canvas_widget; + RptReport *rptr = rpt_report_new_from_file (filename); if (rptr == NULL) { @@ -104,7 +159,17 @@ report_open_from_file (const gchar *filename) menu_toolbar_sensitivity (); - gtk_window_set_title (GTK_WINDOW (w), g_strdup_printf ("GRepTool - %s", report_filename)); + objects_tree_fill_tree (rpt_report); + canvas = canvas_new (rpt_report); + + canvas_widget = canvas_get_widget (canvas); + + gtk_container_add (GTK_CONTAINER (vbox), canvas_widget); + gtk_box_reorder_child (GTK_BOX (vbox), canvas_widget, 3); + + gtk_widget_show_all (canvas_widget); + + gtk_window_set_title (GTK_WINDOW (w), g_strdup_printf ("%s - GRepTool", report_filename)); } static void @@ -242,6 +307,7 @@ on_mnu_help_about_activate (GtkMenuItem *menuitem, { GladeXML *glaAbout = glade_xml_new (GLADEDIR "/greptool.glade", "diag_about", NULL); GtkWidget *diag = glade_xml_get_widget (glaAbout, "diag_about"); + gtk_dialog_run (GTK_DIALOG (diag)); gtk_widget_destroy (diag); } @@ -274,6 +340,51 @@ on_tbtn_save_clicked (GtkToolButton *toolbutton, } } +/* PUBLIC */ +Tool +get_current_tool () +{ + Tool tool = TOOL_SELECT; + + if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (rtbtn_text))) + { + tool = TOOL_TEXT; + } + else if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (rtbtn_line))) + { + tool = TOOL_LINE; + } + else if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (rtbtn_rect))) + { + tool = TOOL_RECT; + } + else if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (rtbtn_ellipse))) + { + tool = TOOL_ELLIPSE; + } + else if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (rtbtn_image))) + { + tool = TOOL_IMAGE; + } + + return tool; +} + +const gchar +*get_new_object_name (Tool tool) +{ + gchar *ret = NULL; + + switch (tool) + { + case TOOL_LINE: + ret = g_strdup_printf ("line%d", ++line_counter); + break; + } + + return ret; +} + int main (int argc, char **argv) { @@ -286,6 +397,8 @@ main (int argc, char **argv) w = glade_xml_get_widget (glaMain, "w_main"); + vbox = glade_xml_get_widget (glaMain, "vbox"); + mnu_file_save = glade_xml_get_widget (glaMain, "mnu_file_save"); mnu_file_save_as = glade_xml_get_widget (glaMain, "mnu_file_save_as"); mnu_file_close = glade_xml_get_widget (glaMain, "mnu_file_close"); @@ -297,6 +410,14 @@ main (int argc, char **argv) tbtn_copy = glade_xml_get_widget (glaMain, "tbtn_copy"); tbtn_paste = glade_xml_get_widget (glaMain, "tbtn_paste"); + handb_tb_objects = glade_xml_get_widget (glaMain, "handb_tb_objects"); + rtbtn_select = glade_xml_get_widget (glaMain, "rtbtn_select"); + rtbtn_text = glade_xml_get_widget (glaMain, "rtbtn_text"); + rtbtn_line = glade_xml_get_widget (glaMain, "rtbtn_line"); + rtbtn_rect = glade_xml_get_widget (glaMain, "rtbtn_rect"); + rtbtn_ellipse = glade_xml_get_widget (glaMain, "rtbtn_ellipse"); + rtbtn_image = glade_xml_get_widget (glaMain, "rtbtn_image"); + report_filename = NULL; rpt_report = NULL; diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..722bdfb --- /dev/null +++ b/src/main.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007 Andrea Zagli + * + * 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 __MAIN_H__ +#define __MAIN_H__ + + +G_BEGIN_DECLS + + +typedef enum +{ + TOOL_SELECT, + TOOL_TEXT, + TOOL_LINE, + TOOL_RECT, + TOOL_ELLIPSE, + TOOL_IMAGE +} Tool; + +Tool get_current_tool (); + +const gchar *get_new_object_name (Tool tool); + + +G_END_DECLS + + +#endif /* __MAIN_H__ */ diff --git a/src/objects_tree.c b/src/objects_tree.c index f22beeb..576de23 100644 --- a/src/objects_tree.c +++ b/src/objects_tree.c @@ -96,11 +96,20 @@ objects_tree_fill_tree_section (RptReportSection section, GList *objects) } } -static void -objects_tree_fill_tree () +void +objects_tree_fill_tree (RptReport *rpt_report) { GList *objects; + if (w_tree == NULL) return; + + if (rpt_report != NULL) + { + rpt_report_ = rpt_report; + } + + gtk_tree_store_clear (tr_store); + objects = rpt_report_section_get_objects (rpt_report_, RPTREPORT_SECTION_REPORT_HEADER); if (objects != NULL) { @@ -158,7 +167,7 @@ objects_tree (RptReport *rpt_report) selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tr_objects_tree)); - objects_tree_fill_tree (); + objects_tree_fill_tree (NULL); gtk_widget_show_all (w_tree); } @@ -167,4 +176,5 @@ void objects_tree_destroy () { gtk_widget_destroy (w_tree); + w_tree = NULL; }