2009-01-30 21:27:06 +01:00
|
|
|
/*
|
|
|
|
* ITfDocumentMgr implementation
|
|
|
|
*
|
|
|
|
* Copyright 2009 Aric Stewart, CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "msctf.h"
|
|
|
|
#include "msctf_internal.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msctf);
|
|
|
|
|
|
|
|
typedef struct tagDocumentMgr {
|
2010-12-23 02:04:10 +01:00
|
|
|
ITfDocumentMgr ITfDocumentMgr_iface;
|
|
|
|
ITfSource ITfSource_iface;
|
2009-01-30 21:27:06 +01:00
|
|
|
LONG refCount;
|
2009-02-02 17:25:06 +01:00
|
|
|
|
2009-06-11 20:33:23 +02:00
|
|
|
/* Aggregation */
|
|
|
|
ITfCompartmentMgr *CompartmentMgr;
|
|
|
|
|
2009-02-02 17:25:06 +01:00
|
|
|
ITfContext* contextStack[2]; /* limit of 2 contexts */
|
2009-03-24 14:21:47 +01:00
|
|
|
ITfThreadMgrEventSink* ThreadMgrSink;
|
2016-05-04 19:42:19 +02:00
|
|
|
|
|
|
|
struct list TransitoryExtensionSink;
|
2009-01-30 21:27:06 +01:00
|
|
|
} DocumentMgr;
|
|
|
|
|
2009-06-30 21:47:12 +02:00
|
|
|
typedef struct tagEnumTfContext {
|
2010-12-23 02:04:10 +01:00
|
|
|
IEnumTfContexts IEnumTfContexts_iface;
|
2009-06-30 21:47:12 +02:00
|
|
|
LONG refCount;
|
|
|
|
|
|
|
|
DWORD index;
|
|
|
|
DocumentMgr *docmgr;
|
|
|
|
} EnumTfContext;
|
|
|
|
|
|
|
|
static HRESULT EnumTfContext_Constructor(DocumentMgr* mgr, IEnumTfContexts **ppOut);
|
|
|
|
|
2010-12-23 02:04:10 +01:00
|
|
|
static inline DocumentMgr *impl_from_ITfDocumentMgr(ITfDocumentMgr *iface)
|
2009-02-02 17:25:59 +01:00
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
return CONTAINING_RECORD(iface, DocumentMgr, ITfDocumentMgr_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DocumentMgr *impl_from_ITfSource(ITfSource *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, DocumentMgr, ITfSource_iface);
|
|
|
|
}
|
|
|
|
|
2012-06-07 01:00:28 +02:00
|
|
|
static inline EnumTfContext *impl_from_IEnumTfContexts(IEnumTfContexts *iface)
|
2010-12-23 02:04:10 +01:00
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, EnumTfContext, IEnumTfContexts_iface);
|
2009-02-02 17:25:59 +01:00
|
|
|
}
|
|
|
|
|
2009-01-30 21:27:06 +01:00
|
|
|
static void DocumentMgr_Destructor(DocumentMgr *This)
|
|
|
|
{
|
2019-08-27 15:06:41 +02:00
|
|
|
ITfThreadMgr *tm = NULL;
|
2009-01-30 21:27:06 +01:00
|
|
|
TRACE("destroying %p\n", This);
|
2009-07-10 14:36:56 +02:00
|
|
|
|
|
|
|
TF_GetThreadMgr(&tm);
|
2019-08-27 15:06:41 +02:00
|
|
|
if (tm)
|
|
|
|
{
|
|
|
|
ThreadMgr_OnDocumentMgrDestruction(tm, &This->ITfDocumentMgr_iface);
|
|
|
|
ITfThreadMgr_Release(tm);
|
|
|
|
}
|
2009-07-10 14:36:56 +02:00
|
|
|
|
2009-02-02 17:25:06 +01:00
|
|
|
if (This->contextStack[0])
|
|
|
|
ITfContext_Release(This->contextStack[0]);
|
|
|
|
if (This->contextStack[1])
|
|
|
|
ITfContext_Release(This->contextStack[1]);
|
2016-05-04 19:42:19 +02:00
|
|
|
free_sinks(&This->TransitoryExtensionSink);
|
2009-06-11 20:33:23 +02:00
|
|
|
CompartmentMgr_Destructor(This->CompartmentMgr);
|
2009-01-30 21:27:06 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_QueryInterface(ITfDocumentMgr *iface, REFIID iid, LPVOID *ppvOut)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-01-30 21:27:06 +01:00
|
|
|
*ppvOut = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfDocumentMgr))
|
|
|
|
{
|
2013-11-17 09:21:51 +01:00
|
|
|
*ppvOut = &This->ITfDocumentMgr_iface;
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
2009-02-02 17:25:59 +01:00
|
|
|
else if (IsEqualIID(iid, &IID_ITfSource))
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
*ppvOut = &This->ITfSource_iface;
|
2009-02-02 17:25:59 +01:00
|
|
|
}
|
2009-06-11 20:33:23 +02:00
|
|
|
else if (IsEqualIID(iid, &IID_ITfCompartmentMgr))
|
|
|
|
{
|
|
|
|
*ppvOut = This->CompartmentMgr;
|
|
|
|
}
|
2009-01-30 21:27:06 +01:00
|
|
|
|
|
|
|
if (*ppvOut)
|
|
|
|
{
|
2012-08-19 20:01:36 +02:00
|
|
|
ITfDocumentMgr_AddRef(iface);
|
2009-01-30 21:27:06 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("unsupported interface: %s\n", debugstr_guid(iid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DocumentMgr_AddRef(ITfDocumentMgr *iface)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-01-30 21:27:06 +01:00
|
|
|
return InterlockedIncrement(&This->refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DocumentMgr_Release(ITfDocumentMgr *iface)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-01-30 21:27:06 +01:00
|
|
|
ULONG ret;
|
|
|
|
|
|
|
|
ret = InterlockedDecrement(&This->refCount);
|
|
|
|
if (ret == 0)
|
|
|
|
DocumentMgr_Destructor(This);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* ITfDocumentMgr functions
|
|
|
|
*****************************************************/
|
|
|
|
static HRESULT WINAPI DocumentMgr_CreateContext(ITfDocumentMgr *iface,
|
|
|
|
TfClientId tidOwner,
|
|
|
|
DWORD dwFlags, IUnknown *punk, ITfContext **ppic,
|
|
|
|
TfEditCookie *pecTextStore)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-02-02 17:24:59 +01:00
|
|
|
TRACE("(%p) 0x%x 0x%x %p %p %p\n",This,tidOwner,dwFlags,punk,ppic,pecTextStore);
|
2009-06-17 10:00:03 +02:00
|
|
|
return Context_Constructor(tidOwner, punk, iface, ppic, pecTextStore);
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_Push(ITfDocumentMgr *iface, ITfContext *pic)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-02-02 17:25:06 +01:00
|
|
|
ITfContext *check;
|
|
|
|
|
|
|
|
TRACE("(%p) %p\n",This,pic);
|
|
|
|
|
|
|
|
if (This->contextStack[1]) /* FUll */
|
|
|
|
return TF_E_STACKFULL;
|
|
|
|
|
2012-08-19 20:01:36 +02:00
|
|
|
if (!pic || FAILED(ITfContext_QueryInterface(pic,&IID_ITfContext,(LPVOID*) &check)))
|
2009-02-02 17:25:06 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2009-03-24 14:21:47 +01:00
|
|
|
if (This->contextStack[0] == NULL)
|
|
|
|
ITfThreadMgrEventSink_OnInitDocumentMgr(This->ThreadMgrSink,iface);
|
|
|
|
|
2009-02-02 17:25:06 +01:00
|
|
|
This->contextStack[1] = This->contextStack[0];
|
|
|
|
This->contextStack[0] = check;
|
|
|
|
|
2009-06-16 11:37:54 +02:00
|
|
|
Context_Initialize(check, iface);
|
2009-06-24 10:29:51 +02:00
|
|
|
ITfThreadMgrEventSink_OnPushContext(This->ThreadMgrSink,check);
|
2009-03-24 14:21:47 +01:00
|
|
|
|
2009-02-02 17:25:06 +01:00
|
|
|
return S_OK;
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_Pop(ITfDocumentMgr *iface, DWORD dwFlags)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-02-02 17:25:16 +01:00
|
|
|
TRACE("(%p) 0x%x\n",This,dwFlags);
|
|
|
|
|
|
|
|
if (dwFlags == TF_POPF_ALL)
|
|
|
|
{
|
2013-11-19 13:17:52 +01:00
|
|
|
int i;
|
|
|
|
|
2018-07-30 21:18:13 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(This->contextStack); i++)
|
2013-11-19 13:17:52 +01:00
|
|
|
if (This->contextStack[i])
|
|
|
|
{
|
|
|
|
ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink, This->contextStack[i]);
|
|
|
|
Context_Uninitialize(This->contextStack[i]);
|
|
|
|
ITfContext_Release(This->contextStack[i]);
|
|
|
|
This->contextStack[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-24 14:21:47 +01:00
|
|
|
ITfThreadMgrEventSink_OnUninitDocumentMgr(This->ThreadMgrSink, iface);
|
2009-02-02 17:25:16 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dwFlags)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2009-04-10 20:16:14 +02:00
|
|
|
if (This->contextStack[1] == NULL) /* Cannot pop last context */
|
2009-02-02 17:25:16 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
2009-03-24 14:21:47 +01:00
|
|
|
ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]);
|
2009-05-15 21:09:58 +02:00
|
|
|
Context_Uninitialize(This->contextStack[0]);
|
2012-10-11 16:49:13 +02:00
|
|
|
ITfContext_Release(This->contextStack[0]);
|
2009-02-02 17:25:16 +01:00
|
|
|
This->contextStack[0] = This->contextStack[1];
|
|
|
|
This->contextStack[1] = NULL;
|
|
|
|
|
2009-03-24 14:21:47 +01:00
|
|
|
if (This->contextStack[0] == NULL)
|
|
|
|
ITfThreadMgrEventSink_OnUninitDocumentMgr(This->ThreadMgrSink, iface);
|
|
|
|
|
2009-02-02 17:25:16 +01:00
|
|
|
return S_OK;
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_GetTop(ITfDocumentMgr *iface, ITfContext **ppic)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-02-02 17:25:22 +01:00
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
if (!ppic)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (This->contextStack[0])
|
|
|
|
ITfContext_AddRef(This->contextStack[0]);
|
|
|
|
|
|
|
|
*ppic = This->contextStack[0];
|
|
|
|
|
|
|
|
return S_OK;
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_GetBase(ITfDocumentMgr *iface, ITfContext **ppic)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-04-10 20:16:11 +02:00
|
|
|
ITfContext *tgt;
|
|
|
|
|
2009-02-02 17:25:30 +01:00
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
if (!ppic)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (This->contextStack[1])
|
2009-04-10 20:16:11 +02:00
|
|
|
tgt = This->contextStack[1];
|
|
|
|
else
|
|
|
|
tgt = This->contextStack[0];
|
|
|
|
|
|
|
|
if (tgt)
|
|
|
|
ITfContext_AddRef(tgt);
|
2009-02-02 17:25:30 +01:00
|
|
|
|
2009-04-10 20:16:11 +02:00
|
|
|
*ppic = tgt;
|
2009-02-02 17:25:30 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_EnumContexts(ITfDocumentMgr *iface, IEnumTfContexts **ppEnum)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfDocumentMgr(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
TRACE("(%p) %p\n",This,ppEnum);
|
|
|
|
return EnumTfContext_Constructor(This, ppEnum);
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:14:45 +01:00
|
|
|
static const ITfDocumentMgrVtbl DocumentMgrVtbl =
|
2009-01-30 21:27:06 +01:00
|
|
|
{
|
|
|
|
DocumentMgr_QueryInterface,
|
|
|
|
DocumentMgr_AddRef,
|
|
|
|
DocumentMgr_Release,
|
|
|
|
DocumentMgr_CreateContext,
|
|
|
|
DocumentMgr_Push,
|
|
|
|
DocumentMgr_Pop,
|
|
|
|
DocumentMgr_GetTop,
|
|
|
|
DocumentMgr_GetBase,
|
|
|
|
DocumentMgr_EnumContexts
|
|
|
|
};
|
|
|
|
|
2013-11-19 13:14:45 +01:00
|
|
|
static HRESULT WINAPI DocumentMgrSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
|
2009-02-02 17:25:59 +01:00
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfSource(iface);
|
2013-11-17 09:22:17 +01:00
|
|
|
return ITfDocumentMgr_QueryInterface(&This->ITfDocumentMgr_iface, iid, ppvOut);
|
2009-02-02 17:25:59 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:14:45 +01:00
|
|
|
static ULONG WINAPI DocumentMgrSource_AddRef(ITfSource *iface)
|
2009-02-02 17:25:59 +01:00
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfSource(iface);
|
2013-11-17 09:21:51 +01:00
|
|
|
return ITfDocumentMgr_AddRef(&This->ITfDocumentMgr_iface);
|
2009-02-02 17:25:59 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:14:45 +01:00
|
|
|
static ULONG WINAPI DocumentMgrSource_Release(ITfSource *iface)
|
2009-02-02 17:25:59 +01:00
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfSource(iface);
|
2013-11-17 09:21:51 +01:00
|
|
|
return ITfDocumentMgr_Release(&This->ITfDocumentMgr_iface);
|
2009-02-02 17:25:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* ITfSource functions
|
|
|
|
*****************************************************/
|
2009-09-19 23:33:29 +02:00
|
|
|
static HRESULT WINAPI DocumentMgrSource_AdviseSink(ITfSource *iface,
|
2009-02-02 17:25:59 +01:00
|
|
|
REFIID riid, IUnknown *punk, DWORD *pdwCookie)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfSource(iface);
|
2016-05-04 19:42:19 +02:00
|
|
|
|
|
|
|
TRACE("(%p) %s %p %p\n", This, debugstr_guid(riid), punk, pdwCookie);
|
|
|
|
|
|
|
|
if (!riid || !punk || !pdwCookie)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_ITfTransitoryExtensionSink))
|
|
|
|
{
|
|
|
|
WARN("semi-stub for ITfTransitoryExtensionSink: callback won't be used.\n");
|
|
|
|
return advise_sink(&This->TransitoryExtensionSink, &IID_ITfTransitoryExtensionSink,
|
|
|
|
COOKIE_MAGIC_DMSINK, punk, pdwCookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
|
2009-02-02 17:25:59 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-09-19 23:33:29 +02:00
|
|
|
static HRESULT WINAPI DocumentMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
|
2009-02-02 17:25:59 +01:00
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
DocumentMgr *This = impl_from_ITfSource(iface);
|
2016-05-04 19:42:19 +02:00
|
|
|
|
|
|
|
TRACE("(%p) %x\n",This,pdwCookie);
|
|
|
|
|
|
|
|
if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_DMSINK)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return unadvise_sink(pdwCookie);
|
2009-02-02 17:25:59 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:14:45 +01:00
|
|
|
static const ITfSourceVtbl DocumentMgrSourceVtbl =
|
2009-02-02 17:25:59 +01:00
|
|
|
{
|
2013-11-19 13:14:45 +01:00
|
|
|
DocumentMgrSource_QueryInterface,
|
|
|
|
DocumentMgrSource_AddRef,
|
|
|
|
DocumentMgrSource_Release,
|
2009-02-02 17:25:59 +01:00
|
|
|
DocumentMgrSource_AdviseSink,
|
|
|
|
DocumentMgrSource_UnadviseSink,
|
|
|
|
};
|
|
|
|
|
2009-03-24 14:21:47 +01:00
|
|
|
HRESULT DocumentMgr_Constructor(ITfThreadMgrEventSink *ThreadMgrSink, ITfDocumentMgr **ppOut)
|
2009-01-30 21:27:06 +01:00
|
|
|
{
|
|
|
|
DocumentMgr *This;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DocumentMgr));
|
|
|
|
if (This == NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2013-11-19 13:14:45 +01:00
|
|
|
This->ITfDocumentMgr_iface.lpVtbl = &DocumentMgrVtbl;
|
|
|
|
This->ITfSource_iface.lpVtbl = &DocumentMgrSourceVtbl;
|
2009-01-30 21:27:06 +01:00
|
|
|
This->refCount = 1;
|
2009-03-24 14:21:47 +01:00
|
|
|
This->ThreadMgrSink = ThreadMgrSink;
|
2016-05-04 19:42:19 +02:00
|
|
|
list_init(&This->TransitoryExtensionSink);
|
2009-01-30 21:27:06 +01:00
|
|
|
|
2013-11-19 13:14:45 +01:00
|
|
|
CompartmentMgr_Constructor((IUnknown*)&This->ITfDocumentMgr_iface, &IID_IUnknown, (IUnknown**)&This->CompartmentMgr);
|
2009-06-11 20:33:23 +02:00
|
|
|
|
2010-12-23 02:04:10 +01:00
|
|
|
*ppOut = &This->ITfDocumentMgr_iface;
|
2013-11-19 13:14:45 +01:00
|
|
|
TRACE("returning %p\n", *ppOut);
|
2009-01-30 21:27:06 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2009-06-30 21:47:12 +02:00
|
|
|
|
|
|
|
/**************************************************
|
2011-08-24 15:28:14 +02:00
|
|
|
* IEnumTfContexts implementation
|
2009-06-30 21:47:12 +02:00
|
|
|
**************************************************/
|
|
|
|
static void EnumTfContext_Destructor(EnumTfContext *This)
|
|
|
|
{
|
|
|
|
TRACE("destroying %p\n", This);
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumTfContext_QueryInterface(IEnumTfContexts *iface, REFIID iid, LPVOID *ppvOut)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *This = impl_from_IEnumTfContexts(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
*ppvOut = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfContexts))
|
|
|
|
{
|
2013-11-17 09:21:51 +01:00
|
|
|
*ppvOut = &This->IEnumTfContexts_iface;
|
2009-06-30 21:47:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*ppvOut)
|
|
|
|
{
|
2012-08-19 20:01:36 +02:00
|
|
|
IEnumTfContexts_AddRef(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("unsupported interface: %s\n", debugstr_guid(iid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI EnumTfContext_AddRef(IEnumTfContexts *iface)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *This = impl_from_IEnumTfContexts(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
return InterlockedIncrement(&This->refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI EnumTfContext_Release(IEnumTfContexts *iface)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *This = impl_from_IEnumTfContexts(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
ULONG ret;
|
|
|
|
|
|
|
|
ret = InterlockedDecrement(&This->refCount);
|
|
|
|
if (ret == 0)
|
|
|
|
EnumTfContext_Destructor(This);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumTfContext_Next(IEnumTfContexts *iface,
|
|
|
|
ULONG ulCount, ITfContext **rgContext, ULONG *pcFetched)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *This = impl_from_IEnumTfContexts(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
ULONG fetched = 0;
|
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
if (rgContext == NULL) return E_POINTER;
|
|
|
|
|
|
|
|
while (fetched < ulCount)
|
|
|
|
{
|
|
|
|
if (This->index > 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!This->docmgr->contextStack[This->index])
|
|
|
|
break;
|
|
|
|
|
|
|
|
*rgContext = This->docmgr->contextStack[This->index];
|
|
|
|
ITfContext_AddRef(*rgContext);
|
|
|
|
|
|
|
|
++This->index;
|
|
|
|
++fetched;
|
|
|
|
++rgContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pcFetched) *pcFetched = fetched;
|
|
|
|
return fetched == ulCount ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumTfContext_Skip( IEnumTfContexts* iface, ULONG celt)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *This = impl_from_IEnumTfContexts(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
This->index += celt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumTfContext_Reset( IEnumTfContexts* iface)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *This = impl_from_IEnumTfContexts(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
This->index = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumTfContext_Clone( IEnumTfContexts *iface,
|
|
|
|
IEnumTfContexts **ppenum)
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *This = impl_from_IEnumTfContexts(iface);
|
2009-06-30 21:47:12 +02:00
|
|
|
HRESULT res;
|
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
if (ppenum == NULL) return E_POINTER;
|
|
|
|
|
|
|
|
res = EnumTfContext_Constructor(This->docmgr, ppenum);
|
|
|
|
if (SUCCEEDED(res))
|
|
|
|
{
|
2010-12-23 02:04:10 +01:00
|
|
|
EnumTfContext *new_This = impl_from_IEnumTfContexts(*ppenum);
|
2009-06-30 21:47:12 +02:00
|
|
|
new_This->index = This->index;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumTfContextsVtbl IEnumTfContexts_Vtbl ={
|
|
|
|
EnumTfContext_QueryInterface,
|
|
|
|
EnumTfContext_AddRef,
|
|
|
|
EnumTfContext_Release,
|
|
|
|
|
|
|
|
EnumTfContext_Clone,
|
|
|
|
EnumTfContext_Next,
|
|
|
|
EnumTfContext_Reset,
|
|
|
|
EnumTfContext_Skip
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT EnumTfContext_Constructor(DocumentMgr *mgr, IEnumTfContexts **ppOut)
|
|
|
|
{
|
|
|
|
EnumTfContext *This;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfContext));
|
|
|
|
if (This == NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-23 02:04:10 +01:00
|
|
|
This->IEnumTfContexts_iface.lpVtbl = &IEnumTfContexts_Vtbl;
|
2009-06-30 21:47:12 +02:00
|
|
|
This->refCount = 1;
|
|
|
|
This->docmgr = mgr;
|
|
|
|
|
2010-12-23 02:04:10 +01:00
|
|
|
*ppOut = &This->IEnumTfContexts_iface;
|
2013-11-19 13:14:45 +01:00
|
|
|
TRACE("returning %p\n", *ppOut);
|
2009-06-30 21:47:12 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|