Revert r66580 and r66579.
[reactos.git] / reactos / dll / win32 / mshtml / service.c
1 /*
2 * Copyright 2005 Jacek Caban
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 "mshtml_private.h"
20
21 typedef struct {
22 IOleUndoManager IOleUndoManager_iface;
23
24 LONG ref;
25 } UndoManager;
26
27 static inline UndoManager *impl_from_IOleUndoManager(IOleUndoManager *iface)
28 {
29 return CONTAINING_RECORD(iface, UndoManager, IOleUndoManager_iface);
30 }
31
32 static HRESULT WINAPI OleUndoManager_QueryInterface(IOleUndoManager *iface, REFIID riid, void **ppv)
33 {
34 UndoManager *This = impl_from_IOleUndoManager(iface);
35
36 if(IsEqualGUID(riid, &IID_IUnknown)) {
37 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
38 *ppv = &This->IOleUndoManager_iface;
39 }else if(IsEqualGUID(riid, &IID_IOleUndoManager)) {
40 TRACE("(%p)->(IID_IOleUndoManager %p)\n", This, ppv);
41 *ppv = &This->IOleUndoManager_iface;
42 }else {
43 *ppv = NULL;
44 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
45 return E_NOINTERFACE;
46 }
47
48 IUnknown_AddRef((IUnknown*)*ppv);
49 return S_OK;
50 }
51
52 static ULONG WINAPI OleUndoManager_AddRef(IOleUndoManager *iface)
53 {
54 UndoManager *This = impl_from_IOleUndoManager(iface);
55 LONG ref = InterlockedIncrement(&This->ref);
56
57 TRACE("(%p) ref=%d\n", This, ref);
58
59 return ref;
60 }
61
62 static ULONG WINAPI OleUndoManager_Release(IOleUndoManager *iface)
63 {
64 UndoManager *This = impl_from_IOleUndoManager(iface);
65 LONG ref = InterlockedDecrement(&This->ref);
66
67 TRACE("(%p) ref=%d\n", This, ref);
68
69 if(!ref)
70 heap_free(This);
71
72 return ref;
73 }
74
75 static HRESULT WINAPI OleUndoManager_Open(IOleUndoManager *iface, IOleParentUndoUnit *pPUU)
76 {
77 UndoManager *This = impl_from_IOleUndoManager(iface);
78 FIXME("(%p)->(%p)\n", This, pPUU);
79 return E_NOTIMPL;
80 }
81
82 static HRESULT WINAPI OleUndoManager_Close(IOleUndoManager *iface, IOleParentUndoUnit *pPUU,
83 BOOL fCommit)
84 {
85 UndoManager *This = impl_from_IOleUndoManager(iface);
86 FIXME("(%p)->(%p %x)\n", This, pPUU, fCommit);
87 return E_NOTIMPL;
88 }
89
90 static HRESULT WINAPI OleUndoManager_Add(IOleUndoManager *iface, IOleUndoUnit *pUU)
91 {
92 UndoManager *This = impl_from_IOleUndoManager(iface);
93 FIXME("(%p)->(%p)\n", This, pUU);
94 return E_NOTIMPL;
95 }
96
97 static HRESULT WINAPI OleUndoManager_GetOpenParentState(IOleUndoManager *iface, DWORD *pdwState)
98 {
99 UndoManager *This = impl_from_IOleUndoManager(iface);
100 FIXME("(%p)->(%p)\n", This, pdwState);
101 return E_NOTIMPL;
102 }
103
104 static HRESULT WINAPI OleUndoManager_DiscardFrom(IOleUndoManager *iface, IOleUndoUnit *pUU)
105 {
106 UndoManager *This = impl_from_IOleUndoManager(iface);
107 FIXME("(%p)->(%p)\n", This, pUU);
108 return S_OK;
109 }
110
111 static HRESULT WINAPI OleUndoManager_UndoTo(IOleUndoManager *iface, IOleUndoUnit *pUU)
112 {
113 UndoManager *This = impl_from_IOleUndoManager(iface);
114 FIXME("(%p)->(%p)\n", This, pUU);
115 return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI OleUndoManager_RedoTo(IOleUndoManager *iface, IOleUndoUnit *pUU)
119 {
120 UndoManager *This = impl_from_IOleUndoManager(iface);
121 FIXME("(%p)->(%p)\n", This, pUU);
122 return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI OleUndoManager_EnumUndoable(IOleUndoManager *iface,
126 IEnumOleUndoUnits **ppEnum)
127 {
128 UndoManager *This = impl_from_IOleUndoManager(iface);
129 FIXME("(%p)->(%p)\n", This, ppEnum);
130 return E_NOTIMPL;
131 }
132
133 static HRESULT WINAPI OleUndoManager_EnumRedoable(IOleUndoManager *iface,
134 IEnumOleUndoUnits **ppEnum)
135 {
136 UndoManager *This = impl_from_IOleUndoManager(iface);
137 FIXME("(%p)->(%p)\n", This, ppEnum);
138 return E_NOTIMPL;
139 }
140
141 static HRESULT WINAPI OleUndoManager_GetLastUndoDescription(IOleUndoManager *iface, BSTR *pBstr)
142 {
143 UndoManager *This = impl_from_IOleUndoManager(iface);
144 FIXME("(%p)->(%p)\n", This, pBstr);
145 return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI OleUndoManager_GetLastRedoDescription(IOleUndoManager *iface, BSTR *pBstr)
149 {
150 UndoManager *This = impl_from_IOleUndoManager(iface);
151 FIXME("(%p)->(%p)\n", This, pBstr);
152 return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI OleUndoManager_Enable(IOleUndoManager *iface, BOOL fEnable)
156 {
157 UndoManager *This = impl_from_IOleUndoManager(iface);
158 FIXME("(%p)->(%x)\n", This, fEnable);
159 return E_NOTIMPL;
160 }
161
162 static const IOleUndoManagerVtbl OleUndoManagerVtbl = {
163 OleUndoManager_QueryInterface,
164 OleUndoManager_AddRef,
165 OleUndoManager_Release,
166 OleUndoManager_Open,
167 OleUndoManager_Close,
168 OleUndoManager_Add,
169 OleUndoManager_GetOpenParentState,
170 OleUndoManager_DiscardFrom,
171 OleUndoManager_UndoTo,
172 OleUndoManager_RedoTo,
173 OleUndoManager_EnumUndoable,
174 OleUndoManager_EnumRedoable,
175 OleUndoManager_GetLastUndoDescription,
176 OleUndoManager_GetLastRedoDescription,
177 OleUndoManager_Enable
178 };
179
180 static IOleUndoManager *create_undomgr(void)
181 {
182 UndoManager *ret = heap_alloc(sizeof(UndoManager));
183
184 ret->IOleUndoManager_iface.lpVtbl = &OleUndoManagerVtbl;
185 ret->ref = 1;
186
187 return &ret->IOleUndoManager_iface;
188 }
189
190 /**********************************************************
191 * IServiceProvider implementation
192 */
193
194 static inline HTMLDocument *impl_from_IServiceProvider(IServiceProvider *iface)
195 {
196 return CONTAINING_RECORD(iface, HTMLDocument, IServiceProvider_iface);
197 }
198
199 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
200 {
201 HTMLDocument *This = impl_from_IServiceProvider(iface);
202 return htmldoc_query_interface(This, riid, ppv);
203 }
204
205 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
206 {
207 HTMLDocument *This = impl_from_IServiceProvider(iface);
208 return htmldoc_addref(This);
209 }
210
211 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
212 {
213 HTMLDocument *This = impl_from_IServiceProvider(iface);
214 return htmldoc_release(This);
215 }
216
217 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
218 REFIID riid, void **ppv)
219 {
220 HTMLDocument *This = impl_from_IServiceProvider(iface);
221
222 if(IsEqualGUID(&CLSID_CMarkup, guidService)) {
223 FIXME("(%p)->(CLSID_CMarkup %s %p)\n", This, debugstr_guid(riid), ppv);
224 return E_NOINTERFACE;
225 }
226
227 if(IsEqualGUID(&SID_SOleUndoManager, guidService)) {
228 TRACE("SID_SOleUndoManager\n");
229
230 if(!This->doc_obj->undomgr)
231 This->doc_obj->undomgr = create_undomgr();
232
233 return IOleUndoManager_QueryInterface(This->doc_obj->undomgr, riid, ppv);
234 }
235
236 if(IsEqualGUID(&SID_SContainerDispatch, guidService)) {
237 TRACE("SID_SContainerDispatch\n");
238 return IHTMLDocument2_QueryInterface(&This->IHTMLDocument2_iface, riid, ppv);
239 }
240
241 if(IsEqualGUID(&IID_IWindowForBindingUI, guidService)) {
242 TRACE("IID_IWindowForBindingUI\n");
243 return IWindowForBindingUI_QueryInterface(&This->doc_obj->IWindowForBindingUI_iface, riid, ppv);
244 }
245
246 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
247
248 if(This->doc_obj->client) {
249 HRESULT hres;
250
251 hres = do_query_service((IUnknown*)This->doc_obj->client, guidService, riid, ppv);
252 if(SUCCEEDED(hres))
253 return hres;
254 }
255
256 FIXME("unknown service %s\n", debugstr_guid(guidService));
257 return E_NOINTERFACE;
258 }
259
260 static const IServiceProviderVtbl ServiceProviderVtbl = {
261 ServiceProvider_QueryInterface,
262 ServiceProvider_AddRef,
263 ServiceProvider_Release,
264 ServiceProvider_QueryService
265 };
266
267 void HTMLDocument_Service_Init(HTMLDocument *This)
268 {
269 This->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
270 }