Code

fix 1516323
[inkscape.git] / src / dialogs / object-attributes.cpp
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
18 #include <glibmm/i18n.h>
19 #include "helper/window.h"
20 #include "macros.h"
21 #include "sp-anchor.h"
22 #include "sp-attribute-widget.h"
24 #include <sigc++/connection.h>
25 #include <sigc++/functors/ptr_fun.h>
26 #include <sigc++/adaptors/bind.h>
28 struct SPAttrDesc {
29     gchar const *label;
30     gchar const *attribute;
31 };
33 static const SPAttrDesc anchor_desc[] = {
34     { N_("Href:"), "xlink:href"},
35     { N_("Target:"), "target"},
36     { N_("Type:"), "xlink:type"},
37     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute
38     // Identifies the type of the related resource with an absolute URI
39     { N_("Role:"), "xlink:role"},
40     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute
41     // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link.
42     { N_("Arcrole:"), "xlink:arcrole"},
43     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute
44     { N_("Title:"), "xlink:title"},
45     { N_("Show:"), "xlink:show"},
46     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute
47     { N_("Actuate:"), "xlink:actuate"},
48     { NULL, NULL}
49 };
51 static const SPAttrDesc image_desc[] = {
52     { N_("URL:"), "xlink:href"},
53     { N_("X:"), "x"},
54     { N_("Y:"), "y"},
55     { N_("Width:"), "width"},
56     { N_("Height:"), "height"},
57     { NULL, NULL}
58 };
61 static void
62 object_released (SPObject *object, GtkWidget *widget)
63 {
64     gtk_widget_destroy (widget);
65 }
69 static void
70 window_destroyed (GtkObject *window, GtkObject *object)
71 {
72     sigc::connection *release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(window), "release_connection");
73     release_connection->disconnect();
74     delete release_connection;
75 }
79 static void
80 sp_object_attr_show_dialog ( SPObject *object,
81                              const SPAttrDesc *desc,
82                              const gchar *tag )
83 {
84     const gchar **labels, **attrs;
85     gint len, i;
86     gchar *title;
87     GtkWidget *w, *t;
89     len = 0;
90     while (desc[len].label) len += 1;
92     labels = (const gchar **)alloca (len * sizeof (char *));
93     attrs = (const gchar **)alloca (len * sizeof (char *));
95     for (i = 0; i < len; i++) {
96         labels[i] = desc[i].label;
97         attrs[i] = desc[i].attribute;
98     }
100     title = g_strdup_printf (_("%s Properties"), tag);
101     w = sp_window_new (title, TRUE);
102     g_free (title);
104     t = sp_attribute_table_new (object, len, labels, attrs);
105     gtk_widget_show (t);
106     gtk_container_add (GTK_CONTAINER (w), t);
108     g_signal_connect ( G_OBJECT (w), "destroy",
109                        G_CALLBACK (window_destroyed), object );
111     sigc::connection *release_connection = new sigc::connection();
112     *release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&object_released), w));
113     g_object_set_data(G_OBJECT(w), "release_connection", release_connection);
115     gtk_widget_show (w);
117 } // end of sp_object_attr_show_dialog()
121 void
122 sp_object_attributes_dialog (SPObject *object, const gchar *tag)
124     g_return_if_fail (object != NULL);
125     g_return_if_fail (SP_IS_OBJECT (object));
126     g_return_if_fail (tag != NULL);
128     if (!strcmp (tag, "Link")) {
129         sp_object_attr_show_dialog (object, anchor_desc, tag);
130     } else if (!strcmp (tag, "Image")) {
131         sp_object_attr_show_dialog (object, image_desc, tag);
132     } 
134 } // end of sp_object_attributes_dialog()
138 /*
139   Local Variables:
140   mode:c++
141   c-file-style:"stroustrup"
142   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
143   indent-tabs-mode:nil
144   fill-column:99
145   End:
146 */
147 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :