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