1 /*
2 * Copyright (C) 2007 Kevin Ollivier All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 %module webview
27
28 %{
29 #include "config.h"
30
31 #include "wx/wxPython/wxPython.h"
32 #include "wx/wxPython/pyclasses.h"
33 #include "WebBrowserShell.h"
34 #include "WebDOMSelection.h"
35 #include "WebEdit.h"
36 #include "WebFrame.h"
37 #include "WebSettings.h"
38 #include "WebView.h"
39
40 #include "WebDOMAttr.h"
41 #include "WebDOMCSSStyleDeclaration.h"
42 #include "WebDOMDocument.h"
43 #include "WebDOMDocumentFragment.h"
44 #include "WebDOMDOMSelection.h"
45 #include "WebDOMElement.h"
46 #include "WebDOMEventListener.h"
47 #include "WebDOMNamedNodeMap.h"
48 #include "WebDOMNode.h"
49 #include "WebDOMNodeList.h"
50 #include "WebDOMObject.h"
51 #include "WebDOMRange.h"
52 #include "WebDOMWebKitAnimationList.h"
53
54 #ifndef __WXMSW__
createDOMNodeSubtype(WebDOMNode * ptr,bool setThisOwn,bool isValueObject)55 PyObject* createDOMNodeSubtype(WebDOMNode* ptr, bool setThisOwn, bool isValueObject)
56 {
57 //static wxPyTypeInfoHashMap* typeInfoCache = NULL;
58
59 //if (typeInfoCache == NULL)
60 // typeInfoCache = new wxPyTypeInfoHashMap;
61
62 swig_type_info* swigType = 0; //(*typeInfoCache)[name];
63 char* name = 0;
64 if (ptr) {
65 // it wasn't in the cache, so look it up from SWIG
66 switch (ptr->nodeType()) {
67 case WebDOMNode::WEBDOM_ELEMENT_NODE:
68 name = "WebDOMElement*";
69 break;
70 case WebDOMNode::WEBDOM_ATTRIBUTE_NODE:
71 name = "WebDOMAttr*";
72 break;
73 default:
74 name = "WebDOMNode*";
75 }
76 swigType = SWIG_TypeQuery(name);
77 if (swigType) {
78 if (isValueObject) {
79 return SWIG_Python_NewPointerObj(new WebDOMNode(*ptr), swigType, setThisOwn);
80 }
81
82 return SWIG_Python_NewPointerObj(ptr, swigType, setThisOwn);
83 }
84 // if it still wasn't found, try looking for a mapped name
85 //if (swigType) {
86 // and add it to the map if found
87 // (*typeInfoCache)[className] = swigType;
88 //}
89 }
90
91 Py_INCREF(Py_None);
92
93 return Py_None;
94 }
95
createWebDOMString(PyObject * source)96 WebDOMString* createWebDOMString(PyObject* source)
97 {
98 if (!PyString_Check(source) && !PyUnicode_Check(source)) {
99 PyErr_SetString(PyExc_TypeError, "String or Unicode type required");
100 return new WebDOMString();
101 }
102
103 char* tmpPtr;
104 Py_ssize_t tmpSize;
105
106 if (PyString_Check(source))
107 PyString_AsStringAndSize(source, &tmpPtr, &tmpSize);
108 else {
109 PyObject* str = PyUnicode_AsUTF8String(source);
110 PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
111 Py_DECREF(str);
112 }
113
114 WebDOMString temp = WebDOMString::fromUTF8(tmpPtr);
115
116 return new WebDOMString(temp);
117 }
118
119 #endif
120
121
122
123 %}
124 //---------------------------------------------------------------------------
125
126 %import core.i
127 %import windows.i
128
129 #ifndef __WXMSW__
130 %typemap(out) WebDOMNode* { $result = createDOMNodeSubtype($1, (bool)$owner, 0); }
131 %typemap(out) WebDOMElement* { $result = createDOMNodeSubtype($1, (bool)$owner, 0); }
132 %typemap(out) WebDOMNode { $result = createDOMNodeSubtype(&$1, (bool)$owner, 1); }
133 %typemap(out) WebDOMElement { $result = createDOMNodeSubtype(&$1, (bool)$owner, 1); }
134 %typemap(in) WebDOMString& { $1 = createWebDOMString($input); }
135 %typemap(out) WebDOMString { $result = PyUnicode_DecodeUTF8($1.utf8().data(), $1.utf8().length(), NULL); }
136 %typemap(out) WebDOMString& { $result = PyUnicode_DecodeUTF8($1.utf8().data(), $1.utf8().length(), NULL); }
137 #endif
138
139 MAKE_CONST_WXSTRING(WebViewNameStr);
140
141 MustHaveApp(wxWebBrowserShell);
142 MustHaveApp(wxWebFrame);
143 MustHaveApp(wxWebView);
144
145 %include WebKitDefines.h
146
147 #ifndef __WXMSW__
148 %include WebDOMObject.h
149 %include WebDOMNode.h
150
151 %include WebDOMAttr.h
152 %include WebDOMDOMSelection.h
153 %include WebDOMElement.h
154 %include WebDOMNodeList.h
155 %include WebDOMRange.h
156 #endif
157
158 %include WebBrowserShell.h
159 %include WebDOMSelection.h
160 %include WebEdit.h
161 %include WebFrame.h
162 %include WebSettings.h
163 %include WebView.h
164
165 %constant wxEventType wxEVT_WEBVIEW_BEFORE_LOAD;
166 %constant wxEventType wxEVT_WEBVIEW_LOAD;
167 %constant wxEventType wxEVT_WEBVIEW_NEW_WINDOW;
168 %constant wxEventType wxEVT_WEBVIEW_RIGHT_CLICK;
169 %constant wxEventType wxEVT_WEBVIEW_CONSOLE_MESSAGE;
170 %constant wxEventType wxEVT_WEBVIEW_RECEIVED_TITLE;
171 %constant wxEventType wxEVT_WEBVIEW_CONTENTS_CHANGED;
172 %constant wxEventType wxEVT_WEBVIEW_SELECTION_CHANGED;
173
174 %pythoncode {
175 EVT_WEBVIEW_BEFORE_LOAD = wx.PyEventBinder( wxEVT_WEBVIEW_BEFORE_LOAD, 1 )
176 EVT_WEBVIEW_LOAD = wx.PyEventBinder( wxEVT_WEBVIEW_LOAD, 1 )
177 EVT_WEBVIEW_NEW_WINDOW = wx.PyEventBinder( wxEVT_WEBVIEW_NEW_WINDOW, 1 )
178 EVT_WEBVIEW_RIGHT_CLICK = wx.PyEventBinder( wxEVT_WEBVIEW_RIGHT_CLICK, 1 )
179 EVT_WEBVIEW_CONSOLE_MESSAGE = wx.PyEventBinder( wxEVT_WEBVIEW_CONSOLE_MESSAGE, 1 )
180 EVT_WEBVIEW_RECEIVED_TITLE = wx.PyEventBinder( wxEVT_WEBVIEW_RECEIVED_TITLE, 1 )
181 EVT_WEBVIEW_CONTENTS_CHANGED = wx.PyEventBinder( wxEVT_WEBVIEW_CONTENTS_CHANGED, 1 )
182 EVT_WEBVIEW_SELECTION_CHANGED = wx.PyEventBinder( wxEVT_WEBVIEW_SELECTION_CHANGED, 1 )
183 }
184