From: Andrea Zagli Date: Sat, 16 Jun 2007 14:28:56 +0000 (+0000) Subject: Added CanvasRect. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=e585cd0c4303e1e3c8ae5947bc3f21f0ef01c04f;p=reptool%2Fgreptool Added CanvasRect. Some code adjustments. Some new implementations. git-svn-id: svn+ssh://saetta.homelinux.org/svn/greptool/trunk@6 76169498-11ee-428b-941f-28d7a79d5cb2 --- diff --git a/data/greptool/glade/greptool.glade b/data/greptool/glade/greptool.glade index 898f4f4..953d95c 100644 --- a/data/greptool/glade/greptool.glade +++ b/data/greptool/glade/greptool.glade @@ -134,27 +134,71 @@ - + True - _Report Properties - True - - - - - - True - _Page Properties + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Select True - + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _All + True + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _None + True + + + + - + True - _Object Properties + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Properties True - + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + _Page + True + + + + + + True + _Report + True + + + + + + True + _Object + True + + + + + @@ -466,27 +510,40 @@ 4 3 - + True - True + 0 + Provider + + + GTK_FILL + + + + + + True + 0 + Connection String - 1 - 2 1 2 + GTK_FILL - + True + 0 + SQL - 1 - 2 + 2 + 3 GTK_FILL - GTK_FILL + @@ -509,39 +566,26 @@ - + True - 0 - SQL - 2 - 3 + 1 + 2 GTK_FILL - + GTK_FILL - + True - 0 - Connection String + True + 1 + 2 1 2 - GTK_FILL - - - - - - True - 0 - Provider - - - GTK_FILL @@ -579,18 +623,27 @@ 3 3 - + + True + 0 + Height + + + GTK_FILL + + + + + True True - True - True + 1 1 10000 1 10 10 + 1 + 2 1 2 - 1 - 2 - GTK_FILL @@ -608,26 +661,18 @@ - + True True - 1 1 10000 1 10 10 - 1 - 2 + True + 0 + True 1 2 - - - - - - True - 0 - Height - - + 1 + 2 GTK_FILL @@ -642,6 +687,7 @@ True Header True + 0 True @@ -673,18 +719,27 @@ 3 3 - + + True + 0 + Height + + + GTK_FILL + + + + + True True - True - True + 1 1 10000 1 10 10 + 1 + 2 1 2 - 1 - 2 - GTK_FILL @@ -702,26 +757,18 @@ - + True True - 1 1 10000 1 10 10 - 1 - 2 + True + 0 + True 1 2 - - - - - - True - 0 - Height - - + 1 + 2 GTK_FILL @@ -736,6 +783,7 @@ True Footer True + 0 True @@ -763,6 +811,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-cancel True + 0 @@ -774,6 +823,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-ok True + 0 @@ -822,32 +872,35 @@ 3 3 - + 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 + - + 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 True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -857,12 +910,11 @@ Custom 1 2 - 2 - 3 + 1 - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -872,35 +924,33 @@ Custom 1 2 - 1 + 2 + 3 - + 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 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 @@ -943,61 +993,43 @@ Custom 3 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 - 3 - 4 - - - - + 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 - 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 + 0 + Bottom - 1 - 2 + 2 + 3 + GTK_FILL + @@ -1015,43 +1047,61 @@ Custom - + 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 - + 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 1 2 - GTK_FILL - - + 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 + 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 + 3 + 4 @@ -1090,6 +1140,7 @@ Custom GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-cancel True + 0 @@ -1101,6 +1152,7 @@ Custom GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-ok True + 0 diff --git a/src/Makefile.am b/src/Makefile.am index 3c2d981..cf21935 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,4 +15,5 @@ greptool_SOURCES = \ objects_tree.c \ canvas.c \ canvasitem.c \ - canvasline.c + canvasline.c \ + canvasrect.c diff --git a/src/canvas.c b/src/canvas.c index ac8f306..0923ce4 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -18,10 +18,13 @@ #include #include +#include #include "main.h" #include "canvas.h" +#include "canvasitem.h" #include "canvasline.h" +#include "canvasrect.h" static void grpt_canvas_class_init (GRptCanvasClass *klass); static void grpt_canvas_init (GRptCanvas *canvas); @@ -36,12 +39,16 @@ struct _GRptCanvasPrivate RptReport *rpt_report; GtkWidget *scrolledw; - GtkWidget *grpt_canvas; + GtkWidget *goo_canvas; GooCanvasItem *root; GooCanvasItem *selection; + GList *report_header_objects; + GList *page_header_objects; GList *body_objects; + GList *report_footer_objects; + GList *page_footer_objects; gdouble sel_x_start; gdouble sel_y_start; @@ -112,42 +119,67 @@ grpt_canvas_init (GRptCanvas *grpt_canvas) } static void -grpt_canvas_add_object (GRptCanvas *grpt_canvas, RptReportSection section, - gdouble x, gdouble y, gdouble width, gdouble height) +grpt_canvas_add_object (GRptCanvas *grpt_canvas, RptReportSection section, Tool tool, + gdouble x, gdouble y, gdouble width, gdouble height) { GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas); GRptCanvasClass *klass = GRPT_CANVAS_GET_CLASS (grpt_canvas); + RptObject *rpt_object; GRptCanvasItem *item; - switch (priv->tool) + RptPoint position; + RptSize size; + + position.x = x; + position.y = y; + + size.width = width; + size.height = height; + + switch (tool) { case TOOL_LINE: { - RptObject *rpt_object_line; - RptPoint position; - RptSize size; + rpt_object = rpt_obj_line_new (get_new_object_name (priv->tool), position); + rpt_report_add_object_to_section (priv->rpt_report, rpt_object, RPTREPORT_SECTION_BODY); - 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), + g_object_set (G_OBJECT (rpt_object), "size", &size, NULL); item = grpt_canvas_line_new (priv->root, x, y, width, height, - RPT_OBJ_LINE (rpt_object_line), + RPT_OBJ_LINE (rpt_object), NULL); - grpt_canvas_item_set_section (item, RPTREPORT_SECTION_BODY); + } break; + + case TOOL_RECT: + { + rpt_object = rpt_obj_rect_new (get_new_object_name (priv->tool), position); + rpt_report_add_object_to_section (priv->rpt_report, rpt_object, RPTREPORT_SECTION_BODY); + + g_object_set (G_OBJECT (rpt_object), + "size", &size, + NULL); + + item = grpt_canvas_rect_new (priv->root, + x, y, + width, height, + RPT_OBJ_RECT (rpt_object), + NULL); + } + break; + + default: + return; } + grpt_canvas_item_set_section (item, RPTREPORT_SECTION_BODY); + priv->body_objects = g_list_append (priv->body_objects, item); g_signal_emit (grpt_canvas, klass->object_added_signal_id, 0, @@ -157,8 +189,8 @@ grpt_canvas_add_object (GRptCanvas *grpt_canvas, RptReportSection section, /* SIGNALS */ static gboolean grpt_canvas_on_button_press_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) + GdkEventButton *event, + gpointer user_data) { GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE ((GRptCanvas *)user_data); @@ -183,8 +215,8 @@ grpt_canvas_on_button_press_event (GtkWidget *widget, static gboolean grpt_canvas_on_button_release_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) + GdkEventButton *event, + gpointer user_data) { gdouble x; gdouble y; @@ -193,32 +225,66 @@ grpt_canvas_on_button_release_event (GtkWidget *widget, GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE ((GRptCanvas *)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 + if (event->button == 1) { - y = priv->sel_y_start; - height = event->y - y; - } + g_object_set (G_OBJECT (priv->selection), + "visibility", GOO_CANVAS_ITEM_HIDDEN, + NULL); - grpt_canvas_add_object ((GRptCanvas *)user_data, RPTREPORT_SECTION_BODY, x, y, width, height); + 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; + } + + if (priv->tool != TOOL_SELECT) + { + grpt_canvas_add_object ((GRptCanvas *)user_data, RPTREPORT_SECTION_BODY, priv->tool, x, y, width, height); + } + else + { + GooCanvasBounds bound; + GList *objects; + GooCanvasItemSimple *item; + + bound.x1 = x; + bound.y1 = y; + bound.x2 = x + width; + bound.y2 = y + height; + objects = goo_canvas_get_items_in_area (GOO_CANVAS (priv->goo_canvas), + &bound, + TRUE, TRUE, FALSE); + + if (objects != NULL) + { + objects = g_list_first (objects); + } + while (objects != NULL) + { + item = (GooCanvasItemSimple *)objects->data; + + grpt_canvas_item_set_selected (GRPT_CANVAS_ITEM (item), TRUE); + + objects = g_list_next (objects); + } + g_list_free (objects); + } + } return FALSE; } @@ -312,17 +378,17 @@ GRptCanvas fixed = gtk_fixed_new (); gtk_container_add (GTK_CONTAINER (viewport), fixed); - priv->grpt_canvas = goo_canvas_new (); - gtk_fixed_put (GTK_FIXED (fixed), priv->grpt_canvas, 0, 0); + priv->goo_canvas = goo_canvas_new (); + gtk_fixed_put (GTK_FIXED (fixed), priv->goo_canvas, 0, 0); - g_signal_connect (G_OBJECT (priv->grpt_canvas), "button-press-event", + g_signal_connect (G_OBJECT (priv->goo_canvas), "button-press-event", G_CALLBACK (grpt_canvas_on_button_press_event), (gpointer)grpt_canvas); - g_signal_connect (G_OBJECT (priv->grpt_canvas), "button-release-event", + g_signal_connect (G_OBJECT (priv->goo_canvas), "button-release-event", G_CALLBACK (grpt_canvas_on_button_release_event), (gpointer)grpt_canvas); - g_signal_connect (G_OBJECT (priv->grpt_canvas), "motion-notify-event", + g_signal_connect (G_OBJECT (priv->goo_canvas), "motion-notify-event", G_CALLBACK (grpt_canvas_on_motion_notify_event), (gpointer)grpt_canvas); - priv->root = goo_canvas_get_root_item (GOO_CANVAS (priv->grpt_canvas)); + priv->root = goo_canvas_get_root_item (GOO_CANVAS (priv->goo_canvas)); /* setting size */ size = rpt_report_get_page_size (priv->rpt_report); @@ -351,8 +417,8 @@ grpt_canvas_set_size (GRptCanvas *grpt_canvas, RptSize size) { GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas); - gtk_widget_set_size_request (priv->grpt_canvas, size.width, size.height); - goo_canvas_set_bounds (GOO_CANVAS (priv->grpt_canvas), 0, 0, size.width, size.height); + gtk_widget_set_size_request (priv->goo_canvas, size.width, size.height); + goo_canvas_set_bounds (GOO_CANVAS (priv->goo_canvas), 0, 0, size.width, size.height); } GList @@ -364,19 +430,152 @@ GList switch (section) { + case RPTREPORT_SECTION_REPORT_HEADER: + objects = g_list_copy (priv->report_header_objects); + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + objects = g_list_copy (priv->page_header_objects); + break; + case RPTREPORT_SECTION_BODY: objects = g_list_copy (priv->body_objects); break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + objects = g_list_copy (priv->report_footer_objects); + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + objects = g_list_copy (priv->page_footer_objects); + break; } return objects; } +void +grpt_canvas_set_object_selected (GRptCanvas *grpt_canvas, GRptCanvasItem *grpt_canvas_item, gboolean selected, gboolean add_to_selection) +{ + if (selected && !add_to_selection) + { + grpt_canvas_select_none (grpt_canvas); + } + grpt_canvas_item_set_selected (grpt_canvas_item, selected); +} + +void +grpt_canvas_select_all (GRptCanvas *grpt_canvas) +{ + grpt_canvas_select_section_all (grpt_canvas, RPTREPORT_SECTION_REPORT_HEADER, FALSE); + grpt_canvas_select_section_all (grpt_canvas, RPTREPORT_SECTION_PAGE_HEADER, TRUE); + grpt_canvas_select_section_all (grpt_canvas, RPTREPORT_SECTION_BODY, TRUE); + grpt_canvas_select_section_all (grpt_canvas, RPTREPORT_SECTION_REPORT_FOOTER, TRUE); + grpt_canvas_select_section_all (grpt_canvas, RPTREPORT_SECTION_REPORT_HEADER, TRUE); +} + +void +grpt_canvas_select_none (GRptCanvas *grpt_canvas) +{ + grpt_canvas_select_section_none (grpt_canvas, RPTREPORT_SECTION_REPORT_HEADER); + grpt_canvas_select_section_none (grpt_canvas, RPTREPORT_SECTION_PAGE_HEADER); + grpt_canvas_select_section_none (grpt_canvas, RPTREPORT_SECTION_BODY); + grpt_canvas_select_section_none (grpt_canvas, RPTREPORT_SECTION_REPORT_FOOTER); + grpt_canvas_select_section_none (grpt_canvas, RPTREPORT_SECTION_REPORT_HEADER); +} + +void +grpt_canvas_select_section_all (GRptCanvas *grpt_canvas, RptReportSection section, gboolean add_to_selection) +{ + GList *objects = NULL; + + GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas); + + if (!add_to_selection) + { + grpt_canvas_select_section_none (grpt_canvas, section); + } + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + objects = g_list_copy (priv->report_header_objects); + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + objects = g_list_copy (priv->page_header_objects); + break; + + case RPTREPORT_SECTION_BODY: + objects = g_list_copy (priv->body_objects); + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + objects = g_list_copy (priv->report_footer_objects); + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + objects = g_list_copy (priv->page_footer_objects); + break; + } + + if (objects != NULL) + { + objects = g_list_first (objects); + } + while (objects != NULL) + { + grpt_canvas_item_set_selected ((GRptCanvasItem *)objects->data, TRUE); + objects = g_list_next (objects); + } +} + +void +grpt_canvas_select_section_none (GRptCanvas *grpt_canvas, RptReportSection section) +{ + GList *objects = NULL; + + GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas); + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + objects = g_list_copy (priv->report_header_objects); + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + objects = g_list_copy (priv->page_header_objects); + break; + + case RPTREPORT_SECTION_BODY: + objects = g_list_copy (priv->body_objects); + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + objects = g_list_copy (priv->report_footer_objects); + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + objects = g_list_copy (priv->page_footer_objects); + break; + } + + if (objects != NULL) + { + objects = g_list_first (objects); + } + while (objects != NULL) + { + grpt_canvas_item_set_selected ((GRptCanvasItem *)objects->data, FALSE); + objects = g_list_next (objects); + } +} + void grpt_canvas_free (GRptCanvas *grpt_canvas) { GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas); - gtk_widget_destroy (priv->grpt_canvas); + gtk_widget_destroy (priv->goo_canvas); gtk_widget_destroy (priv->scrolledw); } diff --git a/src/canvas.h b/src/canvas.h index b90d94f..2548c53 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -62,7 +62,19 @@ void grpt_canvas_set_size (GRptCanvas *grpt_canvas, RptSize size); GList *grpt_canvas_section_get_objects (GRptCanvas *grpt_canvas, RptReportSection section); -void grpt_canvas_select_object (GRptCanvas *grpt_canvas, GRptCanvasItem *grpt_canvas_item); +void grpt_canvas_set_object_selected (GRptCanvas *grpt_canvas, + GRptCanvasItem *grpt_canvas_item, + gboolean selected, + gboolean add_to_selection); + +void grpt_canvas_select_all (GRptCanvas *grpt_canvas); +void grpt_canvas_select_none (GRptCanvas *grpt_canvas); + +void grpt_canvas_select_section_all (GRptCanvas *grpt_canvas, + RptReportSection section, + gboolean add_to_selection); +void grpt_canvas_select_section_none (GRptCanvas *grpt_canvas, + RptReportSection section); void grpt_canvas_free (GRptCanvas *grpt_canvas); diff --git a/src/canvasitem.c b/src/canvasitem.c index fff451a..f43da85 100644 --- a/src/canvasitem.c +++ b/src/canvasitem.c @@ -25,6 +25,9 @@ static void grpt_canvas_item_init (GRptCanvasItem *grpt_canvas_item); static void grpt_canvas_item_update (GooCanvasItemSimple *simple, cairo_t *cr); +static void grpt_canvas_item_paint (GooCanvasItemSimple *simple, + cairo_t *cr, + const GooCanvasBounds *bounds); static gboolean grpt_canvas_item_is_item_at (GooCanvasItemSimple *simple, gdouble x, gdouble y, @@ -38,6 +41,8 @@ typedef struct _GRptCanvasItemPrivate GRptCanvasItemPrivate; struct _GRptCanvasItemPrivate { RptReportSection section; + + gboolean selected; }; GType @@ -77,16 +82,21 @@ grpt_canvas_item_class_init (GRptCanvasItemClass *klass) g_type_class_add_private (object_class, sizeof (GRptCanvasItemPrivate)); simple_class->simple_update = grpt_canvas_item_update; + simple_class->simple_paint = grpt_canvas_item_paint; simple_class->simple_is_item_at = grpt_canvas_item_is_item_at; } static void grpt_canvas_item_init (GRptCanvasItem *grpt_canvas_item) { + GRptCanvasItemPrivate *priv = GRPT_CANVAS_ITEM_GET_PRIVATE (grpt_canvas_item); + grpt_canvas_item->x = 0.0; grpt_canvas_item->y = 0.0; grpt_canvas_item->width = 0.0; grpt_canvas_item->height = 0.0; + + priv->selected = FALSE; } GooCanvasItem @@ -96,7 +106,6 @@ GooCanvasItem GRptCanvasItem *grpt_canvas_item; const char *first_property; va_list var_args; - GRptCanvasItemPrivate *priv; item = g_object_new (GRPT_TYPE_CANVAS_ITEM, NULL); @@ -152,18 +161,51 @@ grpt_canvas_item_set_section (GRptCanvasItem *grpt_canvas_item, RptReportSection priv->section = section; } +gboolean +grpt_canvas_item_is_selected (GRptCanvasItem *grpt_canvas_item) +{ + GRptCanvasItemPrivate *priv = GRPT_CANVAS_ITEM_GET_PRIVATE (grpt_canvas_item); + + return priv->selected; +} + +void +grpt_canvas_item_set_selected (GRptCanvasItem *grpt_canvas_item, gboolean selected) +{ + GRptCanvasItemPrivate *priv = GRPT_CANVAS_ITEM_GET_PRIVATE (grpt_canvas_item); + + priv->selected = selected; +} + static void grpt_canvas_item_update (GooCanvasItemSimple *simple, cairo_t *cr) { GRptCanvasItem *grpt_canvas_item = (GRptCanvasItem *)simple; - /* Compute the new bounds. */ simple->bounds.x1 = grpt_canvas_item->x; simple->bounds.y1 = grpt_canvas_item->y; simple->bounds.x2 = grpt_canvas_item->x + grpt_canvas_item->width; simple->bounds.y2 = grpt_canvas_item->y + grpt_canvas_item->height; } +static void +grpt_canvas_item_paint (GooCanvasItemSimple *simple, + cairo_t *cr, + const GooCanvasBounds *bounds) +{ + GRptCanvasItem *item = GRPT_CANVAS_ITEM (simple); + GRptCanvasItemPrivate *priv = GRPT_CANVAS_ITEM_GET_PRIVATE (item); + + if (GRPT_CANVAS_ITEM_GET_CLASS (item)->paint) + { + GRPT_CANVAS_ITEM_GET_CLASS (item)->paint (simple, cr, bounds); + } + + if (priv->selected) + { + } +} + static gboolean grpt_canvas_item_is_item_at (GooCanvasItemSimple *simple, gdouble x, gdouble y, cairo_t *cr, gboolean is_pointer_event) { diff --git a/src/canvasitem.h b/src/canvasitem.h index db330f4..7eeeec5 100644 --- a/src/canvasitem.h +++ b/src/canvasitem.h @@ -49,6 +49,10 @@ struct _GRptCanvasItemClass { GooCanvasItemSimpleClass parent_class; + void (*paint) (GooCanvasItemSimple *simple, + cairo_t *cr, + const GooCanvasBounds *bounds); + RptObject *(*get_rpt_object) (GRptCanvasItem *canvas_item); }; @@ -66,6 +70,9 @@ RptObject *grpt_canvas_item_get_rpt_object (GRptCanvasItem *grpt_canvas_item); RptReportSection grpt_canvas_item_get_section (GRptCanvasItem *grpt_canvas_item); void grpt_canvas_item_set_section (GRptCanvasItem *grpt_canvas_item, RptReportSection section); +gboolean grpt_canvas_item_is_selected (GRptCanvasItem *grpt_canvas_item); +void grpt_canvas_item_set_selected (GRptCanvasItem *grpt_canvas_item, gboolean selected); + G_END_DECLS diff --git a/src/canvasline.c b/src/canvasline.c index 867e827..d8cddb9 100644 --- a/src/canvasline.c +++ b/src/canvasline.c @@ -76,8 +76,7 @@ grpt_canvas_line_class_init (GRptCanvasLineClass *klass) g_type_class_add_private (object_class, sizeof (GRptCanvasLinePrivate)); - simple_class->simple_paint = grpt_canvas_line_paint; - + canvas_item_class->paint = grpt_canvas_line_paint; canvas_item_class->get_rpt_object = grpt_canvas_line_get_rpt_object; } diff --git a/src/canvasrect.c b/src/canvasrect.c new file mode 100644 index 0000000..bc07561 --- /dev/null +++ b/src/canvasrect.c @@ -0,0 +1,194 @@ +/* + * 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 "canvasrect.h" + + +static void grpt_canvas_rect_class_init (GRptCanvasRectClass *klass); +static void grpt_canvas_rect_init (GRptCanvasRect *grpt_canvas_rect); + + +static void grpt_canvas_rect_paint (GooCanvasItemSimple *simple, + cairo_t *cr, + const GooCanvasBounds *bounds); + +static RptObject *grpt_canvas_rect_get_rpt_object (GRptCanvasItem *grpt_canvas_item); + + +#define GRPT_CANVAS_RECT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GRPT_TYPE_CANVAS_RECT, GRptCanvasRectPrivate)) + + +typedef struct _GRptCanvasRectPrivate GRptCanvasRectPrivate; +struct _GRptCanvasRectPrivate + { + RptObjRect *rpt_object_rect; + }; + +GType +grpt_canvas_rect_get_type (void) +{ + static GType grpt_canvas_rect_type = 0; + + if (!grpt_canvas_rect_type) + { + static const GTypeInfo grpt_canvas_rect_info = + { + sizeof (GRptCanvasRectClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) grpt_canvas_rect_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GRptCanvasRect), + 0, /* n_preallocs */ + (GInstanceInitFunc) grpt_canvas_rect_init, + NULL + }; + + grpt_canvas_rect_type = g_type_register_static (GRPT_TYPE_CANVAS_ITEM, "GRptCanvasRect", + &grpt_canvas_rect_info, 0); + } + + return grpt_canvas_rect_type; +} + +static void +grpt_canvas_rect_class_init (GRptCanvasRectClass *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 (GRptCanvasRectPrivate)); + + simple_class->simple_paint = grpt_canvas_rect_paint; + + canvas_item_class->get_rpt_object = grpt_canvas_rect_get_rpt_object; +} + +static void +grpt_canvas_rect_init (GRptCanvasRect *grpt_canvas_rect) +{ +} + +GRptCanvasItem +*grpt_canvas_rect_new (GooCanvasItem *parent, gdouble x, gdouble y, gdouble width, gdouble height, RptObjRect *rpt_object_rect, ...) +{ + GRptCanvasItem *item; + GRptCanvasRect *grpt_canvas_rect; + const char *first_property; + va_list var_args; + GRptCanvasRectPrivate *priv; + + item = g_object_new (GRPT_TYPE_CANVAS_RECT, NULL); + item->x = x; + item->y = y; + item->width = width; + item->height = height; + + grpt_canvas_rect = (GRptCanvasRect *)item; + + priv = GRPT_CANVAS_RECT_GET_PRIVATE (grpt_canvas_rect); + priv->rpt_object_rect = g_object_ref (rpt_object_rect); + + va_start (var_args, rpt_object_rect); + 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); + } + + return item; +} + +static void +grpt_canvas_rect_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; + + GRptCanvasRect *grpt_canvas_rect = (GRptCanvasRect *)simple; + + GRptCanvasItem *grpt_canvas_item = (GRptCanvasItem *)simple; + + GRptCanvasRectPrivate *priv = GRPT_CANVAS_RECT_GET_PRIVATE (grpt_canvas_rect); + + g_object_get (G_OBJECT (priv->rpt_object_rect), + "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_rect_get_rpt_object (GRptCanvasItem *grpt_canvas_item) +{ + GRptCanvasRectPrivate *priv = GRPT_CANVAS_RECT_GET_PRIVATE (GRPT_CANVAS_RECT (grpt_canvas_item)); + + return RPT_OBJECT (priv->rpt_object_rect); +} diff --git a/src/canvasrect.h b/src/canvasrect.h new file mode 100644 index 0000000..e03063a --- /dev/null +++ b/src/canvasrect.h @@ -0,0 +1,66 @@ +/* + * 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 __GRPT_CANVAS_RECT_H__ +#define __GRPT_CANVAS_RECT_H__ + +#include +#include + +#include "canvasitem.h" + + +G_BEGIN_DECLS + + +#define GRPT_TYPE_CANVAS_RECT (grpt_canvas_rect_get_type ()) +#define GRPT_CANVAS_RECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRPT_TYPE_CANVAS_RECT, GRptCanvasRect)) +#define GRPT_CANVAS_RECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRPT_TYPE_CANVAS_RECT, GRptCanvasRectClass)) +#define GRPT_IS_CANVAS_RECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRPT_TYPE_CANVAS_RECT)) +#define GRPT_IS_CANVAS_RECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRPT_TYPE_CANVAS_RECT)) +#define GRPT_CANVAS_RECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRPT_TYPE_CANVAS_RECT, GRptCanvasRectClass)) + + +typedef struct _GRptCanvasRect GRptCanvasRect; +typedef struct _GRptCanvasRectClass GRptCanvasRectClass; + +struct _GRptCanvasRect +{ + GRptCanvasItem parent; +}; + +struct _GRptCanvasRectClass +{ + GRptCanvasItemClass parent_class; +}; + +GType grpt_canvas_rect_get_type (void) G_GNUC_CONST; + +GRptCanvasItem *grpt_canvas_rect_new (GooCanvasItem *parent, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + RptObjRect *rpt_object_rect, + ...); + + +G_END_DECLS + + +#endif /* __GRPT_CANVAS_RECT_H__ */ diff --git a/src/main.c b/src/main.c index d0aceb3..c1029b8 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,7 @@ static gchar *report_filename; static RptReport *rpt_report; static gint line_counter = 0; +static gint rect_counter = 0; static GtkWidget *w; static GtkWidget *vbox; @@ -414,6 +415,10 @@ const gchar case TOOL_LINE: ret = g_strdup_printf ("line%d", ++line_counter); break; + + case TOOL_RECT: + ret = g_strdup_printf ("rect%d", ++rect_counter); + break; } return ret; diff --git a/src/objects_tree.c b/src/objects_tree.c index 363a885..5e100f4 100644 --- a/src/objects_tree.c +++ b/src/objects_tree.c @@ -49,7 +49,11 @@ struct _GRptObjectsTreePrivate GtkTreeStore *tr_store; GtkTreeSelection *selection; + GtkTreeRowReference *trr_report_header; + GtkTreeRowReference *trr_page_header; GtkTreeRowReference *trr_body; + GtkTreeRowReference *trr_report_footer; + GtkTreeRowReference *trr_page_footer; }; GType @@ -101,31 +105,44 @@ grpt_objects_tree_create_tree_section (GRptObjectsTree *grpt_objects_tree, RptRe { GtkTreeIter iter; gchar *name = NULL; + GtkTreeRowReference *trr; GRptObjectsTreePrivate *priv = GRPT_OBJECTS_TREE_GET_PRIVATE (grpt_objects_tree); switch (section) { case RPTREPORT_SECTION_REPORT_HEADER: - name = g_strdup ("Report Header"); + if (priv->trr_report_header == NULL) + { + name = g_strdup ("Report Header"); + } break; case RPTREPORT_SECTION_PAGE_HEADER: - name = g_strdup ("Page Header"); + if (priv->trr_page_header == NULL) + { + name = g_strdup ("Page Header"); + } break; - case RPTREPORT_SECTION_REPORT_FOOTER: - name = g_strdup ("Report Footer"); + case RPTREPORT_SECTION_BODY: + if (priv->trr_body == NULL) + { + name = g_strdup ("Body"); + } break; - case RPTREPORT_SECTION_PAGE_FOOTER: - name = g_strdup ("Page Footer"); + case RPTREPORT_SECTION_REPORT_FOOTER: + if (priv->trr_report_footer == NULL) + { + name = g_strdup ("Report Footer"); + } break; - case RPTREPORT_SECTION_BODY: - if (priv->trr_body == NULL) + case RPTREPORT_SECTION_PAGE_FOOTER: + if (priv->trr_page_footer == NULL) { - name = g_strdup ("Body"); + name = g_strdup ("Page Footer"); } break; } @@ -137,10 +154,33 @@ grpt_objects_tree_create_tree_section (GRptObjectsTree *grpt_objects_tree, RptRe OBJS_TREE_COL_NAME, name, OBJS_TREE_COL_SECTION, section, -1); - - priv->trr_body = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->tr_store), - gtk_tree_model_get_path (GTK_TREE_MODEL (priv->tr_store), - &iter)); + + trr = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->tr_store), + gtk_tree_model_get_path (GTK_TREE_MODEL (priv->tr_store), + &iter)); + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + priv->trr_report_header = trr; + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + priv->trr_page_header = trr; + break; + + case RPTREPORT_SECTION_BODY: + priv->trr_body = trr; + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + priv->trr_report_footer = trr; + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + priv->trr_page_footer = trr; + break; + } } } @@ -274,9 +314,25 @@ grpt_objects_tree_add_object_to_section (GRptObjectsTree *grpt_objects_tree, switch (section) { + case RPTREPORT_SECTION_REPORT_HEADER: + trr = priv->trr_report_header; + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + trr = priv->trr_page_header; + break; + case RPTREPORT_SECTION_BODY: trr = priv->trr_body; break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + trr = priv->trr_report_footer; + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + trr = priv->trr_page_footer; + break; } path = gtk_tree_row_reference_get_path (trr);