msctf: Implement TF_GetThreadMgr.
[wine] / dlls / msctf / context.c
1 /*
2  *  ITfContext 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 tagContext {
44     const ITfContextVtbl *ContextVtbl;
45     const ITfSourceVtbl *SourceVtbl;
46     LONG refCount;
47
48     TfClientId tidOwner;
49     IUnknown *punk;  /* possible ITextStoreACP or ITfContextOwnerCompositionSink */
50 } Context;
51
52 static inline Context *impl_from_ITfSourceVtbl(ITfSource *iface)
53 {
54     return (Context *)((char *)iface - FIELD_OFFSET(Context,SourceVtbl));
55 }
56
57 static void Context_Destructor(Context *This)
58 {
59     TRACE("destroying %p\n", This);
60     HeapFree(GetProcessHeap(),0,This);
61 }
62
63 static HRESULT WINAPI Context_QueryInterface(ITfContext *iface, REFIID iid, LPVOID *ppvOut)
64 {
65     Context *This = (Context *)iface;
66     *ppvOut = NULL;
67
68     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfContext))
69     {
70         *ppvOut = This;
71     }
72     else if (IsEqualIID(iid, &IID_ITfSource))
73     {
74         *ppvOut = &This->SourceVtbl;
75     }
76
77     if (*ppvOut)
78     {
79         IUnknown_AddRef(iface);
80         return S_OK;
81     }
82
83     WARN("unsupported interface: %s\n", debugstr_guid(iid));
84     return E_NOINTERFACE;
85 }
86
87 static ULONG WINAPI Context_AddRef(ITfContext *iface)
88 {
89     Context *This = (Context *)iface;
90     return InterlockedIncrement(&This->refCount);
91 }
92
93 static ULONG WINAPI Context_Release(ITfContext *iface)
94 {
95     Context *This = (Context *)iface;
96     ULONG ret;
97
98     ret = InterlockedDecrement(&This->refCount);
99     if (ret == 0)
100         Context_Destructor(This);
101     return ret;
102 }
103
104 /*****************************************************
105  * ITfContext functions
106  *****************************************************/
107 static HRESULT WINAPI Context_RequestEditSession (ITfContext *iface,
108         TfClientId tid, ITfEditSession *pes, DWORD dwFlags,
109         HRESULT *phrSession)
110 {
111     Context *This = (Context *)iface;
112     FIXME("STUB:(%p)\n",This);
113     return E_NOTIMPL;
114 }
115
116 static HRESULT WINAPI Context_InWriteSession (ITfContext *iface,
117          TfClientId tid,
118          BOOL *pfWriteSession)
119 {
120     Context *This = (Context *)iface;
121     FIXME("STUB:(%p)\n",This);
122     return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI Context_GetSelection (ITfContext *iface,
126         TfEditCookie ec, ULONG ulIndex, ULONG ulCount,
127         TF_SELECTION *pSelection, ULONG *pcFetched)
128 {
129     Context *This = (Context *)iface;
130     FIXME("STUB:(%p)\n",This);
131     return E_NOTIMPL;
132 }
133
134 static HRESULT WINAPI Context_SetSelection (ITfContext *iface,
135         TfEditCookie ec, ULONG ulCount, const TF_SELECTION *pSelection)
136 {
137     Context *This = (Context *)iface;
138     FIXME("STUB:(%p)\n",This);
139     return E_NOTIMPL;
140 }
141
142 static HRESULT WINAPI Context_GetStart (ITfContext *iface,
143         TfEditCookie ec, ITfRange **ppStart)
144 {
145     Context *This = (Context *)iface;
146     FIXME("STUB:(%p)\n",This);
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI Context_GetEnd (ITfContext *iface,
151         TfEditCookie ec, ITfRange **ppEnd)
152 {
153     Context *This = (Context *)iface;
154     FIXME("STUB:(%p)\n",This);
155     return E_NOTIMPL;
156 }
157
158 static HRESULT WINAPI Context_GetActiveView (ITfContext *iface,
159   ITfContextView **ppView)
160 {
161     Context *This = (Context *)iface;
162     FIXME("STUB:(%p)\n",This);
163     return E_NOTIMPL;
164 }
165
166 static HRESULT WINAPI Context_EnumViews (ITfContext *iface,
167         IEnumTfContextViews **ppEnum)
168 {
169     Context *This = (Context *)iface;
170     FIXME("STUB:(%p)\n",This);
171     return E_NOTIMPL;
172 }
173
174 static HRESULT WINAPI Context_GetStatus (ITfContext *iface,
175         TF_STATUS *pdcs)
176 {
177     Context *This = (Context *)iface;
178     FIXME("STUB:(%p)\n",This);
179     return E_NOTIMPL;
180 }
181
182 static HRESULT WINAPI Context_GetProperty (ITfContext *iface,
183         REFGUID guidProp, ITfProperty **ppProp)
184 {
185     Context *This = (Context *)iface;
186     FIXME("STUB:(%p)\n",This);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI Context_GetAppProperty (ITfContext *iface,
191         REFGUID guidProp, ITfReadOnlyProperty **ppProp)
192 {
193     Context *This = (Context *)iface;
194     FIXME("STUB:(%p)\n",This);
195     return E_NOTIMPL;
196 }
197
198 static HRESULT WINAPI Context_TrackProperties (ITfContext *iface,
199         const GUID **prgProp, ULONG cProp, const GUID **prgAppProp,
200         ULONG cAppProp, ITfReadOnlyProperty **ppProperty)
201 {
202     Context *This = (Context *)iface;
203     FIXME("STUB:(%p)\n",This);
204     return E_NOTIMPL;
205 }
206
207 static HRESULT WINAPI Context_EnumProperties (ITfContext *iface,
208         IEnumTfProperties **ppEnum)
209 {
210     Context *This = (Context *)iface;
211     FIXME("STUB:(%p)\n",This);
212     return E_NOTIMPL;
213 }
214
215 static HRESULT WINAPI Context_GetDocumentMgr (ITfContext *iface,
216         ITfDocumentMgr **ppDm)
217 {
218     Context *This = (Context *)iface;
219     FIXME("STUB:(%p)\n",This);
220     return E_NOTIMPL;
221 }
222
223 static HRESULT WINAPI Context_CreateRangeBackup (ITfContext *iface,
224         TfEditCookie ec, ITfRange *pRange, ITfRangeBackup **ppBackup)
225 {
226     Context *This = (Context *)iface;
227     FIXME("STUB:(%p)\n",This);
228     return E_NOTIMPL;
229 }
230
231 static const ITfContextVtbl Context_ContextVtbl =
232 {
233     Context_QueryInterface,
234     Context_AddRef,
235     Context_Release,
236
237     Context_RequestEditSession,
238     Context_InWriteSession,
239     Context_GetSelection,
240     Context_SetSelection,
241     Context_GetStart,
242     Context_GetEnd,
243     Context_GetActiveView,
244     Context_EnumViews,
245     Context_GetStatus,
246     Context_GetProperty,
247     Context_GetAppProperty,
248     Context_TrackProperties,
249     Context_EnumProperties,
250     Context_GetDocumentMgr,
251     Context_CreateRangeBackup
252 };
253
254 static HRESULT WINAPI Source_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
255 {
256     Context *This = impl_from_ITfSourceVtbl(iface);
257     return Context_QueryInterface((ITfContext *)This, iid, *ppvOut);
258 }
259
260 static ULONG WINAPI Source_AddRef(ITfSource *iface)
261 {
262     Context *This = impl_from_ITfSourceVtbl(iface);
263     return Context_AddRef((ITfContext *)This);
264 }
265
266 static ULONG WINAPI Source_Release(ITfSource *iface)
267 {
268     Context *This = impl_from_ITfSourceVtbl(iface);
269     return Context_Release((ITfContext *)This);
270 }
271
272 /*****************************************************
273  * ITfSource functions
274  *****************************************************/
275 static WINAPI HRESULT ContextSource_AdviseSink(ITfSource *iface,
276         REFIID riid, IUnknown *punk, DWORD *pdwCookie)
277 {
278     Context *This = impl_from_ITfSourceVtbl(iface);
279     FIXME("STUB:(%p)\n",This);
280     return E_NOTIMPL;
281 }
282
283 static WINAPI HRESULT ContextSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
284 {
285     Context *This = impl_from_ITfSourceVtbl(iface);
286     FIXME("STUB:(%p)\n",This);
287     return E_NOTIMPL;
288 }
289
290 static const ITfSourceVtbl Context_SourceVtbl =
291 {
292     Source_QueryInterface,
293     Source_AddRef,
294     Source_Release,
295
296     ContextSource_AdviseSink,
297     ContextSource_UnadviseSink,
298 };
299
300 HRESULT Context_Constructor(TfClientId tidOwner, IUnknown *punk, ITfContext **ppOut, TfEditCookie *pecTextStore)
301 {
302     Context *This;
303
304     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Context));
305     if (This == NULL)
306         return E_OUTOFMEMORY;
307
308     This->ContextVtbl= &Context_ContextVtbl;
309     This->SourceVtbl = &Context_SourceVtbl;
310     This->refCount = 1;
311     This->tidOwner = tidOwner;
312     This->punk = punk;
313
314     TRACE("returning %p\n", This);
315     *ppOut = (ITfContext*)This;
316     /* FIXME */
317     *pecTextStore = 0xdeaddead;
318     return S_OK;
319 }