1 /** @file
2 * @brief Generic properties editor
3 */
4 /* Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>
6 * bulia byak <buliabyak@users.sf.net>
7 *
8 * Copyright (C) 1999-2005 Authors
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
13 #include <glibmm/i18n.h>
14 #include <string>
15 #include <cstring>
16 #include <sigc++/connection.h>
17 #include <sigc++/functors/ptr_fun.h>
18 #include <sigc++/adaptors/bind.h>
20 #include "helper/window.h"
21 #include "macros.h"
22 #include "sp-anchor.h"
23 #include "widgets/sp-attribute-widget.h"
24 #include "../xml/repr.h"
26 struct SPAttrDesc {
27 gchar const *label;
28 gchar const *attribute;
29 };
31 static const SPAttrDesc anchor_desc[] = {
32 { N_("Href:"), "xlink:href"},
33 { N_("Target:"), "target"},
34 { N_("Type:"), "xlink:type"},
35 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute
36 // Identifies the type of the related resource with an absolute URI
37 { N_("Role:"), "xlink:role"},
38 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute
39 // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link.
40 { N_("Arcrole:"), "xlink:arcrole"},
41 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute
42 { N_("Title:"), "xlink:title"},
43 { N_("Show:"), "xlink:show"},
44 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute
45 { N_("Actuate:"), "xlink:actuate"},
46 { NULL, NULL}
47 };
49 static const SPAttrDesc image_desc[] = {
50 { N_("URL:"), "xlink:href"},
51 { N_("X:"), "x"},
52 { N_("Y:"), "y"},
53 { N_("Width:"), "width"},
54 { N_("Height:"), "height"},
55 { NULL, NULL}
56 };
58 static const SPAttrDesc image_nohref_desc[] = {
59 { N_("X:"), "x"},
60 { N_("Y:"), "y"},
61 { N_("Width:"), "width"},
62 { N_("Height:"), "height"},
63 { NULL, NULL}
64 };
67 static void
68 object_released( SPObject */*object*/, GtkWidget *widget )
69 {
70 gtk_widget_destroy (widget);
71 }
75 static void
76 window_destroyed( GtkObject *window, GtkObject */*object*/ )
77 {
78 sigc::connection *release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(window), "release_connection");
79 release_connection->disconnect();
80 delete release_connection;
81 }
85 static void
86 sp_object_attr_show_dialog ( SPObject *object,
87 const SPAttrDesc *desc,
88 const gchar *tag )
89 {
90 const gchar **labels, **attrs;
91 gint len, i;
92 gchar *title;
93 GtkWidget *w, *t;
95 len = 0;
96 while (desc[len].label) len += 1;
98 labels = (const gchar **)alloca (len * sizeof (char *));
99 attrs = (const gchar **)alloca (len * sizeof (char *));
101 for (i = 0; i < len; i++) {
102 labels[i] = desc[i].label;
103 attrs[i] = desc[i].attribute;
104 }
106 if (!strcmp (tag, "Link")) {
107 title = g_strdup_printf (_("Link Properties"));
108 } else if (!strcmp (tag, "Image")) {
109 title = g_strdup_printf (_("Image Properties"));
110 } else {
111 title = g_strdup_printf (_("%s Properties"), tag);
112 }
114 w = sp_window_new (title, TRUE);
115 g_free (title);
117 t = sp_attribute_table_new (object, len, labels, attrs);
118 gtk_widget_show (t);
119 gtk_container_add (GTK_CONTAINER (w), t);
121 g_signal_connect ( G_OBJECT (w), "destroy",
122 G_CALLBACK (window_destroyed), object );
124 sigc::connection *release_connection = new sigc::connection();
125 *release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&object_released), w));
126 g_object_set_data(G_OBJECT(w), "release_connection", release_connection);
128 gtk_widget_show (w);
130 } // end of sp_object_attr_show_dialog()
134 void
135 sp_object_attributes_dialog (SPObject *object, const gchar *tag)
136 {
137 g_return_if_fail (object != NULL);
138 g_return_if_fail (SP_IS_OBJECT (object));
139 g_return_if_fail (tag != NULL);
141 if (!strcmp (tag, "Link")) {
142 sp_object_attr_show_dialog (object, anchor_desc, tag);
143 } else if (!strcmp (tag, "Image")) {
144 Inkscape::XML::Node *ir = SP_OBJECT_REPR(object);
145 const gchar *href = ir->attribute("xlink:href");
146 if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) {
147 sp_object_attr_show_dialog (object, image_nohref_desc, tag);
148 } else {
149 sp_object_attr_show_dialog (object, image_desc, tag);
150 }
151 }
152 } // end of sp_object_attributes_dialog()
154 /*
155 Local Variables:
156 mode:c++
157 c-file-style:"stroustrup"
158 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
159 indent-tabs-mode:nil
160 fill-column:99
161 End:
162 */
163 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :