From c082108e24f9d3461875fd95a2cf654b17289ac8 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 13 Mar 2018 22:51:23 +0100 Subject: [PATCH] msctf: Added semi-stub support for ITfKeyTraceEventSink event sink. Signed-off-by: Jacek Caban Signed-off-by: Aric Stewart Signed-off-by: Alexandre Julliard --- dlls/msctf/msctf_internal.h | 1 + dlls/msctf/tests/inputprocessor.c | 59 +++++++++++++++++++++++++++++-- dlls/msctf/threadmgr.c | 12 ++++++- include/msctf.idl | 17 +++++++++ 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/dlls/msctf/msctf_internal.h b/dlls/msctf/msctf_internal.h index d5e7fe0d038..9d375483616 100644 --- a/dlls/msctf/msctf_internal.h +++ b/dlls/msctf/msctf_internal.h @@ -31,6 +31,7 @@ #define COOKIE_MAGIC_COMPARTMENTSINK 0x0060 #define COOKIE_MAGIC_DMSINK 0x0070 #define COOKIE_MAGIC_THREADFOCUSSINK 0x0080 +#define COOKIE_MAGIC_KEYTRACESINK 0x0090 extern DWORD tlsIndex DECLSPEC_HIDDEN; extern TfClientId processId DECLSPEC_HIDDEN; diff --git a/dlls/msctf/tests/inputprocessor.c b/dlls/msctf/tests/inputprocessor.c index 9bd112c8304..8a02f951175 100644 --- a/dlls/msctf/tests/inputprocessor.c +++ b/dlls/msctf/tests/inputprocessor.c @@ -64,6 +64,7 @@ static DWORD tmSinkCookie; static DWORD tmSinkRefCount; static DWORD dmSinkCookie; static DWORD documentStatus; +static DWORD key_trace_sink_cookie; static ITfDocumentMgr *test_CurrentFocus = NULL; static ITfDocumentMgr *test_PrevFocus = NULL; static ITfDocumentMgr *test_LastCurrentFocus = FOCUS_SAVE; @@ -625,6 +626,51 @@ static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut) return S_OK; } +static HRESULT WINAPI TfKeyTraceEventSink_QueryInterface(ITfKeyTraceEventSink *iface, REFIID riid, void **ppv) +{ + if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ITfKeyTraceEventSink, riid)) { + *ppv = iface; + return S_OK; + } + + *ppv = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI TfKeyTraceEventSink_AddRef(ITfKeyTraceEventSink *iface) +{ + return 2; +} + +static ULONG WINAPI TfKeyTraceEventSink_Release(ITfKeyTraceEventSink *iface) +{ + return 1; +} + +static HRESULT WINAPI TfKeyTraceEventSink_OnKeyTraceDown(ITfKeyTraceEventSink *iface, + WPARAM wparam, LPARAM lparam) +{ + ok(0, "unexpected call\n"); + return E_NOTIMPL; +} + +static HRESULT WINAPI TfKeyTraceEventSink_OnKeyTraceUp(ITfKeyTraceEventSink *iface, + WPARAM wparam, LPARAM lparam) +{ + ok(0, "unexpected call\n"); + return E_NOTIMPL; +} + +static const ITfKeyTraceEventSinkVtbl TfKeyTraceEventSinkVtbl = { + TfKeyTraceEventSink_QueryInterface, + TfKeyTraceEventSink_AddRef, + TfKeyTraceEventSink_Release, + TfKeyTraceEventSink_OnKeyTraceDown, + TfKeyTraceEventSink_OnKeyTraceUp +}; + +static ITfKeyTraceEventSink TfKeyTraceEventSink = { &TfKeyTraceEventSinkVtbl }; + static HRESULT WINAPI TfTransitoryExtensionSink_QueryInterface(ITfTransitoryExtensionSink *iface, REFIID riid, void **ppv) { if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ITfTransitoryExtensionSink, riid)) { @@ -1070,13 +1116,18 @@ static void test_ThreadMgrAdviseSinks(void) tmSinkRefCount = 1; tmSinkCookie = 0; hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie); - ok(SUCCEEDED(hr),"Failed to Advise Sink\n"); + ok(hr == S_OK, "Failed to Advise Sink\n"); ok(tmSinkCookie!=0,"Failed to get sink cookie\n"); /* Advising the sink adds a ref, Releasing here lets the object be deleted when unadvised */ tmSinkRefCount = 2; IUnknown_Release(sink); + + hr = ITfSource_AdviseSink(source, &IID_ITfKeyTraceEventSink, (IUnknown*)&TfKeyTraceEventSink, + &key_trace_sink_cookie); + ok(hr == S_OK, "Failed to Advise Sink\n"); + ITfSource_Release(source); } @@ -1092,7 +1143,11 @@ static void test_ThreadMgrUnadviseSinks(void) tmSinkRefCount = 1; hr = ITfSource_UnadviseSink(source, tmSinkCookie); - ok(SUCCEEDED(hr),"Failed to unadvise Sink\n"); + ok(hr == S_OK, "Failed to unadvise Sink\n"); + + hr = ITfSource_UnadviseSink(source, key_trace_sink_cookie); + ok(hr == S_OK, "Failed to unadvise Sink\n"); + ITfSource_Release(source); } diff --git a/dlls/msctf/threadmgr.c b/dlls/msctf/threadmgr.c index 8ca12ac0788..5338e7271c5 100644 --- a/dlls/msctf/threadmgr.c +++ b/dlls/msctf/threadmgr.c @@ -621,6 +621,13 @@ static HRESULT WINAPI ThreadMgrSource_AdviseSink(ITfSource *iface, return advise_sink(&This->ThreadFocusSink, &IID_ITfThreadFocusSink, COOKIE_MAGIC_THREADFOCUSSINK, punk, pdwCookie); } + if (IsEqualIID(riid, &IID_ITfKeyTraceEventSink)) + { + WARN("semi-stub for ITfKeyTraceEventSink: sink won't be used.\n"); + return advise_sink(&This->KeyTraceEventSink, &IID_ITfKeyTraceEventSink, + COOKIE_MAGIC_KEYTRACESINK, punk, pdwCookie); + } + FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid)); return E_NOTIMPL; } @@ -628,10 +635,13 @@ static HRESULT WINAPI ThreadMgrSource_AdviseSink(ITfSource *iface, static HRESULT WINAPI ThreadMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie) { ThreadMgr *This = impl_from_ITfSource(iface); + DWORD magic; TRACE("(%p) %x\n",This,pdwCookie); - if (get_Cookie_magic(pdwCookie) != COOKIE_MAGIC_TMSINK && get_Cookie_magic(pdwCookie) != COOKIE_MAGIC_THREADFOCUSSINK) + magic = get_Cookie_magic(pdwCookie); + if (magic != COOKIE_MAGIC_TMSINK && magic != COOKIE_MAGIC_THREADFOCUSSINK + && magic != COOKIE_MAGIC_KEYTRACESINK) return E_INVALIDARG; return unadvise_sink(pdwCookie); diff --git a/include/msctf.idl b/include/msctf.idl index 0b96faa02ca..01e944cf5df 100644 --- a/include/msctf.idl +++ b/include/msctf.idl @@ -1119,6 +1119,23 @@ interface ITfKeyEventSink : IUnknown [out] BOOL *pfEaten); } +[ + object, + local, + uuid(1cd4c13b-1c36-4191-a70a-7f3e611f367d), + pointer_default(unique) +] +interface ITfKeyTraceEventSink : IUnknown +{ + HRESULT OnKeyTraceDown( + [in] WPARAM wParam, + [in] LPARAM lParam); + + HRESULT OnKeyTraceUp( + [in] WPARAM wParam, + [in] LPARAM lParam); +} + [ object, local,