summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/object-attributes.cpp
blob: 95882111262fbd2c7b67a5029ef7b9e0c7f14670 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * Generic object attribute editor
 *//*
 * Authors:
 * see git history
 * Kris De Gussem <Kris.DeGussem@gmail.com>
 *
 * Copyright (C) 2018 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */


#include <glibmm/i18n.h>

#include "desktop.h"
#include "inkscape.h"

#include "object/sp-anchor.h"
#include "object/sp-image.h"

#include "ui/dialog/object-attributes.h"

#include "widgets/sp-attribute-widget.h"

namespace Inkscape {
namespace UI {
namespace Dialog {

struct SPAttrDesc {
    gchar const *label;
    gchar const *attribute;
};

static const SPAttrDesc anchor_desc[] = {
    { N_("Href:"), "xlink:href"},
    { N_("Target:"), "target"},
    { N_("Type:"), "xlink:type"},
    // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute
    // Identifies the type of the related resource with an absolute URI
    { N_("Role:"), "xlink:role"},
    // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute
    // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link.
    { N_("Arcrole:"), "xlink:arcrole"},
    // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute
    { N_("Title:"), "xlink:title"},
    { N_("Show:"), "xlink:show"},
    // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute
    { N_("Actuate:"), "xlink:actuate"},
    { nullptr, nullptr}
};

static const SPAttrDesc image_desc[] = {
    { N_("URL:"), "xlink:href"},
    { N_("X:"), "x"},
    { N_("Y:"), "y"},
    { N_("Width:"), "width"},
    { N_("Height:"), "height"},
    { nullptr, nullptr}
};

static const SPAttrDesc image_nohref_desc[] = {
    { N_("X:"), "x"},
    { N_("Y:"), "y"},
    { N_("Width:"), "width"},
    { N_("Height:"), "height"},
    { nullptr, nullptr}
};

ObjectAttributes::ObjectAttributes()
    : DialogBase("/dialogs/objectattr/", "ObjectAttributes")
    , blocked(false)
    , CurrentItem(nullptr)
    , attrTable(Gtk::manage(new SPAttributeTable()))
{
    attrTable->show();
}

void ObjectAttributes::widget_setup ()
{
    if (blocked || !getDesktop()) {
        return;
    }

    Inkscape::Selection *selection = getDesktop()->getSelection();
    SPItem *item = selection->singleItem();
    if (!item)
    {
        set_sensitive (false);
        CurrentItem = nullptr;
        //no selection anymore or multiple objects selected, means that we need
        //to close the connections to the previously selected object
        return;
    }

    blocked = true;

    // CPPIFY
    SPObject *obj = item; //to get the selected item
//    GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type
//    GType type = G_TYPE_FROM_CLASS(klass);
    const SPAttrDesc *desc;

//    if (type == SP_TYPE_ANCHOR)
    if (SP_IS_ANCHOR(item))
    {
        desc = anchor_desc;
    }
//    else if (type == SP_TYPE_IMAGE)
    else if (SP_IS_IMAGE(item))
    {
        Inkscape::XML::Node *ir = obj->getRepr();
        const gchar *href = ir->attribute("xlink:href");
        if ( (!href) || ((strncmp(href, "data:", 5) == 0)) )
        {
            desc = image_nohref_desc;
        }
        else
        {
            desc = image_desc;
        }
    }
    else
    {
        blocked = false;
        set_sensitive (false);
        return;
    }

    std::vector<Glib::ustring> labels;
    std::vector<Glib::ustring> attrs;
    if (CurrentItem != item)
    {
        int len = 0;
        while (desc[len].label)
        {
            labels.emplace_back(desc[len].label);
            attrs.emplace_back(desc[len].attribute);
            len += 1;
        }
        attrTable->set_object(obj, labels, attrs, (GtkWidget*)gobj());
        CurrentItem = item;
    }
    else
    {
        attrTable->change_object(obj);
    }

    set_sensitive (true);
    show_all();
    blocked = false;
}

void ObjectAttributes::selectionChanged(Selection *selection)
{
    widget_setup();
}

void ObjectAttributes::selectionModified(Selection *selection, guint flags)
{
    if (flags & ( SP_OBJECT_MODIFIED_FLAG |
                   SP_OBJECT_PARENT_MODIFIED_FLAG |
                   SP_OBJECT_STYLE_MODIFIED_FLAG) ) {
        attrTable->reread_properties();
    }
}


}
}
}

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :