2 * ITfThreadMgr implementation
4 * Copyright 2008 Aric Stewart, CodeWeavers
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.
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.
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
27 #include "wine/debug.h"
37 #include "wine/unicode.h"
38 #include "wine/list.h"
41 #include "msctf_internal.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
45 typedef struct tagThreadMgrSink {
50 /* ITfActiveLanguageProfileNotifySink *pITfActiveLanguageProfileNotifySink; */
51 /* ITfDisplayAttributeNotifySink *pITfDisplayAttributeNotifySink; */
52 /* ITfKeyTraceEventSink *pITfKeyTraceEventSink; */
53 /* ITfPreservedKeyNotifySink *pITfPreservedKeyNotifySink; */
54 /* ITfThreadFocusSink *pITfThreadFocusSink; */
55 ITfThreadMgrEventSink *pITfThreadMgrEventSink;
59 typedef struct tagACLMulti {
60 const ITfThreadMgrVtbl *ThreadMgrVtbl;
61 const ITfSourceVtbl *SourceVtbl;
64 ITfDocumentMgr *focus;
66 /* kept as separate lists to reduce unnecessary iterations */
67 struct list ActiveLanguageProfileNotifySink;
68 struct list DisplayAttributeNotifySink;
69 struct list KeyTraceEventSink;
70 struct list PreservedKeyNotifySink;
71 struct list ThreadFocusSink;
72 struct list ThreadMgrEventSink;
75 static inline ThreadMgr *impl_from_ITfSourceVtbl(ITfSource *iface)
77 return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,SourceVtbl));
80 static void free_sink(ThreadMgrSink *sink)
82 IUnknown_Release(sink->interfaces.pIUnknown);
83 HeapFree(GetProcessHeap(),0,sink);
86 static void ThreadMgr_Destructor(ThreadMgr *This)
88 struct list *cursor, *cursor2;
90 TlsSetValue(tlsIndex,NULL);
91 TRACE("destroying %p\n", This);
93 ITfDocumentMgr_Release(This->focus);
96 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->ActiveLanguageProfileNotifySink)
98 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
102 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->DisplayAttributeNotifySink)
104 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
108 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->KeyTraceEventSink)
110 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
114 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->PreservedKeyNotifySink)
116 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
120 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->ThreadFocusSink)
122 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
126 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->ThreadMgrEventSink)
128 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
133 HeapFree(GetProcessHeap(),0,This);
136 static HRESULT WINAPI ThreadMgr_QueryInterface(ITfThreadMgr *iface, REFIID iid, LPVOID *ppvOut)
138 ThreadMgr *This = (ThreadMgr *)iface;
141 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgr))
145 else if (IsEqualIID(iid, &IID_ITfSource))
147 *ppvOut = &This->SourceVtbl;
152 IUnknown_AddRef(iface);
156 WARN("unsupported interface: %s\n", debugstr_guid(iid));
157 return E_NOINTERFACE;
160 static ULONG WINAPI ThreadMgr_AddRef(ITfThreadMgr *iface)
162 ThreadMgr *This = (ThreadMgr *)iface;
163 return InterlockedIncrement(&This->refCount);
166 static ULONG WINAPI ThreadMgr_Release(ITfThreadMgr *iface)
168 ThreadMgr *This = (ThreadMgr *)iface;
171 ret = InterlockedDecrement(&This->refCount);
173 ThreadMgr_Destructor(This);
177 /*****************************************************
178 * ITfThreadMgr functions
179 *****************************************************/
181 static HRESULT WINAPI ThreadMgr_fnActivate( ITfThreadMgr* iface, TfClientId *ptid)
183 ThreadMgr *This = (ThreadMgr *)iface;
184 FIXME("STUB:(%p)\n",This);
188 static HRESULT WINAPI ThreadMgr_fnDeactivate( ITfThreadMgr* iface)
190 ThreadMgr *This = (ThreadMgr *)iface;
191 FIXME("STUB:(%p)\n",This);
195 static HRESULT WINAPI ThreadMgr_CreateDocumentMgr( ITfThreadMgr* iface, ITfDocumentMgr
198 TRACE("(%p)\n",iface);
199 return DocumentMgr_Constructor(ppdim);
202 static HRESULT WINAPI ThreadMgr_EnumDocumentMgrs( ITfThreadMgr* iface, IEnumTfDocumentMgrs
205 ThreadMgr *This = (ThreadMgr *)iface;
206 FIXME("STUB:(%p)\n",This);
210 static HRESULT WINAPI ThreadMgr_GetFocus( ITfThreadMgr* iface, ITfDocumentMgr
213 ThreadMgr *This = (ThreadMgr *)iface;
214 TRACE("(%p)\n",This);
219 *ppdimFocus = This->focus;
221 TRACE("->%p\n",This->focus);
223 if (This->focus == NULL)
226 ITfDocumentMgr_AddRef(This->focus);
231 static HRESULT WINAPI ThreadMgr_SetFocus( ITfThreadMgr* iface, ITfDocumentMgr *pdimFocus)
233 ITfDocumentMgr *check;
234 ThreadMgr *This = (ThreadMgr *)iface;
236 TRACE("(%p) %p\n",This,pdimFocus);
238 if (!pdimFocus || FAILED(IUnknown_QueryInterface(pdimFocus,&IID_ITfDocumentMgr,(LPVOID*) &check)))
242 ITfDocumentMgr_Release(This->focus);
248 static HRESULT WINAPI ThreadMgr_AssociateFocus( ITfThreadMgr* iface, HWND hwnd,
249 ITfDocumentMgr *pdimNew, ITfDocumentMgr **ppdimPrev)
251 ThreadMgr *This = (ThreadMgr *)iface;
252 FIXME("STUB:(%p)\n",This);
256 static HRESULT WINAPI ThreadMgr_IsThreadFocus( ITfThreadMgr* iface, BOOL *pfThreadFocus)
258 ThreadMgr *This = (ThreadMgr *)iface;
259 FIXME("STUB:(%p)\n",This);
263 static HRESULT WINAPI ThreadMgr_GetFunctionProvider( ITfThreadMgr* iface, REFCLSID clsid,
264 ITfFunctionProvider **ppFuncProv)
266 ThreadMgr *This = (ThreadMgr *)iface;
267 FIXME("STUB:(%p)\n",This);
271 static HRESULT WINAPI ThreadMgr_EnumFunctionProviders( ITfThreadMgr* iface,
272 IEnumTfFunctionProviders **ppEnum)
274 ThreadMgr *This = (ThreadMgr *)iface;
275 FIXME("STUB:(%p)\n",This);
279 static HRESULT WINAPI ThreadMgr_GetGlobalCompartment( ITfThreadMgr* iface,
280 ITfCompartmentMgr **ppCompMgr)
282 ThreadMgr *This = (ThreadMgr *)iface;
283 FIXME("STUB:(%p)\n",This);
287 static const ITfThreadMgrVtbl ThreadMgr_ThreadMgrVtbl =
289 ThreadMgr_QueryInterface,
293 ThreadMgr_fnActivate,
294 ThreadMgr_fnDeactivate,
295 ThreadMgr_CreateDocumentMgr,
296 ThreadMgr_EnumDocumentMgrs,
299 ThreadMgr_AssociateFocus,
300 ThreadMgr_IsThreadFocus,
301 ThreadMgr_GetFunctionProvider,
302 ThreadMgr_EnumFunctionProviders,
303 ThreadMgr_GetGlobalCompartment
307 static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
309 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
310 return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
313 static ULONG WINAPI Source_AddRef(ITfSource *iface)
315 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
316 return ThreadMgr_AddRef((ITfThreadMgr*)This);
319 static ULONG WINAPI Source_Release(ITfSource *iface)
321 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
322 return ThreadMgr_Release((ITfThreadMgr *)This);
325 /*****************************************************
326 * ITfSource functions
327 *****************************************************/
328 static WINAPI HRESULT ThreadMgrSource_AdviseSink(ITfSource *iface,
329 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
332 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
334 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
336 if (!riid || !punk || !pdwCookie)
339 if (IsEqualIID(riid, &IID_ITfThreadMgrEventSink))
341 tms = HeapAlloc(GetProcessHeap(),0,sizeof(ThreadMgrSink));
343 return E_OUTOFMEMORY;
344 if (!SUCCEEDED(IUnknown_QueryInterface(punk, riid, (LPVOID*)&tms->interfaces.pITfThreadMgrEventSink)))
346 HeapFree(GetProcessHeap(),0,tms);
347 return CONNECT_E_CANNOTCONNECT;
349 list_add_head(&This->ThreadMgrEventSink,&tms->entry);
350 *pdwCookie = (DWORD)tms;
354 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
358 TRACE("cookie %x\n",*pdwCookie);
363 static WINAPI HRESULT ThreadMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
365 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
366 FIXME("STUB:(%p)\n",This);
370 static const ITfSourceVtbl ThreadMgr_SourceVtbl =
372 Source_QueryInterface,
376 ThreadMgrSource_AdviseSink,
377 ThreadMgrSource_UnadviseSink,
380 HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
384 return CLASS_E_NOAGGREGATION;
386 /* Only 1 ThreadMgr is created per thread */
387 This = TlsGetValue(tlsIndex);
390 ThreadMgr_AddRef((ITfThreadMgr*)This);
391 *ppOut = (IUnknown*)This;
395 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgr));
397 return E_OUTOFMEMORY;
399 This->ThreadMgrVtbl= &ThreadMgr_ThreadMgrVtbl;
400 This->SourceVtbl = &ThreadMgr_SourceVtbl;
402 TlsSetValue(tlsIndex,This);
404 list_init(&This->ActiveLanguageProfileNotifySink);
405 list_init(&This->DisplayAttributeNotifySink);
406 list_init(&This->KeyTraceEventSink);
407 list_init(&This->PreservedKeyNotifySink);
408 list_init(&This->ThreadFocusSink);
409 list_init(&This->ThreadMgrEventSink);
411 TRACE("returning %p\n", This);
412 *ppOut = (IUnknown *)This;