ole32: Remove some assertions in the stuctured storage code by
[wine] / dlls / riched20 / richole.c
1 /*
2  * RichEdit GUIDs and OLE interface
3  *
4  * Copyright 2004 by Krzysztof Foltman
5  * Copyright 2004 Aric Stewart
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdarg.h>
23
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #define COBJMACROS
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "ole2.h"
33 #include "richole.h"
34 #include "editor.h"
35 #include "tom.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
39
40 /* there is no way to be consistent across different sets of headers - mingw, Wine, Win32 SDK*/
41
42 /* FIXME: the next 6 lines should be in textserv.h */
43 #include "initguid.h"
44 #define TEXTSERV_GUID(name, l, w1, w2, b1, b2) \
45     DEFINE_GUID(name, l, w1, w2, b1, b2, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5)
46
47 TEXTSERV_GUID(IID_ITextServices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d);
48 TEXTSERV_GUID(IID_ITextHost, 0xc5bdd8d0, 0xd26e, 0x11ce, 0xa8, 0x9e);
49 TEXTSERV_GUID(IID_ITextHost2, 0xc5bdd8d0, 0xd26e, 0x11ce, 0xa8, 0x9e);
50 DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
51
52 typedef struct IRichEditOleImpl {
53     const IRichEditOleVtbl *lpRichEditOleVtbl;
54     const ITextDocumentVtbl *lpTextDocumentVtbl;
55     LONG ref;
56
57     ME_TextEditor *editor;
58 } IRichEditOleImpl;
59
60 static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
61 {
62     return (IRichEditOleImpl *)((BYTE*)iface - FIELD_OFFSET(IRichEditOleImpl, lpRichEditOleVtbl));
63 }
64
65 static inline IRichEditOleImpl *impl_from_ITextDocument(ITextDocument *iface)
66 {
67     return (IRichEditOleImpl *)((BYTE*)iface - FIELD_OFFSET(IRichEditOleImpl, lpTextDocumentVtbl));
68 }
69
70 static HRESULT WINAPI
71 IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
72 {
73     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
74
75     TRACE("%p %s\n", This, debugstr_guid(riid) );
76
77     *ppvObj = NULL;
78     if (IsEqualGUID(riid, &IID_IUnknown) ||
79         IsEqualGUID(riid, &IID_IRichEditOle))
80         *ppvObj = &This->lpRichEditOleVtbl;
81     else if (IsEqualGUID(riid, &IID_ITextDocument))
82         *ppvObj = &This->lpTextDocumentVtbl;
83     if (*ppvObj)
84     {
85         IRichEditOle_AddRef(me);
86         return S_OK;
87     }
88     FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid) );
89  
90     return E_NOINTERFACE;   
91 }
92
93 static ULONG WINAPI
94 IRichEditOle_fnAddRef(IRichEditOle *me)
95 {
96     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
97     ULONG ref = InterlockedIncrement( &This->ref );
98
99     TRACE("%p ref = %lu\n", This, ref);
100
101     return ref;
102 }
103
104 static ULONG WINAPI
105 IRichEditOle_fnRelease(IRichEditOle *me)
106 {
107     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
108     ULONG ref = InterlockedDecrement(&This->ref);
109
110     TRACE ("%p ref=%lu\n", This, ref);
111
112     if (!ref)
113     {
114         TRACE ("Destroying %p\n", This);
115         HeapFree(GetProcessHeap(),0,This);
116     }
117     return ref;
118 }
119
120 static HRESULT WINAPI
121 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
122 {
123     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
124     FIXME("stub %p\n",This);
125     return E_NOTIMPL;
126 }
127
128 static HRESULT WINAPI
129 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
130 {
131     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
132     FIXME("stub %p\n",This);
133     return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI
137 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
138                REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
139 {
140     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
141     FIXME("stub %p\n",This);
142     return E_NOTIMPL;
143 }
144
145 static HRESULT WINAPI
146 IRichEditOle_fnGetClientSite(IRichEditOle *me,
147                LPOLECLIENTSITE *lplpolesite)
148 {
149     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
150     FIXME("stub %p\n",This);
151     return E_NOTIMPL;
152 }
153
154 static HRESULT WINAPI
155 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
156                DWORD reco, LPDATAOBJECT *lplpdataobj)
157 {
158     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
159     CHARRANGE tmpchrg;
160
161     TRACE("(%p,%p,%ld)\n",This, lpchrg, reco);
162     if(!lplpdataobj)
163         return E_INVALIDARG;
164     if(!lpchrg) {
165         ME_GetSelection(This->editor, (int*)&tmpchrg.cpMin, (int*)&tmpchrg.cpMax);
166         lpchrg = &tmpchrg;
167     }
168     return ME_GetDataObject(This->editor, lpchrg, lplpdataobj);
169 }
170
171 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
172 {
173     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
174     FIXME("stub %p\n",This);
175     return E_NOTIMPL;
176 }
177
178 static HRESULT WINAPI
179 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
180                REOBJECT *lpreobject, DWORD dwFlags)
181 {
182     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
183     FIXME("stub %p\n",This);
184     return E_NOTIMPL;
185 }
186
187 static LONG WINAPI
188 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
189 {
190     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
191     FIXME("stub %p\n",This);
192     return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI
196 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
197 {
198     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
199     FIXME("stub %p\n",This);
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI
204 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
205                CLIPFORMAT cf, HGLOBAL hMetaPict)
206 {
207     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
208     FIXME("stub %p\n",This);
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI
213 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
214 {
215     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
216     FIXME("stub %p\n",This);
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI
221 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *lpreobject)
222 {
223     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
224     FIXME("stub %p\n",This);
225     return E_NOTIMPL;
226 }
227
228 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
229                LPSTORAGE lpstg)
230 {
231     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
232     FIXME("stub %p\n",This);
233     return E_NOTIMPL;
234 }
235
236 static HRESULT WINAPI
237 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
238 {
239     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
240     FIXME("stub %p\n",This);
241     return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
245                LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
246 {
247     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
248     FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
249     return E_NOTIMPL;
250 }
251
252 static HRESULT WINAPI
253 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
254 {
255     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
256     FIXME("stub %p\n",This);
257     return E_NOTIMPL;
258 }
259
260 static const IRichEditOleVtbl revt = {
261     IRichEditOle_fnQueryInterface,
262     IRichEditOle_fnAddRef,
263     IRichEditOle_fnRelease,
264     IRichEditOle_fnGetClientSite,
265     IRichEditOle_fnGetObjectCount,
266     IRichEditOle_fnGetLinkCount,
267     IRichEditOle_fnGetObject,
268     IRichEditOle_fnInsertObject,
269     IRichEditOle_fnConvertObject,
270     IRichEditOle_fnActivateAs,
271     IRichEditOle_fnSetHostNames,
272     IRichEditOle_fnSetLinkAvailable,
273     IRichEditOle_fnSetDvaspect,
274     IRichEditOle_fnHandsOffStorage,
275     IRichEditOle_fnSaveCompleted,
276     IRichEditOle_fnInPlaceDeactivate,
277     IRichEditOle_fnContextSensitiveHelp,
278     IRichEditOle_fnGetClipboardData,
279     IRichEditOle_fnImportDataObject
280 };
281
282 static HRESULT WINAPI
283 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
284     void** ppvObject)
285 {
286     IRichEditOleImpl *This = impl_from_ITextDocument(me);
287     return IRichEditOle_fnQueryInterface((IRichEditOle*)&This->lpRichEditOleVtbl,
288             riid, ppvObject);
289 }
290
291 static ULONG WINAPI
292 ITextDocument_fnAddRef(ITextDocument* me)
293 {
294     IRichEditOleImpl *This = impl_from_ITextDocument(me);
295     return IRichEditOle_fnAddRef((IRichEditOle*)&This->lpRichEditOleVtbl);
296 }
297
298 static ULONG WINAPI
299 ITextDocument_fnRelease(ITextDocument* me)
300 {
301     IRichEditOleImpl *This = impl_from_ITextDocument(me);
302     return IRichEditOle_fnRelease((IRichEditOle*)&This->lpRichEditOleVtbl);
303 }
304
305 static HRESULT WINAPI
306 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
307     UINT* pctinfo)
308 {
309     IRichEditOleImpl *This = impl_from_ITextDocument(me);
310     FIXME("stub %p\n",This);
311     return E_NOTIMPL;
312 }
313
314 static HRESULT WINAPI
315 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
316     ITypeInfo** ppTInfo)
317 {
318     IRichEditOleImpl *This = impl_from_ITextDocument(me);
319     FIXME("stub %p\n",This);
320     return E_NOTIMPL;
321 }
322
323 static HRESULT WINAPI
324 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
325     LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
326 {
327     IRichEditOleImpl *This = impl_from_ITextDocument(me);
328     FIXME("stub %p\n",This);
329     return E_NOTIMPL;
330 }
331
332 static HRESULT WINAPI
333 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
334     REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
335     VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
336 {
337     IRichEditOleImpl *This = impl_from_ITextDocument(me);
338     FIXME("stub %p\n",This);
339     return E_NOTIMPL;
340 }
341
342 static HRESULT WINAPI
343 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
344 {
345     IRichEditOleImpl *This = impl_from_ITextDocument(me);
346     FIXME("stub %p\n",This);
347     return E_NOTIMPL;
348 }
349
350 static HRESULT WINAPI
351 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
352 {
353     IRichEditOleImpl *This = impl_from_ITextDocument(me);
354     FIXME("stub %p\n",This);
355     return E_NOTIMPL;
356 }
357
358 static HRESULT WINAPI
359 ITextDocument_fnGetStoryCount(ITextDocument* me, long* pCount)
360 {
361     IRichEditOleImpl *This = impl_from_ITextDocument(me);
362     FIXME("stub %p\n",This);
363     return E_NOTIMPL;
364 }
365
366 static HRESULT WINAPI
367 ITextDocument_fnGetStoryRanges(ITextDocument* me,
368     ITextStoryRanges** ppStories)
369 {
370     IRichEditOleImpl *This = impl_from_ITextDocument(me);
371     FIXME("stub %p\n",This);
372     return E_NOTIMPL;
373 }
374
375 static HRESULT WINAPI
376 ITextDocument_fnGetSaved(ITextDocument* me, long* pValue)
377 {
378     IRichEditOleImpl *This = impl_from_ITextDocument(me);
379     FIXME("stub %p\n",This);
380     return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI
384 ITextDocument_fnSetSaved(ITextDocument* me, long Value)
385 {
386     IRichEditOleImpl *This = impl_from_ITextDocument(me);
387     FIXME("stub %p\n",This);
388     return E_NOTIMPL;
389 }
390
391 static HRESULT WINAPI
392 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
393 {
394     IRichEditOleImpl *This = impl_from_ITextDocument(me);
395     FIXME("stub %p\n",This);
396     return E_NOTIMPL;
397 }
398
399 static HRESULT WINAPI
400 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
401 {
402     IRichEditOleImpl *This = impl_from_ITextDocument(me);
403     FIXME("stub %p\n",This);
404     return E_NOTIMPL;
405 }
406
407 static HRESULT WINAPI
408 ITextDocument_fnNew(ITextDocument* me)
409 {
410     IRichEditOleImpl *This = impl_from_ITextDocument(me);
411     FIXME("stub %p\n",This);
412     return E_NOTIMPL;
413 }
414
415 static HRESULT WINAPI
416 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, long Flags,
417     long CodePage)
418 {
419     IRichEditOleImpl *This = impl_from_ITextDocument(me);
420     FIXME("stub %p\n",This);
421     return E_NOTIMPL;
422 }
423
424 static HRESULT WINAPI
425 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, long Flags,
426     long CodePage)
427 {
428     IRichEditOleImpl *This = impl_from_ITextDocument(me);
429     FIXME("stub %p\n",This);
430     return E_NOTIMPL;
431 }
432
433 static HRESULT WINAPI
434 ITextDocument_fnFreeze(ITextDocument* me, long* pCount)
435 {
436     IRichEditOleImpl *This = impl_from_ITextDocument(me);
437     FIXME("stub %p\n",This);
438     return E_NOTIMPL;
439 }
440
441 static HRESULT WINAPI
442 ITextDocument_fnUnfreeze(ITextDocument* me, long* pCount)
443 {
444     IRichEditOleImpl *This = impl_from_ITextDocument(me);
445     FIXME("stub %p\n",This);
446     return E_NOTIMPL;
447 }
448
449 static HRESULT WINAPI
450 ITextDocument_fnBeginEditCollection(ITextDocument* me)
451 {
452     IRichEditOleImpl *This = impl_from_ITextDocument(me);
453     FIXME("stub %p\n",This);
454     return E_NOTIMPL;
455 }
456
457 static HRESULT WINAPI
458 ITextDocument_fnEndEditCollection(ITextDocument* me)
459 {
460     IRichEditOleImpl *This = impl_from_ITextDocument(me);
461     FIXME("stub %p\n",This);
462     return E_NOTIMPL;
463 }
464
465 static HRESULT WINAPI
466 ITextDocument_fnUndo(ITextDocument* me, long Count, long* prop)
467 {
468     IRichEditOleImpl *This = impl_from_ITextDocument(me);
469     FIXME("stub %p\n",This);
470     return E_NOTIMPL;
471 }
472
473 static HRESULT WINAPI
474 ITextDocument_fnRedo(ITextDocument* me, long Count, long* prop)
475 {
476     IRichEditOleImpl *This = impl_from_ITextDocument(me);
477     FIXME("stub %p\n",This);
478     return E_NOTIMPL;
479 }
480
481 static HRESULT WINAPI
482 ITextDocument_fnRange(ITextDocument* me, long cp1, long cp2,
483     ITextRange** ppRange)
484 {
485     IRichEditOleImpl *This = impl_from_ITextDocument(me);
486     FIXME("stub %p\n",This);
487     return E_NOTIMPL;
488 }
489
490 static HRESULT WINAPI
491 ITextDocument_fnRangeFromPoint(ITextDocument* me, long x, long y,
492     ITextRange** ppRange)
493 {
494     IRichEditOleImpl *This = impl_from_ITextDocument(me);
495     FIXME("stub %p\n",This);
496     return E_NOTIMPL;
497 }
498
499 static const ITextDocumentVtbl tdvt = {
500     ITextDocument_fnQueryInterface,
501     ITextDocument_fnAddRef,
502     ITextDocument_fnRelease,
503     ITextDocument_fnGetTypeInfoCount,
504     ITextDocument_fnGetTypeInfo,
505     ITextDocument_fnGetIDsOfNames,
506     ITextDocument_fnInvoke,
507     ITextDocument_fnGetName,
508     ITextDocument_fnGetSelection,
509     ITextDocument_fnGetStoryCount,
510     ITextDocument_fnGetStoryRanges,
511     ITextDocument_fnGetSaved,
512     ITextDocument_fnSetSaved,
513     ITextDocument_fnGetDefaultTabStop,
514     ITextDocument_fnSetDefaultTabStop,
515     ITextDocument_fnNew,
516     ITextDocument_fnOpen,
517     ITextDocument_fnSave,
518     ITextDocument_fnFreeze,
519     ITextDocument_fnUnfreeze,
520     ITextDocument_fnBeginEditCollection,
521     ITextDocument_fnEndEditCollection,
522     ITextDocument_fnUndo,
523     ITextDocument_fnRedo,
524     ITextDocument_fnRange,
525     ITextDocument_fnRangeFromPoint
526 };
527
528 LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
529 {
530     IRichEditOleImpl *reo;
531
532     reo = HeapAlloc(GetProcessHeap(), 0, sizeof(IRichEditOleImpl));
533     if (!reo)
534         return 0;
535
536     reo->lpRichEditOleVtbl = &revt;
537     reo->lpTextDocumentVtbl = &tdvt;
538     reo->ref = 1;
539     reo->editor = editor;
540     TRACE("Created %p\n",reo);
541     *ppObj = (LPVOID) reo;
542
543     return 1;
544 }