Code

Cmake: restructure build files to be more like current build system. Should reduce...
[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>
17 #include "helper/window.h"
18 #include "macros.h"
19 #include "sp-anchor.h"
20 #include "sp-attribute-widget.h"
21 #include "../xml/repr.h"
23 #include <sigc++/connection.h>
24 #include <sigc++/functors/ptr_fun.h>
25 #include <sigc++/adaptors/bind.h>
27 struct SPAttrDesc {
28     gchar const *label;
29     gchar const *attribute;
30 };
32 static const SPAttrDesc anchor_desc[] = {
33     { N_("Href:"), "xlink:href"},
34     { N_("Target:"), "target"},
35     { N_("Type:"), "xlink:type"},
36     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute
37     // Identifies the type of the related resource with an absolute URI
38     { N_("Role:"), "xlink:role"},
39     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute
40     // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link.
41     { N_("Arcrole:"), "xlink:arcrole"},
42     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute
43     { N_("Title:"), "xlink:title"},
44     { N_("Show:"), "xlink:show"},
45     // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute
46     { N_("Actuate:"), "xlink:actuate"},
47     { NULL, NULL}
48 };
50 static const SPAttrDesc image_desc[] = {
51     { N_("URL:"), "xlink:href"},
52     { N_("X:"), "x"},
53     { N_("Y:"), "y"},
54     { N_("Width:"), "width"},
55     { N_("Height:"), "height"},
56     { NULL, NULL}
57 };
59 static const SPAttrDesc image_nohref_desc[] = {
60     { N_("X:"), "x"},
61     { N_("Y:"), "y"},
62     { N_("Width:"), "width"},
63     { N_("Height:"), "height"},
64     { NULL, NULL}
65 };
68 static void
69 object_released( SPObject */*object*/, GtkWidget *widget )
70 {
71     gtk_widget_destroy (widget);
72 }
76 static void
77 window_destroyed( GtkObject *window, GtkObject */*object*/ )
78 {
79     sigc::connection *release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(window), "release_connection");
80     release_connection->disconnect();
81     delete release_connection;
82 }
86 static void
87 sp_object_attr_show_dialog ( SPObject *object,
88                              const SPAttrDesc *desc,
89                              const gchar *tag )
90 {
91     const gchar **labels, **attrs;
92     gint len, i;
93     gchar *title;
94     GtkWidget *w, *t;
96     len = 0;
97     while (desc[len].label) len += 1;
99     labels = (const gchar **)alloca (len * sizeof (char *));
100     attrs = (const gchar **)alloca (len * sizeof (char *));
102     for (i = 0; i < len; i++) {
103         labels[i] = desc[i].label;
104         attrs[i] = desc[i].attribute;
105     }
107     title = g_strdup_printf (_("%s Properties"), tag);
108     w = sp_window_new (title, TRUE);
109     g_free (title);
111     t = sp_attribute_table_new (object, len, labels, attrs);
112     gtk_widget_show (t);
113     gtk_container_add (GTK_CONTAINER (w), t);
115     g_signal_connect ( G_OBJECT (w), "destroy",
116                        G_CALLBACK (window_destroyed), object );
118     sigc::connection *release_connection = new sigc::connection();
119     *release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&object_released), w));
120     g_object_set_data(G_OBJECT(w), "release_connection", release_connection);
122     gtk_widget_show (w);
124 } // end of sp_object_attr_show_dialog()
128 void
129 sp_object_attributes_dialog (SPObject *object, const gchar *tag)
131     g_return_if_fail (object != NULL);
132     g_return_if_fail (SP_IS_OBJECT (object));
133     g_return_if_fail (tag != NULL);
135     if (!strcmp (tag, "Link")) {
136         sp_object_attr_show_dialog (object, anchor_desc, tag);
137     } else if (!strcmp (tag, "Image")) {
138         Inkscape::XML::Node *ir = SP_OBJECT_REPR(object);
139         const gchar *href = ir->attribute("xlink:href");
140         if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) {
141             sp_object_attr_show_dialog (object, image_nohref_desc, tag);
142         } else {
143             sp_object_attr_show_dialog (object, image_desc, tag);
144         }
145     } 
146 } // end of sp_object_attributes_dialog()
148 /*
149   Local Variables:
150   mode:c++
151   c-file-style:"stroustrup"
152   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
153   indent-tabs-mode:nil
154   fill-column:99
155   End:
156 */
157 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :