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 FIXME("STUB:(%p)\n",This
);
164 static HRESULT WINAPI
DocumentMgr_GetBase(ITfDocumentMgr
*iface
, ITfContext
**ppic
)
166 DocumentMgr
*This
= (DocumentMgr
*)iface
;
167 FIXME("STUB:(%p)\n",This
);
171 static HRESULT WINAPI
DocumentMgr_EnumContexts(ITfDocumentMgr
*iface
, IEnumTfContexts
**ppEnum
)
173 DocumentMgr
*This
= (DocumentMgr
*)iface
;
174 FIXME("STUB:(%p)\n",This
);
178 static const ITfDocumentMgrVtbl DocumentMgr_DocumentMgrVtbl
=
180 DocumentMgr_QueryInterface
,
184 DocumentMgr_CreateContext
,
189 DocumentMgr_EnumContexts
192 HRESULT
DocumentMgr_Constructor(ITfDocumentMgr
**ppOut
)
196 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DocumentMgr
));
198 return E_OUTOFMEMORY
;
200 This
->DocumentMgrVtbl
= &DocumentMgr_DocumentMgrVtbl
;
203 TRACE("returning %p\n", This
);
204 *ppOut
= (ITfDocumentMgr
*)This
;