vbscript: Added IActiveScript::SetScriptSite implementation.
[wine] / dlls / vbscript / vbscript.c
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "ole2.h"
28
29 #include "vbscript.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
34
35 #ifdef _WIN64
36
37 #define CTXARG_T DWORDLONG
38 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
39
40 #else
41
42 #define CTXARG_T DWORD
43 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
44
45 #endif
46
47 static inline VBScript *impl_from_IActiveScript(IActiveScript *iface)
48 {
49     return CONTAINING_RECORD(iface, VBScript, IActiveScript_iface);
50 }
51
52 static HRESULT WINAPI VBScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
53 {
54     VBScript *This = impl_from_IActiveScript(iface);
55
56     if(IsEqualGUID(riid, &IID_IUnknown)) {
57         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
58         *ppv = &This->IActiveScript_iface;
59     }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
60         TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
61         *ppv = &This->IActiveScript_iface;
62     }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
63         TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
64         *ppv = &This->IActiveScriptParse_iface;
65     }else {
66         FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
67         *ppv = NULL;
68         return E_NOINTERFACE;
69     }
70
71     IUnknown_AddRef((IUnknown*)*ppv);
72     return S_OK;
73 }
74
75 static ULONG WINAPI VBScript_AddRef(IActiveScript *iface)
76 {
77     VBScript *This = impl_from_IActiveScript(iface);
78     LONG ref = InterlockedIncrement(&This->ref);
79
80     TRACE("(%p) ref=%d\n", This, ref);
81
82     return ref;
83 }
84
85 static ULONG WINAPI VBScript_Release(IActiveScript *iface)
86 {
87     VBScript *This = impl_from_IActiveScript(iface);
88     LONG ref = InterlockedDecrement(&This->ref);
89
90     TRACE("(%p) ref=%d\n", iface, ref);
91
92     if(!ref) {
93         if(This->site)
94             IActiveScriptSite_Release(This->site);
95         heap_free(This);
96     }
97
98     return ref;
99 }
100
101 static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
102 {
103     VBScript *This = impl_from_IActiveScript(iface);
104     LCID lcid;
105     HRESULT hres;
106
107     TRACE("(%p)->(%p)\n", This, pass);
108
109     if(!pass)
110         return E_POINTER;
111
112     if(This->site)
113         return E_UNEXPECTED;
114
115     if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
116         return E_UNEXPECTED;
117
118     This->site = pass;
119     IActiveScriptSite_AddRef(This->site);
120
121     hres = IActiveScriptSite_GetLCID(This->site, &lcid);
122     if(hres == S_OK)
123         This->lcid = lcid;
124
125     return S_OK;
126 }
127
128 static HRESULT WINAPI VBScript_GetScriptSite(IActiveScript *iface, REFIID riid,
129                                             void **ppvObject)
130 {
131     VBScript *This = impl_from_IActiveScript(iface);
132     FIXME("(%p)->()\n", This);
133     return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI VBScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
137 {
138     VBScript *This = impl_from_IActiveScript(iface);
139     FIXME("(%p)->(%d)\n", This, ss);
140     return S_OK;
141 }
142
143 static HRESULT WINAPI VBScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
144 {
145     VBScript *This = impl_from_IActiveScript(iface);
146     FIXME("(%p)->(%p)\n", This, pssState);
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI VBScript_Close(IActiveScript *iface)
151 {
152     VBScript *This = impl_from_IActiveScript(iface);
153     FIXME("(%p)->()\n", This);
154     return E_NOTIMPL;
155 }
156
157 static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstrName, DWORD dwFlags)
158 {
159     VBScript *This = impl_from_IActiveScript(iface);
160     FIXME("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
161     return S_OK;
162 }
163
164 static HRESULT WINAPI VBScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
165         DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
166 {
167     VBScript *This = impl_from_IActiveScript(iface);
168     FIXME("(%p)->()\n", This);
169     return E_NOTIMPL;
170 }
171
172 static HRESULT WINAPI VBScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName, IDispatch **ppdisp)
173 {
174     VBScript *This = impl_from_IActiveScript(iface);
175     FIXME("(%p)->(%p)\n", This, ppdisp);
176     return E_NOTIMPL;
177 }
178
179 static HRESULT WINAPI VBScript_GetCurrentScriptThreadID(IActiveScript *iface,
180                                                        SCRIPTTHREADID *pstridThread)
181 {
182     VBScript *This = impl_from_IActiveScript(iface);
183     FIXME("(%p)->()\n", This);
184     return E_NOTIMPL;
185 }
186
187 static HRESULT WINAPI VBScript_GetScriptThreadID(IActiveScript *iface,
188                                                 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
189 {
190     VBScript *This = impl_from_IActiveScript(iface);
191     FIXME("(%p)->()\n", This);
192     return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI VBScript_GetScriptThreadState(IActiveScript *iface,
196         SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
197 {
198     VBScript *This = impl_from_IActiveScript(iface);
199     FIXME("(%p)->()\n", This);
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI VBScript_InterruptScriptThread(IActiveScript *iface,
204         SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
205 {
206     VBScript *This = impl_from_IActiveScript(iface);
207     FIXME("(%p)->()\n", This);
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI VBScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
212 {
213     VBScript *This = impl_from_IActiveScript(iface);
214     FIXME("(%p)->()\n", This);
215     return E_NOTIMPL;
216 }
217
218 static const IActiveScriptVtbl VBScriptVtbl = {
219     VBScript_QueryInterface,
220     VBScript_AddRef,
221     VBScript_Release,
222     VBScript_SetScriptSite,
223     VBScript_GetScriptSite,
224     VBScript_SetScriptState,
225     VBScript_GetScriptState,
226     VBScript_Close,
227     VBScript_AddNamedItem,
228     VBScript_AddTypeLib,
229     VBScript_GetScriptDispatch,
230     VBScript_GetCurrentScriptThreadID,
231     VBScript_GetScriptThreadID,
232     VBScript_GetScriptThreadState,
233     VBScript_InterruptScriptThread,
234     VBScript_Clone
235 };
236
237 static inline VBScript *impl_from_IActiveScriptParse(IActiveScriptParse *iface)
238 {
239     return CONTAINING_RECORD(iface, VBScript, IActiveScriptParse_iface);
240 }
241
242 static HRESULT WINAPI VBScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
243 {
244     VBScript *This = impl_from_IActiveScriptParse(iface);
245     return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
246 }
247
248 static ULONG WINAPI VBScriptParse_AddRef(IActiveScriptParse *iface)
249 {
250     VBScript *This = impl_from_IActiveScriptParse(iface);
251     return IActiveScript_AddRef(&This->IActiveScript_iface);
252 }
253
254 static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
255 {
256     VBScript *This = impl_from_IActiveScriptParse(iface);
257     return IActiveScript_Release(&This->IActiveScript_iface);
258 }
259
260 static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
261 {
262     VBScript *This = impl_from_IActiveScriptParse(iface);
263     FIXME("(%p)\n", This);
264     return S_OK;
265 }
266
267 static HRESULT WINAPI VBScriptParse_AddScriptlet(IActiveScriptParse *iface,
268         LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
269         LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
270         CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
271         BSTR *pbstrName, EXCEPINFO *pexcepinfo)
272 {
273     VBScript *This = impl_from_IActiveScriptParse(iface);
274     FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
275           debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
276           debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
277           ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
278     return E_NOTIMPL;
279 }
280
281 static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
282         LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
283         LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
284         DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
285 {
286     VBScript *This = impl_from_IActiveScriptParse(iface);
287     FIXME("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
288           debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
289           wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
290     return E_NOTIMPL;
291 }
292
293 static const IActiveScriptParseVtbl VBScriptParseVtbl = {
294     VBScriptParse_QueryInterface,
295     VBScriptParse_AddRef,
296     VBScriptParse_Release,
297     VBScriptParse_InitNew,
298     VBScriptParse_AddScriptlet,
299     VBScriptParse_ParseScriptText
300 };
301
302 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
303 {
304     VBScript *ret;
305     HRESULT hres;
306
307     TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
308
309     ret = heap_alloc_zero(sizeof(*ret));
310     if(!ret)
311         return E_OUTOFMEMORY;
312
313     ret->IActiveScript_iface.lpVtbl = &VBScriptVtbl;
314     ret->IActiveScriptParse_iface.lpVtbl = &VBScriptParseVtbl;
315
316     ret->ref = 1;
317
318     hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
319     IActiveScript_Release(&ret->IActiveScript_iface);
320     return hres;
321 }