msctf: Implement ITfDocumentMgr::Pop.
[wine/multimedia.git] / dlls / msctf / documentmgr.c
blob040db7bae0d84aa10aa9b31104c27a6efc4a79c1
1 /*
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
21 #include "config.h"
23 #include <stdarg.h>
25 #define COBJMACROS
27 #include "wine/debug.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winuser.h"
32 #include "shlwapi.h"
33 #include "winerror.h"
34 #include "objbase.h"
36 #include "wine/unicode.h"
38 #include "msctf.h"
39 #include "msctf_internal.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
43 typedef struct tagDocumentMgr {
44 const ITfDocumentMgrVtbl *DocumentMgrVtbl;
45 LONG refCount;
47 ITfContext* contextStack[2]; /* limit of 2 contexts */
48 } DocumentMgr;
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;
63 *ppvOut = NULL;
65 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfDocumentMgr))
67 *ppvOut = This;
70 if (*ppvOut)
72 IUnknown_AddRef(iface);
73 return S_OK;
76 WARN("unsupported interface: %s\n", debugstr_guid(iid));
77 return E_NOINTERFACE;
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;
89 ULONG ret;
91 ret = InterlockedDecrement(&This->refCount);
92 if (ret == 0)
93 DocumentMgr_Destructor(This);
94 return ret;
97 /*****************************************************
98 * ITfDocumentMgr functions
99 *****************************************************/
100 static HRESULT WINAPI DocumentMgr_CreateContext(ITfDocumentMgr *iface,
101 TfClientId tidOwner,
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;
113 ITfContext *check;
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)))
121 return E_INVALIDARG;
123 This->contextStack[1] = This->contextStack[0];
124 This->contextStack[0] = check;
126 return S_OK;
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;
141 return S_OK;
144 if (dwFlags)
145 return E_INVALIDARG;
147 if (This->contextStack[0] == NULL) /* Cannot pop last context */
148 return E_FAIL;
150 ITfContext_Release(This->contextStack[0]);
151 This->contextStack[0] = This->contextStack[1];
152 This->contextStack[1] = NULL;
154 return S_OK;
157 static HRESULT WINAPI DocumentMgr_GetTop(ITfDocumentMgr *iface, ITfContext **ppic)
159 DocumentMgr *This = (DocumentMgr *)iface;
160 FIXME("STUB:(%p)\n",This);
161 return E_NOTIMPL;
164 static HRESULT WINAPI DocumentMgr_GetBase(ITfDocumentMgr *iface, ITfContext **ppic)
166 DocumentMgr *This = (DocumentMgr *)iface;
167 FIXME("STUB:(%p)\n",This);
168 return E_NOTIMPL;
171 static HRESULT WINAPI DocumentMgr_EnumContexts(ITfDocumentMgr *iface, IEnumTfContexts **ppEnum)
173 DocumentMgr *This = (DocumentMgr *)iface;
174 FIXME("STUB:(%p)\n",This);
175 return E_NOTIMPL;
178 static const ITfDocumentMgrVtbl DocumentMgr_DocumentMgrVtbl =
180 DocumentMgr_QueryInterface,
181 DocumentMgr_AddRef,
182 DocumentMgr_Release,
184 DocumentMgr_CreateContext,
185 DocumentMgr_Push,
186 DocumentMgr_Pop,
187 DocumentMgr_GetTop,
188 DocumentMgr_GetBase,
189 DocumentMgr_EnumContexts
192 HRESULT DocumentMgr_Constructor(ITfDocumentMgr **ppOut)
194 DocumentMgr *This;
196 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DocumentMgr));
197 if (This == NULL)
198 return E_OUTOFMEMORY;
200 This->DocumentMgrVtbl= &DocumentMgr_DocumentMgrVtbl;
201 This->refCount = 1;
203 TRACE("returning %p\n", This);
204 *ppOut = (ITfDocumentMgr*)This;
205 return S_OK;