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;
61 /* const ITfContextCompositionVtbl *ContextCompositionVtbl; */
62 /* const ITfContextOwnerCompositionServicesVtbl *ContextOwnerCompositionServicesVtbl; */
63 /* const ITfContextOwnerServicesVtbl *ContextOwnerServicesVtbl; */
64 const ITfInsertAtSelectionVtbl *InsertAtSelectionVtbl;
65 /* const ITfMouseTrackerVtbl *MouseTrackerVtbl; */
66 /* const ITfQueryEmbeddedVtbl *QueryEmbeddedVtbl; */
67 /* const ITfSourceSingleVtbl *SourceSingleVtbl; */
72 TfEditCookie defaultCookie;
73 TS_STATUS documentStatus;
75 ITextStoreACP *pITextStoreACP;
76 ITfContextOwnerCompositionSink *pITfContextOwnerCompositionSink;
78 ITextStoreACPSink *pITextStoreACPSink;
79 ITfEditSession* currentEditSession;
81 /* kept as separate lists to reduce unnecessary iterations */
82 struct list pContextKeyEventSink;
83 struct list pEditTransactionSink;
84 struct list pStatusSink;
85 struct list pTextEditSink;
86 struct list pTextLayoutSink;
90 typedef struct tagEditCookie {
92 Context *pOwningContext;
95 typedef struct tagTextStoreACPSink {
96 const ITextStoreACPSinkVtbl *TextStoreACPSinkVtbl;
97 /* const ITextStoreACPServicesVtbl *TextStoreACPServicesVtbl; */
104 static HRESULT TextStoreACPSink_Constructor(ITextStoreACPSink **ppOut, Context *pContext);
106 static inline Context *impl_from_ITfSourceVtbl(ITfSource *iface)
108 return (Context *)((char *)iface - FIELD_OFFSET(Context,SourceVtbl));
111 static inline Context *impl_from_ITfInsertAtSelectionVtbl(ITfInsertAtSelection*iface)
113 return (Context *)((char *)iface - FIELD_OFFSET(Context,InsertAtSelectionVtbl));
116 static void free_sink(ContextSink *sink)
118 IUnknown_Release(sink->interfaces.pIUnknown);
119 HeapFree(GetProcessHeap(),0,sink);
122 static void Context_Destructor(Context *This)
124 struct list *cursor, *cursor2;
126 TRACE("destroying %p\n", This);
128 if (This->pITextStoreACPSink)
130 ITextStoreACP_UnadviseSink(This->pITextStoreACP, (IUnknown*)This->pITextStoreACPSink);
131 ITextStoreACPSink_Release(This->pITextStoreACPSink);
134 if (This->pITextStoreACP)
135 ITextStoreACPSink_Release(This->pITextStoreACP);
137 if (This->pITfContextOwnerCompositionSink)
138 ITextStoreACPSink_Release(This->pITfContextOwnerCompositionSink);
140 if (This->defaultCookie)
142 cookie = remove_Cookie(This->defaultCookie);
143 HeapFree(GetProcessHeap(),0,cookie);
144 This->defaultCookie = 0;
147 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pContextKeyEventSink)
149 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
153 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pEditTransactionSink)
155 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
159 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pStatusSink)
161 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
165 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pTextEditSink)
167 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
171 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->pTextLayoutSink)
173 ContextSink* sink = LIST_ENTRY(cursor,ContextSink,entry);
178 HeapFree(GetProcessHeap(),0,This);
181 static HRESULT WINAPI Context_QueryInterface(ITfContext *iface, REFIID iid, LPVOID *ppvOut)
183 Context *This = (Context *)iface;
186 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfContext))
190 else if (IsEqualIID(iid, &IID_ITfSource))
192 *ppvOut = &This->SourceVtbl;
194 else if (IsEqualIID(iid, &IID_ITfInsertAtSelection))
196 *ppvOut = &This->InsertAtSelectionVtbl;
201 IUnknown_AddRef(iface);
205 WARN("unsupported interface: %s\n", debugstr_guid(iid));
206 return E_NOINTERFACE;
209 static ULONG WINAPI Context_AddRef(ITfContext *iface)
211 Context *This = (Context *)iface;
212 return InterlockedIncrement(&This->refCount);
215 static ULONG WINAPI Context_Release(ITfContext *iface)
217 Context *This = (Context *)iface;
220 ret = InterlockedDecrement(&This->refCount);
222 Context_Destructor(This);
226 /*****************************************************
227 * ITfContext functions
228 *****************************************************/
229 static HRESULT WINAPI Context_RequestEditSession (ITfContext *iface,
230 TfClientId tid, ITfEditSession *pes, DWORD dwFlags,
234 Context *This = (Context *)iface;
235 DWORD dwLockFlags = 0x0;
237 TRACE("(%p) %i %p %x %p\n",This, tid, pes, dwFlags, phrSession);
239 if (!(dwFlags & TF_ES_READ) && !(dwFlags & TF_ES_READWRITE))
241 *phrSession = E_FAIL;
245 if (!This->pITextStoreACP)
247 FIXME("No ITextStoreACP avaliable\n");
248 *phrSession = E_FAIL;
252 if (!(dwFlags & TF_ES_ASYNC))
253 dwLockFlags |= TS_LF_SYNC;
255 if ((dwFlags & TF_ES_READWRITE) == TF_ES_READWRITE)
256 dwLockFlags |= TS_LF_READWRITE;
257 else if (dwFlags & TF_ES_READ)
258 dwLockFlags |= TS_LF_READ;
260 if (!This->documentStatus.dwDynamicFlags)
261 ITextStoreACP_GetStatus(This->pITextStoreACP, &This->documentStatus);
263 if (((dwFlags & TF_ES_READWRITE) == TF_ES_READWRITE) && (This->documentStatus.dwDynamicFlags & TS_SD_READONLY))
265 *phrSession = TS_E_READONLY;
269 if (FAILED (ITfEditSession_QueryInterface(pes, &IID_ITfEditSession, (LPVOID*)&This->currentEditSession)))
271 *phrSession = E_FAIL;
275 hr = ITextStoreACP_RequestLock(This->pITextStoreACP, dwLockFlags, phrSession);
280 static HRESULT WINAPI Context_InWriteSession (ITfContext *iface,
282 BOOL *pfWriteSession)
284 Context *This = (Context *)iface;
285 FIXME("STUB:(%p)\n",This);
289 static HRESULT WINAPI Context_GetSelection (ITfContext *iface,
290 TfEditCookie ec, ULONG ulIndex, ULONG ulCount,
291 TF_SELECTION *pSelection, ULONG *pcFetched)
293 Context *This = (Context *)iface;
296 ULONG totalFetched = 0;
299 if (!pSelection || !pcFetched)
304 if (!This->connected)
305 return TF_E_DISCONNECTED;
307 if (get_Cookie_magic(ec)!=COOKIE_MAGIC_EDITCOOKIE)
310 if (!This->pITextStoreACP)
312 FIXME("Context does not have a ITextStoreACP\n");
316 cookie = get_Cookie_data(ec);
318 if (ulIndex == TF_DEFAULT_SELECTION)
323 for (i = 0; i < count; i++)
326 TS_SELECTION_ACP acps;
328 hr = ITextStoreACP_GetSelection(This->pITextStoreACP, ulIndex + i,
331 if (hr == TS_E_NOLOCK)
333 else if (SUCCEEDED(hr))
335 pSelection[totalFetched].style.ase = acps.style.ase;
336 pSelection[totalFetched].style.fInterimChar = acps.style.fInterimChar;
337 Range_Constructor(iface, This->pITextStoreACP, cookie->lockType, acps.acpStart, acps.acpEnd, &pSelection[totalFetched].range);
344 *pcFetched = totalFetched;
349 static HRESULT WINAPI Context_SetSelection (ITfContext *iface,
350 TfEditCookie ec, ULONG ulCount, const TF_SELECTION *pSelection)
352 TS_SELECTION_ACP *acp;
353 Context *This = (Context *)iface;
357 TRACE("(%p) %i %i %p\n",This,ec,ulCount,pSelection);
359 if (!This->pITextStoreACP)
361 FIXME("Context does not have a ITextStoreACP\n");
365 if (get_Cookie_magic(ec)!=COOKIE_MAGIC_EDITCOOKIE)
368 acp = HeapAlloc(GetProcessHeap(), 0, sizeof(TS_SELECTION_ACP) * ulCount);
370 return E_OUTOFMEMORY;
372 for (i = 0; i < ulCount; i++)
373 if (FAILED(TF_SELECTION_to_TS_SELECTION_ACP(&pSelection[i], &acp[i])))
375 TRACE("Selection Conversion Failed\n");
376 HeapFree(GetProcessHeap(), 0 , acp);
380 hr = ITextStoreACP_SetSelection(This->pITextStoreACP, ulCount, acp);
382 HeapFree(GetProcessHeap(), 0, acp);
387 static HRESULT WINAPI Context_GetStart (ITfContext *iface,
388 TfEditCookie ec, ITfRange **ppStart)
390 Context *This = (Context *)iface;
392 TRACE("(%p) %i %p\n",This,ec,ppStart);
399 if (!This->connected)
400 return TF_E_DISCONNECTED;
402 if (get_Cookie_magic(ec)!=COOKIE_MAGIC_EDITCOOKIE)
405 cookie = get_Cookie_data(ec);
406 return Range_Constructor(iface, This->pITextStoreACP, cookie->lockType, 0, 0, ppStart);
409 static HRESULT WINAPI Context_GetEnd (ITfContext *iface,
410 TfEditCookie ec, ITfRange **ppEnd)
412 Context *This = (Context *)iface;
415 TRACE("(%p) %i %p\n",This,ec,ppEnd);
422 if (!This->connected)
423 return TF_E_DISCONNECTED;
425 if (get_Cookie_magic(ec)!=COOKIE_MAGIC_EDITCOOKIE)
428 if (!This->pITextStoreACP)
430 FIXME("Context does not have a ITextStoreACP\n");
434 cookie = get_Cookie_data(ec);
435 ITextStoreACP_GetEndACP(This->pITextStoreACP,&end);
437 return Range_Constructor(iface, This->pITextStoreACP, cookie->lockType, end, end, ppEnd);
440 static HRESULT WINAPI Context_GetActiveView (ITfContext *iface,
441 ITfContextView **ppView)
443 Context *This = (Context *)iface;
444 FIXME("STUB:(%p)\n",This);
448 static HRESULT WINAPI Context_EnumViews (ITfContext *iface,
449 IEnumTfContextViews **ppEnum)
451 Context *This = (Context *)iface;
452 FIXME("STUB:(%p)\n",This);
456 static HRESULT WINAPI Context_GetStatus (ITfContext *iface,
459 Context *This = (Context *)iface;
460 FIXME("STUB:(%p)\n",This);
464 static HRESULT WINAPI Context_GetProperty (ITfContext *iface,
465 REFGUID guidProp, ITfProperty **ppProp)
467 Context *This = (Context *)iface;
468 FIXME("STUB:(%p)\n",This);
472 static HRESULT WINAPI Context_GetAppProperty (ITfContext *iface,
473 REFGUID guidProp, ITfReadOnlyProperty **ppProp)
475 Context *This = (Context *)iface;
476 FIXME("STUB:(%p)\n",This);
480 static HRESULT WINAPI Context_TrackProperties (ITfContext *iface,
481 const GUID **prgProp, ULONG cProp, const GUID **prgAppProp,
482 ULONG cAppProp, ITfReadOnlyProperty **ppProperty)
484 Context *This = (Context *)iface;
485 FIXME("STUB:(%p)\n",This);
489 static HRESULT WINAPI Context_EnumProperties (ITfContext *iface,
490 IEnumTfProperties **ppEnum)
492 Context *This = (Context *)iface;
493 FIXME("STUB:(%p)\n",This);
497 static HRESULT WINAPI Context_GetDocumentMgr (ITfContext *iface,
498 ITfDocumentMgr **ppDm)
500 Context *This = (Context *)iface;
501 FIXME("STUB:(%p)\n",This);
505 static HRESULT WINAPI Context_CreateRangeBackup (ITfContext *iface,
506 TfEditCookie ec, ITfRange *pRange, ITfRangeBackup **ppBackup)
508 Context *This = (Context *)iface;
509 FIXME("STUB:(%p)\n",This);
513 static const ITfContextVtbl Context_ContextVtbl =
515 Context_QueryInterface,
519 Context_RequestEditSession,
520 Context_InWriteSession,
521 Context_GetSelection,
522 Context_SetSelection,
525 Context_GetActiveView,
529 Context_GetAppProperty,
530 Context_TrackProperties,
531 Context_EnumProperties,
532 Context_GetDocumentMgr,
533 Context_CreateRangeBackup
536 static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
538 Context *This = impl_from_ITfSourceVtbl(iface);
539 return Context_QueryInterface((ITfContext *)This, iid, *ppvOut);
542 static ULONG WINAPI Source_AddRef(ITfSource *iface)
544 Context *This = impl_from_ITfSourceVtbl(iface);
545 return Context_AddRef((ITfContext *)This);
548 static ULONG WINAPI Source_Release(ITfSource *iface)
550 Context *This = impl_from_ITfSourceVtbl(iface);
551 return Context_Release((ITfContext *)This);
554 /*****************************************************
555 * ITfSource functions
556 *****************************************************/
557 static WINAPI HRESULT ContextSource_AdviseSink(ITfSource *iface,
558 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
561 Context *This = impl_from_ITfSourceVtbl(iface);
562 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
564 if (!riid || !punk || !pdwCookie)
567 if (IsEqualIID(riid, &IID_ITfTextEditSink))
569 es = HeapAlloc(GetProcessHeap(),0,sizeof(ContextSink));
571 return E_OUTOFMEMORY;
572 if (FAILED(IUnknown_QueryInterface(punk, riid, (LPVOID *)&es->interfaces.pITfTextEditSink)))
574 HeapFree(GetProcessHeap(),0,es);
575 return CONNECT_E_CANNOTCONNECT;
577 list_add_head(&This->pTextEditSink ,&es->entry);
578 *pdwCookie = generate_Cookie(COOKIE_MAGIC_CONTEXTSINK, es);
582 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
586 TRACE("cookie %x\n",*pdwCookie);
590 static WINAPI HRESULT ContextSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
593 Context *This = impl_from_ITfSourceVtbl(iface);
595 TRACE("(%p) %x\n",This,pdwCookie);
597 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_CONTEXTSINK)
600 sink = (ContextSink*)remove_Cookie(pdwCookie);
602 return CONNECT_E_NOCONNECTION;
604 list_remove(&sink->entry);
610 static const ITfSourceVtbl Context_SourceVtbl =
612 Source_QueryInterface,
616 ContextSource_AdviseSink,
617 ContextSource_UnadviseSink,
620 /*****************************************************
621 * ITfInsertAtSelection functions
622 *****************************************************/
623 static HRESULT WINAPI InsertAtSelection_QueryInterface(ITfInsertAtSelection *iface, REFIID iid, LPVOID *ppvOut)
625 Context *This = impl_from_ITfInsertAtSelectionVtbl(iface);
626 return Context_QueryInterface((ITfContext *)This, iid, *ppvOut);
629 static ULONG WINAPI InsertAtSelection_AddRef(ITfInsertAtSelection *iface)
631 Context *This = impl_from_ITfInsertAtSelectionVtbl(iface);
632 return Context_AddRef((ITfContext *)This);
635 static ULONG WINAPI InsertAtSelection_Release(ITfInsertAtSelection *iface)
637 Context *This = impl_from_ITfInsertAtSelectionVtbl(iface);
638 return Context_Release((ITfContext *)This);
641 static WINAPI HRESULT InsertAtSelection_InsertTextAtSelection(
642 ITfInsertAtSelection *iface, TfEditCookie ec, DWORD dwFlags,
643 const WCHAR *pchText, LONG cch, ITfRange **ppRange)
645 Context *This = impl_from_ITfInsertAtSelectionVtbl(iface);
647 LONG acpStart, acpEnd;
648 TS_TEXTCHANGE change;
651 TRACE("(%p) %i %x %s %p\n",This, ec, dwFlags, debugstr_wn(pchText,cch), ppRange);
653 if (!This->connected)
654 return TF_E_DISCONNECTED;
656 if (get_Cookie_magic(ec)!=COOKIE_MAGIC_EDITCOOKIE)
659 cookie = get_Cookie_data(ec);
661 if ((cookie->lockType & TS_LF_READWRITE) != TS_LF_READWRITE )
662 return TS_E_READONLY;
664 if (!This->pITextStoreACP)
666 FIXME("Context does not have a ITextStoreACP\n");
670 hr = ITextStoreACP_InsertTextAtSelection(This->pITextStoreACP, dwFlags, pchText, cch, &acpStart, &acpEnd, &change);
672 Range_Constructor((ITfContext*)This, This->pITextStoreACP, cookie->lockType, change.acpStart, change.acpNewEnd, ppRange);
677 static WINAPI HRESULT InsertAtSelection_InsertEmbeddedAtSelection(
678 ITfInsertAtSelection *iface, TfEditCookie ec, DWORD dwFlags,
679 IDataObject *pDataObject, ITfRange **ppRange)
681 Context *This = impl_from_ITfInsertAtSelectionVtbl(iface);
682 FIXME("STUB:(%p)\n",This);
686 static const ITfInsertAtSelectionVtbl Context_InsertAtSelectionVtbl =
688 InsertAtSelection_QueryInterface,
689 InsertAtSelection_AddRef,
690 InsertAtSelection_Release,
692 InsertAtSelection_InsertTextAtSelection,
693 InsertAtSelection_InsertEmbeddedAtSelection,
696 HRESULT Context_Constructor(TfClientId tidOwner, IUnknown *punk, ITfContext **ppOut, TfEditCookie *pecTextStore)
701 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Context));
703 return E_OUTOFMEMORY;
705 cookie = HeapAlloc(GetProcessHeap(),0,sizeof(EditCookie));
708 HeapFree(GetProcessHeap(),0,This);
709 return E_OUTOFMEMORY;
712 TRACE("(%p) %x %p %p %p\n",This, tidOwner, punk, ppOut, pecTextStore);
714 This->ContextVtbl= &Context_ContextVtbl;
715 This->SourceVtbl = &Context_SourceVtbl;
716 This->InsertAtSelectionVtbl = &Context_InsertAtSelectionVtbl;
718 This->tidOwner = tidOwner;
719 This->connected = FALSE;
721 cookie->lockType = TF_ES_READ;
722 cookie->pOwningContext = This;
726 IUnknown_QueryInterface(punk, &IID_ITextStoreACP,
727 (LPVOID*)&This->pITextStoreACP);
729 IUnknown_QueryInterface(punk, &IID_ITfContextOwnerCompositionSink,
730 (LPVOID*)&This->pITfContextOwnerCompositionSink);
732 if (!This->pITextStoreACP && !This->pITfContextOwnerCompositionSink)
733 FIXME("Unhandled pUnk\n");
736 This->defaultCookie = generate_Cookie(COOKIE_MAGIC_EDITCOOKIE,cookie);
737 *pecTextStore = This->defaultCookie;
739 list_init(&This->pContextKeyEventSink);
740 list_init(&This->pEditTransactionSink);
741 list_init(&This->pStatusSink);
742 list_init(&This->pTextEditSink);
743 list_init(&This->pTextLayoutSink);
745 *ppOut = (ITfContext*)This;
746 TRACE("returning %p\n", This);
751 HRESULT Context_Initialize(ITfContext *iface)
753 Context *This = (Context *)iface;
755 if (This->pITextStoreACP)
757 if (SUCCEEDED(TextStoreACPSink_Constructor(&This->pITextStoreACPSink, This)))
758 ITextStoreACP_AdviseSink(This->pITextStoreACP, &IID_ITextStoreACPSink,
759 (IUnknown*)This->pITextStoreACPSink, TS_AS_ALL_SINKS);
761 This->connected = TRUE;
765 HRESULT Context_Uninitialize(ITfContext *iface)
767 Context *This = (Context *)iface;
769 if (This->pITextStoreACPSink)
771 ITextStoreACP_UnadviseSink(This->pITextStoreACP, (IUnknown*)This->pITextStoreACPSink);
772 if (ITextStoreACPSink_Release(This->pITextStoreACPSink) == 0)
773 This->pITextStoreACPSink = NULL;
775 This->connected = FALSE;
779 /**************************************************************************
781 **************************************************************************/
783 static void TextStoreACPSink_Destructor(TextStoreACPSink *This)
785 TRACE("destroying %p\n", This);
786 HeapFree(GetProcessHeap(),0,This);
789 static HRESULT WINAPI TextStoreACPSink_QueryInterface(ITextStoreACPSink *iface, REFIID iid, LPVOID *ppvOut)
791 TextStoreACPSink *This = (TextStoreACPSink *)iface;
794 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACPSink))
801 IUnknown_AddRef(iface);
805 WARN("unsupported interface: %s\n", debugstr_guid(iid));
806 return E_NOINTERFACE;
809 static ULONG WINAPI TextStoreACPSink_AddRef(ITextStoreACPSink *iface)
811 TextStoreACPSink *This = (TextStoreACPSink *)iface;
812 return InterlockedIncrement(&This->refCount);
815 static ULONG WINAPI TextStoreACPSink_Release(ITextStoreACPSink *iface)
817 TextStoreACPSink *This = (TextStoreACPSink *)iface;
820 ret = InterlockedDecrement(&This->refCount);
822 TextStoreACPSink_Destructor(This);
826 /*****************************************************
827 * ITextStoreACPSink functions
828 *****************************************************/
830 static HRESULT WINAPI TextStoreACPSink_OnTextChange(ITextStoreACPSink *iface,
831 DWORD dwFlags, const TS_TEXTCHANGE *pChange)
833 TextStoreACPSink *This = (TextStoreACPSink *)iface;
834 FIXME("STUB:(%p)\n",This);
838 static HRESULT WINAPI TextStoreACPSink_OnSelectionChange(ITextStoreACPSink *iface)
840 TextStoreACPSink *This = (TextStoreACPSink *)iface;
841 FIXME("STUB:(%p)\n",This);
845 static HRESULT WINAPI TextStoreACPSink_OnLayoutChange(ITextStoreACPSink *iface,
846 TsLayoutCode lcode, TsViewCookie vcView)
848 TextStoreACPSink *This = (TextStoreACPSink *)iface;
849 FIXME("STUB:(%p)\n",This);
853 static HRESULT WINAPI TextStoreACPSink_OnStatusChange(ITextStoreACPSink *iface,
856 TextStoreACPSink *This = (TextStoreACPSink *)iface;
857 HRESULT hr, hrSession;
859 TRACE("(%p) %x\n",This, dwFlags);
863 ERR("No context?\n");
867 if (!This->pContext->pITextStoreACP)
869 FIXME("Context does not have a ITextStoreACP\n");
873 hr = ITextStoreACP_RequestLock(This->pContext->pITextStoreACP, TS_LF_READ, &hrSession);
875 if(SUCCEEDED(hr) && SUCCEEDED(hrSession))
876 This->pContext->documentStatus.dwDynamicFlags = dwFlags;
881 static HRESULT WINAPI TextStoreACPSink_OnAttrsChange(ITextStoreACPSink *iface,
882 LONG acpStart, LONG acpEnd, ULONG cAttrs, const TS_ATTRID *paAttrs)
884 TextStoreACPSink *This = (TextStoreACPSink *)iface;
885 FIXME("STUB:(%p)\n",This);
889 static HRESULT WINAPI TextStoreACPSink_OnLockGranted(ITextStoreACPSink *iface,
892 TextStoreACPSink *This = (TextStoreACPSink *)iface;
897 TRACE("(%p) %x\n",This, dwLockFlags);
901 ERR("OnLockGranted called without a context\n");
905 if (!This->pContext->currentEditSession)
907 FIXME("OnLockGranted called for something other than an EditSession\n");
911 cookie = HeapAlloc(GetProcessHeap(),0,sizeof(EditCookie));
913 return E_OUTOFMEMORY;
915 cookie->lockType = dwLockFlags;
916 cookie->pOwningContext = This->pContext;
917 ec = generate_Cookie(COOKIE_MAGIC_EDITCOOKIE, cookie);
919 hr = ITfEditSession_DoEditSession(This->pContext->currentEditSession, ec);
921 ITfEditSession_Release(This->pContext->currentEditSession);
922 This->pContext->currentEditSession = NULL;
924 /* Edit Cookie is only valid during the edit session */
925 cookie = remove_Cookie(ec);
926 HeapFree(GetProcessHeap(),0,cookie);
931 static HRESULT WINAPI TextStoreACPSink_OnStartEditTransaction(ITextStoreACPSink *iface)
933 TextStoreACPSink *This = (TextStoreACPSink *)iface;
934 FIXME("STUB:(%p)\n",This);
938 static HRESULT WINAPI TextStoreACPSink_OnEndEditTransaction(ITextStoreACPSink *iface)
940 TextStoreACPSink *This = (TextStoreACPSink *)iface;
941 FIXME("STUB:(%p)\n",This);
945 static const ITextStoreACPSinkVtbl TextStoreACPSink_TextStoreACPSinkVtbl =
947 TextStoreACPSink_QueryInterface,
948 TextStoreACPSink_AddRef,
949 TextStoreACPSink_Release,
951 TextStoreACPSink_OnTextChange,
952 TextStoreACPSink_OnSelectionChange,
953 TextStoreACPSink_OnLayoutChange,
954 TextStoreACPSink_OnStatusChange,
955 TextStoreACPSink_OnAttrsChange,
956 TextStoreACPSink_OnLockGranted,
957 TextStoreACPSink_OnStartEditTransaction,
958 TextStoreACPSink_OnEndEditTransaction
961 static HRESULT TextStoreACPSink_Constructor(ITextStoreACPSink **ppOut, Context *pContext)
963 TextStoreACPSink *This;
965 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACPSink));
967 return E_OUTOFMEMORY;
969 This->TextStoreACPSinkVtbl= &TextStoreACPSink_TextStoreACPSinkVtbl;
972 This->pContext = pContext;
974 TRACE("returning %p\n", This);
975 *ppOut = (ITextStoreACPSink*)This;