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"
36 #include "wine/unicode.h"
37 #include "wine/list.h"
40 #include "msctf_internal.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
44 typedef struct tagThreadMgrSink {
49 /* ITfActiveLanguageProfileNotifySink *pITfActiveLanguageProfileNotifySink; */
50 /* ITfDisplayAttributeNotifySink *pITfDisplayAttributeNotifySink; */
51 /* ITfKeyTraceEventSink *pITfKeyTraceEventSink; */
52 /* ITfPreservedKeyNotifySink *pITfPreservedKeyNotifySink; */
53 /* ITfThreadFocusSink *pITfThreadFocusSink; */
54 /* ITfThreadMgrEventSink *pITfThreadMgrEventSink; */
58 typedef struct tagACLMulti {
59 const ITfThreadMgrVtbl *ThreadMgrVtbl;
60 const ITfSourceVtbl *SourceVtbl;
63 ITfDocumentMgr *focus;
65 /* kept as separate lists to reduce unnecessary iterations */
66 struct list ActiveLanguageProfileNotifySink;
67 struct list DisplayAttributeNotifySink;
68 struct list KeyTraceEventSink;
69 struct list PreservedKeyNotifySink;
70 struct list ThreadFocusSink;
71 struct list ThreadMgrEventSink;
74 static inline ThreadMgr *impl_from_ITfSourceVtbl(ITfSource *iface)
76 return (ThreadMgr *)((char *)iface - FIELD_OFFSET(ThreadMgr,SourceVtbl));
79 static void free_sink(ThreadMgrSink *sink)
81 IUnknown_Release(sink->interfaces.pIUnknown);
82 HeapFree(GetProcessHeap(),0,sink);
85 static void ThreadMgr_Destructor(ThreadMgr *This)
87 struct list *cursor, *cursor2;
89 TlsSetValue(tlsIndex,NULL);
90 TRACE("destroying %p\n", This);
92 ITfDocumentMgr_Release(This->focus);
95 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->ActiveLanguageProfileNotifySink)
97 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
101 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->DisplayAttributeNotifySink)
103 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
107 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->KeyTraceEventSink)
109 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
113 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->PreservedKeyNotifySink)
115 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
119 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->ThreadFocusSink)
121 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
125 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->ThreadMgrEventSink)
127 ThreadMgrSink* sink = LIST_ENTRY(cursor,ThreadMgrSink,entry);
132 HeapFree(GetProcessHeap(),0,This);
135 static HRESULT WINAPI ThreadMgr_QueryInterface(ITfThreadMgr *iface, REFIID iid, LPVOID *ppvOut)
137 ThreadMgr *This = (ThreadMgr *)iface;
140 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgr))
144 else if (IsEqualIID(iid, &IID_ITfSource))
146 *ppvOut = &This->SourceVtbl;
151 IUnknown_AddRef(iface);
155 WARN("unsupported interface: %s\n", debugstr_guid(iid));
156 return E_NOINTERFACE;
159 static ULONG WINAPI ThreadMgr_AddRef(ITfThreadMgr *iface)
161 ThreadMgr *This = (ThreadMgr *)iface;
162 return InterlockedIncrement(&This->refCount);
165 static ULONG WINAPI ThreadMgr_Release(ITfThreadMgr *iface)
167 ThreadMgr *This = (ThreadMgr *)iface;
170 ret = InterlockedDecrement(&This->refCount);
172 ThreadMgr_Destructor(This);
176 /*****************************************************
177 * ITfThreadMgr functions
178 *****************************************************/
180 static HRESULT WINAPI ThreadMgr_fnActivate( ITfThreadMgr* iface, TfClientId *ptid)
182 ThreadMgr *This = (ThreadMgr *)iface;
183 FIXME("STUB:(%p)\n",This);
187 static HRESULT WINAPI ThreadMgr_fnDeactivate( ITfThreadMgr* iface)
189 ThreadMgr *This = (ThreadMgr *)iface;
190 FIXME("STUB:(%p)\n",This);
194 static HRESULT WINAPI ThreadMgr_CreateDocumentMgr( ITfThreadMgr* iface, ITfDocumentMgr
197 TRACE("(%p)\n",iface);
198 return DocumentMgr_Constructor(ppdim);
201 static HRESULT WINAPI ThreadMgr_EnumDocumentMgrs( ITfThreadMgr* iface, IEnumTfDocumentMgrs
204 ThreadMgr *This = (ThreadMgr *)iface;
205 FIXME("STUB:(%p)\n",This);
209 static HRESULT WINAPI ThreadMgr_GetFocus( ITfThreadMgr* iface, ITfDocumentMgr
212 ThreadMgr *This = (ThreadMgr *)iface;
213 TRACE("(%p)\n",This);
218 *ppdimFocus = This->focus;
220 TRACE("->%p\n",This->focus);
222 if (This->focus == NULL)
225 ITfDocumentMgr_AddRef(This->focus);
230 static HRESULT WINAPI ThreadMgr_SetFocus( ITfThreadMgr* iface, ITfDocumentMgr *pdimFocus)
232 ITfDocumentMgr *check;
233 ThreadMgr *This = (ThreadMgr *)iface;
235 TRACE("(%p) %p\n",This,pdimFocus);
237 if (!pdimFocus || FAILED(IUnknown_QueryInterface(pdimFocus,&IID_ITfDocumentMgr,(LPVOID*) &check)))
241 ITfDocumentMgr_Release(This->focus);
247 static HRESULT WINAPI ThreadMgr_AssociateFocus( ITfThreadMgr* iface, HWND hwnd,
248 ITfDocumentMgr *pdimNew, ITfDocumentMgr **ppdimPrev)
250 ThreadMgr *This = (ThreadMgr *)iface;
251 FIXME("STUB:(%p)\n",This);
255 static HRESULT WINAPI ThreadMgr_IsThreadFocus( ITfThreadMgr* iface, BOOL *pfThreadFocus)
257 ThreadMgr *This = (ThreadMgr *)iface;
258 FIXME("STUB:(%p)\n",This);
262 static HRESULT WINAPI ThreadMgr_GetFunctionProvider( ITfThreadMgr* iface, REFCLSID clsid,
263 ITfFunctionProvider **ppFuncProv)
265 ThreadMgr *This = (ThreadMgr *)iface;
266 FIXME("STUB:(%p)\n",This);
270 static HRESULT WINAPI ThreadMgr_EnumFunctionProviders( ITfThreadMgr* iface,
271 IEnumTfFunctionProviders **ppEnum)
273 ThreadMgr *This = (ThreadMgr *)iface;
274 FIXME("STUB:(%p)\n",This);
278 static HRESULT WINAPI ThreadMgr_GetGlobalCompartment( ITfThreadMgr* iface,
279 ITfCompartmentMgr **ppCompMgr)
281 ThreadMgr *This = (ThreadMgr *)iface;
282 FIXME("STUB:(%p)\n",This);
286 static const ITfThreadMgrVtbl ThreadMgr_ThreadMgrVtbl =
288 ThreadMgr_QueryInterface,
292 ThreadMgr_fnActivate,
293 ThreadMgr_fnDeactivate,
294 ThreadMgr_CreateDocumentMgr,
295 ThreadMgr_EnumDocumentMgrs,
298 ThreadMgr_AssociateFocus,
299 ThreadMgr_IsThreadFocus,
300 ThreadMgr_GetFunctionProvider,
301 ThreadMgr_EnumFunctionProviders,
302 ThreadMgr_GetGlobalCompartment
306 static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
308 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
309 return ThreadMgr_QueryInterface((ITfThreadMgr *)This, iid, *ppvOut);
312 static ULONG WINAPI Source_AddRef(ITfSource *iface)
314 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
315 return ThreadMgr_AddRef((ITfThreadMgr*)This);
318 static ULONG WINAPI Source_Release(ITfSource *iface)
320 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
321 return ThreadMgr_Release((ITfThreadMgr *)This);
324 /*****************************************************
325 * ITfSource functions
326 *****************************************************/
327 static WINAPI HRESULT ThreadMgrSource_AdviseSink(ITfSource *iface,
328 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
330 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
331 FIXME("STUB:(%p)\n",This);
335 static WINAPI HRESULT ThreadMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
337 ThreadMgr *This = impl_from_ITfSourceVtbl(iface);
338 FIXME("STUB:(%p)\n",This);
342 static const ITfSourceVtbl ThreadMgr_SourceVtbl =
344 Source_QueryInterface,
348 ThreadMgrSource_AdviseSink,
349 ThreadMgrSource_UnadviseSink,
352 HRESULT ThreadMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
356 return CLASS_E_NOAGGREGATION;
358 /* Only 1 ThreadMgr is created per thread */
359 This = TlsGetValue(tlsIndex);
362 ThreadMgr_AddRef((ITfThreadMgr*)This);
363 *ppOut = (IUnknown*)This;
367 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgr));
369 return E_OUTOFMEMORY;
371 This->ThreadMgrVtbl= &ThreadMgr_ThreadMgrVtbl;
372 This->SourceVtbl = &ThreadMgr_SourceVtbl;
374 TlsSetValue(tlsIndex,This);
376 list_init(&This->ActiveLanguageProfileNotifySink);
377 list_init(&This->DisplayAttributeNotifySink);
378 list_init(&This->KeyTraceEventSink);
379 list_init(&This->PreservedKeyNotifySink);
380 list_init(&This->ThreadFocusSink);
381 list_init(&This->ThreadMgrEventSink);
383 TRACE("returning %p\n", This);
384 *ppOut = (IUnknown *)This;