Code

New Class SPDocumentUndo created which takes care of c++fying some non SPDocument...
[inkscape.git] / src / dialogs / object-attributes.cpp
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     title = g_strdup_printf (_("%s Properties"), tag);
107     w = sp_window_new (title, TRUE);
108     g_free (title);
110     t = sp_attribute_table_new (object, len, labels, attrs);
111     gtk_widget_show (t);
112     gtk_container_add (GTK_CONTAINER (w), t);
114     g_signal_connect ( G_OBJECT (w), "destroy",
115                        G_CALLBACK (window_destroyed), object );
117     sigc::connection *release_connection = new sigc::connection();
118     *release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&object_released), w));
119     g_object_set_data(G_OBJECT(w), "release_connection", release_connection);
121     gtk_widget_show (w);
123 } // end of sp_object_attr_show_dialog()
127 void
128 sp_object_attributes_dialog (SPObject *object, const gchar *tag)
130     g_return_if_fail (object != NULL);
131     g_return_if_fail (SP_IS_OBJECT (object));
132     g_return_if_fail (tag != NULL);
134     if (!strcmp (tag, "Link")) {
135         sp_object_attr_show_dialog (object, anchor_desc, tag);
136     } else if (!strcmp (tag, "Image")) {
137         Inkscape::XML::Node *ir = SP_OBJECT_REPR(object);
138         const gchar *href = ir->attribute("xlink:href");
139         if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) {
140             sp_object_attr_show_dialog (object, image_nohref_desc, tag);
141         } else {
142             sp_object_attr_show_dialog (object, image_desc, tag);
143         }
144     } 
145 } // end of sp_object_attributes_dialog()
147 /*
148   Local Variables:
149   mode:c++
150   c-file-style:"stroustrup"
151   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
152   indent-tabs-mode:nil
153   fill-column:99
154   End:
155 */
156 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :