diff --git a/dlls/msctf/context.c b/dlls/msctf/context.c index dff4fd88f9f..42ae71eb7d0 100644 --- a/dlls/msctf/context.c +++ b/dlls/msctf/context.c @@ -66,6 +66,7 @@ typedef struct tagContext { /* const ITfQueryEmbeddedVtbl *QueryEmbeddedVtbl; */ /* const ITfSourceSingleVtbl *SourceSingleVtbl; */ LONG refCount; + BOOL connected; TfClientId tidOwner; @@ -446,16 +447,12 @@ HRESULT Context_Constructor(TfClientId tidOwner, IUnknown *punk, ITfContext **pp This->SourceVtbl = &Context_SourceVtbl; This->refCount = 1; This->tidOwner = tidOwner; + This->connected = FALSE; if (punk) { - if (SUCCEEDED(IUnknown_QueryInterface(punk, &IID_ITextStoreACP, - (LPVOID*)&This->pITextStoreACP))) - { - if (SUCCEEDED(TextStoreACPSink_Constructor(&This->pITextStoreACPSink, This))) - ITextStoreACP_AdviseSink(This->pITextStoreACP, &IID_ITextStoreACPSink, - (IUnknown*)This->pITextStoreACPSink, TS_AS_ALL_SINKS); - } + IUnknown_QueryInterface(punk, &IID_ITextStoreACP, + (LPVOID*)&This->pITextStoreACP); IUnknown_QueryInterface(punk, &IID_ITfContextOwnerCompositionSink, (LPVOID*)&This->pITfContextOwnerCompositionSink); @@ -478,6 +475,34 @@ HRESULT Context_Constructor(TfClientId tidOwner, IUnknown *punk, ITfContext **pp return S_OK; } +HRESULT Context_Initialize(ITfContext *iface) +{ + Context *This = (Context *)iface; + + if (This->pITextStoreACP) + { + if (SUCCEEDED(TextStoreACPSink_Constructor(&This->pITextStoreACPSink, This))) + ITextStoreACP_AdviseSink(This->pITextStoreACP, &IID_ITextStoreACPSink, + (IUnknown*)This->pITextStoreACPSink, TS_AS_ALL_SINKS); + } + This->connected = TRUE; + return S_OK; +} + +HRESULT Context_Uninitialize(ITfContext *iface) +{ + Context *This = (Context *)iface; + + if (This->pITextStoreACPSink) + { + ITextStoreACP_UnadviseSink(This->pITextStoreACP, (IUnknown*)This->pITextStoreACPSink); + if (ITextStoreACPSink_Release(This->pITextStoreACPSink) == 0) + This->pITextStoreACPSink = NULL; + } + This->connected = FALSE; + return S_OK; +} + /************************************************************************** * ITextStoreACPSink **************************************************************************/ diff --git a/dlls/msctf/documentmgr.c b/dlls/msctf/documentmgr.c index e1e5b193433..7fd354aa1b8 100644 --- a/dlls/msctf/documentmgr.c +++ b/dlls/msctf/documentmgr.c @@ -138,6 +138,7 @@ static HRESULT WINAPI DocumentMgr_Push(ITfDocumentMgr *iface, ITfContext *pic) This->contextStack[0] = check; ITfThreadMgrEventSink_OnPushContext(This->ThreadMgrSink,check); + Context_Initialize(check); return S_OK; } @@ -153,11 +154,13 @@ static HRESULT WINAPI DocumentMgr_Pop(ITfDocumentMgr *iface, DWORD dwFlags) { ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]); ITfContext_Release(This->contextStack[0]); + Context_Uninitialize(This->contextStack[0]); } if (This->contextStack[1]) { ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[1]); ITfContext_Release(This->contextStack[1]); + Context_Uninitialize(This->contextStack[1]); } This->contextStack[0] = This->contextStack[1] = NULL; ITfThreadMgrEventSink_OnUninitDocumentMgr(This->ThreadMgrSink, iface); @@ -172,6 +175,7 @@ static HRESULT WINAPI DocumentMgr_Pop(ITfDocumentMgr *iface, DWORD dwFlags) ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]); ITfContext_Release(This->contextStack[0]); + Context_Uninitialize(This->contextStack[0]); This->contextStack[0] = This->contextStack[1]; This->contextStack[1] = NULL; diff --git a/dlls/msctf/msctf_internal.h b/dlls/msctf/msctf_internal.h index 15950ed616c..3dce7782a20 100644 --- a/dlls/msctf/msctf_internal.h +++ b/dlls/msctf/msctf_internal.h @@ -35,6 +35,9 @@ extern HRESULT Context_Constructor(TfClientId tidOwner, IUnknown *punk, ITfConte extern HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut); extern HRESULT CategoryMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut); +extern HRESULT Context_Initialize(ITfContext *cxt); +extern HRESULT Context_Uninitialize(ITfContext *cxt); + /* cookie function */ extern DWORD generate_Cookie(DWORD magic, LPVOID data); extern DWORD get_Cookie_magic(DWORD id);