mshtml: Added IHTMLDocument2::put_designMode tests.
[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 #include "initguid.h"
43 DEFINE_GUID(IID_ITextServices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
44 DEFINE_GUID(IID_ITextHost, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
45 DEFINE_GUID(IID_ITextHost2, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
46 DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
47 DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
48 DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
49
50 typedef struct ITextSelectionImpl ITextSelectionImpl;
51 typedef struct IOleClientSiteImpl IOleClientSiteImpl;
52
53 typedef struct IRichEditOleImpl {
54     IRichEditOle IRichEditOle_iface;
55     ITextDocument ITextDocument_iface;
56     LONG ref;
57
58     ME_TextEditor *editor;
59     ITextSelectionImpl *txtSel;
60     IOleClientSiteImpl *clientSite;
61 } IRichEditOleImpl;
62
63 struct ITextSelectionImpl {
64     ITextSelection ITextSelection_iface;
65     LONG ref;
66
67     IRichEditOleImpl *reOle;
68 };
69
70 struct IOleClientSiteImpl {
71     IOleClientSite IOleClientSite_iface;
72     LONG ref;
73
74     IRichEditOleImpl *reOle;
75 };
76
77 static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
78 {
79     return CONTAINING_RECORD(iface, IRichEditOleImpl, IRichEditOle_iface);
80 }
81
82 static inline IRichEditOleImpl *impl_from_ITextDocument(ITextDocument *iface)
83 {
84     return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument_iface);
85 }
86
87 static HRESULT WINAPI
88 IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
89 {
90     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
91
92     TRACE("%p %s\n", This, debugstr_guid(riid) );
93
94     *ppvObj = NULL;
95     if (IsEqualGUID(riid, &IID_IUnknown) ||
96         IsEqualGUID(riid, &IID_IRichEditOle))
97         *ppvObj = &This->IRichEditOle_iface;
98     else if (IsEqualGUID(riid, &IID_ITextDocument))
99         *ppvObj = &This->ITextDocument_iface;
100     if (*ppvObj)
101     {
102         IRichEditOle_AddRef(me);
103         return S_OK;
104     }
105     FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid) );
106  
107     return E_NOINTERFACE;   
108 }
109
110 static ULONG WINAPI
111 IRichEditOle_fnAddRef(IRichEditOle *me)
112 {
113     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
114     ULONG ref = InterlockedIncrement( &This->ref );
115
116     TRACE("%p ref = %u\n", This, ref);
117
118     return ref;
119 }
120
121 static ULONG WINAPI
122 IRichEditOle_fnRelease(IRichEditOle *me)
123 {
124     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
125     ULONG ref = InterlockedDecrement(&This->ref);
126
127     TRACE ("%p ref=%u\n", This, ref);
128
129     if (!ref)
130     {
131         TRACE ("Destroying %p\n", This);
132         This->txtSel->reOle = NULL;
133         ITextSelection_Release(&This->txtSel->ITextSelection_iface);
134         IOleClientSite_Release(&This->clientSite->IOleClientSite_iface);
135         heap_free(This);
136     }
137     return ref;
138 }
139
140 static HRESULT WINAPI
141 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
142 {
143     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
144     FIXME("stub %p\n",This);
145     return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI
149 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
150 {
151     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
152     FIXME("stub %p\n",This);
153     return E_NOTIMPL;
154 }
155
156 static HRESULT WINAPI
157 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
158                REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
159 {
160     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
161     FIXME("stub %p\n",This);
162     return E_NOTIMPL;
163 }
164
165 static inline IOleClientSiteImpl *impl_from_IOleClientSite(IOleClientSite *iface)
166 {
167     return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleClientSite_iface);
168 }
169
170 static HRESULT WINAPI
171 IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
172 {
173     TRACE("%p %s\n", me, debugstr_guid(riid) );
174
175     *ppvObj = NULL;
176     if (IsEqualGUID(riid, &IID_IUnknown) ||
177         IsEqualGUID(riid, &IID_IOleClientSite))
178         *ppvObj = me;
179     if (*ppvObj)
180     {
181         IOleClientSite_AddRef(me);
182         return S_OK;
183     }
184     FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );
185
186     return E_NOINTERFACE;
187 }
188
189 static ULONG WINAPI IOleClientSite_fnAddRef(IOleClientSite *iface)
190 {
191     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
192     return InterlockedIncrement(&This->ref);
193 }
194
195 static ULONG WINAPI IOleClientSite_fnRelease(IOleClientSite *iface)
196 {
197     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
198     ULONG ref = InterlockedDecrement(&This->ref);
199     if (ref == 0)
200         heap_free(This);
201     return ref;
202 }
203
204 static HRESULT WINAPI IOleClientSite_fnSaveObject(IOleClientSite *iface)
205 {
206     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
207     if (!This->reOle)
208         return CO_E_RELEASED;
209
210     FIXME("stub %p\n", iface);
211     return E_NOTIMPL;
212 }
213
214
215 static HRESULT WINAPI IOleClientSite_fnGetMoniker(IOleClientSite *iface, DWORD dwAssign,
216         DWORD dwWhichMoniker, IMoniker **ppmk)
217 {
218     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
219     if (!This->reOle)
220         return CO_E_RELEASED;
221
222     FIXME("stub %p\n", iface);
223     return E_NOTIMPL;
224 }
225
226 static HRESULT WINAPI IOleClientSite_fnGetContainer(IOleClientSite *iface,
227         IOleContainer **ppContainer)
228 {
229     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
230     if (!This->reOle)
231         return CO_E_RELEASED;
232
233     FIXME("stub %p\n", iface);
234     return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI IOleClientSite_fnShowObject(IOleClientSite *iface)
238 {
239     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
240     if (!This->reOle)
241         return CO_E_RELEASED;
242
243     FIXME("stub %p\n", iface);
244     return E_NOTIMPL;
245 }
246
247 static HRESULT WINAPI IOleClientSite_fnOnShowWindow(IOleClientSite *iface, BOOL fShow)
248 {
249     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
250     if (!This->reOle)
251         return CO_E_RELEASED;
252
253     FIXME("stub %p\n", iface);
254     return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *iface)
258 {
259     IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
260     if (!This->reOle)
261         return CO_E_RELEASED;
262
263     FIXME("stub %p\n", iface);
264     return E_NOTIMPL;
265 }
266
267 static const IOleClientSiteVtbl ocst = {
268     IOleClientSite_fnQueryInterface,
269     IOleClientSite_fnAddRef,
270     IOleClientSite_fnRelease,
271     IOleClientSite_fnSaveObject,
272     IOleClientSite_fnGetMoniker,
273     IOleClientSite_fnGetContainer,
274     IOleClientSite_fnShowObject,
275     IOleClientSite_fnOnShowWindow,
276     IOleClientSite_fnRequestNewObjectLayout
277 };
278
279 static IOleClientSiteImpl *
280 CreateOleClientSite(IRichEditOleImpl *reOle)
281 {
282     IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
283     if (!clientSite)
284         return NULL;
285
286     clientSite->IOleClientSite_iface.lpVtbl = &ocst;
287     clientSite->ref = 1;
288     clientSite->reOle = reOle;
289     return clientSite;
290 }
291
292 static HRESULT WINAPI
293 IRichEditOle_fnGetClientSite(IRichEditOle *me,
294                LPOLECLIENTSITE *lplpolesite)
295 {
296     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
297
298     TRACE("%p,%p\n",This, lplpolesite);
299
300     if(!lplpolesite)
301         return E_INVALIDARG;
302     *lplpolesite = &This->clientSite->IOleClientSite_iface;
303     IOleClientSite_fnAddRef(*lplpolesite);
304     return S_OK;
305 }
306
307 static HRESULT WINAPI
308 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
309                DWORD reco, LPDATAOBJECT *lplpdataobj)
310 {
311     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
312     ME_Cursor start;
313     int nChars;
314
315     TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
316     if(!lplpdataobj)
317         return E_INVALIDARG;
318     if(!lpchrg) {
319         int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
320         start = This->editor->pCursors[nStartCur];
321         nChars = nTo - nFrom;
322     } else {
323         ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
324         nChars = lpchrg->cpMax - lpchrg->cpMin;
325     }
326     return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
327 }
328
329 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
330 {
331     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
332     FIXME("stub %p\n",This);
333     return E_NOTIMPL;
334 }
335
336 static HRESULT WINAPI
337 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
338                REOBJECT *lpreobject, DWORD dwFlags)
339 {
340     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
341     FIXME("stub %p\n",This);
342     return E_NOTIMPL;
343 }
344
345 static LONG WINAPI
346 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
347 {
348     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
349     FIXME("stub %p\n",This);
350     return 0;
351 }
352
353 static HRESULT WINAPI
354 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
355 {
356     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
357     FIXME("stub %p\n",This);
358     return E_NOTIMPL;
359 }
360
361 static HRESULT WINAPI
362 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
363                CLIPFORMAT cf, HGLOBAL hMetaPict)
364 {
365     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
366     FIXME("stub %p\n",This);
367     return E_NOTIMPL;
368 }
369
370 static HRESULT WINAPI
371 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
372 {
373     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
374     FIXME("stub %p\n",This);
375     return E_NOTIMPL;
376 }
377
378 static HRESULT WINAPI
379 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
380 {
381     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
382     TRACE("(%p,%p)\n", This, reo);
383
384     if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
385
386     ME_InsertOLEFromCursor(This->editor, reo, 0);
387     ME_CommitUndo(This->editor);
388     ME_UpdateRepaint(This->editor, FALSE);
389     return S_OK;
390 }
391
392 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
393                LPSTORAGE lpstg)
394 {
395     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
396     FIXME("stub %p\n",This);
397     return E_NOTIMPL;
398 }
399
400 static HRESULT WINAPI
401 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
402 {
403     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
404     FIXME("stub %p\n",This);
405     return E_NOTIMPL;
406 }
407
408 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
409                LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
410 {
411     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
412     FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
413     return E_NOTIMPL;
414 }
415
416 static HRESULT WINAPI
417 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
418 {
419     IRichEditOleImpl *This = impl_from_IRichEditOle(me);
420     FIXME("stub %p\n",This);
421     return E_NOTIMPL;
422 }
423
424 static const IRichEditOleVtbl revt = {
425     IRichEditOle_fnQueryInterface,
426     IRichEditOle_fnAddRef,
427     IRichEditOle_fnRelease,
428     IRichEditOle_fnGetClientSite,
429     IRichEditOle_fnGetObjectCount,
430     IRichEditOle_fnGetLinkCount,
431     IRichEditOle_fnGetObject,
432     IRichEditOle_fnInsertObject,
433     IRichEditOle_fnConvertObject,
434     IRichEditOle_fnActivateAs,
435     IRichEditOle_fnSetHostNames,
436     IRichEditOle_fnSetLinkAvailable,
437     IRichEditOle_fnSetDvaspect,
438     IRichEditOle_fnHandsOffStorage,
439     IRichEditOle_fnSaveCompleted,
440     IRichEditOle_fnInPlaceDeactivate,
441     IRichEditOle_fnContextSensitiveHelp,
442     IRichEditOle_fnGetClipboardData,
443     IRichEditOle_fnImportDataObject
444 };
445
446 static HRESULT WINAPI
447 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
448     void** ppvObject)
449 {
450     IRichEditOleImpl *This = impl_from_ITextDocument(me);
451     return IRichEditOle_fnQueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
452 }
453
454 static ULONG WINAPI
455 ITextDocument_fnAddRef(ITextDocument* me)
456 {
457     IRichEditOleImpl *This = impl_from_ITextDocument(me);
458     return IRichEditOle_fnAddRef(&This->IRichEditOle_iface);
459 }
460
461 static ULONG WINAPI
462 ITextDocument_fnRelease(ITextDocument* me)
463 {
464     IRichEditOleImpl *This = impl_from_ITextDocument(me);
465     return IRichEditOle_fnRelease(&This->IRichEditOle_iface);
466 }
467
468 static HRESULT WINAPI
469 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
470     UINT* pctinfo)
471 {
472     IRichEditOleImpl *This = impl_from_ITextDocument(me);
473     FIXME("stub %p\n",This);
474     return E_NOTIMPL;
475 }
476
477 static HRESULT WINAPI
478 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
479     ITypeInfo** ppTInfo)
480 {
481     IRichEditOleImpl *This = impl_from_ITextDocument(me);
482     FIXME("stub %p\n",This);
483     return E_NOTIMPL;
484 }
485
486 static HRESULT WINAPI
487 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
488     LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
489 {
490     IRichEditOleImpl *This = impl_from_ITextDocument(me);
491     FIXME("stub %p\n",This);
492     return E_NOTIMPL;
493 }
494
495 static HRESULT WINAPI
496 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
497     REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
498     VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
499 {
500     IRichEditOleImpl *This = impl_from_ITextDocument(me);
501     FIXME("stub %p\n",This);
502     return E_NOTIMPL;
503 }
504
505 static HRESULT WINAPI
506 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
507 {
508     IRichEditOleImpl *This = impl_from_ITextDocument(me);
509     FIXME("stub %p\n",This);
510     return E_NOTIMPL;
511 }
512
513 static HRESULT WINAPI
514 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
515 {
516     IRichEditOleImpl *This = impl_from_ITextDocument(me);
517     TRACE("(%p)\n", me);
518     *ppSel = &This->txtSel->ITextSelection_iface;
519     ITextSelection_AddRef(*ppSel);
520     return S_OK;
521 }
522
523 static HRESULT WINAPI
524 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
525 {
526     IRichEditOleImpl *This = impl_from_ITextDocument(me);
527     FIXME("stub %p\n",This);
528     return E_NOTIMPL;
529 }
530
531 static HRESULT WINAPI
532 ITextDocument_fnGetStoryRanges(ITextDocument* me,
533     ITextStoryRanges** ppStories)
534 {
535     IRichEditOleImpl *This = impl_from_ITextDocument(me);
536     FIXME("stub %p\n",This);
537     return E_NOTIMPL;
538 }
539
540 static HRESULT WINAPI
541 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
542 {
543     IRichEditOleImpl *This = impl_from_ITextDocument(me);
544     FIXME("stub %p\n",This);
545     return E_NOTIMPL;
546 }
547
548 static HRESULT WINAPI
549 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
550 {
551     IRichEditOleImpl *This = impl_from_ITextDocument(me);
552     FIXME("stub %p\n",This);
553     return E_NOTIMPL;
554 }
555
556 static HRESULT WINAPI
557 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
558 {
559     IRichEditOleImpl *This = impl_from_ITextDocument(me);
560     FIXME("stub %p\n",This);
561     return E_NOTIMPL;
562 }
563
564 static HRESULT WINAPI
565 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
566 {
567     IRichEditOleImpl *This = impl_from_ITextDocument(me);
568     FIXME("stub %p\n",This);
569     return E_NOTIMPL;
570 }
571
572 static HRESULT WINAPI
573 ITextDocument_fnNew(ITextDocument* me)
574 {
575     IRichEditOleImpl *This = impl_from_ITextDocument(me);
576     FIXME("stub %p\n",This);
577     return E_NOTIMPL;
578 }
579
580 static HRESULT WINAPI
581 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
582     LONG CodePage)
583 {
584     IRichEditOleImpl *This = impl_from_ITextDocument(me);
585     FIXME("stub %p\n",This);
586     return E_NOTIMPL;
587 }
588
589 static HRESULT WINAPI
590 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
591     LONG CodePage)
592 {
593     IRichEditOleImpl *This = impl_from_ITextDocument(me);
594     FIXME("stub %p\n",This);
595     return E_NOTIMPL;
596 }
597
598 static HRESULT WINAPI
599 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
600 {
601     IRichEditOleImpl *This = impl_from_ITextDocument(me);
602     FIXME("stub %p\n",This);
603     return E_NOTIMPL;
604 }
605
606 static HRESULT WINAPI
607 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
608 {
609     IRichEditOleImpl *This = impl_from_ITextDocument(me);
610     FIXME("stub %p\n",This);
611     return E_NOTIMPL;
612 }
613
614 static HRESULT WINAPI
615 ITextDocument_fnBeginEditCollection(ITextDocument* me)
616 {
617     IRichEditOleImpl *This = impl_from_ITextDocument(me);
618     FIXME("stub %p\n",This);
619     return E_NOTIMPL;
620 }
621
622 static HRESULT WINAPI
623 ITextDocument_fnEndEditCollection(ITextDocument* me)
624 {
625     IRichEditOleImpl *This = impl_from_ITextDocument(me);
626     FIXME("stub %p\n",This);
627     return E_NOTIMPL;
628 }
629
630 static HRESULT WINAPI
631 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
632 {
633     IRichEditOleImpl *This = impl_from_ITextDocument(me);
634     FIXME("stub %p\n",This);
635     return E_NOTIMPL;
636 }
637
638 static HRESULT WINAPI
639 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
640 {
641     IRichEditOleImpl *This = impl_from_ITextDocument(me);
642     FIXME("stub %p\n",This);
643     return E_NOTIMPL;
644 }
645
646 static HRESULT WINAPI
647 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
648     ITextRange** ppRange)
649 {
650     IRichEditOleImpl *This = impl_from_ITextDocument(me);
651     FIXME("stub %p\n",This);
652     return E_NOTIMPL;
653 }
654
655 static HRESULT WINAPI
656 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
657     ITextRange** ppRange)
658 {
659     IRichEditOleImpl *This = impl_from_ITextDocument(me);
660     FIXME("stub %p\n",This);
661     return E_NOTIMPL;
662 }
663
664 static const ITextDocumentVtbl tdvt = {
665     ITextDocument_fnQueryInterface,
666     ITextDocument_fnAddRef,
667     ITextDocument_fnRelease,
668     ITextDocument_fnGetTypeInfoCount,
669     ITextDocument_fnGetTypeInfo,
670     ITextDocument_fnGetIDsOfNames,
671     ITextDocument_fnInvoke,
672     ITextDocument_fnGetName,
673     ITextDocument_fnGetSelection,
674     ITextDocument_fnGetStoryCount,
675     ITextDocument_fnGetStoryRanges,
676     ITextDocument_fnGetSaved,
677     ITextDocument_fnSetSaved,
678     ITextDocument_fnGetDefaultTabStop,
679     ITextDocument_fnSetDefaultTabStop,
680     ITextDocument_fnNew,
681     ITextDocument_fnOpen,
682     ITextDocument_fnSave,
683     ITextDocument_fnFreeze,
684     ITextDocument_fnUnfreeze,
685     ITextDocument_fnBeginEditCollection,
686     ITextDocument_fnEndEditCollection,
687     ITextDocument_fnUndo,
688     ITextDocument_fnRedo,
689     ITextDocument_fnRange,
690     ITextDocument_fnRangeFromPoint
691 };
692
693 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
694 {
695     return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
696 }
697
698 static HRESULT WINAPI ITextSelection_fnQueryInterface(
699     ITextSelection *me,
700     REFIID riid,
701     void **ppvObj)
702 {
703     *ppvObj = NULL;
704     if (IsEqualGUID(riid, &IID_IUnknown)
705         || IsEqualGUID(riid, &IID_IDispatch)
706         || IsEqualGUID(riid, &IID_ITextRange)
707         || IsEqualGUID(riid, &IID_ITextSelection))
708     {
709         *ppvObj = me;
710         ITextSelection_AddRef(me);
711         return S_OK;
712     }
713
714     return E_NOINTERFACE;
715 }
716
717 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
718 {
719     ITextSelectionImpl *This = impl_from_ITextSelection(me);
720     return InterlockedIncrement(&This->ref);
721 }
722
723 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
724 {
725     ITextSelectionImpl *This = impl_from_ITextSelection(me);
726     ULONG ref = InterlockedDecrement(&This->ref);
727     if (ref == 0)
728         heap_free(This);
729     return ref;
730 }
731
732 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
733 {
734     ITextSelectionImpl *This = impl_from_ITextSelection(me);
735     if (!This->reOle)
736         return CO_E_RELEASED;
737
738     FIXME("not implemented\n");
739     return E_NOTIMPL;
740 }
741
742 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
743     ITypeInfo **ppTInfo)
744 {
745     ITextSelectionImpl *This = impl_from_ITextSelection(me);
746     if (!This->reOle)
747         return CO_E_RELEASED;
748
749     FIXME("not implemented\n");
750     return E_NOTIMPL;
751 }
752
753 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
754     LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
755 {
756     ITextSelectionImpl *This = impl_from_ITextSelection(me);
757     if (!This->reOle)
758         return CO_E_RELEASED;
759
760     FIXME("not implemented\n");
761     return E_NOTIMPL;
762 }
763
764 static HRESULT WINAPI ITextSelection_fnInvoke(
765     ITextSelection *me,
766     DISPID dispIdMember,
767     REFIID riid,
768     LCID lcid,
769     WORD wFlags,
770     DISPPARAMS *pDispParams,
771     VARIANT *pVarResult,
772     EXCEPINFO *pExcepInfo,
773     UINT *puArgErr)
774 {
775     FIXME("not implemented\n");
776     return E_NOTIMPL;
777 }
778
779 /*** ITextRange methods ***/
780 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
781 {
782     ITextSelectionImpl *This = impl_from_ITextSelection(me);
783     if (!This->reOle)
784         return CO_E_RELEASED;
785
786     FIXME("not implemented\n");
787     return E_NOTIMPL;
788 }
789
790 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
791 {
792     ITextSelectionImpl *This = impl_from_ITextSelection(me);
793     if (!This->reOle)
794         return CO_E_RELEASED;
795
796     FIXME("not implemented\n");
797     return E_NOTIMPL;
798 }
799
800 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
801 {
802     ITextSelectionImpl *This = impl_from_ITextSelection(me);
803     if (!This->reOle)
804         return CO_E_RELEASED;
805
806     FIXME("not implemented\n");
807     return E_NOTIMPL;
808 }
809
810 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
811 {
812     ITextSelectionImpl *This = impl_from_ITextSelection(me);
813     if (!This->reOle)
814         return CO_E_RELEASED;
815
816     FIXME("not implemented\n");
817     return E_NOTIMPL;
818 }
819
820 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
821 {
822     ITextSelectionImpl *This = impl_from_ITextSelection(me);
823     if (!This->reOle)
824         return CO_E_RELEASED;
825
826     FIXME("not implemented\n");
827     return E_NOTIMPL;
828 }
829
830 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)
831 {
832     ITextSelectionImpl *This = impl_from_ITextSelection(me);
833     if (!This->reOle)
834         return CO_E_RELEASED;
835
836     FIXME("not implemented\n");
837     return E_NOTIMPL;
838 }
839
840 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *pRange)
841 {
842     ITextSelectionImpl *This = impl_from_ITextSelection(me);
843     if (!This->reOle)
844         return CO_E_RELEASED;
845
846     FIXME("not implemented\n");
847     return E_NOTIMPL;
848 }
849
850 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
851 {
852     ITextSelectionImpl *This = impl_from_ITextSelection(me);
853     if (!This->reOle)
854         return CO_E_RELEASED;
855
856     FIXME("not implemented\n");
857     return E_NOTIMPL;
858 }
859
860 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst)
861 {
862     ITextSelectionImpl *This = impl_from_ITextSelection(me);
863     if (!This->reOle)
864         return CO_E_RELEASED;
865
866     FIXME("not implemented\n");
867     return E_NOTIMPL;
868 }
869
870 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
871 {
872     ITextSelectionImpl *This = impl_from_ITextSelection(me);
873     if (!This->reOle)
874         return CO_E_RELEASED;
875
876     FIXME("not implemented\n");
877     return E_NOTIMPL;
878 }
879
880 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
881 {
882     ITextSelectionImpl *This = impl_from_ITextSelection(me);
883     if (!This->reOle)
884         return CO_E_RELEASED;
885
886     FIXME("not implemented\n");
887     return E_NOTIMPL;
888 }
889
890 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **pFont)
891 {
892     ITextSelectionImpl *This = impl_from_ITextSelection(me);
893     if (!This->reOle)
894         return CO_E_RELEASED;
895
896     FIXME("not implemented\n");
897     return E_NOTIMPL;
898 }
899
900 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
901 {
902     ITextSelectionImpl *This = impl_from_ITextSelection(me);
903     if (!This->reOle)
904         return CO_E_RELEASED;
905
906     FIXME("not implemented\n");
907     return E_NOTIMPL;
908 }
909
910 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **ppPara)
911 {
912     ITextSelectionImpl *This = impl_from_ITextSelection(me);
913     if (!This->reOle)
914         return CO_E_RELEASED;
915
916     FIXME("not implemented\n");
917     return E_NOTIMPL;
918 }
919
920 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pPara)
921 {
922     ITextSelectionImpl *This = impl_from_ITextSelection(me);
923     if (!This->reOle)
924         return CO_E_RELEASED;
925
926     FIXME("not implemented\n");
927     return E_NOTIMPL;
928 }
929
930 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *pcch)
931 {
932     ITextSelectionImpl *This = impl_from_ITextSelection(me);
933     if (!This->reOle)
934         return CO_E_RELEASED;
935
936     FIXME("not implemented\n");
937     return E_NOTIMPL;
938 }
939
940 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pValue)
941 {
942     ITextSelectionImpl *This = impl_from_ITextSelection(me);
943     if (!This->reOle)
944         return CO_E_RELEASED;
945
946     FIXME("not implemented\n");
947     return E_NOTIMPL;
948 }
949
950 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
951 {
952     ITextSelectionImpl *This = impl_from_ITextSelection(me);
953     if (!This->reOle)
954         return CO_E_RELEASED;
955
956     FIXME("not implemented\n");
957     return E_NOTIMPL;
958 }
959
960 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
961 {
962     ITextSelectionImpl *This = impl_from_ITextSelection(me);
963     if (!This->reOle)
964         return CO_E_RELEASED;
965
966     FIXME("not implemented\n");
967     return E_NOTIMPL;
968 }
969
970 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
971 {
972     ITextSelectionImpl *This = impl_from_ITextSelection(me);
973     if (!This->reOle)
974         return CO_E_RELEASED;
975
976     FIXME("not implemented\n");
977     return E_NOTIMPL;
978 }
979
980 static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG Unit, LONG Index,
981     LONG Extend)
982 {
983     ITextSelectionImpl *This = impl_from_ITextSelection(me);
984     if (!This->reOle)
985         return CO_E_RELEASED;
986
987     FIXME("not implemented\n");
988     return E_NOTIMPL;
989 }
990
991 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActive, LONG cpOther)
992 {
993     ITextSelectionImpl *This = impl_from_ITextSelection(me);
994     if (!This->reOle)
995         return CO_E_RELEASED;
996
997     FIXME("not implemented\n");
998     return E_NOTIMPL;
999 }
1000
1001 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
1002 {
1003     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1004     if (!This->reOle)
1005         return CO_E_RELEASED;
1006
1007     FIXME("not implemented\n");
1008     return E_NOTIMPL;
1009 }
1010
1011 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)
1012 {
1013     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1014     if (!This->reOle)
1015         return CO_E_RELEASED;
1016
1017     FIXME("not implemented\n");
1018     return E_NOTIMPL;
1019 }
1020
1021 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb)
1022 {
1023     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1024     if (!This->reOle)
1025         return CO_E_RELEASED;
1026
1027     FIXME("not implemented\n");
1028     return E_NOTIMPL;
1029 }
1030
1031 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
1032 {
1033     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1034     if (!This->reOle)
1035         return CO_E_RELEASED;
1036
1037     FIXME("not implemented\n");
1038     return E_NOTIMPL;
1039 }
1040
1041 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG Unit, LONG Extend,
1042     LONG *pDelta)
1043 {
1044     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1045     if (!This->reOle)
1046         return CO_E_RELEASED;
1047
1048     FIXME("not implemented\n");
1049     return E_NOTIMPL;
1050 }
1051
1052 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG Extend,
1053     LONG *pDelta)
1054 {
1055     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1056     if (!This->reOle)
1057         return CO_E_RELEASED;
1058
1059     FIXME("not implemented\n");
1060     return E_NOTIMPL;
1061 }
1062
1063 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG Unit, LONG Count, LONG *pDelta)
1064 {
1065     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1066     if (!This->reOle)
1067         return CO_E_RELEASED;
1068
1069     FIXME("not implemented\n");
1070     return E_NOTIMPL;
1071 }
1072
1073 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG Unit, LONG Count,
1074     LONG *pDelta)
1075 {
1076     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1077     if (!This->reOle)
1078         return CO_E_RELEASED;
1079
1080     FIXME("not implemented\n");
1081     return E_NOTIMPL;
1082 }
1083
1084 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG Unit, LONG Count,
1085     LONG *pDelta)
1086 {
1087     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1088     if (!This->reOle)
1089         return CO_E_RELEASED;
1090
1091     FIXME("not implemented\n");
1092     return E_NOTIMPL;
1093 }
1094
1095 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1096     LONG *pDelta)
1097 {
1098     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1099     if (!This->reOle)
1100         return CO_E_RELEASED;
1101
1102     FIXME("not implemented\n");
1103     return E_NOTIMPL;
1104 }
1105
1106 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1107     LONG *pDelta)
1108 {
1109     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1110     if (!This->reOle)
1111         return CO_E_RELEASED;
1112
1113     FIXME("not implemented\n");
1114     return E_NOTIMPL;
1115 }
1116
1117 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1118     LONG *pDelta)
1119 {
1120     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1121     if (!This->reOle)
1122         return CO_E_RELEASED;
1123
1124     FIXME("not implemented\n");
1125     return E_NOTIMPL;
1126 }
1127
1128 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1129     LONG *pDelta)
1130 {
1131     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1132     if (!This->reOle)
1133         return CO_E_RELEASED;
1134
1135     FIXME("not implemented\n");
1136     return E_NOTIMPL;
1137 }
1138
1139 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1140     LONG *pDelta)
1141 {
1142     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1143     if (!This->reOle)
1144         return CO_E_RELEASED;
1145
1146     FIXME("not implemented\n");
1147     return E_NOTIMPL;
1148 }
1149
1150 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1151     LONG *pDelta)
1152 {
1153     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1154     if (!This->reOle)
1155         return CO_E_RELEASED;
1156
1157     FIXME("not implemented\n");
1158     return E_NOTIMPL;
1159 }
1160
1161 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR bstr, LONG cch, LONG Flags,
1162     LONG *pLength)
1163 {
1164     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1165     if (!This->reOle)
1166         return CO_E_RELEASED;
1167
1168     FIXME("not implemented\n");
1169     return E_NOTIMPL;
1170 }
1171
1172 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR bstr, LONG cch,
1173     LONG Flags, LONG *pLength)
1174 {
1175     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1176     if (!This->reOle)
1177         return CO_E_RELEASED;
1178
1179     FIXME("not implemented\n");
1180     return E_NOTIMPL;
1181 }
1182
1183 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR bstr, LONG cch,
1184     LONG Flags, LONG *pLength)
1185 {
1186     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1187     if (!This->reOle)
1188         return CO_E_RELEASED;
1189
1190     FIXME("not implemented\n");
1191     return E_NOTIMPL;
1192 }
1193
1194 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG Unit, LONG Count,
1195     LONG *pDelta)
1196 {
1197     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1198     if (!This->reOle)
1199         return CO_E_RELEASED;
1200
1201     FIXME("not implemented\n");
1202     return E_NOTIMPL;
1203 }
1204
1205 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *pVar)
1206 {
1207     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1208     if (!This->reOle)
1209         return CO_E_RELEASED;
1210
1211     FIXME("not implemented\n");
1212     return E_NOTIMPL;
1213 }
1214
1215 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *pVar)
1216 {
1217     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1218     if (!This->reOle)
1219         return CO_E_RELEASED;
1220
1221     FIXME("not implemented\n");
1222     return E_NOTIMPL;
1223 }
1224
1225 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *pVar, LONG Format)
1226 {
1227     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1228     if (!This->reOle)
1229         return CO_E_RELEASED;
1230
1231     FIXME("not implemented\n");
1232     return E_NOTIMPL;
1233 }
1234
1235 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *pVar, LONG Format,
1236     LONG *pb)
1237 {
1238     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1239     if (!This->reOle)
1240         return CO_E_RELEASED;
1241
1242     FIXME("not implemented\n");
1243     return E_NOTIMPL;
1244 }
1245
1246 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *pb)
1247 {
1248     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1249     if (!This->reOle)
1250         return CO_E_RELEASED;
1251
1252     FIXME("not implemented\n");
1253     return E_NOTIMPL;
1254 }
1255
1256 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG Type)
1257 {
1258     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1259     if (!This->reOle)
1260         return CO_E_RELEASED;
1261
1262     FIXME("not implemented\n");
1263     return E_NOTIMPL;
1264 }
1265
1266 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG Type, LONG *cx, LONG *cy)
1267 {
1268     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1269     if (!This->reOle)
1270         return CO_E_RELEASED;
1271
1272     FIXME("not implemented\n");
1273     return E_NOTIMPL;
1274 }
1275
1276 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG Type,
1277     LONG Extend)
1278 {
1279     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1280     if (!This->reOle)
1281         return CO_E_RELEASED;
1282
1283     FIXME("not implemented\n");
1284     return E_NOTIMPL;
1285 }
1286
1287 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG Value)
1288 {
1289     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1290     if (!This->reOle)
1291         return CO_E_RELEASED;
1292
1293     FIXME("not implemented\n");
1294     return E_NOTIMPL;
1295 }
1296
1297 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
1298 {
1299     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1300     if (!This->reOle)
1301         return CO_E_RELEASED;
1302
1303     FIXME("not implemented\n");
1304     return E_NOTIMPL;
1305 }
1306
1307 /*** ITextSelection methods ***/
1308 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags)
1309 {
1310     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1311     if (!This->reOle)
1312         return CO_E_RELEASED;
1313
1314     FIXME("not implemented\n");
1315     return E_NOTIMPL;
1316 }
1317
1318 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
1319 {
1320     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1321     if (!This->reOle)
1322         return CO_E_RELEASED;
1323
1324     FIXME("not implemented\n");
1325     return E_NOTIMPL;
1326 }
1327
1328 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *pType)
1329 {
1330     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1331     if (!This->reOle)
1332         return CO_E_RELEASED;
1333
1334     FIXME("not implemented\n");
1335     return E_NOTIMPL;
1336 }
1337
1338 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG Unit, LONG Count,
1339     LONG Extend, LONG *pDelta)
1340 {
1341     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1342     if (!This->reOle)
1343         return CO_E_RELEASED;
1344
1345     FIXME("not implemented\n");
1346     return E_NOTIMPL;
1347 }
1348
1349 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG Unit, LONG Count,
1350     LONG Extend, LONG *pDelta)
1351 {
1352     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1353     if (!This->reOle)
1354         return CO_E_RELEASED;
1355
1356     FIXME("not implemented\n");
1357     return E_NOTIMPL;
1358 }
1359
1360 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG Unit, LONG Count,
1361     LONG Extend, LONG *pDelta)
1362 {
1363     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1364     if (!This->reOle)
1365         return CO_E_RELEASED;
1366
1367     FIXME("not implemented\n");
1368     return E_NOTIMPL;
1369 }
1370
1371 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG Unit, LONG Count,
1372     LONG Extend, LONG *pDelta)
1373 {
1374     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1375     if (!This->reOle)
1376         return CO_E_RELEASED;
1377
1378     FIXME("not implemented\n");
1379     return E_NOTIMPL;
1380 }
1381
1382 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG Unit, LONG Extend,
1383     LONG *pDelta)
1384 {
1385     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1386     if (!This->reOle)
1387         return CO_E_RELEASED;
1388
1389     FIXME("not implemented\n");
1390     return E_NOTIMPL;
1391 }
1392
1393 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LONG Extend,
1394     LONG *pDelta)
1395 {
1396     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1397     if (!This->reOle)
1398         return CO_E_RELEASED;
1399
1400     FIXME("not implemented\n");
1401     return E_NOTIMPL;
1402 }
1403
1404 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR bstr)
1405 {
1406     ITextSelectionImpl *This = impl_from_ITextSelection(me);
1407     if (!This->reOle)
1408         return CO_E_RELEASED;
1409
1410     FIXME("not implemented\n");
1411     return E_NOTIMPL;
1412 }
1413
1414 static const ITextSelectionVtbl tsvt = {
1415     ITextSelection_fnQueryInterface,
1416     ITextSelection_fnAddRef,
1417     ITextSelection_fnRelease,
1418     ITextSelection_fnGetTypeInfoCount,
1419     ITextSelection_fnGetTypeInfo,
1420     ITextSelection_fnGetIDsOfNames,
1421     ITextSelection_fnInvoke,
1422     ITextSelection_fnGetText,
1423     ITextSelection_fnSetText,
1424     ITextSelection_fnGetChar,
1425     ITextSelection_fnSetChar,
1426     ITextSelection_fnGetDuplicate,
1427     ITextSelection_fnGetFormattedText,
1428     ITextSelection_fnSetFormattedText,
1429     ITextSelection_fnGetStart,
1430     ITextSelection_fnSetStart,
1431     ITextSelection_fnGetEnd,
1432     ITextSelection_fnSetEnd,
1433     ITextSelection_fnGetFont,
1434     ITextSelection_fnSetFont,
1435     ITextSelection_fnGetPara,
1436     ITextSelection_fnSetPara,
1437     ITextSelection_fnGetStoryLength,
1438     ITextSelection_fnGetStoryType,
1439     ITextSelection_fnCollapse,
1440     ITextSelection_fnExpand,
1441     ITextSelection_fnGetIndex,
1442     ITextSelection_fnSetIndex,
1443     ITextSelection_fnSetRange,
1444     ITextSelection_fnInRange,
1445     ITextSelection_fnInStory,
1446     ITextSelection_fnIsEqual,
1447     ITextSelection_fnSelect,
1448     ITextSelection_fnStartOf,
1449     ITextSelection_fnEndOf,
1450     ITextSelection_fnMove,
1451     ITextSelection_fnMoveStart,
1452     ITextSelection_fnMoveEnd,
1453     ITextSelection_fnMoveWhile,
1454     ITextSelection_fnMoveStartWhile,
1455     ITextSelection_fnMoveEndWhile,
1456     ITextSelection_fnMoveUntil,
1457     ITextSelection_fnMoveStartUntil,
1458     ITextSelection_fnMoveEndUntil,
1459     ITextSelection_fnFindText,
1460     ITextSelection_fnFindTextStart,
1461     ITextSelection_fnFindTextEnd,
1462     ITextSelection_fnDelete,
1463     ITextSelection_fnCut,
1464     ITextSelection_fnCopy,
1465     ITextSelection_fnPaste,
1466     ITextSelection_fnCanPaste,
1467     ITextSelection_fnCanEdit,
1468     ITextSelection_fnChangeCase,
1469     ITextSelection_fnGetPoint,
1470     ITextSelection_fnSetPoint,
1471     ITextSelection_fnScrollIntoView,
1472     ITextSelection_fnGetEmbeddedObject,
1473     ITextSelection_fnGetFlags,
1474     ITextSelection_fnSetFlags,
1475     ITextSelection_fnGetType,
1476     ITextSelection_fnMoveLeft,
1477     ITextSelection_fnMoveRight,
1478     ITextSelection_fnMoveUp,
1479     ITextSelection_fnMoveDown,
1480     ITextSelection_fnHomeKey,
1481     ITextSelection_fnEndKey,
1482     ITextSelection_fnTypeText
1483 };
1484
1485 static ITextSelectionImpl *
1486 CreateTextSelection(IRichEditOleImpl *reOle)
1487 {
1488     ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
1489     if (!txtSel)
1490         return NULL;
1491
1492     txtSel->ITextSelection_iface.lpVtbl = &tsvt;
1493     txtSel->ref = 1;
1494     txtSel->reOle = reOle;
1495     return txtSel;
1496 }
1497
1498 LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
1499 {
1500     IRichEditOleImpl *reo;
1501
1502     reo = heap_alloc(sizeof(IRichEditOleImpl));
1503     if (!reo)
1504         return 0;
1505
1506     reo->IRichEditOle_iface.lpVtbl = &revt;
1507     reo->ITextDocument_iface.lpVtbl = &tdvt;
1508     reo->ref = 1;
1509     reo->editor = editor;
1510     reo->txtSel = CreateTextSelection(reo);
1511     if (!reo->txtSel)
1512     {
1513         heap_free(reo);
1514         return 0;
1515     }
1516     reo->clientSite = CreateOleClientSite(reo);
1517     if (!reo->txtSel)
1518     {
1519         ITextSelection_Release(&reo->txtSel->ITextSelection_iface);
1520         heap_free(reo);
1521         return 0;
1522     }
1523     TRACE("Created %p\n",reo);
1524     *ppObj = reo;
1525
1526     return 1;
1527 }
1528
1529 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
1530 {
1531   /* sizel is in .01 millimeters, sz in pixels */
1532   sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
1533   sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
1534 }
1535
1536 /******************************************************************************
1537  * ME_GetOLEObjectSize
1538  *
1539  * Sets run extent for OLE objects.
1540  */
1541 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
1542 {
1543   IDataObject*  ido;
1544   FORMATETC     fmt;
1545   STGMEDIUM     stgm;
1546   DIBSECTION    dibsect;
1547   ENHMETAHEADER emh;
1548
1549   assert(run->nFlags & MERF_GRAPHICS);
1550   assert(run->ole_obj);
1551
1552   if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
1553   {
1554     convert_sizel(c, &run->ole_obj->sizel, pSize);
1555     if (c->editor->nZoomNumerator != 0)
1556     {
1557       pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1558       pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1559     }
1560     return;
1561   }
1562
1563   IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido);
1564   fmt.cfFormat = CF_BITMAP;
1565   fmt.ptd = NULL;
1566   fmt.dwAspect = DVASPECT_CONTENT;
1567   fmt.lindex = -1;
1568   fmt.tymed = TYMED_GDI;
1569   if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
1570   {
1571     fmt.cfFormat = CF_ENHMETAFILE;
1572     fmt.tymed = TYMED_ENHMF;
1573     if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
1574     {
1575       FIXME("unsupported format\n");
1576       pSize->cx = pSize->cy = 0;
1577       IDataObject_Release(ido);
1578       return;
1579     }
1580   }
1581
1582   switch (stgm.tymed)
1583   {
1584   case TYMED_GDI:
1585     GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
1586     pSize->cx = dibsect.dsBm.bmWidth;
1587     pSize->cy = dibsect.dsBm.bmHeight;
1588     if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
1589     break;
1590   case TYMED_ENHMF:
1591     GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
1592     pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
1593     pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
1594     if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
1595     break;
1596   default:
1597     FIXME("Unsupported tymed %d\n", stgm.tymed);
1598     break;
1599   }
1600   IDataObject_Release(ido);
1601   if (c->editor->nZoomNumerator != 0)
1602   {
1603     pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1604     pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1605   }
1606 }
1607
1608 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
1609                 ME_Paragraph *para, BOOL selected)
1610 {
1611   IDataObject*  ido;
1612   FORMATETC     fmt;
1613   STGMEDIUM     stgm;
1614   DIBSECTION    dibsect;
1615   ENHMETAHEADER emh;
1616   HDC           hMemDC;
1617   SIZE          sz;
1618   BOOL          has_size;
1619
1620   assert(run->nFlags & MERF_GRAPHICS);
1621   assert(run->ole_obj);
1622   if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
1623   {
1624     FIXME("Couldn't get interface\n");
1625     return;
1626   }
1627   has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
1628   fmt.cfFormat = CF_BITMAP;
1629   fmt.ptd = NULL;
1630   fmt.dwAspect = DVASPECT_CONTENT;
1631   fmt.lindex = -1;
1632   fmt.tymed = TYMED_GDI;
1633   if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
1634   {
1635     fmt.cfFormat = CF_ENHMETAFILE;
1636     fmt.tymed = TYMED_ENHMF;
1637     if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
1638     {
1639       FIXME("Couldn't get storage medium\n");
1640       IDataObject_Release(ido);
1641       return;
1642     }
1643   }
1644   switch (stgm.tymed)
1645   {
1646   case TYMED_GDI:
1647     GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
1648     hMemDC = CreateCompatibleDC(c->hDC);
1649     SelectObject(hMemDC, stgm.u.hBitmap);
1650     if (has_size)
1651     {
1652       convert_sizel(c, &run->ole_obj->sizel, &sz);
1653     } else {
1654       sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
1655       sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
1656     }
1657     if (c->editor->nZoomNumerator != 0)
1658     {
1659       sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1660       sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1661     }
1662     if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
1663     {
1664       BitBlt(c->hDC, x, y - sz.cy,
1665              dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
1666              hMemDC, 0, 0, SRCCOPY);
1667     } else {
1668       StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
1669                  hMemDC, 0, 0, dibsect.dsBm.bmWidth,
1670                  dibsect.dsBm.bmHeight, SRCCOPY);
1671     }
1672     DeleteDC(hMemDC);
1673     if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
1674     break;
1675   case TYMED_ENHMF:
1676     GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
1677     if (has_size)
1678     {
1679       convert_sizel(c, &run->ole_obj->sizel, &sz);
1680     } else {
1681       sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
1682       sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
1683     }
1684     if (c->editor->nZoomNumerator != 0)
1685     {
1686       sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1687       sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1688     }
1689
1690     {
1691       RECT    rc;
1692
1693       rc.left = x;
1694       rc.top = y - sz.cy;
1695       rc.right = x + sz.cx;
1696       rc.bottom = y;
1697       PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
1698     }
1699     if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
1700     break;
1701   default:
1702     FIXME("Unsupported tymed %d\n", stgm.tymed);
1703     selected = FALSE;
1704     break;
1705   }
1706   if (selected && !c->editor->bHideSelection)
1707     PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
1708   IDataObject_Release(ido);
1709 }
1710
1711 void ME_DeleteReObject(REOBJECT* reo)
1712 {
1713     if (reo->poleobj)   IOleObject_Release(reo->poleobj);
1714     if (reo->pstg)      IStorage_Release(reo->pstg);
1715     if (reo->polesite)  IOleClientSite_Release(reo->polesite);
1716     FREE_OBJ(reo);
1717 }
1718
1719 void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
1720 {
1721     *dst = *src;
1722
1723     if (dst->poleobj)   IOleObject_AddRef(dst->poleobj);
1724     if (dst->pstg)      IStorage_AddRef(dst->pstg);
1725     if (dst->polesite)  IOleClientSite_AddRef(dst->polesite);
1726 }