mshtml: Added IHTMLDocument7::getElementsByClassName implementation.
[wine.git] / dlls / msctf / range.c
blobdca8983efdb85bfefb72d38f97bc3f4bb58c264d
1 /*
2 * ITfRange 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
21 #include "config.h"
23 #include <stdarg.h>
25 #define COBJMACROS
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"
36 #include "wine/unicode.h"
38 #include "msctf.h"
39 #include "msctf_internal.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
43 typedef struct tagRange {
44 ITfRange ITfRange_iface;
45 /* const ITfRangeACPVtb *RangeACPVtbl; */
46 LONG refCount;
48 ITextStoreACP *pITextStoreACP;
49 ITfContext *pITfContext;
51 DWORD lockType;
52 TfGravity gravityStart, gravityEnd;
53 DWORD anchorStart, anchorEnd;
55 } Range;
57 static inline Range *impl_from_ITfRange(ITfRange *iface)
59 return CONTAINING_RECORD(iface, Range, ITfRange_iface);
62 static void Range_Destructor(Range *This)
64 TRACE("destroying %p\n", This);
65 HeapFree(GetProcessHeap(),0,This);
68 static HRESULT WINAPI Range_QueryInterface(ITfRange *iface, REFIID iid, LPVOID *ppvOut)
70 Range *This = impl_from_ITfRange(iface);
71 *ppvOut = NULL;
73 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfRange))
75 *ppvOut = &This->ITfRange_iface;
78 if (*ppvOut)
80 ITfRange_AddRef(iface);
81 return S_OK;
84 WARN("unsupported interface: %s\n", debugstr_guid(iid));
85 return E_NOINTERFACE;
88 static ULONG WINAPI Range_AddRef(ITfRange *iface)
90 Range *This = impl_from_ITfRange(iface);
91 return InterlockedIncrement(&This->refCount);
94 static ULONG WINAPI Range_Release(ITfRange *iface)
96 Range *This = impl_from_ITfRange(iface);
97 ULONG ret;
99 ret = InterlockedDecrement(&This->refCount);
100 if (ret == 0)
101 Range_Destructor(This);
102 return ret;
105 /*****************************************************
106 * ITfRange functions
107 *****************************************************/
109 static HRESULT WINAPI Range_GetText(ITfRange *iface, TfEditCookie ec,
110 DWORD dwFlags, WCHAR *pchText, ULONG cchMax, ULONG *pcch)
112 Range *This = impl_from_ITfRange(iface);
113 FIXME("STUB:(%p)\n",This);
114 return E_NOTIMPL;
117 static HRESULT WINAPI Range_SetText(ITfRange *iface, TfEditCookie ec,
118 DWORD dwFlags, const WCHAR *pchText, LONG cch)
120 Range *This = impl_from_ITfRange(iface);
121 FIXME("STUB:(%p)\n",This);
122 return E_NOTIMPL;
125 static HRESULT WINAPI Range_GetFormattedText(ITfRange *iface, TfEditCookie ec,
126 IDataObject **ppDataObject)
128 Range *This = impl_from_ITfRange(iface);
129 FIXME("STUB:(%p)\n",This);
130 return E_NOTIMPL;
133 static HRESULT WINAPI Range_GetEmbedded(ITfRange *iface, TfEditCookie ec,
134 REFGUID rguidService, REFIID riid, IUnknown **ppunk)
136 Range *This = impl_from_ITfRange(iface);
137 FIXME("STUB:(%p)\n",This);
138 return E_NOTIMPL;
141 static HRESULT WINAPI Range_InsertEmbedded(ITfRange *iface, TfEditCookie ec,
142 DWORD dwFlags, IDataObject *pDataObject)
144 Range *This = impl_from_ITfRange(iface);
145 FIXME("STUB:(%p)\n",This);
146 return E_NOTIMPL;
149 static HRESULT WINAPI Range_ShiftStart(ITfRange *iface, TfEditCookie ec,
150 LONG cchReq, LONG *pcch, const TF_HALTCOND *pHalt)
152 Range *This = impl_from_ITfRange(iface);
153 FIXME("STUB:(%p)\n",This);
154 return E_NOTIMPL;
157 static HRESULT WINAPI Range_ShiftEnd(ITfRange *iface, TfEditCookie ec,
158 LONG cchReq, LONG *pcch, const TF_HALTCOND *pHalt)
160 Range *This = impl_from_ITfRange(iface);
161 FIXME("STUB:(%p)\n",This);
162 return E_NOTIMPL;
165 static HRESULT WINAPI Range_ShiftStartToRange(ITfRange *iface, TfEditCookie ec,
166 ITfRange *pRange, TfAnchor aPos)
168 Range *This = impl_from_ITfRange(iface);
169 FIXME("STUB:(%p)\n",This);
170 return E_NOTIMPL;
173 static HRESULT WINAPI Range_ShiftEndToRange(ITfRange *iface, TfEditCookie ec,
174 ITfRange *pRange, TfAnchor aPos)
176 Range *This = impl_from_ITfRange(iface);
177 FIXME("STUB:(%p)\n",This);
178 return E_NOTIMPL;
181 static HRESULT WINAPI Range_ShiftStartRegion(ITfRange *iface, TfEditCookie ec,
182 TfShiftDir dir, BOOL *pfNoRegion)
184 Range *This = impl_from_ITfRange(iface);
185 FIXME("STUB:(%p)\n",This);
186 return E_NOTIMPL;
189 static HRESULT WINAPI Range_ShiftEndRegion(ITfRange *iface, TfEditCookie ec,
190 TfShiftDir dir, BOOL *pfNoRegion)
192 Range *This = impl_from_ITfRange(iface);
193 FIXME("STUB:(%p)\n",This);
194 return E_NOTIMPL;
197 static HRESULT WINAPI Range_IsEmpty(ITfRange *iface, TfEditCookie ec,
198 BOOL *pfEmpty)
200 Range *This = impl_from_ITfRange(iface);
201 FIXME("STUB:(%p)\n",This);
202 return E_NOTIMPL;
205 static HRESULT WINAPI Range_Collapse(ITfRange *iface, TfEditCookie ec,
206 TfAnchor aPos)
208 Range *This = impl_from_ITfRange(iface);
209 TRACE("(%p) %i %i\n",This,ec,aPos);
211 switch (aPos)
213 case TF_ANCHOR_START:
214 This->anchorEnd = This->anchorStart;
215 break;
216 case TF_ANCHOR_END:
217 This->anchorStart = This->anchorEnd;
218 break;
219 default:
220 return E_INVALIDARG;
223 return S_OK;
226 static HRESULT WINAPI Range_IsEqualStart(ITfRange *iface, TfEditCookie ec,
227 ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual)
229 Range *This = impl_from_ITfRange(iface);
230 FIXME("STUB:(%p)\n",This);
231 return E_NOTIMPL;
234 static HRESULT WINAPI Range_IsEqualEnd(ITfRange *iface, TfEditCookie ec,
235 ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual)
237 Range *This = impl_from_ITfRange(iface);
238 FIXME("STUB:(%p)\n",This);
239 return E_NOTIMPL;
242 static HRESULT WINAPI Range_CompareStart(ITfRange *iface, TfEditCookie ec,
243 ITfRange *pWith, TfAnchor aPos, LONG *plResult)
245 Range *This = impl_from_ITfRange(iface);
246 FIXME("STUB:(%p)\n",This);
247 return E_NOTIMPL;
250 static HRESULT WINAPI Range_CompareEnd(ITfRange *iface, TfEditCookie ec,
251 ITfRange *pWith, TfAnchor aPos, LONG *plResult)
253 Range *This = impl_from_ITfRange(iface);
254 FIXME("STUB:(%p)\n",This);
255 return E_NOTIMPL;
258 static HRESULT WINAPI Range_AdjustForInsert(ITfRange *iface, TfEditCookie ec,
259 ULONG cchInsert, BOOL *pfInsertOk)
261 Range *This = impl_from_ITfRange(iface);
262 FIXME("STUB:(%p)\n",This);
263 return E_NOTIMPL;
266 static HRESULT WINAPI Range_GetGravity(ITfRange *iface,
267 TfGravity *pgStart, TfGravity *pgEnd)
269 Range *This = impl_from_ITfRange(iface);
270 FIXME("STUB:(%p)\n",This);
271 return E_NOTIMPL;
274 static HRESULT WINAPI Range_SetGravity(ITfRange *iface, TfEditCookie ec,
275 TfGravity gStart, TfGravity gEnd)
277 Range *This = impl_from_ITfRange(iface);
278 FIXME("STUB:(%p)\n",This);
279 return E_NOTIMPL;
282 static HRESULT WINAPI Range_Clone(ITfRange *iface, ITfRange **ppClone)
284 Range *This = impl_from_ITfRange(iface);
285 FIXME("STUB:(%p)\n",This);
286 return E_NOTIMPL;
289 static HRESULT WINAPI Range_GetContext(ITfRange *iface, ITfContext **ppContext)
291 Range *This = impl_from_ITfRange(iface);
292 TRACE("(%p)\n",This);
293 if (!ppContext)
294 return E_INVALIDARG;
295 *ppContext = This->pITfContext;
296 return S_OK;
299 static const ITfRangeVtbl Range_RangeVtbl =
301 Range_QueryInterface,
302 Range_AddRef,
303 Range_Release,
305 Range_GetText,
306 Range_SetText,
307 Range_GetFormattedText,
308 Range_GetEmbedded,
309 Range_InsertEmbedded,
310 Range_ShiftStart,
311 Range_ShiftEnd,
312 Range_ShiftStartToRange,
313 Range_ShiftEndToRange,
314 Range_ShiftStartRegion,
315 Range_ShiftEndRegion,
316 Range_IsEmpty,
317 Range_Collapse,
318 Range_IsEqualStart,
319 Range_IsEqualEnd,
320 Range_CompareStart,
321 Range_CompareEnd,
322 Range_AdjustForInsert,
323 Range_GetGravity,
324 Range_SetGravity,
325 Range_Clone,
326 Range_GetContext
329 HRESULT Range_Constructor(ITfContext *context, ITextStoreACP *textstore, DWORD lockType, DWORD anchorStart, DWORD anchorEnd, ITfRange **ppOut)
331 Range *This;
333 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Range));
334 if (This == NULL)
335 return E_OUTOFMEMORY;
337 TRACE("(%p) %p %p\n",This, context, textstore);
339 This->ITfRange_iface.lpVtbl = &Range_RangeVtbl;
340 This->refCount = 1;
341 This->pITfContext = context;
342 This->pITextStoreACP = textstore;
343 This->lockType = lockType;
344 This->anchorStart = anchorStart;
345 This->anchorEnd = anchorEnd;
347 *ppOut = &This->ITfRange_iface;
348 TRACE("returning %p\n", *ppOut);
350 return S_OK;
353 /* Internal conversion functions */
355 HRESULT TF_SELECTION_to_TS_SELECTION_ACP(const TF_SELECTION *tf, TS_SELECTION_ACP *tsAcp)
357 Range *This;
359 if (!tf || !tsAcp || !tf->range)
360 return E_INVALIDARG;
362 This = impl_from_ITfRange(tf->range);
364 tsAcp->acpStart = This->anchorStart;
365 tsAcp->acpEnd = This->anchorEnd;
366 tsAcp->style.ase = tf->style.ase;
367 tsAcp->style.fInterimChar = tf->style.fInterimChar;
368 return S_OK;