Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 1 | /* |
| 2 | * ITfDocumentMgr implementation |
| 3 | * |
| 4 | * Copyright 2009 Aric Stewart, CodeWeavers |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
| 23 | #include <stdarg.h> |
| 24 | |
| 25 | #define COBJMACROS |
| 26 | |
| 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" |
| 35 | |
| 36 | #include "wine/unicode.h" |
| 37 | |
| 38 | #include "msctf.h" |
| 39 | #include "msctf_internal.h" |
| 40 | |
| 41 | WINE_DEFAULT_DEBUG_CHANNEL(msctf); |
| 42 | |
| 43 | typedef struct tagDocumentMgr { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 44 | ITfDocumentMgr ITfDocumentMgr_iface; |
| 45 | ITfSource ITfSource_iface; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 46 | LONG refCount; |
Aric Stewart | fd8c2a1 | 2009-02-02 10:25:06 -0600 | [diff] [blame] | 47 | |
Aric Stewart | 1ffa351 | 2009-06-11 13:33:23 -0500 | [diff] [blame] | 48 | /* Aggregation */ |
| 49 | ITfCompartmentMgr *CompartmentMgr; |
| 50 | |
Aric Stewart | fd8c2a1 | 2009-02-02 10:25:06 -0600 | [diff] [blame] | 51 | ITfContext* contextStack[2]; /* limit of 2 contexts */ |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 52 | ITfThreadMgrEventSink* ThreadMgrSink; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 53 | } DocumentMgr; |
| 54 | |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 55 | typedef struct tagEnumTfContext { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 56 | IEnumTfContexts IEnumTfContexts_iface; |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 57 | LONG refCount; |
| 58 | |
| 59 | DWORD index; |
| 60 | DocumentMgr *docmgr; |
| 61 | } EnumTfContext; |
| 62 | |
| 63 | static HRESULT EnumTfContext_Constructor(DocumentMgr* mgr, IEnumTfContexts **ppOut); |
| 64 | |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 65 | static inline DocumentMgr *impl_from_ITfDocumentMgr(ITfDocumentMgr *iface) |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 66 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 67 | return CONTAINING_RECORD(iface, DocumentMgr, ITfDocumentMgr_iface); |
| 68 | } |
| 69 | |
| 70 | static inline DocumentMgr *impl_from_ITfSource(ITfSource *iface) |
| 71 | { |
| 72 | return CONTAINING_RECORD(iface, DocumentMgr, ITfSource_iface); |
| 73 | } |
| 74 | |
| 75 | static inline EnumTfContext *impl_from_IEnumTfContexts(IEnumTfContexts *iface)\ |
| 76 | { |
| 77 | return CONTAINING_RECORD(iface, EnumTfContext, IEnumTfContexts_iface); |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 78 | } |
| 79 | |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 80 | static void DocumentMgr_Destructor(DocumentMgr *This) |
| 81 | { |
Aric Stewart | 171a1ad | 2009-07-10 07:36:56 -0500 | [diff] [blame] | 82 | ITfThreadMgr *tm; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 83 | TRACE("destroying %p\n", This); |
Aric Stewart | 171a1ad | 2009-07-10 07:36:56 -0500 | [diff] [blame] | 84 | |
| 85 | TF_GetThreadMgr(&tm); |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 86 | ThreadMgr_OnDocumentMgrDestruction(tm, &This->ITfDocumentMgr_iface); |
Aric Stewart | 171a1ad | 2009-07-10 07:36:56 -0500 | [diff] [blame] | 87 | |
Aric Stewart | fd8c2a1 | 2009-02-02 10:25:06 -0600 | [diff] [blame] | 88 | if (This->contextStack[0]) |
| 89 | ITfContext_Release(This->contextStack[0]); |
| 90 | if (This->contextStack[1]) |
| 91 | ITfContext_Release(This->contextStack[1]); |
Aric Stewart | 1ffa351 | 2009-06-11 13:33:23 -0500 | [diff] [blame] | 92 | CompartmentMgr_Destructor(This->CompartmentMgr); |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 93 | HeapFree(GetProcessHeap(),0,This); |
| 94 | } |
| 95 | |
| 96 | static HRESULT WINAPI DocumentMgr_QueryInterface(ITfDocumentMgr *iface, REFIID iid, LPVOID *ppvOut) |
| 97 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 98 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 99 | *ppvOut = NULL; |
| 100 | |
| 101 | if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfDocumentMgr)) |
| 102 | { |
| 103 | *ppvOut = This; |
| 104 | } |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 105 | else if (IsEqualIID(iid, &IID_ITfSource)) |
| 106 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 107 | *ppvOut = &This->ITfSource_iface; |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 108 | } |
Aric Stewart | 1ffa351 | 2009-06-11 13:33:23 -0500 | [diff] [blame] | 109 | else if (IsEqualIID(iid, &IID_ITfCompartmentMgr)) |
| 110 | { |
| 111 | *ppvOut = This->CompartmentMgr; |
| 112 | } |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 113 | |
| 114 | if (*ppvOut) |
| 115 | { |
| 116 | IUnknown_AddRef(iface); |
| 117 | return S_OK; |
| 118 | } |
| 119 | |
| 120 | WARN("unsupported interface: %s\n", debugstr_guid(iid)); |
| 121 | return E_NOINTERFACE; |
| 122 | } |
| 123 | |
| 124 | static ULONG WINAPI DocumentMgr_AddRef(ITfDocumentMgr *iface) |
| 125 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 126 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 127 | return InterlockedIncrement(&This->refCount); |
| 128 | } |
| 129 | |
| 130 | static ULONG WINAPI DocumentMgr_Release(ITfDocumentMgr *iface) |
| 131 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 132 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 133 | ULONG ret; |
| 134 | |
| 135 | ret = InterlockedDecrement(&This->refCount); |
| 136 | if (ret == 0) |
| 137 | DocumentMgr_Destructor(This); |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | /***************************************************** |
| 142 | * ITfDocumentMgr functions |
| 143 | *****************************************************/ |
| 144 | static HRESULT WINAPI DocumentMgr_CreateContext(ITfDocumentMgr *iface, |
| 145 | TfClientId tidOwner, |
| 146 | DWORD dwFlags, IUnknown *punk, ITfContext **ppic, |
| 147 | TfEditCookie *pecTextStore) |
| 148 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 149 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | b712f39 | 2009-02-02 10:24:59 -0600 | [diff] [blame] | 150 | TRACE("(%p) 0x%x 0x%x %p %p %p\n",This,tidOwner,dwFlags,punk,ppic,pecTextStore); |
Aric Stewart | ca9ca58 | 2009-06-17 17:00:03 +0900 | [diff] [blame] | 151 | return Context_Constructor(tidOwner, punk, iface, ppic, pecTextStore); |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static HRESULT WINAPI DocumentMgr_Push(ITfDocumentMgr *iface, ITfContext *pic) |
| 155 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 156 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | fd8c2a1 | 2009-02-02 10:25:06 -0600 | [diff] [blame] | 157 | ITfContext *check; |
| 158 | |
| 159 | TRACE("(%p) %p\n",This,pic); |
| 160 | |
| 161 | if (This->contextStack[1]) /* FUll */ |
| 162 | return TF_E_STACKFULL; |
| 163 | |
| 164 | if (!pic || FAILED(IUnknown_QueryInterface(pic,&IID_ITfContext,(LPVOID*) &check))) |
| 165 | return E_INVALIDARG; |
| 166 | |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 167 | if (This->contextStack[0] == NULL) |
| 168 | ITfThreadMgrEventSink_OnInitDocumentMgr(This->ThreadMgrSink,iface); |
| 169 | |
Aric Stewart | fd8c2a1 | 2009-02-02 10:25:06 -0600 | [diff] [blame] | 170 | This->contextStack[1] = This->contextStack[0]; |
| 171 | This->contextStack[0] = check; |
| 172 | |
Aric Stewart | dee4e5d | 2009-06-16 18:37:54 +0900 | [diff] [blame] | 173 | Context_Initialize(check, iface); |
Aric Stewart | e73b17d | 2009-06-24 17:29:51 +0900 | [diff] [blame] | 174 | ITfThreadMgrEventSink_OnPushContext(This->ThreadMgrSink,check); |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 175 | |
Aric Stewart | fd8c2a1 | 2009-02-02 10:25:06 -0600 | [diff] [blame] | 176 | return S_OK; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static HRESULT WINAPI DocumentMgr_Pop(ITfDocumentMgr *iface, DWORD dwFlags) |
| 180 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 181 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 182 | TRACE("(%p) 0x%x\n",This,dwFlags); |
| 183 | |
| 184 | if (dwFlags == TF_POPF_ALL) |
| 185 | { |
| 186 | if (This->contextStack[0]) |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 187 | { |
| 188 | ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]); |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 189 | ITfContext_Release(This->contextStack[0]); |
Aric Stewart | 7d4e133 | 2009-05-15 14:09:58 -0500 | [diff] [blame] | 190 | Context_Uninitialize(This->contextStack[0]); |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 191 | } |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 192 | if (This->contextStack[1]) |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 193 | { |
| 194 | ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[1]); |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 195 | ITfContext_Release(This->contextStack[1]); |
Aric Stewart | 7d4e133 | 2009-05-15 14:09:58 -0500 | [diff] [blame] | 196 | Context_Uninitialize(This->contextStack[1]); |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 197 | } |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 198 | This->contextStack[0] = This->contextStack[1] = NULL; |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 199 | ITfThreadMgrEventSink_OnUninitDocumentMgr(This->ThreadMgrSink, iface); |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 200 | return S_OK; |
| 201 | } |
| 202 | |
| 203 | if (dwFlags) |
| 204 | return E_INVALIDARG; |
| 205 | |
Aric Stewart | ed74088 | 2009-04-10 13:16:14 -0500 | [diff] [blame] | 206 | if (This->contextStack[1] == NULL) /* Cannot pop last context */ |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 207 | return E_FAIL; |
| 208 | |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 209 | ITfThreadMgrEventSink_OnPopContext(This->ThreadMgrSink,This->contextStack[0]); |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 210 | ITfContext_Release(This->contextStack[0]); |
Aric Stewart | 7d4e133 | 2009-05-15 14:09:58 -0500 | [diff] [blame] | 211 | Context_Uninitialize(This->contextStack[0]); |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 212 | This->contextStack[0] = This->contextStack[1]; |
| 213 | This->contextStack[1] = NULL; |
| 214 | |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 215 | if (This->contextStack[0] == NULL) |
| 216 | ITfThreadMgrEventSink_OnUninitDocumentMgr(This->ThreadMgrSink, iface); |
| 217 | |
Aric Stewart | f3e2027 | 2009-02-02 10:25:16 -0600 | [diff] [blame] | 218 | return S_OK; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static HRESULT WINAPI DocumentMgr_GetTop(ITfDocumentMgr *iface, ITfContext **ppic) |
| 222 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 223 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | 130303b | 2009-02-02 10:25:22 -0600 | [diff] [blame] | 224 | TRACE("(%p)\n",This); |
| 225 | if (!ppic) |
| 226 | return E_INVALIDARG; |
| 227 | |
| 228 | if (This->contextStack[0]) |
| 229 | ITfContext_AddRef(This->contextStack[0]); |
| 230 | |
| 231 | *ppic = This->contextStack[0]; |
| 232 | |
| 233 | return S_OK; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static HRESULT WINAPI DocumentMgr_GetBase(ITfDocumentMgr *iface, ITfContext **ppic) |
| 237 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 238 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | 846093e | 2009-04-10 13:16:11 -0500 | [diff] [blame] | 239 | ITfContext *tgt; |
| 240 | |
Aric Stewart | e1014b3 | 2009-02-02 10:25:30 -0600 | [diff] [blame] | 241 | TRACE("(%p)\n",This); |
| 242 | if (!ppic) |
| 243 | return E_INVALIDARG; |
| 244 | |
| 245 | if (This->contextStack[1]) |
Aric Stewart | 846093e | 2009-04-10 13:16:11 -0500 | [diff] [blame] | 246 | tgt = This->contextStack[1]; |
| 247 | else |
| 248 | tgt = This->contextStack[0]; |
Aric Stewart | e1014b3 | 2009-02-02 10:25:30 -0600 | [diff] [blame] | 249 | |
Aric Stewart | 846093e | 2009-04-10 13:16:11 -0500 | [diff] [blame] | 250 | if (tgt) |
| 251 | ITfContext_AddRef(tgt); |
| 252 | |
| 253 | *ppic = tgt; |
Aric Stewart | e1014b3 | 2009-02-02 10:25:30 -0600 | [diff] [blame] | 254 | |
| 255 | return S_OK; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static HRESULT WINAPI DocumentMgr_EnumContexts(ITfDocumentMgr *iface, IEnumTfContexts **ppEnum) |
| 259 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 260 | DocumentMgr *This = impl_from_ITfDocumentMgr(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 261 | TRACE("(%p) %p\n",This,ppEnum); |
| 262 | return EnumTfContext_Constructor(This, ppEnum); |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static const ITfDocumentMgrVtbl DocumentMgr_DocumentMgrVtbl = |
| 266 | { |
| 267 | DocumentMgr_QueryInterface, |
| 268 | DocumentMgr_AddRef, |
| 269 | DocumentMgr_Release, |
| 270 | |
| 271 | DocumentMgr_CreateContext, |
| 272 | DocumentMgr_Push, |
| 273 | DocumentMgr_Pop, |
| 274 | DocumentMgr_GetTop, |
| 275 | DocumentMgr_GetBase, |
| 276 | DocumentMgr_EnumContexts |
| 277 | }; |
| 278 | |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 279 | |
| 280 | static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut) |
| 281 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 282 | DocumentMgr *This = impl_from_ITfSource(iface); |
| 283 | return DocumentMgr_QueryInterface(&This->ITfDocumentMgr_iface, iid, *ppvOut); |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static ULONG WINAPI Source_AddRef(ITfSource *iface) |
| 287 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 288 | DocumentMgr *This = impl_from_ITfSource(iface); |
| 289 | return DocumentMgr_AddRef(&This->ITfDocumentMgr_iface); |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static ULONG WINAPI Source_Release(ITfSource *iface) |
| 293 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 294 | DocumentMgr *This = impl_from_ITfSource(iface); |
| 295 | return DocumentMgr_Release(&This->ITfDocumentMgr_iface); |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /***************************************************** |
| 299 | * ITfSource functions |
| 300 | *****************************************************/ |
Stefan Ginsberg | 32648d4 | 2009-09-19 23:33:29 +0200 | [diff] [blame] | 301 | static HRESULT WINAPI DocumentMgrSource_AdviseSink(ITfSource *iface, |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 302 | REFIID riid, IUnknown *punk, DWORD *pdwCookie) |
| 303 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 304 | DocumentMgr *This = impl_from_ITfSource(iface); |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 305 | FIXME("STUB:(%p)\n",This); |
| 306 | return E_NOTIMPL; |
| 307 | } |
| 308 | |
Stefan Ginsberg | 32648d4 | 2009-09-19 23:33:29 +0200 | [diff] [blame] | 309 | static HRESULT WINAPI DocumentMgrSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie) |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 310 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 311 | DocumentMgr *This = impl_from_ITfSource(iface); |
Aric Stewart | aacbe97 | 2009-02-02 10:25:59 -0600 | [diff] [blame] | 312 | FIXME("STUB:(%p)\n",This); |
| 313 | return E_NOTIMPL; |
| 314 | } |
| 315 | |
| 316 | static const ITfSourceVtbl DocumentMgr_SourceVtbl = |
| 317 | { |
| 318 | Source_QueryInterface, |
| 319 | Source_AddRef, |
| 320 | Source_Release, |
| 321 | |
| 322 | DocumentMgrSource_AdviseSink, |
| 323 | DocumentMgrSource_UnadviseSink, |
| 324 | }; |
| 325 | |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 326 | HRESULT DocumentMgr_Constructor(ITfThreadMgrEventSink *ThreadMgrSink, ITfDocumentMgr **ppOut) |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 327 | { |
| 328 | DocumentMgr *This; |
| 329 | |
| 330 | This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DocumentMgr)); |
| 331 | if (This == NULL) |
| 332 | return E_OUTOFMEMORY; |
| 333 | |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 334 | This->ITfDocumentMgr_iface.lpVtbl = &DocumentMgr_DocumentMgrVtbl; |
| 335 | This->ITfSource_iface.lpVtbl = &DocumentMgr_SourceVtbl; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 336 | This->refCount = 1; |
Aric Stewart | db37679 | 2009-03-24 08:21:47 -0500 | [diff] [blame] | 337 | This->ThreadMgrSink = ThreadMgrSink; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 338 | |
Aric Stewart | 1ffa351 | 2009-06-11 13:33:23 -0500 | [diff] [blame] | 339 | CompartmentMgr_Constructor((IUnknown*)This, &IID_IUnknown, (IUnknown**)&This->CompartmentMgr); |
| 340 | |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 341 | TRACE("returning %p\n", This); |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 342 | *ppOut = &This->ITfDocumentMgr_iface; |
Aric Stewart | fdbe3d1 | 2009-01-30 14:27:06 -0600 | [diff] [blame] | 343 | return S_OK; |
| 344 | } |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 345 | |
| 346 | /************************************************** |
| 347 | * IEnumTfContexts implementaion |
| 348 | **************************************************/ |
| 349 | static void EnumTfContext_Destructor(EnumTfContext *This) |
| 350 | { |
| 351 | TRACE("destroying %p\n", This); |
| 352 | HeapFree(GetProcessHeap(),0,This); |
| 353 | } |
| 354 | |
| 355 | static HRESULT WINAPI EnumTfContext_QueryInterface(IEnumTfContexts *iface, REFIID iid, LPVOID *ppvOut) |
| 356 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 357 | EnumTfContext *This = impl_from_IEnumTfContexts(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 358 | *ppvOut = NULL; |
| 359 | |
| 360 | if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfContexts)) |
| 361 | { |
| 362 | *ppvOut = This; |
| 363 | } |
| 364 | |
| 365 | if (*ppvOut) |
| 366 | { |
| 367 | IUnknown_AddRef(iface); |
| 368 | return S_OK; |
| 369 | } |
| 370 | |
| 371 | WARN("unsupported interface: %s\n", debugstr_guid(iid)); |
| 372 | return E_NOINTERFACE; |
| 373 | } |
| 374 | |
| 375 | static ULONG WINAPI EnumTfContext_AddRef(IEnumTfContexts *iface) |
| 376 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 377 | EnumTfContext *This = impl_from_IEnumTfContexts(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 378 | return InterlockedIncrement(&This->refCount); |
| 379 | } |
| 380 | |
| 381 | static ULONG WINAPI EnumTfContext_Release(IEnumTfContexts *iface) |
| 382 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 383 | EnumTfContext *This = impl_from_IEnumTfContexts(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 384 | ULONG ret; |
| 385 | |
| 386 | ret = InterlockedDecrement(&This->refCount); |
| 387 | if (ret == 0) |
| 388 | EnumTfContext_Destructor(This); |
| 389 | return ret; |
| 390 | } |
| 391 | |
| 392 | static HRESULT WINAPI EnumTfContext_Next(IEnumTfContexts *iface, |
| 393 | ULONG ulCount, ITfContext **rgContext, ULONG *pcFetched) |
| 394 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 395 | EnumTfContext *This = impl_from_IEnumTfContexts(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 396 | ULONG fetched = 0; |
| 397 | |
| 398 | TRACE("(%p)\n",This); |
| 399 | |
| 400 | if (rgContext == NULL) return E_POINTER; |
| 401 | |
| 402 | while (fetched < ulCount) |
| 403 | { |
| 404 | if (This->index > 1) |
| 405 | break; |
| 406 | |
| 407 | if (!This->docmgr->contextStack[This->index]) |
| 408 | break; |
| 409 | |
| 410 | *rgContext = This->docmgr->contextStack[This->index]; |
| 411 | ITfContext_AddRef(*rgContext); |
| 412 | |
| 413 | ++This->index; |
| 414 | ++fetched; |
| 415 | ++rgContext; |
| 416 | } |
| 417 | |
| 418 | if (pcFetched) *pcFetched = fetched; |
| 419 | return fetched == ulCount ? S_OK : S_FALSE; |
| 420 | } |
| 421 | |
| 422 | static HRESULT WINAPI EnumTfContext_Skip( IEnumTfContexts* iface, ULONG celt) |
| 423 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 424 | EnumTfContext *This = impl_from_IEnumTfContexts(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 425 | TRACE("(%p)\n",This); |
| 426 | This->index += celt; |
| 427 | return S_OK; |
| 428 | } |
| 429 | |
| 430 | static HRESULT WINAPI EnumTfContext_Reset( IEnumTfContexts* iface) |
| 431 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 432 | EnumTfContext *This = impl_from_IEnumTfContexts(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 433 | TRACE("(%p)\n",This); |
| 434 | This->index = 0; |
| 435 | return S_OK; |
| 436 | } |
| 437 | |
| 438 | static HRESULT WINAPI EnumTfContext_Clone( IEnumTfContexts *iface, |
| 439 | IEnumTfContexts **ppenum) |
| 440 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 441 | EnumTfContext *This = impl_from_IEnumTfContexts(iface); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 442 | HRESULT res; |
| 443 | |
| 444 | TRACE("(%p)\n",This); |
| 445 | |
| 446 | if (ppenum == NULL) return E_POINTER; |
| 447 | |
| 448 | res = EnumTfContext_Constructor(This->docmgr, ppenum); |
| 449 | if (SUCCEEDED(res)) |
| 450 | { |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 451 | EnumTfContext *new_This = impl_from_IEnumTfContexts(*ppenum); |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 452 | new_This->index = This->index; |
| 453 | } |
| 454 | return res; |
| 455 | } |
| 456 | |
| 457 | static const IEnumTfContextsVtbl IEnumTfContexts_Vtbl ={ |
| 458 | EnumTfContext_QueryInterface, |
| 459 | EnumTfContext_AddRef, |
| 460 | EnumTfContext_Release, |
| 461 | |
| 462 | EnumTfContext_Clone, |
| 463 | EnumTfContext_Next, |
| 464 | EnumTfContext_Reset, |
| 465 | EnumTfContext_Skip |
| 466 | }; |
| 467 | |
| 468 | static HRESULT EnumTfContext_Constructor(DocumentMgr *mgr, IEnumTfContexts **ppOut) |
| 469 | { |
| 470 | EnumTfContext *This; |
| 471 | |
| 472 | This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfContext)); |
| 473 | if (This == NULL) |
| 474 | return E_OUTOFMEMORY; |
| 475 | |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 476 | This->IEnumTfContexts_iface.lpVtbl = &IEnumTfContexts_Vtbl; |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 477 | This->refCount = 1; |
| 478 | This->docmgr = mgr; |
| 479 | |
| 480 | TRACE("returning %p\n", This); |
Michael Stefaniuc | 6aaf2aa | 2010-12-23 02:04:10 +0100 | [diff] [blame] | 481 | *ppOut = &This->IEnumTfContexts_iface; |
Aric Stewart | 7de0b82 | 2009-06-30 14:47:12 -0500 | [diff] [blame] | 482 | return S_OK; |
| 483 | } |