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
= generate_Cookie(COOKIE_MAGIC_CONTEXTSINK
, 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
)
400 Context
*This
= impl_from_ITfSourceVtbl(iface
);
402 TRACE("(%p) %x\n",This
,pdwCookie
);
404 if (get_Cookie_magic(pdwCookie
)!=COOKIE_MAGIC_CONTEXTSINK
)
407 sink
= (ContextSink
*)remove_Cookie(pdwCookie
);
409 return CONNECT_E_NOCONNECTION
;
411 list_remove(&sink
->entry
);
417 static const ITfSourceVtbl Context_SourceVtbl
=
419 Source_QueryInterface
,
423 ContextSource_AdviseSink
,
424 ContextSource_UnadviseSink
,
427 HRESULT
Context_Constructor(TfClientId tidOwner
, IUnknown
*punk
, ITfContext
**ppOut
, TfEditCookie
*pecTextStore
)
431 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(Context
));
433 return E_OUTOFMEMORY
;
435 TRACE("(%p) %x %p %p %p\n",This
, tidOwner
, punk
, ppOut
, pecTextStore
);
437 This
->ContextVtbl
= &Context_ContextVtbl
;
438 This
->SourceVtbl
= &Context_SourceVtbl
;
440 This
->tidOwner
= tidOwner
;
444 if (SUCCEEDED(IUnknown_QueryInterface(punk
, &IID_ITextStoreACP
,
445 (LPVOID
*)&This
->pITextStoreACP
)))
447 if (SUCCEEDED(TextStoreACPSink_Constructor(&This
->pITextStoreACPSink
, This
)))
448 ITextStoreACP_AdviseSink(This
->pITextStoreACP
, &IID_ITextStoreACPSink
,
449 (IUnknown
*)This
->pITextStoreACPSink
, TS_AS_ALL_SINKS
);
452 IUnknown_QueryInterface(punk
, &IID_ITfContextOwnerCompositionSink
,
453 (LPVOID
*)&This
->pITfContextOwnerCompositionSink
);
455 if (!This
->pITextStoreACP
&& !This
->pITfContextOwnerCompositionSink
)
456 FIXME("Unhandled pUnk\n");
459 TRACE("returning %p\n", This
);
460 *ppOut
= (ITfContext
*)This
;
462 *pecTextStore
= 0xdeaddead;
464 list_init(&This
->pContextKeyEventSink
);
465 list_init(&This
->pEditTransactionSink
);
466 list_init(&This
->pStatusSink
);
467 list_init(&This
->pTextEditSink
);
468 list_init(&This
->pTextLayoutSink
);
473 /**************************************************************************
475 **************************************************************************/
477 static void TextStoreACPSink_Destructor(TextStoreACPSink
*This
)
479 TRACE("destroying %p\n", This
);
480 HeapFree(GetProcessHeap(),0,This
);
483 static HRESULT WINAPI
TextStoreACPSink_QueryInterface(ITextStoreACPSink
*iface
, REFIID iid
, LPVOID
*ppvOut
)
485 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
488 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITextStoreACPSink
))
495 IUnknown_AddRef(iface
);
499 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
500 return E_NOINTERFACE
;
503 static ULONG WINAPI
TextStoreACPSink_AddRef(ITextStoreACPSink
*iface
)
505 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
506 return InterlockedIncrement(&This
->refCount
);
509 static ULONG WINAPI
TextStoreACPSink_Release(ITextStoreACPSink
*iface
)
511 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
514 ret
= InterlockedDecrement(&This
->refCount
);
516 TextStoreACPSink_Destructor(This
);
520 /*****************************************************
521 * ITextStoreACPSink functions
522 *****************************************************/
524 static HRESULT WINAPI
TextStoreACPSink_OnTextChange(ITextStoreACPSink
*iface
,
525 DWORD dwFlags
, const TS_TEXTCHANGE
*pChange
)
527 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
528 FIXME("STUB:(%p)\n",This
);
532 static HRESULT WINAPI
TextStoreACPSink_OnSelectionChange(ITextStoreACPSink
*iface
)
534 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
535 FIXME("STUB:(%p)\n",This
);
539 static HRESULT WINAPI
TextStoreACPSink_OnLayoutChange(ITextStoreACPSink
*iface
,
540 TsLayoutCode lcode
, TsViewCookie vcView
)
542 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
543 FIXME("STUB:(%p)\n",This
);
547 static HRESULT WINAPI
TextStoreACPSink_OnStatusChange(ITextStoreACPSink
*iface
,
550 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
551 FIXME("STUB:(%p)\n",This
);
555 static HRESULT WINAPI
TextStoreACPSink_OnAttrsChange(ITextStoreACPSink
*iface
,
556 LONG acpStart
, LONG acpEnd
, ULONG cAttrs
, const TS_ATTRID
*paAttrs
)
558 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
559 FIXME("STUB:(%p)\n",This
);
563 static HRESULT WINAPI
TextStoreACPSink_OnLockGranted(ITextStoreACPSink
*iface
,
566 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
567 FIXME("STUB:(%p)\n",This
);
571 static HRESULT WINAPI
TextStoreACPSink_OnStartEditTransaction(ITextStoreACPSink
*iface
)
573 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
574 FIXME("STUB:(%p)\n",This
);
578 static HRESULT WINAPI
TextStoreACPSink_OnEndEditTransaction(ITextStoreACPSink
*iface
)
580 TextStoreACPSink
*This
= (TextStoreACPSink
*)iface
;
581 FIXME("STUB:(%p)\n",This
);
585 static const ITextStoreACPSinkVtbl TextStoreACPSink_TextStoreACPSinkVtbl
=
587 TextStoreACPSink_QueryInterface
,
588 TextStoreACPSink_AddRef
,
589 TextStoreACPSink_Release
,
591 TextStoreACPSink_OnTextChange
,
592 TextStoreACPSink_OnSelectionChange
,
593 TextStoreACPSink_OnLayoutChange
,
594 TextStoreACPSink_OnStatusChange
,
595 TextStoreACPSink_OnAttrsChange
,
596 TextStoreACPSink_OnLockGranted
,
597 TextStoreACPSink_OnStartEditTransaction
,
598 TextStoreACPSink_OnEndEditTransaction
601 static HRESULT
TextStoreACPSink_Constructor(ITextStoreACPSink
**ppOut
, Context
*pContext
)
603 TextStoreACPSink
*This
;
605 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextStoreACPSink
));
607 return E_OUTOFMEMORY
;
609 This
->TextStoreACPSinkVtbl
= &TextStoreACPSink_TextStoreACPSinkVtbl
;
612 This
->pContext
= pContext
;
614 TRACE("returning %p\n", This
);
615 *ppOut
= (ITextStoreACPSink
*)This
;