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