6391
by JucaBlues
initial handling of <script> tag |
1 |
/*
|
2 |
* SVG <script> implementation
|
|
3 |
*
|
|
4 |
* Authors:
|
|
8889
by Felipe C. da S. Sanches
updating my email address in file headers |
5 |
* Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
|
9945.1.1
by Jon A. Cruz
Merge and cleanup of GSoC C++-ification project. |
6 |
* Jon A. Cruz <jon@joncruz.org>
|
7 |
* Abhishek Sharma
|
|
6391
by JucaBlues
initial handling of <script> tag |
8 |
*
|
9 |
* Copyright (C) 2008 authors
|
|
10 |
*
|
|
11 |
* Released under GNU GPL version 2 or later, read the file 'COPYING' for more information
|
|
12 |
*/
|
|
13 |
||
14 |
#include "sp-script.h" |
|
7137
by JucaBlues
adding a "scripting" tab to document properties dialog that allow the user to manage external javascript references. |
15 |
#include "attributes.h" |
16 |
#include <cstring> |
|
17 |
#include "document.h" |
|
6391
by JucaBlues
initial handling of <script> tag |
18 |
|
11608.1.69
by Markus Engel
Registered classes with new factory. Hkern, Vkern and FeFuncX have to be rewritten, as they aren't real classes. |
19 |
#include "sp-factory.h" |
20 |
||
21 |
namespace { |
|
22 |
SPObject* createScript() { |
|
23 |
return new SPScript(); |
|
24 |
}
|
|
25 |
||
26 |
bool scriptRegistered = SPFactory::instance().registerObject("svg:script", createScript); |
|
27 |
}
|
|
28 |
||
11608.1.86
by Markus Engel
Merge Object and subclasses. Merging of SP- and C-classes complete. |
29 |
SPScript::SPScript() : SPObject() { |
11608.1.84
by Markus Engel
Merged more classes. |
30 |
this->xlinkhref = NULL; |
31 |
}
|
|
32 |
||
33 |
SPScript::~SPScript() { |
|
34 |
}
|
|
35 |
||
36 |
void SPScript::build(SPDocument* doc, Inkscape::XML::Node* repr) { |
|
11608.1.86
by Markus Engel
Merge Object and subclasses. Merging of SP- and C-classes complete. |
37 |
SPObject::build(doc, repr); |
11608.1.34
by Markus Engel
Added "virtual pad" to SPScript. |
38 |
|
39 |
//Read values of key attributes from XML nodes into object.
|
|
11608.1.117
by Markus Engel
Cleaned up. |
40 |
this->readAttr( "xlink:href" ); |
11608.1.34
by Markus Engel
Added "virtual pad" to SPScript. |
41 |
|
11608.1.117
by Markus Engel
Cleaned up. |
42 |
doc->addResource("script", this); |
11608.1.34
by Markus Engel
Added "virtual pad" to SPScript. |
43 |
}
|
7137
by JucaBlues
adding a "scripting" tab to document properties dialog that allow the user to manage external javascript references. |
44 |
|
45 |
/**
|
|
46 |
* Reads the Inkscape::XML::Node, and initializes SPScript variables. For this to get called,
|
|
47 |
* our name must be associated with a repr via "sp_object_type_register". Best done through
|
|
48 |
* sp-object-repr.cpp's repr_name_entries array.
|
|
49 |
*/
|
|
50 |
||
11608.1.84
by Markus Engel
Merged more classes. |
51 |
void SPScript::release() { |
11608.1.117
by Markus Engel
Cleaned up. |
52 |
if (this->document) { |
10060
by Jon A. Cruz
Finished cleanup of outated SP_OBJECT_DOCUMENT C macro. |
53 |
// Unregister ourselves
|
11608.1.117
by Markus Engel
Cleaned up. |
54 |
this->document->removeResource("script", this); |
6391
by JucaBlues
initial handling of <script> tag |
55 |
}
|
7137
by JucaBlues
adding a "scripting" tab to document properties dialog that allow the user to manage external javascript references. |
56 |
|
11608.1.86
by Markus Engel
Merge Object and subclasses. Merging of SP- and C-classes complete. |
57 |
SPObject::release(); |
11608.1.57
by Markus Engel
Renamed virtual function names. |
58 |
}
|
59 |
||
12738
by Kris
"fix" some "unused parameter" warnings |
60 |
void SPScript::update(SPCtx* /*ctx*/, unsigned int /*flags*/) { |
11608.1.84
by Markus Engel
Merged more classes. |
61 |
}
|
62 |
||
63 |
||
12738
by Kris
"fix" some "unused parameter" warnings |
64 |
void SPScript::modified(unsigned int /*flags*/) { |
11608.1.84
by Markus Engel
Merged more classes. |
65 |
}
|
66 |
||
67 |
||
68 |
void SPScript::set(unsigned int key, const gchar* value) { |
|
7137
by JucaBlues
adding a "scripting" tab to document properties dialog that allow the user to manage external javascript references. |
69 |
switch (key) { |
70 |
case SP_ATTR_XLINK_HREF: |
|
11608.1.117
by Markus Engel
Cleaned up. |
71 |
if (this->xlinkhref) { |
72 |
g_free(this->xlinkhref); |
|
73 |
}
|
|
74 |
||
75 |
this->xlinkhref = g_strdup(value); |
|
76 |
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); |
|
7137
by JucaBlues
adding a "scripting" tab to document properties dialog that allow the user to manage external javascript references. |
77 |
break; |
78 |
default: |
|
11608.1.86
by Markus Engel
Merge Object and subclasses. Merging of SP- and C-classes complete. |
79 |
SPObject::set(key, value); |
7137
by JucaBlues
adding a "scripting" tab to document properties dialog that allow the user to manage external javascript references. |
80 |
break; |
81 |
}
|
|
82 |
}
|
|
83 |
||
12738
by Kris
"fix" some "unused parameter" warnings |
84 |
Inkscape::XML::Node* SPScript::write(Inkscape::XML::Document* /*doc*/, Inkscape::XML::Node* repr, guint /*flags*/) { |
11608.1.34
by Markus Engel
Added "virtual pad" to SPScript. |
85 |
return repr; |
86 |
}
|
|
87 |
||
11608.1.56
by Markus Engel
merged from trunk |
88 |
//static Inkscape::XML::Node *sp_script_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
|
89 |
//{
|
|
6391
by JucaBlues
initial handling of <script> tag |
90 |
/*
|
91 |
TODO:
|
|
92 |
code copied from sp-defs
|
|
93 |
decide what to do here!
|
|
94 |
||
95 |
if (flags & SP_OBJECT_WRITE_BUILD) {
|
|
96 |
||
97 |
if (!repr) {
|
|
98 |
repr = xml_doc->createElement("svg:script");
|
|
99 |
}
|
|
100 |
||
101 |
GSList *l = NULL;
|
|
9945.1.1
by Jon A. Cruz
Merge and cleanup of GSoC C++-ification project. |
102 |
for ( SPObject *child = object->firstChild() ; child; child = child->getNext() ) {
|
6391
by JucaBlues
initial handling of <script> tag |
103 |
Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags);
|
9945.1.1
by Jon A. Cruz
Merge and cleanup of GSoC C++-ification project. |
104 |
if (crepr) {
|
105 |
l = g_slist_prepend(l, crepr);
|
|
106 |
}
|
|
6391
by JucaBlues
initial handling of <script> tag |
107 |
}
|
108 |
||
109 |
while (l) {
|
|
110 |
repr->addChild((Inkscape::XML::Node *) l->data, NULL);
|
|
111 |
Inkscape::GC::release((Inkscape::XML::Node *) l->data);
|
|
112 |
l = g_slist_remove(l, l->data);
|
|
113 |
}
|
|
114 |
||
115 |
} else {
|
|
9945.1.1
by Jon A. Cruz
Merge and cleanup of GSoC C++-ification project. |
116 |
for ( SPObject *child = object->firstChild() ; child; child = child->getNext() ) {
|
6391
by JucaBlues
initial handling of <script> tag |
117 |
child->updateRepr(flags);
|
118 |
}
|
|
119 |
}
|
|
120 |
||
121 |
if (((SPObjectClass *) (parent_class))->write) {
|
|
122 |
(* ((SPObjectClass *) (parent_class))->write)(object, xml_doc, repr, flags);
|
|
123 |
}
|
|
124 |
*/
|
|
11608.1.56
by Markus Engel
merged from trunk |
125 |
//
|
126 |
// return ((SPScript*)object)->cscript->onWrite(xml_doc, repr, flags);
|
|
127 |
//}
|
|
6391
by JucaBlues
initial handling of <script> tag |
128 |
|
129 |
/*
|
|
130 |
Local Variables:
|
|
131 |
mode:c++
|
|
132 |
c-file-style:"stroustrup"
|
|
133 |
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
|
|
134 |
indent-tabs-mode:nil
|
|
135 |
fill-column:99
|
|
136 |
End:
|
|
137 |
*/
|
|
138 |
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
|