Code

Filter effects dialog:
[inkscape.git] / src / dom / jsdombind.h
1 #ifndef __JSDOMBIND_H__
2 #define __JSDOMBIND_H__
3 /**
4  * Phoebe DOM Implementation.
5  *
6  * This is a C++ approximation of the W3C DOM model, which follows
7  * fairly closely the specifications in the various .idl files, copies of
8  * which are provided for reference.  Most important is this one:
9  *
10  * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11  *
12  * Authors:
13  *   Bob Jamison
14  *
15  * Copyright (C) 2006-2007 Bob Jamison
16  *
17  *  This library is free software; you can redistribute it and/or
18  *  modify it under the terms of the GNU Lesser General Public
19  *  License as published by the Free Software Foundation; either
20  *  version 2.1 of the License, or (at your option) any later version.
21  *
22  *  This library is distributed in the hope that it will be useful,
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  *  Lesser General Public License for more details.
26  *
27  *  You should have received a copy of the GNU Lesser General Public
28  *  License along with this library; if not, write to the Free Software
29  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30  */
32 #include "jsengine.h"
35 namespace org
36 {
37 namespace w3c
38 {
39 namespace dom
40 {
43 /**
44  * Wrap the W3C DOM Core classes around a JavascriptEngine.
45  */
46 class JavascriptDOMBinder
47 {
48 public:
50     /**
51      *  Constructor
52      */
53     JavascriptDOMBinder(JavascriptEngine &someEngine)
54                   : engine(someEngine)
55         { init(); }
58     /**
59      *  Destructor
60      */
61     virtual ~JavascriptDOMBinder()
62         {  }
65     JSObject *wrapDocument(const Document *doc);
67     /**
68      *  Bind with the basic DOM classes
69      */
70     bool createClasses();
72     JSObject *proto_Attr;
73     JSObject *proto_CDATASection;
74     JSObject *proto_CharacterData;
75     JSObject *proto_Comment;
76     JSObject *proto_Document;
77     JSObject *proto_DocumentFragment;
78     JSObject *proto_DocumentType;
79     JSObject *proto_DOMConfiguration;
80     JSObject *proto_DOMError;
81     JSObject *proto_DOMException;
82     JSObject *proto_DOMImplementation;
83     JSObject *proto_DOMImplementationList;
84     JSObject *proto_DOMImplementationRegistry;
85     JSObject *proto_DOMImplementationSource;
86     JSObject *proto_DOMLocator;
87     JSObject *proto_DOMStringList;
88     JSObject *proto_Element;
89     JSObject *proto_Entity;
90     JSObject *proto_EntityReference;
91     JSObject *proto_NamedNodeMap;
92     JSObject *proto_NameList;
93     JSObject *proto_Node;
94     JSObject *proto_NodeList;
95     JSObject *proto_Notation;
96     JSObject *proto_ProcessingInstruction;
97     JSObject *proto_Text;
98     JSObject *proto_TypeInfo;
99     JSObject *proto_UserDataHandler;
101 private:
103     void init()
104         {
105         rt        = engine.getRuntime();
106         cx        = engine.getContext();
107         globalObj = engine.getGlobalObject();
108         }
109     
110     /**
111      *  Assignment operator.  Let's keep this private for now,
112      *  as we want one Spidermonkey runtime per c++ shell     
113      */
114     JavascriptDOMBinder &operator=(const JavascriptDOMBinder &other)
115         { assign(other); return *this; }
117     void assign(const JavascriptDOMBinder &other)
118         {
119         rt        = other.rt;
120         cx        = other.cx;
121         globalObj = other.globalObj;
122         }
125     /**
126      * Ouput a printf-formatted error message
127      */
128     void error(char *fmt, ...)
129     #ifdef G_GNUC_PRINTF
130     G_GNUC_PRINTF(2, 3)
131     #endif
132     ;
134     /**
135      * Ouput a printf-formatted error message
136      */
137     void trace(char *fmt, ...)
138     #ifdef G_GNUC_PRINTF
139     G_GNUC_PRINTF(2, 3)
140     #endif
141     ;
143     JSRuntime *rt;
145     JSContext *cx;
147     JSObject *globalObj;
149     
150     
151     JavascriptEngine &engine;
152 };
156 } // namespace dom
157 } // namespace w3c
158 } // namespace org
161 #endif /* __JSDOMBIND_H__ */