Code

Extensions. Restack patch for bug #524481 (restack extension hangs for drawings with...
[inkscape.git] / src / xml / croco-node-iface.cpp
2 #include <cstring>
3 #include <string>
4 #include <glib/gstrfuncs.h>
6 #include "xml/croco-node-iface.h"
7 #include "xml/node.h"
9 static char const *
10 local_part(char const *const qname)
11 {
12     char const *ret = std::strrchr(qname, ':');
13     if (ret)
14         return ++ret;
15     else
16         return qname;
17 }
19 namespace Inkscape {
20 namespace XML {
22 extern "C" {
24 static CRXMLNodePtr get_parent(CRXMLNodePtr n) { return static_cast<Node const *>(n)->parent(); }
25 static CRXMLNodePtr get_first_child(CRXMLNodePtr n) { return static_cast<Node const *>(n)->firstChild(); }
26 static CRXMLNodePtr get_next(CRXMLNodePtr n) { return static_cast<Node const *>(n)->next(); }
28 static CRXMLNodePtr get_prev(CRXMLNodePtr cn)
29 {
30     Node const *n = static_cast<Node const *>(cn);
31     unsigned const n_pos = n->position();
32     if (n_pos) {
33         return n->parent()->nthChild(n_pos - 1);
34     } else {
35         return NULL;
36     }
37 }
39 static char *get_attr(CRXMLNodePtr n, char const *a)
40 {
41     return g_strdup(static_cast<Node const *>(n)->attribute(a));
42 }
44 static char const *get_local_name(CRXMLNodePtr n) { return local_part(static_cast<Node const *>(n)->name()); }
45 static gboolean is_element_node(CRXMLNodePtr n) { return static_cast<Node const *>(n)->type() == ELEMENT_NODE; }
46 }
48 /**
49  * @brief Interface for XML nodes used by libcroco
50  *
51  * This structure defines operations on Inkscape::XML::Node used by the libcroco
52  * CSS parsing library.
53  */
54 CRNodeIface const croco_node_iface = {
55     get_parent,
56     get_first_child,
57     get_next,
58     get_prev,
59     get_local_name,
60     get_attr,
61     g_free,
62     is_element_node
63 };
65 }
66 }
69 /*
70   Local Variables:
71   mode:c++
72   c-file-style:"stroustrup"
73   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74   indent-tabs-mode:nil
75   fill-column:99
76   End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :