e0c891ea1ad22c4aedf4f30eec1d88f610fc1238
1 #define __SP_OBJECT_ATTRIBUTES_C__
3 /**
4 * \brief Generic properties editor
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 1999-2005 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
19 #include <glibmm/i18n.h>
20 #include <string>
21 #include <cstring>
23 #include "helper/window.h"
24 #include "macros.h"
25 #include "sp-anchor.h"
26 #include "sp-attribute-widget.h"
27 #include "../xml/repr.h"
29 #include <sigc++/connection.h>
30 #include <sigc++/functors/ptr_fun.h>
31 #include <sigc++/adaptors/bind.h>
33 struct SPAttrDesc {
34 gchar const *label;
35 gchar const *attribute;
36 };
38 static const SPAttrDesc anchor_desc[] = {
39 { N_("Href:"), "xlink:href"},
40 { N_("Target:"), "target"},
41 { N_("Type:"), "xlink:type"},
42 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute
43 // Identifies the type of the related resource with an absolute URI
44 { N_("Role:"), "xlink:role"},
45 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute
46 // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link.
47 { N_("Arcrole:"), "xlink:arcrole"},
48 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute
49 { N_("Title:"), "xlink:title"},
50 { N_("Show:"), "xlink:show"},
51 // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute
52 { N_("Actuate:"), "xlink:actuate"},
53 { NULL, NULL}
54 };
56 static const SPAttrDesc image_desc[] = {
57 { N_("URL:"), "xlink:href"},
58 { N_("X:"), "x"},
59 { N_("Y:"), "y"},
60 { N_("Width:"), "width"},
61 { N_("Height:"), "height"},
62 { NULL, NULL}
63 };
65 static const SPAttrDesc image_nohref_desc[] = {
66 { N_("X:"), "x"},
67 { N_("Y:"), "y"},
68 { N_("Width:"), "width"},
69 { N_("Height:"), "height"},
70 { NULL, NULL}
71 };
74 static void
75 object_released( SPObject */*object*/, GtkWidget *widget )
76 {
77 gtk_widget_destroy (widget);
78 }
82 static void
83 window_destroyed( GtkObject *window, GtkObject */*object*/ )
84 {
85 sigc::connection *release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(window), "release_connection");
86 release_connection->disconnect();
87 delete release_connection;
88 }
92 static void
93 sp_object_attr_show_dialog ( SPObject *object,
94 const SPAttrDesc *desc,
95 const gchar *tag )
96 {
97 const gchar **labels, **attrs;
98 gint len, i;
99 gchar *title;
100 GtkWidget *w, *t;
102 len = 0;
103 while (desc[len].label) len += 1;
105 labels = (const gchar **)alloca (len * sizeof (char *));
106 attrs = (const gchar **)alloca (len * sizeof (char *));
108 for (i = 0; i < len; i++) {
109 labels[i] = desc[i].label;
110 attrs[i] = desc[i].attribute;
111 }
113 title = g_strdup_printf (_("%s Properties"), tag);
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 }
153 } // end of sp_object_attributes_dialog()
157 /*
158 Local Variables:
159 mode:c++
160 c-file-style:"stroustrup"
161 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
162 indent-tabs-mode:nil
163 fill-column:99
164 End:
165 */
166 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :