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 "config.h"
|
|
|
|
|
|
|
|
#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 "wine/unicode.h"
|
|
|
|
|
|
|
|
#include "msctf.h"
|
|
|
|
#include "msctf_internal.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msctf);
|
|
|
|
|
|
|
|
typedef struct tagDocumentMgr {
|
|
|
|
const ITfDocumentMgrVtbl *DocumentMgrVtbl;
|
2009-02-02 17:25:59 +01:00
|
|
|
const ITfSourceVtbl *SourceVtbl;
|
2009-01-30 21:27:06 +01:00
|
|
|
LONG refCount;
|
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;
|
2009-01-30 21:27:06 +01:00
|
|
|
} DocumentMgr;
|
|
|
|
|
2009-02-02 17:25:59 +01:00
|
|
|
static inline DocumentMgr *impl_from_ITfSourceVtbl(ITfSource *iface)
|
|
|
|
{
|
|
|
|
return (DocumentMgr *)((char *)iface - FIELD_OFFSET(DocumentMgr,SourceVtbl));
|
|
|
|
}
|
|
|
|
|
2009-01-30 21:27:06 +01:00
|
|
|
static void DocumentMgr_Destructor(DocumentMgr *This)
|
|
|
|
{
|
|
|
|
TRACE("destroying %p\n", This);
|
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]);
|
2009-01-30 21:27:06 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_QueryInterface(ITfDocumentMgr *iface, REFIID iid, LPVOID *ppvOut)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)iface;
|
|
|
|
*ppvOut = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfDocumentMgr))
|
|
|
|
{
|
|
|
|
*ppvOut = This;
|
|
|
|
}
|
2009-02-02 17:25:59 +01:00
|
|
|
else if (IsEqualIID(iid, &IID_ITfSource))
|
|
|
|
{
|
|
|
|
*ppvOut = &This->SourceVtbl;
|
|
|
|
}
|
2009-01-30 21:27:06 +01:00
|
|
|
|
|
|
|
if (*ppvOut)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("unsupported interface: %s\n", debugstr_guid(iid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DocumentMgr_AddRef(ITfDocumentMgr *iface)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)iface;
|
|
|
|
return InterlockedIncrement(&This->refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DocumentMgr_Release(ITfDocumentMgr *iface)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)iface;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)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);
|
|
|
|
return Context_Constructor(tidOwner, punk, ppic, pecTextStore);
|
2009-01-30 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DocumentMgr_Push(ITfDocumentMgr *iface, ITfContext *pic)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)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;
|
|
|
|
|
|
|
|
if (!pic || FAILED(IUnknown_QueryInterface(pic,&IID_ITfContext,(LPVOID*) &check)))
|
|
|
|
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-03-24 14:21:47 +01:00
|
|
|
ITfThreadMgrEventSink_OnPushContext(This->ThreadMgrSink,check);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)iface;
|
2009-02-02 17:25:16 +01:00
|
|
|
TRACE("(%p) 0x%x\n",This,dwFlags);
|
|
|
|
|
|
|
|
if (dwFlags == TF_POPF_ALL)
|
|
|
|
{
|
|
|
|
if (This->contextStack[0])
|
2009-03-24 14:21:47 +01:00
|
|
|
{
|
|
|
|
ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]);
|
2009-02-02 17:25:16 +01:00
|
|
|
ITfContext_Release(This->contextStack[0]);
|
2009-03-24 14:21:47 +01:00
|
|
|
}
|
2009-02-02 17:25:16 +01:00
|
|
|
if (This->contextStack[1])
|
2009-03-24 14:21:47 +01:00
|
|
|
{
|
|
|
|
ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[1]);
|
2009-02-02 17:25:16 +01:00
|
|
|
ITfContext_Release(This->contextStack[1]);
|
2009-03-24 14:21:47 +01:00
|
|
|
}
|
2009-02-02 17:25:16 +01:00
|
|
|
This->contextStack[0] = This->contextStack[1] = 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-02-02 17:25:16 +01:00
|
|
|
ITfContext_Release(This->contextStack[0]);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)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)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)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)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = (DocumentMgr *)iface;
|
|
|
|
FIXME("STUB:(%p)\n",This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ITfDocumentMgrVtbl DocumentMgr_DocumentMgrVtbl =
|
|
|
|
{
|
|
|
|
DocumentMgr_QueryInterface,
|
|
|
|
DocumentMgr_AddRef,
|
|
|
|
DocumentMgr_Release,
|
|
|
|
|
|
|
|
DocumentMgr_CreateContext,
|
|
|
|
DocumentMgr_Push,
|
|
|
|
DocumentMgr_Pop,
|
|
|
|
DocumentMgr_GetTop,
|
|
|
|
DocumentMgr_GetBase,
|
|
|
|
DocumentMgr_EnumContexts
|
|
|
|
};
|
|
|
|
|
2009-02-02 17:25:59 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
|
|
|
|
return DocumentMgr_QueryInterface((ITfDocumentMgr*)This, iid, *ppvOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Source_AddRef(ITfSource *iface)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
|
|
|
|
return DocumentMgr_AddRef((ITfDocumentMgr*)This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Source_Release(ITfSource *iface)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
|
|
|
|
return DocumentMgr_Release((ITfDocumentMgr*)This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* ITfSource functions
|
|
|
|
*****************************************************/
|
|
|
|
static WINAPI HRESULT DocumentMgrSource_AdviseSink(ITfSource *iface,
|
|
|
|
REFIID riid, IUnknown *punk, DWORD *pdwCookie)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
|
|
|
|
FIXME("STUB:(%p)\n",This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WINAPI HRESULT DocumentMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
|
|
|
|
{
|
|
|
|
DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
|
|
|
|
FIXME("STUB:(%p)\n",This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ITfSourceVtbl DocumentMgr_SourceVtbl =
|
|
|
|
{
|
|
|
|
Source_QueryInterface,
|
|
|
|
Source_AddRef,
|
|
|
|
Source_Release,
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
This->DocumentMgrVtbl= &DocumentMgr_DocumentMgrVtbl;
|
2009-02-02 17:25:59 +01:00
|
|
|
This->SourceVtbl = &DocumentMgr_SourceVtbl;
|
2009-01-30 21:27:06 +01:00
|
|
|
This->refCount = 1;
|
2009-03-24 14:21:47 +01:00
|
|
|
This->ThreadMgrSink = ThreadMgrSink;
|
2009-01-30 21:27:06 +01:00
|
|
|
|
|
|
|
TRACE("returning %p\n", This);
|
|
|
|
*ppOut = (ITfDocumentMgr*)This;
|
|
|
|
return S_OK;
|
|
|
|
}
|