2 * ITfDocumentMgr 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"
36 #include "wine/unicode.h"
39 #include "msctf_internal.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
43 typedef struct tagDocumentMgr {
44 const ITfDocumentMgrVtbl *DocumentMgrVtbl;
47 ITfContext* contextStack[2]; /* limit of 2 contexts */
50 static void DocumentMgr_Destructor(DocumentMgr *This)
52 TRACE("destroying %p\n", This);
53 if (This->contextStack[0])
54 ITfContext_Release(This->contextStack[0]);
55 if (This->contextStack[1])
56 ITfContext_Release(This->contextStack[1]);
57 HeapFree(GetProcessHeap(),0,This);
60 static HRESULT WINAPI DocumentMgr_QueryInterface(ITfDocumentMgr *iface, REFIID iid, LPVOID *ppvOut)
62 DocumentMgr *This = (DocumentMgr *)iface;
65 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfDocumentMgr))
72 IUnknown_AddRef(iface);
76 WARN("unsupported interface: %s\n", debugstr_guid(iid));
80 static ULONG WINAPI DocumentMgr_AddRef(ITfDocumentMgr *iface)
82 DocumentMgr *This = (DocumentMgr *)iface;
83 return InterlockedIncrement(&This->refCount);
86 static ULONG WINAPI DocumentMgr_Release(ITfDocumentMgr *iface)
88 DocumentMgr *This = (DocumentMgr *)iface;
91 ret = InterlockedDecrement(&This->refCount);
93 DocumentMgr_Destructor(This);
97 /*****************************************************
98 * ITfDocumentMgr functions
99 *****************************************************/
100 static HRESULT WINAPI DocumentMgr_CreateContext(ITfDocumentMgr *iface,
102 DWORD dwFlags, IUnknown *punk, ITfContext **ppic,
103 TfEditCookie *pecTextStore)
105 DocumentMgr *This = (DocumentMgr *)iface;
106 TRACE("(%p) 0x%x 0x%x %p %p %p\n",This,tidOwner,dwFlags,punk,ppic,pecTextStore);
107 return Context_Constructor(tidOwner, punk, ppic, pecTextStore);
110 static HRESULT WINAPI DocumentMgr_Push(ITfDocumentMgr *iface, ITfContext *pic)
112 DocumentMgr *This = (DocumentMgr *)iface;
115 TRACE("(%p) %p\n",This,pic);
117 if (This->contextStack[1]) /* FUll */
118 return TF_E_STACKFULL;
120 if (!pic || FAILED(IUnknown_QueryInterface(pic,&IID_ITfContext,(LPVOID*) &check)))
123 This->contextStack[1] = This->contextStack[0];
124 This->contextStack[0] = check;
129 static HRESULT WINAPI DocumentMgr_Pop(ITfDocumentMgr *iface, DWORD dwFlags)
131 DocumentMgr *This = (DocumentMgr *)iface;
132 TRACE("(%p) 0x%x\n",This,dwFlags);
134 if (dwFlags == TF_POPF_ALL)
136 if (This->contextStack[0])
137 ITfContext_Release(This->contextStack[0]);
138 if (This->contextStack[1])
139 ITfContext_Release(This->contextStack[1]);
140 This->contextStack[0] = This->contextStack[1] = NULL;
147 if (This->contextStack[0] == NULL) /* Cannot pop last context */
150 ITfContext_Release(This->contextStack[0]);
151 This->contextStack[0] = This->contextStack[1];
152 This->contextStack[1] = NULL;
157 static HRESULT WINAPI DocumentMgr_GetTop(ITfDocumentMgr *iface, ITfContext **ppic)
159 DocumentMgr *This = (DocumentMgr *)iface;
160 TRACE("(%p)\n",This);
164 if (This->contextStack[0])
165 ITfContext_AddRef(This->contextStack[0]);
167 *ppic = This->contextStack[0];
172 static HRESULT WINAPI DocumentMgr_GetBase(ITfDocumentMgr *iface, ITfContext **ppic)
174 DocumentMgr *This = (DocumentMgr *)iface;
175 TRACE("(%p)\n",This);
179 if (This->contextStack[1])
180 ITfContext_AddRef(This->contextStack[1]);
182 *ppic = This->contextStack[1];
187 static HRESULT WINAPI DocumentMgr_EnumContexts(ITfDocumentMgr *iface, IEnumTfContexts **ppEnum)
189 DocumentMgr *This = (DocumentMgr *)iface;
190 FIXME("STUB:(%p)\n",This);
194 static const ITfDocumentMgrVtbl DocumentMgr_DocumentMgrVtbl =
196 DocumentMgr_QueryInterface,
200 DocumentMgr_CreateContext,
205 DocumentMgr_EnumContexts
208 HRESULT DocumentMgr_Constructor(ITfDocumentMgr **ppOut)
212 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DocumentMgr));
214 return E_OUTOFMEMORY;
216 This->DocumentMgrVtbl= &DocumentMgr_DocumentMgrVtbl;
219 TRACE("returning %p\n", This);
220 *ppOut = (ITfDocumentMgr*)This;