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