diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2011-12-16 21:03:31 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2011-12-16 21:03:31 +0000 |
| commit | 8a8d0dacce18cf93f3c808199a6125c0132bdb33 (patch) | |
| tree | 22db3e6f988e7666480dc664c01ebffe51ece4f2 /src | |
| parent | Extensions. convert2dashes. delete 'stroke-dasharray' attribute in style (Bug... (diff) | |
| parent | - Dropped deprecated sp_window_new (diff) | |
| download | inkscape-8a8d0dacce18cf93f3c808199a6125c0132bdb33.tar.gz inkscape-8a8d0dacce18cf93f3c808199a6125c0132bdb33.zip | |
- SPAttributeWidget and SPAttributeTable C++ified
- fixed memory leak with item properties (old instances of item properties window were not destroyed)
(bzr r10775)
Diffstat (limited to 'src')
36 files changed, 425 insertions, 808 deletions
diff --git a/src/conn-avoid-ref.h b/src/conn-avoid-ref.h index f99d1f0cb..89e86ded7 100644 --- a/src/conn-avoid-ref.h +++ b/src/conn-avoid-ref.h @@ -13,12 +13,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <glib.h> +#include <glib/gslist.h> #include <stddef.h> #include <sigc++/connection.h> -struct SPDesktop; -struct SPItem; +class SPDesktop; +class SPItem; struct ConnectionPoint; typedef std::map<int, ConnectionPoint> IdConnectionPointMap; namespace Avoid { class ShapeRef; } diff --git a/src/context-fns.h b/src/context-fns.h index c56c67a27..12d6e6194 100644 --- a/src/context-fns.h +++ b/src/context-fns.h @@ -14,8 +14,8 @@ #include <gdk/gdk.h> #include <2geom/forward.h> -struct SPDesktop; -struct SPItem; +class SPDesktop; +class SPItem; struct SPEventContext; const double goldenratio = 1.61803398874989484820; // golden ratio diff --git a/src/desktop-events.h b/src/desktop-events.h index e573fc878..cac7e089f 100644 --- a/src/desktop-events.h +++ b/src/desktop-events.h @@ -16,9 +16,9 @@ #include <gdk/gdk.h> #include <gtk/gtk.h> -class SPDesktop; -class SPDesktopWidget; -class SPCanvasItem; +class SPDesktop; +class SPDesktopWidget; +struct SPCanvasItem; /* Item handlers */ diff --git a/src/desktop-style.h b/src/desktop-style.h index 3719c2a9e..81485420b 100644 --- a/src/desktop-style.h +++ b/src/desktop-style.h @@ -17,8 +17,8 @@ class ColorRGBA; struct SPCSSAttr; -struct SPDesktop; -struct SPObject; +class SPDesktop; +class SPObject; struct SPStyle; namespace Inkscape { namespace XML { diff --git a/src/desktop.h b/src/desktop.h index 8921f45b8..b466fff15 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -44,9 +44,9 @@ struct SPCanvas; struct SPCanvasItem; struct SPCanvasGroup; struct SPEventContext; -struct SPItem; +class SPItem; struct SPNamedView; -struct SPObject; +class SPObject; struct SPStyle; typedef struct _DocumentInterface DocumentInterface;//struct DocumentInterface; diff --git a/src/dialogs/item-properties.cpp b/src/dialogs/item-properties.cpp index 4ca2b2753..2e805c14e 100644 --- a/src/dialogs/item-properties.cpp +++ b/src/dialogs/item-properties.cpp @@ -7,8 +7,9 @@ * bulia byak <buliabyak@users.sf.net> * Johan Engelen <goejendaagh@zonnet.nl> * Abhishek Sharma + * Kris De Gussem <Kris.DeGussem@gmail.com> * - * Copyright (C) 1999-2006 Authors + * Copyright (C) 1999-2011 Authors * Copyright (C) 2001 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -18,11 +19,11 @@ # include "config.h" #endif #include <gtk/gtk.h> +#include <glibmm/i18n.h> #include "../desktop-handles.h" #include "dialog-events.h" #include "../document.h" -#include <glibmm/i18n.h> #include "../helper/window.h" #include "../inkscape.h" #include "../interface.h" @@ -39,6 +40,7 @@ using Inkscape::DocumentUndo; #define MIN_ONSCREEN_DISTANCE 50 static GtkWidget *dlg = NULL; +static SPAttributeTable* attrTable = NULL; static win_data wd; // impossible original values to make sure they are read from prefs @@ -52,16 +54,18 @@ static void sp_item_widget_sensitivity_toggled (GtkWidget *widget, SPWidget *spw static void sp_item_widget_hidden_toggled (GtkWidget *widget, SPWidget *spw); static void sp_item_widget_label_changed (GtkWidget *widget, SPWidget *spw); -static void -sp_item_dialog_destroy( GtkObject */*object*/, gpointer /*data*/ ) +static void sp_item_dialog_destroy( GtkObject */*object*/, gpointer /*data*/ ) { + if (attrTable) + { + delete attrTable; + } sp_signal_disconnect_by_data (INKSCAPE, dlg); wd.win = dlg = NULL; wd.stop = 0; } -static gboolean -sp_item_dialog_delete( GtkObject */*object*/, GdkEvent */*event*/, gpointer /*data*/ ) +static gboolean sp_item_dialog_delete( GtkObject */*object*/, GdkEvent */*event*/, gpointer /*data*/ ) { gtk_window_get_position ((GtkWindow *) dlg, &x, &y); gtk_window_get_size ((GtkWindow *) dlg, &w, &h); @@ -246,8 +250,7 @@ GtkWidget *sp_item_widget_new(void) -static void -sp_item_widget_modify_selection( SPWidget *spw, +static void sp_item_widget_modify_selection( SPWidget *spw, Inkscape::Selection *selection, guint /*flags*/, GtkWidget */*itemw*/ ) @@ -257,8 +260,7 @@ sp_item_widget_modify_selection( SPWidget *spw, -static void -sp_item_widget_change_selection ( SPWidget *spw, +static void sp_item_widget_change_selection ( SPWidget *spw, Inkscape::Selection *selection, GtkWidget */*itemw*/ ) { @@ -352,29 +354,34 @@ static void sp_item_widget_setup( SPWidget *spw, Inkscape::Selection *selection w = GTK_WIDGET(g_object_get_data(G_OBJECT(spw), "interactivity")); GtkWidget* int_table = GTK_WIDGET(g_object_get_data(G_OBJECT(spw), "interactivity_table")); - if (int_table){ - gtk_container_remove(GTK_CONTAINER(w), int_table); - } - - const gchar* int_labels[10] = {"onclick", "onmouseover", "onmouseout", "onmousedown", "onmouseup", "onmousemove","onfocusin", "onfocusout", "onactivate", "onload"}; - - int_table = sp_attribute_table_new (obj, 10, int_labels, int_labels); - gtk_widget_show_all (int_table); - g_object_set_data(G_OBJECT(spw), "interactivity_table", int_table); - - gtk_container_add (GTK_CONTAINER (w), int_table); + std::vector<Glib::ustring> int_labels; + int_labels.push_back("onclick"); + int_labels.push_back("onmouseover"); + int_labels.push_back("onmouseout"); + int_labels.push_back("onmousedown"); + int_labels.push_back("onmouseup"); + int_labels.push_back("onmousemove"); + int_labels.push_back("onfocusin"); + int_labels.push_back("onfocusout"); + int_labels.push_back("onfocusout"); + int_labels.push_back("onload"); + + if (attrTable) + { + delete(attrTable); + } + attrTable = new SPAttributeTable (obj, int_labels, int_labels, w); + attrTable->show_all(); + g_object_set_data(G_OBJECT(spw), "interactivity_table", (GtkWidget*) attrTable->gobj()); } g_object_set_data (G_OBJECT (spw), "blocked", GUINT_TO_POINTER (FALSE)); - - } // end of sp_item_widget_setup() -static void -sp_item_widget_sensitivity_toggled (GtkWidget *widget, SPWidget *spw) +static void sp_item_widget_sensitivity_toggled (GtkWidget *widget, SPWidget *spw) { if (g_object_get_data(G_OBJECT (spw), "blocked")) return; @@ -392,8 +399,7 @@ sp_item_widget_sensitivity_toggled (GtkWidget *widget, SPWidget *spw) g_object_set_data (G_OBJECT (spw), "blocked", GUINT_TO_POINTER (FALSE)); } -void -sp_item_widget_hidden_toggled(GtkWidget *widget, SPWidget *spw) +void sp_item_widget_hidden_toggled(GtkWidget *widget, SPWidget *spw) { if (g_object_get_data(G_OBJECT (spw), "blocked")) return; @@ -411,8 +417,7 @@ sp_item_widget_hidden_toggled(GtkWidget *widget, SPWidget *spw) g_object_set_data (G_OBJECT (spw), "blocked", GUINT_TO_POINTER (FALSE)); } -static void -sp_item_widget_label_changed( GtkWidget */*widget*/, SPWidget *spw ) +static void sp_item_widget_label_changed( GtkWidget */*widget*/, SPWidget *spw ) { if (g_object_get_data(G_OBJECT (spw), "blocked")) return; @@ -490,8 +495,9 @@ void sp_item_dialog(void) gchar title[500]; sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_ITEM), title); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - dlg = sp_window_new (title, TRUE); + + Gtk::Window* window = Inkscape::UI::window_new (title, true); + dlg = (GtkWidget*)window->gobj(); if (x == -1000 || y == -1000) { x = prefs->getInt(prefs_path + "x", -1000); y = prefs->getInt(prefs_path + "y", -1000); @@ -501,9 +507,6 @@ void sp_item_dialog(void) h = prefs->getInt(prefs_path + "h", 0); } -// if (x<0) x=0; -// if (y<0) y=0; - if (w && h) { gtk_window_resize ((GtkWindow *) dlg, w, h); } @@ -513,24 +516,22 @@ void sp_item_dialog(void) gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER); } - sp_transientize (dlg); wd.win = dlg; wd.stop = 0; - g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd); + g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd); g_signal_connect ( G_OBJECT (dlg), "event", G_CALLBACK (sp_dialog_event_handler), dlg); g_signal_connect ( G_OBJECT (dlg), "destroy", G_CALLBACK (sp_item_dialog_destroy), dlg); g_signal_connect ( G_OBJECT (dlg), "delete_event", G_CALLBACK (sp_item_dialog_delete), dlg); - g_signal_connect ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (sp_item_dialog_delete), dlg); - g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg); - g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg); + g_signal_connect ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (sp_item_dialog_delete), dlg); + g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg); + g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg); // Dialog-specific stuff GtkWidget *itemw = sp_item_widget_new (); gtk_widget_show (itemw); gtk_container_add (GTK_CONTAINER (dlg), itemw); - } gtk_window_present ((GtkWindow *) dlg); diff --git a/src/dialogs/object-attributes.cpp b/src/dialogs/object-attributes.cpp index f83d3ef1f..0511ebb3a 100644 --- a/src/dialogs/object-attributes.cpp +++ b/src/dialogs/object-attributes.cpp @@ -5,8 +5,9 @@ /* Authors: * Lauris Kaplinski <lauris@kaplinski.com> * bulia byak <buliabyak@users.sf.net> + * Kris De Gussem <Kris.DeGussem@gmail.com> * - * Copyright (C) 1999-2005 Authors + * Copyright (C) 1999-2011 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -66,41 +67,16 @@ static const SPAttrDesc image_nohref_desc[] = { }; -static void object_released( SPObject */*object*/, GtkWidget *widget ) -{ - gtk_widget_destroy (widget); -} - - - -static void window_destroyed( GtkObject *window, GtkObject */*object*/ ) -{ - sigc::connection *release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(window), "release_connection"); - release_connection->disconnect(); - delete release_connection; -} - - - static void sp_object_attr_show_dialog ( SPObject *object, const SPAttrDesc *desc, const gchar *tag ) { - const gchar **labels, **attrs; - gint len, i; + int len; + Gtk::Window *window; + SPAttributeTable* t; Glib::ustring title; - GtkWidget *w, *t; - - len = 0; - while (desc[len].label) len += 1; - - labels = (const gchar **) new gchar* [len]; - attrs = (const gchar **) new gchar* [len]; - - for (i = 0; i < len; i++) { - labels[i] = desc[i].label; - attrs[i] = desc[i].attribute; - } + std::vector<Glib::ustring> labels; + std::vector<Glib::ustring> attrs; if (!strcmp (tag, "Link")) { title = _("Link Properties"); @@ -110,26 +86,21 @@ static void sp_object_attr_show_dialog ( SPObject *object, title = Glib::ustring::compose(_("%1 Properties"), tag); } - w = sp_window_new (title.c_str(), TRUE); - - t = sp_attribute_table_new (object, len, labels, attrs); - gtk_widget_show (t); - gtk_container_add (GTK_CONTAINER (w), t); - delete labels; - delete attrs; - - g_signal_connect ( G_OBJECT (w), "destroy", - G_CALLBACK (window_destroyed), object ); - - sigc::connection *release_connection = new sigc::connection(); - *release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&object_released), w)); - g_object_set_data(G_OBJECT(w), "release_connection", release_connection); - - gtk_widget_show (w); + len = 0; + while (desc[len].label) + { + labels.push_back(desc[len].label); + attrs.push_back (desc[len].attribute); + len += 1; + } + + window = Inkscape::UI::window_new (title.c_str(), true); + t = new SPAttributeTable (object, labels, attrs, (GtkWidget*)window->gobj()); + t->show(); + window->show(); } // end of sp_object_attr_show_dialog() - void sp_object_attributes_dialog (SPObject *object, const gchar *tag) { g_return_if_fail (object != NULL); diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index e63d660fe..1f8bad51d 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -24,7 +24,7 @@ #include "canvas-grid.h" -struct SPDesktop; +class SPDesktop; struct SPNamedView; namespace Inkscape { diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 10feeca0e..f7cc3c032 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -24,10 +24,10 @@ #include "snapper.h" #include "line-snapper.h" -struct SPDesktop; +class SPDesktop; struct SPNamedView; struct SPCanvasBuf; -class SPDocument; +class SPDocument; namespace Inkscape { diff --git a/src/display/canvas-text.h b/src/display/canvas-text.h index 85333d84e..90c02717c 100644 --- a/src/display/canvas-text.h +++ b/src/display/canvas-text.h @@ -16,8 +16,8 @@ #include "sp-canvas-item.h" -struct SPItem; -struct SPDesktop; +class SPItem; +class SPDesktop; #define SP_TYPE_CANVASTEXT (sp_canvastext_get_type ()) #define SP_CANVASTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_CANVASTEXT, SPCanvasText)) diff --git a/src/display/gnome-canvas-acetate.cpp b/src/display/gnome-canvas-acetate.cpp index bdda3a120..544efe61f 100644 --- a/src/display/gnome-canvas-acetate.cpp +++ b/src/display/gnome-canvas-acetate.cpp @@ -25,8 +25,7 @@ static double sp_canvas_acetate_point (SPCanvasItem *item, Geom::Point p, SPCanv static SPCanvasItemClass *parent_class; -GType -sp_canvas_acetate_get_type (void) +GType sp_canvas_acetate_get_type (void) { static GType acetate_type = 0; if (!acetate_type) { @@ -45,8 +44,7 @@ sp_canvas_acetate_get_type (void) return acetate_type; } -static void -sp_canvas_acetate_class_init (SPCanvasAcetateClass *klass) +static void sp_canvas_acetate_class_init (SPCanvasAcetateClass *klass) { GtkObjectClass *object_class; SPCanvasItemClass *item_class; @@ -62,14 +60,12 @@ sp_canvas_acetate_class_init (SPCanvasAcetateClass *klass) item_class->point = sp_canvas_acetate_point; } -static void -sp_canvas_acetate_init (SPCanvasAcetate */*acetate*/) +static void sp_canvas_acetate_init (SPCanvasAcetate */*acetate*/) { /* Nothing here */ } -static void -sp_canvas_acetate_destroy (GtkObject *object) +static void sp_canvas_acetate_destroy (GtkObject *object) { SPCanvasAcetate *acetate; @@ -82,8 +78,7 @@ sp_canvas_acetate_destroy (GtkObject *object) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } -static void -sp_canvas_acetate_update( SPCanvasItem *item, Geom::Affine const &/*affine*/, unsigned int /*flags*/ ) +static void sp_canvas_acetate_update( SPCanvasItem *item, Geom::Affine const &/*affine*/, unsigned int /*flags*/ ) { item->x1 = -G_MAXINT; item->y1 = -G_MAXINT; @@ -91,8 +86,7 @@ sp_canvas_acetate_update( SPCanvasItem *item, Geom::Affine const &/*affine*/, un item->y2 = G_MAXINT; } -static double -sp_canvas_acetate_point( SPCanvasItem *item, Geom::Point /*p*/, SPCanvasItem **actual_item ) +static double sp_canvas_acetate_point( SPCanvasItem *item, Geom::Point /*p*/, SPCanvasItem **actual_item ) { *actual_item = item; diff --git a/src/display/sp-ctrlline.h b/src/display/sp-ctrlline.h index eeed7e75d..4bfe50a77 100644 --- a/src/display/sp-ctrlline.h +++ b/src/display/sp-ctrlline.h @@ -16,7 +16,7 @@ #include "sp-canvas-item.h" -struct SPItem; +class SPItem; #define SP_TYPE_CTRLLINE (sp_ctrlline_get_type ()) #define SP_CTRLLINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_CTRLLINE, SPCtrlLine)) diff --git a/src/display/sp-ctrlpoint.h b/src/display/sp-ctrlpoint.h index 907f74bf8..a7a5475b7 100644 --- a/src/display/sp-ctrlpoint.h +++ b/src/display/sp-ctrlpoint.h @@ -14,7 +14,7 @@ #include "sp-canvas-item.h" -struct SPItem; +class SPItem; #define SP_TYPE_CTRLPOINT (sp_ctrlpoint_get_type ()) #define SP_CTRLPOINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_CTRLPOINT, SPCtrlPoint)) diff --git a/src/document.h b/src/document.h index efb14123a..b799cb832 100644 --- a/src/document.h +++ b/src/document.h @@ -39,8 +39,8 @@ class Router; } struct SPDesktop; -struct SPItem; -struct SPObject; +class SPItem; +class SPObject; struct SPGroup; struct SPRoot; struct SPUnit; diff --git a/src/event-context.h b/src/event-context.h index 1c9f46a46..1e641e6ef 100644 --- a/src/event-context.h +++ b/src/event-context.h @@ -20,9 +20,9 @@ #include "preferences.h" struct GrDrag; -struct SPDesktop; -struct SPItem; -class ShapeEditor; +class SPDesktop; +class SPItem; +class ShapeEditor; struct SPEventContext; namespace Inkscape { diff --git a/src/gradient-drag.h b/src/gradient-drag.h index cb3f13e71..8aa9a6550 100644 --- a/src/gradient-drag.h +++ b/src/gradient-drag.h @@ -24,12 +24,12 @@ #include "knot-enums.h" -struct SPItem; struct SPKnot; class SPDesktop; class SPCSSAttr; class SPLinearGradient; +class SPItem; class SPObject; class SPRadialGradient; class SPStop; diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h index e708486ca..5422e6d1b 100644 --- a/src/knot-holder-entity.h +++ b/src/knot-holder-entity.h @@ -19,7 +19,7 @@ #include <2geom/forward.h> #include "snapper.h" -struct SPItem; +class SPItem; struct SPKnot; class SPDesktop; diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 91d09fef6..48577c225 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -21,13 +21,13 @@ struct SPDocument; struct SPDesktop; -struct SPItem; -class SPNodeContext; +class SPItem; +class SPNodeContext; struct LivePathEffectObject; -class SPLPEItem; -class KnotHolder; -class KnotHolderEntity; -class SPPath; +class SPLPEItem; +class KnotHolder; +class KnotHolderEntity; +class SPPath; struct SPCurve; namespace Gtk { diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index fe93e8dca..92c2c8b41 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -15,8 +15,8 @@ class KnotHolder; class SPLPEItem; -struct SPDesktop; -struct SPItem; +class SPDesktop; +class SPItem; namespace Gtk { class Widget; diff --git a/src/object-snapper.h b/src/object-snapper.h index d51cade93..59e2f10ce 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -16,8 +16,8 @@ #include "snap-candidate.h" struct SPNamedView; -struct SPItem; -struct SPObject; +class SPItem; +class SPObject; namespace Inkscape { diff --git a/src/rubberband.h b/src/rubberband.h index 1b71f9ae2..fbebe2b08 100644 --- a/src/rubberband.h +++ b/src/rubberband.h @@ -17,10 +17,10 @@ /* fixme: do multidocument safe */ -class CtrlRect; -class SPCanvasItem; -class SPCurve; -class SPDesktop; +class CtrlRect; +struct SPCanvasItem; +class SPCurve; +class SPDesktop; enum { RUBBERBAND_MODE_RECT, diff --git a/src/selcue.h b/src/selcue.h index 0869a597d..f62ef768a 100644 --- a/src/selcue.h +++ b/src/selcue.h @@ -17,8 +17,8 @@ #include <stddef.h> #include <sigc++/sigc++.h> -class SPDesktop; -class SPCanvasItem; +class SPDesktop; +struct SPCanvasItem; namespace Inkscape { diff --git a/src/seltrans.h b/src/seltrans.h index 3804caef3..122e7a522 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -27,9 +27,9 @@ #include "sp-item.h" struct SPKnot; -class SPDesktop; -class SPCanvasItem; -class SPSelTransHandle; +class SPDesktop; +struct SPCanvasItem; +class SPSelTransHandle; namespace Inkscape { diff --git a/src/snap-candidate.h b/src/snap-candidate.h index 1c5cf3234..5f17c8572 100644 --- a/src/snap-candidate.h +++ b/src/snap-candidate.h @@ -17,7 +17,7 @@ //#include "snapped-point.h" #include "snap-enums.h" -struct SPItem; // forward declaration +class SPItem; // forward declaration namespace Inkscape { diff --git a/src/snapper.h b/src/snapper.h index f5fbd4fdc..78d32c12c 100644 --- a/src/snapper.h +++ b/src/snapper.h @@ -31,7 +31,7 @@ struct IntermSnapResults { }; class SnapManager; -struct SPItem; +class SPItem; namespace Inkscape { diff --git a/src/sp-shape.h b/src/sp-shape.h index 014158b21..c5e9588b3 100644 --- a/src/sp-shape.h +++ b/src/sp-shape.h @@ -31,7 +31,7 @@ #define SP_SHAPE_WRITE_PATH (1 << 2) -struct SPDesktop; +class SPDesktop; namespace Inkscape { diff --git a/src/splivarot.h b/src/splivarot.h index 40089ad71..9dc596888 100644 --- a/src/splivarot.h +++ b/src/splivarot.h @@ -11,7 +11,7 @@ #include <2geom/forward.h> #include <2geom/path.h> class SPCurve; -struct SPItem; +class SPItem; // boolean operations // work on the current selection diff --git a/src/svg-view.h b/src/svg-view.h index 33a9b569a..aaaa8a9a5 100644 --- a/src/svg-view.h +++ b/src/svg-view.h @@ -14,7 +14,7 @@ #include "ui/view/view.h" class SPCanvasGroup; -class SPCanvasItem; +struct SPCanvasItem; /** diff --git a/src/text-editing.h b/src/text-editing.h index c0f104dec..37527d385 100644 --- a/src/text-editing.h +++ b/src/text-editing.h @@ -18,9 +18,9 @@ #include "libnrtype/Layout-TNG.h" #include "text-tag-attributes.h" -class SPCSSAttr; -struct SPItem; -struct SPObject; +class SPCSSAttr; +class SPItem; +class SPObject; struct SPStyle; typedef std::pair<Inkscape::Text::Layout::iterator, Inkscape::Text::Layout::iterator> iterator_pair; diff --git a/src/trace/trace.h b/src/trace/trace.h index 29b8716ee..a7fbe0cc8 100644 --- a/src/trace/trace.h +++ b/src/trace/trace.h @@ -27,7 +27,7 @@ #include <sp-shape.h> struct SPImage; -struct SPItem; +class SPItem; namespace Inkscape { diff --git a/src/ui/dialog/calligraphic-profile-rename.h b/src/ui/dialog/calligraphic-profile-rename.h index e9f6a8b95..f0eb0b491 100644 --- a/src/ui/dialog/calligraphic-profile-rename.h +++ b/src/ui/dialog/calligraphic-profile-rename.h @@ -15,7 +15,7 @@ #include <gtkmm/entry.h> #include <gtkmm/label.h> #include <gtkmm/table.h> -struct SPDesktop; +class SPDesktop; namespace Inkscape { namespace UI { diff --git a/src/ui/dialog/icon-preview.h b/src/ui/dialog/icon-preview.h index 9c10eb89b..ec4b3cac4 100644 --- a/src/ui/dialog/icon-preview.h +++ b/src/ui/dialog/icon-preview.h @@ -26,7 +26,7 @@ #include "ui/widget/panel.h" #include "desktop-tracker.h" -struct SPObject; +class SPObject; namespace Glib { class Timer; } diff --git a/src/ui/widget/ruler.h b/src/ui/widget/ruler.h index 319624709..1a455a325 100644 --- a/src/ui/widget/ruler.h +++ b/src/ui/widget/ruler.h @@ -14,7 +14,7 @@ #include <2geom/point.h> struct SPCanvasItem; -struct SPDesktop; +class SPDesktop; namespace Glib { class ustring; } diff --git a/src/widgets/select-toolbar.h b/src/widgets/select-toolbar.h index a4c42880f..e3573da66 100644 --- a/src/widgets/select-toolbar.h +++ b/src/widgets/select-toolbar.h @@ -15,7 +15,7 @@ */ #include <gtk/gtk.h> -struct SPDesktop; +class SPDesktop; void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); diff --git a/src/widgets/sp-attribute-widget.cpp b/src/widgets/sp-attribute-widget.cpp index f3bdc062d..eb90df60e 100644 --- a/src/widgets/sp-attribute-widget.cpp +++ b/src/widgets/sp-attribute-widget.cpp @@ -1,8 +1,10 @@ /* Authors: * Lauris Kaplinski <lauris@ximian.com> - * Abhishek Sharma + * Abhishek Sharma + * Kris De Gussem <Kris.DeGussem@gmail.com> * * Copyright (C) 2001 Ximian, Inc. + * Copyright (C) 2011, authors * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -20,277 +22,126 @@ using Inkscape::DocumentUndo; -static void sp_attribute_widget_class_init (SPAttributeWidgetClass *klass); -static void sp_attribute_widget_init (SPAttributeWidget *widget); -static void sp_attribute_widget_destroy (GtkObject *object); - -static void sp_attribute_widget_changed (GtkEditable *editable); - static void sp_attribute_widget_object_modified ( SPObject *object, guint flags, SPAttributeWidget *spaw ); -static void sp_attribute_widget_object_release ( SPObject *object, - SPAttributeWidget *spaw ); - -static GtkEntryClass *parent_class; - - - - -GType sp_attribute_widget_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPAttributeWidgetClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_attribute_widget_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPAttributeWidget), - 0, // n_preallocs - (GInstanceInitFunc)sp_attribute_widget_init, - 0 // value_table - }; - type = g_type_register_static(GTK_TYPE_ENTRY, "SPAttributeWidget", &info, static_cast<GTypeFlags>(0)); - } - return type; -} // end of sp_attribute_widget_get_type() - - - -static void sp_attribute_widget_class_init (SPAttributeWidgetClass *klass) -{ - GtkObjectClass *object_class; - GtkEditableClass *editable_class; - - object_class = GTK_OBJECT_CLASS (klass); - editable_class = GTK_EDITABLE_CLASS (klass); - parent_class = (GtkEntryClass*)g_type_class_peek_parent (klass); - object_class->destroy = sp_attribute_widget_destroy; - - editable_class->changed = sp_attribute_widget_changed; - -} // end of sp_attribute_widget_class_init() - - - -static void sp_attribute_widget_init (SPAttributeWidget *spaw) +SPAttributeWidget::SPAttributeWidget () : + blocked(0), + hasobj(0), + _attribute(), + modified_connection() { - spaw->blocked = FALSE; - spaw->hasobj = FALSE; - - spaw->src.object = NULL; - - spaw->attribute = NULL; - - new (&spaw->modified_connection) sigc::connection(); - new (&spaw->release_connection) sigc::connection(); + src.object = NULL; } - - -static void sp_attribute_widget_destroy (GtkObject *object) +SPAttributeWidget::~SPAttributeWidget () { - - SPAttributeWidget *spaw; - - spaw = SP_ATTRIBUTE_WIDGET (object); - - if (spaw->attribute) { - g_free (spaw->attribute); - spaw->attribute = NULL; - } - - - if (spaw->hasobj) { - - if (spaw->src.object) { - spaw->modified_connection.disconnect(); - spaw->release_connection.disconnect(); - spaw->src.object = NULL; - } - } else { - - if (spaw->src.repr) { - spaw->src.repr = Inkscape::GC::release(spaw->src.repr); + if (hasobj) + { + if (src.object) + { + modified_connection.disconnect(); + src.object = NULL; } - } // end of if() - - spaw->modified_connection.~connection(); - spaw->release_connection.~connection(); - - ((GtkObjectClass *) parent_class)->destroy (object); - -} - - - -static void sp_attribute_widget_changed (GtkEditable *editable) -{ - - SPAttributeWidget *spaw; - - spaw = SP_ATTRIBUTE_WIDGET (editable); - - if (!spaw->blocked) { - - const gchar *text; - spaw->blocked = TRUE; - text = gtk_entry_get_text (GTK_ENTRY (spaw)); - if (!*text) - text = NULL; - - if (spaw->hasobj && spaw->src.object) { - spaw->src.object->getRepr()->setAttribute(spaw->attribute, text, false); - DocumentUndo::done(spaw->src.object->document, SP_VERB_NONE, - _("Set attribute")); - - } else if (spaw->src.repr) { - spaw->src.repr->setAttribute(spaw->attribute, text, false); - /* TODO: Warning! Undo will not be flushed in given case */ + } + else + { + if (src.repr) + { + src.repr = Inkscape::GC::release(src.repr); } - spaw->blocked = FALSE; } - -} // end of sp_attribute_widget_changed() - - - -GtkWidget *sp_attribute_widget_new ( SPObject *object, const gchar *attribute ) -{ - SPAttributeWidget *spaw; - - g_return_val_if_fail (!object || SP_IS_OBJECT (object), NULL); - g_return_val_if_fail (!object || attribute, NULL); - - spaw = (SPAttributeWidget*)g_object_new (SP_TYPE_ATTRIBUTE_WIDGET, NULL); - - sp_attribute_widget_set_object (spaw, object, attribute); - - return GTK_WIDGET (spaw); - -} // end of sp_attribute_widget_new() - - - -GtkWidget *sp_attribute_widget_new_repr ( Inkscape::XML::Node *repr, const gchar *attribute ) -{ - SPAttributeWidget *spaw; - - spaw = (SPAttributeWidget*)g_object_new (SP_TYPE_ATTRIBUTE_WIDGET, NULL); - - sp_attribute_widget_set_repr (spaw, repr, attribute); - - return GTK_WIDGET (spaw); } - - -void sp_attribute_widget_set_object ( SPAttributeWidget *spaw, - SPObject *object, - const gchar *attribute ) +void SPAttributeWidget::set_object(SPObject *object, const gchar *attribute) { - - g_return_if_fail (spaw != NULL); - g_return_if_fail (SP_IS_ATTRIBUTE_WIDGET (spaw)); - g_return_if_fail (!object || SP_IS_OBJECT (object)); - g_return_if_fail (!object || attribute); - g_return_if_fail (attribute != NULL); - - if (spaw->attribute) { - g_free (spaw->attribute); - spaw->attribute = NULL; - } - - if (spaw->hasobj) { - - if (spaw->src.object) { - spaw->modified_connection.disconnect(); - spaw->release_connection.disconnect(); - spaw->src.object = NULL; + if (hasobj) { + if (src.object) { + modified_connection.disconnect(); + src.object = NULL; } } else { - if (spaw->src.repr) { - spaw->src.repr = Inkscape::GC::release(spaw->src.repr); + if (src.repr) { + src.repr = Inkscape::GC::release(src.repr); } } - spaw->hasobj = TRUE; - + hasobj = true; + if (object) { const gchar *val; - spaw->blocked = TRUE; - spaw->src.object = object; + blocked = true; + src.object = object; - spaw->modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_widget_object_modified), spaw)); - spaw->release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_attribute_widget_object_release), spaw)); + modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_widget_object_modified), this)); - spaw->attribute = g_strdup (attribute); + _attribute = attribute; val = object->getRepr()->attribute(attribute); - gtk_entry_set_text (GTK_ENTRY (spaw), val ? val : (const gchar *) ""); - spaw->blocked = FALSE; + set_text (val ? val : (const gchar *) ""); + blocked = false; } + gtk_widget_set_sensitive (GTK_WIDGET(this), (src.object != NULL)); +} - gtk_widget_set_sensitive (GTK_WIDGET (spaw), (spaw->src.object != NULL)); - -} // end of sp_attribute_widget_set_object() - - - -void sp_attribute_widget_set_repr ( SPAttributeWidget *spaw, - Inkscape::XML::Node *repr, - const gchar *attribute ) +void SPAttributeWidget::set_repr(Inkscape::XML::Node *repr, const gchar *attribute) { - - g_return_if_fail (spaw != NULL); - g_return_if_fail (SP_IS_ATTRIBUTE_WIDGET (spaw)); - g_return_if_fail (attribute != NULL); - - if (spaw->attribute) { - g_free (spaw->attribute); - spaw->attribute = NULL; - } - - if (spaw->hasobj) { - - if (spaw->src.object) { - spaw->modified_connection.disconnect(); - spaw->release_connection.disconnect(); - spaw->src.object = NULL; + if (hasobj) { + if (src.object) { + modified_connection.disconnect(); + src.object = NULL; } } else { - if (spaw->src.repr) { - spaw->src.repr = Inkscape::GC::release(spaw->src.repr); + if (src.repr) { + src.repr = Inkscape::GC::release(src.repr); } } - spaw->hasobj = FALSE; - + hasobj = false; + if (repr) { const gchar *val; - spaw->blocked = TRUE; - spaw->src.repr = Inkscape::GC::anchor(repr); - spaw->attribute = g_strdup (attribute); + blocked = true; + src.repr = Inkscape::GC::anchor(repr); + attribute = g_strdup (attribute); val = repr->attribute(attribute); - gtk_entry_set_text (GTK_ENTRY (spaw), val ? val : (const gchar *) ""); - spaw->blocked = FALSE; + set_text (val ? val : (const gchar *) ""); + blocked = false; } + gtk_widget_set_sensitive (GTK_WIDGET (this), (src.repr != NULL)); +} - gtk_widget_set_sensitive (GTK_WIDGET (spaw), (spaw->src.repr != NULL)); - -} // end of sp_attribute_widget_set_repr() +void SPAttributeWidget::on_changed (void) +{ + if (!blocked) + { + Glib::ustring text1; + const gchar *text; + blocked = true; + text1 = get_text (); + text = text1.c_str(); + if (!*text) + text = NULL; + if (hasobj && src.object) { + src.object->getRepr()->setAttribute(_attribute.c_str(), text, false); + DocumentUndo::done(src.object->document, SP_VERB_NONE, + _("Set attribute")); + } else if (src.repr) { + src.repr->setAttribute(_attribute.c_str(), text, false); + /* TODO: Warning! Undo will not be flushed in given case */ + } + blocked = false; + } +} static void sp_attribute_widget_object_modified ( SPObject */*object*/, guint flags, @@ -299,18 +150,19 @@ static void sp_attribute_widget_object_modified ( SPObject */*object*/, if (flags && SP_OBJECT_MODIFIED_FLAG) { - const gchar *val, *text; - val = spaw->src.object->getRepr()->attribute(spaw->attribute); - text = gtk_entry_get_text (GTK_ENTRY (spaw)); + const gchar *val; + Glib::ustring text; + Glib::ustring attr = spaw->get_attribute(); + val = spaw->src.object->getRepr()->attribute(attr.c_str()); + text = spaw->get_text(); - if (val || text) { + if (val || !text.empty()) { - if (!val || !text || strcmp (val, text)) { + if (!val || text.empty() || (text == val)) { /* We are different */ - spaw->blocked = TRUE; - gtk_entry_set_text ( GTK_ENTRY (spaw), - val ? val : (const gchar *) ""); - spaw->blocked = FALSE; + spaw->set_blocked(true); + spaw->set_text(val ? val : (const gchar *) ""); + spaw->set_blocked(false); } // end of if() } // end of if() @@ -321,364 +173,201 @@ static void sp_attribute_widget_object_modified ( SPObject */*object*/, -static void -sp_attribute_widget_object_release ( SPObject */*object*/, - SPAttributeWidget *spaw ) -{ - sp_attribute_widget_set_object (spaw, NULL, NULL); -} - - - /* SPAttributeTable */ - -static void sp_attribute_table_class_init (SPAttributeTableClass *klass); -static void sp_attribute_table_init (SPAttributeTable *widget); -static void sp_attribute_table_destroy (GtkObject *object); - static void sp_attribute_table_object_modified (SPObject *object, guint flags, SPAttributeTable *spaw); -static void sp_attribute_table_object_release (SPObject *object, SPAttributeTable *spaw); -static void sp_attribute_table_entry_changed (GtkEditable *editable, SPAttributeTable *spat); - -static GtkVBoxClass *table_parent_class; - - +static void sp_attribute_table_entry_changed (Gtk::Editable *editable, SPAttributeTable *spat); +#define XPAD 4 +#define YPAD 0 -GType sp_attribute_table_get_type(void) +SPAttributeTable::SPAttributeTable () : + blocked(0), + hasobj(0), + table(0), + _attributes(), + _entries(), + modified_connection() { - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPAttributeTableClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_attribute_table_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPAttributeTable), - 0, // n_preallocs - (GInstanceInitFunc)sp_attribute_table_init, - 0 // value_table - }; - type = g_type_register_static(GTK_TYPE_VBOX, "SPAttributeTable", &info, static_cast<GTypeFlags>(0)); - } - return type; -} // end of sp_attribute_table_get_type() - - + src.object = NULL; +} -static void sp_attribute_table_class_init (SPAttributeTableClass *klass) +SPAttributeTable::SPAttributeTable (SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent) : + blocked(0), + hasobj(0), + table(0), + _attributes(), + _entries(), + modified_connection() { - GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); - - table_parent_class = (GtkVBoxClass*)g_type_class_peek_parent (klass); - - object_class->destroy = sp_attribute_table_destroy; - -} // end of sp_attribute_table_class_init() - - + src.object = NULL; + set_object(object, labels, attributes, parent); +} -static void sp_attribute_table_init ( SPAttributeTable *spat ) +SPAttributeTable::~SPAttributeTable () { - spat->blocked = FALSE; - spat->hasobj = FALSE; - spat->table = NULL; - spat->src.object = NULL; - spat->num_attr = 0; - spat->attributes = NULL; - spat->entries = NULL; - - new (&spat->modified_connection) sigc::connection(); - new (&spat->release_connection) sigc::connection(); + clear(); } -static void sp_attribute_table_destroy ( GtkObject *object ) +void SPAttributeTable::clear(void) { - SPAttributeTable *spat; - - spat = SP_ATTRIBUTE_TABLE (object); - - if (spat->attributes) { - gint i; - for (i = 0; i < spat->num_attr; i++) { - g_free (spat->attributes[i]); + Gtk::Widget *w; + + if (table) + { + std::vector<Widget*> ch = table->get_children(); + + for (int i = (ch.size())-1; i >=0 ; i--) + { + w = ch[i]; + ch.pop_back(); + if (w != NULL) + { + try + { + delete w; + } + catch(...) + { + } } - g_free (spat->attributes); - spat->attributes = NULL; } + ch.clear(); + _attributes.clear(); + _entries.clear(); - if (spat->hasobj) { + delete table; + table = NULL; + } - if (spat->src.object) { - spat->modified_connection.disconnect(); - spat->release_connection.disconnect(); - spat->src.object = NULL; + if (hasobj) { + if (src.object) { + modified_connection.disconnect(); + src.object = NULL; } } else { - if (spat->src.repr) { - spat->src.repr = Inkscape::GC::release(spat->src.repr); + if (src.repr) { + src.repr = Inkscape::GC::release(src.repr); } - } // end of if() - - spat->modified_connection.~connection(); - spat->release_connection.~connection(); - - if (spat->entries) { - g_free (spat->entries); - spat->entries = NULL; - } - - spat->table = NULL; - - if (((GtkObjectClass *) table_parent_class)->destroy) { - (* ((GtkObjectClass *) table_parent_class)->destroy) (object); } +} -} // end of sp_attribute_table_destroy() - - -GtkWidget * sp_attribute_table_new ( SPObject *object, - gint num_attr, - const gchar **labels, - const gchar **attributes ) -{ - SPAttributeTable *spat; - - g_return_val_if_fail (!object || SP_IS_OBJECT (object), NULL); - g_return_val_if_fail (!object || (num_attr > 0), NULL); - g_return_val_if_fail (!num_attr || (labels && attributes), NULL); - - spat = (SPAttributeTable*)g_object_new (SP_TYPE_ATTRIBUTE_TABLE, NULL); - - sp_attribute_table_set_object (spat, object, num_attr, labels, attributes); - - return GTK_WIDGET (spat); - -} // end of sp_attribute_table_new() - - - -GtkWidget *sp_attribute_table_new_repr ( Inkscape::XML::Node *repr, - gint num_attr, - const gchar **labels, - const gchar **attributes ) -{ - SPAttributeTable *spat; - - g_return_val_if_fail (!num_attr || (labels && attributes), NULL); - - spat = (SPAttributeTable*)g_object_new (SP_TYPE_ATTRIBUTE_TABLE, NULL); - - sp_attribute_table_set_repr (spat, repr, num_attr, labels, attributes); - - return GTK_WIDGET (spat); - -} // end of sp_attribute_table_new_repr() - - - -#define XPAD 4 -#define YPAD 0 - -void sp_attribute_table_set_object ( SPAttributeTable *spat, - SPObject *object, - gint num_attr, - const gchar **labels, - const gchar **attributes ) +void SPAttributeTable::set_object(SPObject *object, + std::vector<Glib::ustring> &labels, + std::vector<Glib::ustring> &attributes, + GtkWidget* parent) { - - g_return_if_fail (spat != NULL); - g_return_if_fail (SP_IS_ATTRIBUTE_TABLE (spat)); + g_return_if_fail (parent); g_return_if_fail (!object || SP_IS_OBJECT (object)); - g_return_if_fail (!object || (num_attr > 0)); - g_return_if_fail (!num_attr || (labels && attributes)); - - if (spat->table) { - gtk_widget_destroy (spat->table); - spat->table = NULL; - } - - if (spat->attributes) { - gint i; - for (i = 0; i < spat->num_attr; i++) { - g_free (spat->attributes[i]); - } - g_free (spat->attributes); - spat->attributes = NULL; - } - - if (spat->entries) { - g_free (spat->entries); - spat->entries = NULL; - } - - if (spat->hasobj) { - if (spat->src.object) { - spat->modified_connection.disconnect(); - spat->release_connection.disconnect(); - spat->src.object = NULL; - } - } else { - if (spat->src.repr) { - spat->src.repr = Inkscape::GC::release(spat->src.repr); - } - } + g_return_if_fail (!object || !labels.empty() || !attributes.empty()); + g_return_if_fail (labels.size() == attributes.size()); - spat->hasobj = TRUE; + clear(); + hasobj = true; if (object) { - gint i; - - spat->blocked = TRUE; - - /* Set up object */ - spat->src.object = object; - spat->num_attr = num_attr; - - spat->modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_table_object_modified), spat)); - spat->release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_attribute_table_object_release), spat)); - - /* Create table */ - spat->table = gtk_table_new (num_attr, 2, FALSE); - gtk_container_add (GTK_CONTAINER (spat), spat->table); - /* Arrays */ - spat->attributes = g_new0 (gchar *, num_attr); - spat->entries = g_new0 (GtkWidget *, num_attr); - /* Fill rows */ - for (i = 0; i < num_attr; i++) { - GtkWidget *w; + blocked = true; + + // Set up object + src.object = object; + modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_table_object_modified), this)); + + // Create table + table = Gtk::manage(new Gtk::Table (attributes.size(), 2, false)); + gtk_container_add (GTK_CONTAINER (parent),(GtkWidget*)table->gobj()); + + // Fill rows + _attributes = attributes; + for (gint i = 0; i < (attributes.size()); i++) { + Gtk::Label *ll; + Gtk::Entry *ee; + Gtk::Widget *w; const gchar *val; - spat->attributes[i] = g_strdup (attributes[i]); - w = gtk_label_new (_(labels[i])); - gtk_widget_show (w); - gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5); - gtk_table_attach ( GTK_TABLE (spat->table), w, 0, 1, i, i + 1, - GTK_FILL, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + ll = new Gtk::Label (_(labels[i].c_str())); + w = (Gtk::Widget *) ll; + ll->show(); + ll->set_alignment (1.0, 0.5); + table->attach (*w, 0, 1, i, i + 1, + Gtk::FILL, + (Gtk::EXPAND | Gtk::FILL), XPAD, YPAD ); - w = gtk_entry_new (); - gtk_widget_show (w); - val = object->getRepr()->attribute(attributes[i]); - gtk_entry_set_text (GTK_ENTRY (w), val ? val : (const gchar *) ""); - gtk_table_attach ( GTK_TABLE (spat->table), w, 1, 2, i, i + 1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + ee = new Gtk::Entry(); + w = (Gtk::Widget *) ee; + ee->show(); + val = object->getRepr()->attribute(attributes[i].c_str()); + ee->set_text (val ? val : (const gchar *) ""); + table->attach (*w, 1, 2, i, i + 1, + (Gtk::EXPAND | Gtk::FILL), + (Gtk::EXPAND | Gtk::FILL), XPAD, YPAD ); - spat->entries[i] = w; - g_signal_connect ( G_OBJECT (w), "changed", + _entries.push_back(w); + g_signal_connect ( w->gobj(), "changed", G_CALLBACK (sp_attribute_table_entry_changed), - spat ); + this ); } /* Show table */ - gtk_widget_show (spat->table); - - spat->blocked = FALSE; + table->show (); + blocked = false; } +} - gtk_widget_set_sensitive ( GTK_WIDGET (spat), - (spat->src.object != NULL) ); - -} // end of sp_attribute_table_set_object() - - - -void sp_attribute_table_set_repr ( SPAttributeTable *spat, - Inkscape::XML::Node *repr, - gint num_attr, - const gchar **labels, - const gchar **attributes ) +void SPAttributeTable::set_repr (Inkscape::XML::Node *repr, + std::vector<Glib::ustring> &labels, + std::vector<Glib::ustring> &attributes, + GtkWidget* parent) { - g_return_if_fail (spat != NULL); - g_return_if_fail (SP_IS_ATTRIBUTE_TABLE (spat)); - g_return_if_fail (!num_attr || (labels && attributes)); + g_return_if_fail (!labels.empty() || !attributes.empty()); + g_return_if_fail (labels.size() == attributes.size()); - if (spat->table) { - gtk_widget_destroy (spat->table); - spat->table = NULL; - } + clear(); - if (spat->attributes) { - gint i; - for (i = 0; i < spat->num_attr; i++) { - g_free (spat->attributes[i]); - } - g_free (spat->attributes); - spat->attributes = NULL; - } - - if (spat->entries) { - g_free (spat->entries); - spat->entries = NULL; - } - - if (spat->hasobj) { - if (spat->src.object) { - spat->modified_connection.disconnect(); - spat->release_connection.disconnect(); - spat->src.object = NULL; - } - } else { - if (spat->src.repr) { - spat->src.repr = Inkscape::GC::release(spat->src.repr); - } - } - - spat->hasobj = FALSE; + hasobj = false; if (repr) { - gint i; - - spat->blocked = TRUE; - - /* Set up repr */ - spat->src.repr = Inkscape::GC::anchor(repr); - spat->num_attr = num_attr; - /* Create table */ - spat->table = gtk_table_new (num_attr, 2, FALSE); - gtk_container_add (GTK_CONTAINER (spat), spat->table); - /* Arrays */ - spat->attributes = g_new0 (gchar *, num_attr); - spat->entries = g_new0 (GtkWidget *, num_attr); - - /* Fill rows */ - for (i = 0; i < num_attr; i++) { - GtkWidget *w; + blocked = true; + + // Set up repr + src.repr = Inkscape::GC::anchor(repr); + + // Create table + table = new Gtk::Table (attributes.size(), 2, false); + gtk_container_add (GTK_CONTAINER (parent),(GtkWidget*)table->gobj()); + + // Fill rows + _attributes = attributes; + for (gint i = 0; i < (attributes.size()); i++) { + Gtk::Label *ll; + Gtk::Entry *ee; + Gtk::Widget *w; const gchar *val; - spat->attributes[i] = g_strdup (attributes[i]); - w = gtk_label_new (labels[i]); - gtk_widget_show (w); - gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5); - gtk_table_attach ( GTK_TABLE (spat->table), w, 0, 1, i, i + 1, - GTK_FILL, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + ll = new Gtk::Label (_(labels[i].c_str())); + w = (Gtk::Widget *) ll; + ll->show (); + ll->set_alignment (1.0, 0.5); + table->attach (*w, 0, 1, i, i + 1, + Gtk::FILL, + (Gtk::EXPAND | Gtk::FILL), XPAD, YPAD ); - w = gtk_entry_new (); - gtk_widget_show (w); - val = repr->attribute(attributes[i]); - gtk_entry_set_text (GTK_ENTRY (w), val ? val : (const gchar *) ""); - gtk_table_attach ( GTK_TABLE (spat->table), w, 1, 2, i, i + 1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + ee = new Gtk::Entry(); + w = (Gtk::Widget *) ee; + ee->show(); + val = repr->attribute(attributes[i].c_str()); + ee->set_text (val ? val : (const gchar *) ""); + table->attach (*w, 1, 2, i, i + 1, + (Gtk::EXPAND | Gtk::FILL), + (Gtk::EXPAND | Gtk::FILL), XPAD, YPAD ); - spat->entries[i] = w; - g_signal_connect ( G_OBJECT (w), "changed", + _entries.push_back(w); + g_signal_connect ( w->gobj(), "changed", G_CALLBACK (sp_attribute_table_entry_changed), - spat ); + this ); } /* Show table */ - gtk_widget_show (spat->table); - - spat->blocked = FALSE; + table->show (); + blocked = false; } - - gtk_widget_set_sensitive (GTK_WIDGET (spat), (spat->src.repr != NULL)); - -} // end of sp_attribute_table_set_repr() - +} static void sp_attribute_table_object_modified ( SPObject */*object*/, @@ -688,17 +377,21 @@ static void sp_attribute_table_object_modified ( SPObject */*object*/, if (flags && SP_OBJECT_MODIFIED_FLAG) { gint i; - for (i = 0; i < spat->num_attr; i++) { - const gchar *val, *text; - val = spat->src.object->getRepr()->attribute(spat->attributes[i]); - text = gtk_entry_get_text (GTK_ENTRY (spat->entries[i])); - if (val || text) { - if (!val || !text || strcmp (val, text)) { + std::vector<Glib::ustring> attributes = spat->get_attributes(); + std::vector<Gtk::Widget *> entries = spat->get_entries(); + Gtk::Entry* e; + Glib::ustring text; + for (i = 0; i < (attributes.size()); i++) { + const gchar *val; + e = (Gtk::Entry*) entries[i]; + val = spat->src.object->getRepr()->attribute(attributes[i].c_str()); + text = e->get_text (); + if (val || !text.empty()) { + if (text != val) { /* We are different */ - spat->blocked = TRUE; - gtk_entry_set_text ( GTK_ENTRY (spat->entries[i]), - val ? val : (const gchar *) ""); - spat->blocked = FALSE; + spat->blocked = true; + e->set_text (val ? val : (const gchar *) ""); + spat->blocked = false; } } } @@ -706,42 +399,32 @@ static void sp_attribute_table_object_modified ( SPObject */*object*/, } // end of sp_attribute_table_object_modified() - - -static void sp_attribute_table_object_release (SPObject */*object*/, SPAttributeTable *spat) -{ - sp_attribute_table_set_object (spat, NULL, 0, NULL, NULL); -} - - - -static void sp_attribute_table_entry_changed ( GtkEditable *editable, +static void sp_attribute_table_entry_changed ( Gtk::Editable *editable, SPAttributeTable *spat ) { if (!spat->blocked) { gint i; - for (i = 0; i < spat->num_attr; i++) { - - if (GTK_WIDGET (editable) == spat->entries[i]) { - const gchar *text; - spat->blocked = TRUE; - text = gtk_entry_get_text (GTK_ENTRY (spat->entries[i])); - - if (!*text) - text = NULL; + std::vector<Glib::ustring> attributes = spat->get_attributes(); + std::vector<Gtk::Widget *> entries = spat->get_entries(); + Gtk::Entry *e; + for (i = 0; i < (attributes.size()); i++) { + e = (Gtk::Entry *) entries[i]; + if ((GtkWidget*) (editable) == (GtkWidget*) e->gobj()) { + spat->blocked = true; + Glib::ustring text = e->get_text (); if (spat->hasobj && spat->src.object) { - spat->src.object->getRepr()->setAttribute(spat->attributes[i], text, false); + spat->src.object->getRepr()->setAttribute(attributes[i].c_str(), text.c_str(), false); DocumentUndo::done(spat->src.object->document, SP_VERB_NONE, _("Set attribute")); } else if (spat->src.repr) { - spat->src.repr->setAttribute(spat->attributes[i], text, false); + spat->src.repr->setAttribute(attributes[i].c_str(), text.c_str(), false); /* TODO: Warning! Undo will not be flushed in given case */ } - spat->blocked = FALSE; + spat->blocked = false; return; } } diff --git a/src/widgets/sp-attribute-widget.h b/src/widgets/sp-attribute-widget.h index a4acf9504..4b4260127 100644 --- a/src/widgets/sp-attribute-widget.h +++ b/src/widgets/sp-attribute-widget.h @@ -4,8 +4,9 @@ */ /* Authors: * Lauris Kaplinski <lauris@kaplinski.com> + * Kris De Gussem <Kris.DeGussem@gmail.com> * - * Copyright (C) 2002 authors + * Copyright (C) 2002,2011 authors * Copyright (C) 2001 Ximian, Inc. * * Licensed under GNU GPL, read the file 'COPYING' for more information @@ -14,21 +15,12 @@ #ifndef SEEN_DIALOGS_SP_ATTRIBUTE_WIDGET_H #define SEEN_DIALOGS_SP_ATTRIBUTE_WIDGET_H +#include <gtk/gtk.h> +#include <gtkmm.h> #include <glib.h> #include <stddef.h> #include <sigc++/connection.h> - -#define SP_TYPE_ATTRIBUTE_WIDGET (sp_attribute_widget_get_type ()) -#define SP_ATTRIBUTE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_ATTRIBUTE_WIDGET, SPAttributeWidget)) -#define SP_ATTRIBUTE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_ATTRIBUTE_WIDGET, SPAttributeWidgetClass)) -#define SP_IS_ATTRIBUTE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_ATTRIBUTE_WIDGET)) -#define SP_IS_ATTRIBUTE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_ATTRIBUTE_WIDGET)) - -#define SP_TYPE_ATTRIBUTE_TABLE (sp_attribute_table_get_type ()) -#define SP_ATTRIBUTE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_ATTRIBUTE_TABLE, SPAttributeTable)) -#define SP_ATTRIBUTE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_ATTRIBUTE_TABLE, SPAttributeTableClass)) -#define SP_IS_ATTRIBUTE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_ATTRIBUTE_TABLE)) -#define SP_IS_ATTRIBUTE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_ATTRIBUTE_TABLE)) +#include <vector.h> namespace Inkscape { namespace XML { @@ -36,87 +28,63 @@ class Node; } } - -struct SPAttributeWidget; -struct SPAttributeWidgetClass; - struct SPAttributeTable; struct SPAttributeTableClass; - -class SPObject; - -#include <gtk/gtk.h> - -struct SPAttributeWidget { - GtkEntry entry; - guint blocked : 1; - guint hasobj : 1; +class SPObject; + +class SPAttributeWidget : public Gtk::Entry { +//NOTE: SPAttributeWidget does not seem to be used nowhere in Inkscape, conversion to c++ not tested +public: + SPAttributeWidget (); + ~SPAttributeWidget (); + void set_object(SPObject *object, const gchar *attribute); + void set_repr(Inkscape::XML::Node *repr, const gchar *attribute); + Glib::ustring get_attribute(void) {return _attribute;}; + void set_blocked(guint b) {blocked = b;}; + union { SPObject *object; Inkscape::XML::Node *repr; } src; - gchar *attribute; +protected: + void on_changed (void); + +private: + guint blocked; + guint hasobj; + Glib::ustring _attribute; sigc::connection modified_connection; - sigc::connection release_connection; }; -struct SPAttributeWidgetClass { - GtkEntryClass entry_class; -}; - -GType sp_attribute_widget_get_type (void); - -GtkWidget *sp_attribute_widget_new (SPObject *object, const gchar *attribute); -GtkWidget *sp_attribute_widget_new_repr (Inkscape::XML::Node *repr, const gchar *attribute); - -void sp_attribute_widget_set_object ( SPAttributeWidget *spw, - SPObject *object, - const gchar *attribute ); -void sp_attribute_widget_set_repr ( SPAttributeWidget *spw, - Inkscape::XML::Node *repr, - const gchar *attribute ); /* SPAttributeTable */ -struct SPAttributeTable { - GtkVBox vbox; - guint blocked : 1; - guint hasobj : 1; - GtkWidget *table; +class SPAttributeTable : public Gtk::Widget { +public: + SPAttributeTable (); + SPAttributeTable (SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent); + ~SPAttributeTable (); + void set_object(SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent); + void set_repr(Inkscape::XML::Node *repr, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent); + std::vector<Glib::ustring> get_attributes(void) {return _attributes;}; + std::vector<Gtk::Widget *> get_entries(void) {return _entries;}; union { SPObject *object; Inkscape::XML::Node *repr; } src; - gint num_attr; - gchar **attributes; - GtkWidget **entries; + guint blocked; + guint hasobj; +private: + Gtk::Table *table; + std::vector<Glib::ustring> _attributes; + std::vector<Gtk::Widget *> _entries; sigc::connection modified_connection; - sigc::connection release_connection; + + void clear(void); }; -struct SPAttributeTableClass { - GtkEntryClass entry_class; -}; - -GType sp_attribute_table_get_type (void); - -GtkWidget *sp_attribute_table_new ( SPObject *object, gint num_attr, - const gchar **labels, - const gchar **attributes ); -GtkWidget *sp_attribute_table_new_repr ( Inkscape::XML::Node *repr, gint num_attr, - const gchar **labels, - const gchar **attributes ); -void sp_attribute_table_set_object ( SPAttributeTable *spw, - SPObject *object, gint num_attr, - const gchar **labels, - const gchar **attrs ); -void sp_attribute_table_set_repr ( SPAttributeTable *spw, - Inkscape::XML::Node *repr, gint num_attr, - const gchar **labels, - const gchar **attrs ); - #endif /* |
