blob: 2b03166b9c1db05abb92c1538e8e2e2f84a14d88 [file] [log] [blame]
Aric Stewartfdbe3d12009-01-30 14:27:06 -06001/*
2 * ITfDocumentMgr implementation
3 *
4 * Copyright 2009 Aric Stewart, CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "config.h"
22
23#include <stdarg.h>
24
25#define COBJMACROS
26
27#include "wine/debug.h"
28#include "windef.h"
29#include "winbase.h"
30#include "winreg.h"
31#include "winuser.h"
32#include "shlwapi.h"
33#include "winerror.h"
34#include "objbase.h"
35
36#include "wine/unicode.h"
37
38#include "msctf.h"
39#include "msctf_internal.h"
40
41WINE_DEFAULT_DEBUG_CHANNEL(msctf);
42
43typedef struct tagDocumentMgr {
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +010044 ITfDocumentMgr ITfDocumentMgr_iface;
45 ITfSource ITfSource_iface;
Aric Stewartfdbe3d12009-01-30 14:27:06 -060046 LONG refCount;
Aric Stewartfd8c2a12009-02-02 10:25:06 -060047
Aric Stewart1ffa3512009-06-11 13:33:23 -050048 /* Aggregation */
49 ITfCompartmentMgr *CompartmentMgr;
50
Aric Stewartfd8c2a12009-02-02 10:25:06 -060051 ITfContext* contextStack[2]; /* limit of 2 contexts */
Aric Stewartdb376792009-03-24 08:21:47 -050052 ITfThreadMgrEventSink* ThreadMgrSink;
Aric Stewartfdbe3d12009-01-30 14:27:06 -060053} DocumentMgr;
54
Aric Stewart7de0b822009-06-30 14:47:12 -050055typedef struct tagEnumTfContext {
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +010056 IEnumTfContexts IEnumTfContexts_iface;
Aric Stewart7de0b822009-06-30 14:47:12 -050057 LONG refCount;
58
59 DWORD index;
60 DocumentMgr *docmgr;
61} EnumTfContext;
62
63static HRESULT EnumTfContext_Constructor(DocumentMgr* mgr, IEnumTfContexts **ppOut);
64
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +010065static inline DocumentMgr *impl_from_ITfDocumentMgr(ITfDocumentMgr *iface)
Aric Stewartaacbe972009-02-02 10:25:59 -060066{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +010067 return CONTAINING_RECORD(iface, DocumentMgr, ITfDocumentMgr_iface);
68}
69
70static inline DocumentMgr *impl_from_ITfSource(ITfSource *iface)
71{
72 return CONTAINING_RECORD(iface, DocumentMgr, ITfSource_iface);
73}
74
75static inline EnumTfContext *impl_from_IEnumTfContexts(IEnumTfContexts *iface)\
76{
77 return CONTAINING_RECORD(iface, EnumTfContext, IEnumTfContexts_iface);
Aric Stewartaacbe972009-02-02 10:25:59 -060078}
79
Aric Stewartfdbe3d12009-01-30 14:27:06 -060080static void DocumentMgr_Destructor(DocumentMgr *This)
81{
Aric Stewart171a1ad2009-07-10 07:36:56 -050082 ITfThreadMgr *tm;
Aric Stewartfdbe3d12009-01-30 14:27:06 -060083 TRACE("destroying %p\n", This);
Aric Stewart171a1ad2009-07-10 07:36:56 -050084
85 TF_GetThreadMgr(&tm);
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +010086 ThreadMgr_OnDocumentMgrDestruction(tm, &This->ITfDocumentMgr_iface);
Aric Stewart171a1ad2009-07-10 07:36:56 -050087
Aric Stewartfd8c2a12009-02-02 10:25:06 -060088 if (This->contextStack[0])
89 ITfContext_Release(This->contextStack[0]);
90 if (This->contextStack[1])
91 ITfContext_Release(This->contextStack[1]);
Aric Stewart1ffa3512009-06-11 13:33:23 -050092 CompartmentMgr_Destructor(This->CompartmentMgr);
Aric Stewartfdbe3d12009-01-30 14:27:06 -060093 HeapFree(GetProcessHeap(),0,This);
94}
95
96static HRESULT WINAPI DocumentMgr_QueryInterface(ITfDocumentMgr *iface, REFIID iid, LPVOID *ppvOut)
97{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +010098 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewartfdbe3d12009-01-30 14:27:06 -060099 *ppvOut = NULL;
100
101 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfDocumentMgr))
102 {
103 *ppvOut = This;
104 }
Aric Stewartaacbe972009-02-02 10:25:59 -0600105 else if (IsEqualIID(iid, &IID_ITfSource))
106 {
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100107 *ppvOut = &This->ITfSource_iface;
Aric Stewartaacbe972009-02-02 10:25:59 -0600108 }
Aric Stewart1ffa3512009-06-11 13:33:23 -0500109 else if (IsEqualIID(iid, &IID_ITfCompartmentMgr))
110 {
111 *ppvOut = This->CompartmentMgr;
112 }
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600113
114 if (*ppvOut)
115 {
116 IUnknown_AddRef(iface);
117 return S_OK;
118 }
119
120 WARN("unsupported interface: %s\n", debugstr_guid(iid));
121 return E_NOINTERFACE;
122}
123
124static ULONG WINAPI DocumentMgr_AddRef(ITfDocumentMgr *iface)
125{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100126 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600127 return InterlockedIncrement(&This->refCount);
128}
129
130static ULONG WINAPI DocumentMgr_Release(ITfDocumentMgr *iface)
131{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100132 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600133 ULONG ret;
134
135 ret = InterlockedDecrement(&This->refCount);
136 if (ret == 0)
137 DocumentMgr_Destructor(This);
138 return ret;
139}
140
141/*****************************************************
142 * ITfDocumentMgr functions
143 *****************************************************/
144static HRESULT WINAPI DocumentMgr_CreateContext(ITfDocumentMgr *iface,
145 TfClientId tidOwner,
146 DWORD dwFlags, IUnknown *punk, ITfContext **ppic,
147 TfEditCookie *pecTextStore)
148{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100149 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewartb712f392009-02-02 10:24:59 -0600150 TRACE("(%p) 0x%x 0x%x %p %p %p\n",This,tidOwner,dwFlags,punk,ppic,pecTextStore);
Aric Stewartca9ca582009-06-17 17:00:03 +0900151 return Context_Constructor(tidOwner, punk, iface, ppic, pecTextStore);
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600152}
153
154static HRESULT WINAPI DocumentMgr_Push(ITfDocumentMgr *iface, ITfContext *pic)
155{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100156 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewartfd8c2a12009-02-02 10:25:06 -0600157 ITfContext *check;
158
159 TRACE("(%p) %p\n",This,pic);
160
161 if (This->contextStack[1]) /* FUll */
162 return TF_E_STACKFULL;
163
164 if (!pic || FAILED(IUnknown_QueryInterface(pic,&IID_ITfContext,(LPVOID*) &check)))
165 return E_INVALIDARG;
166
Aric Stewartdb376792009-03-24 08:21:47 -0500167 if (This->contextStack[0] == NULL)
168 ITfThreadMgrEventSink_OnInitDocumentMgr(This->ThreadMgrSink,iface);
169
Aric Stewartfd8c2a12009-02-02 10:25:06 -0600170 This->contextStack[1] = This->contextStack[0];
171 This->contextStack[0] = check;
172
Aric Stewartdee4e5d2009-06-16 18:37:54 +0900173 Context_Initialize(check, iface);
Aric Stewarte73b17d2009-06-24 17:29:51 +0900174 ITfThreadMgrEventSink_OnPushContext(This->ThreadMgrSink,check);
Aric Stewartdb376792009-03-24 08:21:47 -0500175
Aric Stewartfd8c2a12009-02-02 10:25:06 -0600176 return S_OK;
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600177}
178
179static HRESULT WINAPI DocumentMgr_Pop(ITfDocumentMgr *iface, DWORD dwFlags)
180{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100181 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewartf3e20272009-02-02 10:25:16 -0600182 TRACE("(%p) 0x%x\n",This,dwFlags);
183
184 if (dwFlags == TF_POPF_ALL)
185 {
186 if (This->contextStack[0])
Aric Stewartdb376792009-03-24 08:21:47 -0500187 {
188 ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]);
Aric Stewartf3e20272009-02-02 10:25:16 -0600189 ITfContext_Release(This->contextStack[0]);
Aric Stewart7d4e1332009-05-15 14:09:58 -0500190 Context_Uninitialize(This->contextStack[0]);
Aric Stewartdb376792009-03-24 08:21:47 -0500191 }
Aric Stewartf3e20272009-02-02 10:25:16 -0600192 if (This->contextStack[1])
Aric Stewartdb376792009-03-24 08:21:47 -0500193 {
194 ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[1]);
Aric Stewartf3e20272009-02-02 10:25:16 -0600195 ITfContext_Release(This->contextStack[1]);
Aric Stewart7d4e1332009-05-15 14:09:58 -0500196 Context_Uninitialize(This->contextStack[1]);
Aric Stewartdb376792009-03-24 08:21:47 -0500197 }
Aric Stewartf3e20272009-02-02 10:25:16 -0600198 This->contextStack[0] = This->contextStack[1] = NULL;
Aric Stewartdb376792009-03-24 08:21:47 -0500199 ITfThreadMgrEventSink_OnUninitDocumentMgr(This->ThreadMgrSink, iface);
Aric Stewartf3e20272009-02-02 10:25:16 -0600200 return S_OK;
201 }
202
203 if (dwFlags)
204 return E_INVALIDARG;
205
Aric Stewarted740882009-04-10 13:16:14 -0500206 if (This->contextStack[1] == NULL) /* Cannot pop last context */
Aric Stewartf3e20272009-02-02 10:25:16 -0600207 return E_FAIL;
208
Aric Stewartdb376792009-03-24 08:21:47 -0500209 ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]);
Aric Stewartf3e20272009-02-02 10:25:16 -0600210 ITfContext_Release(This->contextStack[0]);
Aric Stewart7d4e1332009-05-15 14:09:58 -0500211 Context_Uninitialize(This->contextStack[0]);
Aric Stewartf3e20272009-02-02 10:25:16 -0600212 This->contextStack[0] = This->contextStack[1];
213 This->contextStack[1] = NULL;
214
Aric Stewartdb376792009-03-24 08:21:47 -0500215 if (This->contextStack[0] == NULL)
216 ITfThreadMgrEventSink_OnUninitDocumentMgr(This->ThreadMgrSink, iface);
217
Aric Stewartf3e20272009-02-02 10:25:16 -0600218 return S_OK;
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600219}
220
221static HRESULT WINAPI DocumentMgr_GetTop(ITfDocumentMgr *iface, ITfContext **ppic)
222{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100223 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewart130303b2009-02-02 10:25:22 -0600224 TRACE("(%p)\n",This);
225 if (!ppic)
226 return E_INVALIDARG;
227
228 if (This->contextStack[0])
229 ITfContext_AddRef(This->contextStack[0]);
230
231 *ppic = This->contextStack[0];
232
233 return S_OK;
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600234}
235
236static HRESULT WINAPI DocumentMgr_GetBase(ITfDocumentMgr *iface, ITfContext **ppic)
237{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100238 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewart846093e2009-04-10 13:16:11 -0500239 ITfContext *tgt;
240
Aric Stewarte1014b32009-02-02 10:25:30 -0600241 TRACE("(%p)\n",This);
242 if (!ppic)
243 return E_INVALIDARG;
244
245 if (This->contextStack[1])
Aric Stewart846093e2009-04-10 13:16:11 -0500246 tgt = This->contextStack[1];
247 else
248 tgt = This->contextStack[0];
Aric Stewarte1014b32009-02-02 10:25:30 -0600249
Aric Stewart846093e2009-04-10 13:16:11 -0500250 if (tgt)
251 ITfContext_AddRef(tgt);
252
253 *ppic = tgt;
Aric Stewarte1014b32009-02-02 10:25:30 -0600254
255 return S_OK;
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600256}
257
258static HRESULT WINAPI DocumentMgr_EnumContexts(ITfDocumentMgr *iface, IEnumTfContexts **ppEnum)
259{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100260 DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500261 TRACE("(%p) %p\n",This,ppEnum);
262 return EnumTfContext_Constructor(This, ppEnum);
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600263}
264
265static const ITfDocumentMgrVtbl DocumentMgr_DocumentMgrVtbl =
266{
267 DocumentMgr_QueryInterface,
268 DocumentMgr_AddRef,
269 DocumentMgr_Release,
270
271 DocumentMgr_CreateContext,
272 DocumentMgr_Push,
273 DocumentMgr_Pop,
274 DocumentMgr_GetTop,
275 DocumentMgr_GetBase,
276 DocumentMgr_EnumContexts
277};
278
Aric Stewartaacbe972009-02-02 10:25:59 -0600279
280static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
281{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100282 DocumentMgr *This = impl_from_ITfSource(iface);
283 return DocumentMgr_QueryInterface(&This->ITfDocumentMgr_iface, iid, *ppvOut);
Aric Stewartaacbe972009-02-02 10:25:59 -0600284}
285
286static ULONG WINAPI Source_AddRef(ITfSource *iface)
287{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100288 DocumentMgr *This = impl_from_ITfSource(iface);
289 return DocumentMgr_AddRef(&This->ITfDocumentMgr_iface);
Aric Stewartaacbe972009-02-02 10:25:59 -0600290}
291
292static ULONG WINAPI Source_Release(ITfSource *iface)
293{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100294 DocumentMgr *This = impl_from_ITfSource(iface);
295 return DocumentMgr_Release(&This->ITfDocumentMgr_iface);
Aric Stewartaacbe972009-02-02 10:25:59 -0600296}
297
298/*****************************************************
299 * ITfSource functions
300 *****************************************************/
Stefan Ginsberg32648d42009-09-19 23:33:29 +0200301static HRESULT WINAPI DocumentMgrSource_AdviseSink(ITfSource *iface,
Aric Stewartaacbe972009-02-02 10:25:59 -0600302 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
303{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100304 DocumentMgr *This = impl_from_ITfSource(iface);
Aric Stewartaacbe972009-02-02 10:25:59 -0600305 FIXME("STUB:(%p)\n",This);
306 return E_NOTIMPL;
307}
308
Stefan Ginsberg32648d42009-09-19 23:33:29 +0200309static HRESULT WINAPI DocumentMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
Aric Stewartaacbe972009-02-02 10:25:59 -0600310{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100311 DocumentMgr *This = impl_from_ITfSource(iface);
Aric Stewartaacbe972009-02-02 10:25:59 -0600312 FIXME("STUB:(%p)\n",This);
313 return E_NOTIMPL;
314}
315
316static const ITfSourceVtbl DocumentMgr_SourceVtbl =
317{
318 Source_QueryInterface,
319 Source_AddRef,
320 Source_Release,
321
322 DocumentMgrSource_AdviseSink,
323 DocumentMgrSource_UnadviseSink,
324};
325
Aric Stewartdb376792009-03-24 08:21:47 -0500326HRESULT DocumentMgr_Constructor(ITfThreadMgrEventSink *ThreadMgrSink, ITfDocumentMgr **ppOut)
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600327{
328 DocumentMgr *This;
329
330 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DocumentMgr));
331 if (This == NULL)
332 return E_OUTOFMEMORY;
333
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100334 This->ITfDocumentMgr_iface.lpVtbl = &DocumentMgr_DocumentMgrVtbl;
335 This->ITfSource_iface.lpVtbl = &DocumentMgr_SourceVtbl;
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600336 This->refCount = 1;
Aric Stewartdb376792009-03-24 08:21:47 -0500337 This->ThreadMgrSink = ThreadMgrSink;
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600338
Aric Stewart1ffa3512009-06-11 13:33:23 -0500339 CompartmentMgr_Constructor((IUnknown*)This, &IID_IUnknown, (IUnknown**)&This->CompartmentMgr);
340
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600341 TRACE("returning %p\n", This);
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100342 *ppOut = &This->ITfDocumentMgr_iface;
Aric Stewartfdbe3d12009-01-30 14:27:06 -0600343 return S_OK;
344}
Aric Stewart7de0b822009-06-30 14:47:12 -0500345
346/**************************************************
347 * IEnumTfContexts implementaion
348 **************************************************/
349static void EnumTfContext_Destructor(EnumTfContext *This)
350{
351 TRACE("destroying %p\n", This);
352 HeapFree(GetProcessHeap(),0,This);
353}
354
355static HRESULT WINAPI EnumTfContext_QueryInterface(IEnumTfContexts *iface, REFIID iid, LPVOID *ppvOut)
356{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100357 EnumTfContext *This = impl_from_IEnumTfContexts(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500358 *ppvOut = NULL;
359
360 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfContexts))
361 {
362 *ppvOut = This;
363 }
364
365 if (*ppvOut)
366 {
367 IUnknown_AddRef(iface);
368 return S_OK;
369 }
370
371 WARN("unsupported interface: %s\n", debugstr_guid(iid));
372 return E_NOINTERFACE;
373}
374
375static ULONG WINAPI EnumTfContext_AddRef(IEnumTfContexts *iface)
376{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100377 EnumTfContext *This = impl_from_IEnumTfContexts(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500378 return InterlockedIncrement(&This->refCount);
379}
380
381static ULONG WINAPI EnumTfContext_Release(IEnumTfContexts *iface)
382{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100383 EnumTfContext *This = impl_from_IEnumTfContexts(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500384 ULONG ret;
385
386 ret = InterlockedDecrement(&This->refCount);
387 if (ret == 0)
388 EnumTfContext_Destructor(This);
389 return ret;
390}
391
392static HRESULT WINAPI EnumTfContext_Next(IEnumTfContexts *iface,
393 ULONG ulCount, ITfContext **rgContext, ULONG *pcFetched)
394{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100395 EnumTfContext *This = impl_from_IEnumTfContexts(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500396 ULONG fetched = 0;
397
398 TRACE("(%p)\n",This);
399
400 if (rgContext == NULL) return E_POINTER;
401
402 while (fetched < ulCount)
403 {
404 if (This->index > 1)
405 break;
406
407 if (!This->docmgr->contextStack[This->index])
408 break;
409
410 *rgContext = This->docmgr->contextStack[This->index];
411 ITfContext_AddRef(*rgContext);
412
413 ++This->index;
414 ++fetched;
415 ++rgContext;
416 }
417
418 if (pcFetched) *pcFetched = fetched;
419 return fetched == ulCount ? S_OK : S_FALSE;
420}
421
422static HRESULT WINAPI EnumTfContext_Skip( IEnumTfContexts* iface, ULONG celt)
423{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100424 EnumTfContext *This = impl_from_IEnumTfContexts(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500425 TRACE("(%p)\n",This);
426 This->index += celt;
427 return S_OK;
428}
429
430static HRESULT WINAPI EnumTfContext_Reset( IEnumTfContexts* iface)
431{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100432 EnumTfContext *This = impl_from_IEnumTfContexts(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500433 TRACE("(%p)\n",This);
434 This->index = 0;
435 return S_OK;
436}
437
438static HRESULT WINAPI EnumTfContext_Clone( IEnumTfContexts *iface,
439 IEnumTfContexts **ppenum)
440{
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100441 EnumTfContext *This = impl_from_IEnumTfContexts(iface);
Aric Stewart7de0b822009-06-30 14:47:12 -0500442 HRESULT res;
443
444 TRACE("(%p)\n",This);
445
446 if (ppenum == NULL) return E_POINTER;
447
448 res = EnumTfContext_Constructor(This->docmgr, ppenum);
449 if (SUCCEEDED(res))
450 {
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100451 EnumTfContext *new_This = impl_from_IEnumTfContexts(*ppenum);
Aric Stewart7de0b822009-06-30 14:47:12 -0500452 new_This->index = This->index;
453 }
454 return res;
455}
456
457static const IEnumTfContextsVtbl IEnumTfContexts_Vtbl ={
458 EnumTfContext_QueryInterface,
459 EnumTfContext_AddRef,
460 EnumTfContext_Release,
461
462 EnumTfContext_Clone,
463 EnumTfContext_Next,
464 EnumTfContext_Reset,
465 EnumTfContext_Skip
466};
467
468static HRESULT EnumTfContext_Constructor(DocumentMgr *mgr, IEnumTfContexts **ppOut)
469{
470 EnumTfContext *This;
471
472 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfContext));
473 if (This == NULL)
474 return E_OUTOFMEMORY;
475
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100476 This->IEnumTfContexts_iface.lpVtbl = &IEnumTfContexts_Vtbl;
Aric Stewart7de0b822009-06-30 14:47:12 -0500477 This->refCount = 1;
478 This->docmgr = mgr;
479
480 TRACE("returning %p\n", This);
Michael Stefaniuc6aaf2aa2010-12-23 02:04:10 +0100481 *ppOut = &This->IEnumTfContexts_iface;
Aric Stewart7de0b822009-06-30 14:47:12 -0500482 return S_OK;
483}