user32/tests: Test for failure to change system parameters even if getting them succe...
[wine/multimedia.git] / dlls / msctf / documentmgr.c
blobc87514556adb2f71d5acfc3dccaa299f2d1c0f21
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 const ITfSourceVtbl *SourceVtbl;
46 LONG refCount;
48 ITfContext* contextStack[2]; /* limit of 2 contexts */
49 } DocumentMgr;
51 static inline DocumentMgr *impl_from_ITfSourceVtbl(ITfSource *iface)
53 return (DocumentMgr *)((char *)iface - FIELD_OFFSET(DocumentMgr,SourceVtbl));
56 static void DocumentMgr_Destructor(DocumentMgr *This)
58 TRACE("destroying %p\n", This);
59 if (This->contextStack[0])
60 ITfContext_Release(This->contextStack[0]);
61 if (This->contextStack[1])
62 ITfContext_Release(This->contextStack[1]);
63 HeapFree(GetProcessHeap(),0,This);
66 static HRESULT WINAPI DocumentMgr_QueryInterface(ITfDocumentMgr *iface, REFIID iid, LPVOID *ppvOut)
68 DocumentMgr *This = (DocumentMgr *)iface;
69 *ppvOut = NULL;
71 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfDocumentMgr))
73 *ppvOut = This;
75 else if (IsEqualIID(iid, &IID_ITfSource))
77 *ppvOut = &This->SourceVtbl;
80 if (*ppvOut)
82 IUnknown_AddRef(iface);
83 return S_OK;
86 WARN("unsupported interface: %s\n", debugstr_guid(iid));
87 return E_NOINTERFACE;
90 static ULONG WINAPI DocumentMgr_AddRef(ITfDocumentMgr *iface)
92 DocumentMgr *This = (DocumentMgr *)iface;
93 return InterlockedIncrement(&This->refCount);
96 static ULONG WINAPI DocumentMgr_Release(ITfDocumentMgr *iface)
98 DocumentMgr *This = (DocumentMgr *)iface;
99 ULONG ret;
101 ret = InterlockedDecrement(&This->refCount);
102 if (ret == 0)
103 DocumentMgr_Destructor(This);
104 return ret;
107 /*****************************************************
108 * ITfDocumentMgr functions
109 *****************************************************/
110 static HRESULT WINAPI DocumentMgr_CreateContext(ITfDocumentMgr *iface,
111 TfClientId tidOwner,
112 DWORD dwFlags, IUnknown *punk, ITfContext **ppic,
113 TfEditCookie *pecTextStore)
115 DocumentMgr *This = (DocumentMgr *)iface;
116 TRACE("(%p) 0x%x 0x%x %p %p %p\n",This,tidOwner,dwFlags,punk,ppic,pecTextStore);
117 return Context_Constructor(tidOwner, punk, ppic, pecTextStore);
120 static HRESULT WINAPI DocumentMgr_Push(ITfDocumentMgr *iface, ITfContext *pic)
122 DocumentMgr *This = (DocumentMgr *)iface;
123 ITfContext *check;
125 TRACE("(%p) %p\n",This,pic);
127 if (This->contextStack[1]) /* FUll */
128 return TF_E_STACKFULL;
130 if (!pic || FAILED(IUnknown_QueryInterface(pic,&IID_ITfContext,(LPVOID*) &check)))
131 return E_INVALIDARG;
133 This->contextStack[1] = This->contextStack[0];
134 This->contextStack[0] = check;
136 return S_OK;
139 static HRESULT WINAPI DocumentMgr_Pop(ITfDocumentMgr *iface, DWORD dwFlags)
141 DocumentMgr *This = (DocumentMgr *)iface;
142 TRACE("(%p) 0x%x\n",This,dwFlags);
144 if (dwFlags == TF_POPF_ALL)
146 if (This->contextStack[0])
147 ITfContext_Release(This->contextStack[0]);
148 if (This->contextStack[1])
149 ITfContext_Release(This->contextStack[1]);
150 This->contextStack[0] = This->contextStack[1] = NULL;
151 return S_OK;
154 if (dwFlags)
155 return E_INVALIDARG;
157 if (This->contextStack[0] == NULL) /* Cannot pop last context */
158 return E_FAIL;
160 ITfContext_Release(This->contextStack[0]);
161 This->contextStack[0] = This->contextStack[1];
162 This->contextStack[1] = NULL;
164 return S_OK;
167 static HRESULT WINAPI DocumentMgr_GetTop(ITfDocumentMgr *iface, ITfContext **ppic)
169 DocumentMgr *This = (DocumentMgr *)iface;
170 TRACE("(%p)\n",This);
171 if (!ppic)
172 return E_INVALIDARG;
174 if (This->contextStack[0])
175 ITfContext_AddRef(This->contextStack[0]);
177 *ppic = This->contextStack[0];
179 return S_OK;
182 static HRESULT WINAPI DocumentMgr_GetBase(ITfDocumentMgr *iface, ITfContext **ppic)
184 DocumentMgr *This = (DocumentMgr *)iface;
185 TRACE("(%p)\n",This);
186 if (!ppic)
187 return E_INVALIDARG;
189 if (This->contextStack[1])
190 ITfContext_AddRef(This->contextStack[1]);
192 *ppic = This->contextStack[1];
194 return S_OK;
197 static HRESULT WINAPI DocumentMgr_EnumContexts(ITfDocumentMgr *iface, IEnumTfContexts **ppEnum)
199 DocumentMgr *This = (DocumentMgr *)iface;
200 FIXME("STUB:(%p)\n",This);
201 return E_NOTIMPL;
204 static const ITfDocumentMgrVtbl DocumentMgr_DocumentMgrVtbl =
206 DocumentMgr_QueryInterface,
207 DocumentMgr_AddRef,
208 DocumentMgr_Release,
210 DocumentMgr_CreateContext,
211 DocumentMgr_Push,
212 DocumentMgr_Pop,
213 DocumentMgr_GetTop,
214 DocumentMgr_GetBase,
215 DocumentMgr_EnumContexts
219 static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
221 DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
222 return DocumentMgr_QueryInterface((ITfDocumentMgr*)This, iid, *ppvOut);
225 static ULONG WINAPI Source_AddRef(ITfSource *iface)
227 DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
228 return DocumentMgr_AddRef((ITfDocumentMgr*)This);
231 static ULONG WINAPI Source_Release(ITfSource *iface)
233 DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
234 return DocumentMgr_Release((ITfDocumentMgr*)This);
237 /*****************************************************
238 * ITfSource functions
239 *****************************************************/
240 static WINAPI HRESULT DocumentMgrSource_AdviseSink(ITfSource *iface,
241 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
243 DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
244 FIXME("STUB:(%p)\n",This);
245 return E_NOTIMPL;
248 static WINAPI HRESULT DocumentMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
250 DocumentMgr *This = impl_from_ITfSourceVtbl(iface);
251 FIXME("STUB:(%p)\n",This);
252 return E_NOTIMPL;
255 static const ITfSourceVtbl DocumentMgr_SourceVtbl =
257 Source_QueryInterface,
258 Source_AddRef,
259 Source_Release,
261 DocumentMgrSource_AdviseSink,
262 DocumentMgrSource_UnadviseSink,
265 HRESULT DocumentMgr_Constructor(ITfDocumentMgr **ppOut)
267 DocumentMgr *This;
269 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DocumentMgr));
270 if (This == NULL)
271 return E_OUTOFMEMORY;
273 This->DocumentMgrVtbl= &DocumentMgr_DocumentMgrVtbl;
274 This->SourceVtbl = &DocumentMgr_SourceVtbl;
275 This->refCount = 1;
277 TRACE("returning %p\n", This);
278 *ppOut = (ITfDocumentMgr*)This;
279 return S_OK;