2 * ITfContext implementation
4 * Copyright 2009 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 tagContextSink {
50 /* ITfContextKeyEventSink *pITfContextKeyEventSink; */
51 /* ITfEditTransactionSink *pITfEditTransactionSink; */
52 /* ITfStatusSink *pITfStatusSink; */
53 ITfTextEditSink *pITfTextEditSink;
54 /* ITfTextLayoutSink *pITfTextLayoutSink; */
58 typedef struct tagContext {
59 const ITfContextVtbl *ContextVtbl;
60 const ITfSourceVtbl *SourceVtbl;
65 ITextStoreACP *pITextStoreACP;
66 ITfContextOwnerCompositionSink *pITfContextOwnerCompositionSink;
68 ITextStoreACPSink *pITextStoreACPSink;
70 /* kept as separate lists to reduce unnecessary iterations */
71 struct list pContextKeyEventSink;
72 struct list pEditTransactionSink;
73 struct list pStatusSink;
74 struct list pTextEditSink;
75 struct list pTextLayoutSink;
80 typedef struct tagTextStoreACPSink {
81 const ITextStoreACPSinkVtbl *TextStoreACPSinkVtbl;
88 static HRESULT TextStoreACPSink_Constructor(ITextStoreACPSink **ppOut, Context *pContext);
90 static inline Context *impl_from_ITfSourceVtbl(ITfSource *iface)
92 return (Context *)((char *)iface - FIELD_OFFSET(Context,SourceVtbl));
95 static void free_sink(ContextSink *sink)
97 IUnknown_Release(sink->interfaces.pIUnknown);
98 HeapFree(GetProcessHeap(),0,sink);
101 static void Context_Destructor(Context *This)
103 struct list *cursor, *cursor2;
104 TRACE("destroying %p\n", This);
106 if (This->pITextStoreACPSink)
108 ITextStoreACP_UnadviseSink(This->pITextStoreACP, (IUnknown*)This->pITextStoreACPSink);
109 ITextStoreACPSink_Release(This->pITextStoreACPSink);
112 if (This->pITextStoreACP)
113 ITextStoreACPSink_Release(This->pITextStoreACP);
115 if (This->pITfContextOwnerCompositionSink)
116 ITextStoreACPSink_Release(This->pITfContextOwnerCompositionSink);
118 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pContextKeyEventSink)
120 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
124 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pEditTransactionSink)
126 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
130 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pStatusSink)
132 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
136 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pTextEditSink)
138 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
142 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pTextLayoutSink)
144 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
149 HeapFree(GetProcessHeap(),0,This);
152 static HRESULT WINAPI Context_QueryInterface(ITfContext *iface, REFIID iid, LPVOID *ppvOut)
154 Context *This = (Context *)iface;
157 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfContext))
161 else if (IsEqualIID(iid, &IID_ITfSource))
163 *ppvOut = &This->SourceVtbl;
168 IUnknown_AddRef(iface);
172 WARN("unsupported interface: %s\n", debugstr_guid(iid));
173 return E_NOINTERFACE;
176 static ULONG WINAPI Context_AddRef(ITfContext *iface)
178 Context *This = (Context *)iface;
179 return InterlockedIncrement(&This->refCount);
182 static ULONG WINAPI Context_Release(ITfContext *iface)
184 Context *This = (Context *)iface;
187 ret = InterlockedDecrement(&This->refCount);
189 Context_Destructor(This);
193 /*****************************************************
194 * ITfContext functions
195 *****************************************************/
196 static HRESULT WINAPI Context_RequestEditSession (ITfContext *iface,
197 TfClientId tid, ITfEditSession *pes, DWORD dwFlags,
200 Context *This = (Context *)iface;
201 FIXME("STUB:(%p)\n",This);
205 static HRESULT WINAPI Context_InWriteSession (ITfContext *iface,
207 BOOL *pfWriteSession)
209 Context *This = (Context *)iface;
210 FIXME("STUB:(%p)\n",This);
214 static HRESULT WINAPI Context_GetSelection (ITfContext *iface,
215 TfEditCookie ec, ULONG ulIndex, ULONG ulCount,
216 TF_SELECTION *pSelection, ULONG *pcFetched)
218 Context *This = (Context *)iface;
219 FIXME("STUB:(%p)\n",This);
223 static HRESULT WINAPI Context_SetSelection (ITfContext *iface,
224 TfEditCookie ec, ULONG ulCount, const TF_SELECTION *pSelection)
226 Context *This = (Context *)iface;
227 FIXME("STUB:(%p)\n",This);
231 static HRESULT WINAPI Context_GetStart (ITfContext *iface,
232 TfEditCookie ec, ITfRange **ppStart)
234 Context *This = (Context *)iface;
235 FIXME("STUB:(%p)\n",This);
239 static HRESULT WINAPI Context_GetEnd (ITfContext *iface,
240 TfEditCookie ec, ITfRange **ppEnd)
242 Context *This = (Context *)iface;
243 FIXME("STUB:(%p)\n",This);
247 static HRESULT WINAPI Context_GetActiveView (ITfContext *iface,
248 ITfContextView **ppView)
250 Context *This = (Context *)iface;
251 FIXME("STUB:(%p)\n",This);
255 static HRESULT WINAPI Context_EnumViews (ITfContext *iface,
256 IEnumTfContextViews **ppEnum)
258 Context *This = (Context *)iface;
259 FIXME("STUB:(%p)\n",This);
263 static HRESULT WINAPI Context_GetStatus (ITfContext *iface,
266 Context *This = (Context *)iface;
267 FIXME("STUB:(%p)\n",This);
271 static HRESULT WINAPI Context_GetProperty (ITfContext *iface,
272 REFGUID guidProp, ITfProperty **ppProp)
274 Context *This = (Context *)iface;
275 FIXME("STUB:(%p)\n",This);
279 static HRESULT WINAPI Context_GetAppProperty (ITfContext *iface,
280 REFGUID guidProp, ITfReadOnlyProperty **ppProp)
282 Context *This = (Context *)iface;
283 FIXME("STUB:(%p)\n",This);
287 static HRESULT WINAPI Context_TrackProperties (ITfContext *iface,
288 const GUID **prgProp, ULONG cProp, const GUID **prgAppProp,
289 ULONG cAppProp, ITfReadOnlyProperty **ppProperty)
291 Context *This = (Context *)iface;
292 FIXME("STUB:(%p)\n",This);
296 static HRESULT WINAPI Context_EnumProperties (ITfContext *iface,
297 IEnumTfProperties **ppEnum)
299 Context *This = (Context *)iface;
300 FIXME("STUB:(%p)\n",This);
304 static HRESULT WINAPI Context_GetDocumentMgr (ITfContext *iface,
305 ITfDocumentMgr **ppDm)
307 Context *This = (Context *)iface;
308 FIXME("STUB:(%p)\n",This);
312 static HRESULT WINAPI Context_CreateRangeBackup (ITfContext *iface,
313 TfEditCookie ec, ITfRange *pRange, ITfRangeBackup **ppBackup)
315 Context *This = (Context *)iface;
316 FIXME("STUB:(%p)\n",This);
320 static const ITfContextVtbl Context_ContextVtbl =
322 Context_QueryInterface,
326 Context_RequestEditSession,
327 Context_InWriteSession,
328 Context_GetSelection,
329 Context_SetSelection,
332 Context_GetActiveView,
336 Context_GetAppProperty,
337 Context_TrackProperties,
338 Context_EnumProperties,
339 Context_GetDocumentMgr,
340 Context_CreateRangeBackup
343 static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
345 Context *This = impl_from_ITfSourceVtbl(iface);
346 return Context_QueryInterface((ITfContext *)This, iid, *ppvOut);
349 static ULONG WINAPI Source_AddRef(ITfSource *iface)
351 Context *This = impl_from_ITfSourceVtbl(iface);
352 return Context_AddRef((ITfContext *)This);
355 static ULONG WINAPI Source_Release(ITfSource *iface)
357 Context *This = impl_from_ITfSourceVtbl(iface);
358 return Context_Release((ITfContext *)This);
361 /*****************************************************
362 * ITfSource functions
363 *****************************************************/
364 static WINAPI HRESULT ContextSource_AdviseSink(ITfSource *iface,
365 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
368 Context *This = impl_from_ITfSourceVtbl(iface);
369 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
371 if (!riid || !punk || !pdwCookie)
374 if (IsEqualIID(riid, &IID_ITfTextEditSink))
376 es = HeapAlloc(GetProcessHeap(),0,sizeof(ContextSink));
378 return E_OUTOFMEMORY;
379 if (!SUCCEEDED(IUnknown_QueryInterface(punk, riid, (LPVOID*)&es->interfaces.pITfTextEditSink)))
381 HeapFree(GetProcessHeap(),0,es);
382 return CONNECT_E_CANNOTCONNECT;
384 list_add_head(&This->pTextEditSink ,&es->entry);
385 *pdwCookie = (DWORD)es;
389 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
393 TRACE("cookie %x\n",*pdwCookie);
397 static WINAPI HRESULT ContextSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
399 ContextSink *sink = (ContextSink*)pdwCookie;
400 Context *This = impl_from_ITfSourceVtbl(iface);
401 TRACE("(%p) %x\n",This,pdwCookie);
403 list_remove(&sink->entry);
409 static const ITfSourceVtbl Context_SourceVtbl =
411 Source_QueryInterface,
415 ContextSource_AdviseSink,
416 ContextSource_UnadviseSink,
419 HRESULT Context_Constructor(TfClientId tidOwner, IUnknown *punk, ITfContext **ppOut, TfEditCookie *pecTextStore)
423 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Context));
425 return E_OUTOFMEMORY;
427 TRACE("(%p) %x %p %p %p\n",This, tidOwner, punk, ppOut, pecTextStore);
429 This->ContextVtbl= &Context_ContextVtbl;
430 This->SourceVtbl = &Context_SourceVtbl;
432 This->tidOwner = tidOwner;
436 if (SUCCEEDED(IUnknown_QueryInterface(punk, &IID_ITextStoreACP,
437 (LPVOID*)&This->pITextStoreACP)))
439 if (SUCCEEDED(TextStoreACPSink_Constructor(&This->pITextStoreACPSink, This)))
440 ITextStoreACP_AdviseSink(This->pITextStoreACP, &IID_ITextStoreACPSink,
441 (IUnknown*)This->pITextStoreACPSink, TS_AS_ALL_SINKS);
444 IUnknown_QueryInterface(punk, &IID_ITfContextOwnerCompositionSink,
445 (LPVOID*)&This->pITfContextOwnerCompositionSink);
447 if (!This->pITextStoreACP && !This->pITfContextOwnerCompositionSink)
448 FIXME("Unhandled pUnk\n");
451 TRACE("returning %p\n", This);
452 *ppOut = (ITfContext*)This;
454 *pecTextStore = 0xdeaddead;
456 list_init(&This->pContextKeyEventSink);
457 list_init(&This->pEditTransactionSink);
458 list_init(&This->pStatusSink);
459 list_init(&This->pTextEditSink);
460 list_init(&This->pTextLayoutSink);
465 /**************************************************************************
467 **************************************************************************/
469 static void TextStoreACPSink_Destructor(TextStoreACPSink *This)
471 TRACE("destroying %p\n", This);
472 HeapFree(GetProcessHeap(),0,This);
475 static HRESULT WINAPI TextStoreACPSink_QueryInterface(ITextStoreACPSink *iface, REFIID iid, LPVOID *ppvOut)
477 TextStoreACPSink *This = (TextStoreACPSink *)iface;
480 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACPSink))
487 IUnknown_AddRef(iface);
491 WARN("unsupported interface: %s\n", debugstr_guid(iid));
492 return E_NOINTERFACE;
495 static ULONG WINAPI TextStoreACPSink_AddRef(ITextStoreACPSink *iface)
497 TextStoreACPSink *This = (TextStoreACPSink *)iface;
498 return InterlockedIncrement(&This->refCount);
501 static ULONG WINAPI TextStoreACPSink_Release(ITextStoreACPSink *iface)
503 TextStoreACPSink *This = (TextStoreACPSink *)iface;
506 ret = InterlockedDecrement(&This->refCount);
508 TextStoreACPSink_Destructor(This);
512 /*****************************************************
513 * ITextStoreACPSink functions
514 *****************************************************/
516 static HRESULT WINAPI TextStoreACPSink_OnTextChange(ITextStoreACPSink *iface,
517 DWORD dwFlags, const TS_TEXTCHANGE *pChange)
519 TextStoreACPSink *This = (TextStoreACPSink *)iface;
520 FIXME("STUB:(%p)\n",This);
524 static HRESULT WINAPI TextStoreACPSink_OnSelectionChange(ITextStoreACPSink *iface)
526 TextStoreACPSink *This = (TextStoreACPSink *)iface;
527 FIXME("STUB:(%p)\n",This);
531 static HRESULT WINAPI TextStoreACPSink_OnLayoutChange(ITextStoreACPSink *iface,
532 TsLayoutCode lcode, TsViewCookie vcView)
534 TextStoreACPSink *This = (TextStoreACPSink *)iface;
535 FIXME("STUB:(%p)\n",This);
539 static HRESULT WINAPI TextStoreACPSink_OnStatusChange(ITextStoreACPSink *iface,
542 TextStoreACPSink *This = (TextStoreACPSink *)iface;
543 FIXME("STUB:(%p)\n",This);
547 static HRESULT WINAPI TextStoreACPSink_OnAttrsChange(ITextStoreACPSink *iface,
548 LONG acpStart, LONG acpEnd, ULONG cAttrs, const TS_ATTRID *paAttrs)
550 TextStoreACPSink *This = (TextStoreACPSink *)iface;
551 FIXME("STUB:(%p)\n",This);
555 static HRESULT WINAPI TextStoreACPSink_OnLockGranted(ITextStoreACPSink *iface,
558 TextStoreACPSink *This = (TextStoreACPSink *)iface;
559 FIXME("STUB:(%p)\n",This);
563 static HRESULT WINAPI TextStoreACPSink_OnStartEditTransaction(ITextStoreACPSink *iface)
565 TextStoreACPSink *This = (TextStoreACPSink *)iface;
566 FIXME("STUB:(%p)\n",This);
570 static HRESULT WINAPI TextStoreACPSink_OnEndEditTransaction(ITextStoreACPSink *iface)
572 TextStoreACPSink *This = (TextStoreACPSink *)iface;
573 FIXME("STUB:(%p)\n",This);
577 static const ITextStoreACPSinkVtbl TextStoreACPSink_TextStoreACPSinkVtbl =
579 TextStoreACPSink_QueryInterface,
580 TextStoreACPSink_AddRef,
581 TextStoreACPSink_Release,
583 TextStoreACPSink_OnTextChange,
584 TextStoreACPSink_OnSelectionChange,
585 TextStoreACPSink_OnLayoutChange,
586 TextStoreACPSink_OnStatusChange,
587 TextStoreACPSink_OnAttrsChange,
588 TextStoreACPSink_OnLockGranted,
589 TextStoreACPSink_OnStartEditTransaction,
590 TextStoreACPSink_OnEndEditTransaction
593 static HRESULT TextStoreACPSink_Constructor(ITextStoreACPSink **ppOut, Context *pContext)
595 TextStoreACPSink *This;
597 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACPSink));
599 return E_OUTOFMEMORY;
601 This->TextStoreACPSinkVtbl= &TextStoreACPSink_TextStoreACPSinkVtbl;
604 This->pContext = pContext;
606 TRACE("returning %p\n", This);
607 *ppOut = (ITextStoreACPSink*)This;