Merge r55012 adding Wine3D control panel as per Amine's request.
[reactos.git] / dll / win32 / msctf / range.c
1 /*
2 * ITfRange 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 tagRange {
44 const ITfRangeVtbl *RangeVtbl;
45 /* const ITfRangeACPVtb *RangeACPVtbl; */
46 LONG refCount;
47
48 ITextStoreACP *pITextStoreACP;
49 ITfContext *pITfContext;
50
51 DWORD lockType;
52 TfGravity gravityStart, gravityEnd;
53 DWORD anchorStart, anchorEnd;
54
55 } Range;
56
57 static void Range_Destructor(Range *This)
58 {
59 TRACE("destroying %p\n", This);
60 HeapFree(GetProcessHeap(),0,This);
61 }
62
63 static HRESULT WINAPI Range_QueryInterface(ITfRange *iface, REFIID iid, LPVOID *ppvOut)
64 {
65 Range *This = (Range*)iface;
66 *ppvOut = NULL;
67
68 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfRange))
69 {
70 *ppvOut = This;
71 }
72
73 if (*ppvOut)
74 {
75 IUnknown_AddRef(iface);
76 return S_OK;
77 }
78
79 WARN("unsupported interface: %s\n", debugstr_guid(iid));
80 return E_NOINTERFACE;
81 }
82
83 static ULONG WINAPI Range_AddRef(ITfRange *iface)
84 {
85 Range *This = (Range *)iface;
86 return InterlockedIncrement(&This->refCount);
87 }
88
89 static ULONG WINAPI Range_Release(ITfRange *iface)
90 {
91 Range *This = (Range *)iface;
92 ULONG ret;
93
94 ret = InterlockedDecrement(&This->refCount);
95 if (ret == 0)
96 Range_Destructor(This);
97 return ret;
98 }
99
100 /*****************************************************
101 * ITfRange functions
102 *****************************************************/
103
104 static HRESULT WINAPI Range_GetText(ITfRange *iface, TfEditCookie ec,
105 DWORD dwFlags, WCHAR *pchText, ULONG cchMax, ULONG *pcch)
106 {
107 Range *This = (Range *)iface;
108 FIXME("STUB:(%p)\n",This);
109 return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI Range_SetText(ITfRange *iface, TfEditCookie ec,
113 DWORD dwFlags, const WCHAR *pchText, LONG cch)
114 {
115 Range *This = (Range *)iface;
116 FIXME("STUB:(%p)\n",This);
117 return E_NOTIMPL;
118 }
119
120 static HRESULT WINAPI Range_GetFormattedText(ITfRange *iface, TfEditCookie ec,
121 IDataObject **ppDataObject)
122 {
123 Range *This = (Range *)iface;
124 FIXME("STUB:(%p)\n",This);
125 return E_NOTIMPL;
126 }
127
128 static HRESULT WINAPI Range_GetEmbedded(ITfRange *iface, TfEditCookie ec,
129 REFGUID rguidService, REFIID riid, IUnknown **ppunk)
130 {
131 Range *This = (Range *)iface;
132 FIXME("STUB:(%p)\n",This);
133 return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI Range_InsertEmbedded(ITfRange *iface, TfEditCookie ec,
137 DWORD dwFlags, IDataObject *pDataObject)
138 {
139 Range *This = (Range *)iface;
140 FIXME("STUB:(%p)\n",This);
141 return E_NOTIMPL;
142 }
143
144 static HRESULT WINAPI Range_ShiftStart(ITfRange *iface, TfEditCookie ec,
145 LONG cchReq, LONG *pcch, const TF_HALTCOND *pHalt)
146 {
147 Range *This = (Range *)iface;
148 FIXME("STUB:(%p)\n",This);
149 return E_NOTIMPL;
150 }
151
152 static HRESULT WINAPI Range_ShiftEnd(ITfRange *iface, TfEditCookie ec,
153 LONG cchReq, LONG *pcch, const TF_HALTCOND *pHalt)
154 {
155 Range *This = (Range *)iface;
156 FIXME("STUB:(%p)\n",This);
157 return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI Range_ShiftStartToRange(ITfRange *iface, TfEditCookie ec,
161 ITfRange *pRange, TfAnchor aPos)
162 {
163 Range *This = (Range *)iface;
164 FIXME("STUB:(%p)\n",This);
165 return E_NOTIMPL;
166 }
167
168 static HRESULT WINAPI Range_ShiftEndToRange(ITfRange *iface, TfEditCookie ec,
169 ITfRange *pRange, TfAnchor aPos)
170 {
171 Range *This = (Range *)iface;
172 FIXME("STUB:(%p)\n",This);
173 return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI Range_ShiftStartRegion(ITfRange *iface, TfEditCookie ec,
177 TfShiftDir dir, BOOL *pfNoRegion)
178 {
179 Range *This = (Range *)iface;
180 FIXME("STUB:(%p)\n",This);
181 return E_NOTIMPL;
182 }
183
184 static HRESULT WINAPI Range_ShiftEndRegion(ITfRange *iface, TfEditCookie ec,
185 TfShiftDir dir, BOOL *pfNoRegion)
186 {
187 Range *This = (Range *)iface;
188 FIXME("STUB:(%p)\n",This);
189 return E_NOTIMPL;
190 }
191
192 static HRESULT WINAPI Range_IsEmpty(ITfRange *iface, TfEditCookie ec,
193 BOOL *pfEmpty)
194 {
195 Range *This = (Range *)iface;
196 FIXME("STUB:(%p)\n",This);
197 return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI Range_Collapse(ITfRange *iface, TfEditCookie ec,
201 TfAnchor aPos)
202 {
203 Range *This = (Range *)iface;
204 TRACE("(%p) %i %i\n",This,ec,aPos);
205
206 switch (aPos)
207 {
208 case TF_ANCHOR_START:
209 This->anchorEnd = This->anchorStart;
210 break;
211 case TF_ANCHOR_END:
212 This->anchorStart = This->anchorEnd;
213 break;
214 default:
215 return E_INVALIDARG;
216 }
217
218 return S_OK;
219 }
220
221 static HRESULT WINAPI Range_IsEqualStart(ITfRange *iface, TfEditCookie ec,
222 ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual)
223 {
224 Range *This = (Range *)iface;
225 FIXME("STUB:(%p)\n",This);
226 return E_NOTIMPL;
227 }
228
229 static HRESULT WINAPI Range_IsEqualEnd(ITfRange *iface, TfEditCookie ec,
230 ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual)
231 {
232 Range *This = (Range *)iface;
233 FIXME("STUB:(%p)\n",This);
234 return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI Range_CompareStart(ITfRange *iface, TfEditCookie ec,
238 ITfRange *pWith, TfAnchor aPos, LONG *plResult)
239 {
240 Range *This = (Range *)iface;
241 FIXME("STUB:(%p)\n",This);
242 return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI Range_CompareEnd(ITfRange *iface, TfEditCookie ec,
246 ITfRange *pWith, TfAnchor aPos, LONG *plResult)
247 {
248 Range *This = (Range *)iface;
249 FIXME("STUB:(%p)\n",This);
250 return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI Range_AdjustForInsert(ITfRange *iface, TfEditCookie ec,
254 ULONG cchInsert, BOOL *pfInsertOk)
255 {
256 Range *This = (Range *)iface;
257 FIXME("STUB:(%p)\n",This);
258 return E_NOTIMPL;
259 }
260
261 static HRESULT WINAPI Range_GetGravity(ITfRange *iface,
262 TfGravity *pgStart, TfGravity *pgEnd)
263 {
264 Range *This = (Range *)iface;
265 FIXME("STUB:(%p)\n",This);
266 return E_NOTIMPL;
267 }
268
269 static HRESULT WINAPI Range_SetGravity(ITfRange *iface, TfEditCookie ec,
270 TfGravity gStart, TfGravity gEnd)
271 {
272 Range *This = (Range *)iface;
273 FIXME("STUB:(%p)\n",This);
274 return E_NOTIMPL;
275 }
276
277 static HRESULT WINAPI Range_Clone(ITfRange *iface, ITfRange **ppClone)
278 {
279 Range *This = (Range *)iface;
280 FIXME("STUB:(%p)\n",This);
281 return E_NOTIMPL;
282 }
283
284 static HRESULT WINAPI Range_GetContext(ITfRange *iface, ITfContext **ppContext)
285 {
286 Range *This = (Range *)iface;
287 TRACE("(%p)\n",This);
288 if (!ppContext)
289 return E_INVALIDARG;
290 *ppContext = This->pITfContext;
291 return S_OK;
292 }
293
294 static const ITfRangeVtbl Range_RangeVtbl =
295 {
296 Range_QueryInterface,
297 Range_AddRef,
298 Range_Release,
299
300 Range_GetText,
301 Range_SetText,
302 Range_GetFormattedText,
303 Range_GetEmbedded,
304 Range_InsertEmbedded,
305 Range_ShiftStart,
306 Range_ShiftEnd,
307 Range_ShiftStartToRange,
308 Range_ShiftEndToRange,
309 Range_ShiftStartRegion,
310 Range_ShiftEndRegion,
311 Range_IsEmpty,
312 Range_Collapse,
313 Range_IsEqualStart,
314 Range_IsEqualEnd,
315 Range_CompareStart,
316 Range_CompareEnd,
317 Range_AdjustForInsert,
318 Range_GetGravity,
319 Range_SetGravity,
320 Range_Clone,
321 Range_GetContext
322 };
323
324 HRESULT Range_Constructor(ITfContext *context, ITextStoreACP *textstore, DWORD lockType, DWORD anchorStart, DWORD anchorEnd, ITfRange **ppOut)
325 {
326 Range *This;
327
328 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Range));
329 if (This == NULL)
330 return E_OUTOFMEMORY;
331
332 TRACE("(%p) %p %p\n",This, context, textstore);
333
334 This->RangeVtbl= &Range_RangeVtbl;
335 This->refCount = 1;
336 This->pITfContext = context;
337 This->pITextStoreACP = textstore;
338 This->lockType = lockType;
339 This->anchorStart = anchorStart;
340 This->anchorEnd = anchorEnd;
341
342 *ppOut = (ITfRange*)This;
343 TRACE("returning %p\n", This);
344
345 return S_OK;
346 }
347
348 /* Internal conversion functions */
349
350 HRESULT TF_SELECTION_to_TS_SELECTION_ACP(const TF_SELECTION *tf, TS_SELECTION_ACP *tsAcp)
351 {
352 Range *This;
353
354 if (!tf || !tsAcp || !tf->range)
355 return E_INVALIDARG;
356
357 This = (Range *)tf->range;
358
359 tsAcp->acpStart = This->anchorStart;
360 tsAcp->acpEnd = This->anchorEnd;
361 tsAcp->style.ase = tf->style.ase;
362 tsAcp->style.fInterimChar = tf->style.fInterimChar;
363 return S_OK;
364 }