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
27 #include "wine/debug.h"
36 #include "wine/unicode.h"
39 #include "msctf_internal.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msctf
);
43 typedef struct tagRange
{
44 const ITfRangeVtbl
*RangeVtbl
;
45 /* const ITfRangeACPVtb *RangeACPVtbl; */
48 ITextStoreACP
*pITextStoreACP
;
49 ITfContext
*pITfContext
;
52 TfGravity gravityStart
, gravityEnd
;
53 DWORD anchorStart
, anchorEnd
;
57 static void Range_Destructor(Range
*This
)
59 TRACE("destroying %p\n", This
);
60 HeapFree(GetProcessHeap(),0,This
);
63 static HRESULT WINAPI
Range_QueryInterface(ITfRange
*iface
, REFIID iid
, LPVOID
*ppvOut
)
65 Range
*This
= (Range
*)iface
;
68 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfRange
))
75 IUnknown_AddRef(iface
);
79 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
83 static ULONG WINAPI
Range_AddRef(ITfRange
*iface
)
85 Range
*This
= (Range
*)iface
;
86 return InterlockedIncrement(&This
->refCount
);
89 static ULONG WINAPI
Range_Release(ITfRange
*iface
)
91 Range
*This
= (Range
*)iface
;
94 ret
= InterlockedDecrement(&This
->refCount
);
96 Range_Destructor(This
);
100 /*****************************************************
102 *****************************************************/
104 static HRESULT WINAPI
Range_GetText(ITfRange
*iface
, TfEditCookie ec
,
105 DWORD dwFlags
, WCHAR
*pchText
, ULONG cchMax
, ULONG
*pcch
)
107 Range
*This
= (Range
*)iface
;
108 FIXME("STUB:(%p)\n",This
);
112 static HRESULT WINAPI
Range_SetText(ITfRange
*iface
, TfEditCookie ec
,
113 DWORD dwFlags
, const WCHAR
*pchText
, LONG cch
)
115 Range
*This
= (Range
*)iface
;
116 FIXME("STUB:(%p)\n",This
);
120 static HRESULT WINAPI
Range_GetFormattedText(ITfRange
*iface
, TfEditCookie ec
,
121 IDataObject
**ppDataObject
)
123 Range
*This
= (Range
*)iface
;
124 FIXME("STUB:(%p)\n",This
);
128 static HRESULT WINAPI
Range_GetEmbedded(ITfRange
*iface
, TfEditCookie ec
,
129 REFGUID rguidService
, REFIID riid
, IUnknown
**ppunk
)
131 Range
*This
= (Range
*)iface
;
132 FIXME("STUB:(%p)\n",This
);
136 static HRESULT WINAPI
Range_InsertEmbedded(ITfRange
*iface
, TfEditCookie ec
,
137 DWORD dwFlags
, IDataObject
*pDataObject
)
139 Range
*This
= (Range
*)iface
;
140 FIXME("STUB:(%p)\n",This
);
144 static HRESULT WINAPI
Range_ShiftStart(ITfRange
*iface
, TfEditCookie ec
,
145 LONG cchReq
, LONG
*pcch
, const TF_HALTCOND
*pHalt
)
147 Range
*This
= (Range
*)iface
;
148 FIXME("STUB:(%p)\n",This
);
152 static HRESULT WINAPI
Range_ShiftEnd(ITfRange
*iface
, TfEditCookie ec
,
153 LONG cchReq
, LONG
*pcch
, const TF_HALTCOND
*pHalt
)
155 Range
*This
= (Range
*)iface
;
156 FIXME("STUB:(%p)\n",This
);
160 static HRESULT WINAPI
Range_ShiftStartToRange(ITfRange
*iface
, TfEditCookie ec
,
161 ITfRange
*pRange
, TfAnchor aPos
)
163 Range
*This
= (Range
*)iface
;
164 FIXME("STUB:(%p)\n",This
);
168 static HRESULT WINAPI
Range_ShiftEndToRange(ITfRange
*iface
, TfEditCookie ec
,
169 ITfRange
*pRange
, TfAnchor aPos
)
171 Range
*This
= (Range
*)iface
;
172 FIXME("STUB:(%p)\n",This
);
176 static HRESULT WINAPI
Range_ShiftStartRegion(ITfRange
*iface
, TfEditCookie ec
,
177 TfShiftDir dir
, BOOL
*pfNoRegion
)
179 Range
*This
= (Range
*)iface
;
180 FIXME("STUB:(%p)\n",This
);
184 static HRESULT WINAPI
Range_ShiftEndRegion(ITfRange
*iface
, TfEditCookie ec
,
185 TfShiftDir dir
, BOOL
*pfNoRegion
)
187 Range
*This
= (Range
*)iface
;
188 FIXME("STUB:(%p)\n",This
);
192 static HRESULT WINAPI
Range_IsEmpty(ITfRange
*iface
, TfEditCookie ec
,
195 Range
*This
= (Range
*)iface
;
196 FIXME("STUB:(%p)\n",This
);
200 static HRESULT WINAPI
Range_Collapse(ITfRange
*iface
, TfEditCookie ec
,
203 Range
*This
= (Range
*)iface
;
204 TRACE("(%p) %i %i\n",This
,ec
,aPos
);
208 case TF_ANCHOR_START
:
209 This
->anchorEnd
= This
->anchorStart
;
212 This
->anchorStart
= This
->anchorEnd
;
221 static HRESULT WINAPI
Range_IsEqualStart(ITfRange
*iface
, TfEditCookie ec
,
222 ITfRange
*pWith
, TfAnchor aPos
, BOOL
*pfEqual
)
224 Range
*This
= (Range
*)iface
;
225 FIXME("STUB:(%p)\n",This
);
229 static HRESULT WINAPI
Range_IsEqualEnd(ITfRange
*iface
, TfEditCookie ec
,
230 ITfRange
*pWith
, TfAnchor aPos
, BOOL
*pfEqual
)
232 Range
*This
= (Range
*)iface
;
233 FIXME("STUB:(%p)\n",This
);
237 static HRESULT WINAPI
Range_CompareStart(ITfRange
*iface
, TfEditCookie ec
,
238 ITfRange
*pWith
, TfAnchor aPos
, LONG
*plResult
)
240 Range
*This
= (Range
*)iface
;
241 FIXME("STUB:(%p)\n",This
);
245 static HRESULT WINAPI
Range_CompareEnd(ITfRange
*iface
, TfEditCookie ec
,
246 ITfRange
*pWith
, TfAnchor aPos
, LONG
*plResult
)
248 Range
*This
= (Range
*)iface
;
249 FIXME("STUB:(%p)\n",This
);
253 static HRESULT WINAPI
Range_AdjustForInsert(ITfRange
*iface
, TfEditCookie ec
,
254 ULONG cchInsert
, BOOL
*pfInsertOk
)
256 Range
*This
= (Range
*)iface
;
257 FIXME("STUB:(%p)\n",This
);
261 static HRESULT WINAPI
Range_GetGravity(ITfRange
*iface
,
262 TfGravity
*pgStart
, TfGravity
*pgEnd
)
264 Range
*This
= (Range
*)iface
;
265 FIXME("STUB:(%p)\n",This
);
269 static HRESULT WINAPI
Range_SetGravity(ITfRange
*iface
, TfEditCookie ec
,
270 TfGravity gStart
, TfGravity gEnd
)
272 Range
*This
= (Range
*)iface
;
273 FIXME("STUB:(%p)\n",This
);
277 static HRESULT WINAPI
Range_Clone(ITfRange
*iface
, ITfRange
**ppClone
)
279 Range
*This
= (Range
*)iface
;
280 FIXME("STUB:(%p)\n",This
);
284 static HRESULT WINAPI
Range_GetContext(ITfRange
*iface
, ITfContext
**ppContext
)
286 Range
*This
= (Range
*)iface
;
287 TRACE("(%p)\n",This
);
290 *ppContext
= This
->pITfContext
;
294 static const ITfRangeVtbl Range_RangeVtbl
=
296 Range_QueryInterface
,
302 Range_GetFormattedText
,
304 Range_InsertEmbedded
,
307 Range_ShiftStartToRange
,
308 Range_ShiftEndToRange
,
309 Range_ShiftStartRegion
,
310 Range_ShiftEndRegion
,
317 Range_AdjustForInsert
,
324 HRESULT
Range_Constructor(ITfContext
*context
, ITextStoreACP
*textstore
, DWORD lockType
, DWORD anchorStart
, DWORD anchorEnd
, ITfRange
**ppOut
)
328 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(Range
));
330 return E_OUTOFMEMORY
;
332 TRACE("(%p) %p %p\n",This
, context
, textstore
);
334 This
->RangeVtbl
= &Range_RangeVtbl
;
336 This
->pITfContext
= context
;
337 This
->pITextStoreACP
= textstore
;
338 This
->lockType
= lockType
;
339 This
->anchorStart
= anchorStart
;
340 This
->anchorEnd
= anchorEnd
;
342 *ppOut
= (ITfRange
*)This
;
343 TRACE("returning %p\n", This
);
348 /* Internal conversion functions */
350 HRESULT
TF_SELECTION_to_TS_SELECTION_ACP(const TF_SELECTION
*tf
, TS_SELECTION_ACP
*tsAcp
)
354 if (!tf
|| !tsAcp
|| !tf
->range
)
357 This
= (Range
*)tf
->range
;
359 tsAcp
->acpStart
= This
->anchorStart
;
360 tsAcp
->acpEnd
= This
->anchorEnd
;
361 tsAcp
->style
.ase
= tf
->style
.ase
;
362 tsAcp
->style
.fInterimChar
= tf
->style
.fInterimChar
;