From 28dcdf10f9fef7f4c7d7bf7664040aa3c26126fe Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 19 Jan 2012 20:45:06 +0100 Subject: Gtkmmification of object attributes dialog: image and link attributes now editable in dockable dialog (Bug #592323) (bzr r10910) --- src/ui/dialog/object-attributes.cpp | 211 ++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 src/ui/dialog/object-attributes.cpp (limited to 'src/ui/dialog/object-attributes.cpp') diff --git a/src/ui/dialog/object-attributes.cpp b/src/ui/dialog/object-attributes.cpp new file mode 100644 index 000000000..1f55887f4 --- /dev/null +++ b/src/ui/dialog/object-attributes.cpp @@ -0,0 +1,211 @@ +/** @file + * Generic object attribute editor + */ +/* Authors: + * Lauris Kaplinski + * bulia byak + * Kris De Gussem + * + * Copyright (C) 1999-2012 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "desktop-handles.h" +#include "macros.h" +#include "sp-anchor.h" +#include "sp-image.h" +#include "verbs.h" +#include "xml/repr.h" +#include "ui/dialog/dialog-manager.h" +#include "ui/dialog/object-attributes.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +struct SPAttrDesc { + gchar const *label; + gchar const *attribute; +}; + +static const SPAttrDesc anchor_desc[] = { + { N_("Href:"), "xlink:href"}, + { N_("Target:"), "target"}, + { N_("Type:"), "xlink:type"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute + // Identifies the type of the related resource with an absolute URI + { N_("Role:"), "xlink:role"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute + // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link. + { N_("Arcrole:"), "xlink:arcrole"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute + { N_("Title:"), "xlink:title"}, + { N_("Show:"), "xlink:show"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute + { N_("Actuate:"), "xlink:actuate"}, + { NULL, NULL} +}; + +static const SPAttrDesc image_desc[] = { + { N_("URL:"), "xlink:href"}, + { N_("X:"), "x"}, + { N_("Y:"), "y"}, + { N_("Width:"), "width"}, + { N_("Height:"), "height"}, + { NULL, NULL} +}; + +static const SPAttrDesc image_nohref_desc[] = { + { N_("X:"), "x"}, + { N_("Y:"), "y"}, + { N_("Width:"), "width"}, + { N_("Height:"), "height"}, + { NULL, NULL} +}; + +ObjectAttributes::ObjectAttributes (void) : + UI::Widget::Panel ("", "/dialogs/objectattr/", SP_VERB_DIALOG_ATTR), + blocked (false), + CurrentItem(NULL), + attrTable(), + desktop(NULL), + deskTrack(), + selectChangedConn(), + subselChangedConn(), + selectModifiedConn() +{ + attrTable.show(); + widget_setup(); + + desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &ObjectAttributes::setTargetDesktop) ); + deskTrack.connect(GTK_WIDGET(gobj())); +} + +ObjectAttributes::~ObjectAttributes (void) +{ + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); + desktopChangeConn.disconnect(); + deskTrack.disconnect(); +} + +void ObjectAttributes::widget_setup (void) +{ + if (blocked) + { + return; + } + + Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + SPItem *item = selection->singleItem(); + if (!item) + { + set_sensitive (false); + CurrentItem = NULL; + //no selection anymore or multiple objects selected, means that we need + //to close the connections to the previously selected object + return; + } + + blocked = true; + SPObject *obj = (SPObject*)item; //to get the selected item + GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type + GType type = G_TYPE_FROM_CLASS(klass); + const SPAttrDesc *desc; + + if (type == SP_TYPE_ANCHOR) + { + desc = anchor_desc; + } + else if (type == SP_TYPE_IMAGE) + { + Inkscape::XML::Node *ir = obj->getRepr(); + const gchar *href = ir->attribute("xlink:href"); + if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) + { + desc = image_nohref_desc; + } + else + { + desc = image_desc; + } + } + else + { + blocked = false; + set_sensitive (false); + return; + } + + int len = 0; + std::vector labels; + std::vector attrs; + if (CurrentItem != item) + { + while (desc[len].label) + { + labels.push_back(desc[len].label); + attrs.push_back (desc[len].attribute); + len += 1; + } + attrTable.set_object(obj, labels, attrs, (GtkWidget*)gobj()); + CurrentItem = item; + } + else + { + attrTable.change_object(obj); + } + + set_sensitive (true); + show_all(); + blocked = false; +} + +void ObjectAttributes::setTargetDesktop(SPDesktop *desktop) +{ + if (this->desktop != desktop) { + if (this->desktop) { + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); + } + this->desktop = desktop; + if (desktop && desktop->selection) { + selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &ObjectAttributes::widget_setup))); + subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &ObjectAttributes::widget_setup))); + + // Must check flags, so can't call widget_setup() directly. + selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &ObjectAttributes::selectionModifiedCB))); + } + widget_setup(); + } +} + +void ObjectAttributes::selectionModifiedCB( guint flags ) +{ + if (flags & ( SP_OBJECT_MODIFIED_FLAG | + SP_OBJECT_PARENT_MODIFIED_FLAG | + SP_OBJECT_STYLE_MODIFIED_FLAG) ) { + attrTable.reread_properties(); + } +} + + +} +} +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3