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 ITfRange ITfRange_iface
;
45 /* const ITfRangeACPVtb *RangeACPVtbl; */
48 ITextStoreACP
*pITextStoreACP
;
49 ITfContext
*pITfContext
;
52 TfGravity gravityStart
, gravityEnd
;
53 DWORD anchorStart
, anchorEnd
;
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
);
73 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfRange
))
80 ITfRange_AddRef(iface
);
84 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
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
);
99 ret
= InterlockedDecrement(&This
->refCount
);
101 Range_Destructor(This
);
105 /*****************************************************
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
197 static HRESULT WINAPI
Range_IsEmpty(ITfRange
*iface
, TfEditCookie ec
,
200 Range
*This
= impl_from_ITfRange(iface
);
201 FIXME("STUB:(%p)\n",This
);
205 static HRESULT WINAPI
Range_Collapse(ITfRange
*iface
, TfEditCookie ec
,
208 Range
*This
= impl_from_ITfRange(iface
);
209 TRACE("(%p) %i %i\n",This
,ec
,aPos
);
213 case TF_ANCHOR_START
:
214 This
->anchorEnd
= This
->anchorStart
;
217 This
->anchorStart
= This
->anchorEnd
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
282 static HRESULT WINAPI
Range_Clone(ITfRange
*iface
, ITfRange
**ppClone
)
284 Range
*This
= impl_from_ITfRange(iface
);
285 FIXME("STUB:(%p)\n",This
);
289 static HRESULT WINAPI
Range_GetContext(ITfRange
*iface
, ITfContext
**ppContext
)
291 Range
*This
= impl_from_ITfRange(iface
);
292 TRACE("(%p)\n",This
);
295 *ppContext
= This
->pITfContext
;
299 static const ITfRangeVtbl Range_RangeVtbl
=
301 Range_QueryInterface
,
307 Range_GetFormattedText
,
309 Range_InsertEmbedded
,
312 Range_ShiftStartToRange
,
313 Range_ShiftEndToRange
,
314 Range_ShiftStartRegion
,
315 Range_ShiftEndRegion
,
322 Range_AdjustForInsert
,
329 HRESULT
Range_Constructor(ITfContext
*context
, ITextStoreACP
*textstore
, DWORD lockType
, DWORD anchorStart
, DWORD anchorEnd
, ITfRange
**ppOut
)
333 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(Range
));
335 return E_OUTOFMEMORY
;
337 TRACE("(%p) %p %p\n",This
, context
, textstore
);
339 This
->ITfRange_iface
.lpVtbl
= &Range_RangeVtbl
;
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", This
);
353 /* Internal conversion functions */
355 HRESULT
TF_SELECTION_to_TS_SELECTION_ACP(const TF_SELECTION
*tf
, TS_SELECTION_ACP
*tsAcp
)
359 if (!tf
|| !tsAcp
|| !tf
->range
)
362 This
= (Range
*)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
;