msctf: Use FAILED instead of !SUCCEDED.
[wine] / dlls / 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     FIXME("STUB:(%p)\n",This);
205     return E_NOTIMPL;
206 }
207
208 static HRESULT WINAPI Range_IsEqualStart(ITfRange *iface, TfEditCookie ec,
209         ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual)
210 {
211     Range *This = (Range *)iface;
212     FIXME("STUB:(%p)\n",This);
213     return E_NOTIMPL;
214 }
215
216 static HRESULT WINAPI Range_IsEqualEnd(ITfRange *iface, TfEditCookie ec,
217         ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual)
218 {
219     Range *This = (Range *)iface;
220     FIXME("STUB:(%p)\n",This);
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI Range_CompareStart(ITfRange *iface, TfEditCookie ec,
225         ITfRange *pWith, TfAnchor aPos, LONG *plResult)
226 {
227     Range *This = (Range *)iface;
228     FIXME("STUB:(%p)\n",This);
229     return E_NOTIMPL;
230 }
231
232 static HRESULT WINAPI Range_CompareEnd(ITfRange *iface, TfEditCookie ec,
233         ITfRange *pWith, TfAnchor aPos, LONG *plResult)
234 {
235     Range *This = (Range *)iface;
236     FIXME("STUB:(%p)\n",This);
237     return E_NOTIMPL;
238 }
239
240 static HRESULT WINAPI Range_AdjustForInsert(ITfRange *iface, TfEditCookie ec,
241         ULONG cchInsert, BOOL *pfInsertOk)
242 {
243     Range *This = (Range *)iface;
244     FIXME("STUB:(%p)\n",This);
245     return E_NOTIMPL;
246 }
247
248 static HRESULT WINAPI Range_GetGravity(ITfRange *iface,
249         TfGravity *pgStart, TfGravity *pgEnd)
250 {
251     Range *This = (Range *)iface;
252     FIXME("STUB:(%p)\n",This);
253     return E_NOTIMPL;
254 }
255
256 static HRESULT WINAPI Range_SetGravity(ITfRange *iface, TfEditCookie ec,
257          TfGravity gStart, TfGravity gEnd)
258 {
259     Range *This = (Range *)iface;
260     FIXME("STUB:(%p)\n",This);
261     return E_NOTIMPL;
262 }
263
264 static HRESULT WINAPI Range_Clone(ITfRange *iface, ITfRange **ppClone)
265 {
266     Range *This = (Range *)iface;
267     FIXME("STUB:(%p)\n",This);
268     return E_NOTIMPL;
269 }
270
271 static HRESULT WINAPI Range_GetContext(ITfRange *iface, ITfContext **ppContext)
272 {
273     Range *This = (Range *)iface;
274     TRACE("(%p)\n",This);
275     if (!ppContext)
276         return E_INVALIDARG;
277     *ppContext = This->pITfContext;
278     return S_OK;
279 }
280
281 static const ITfRangeVtbl Range_RangeVtbl =
282 {
283     Range_QueryInterface,
284     Range_AddRef,
285     Range_Release,
286
287     Range_GetText,
288     Range_SetText,
289     Range_GetFormattedText,
290     Range_GetEmbedded,
291     Range_InsertEmbedded,
292     Range_ShiftStart,
293     Range_ShiftEnd,
294     Range_ShiftStartToRange,
295     Range_ShiftEndToRange,
296     Range_ShiftStartRegion,
297     Range_ShiftEndRegion,
298     Range_IsEmpty,
299     Range_Collapse,
300     Range_IsEqualStart,
301     Range_IsEqualEnd,
302     Range_CompareStart,
303     Range_CompareEnd,
304     Range_AdjustForInsert,
305     Range_GetGravity,
306     Range_SetGravity,
307     Range_Clone,
308     Range_GetContext
309 };
310
311 HRESULT Range_Constructor(ITfContext *context, ITextStoreACP *textstore, DWORD lockType, DWORD anchorStart, DWORD anchorEnd, ITfRange **ppOut)
312 {
313     Range *This;
314
315     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Range));
316     if (This == NULL)
317         return E_OUTOFMEMORY;
318
319     TRACE("(%p) %p %p\n",This, context, textstore);
320
321     This->RangeVtbl= &Range_RangeVtbl;
322     This->refCount = 1;
323     This->pITfContext = context;
324     This->pITextStoreACP = textstore;
325     This->lockType = lockType;
326     This->anchorStart = anchorStart;
327     This->anchorEnd = anchorEnd;
328
329     *ppOut = (ITfRange*)This;
330     TRACE("returning %p\n", This);
331
332     return S_OK;
333 }