riched20: Implement ITextRange::GetChar.
[wine.git] / dlls / riched20 / richole.c
blob6a00016493700e12e56da46a6d7de0f7936b37ff
1 /*
2 * RichEdit GUIDs and OLE interface
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2004 Aric Stewart
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.
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.
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
22 #include <stdarg.h>
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #define COBJMACROS
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"
38 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
40 /* there is no way to be consistent across different sets of headers - mingw, Wine, Win32 SDK*/
42 #include "initguid.h"
43 DEFINE_GUID(IID_ITextServices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
44 DEFINE_GUID(IID_ITextHost, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
45 DEFINE_GUID(IID_ITextHost2, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
46 DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
47 DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
48 DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
50 typedef struct ITextSelectionImpl ITextSelectionImpl;
51 typedef struct IOleClientSiteImpl IOleClientSiteImpl;
52 typedef struct ITextRangeImpl ITextRangeImpl;
54 typedef struct IRichEditOleImpl {
55 IRichEditOle IRichEditOle_iface;
56 ITextDocument ITextDocument_iface;
57 LONG ref;
59 ME_TextEditor *editor;
60 ITextSelectionImpl *txtSel;
61 IOleClientSiteImpl *clientSite;
62 struct list rangelist;
63 } IRichEditOleImpl;
65 struct ITextRangeImpl {
66 ITextRange ITextRange_iface;
67 LONG ref;
68 LONG start, end;
69 struct list entry;
71 IRichEditOleImpl *reOle;
74 struct ITextSelectionImpl {
75 ITextSelection ITextSelection_iface;
76 LONG ref;
78 IRichEditOleImpl *reOle;
81 struct IOleClientSiteImpl {
82 IOleClientSite IOleClientSite_iface;
83 LONG ref;
85 IRichEditOleImpl *reOle;
88 static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
90 return CONTAINING_RECORD(iface, IRichEditOleImpl, IRichEditOle_iface);
93 static inline IRichEditOleImpl *impl_from_ITextDocument(ITextDocument *iface)
95 return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument_iface);
98 static HRESULT WINAPI
99 IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
101 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
103 TRACE("%p %s\n", This, debugstr_guid(riid) );
105 *ppvObj = NULL;
106 if (IsEqualGUID(riid, &IID_IUnknown) ||
107 IsEqualGUID(riid, &IID_IRichEditOle))
108 *ppvObj = &This->IRichEditOle_iface;
109 else if (IsEqualGUID(riid, &IID_ITextDocument))
110 *ppvObj = &This->ITextDocument_iface;
111 if (*ppvObj)
113 IRichEditOle_AddRef(me);
114 return S_OK;
116 FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid) );
118 return E_NOINTERFACE;
121 static ULONG WINAPI
122 IRichEditOle_fnAddRef(IRichEditOle *me)
124 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
125 ULONG ref = InterlockedIncrement( &This->ref );
127 TRACE("%p ref = %u\n", This, ref);
129 return ref;
132 static ULONG WINAPI
133 IRichEditOle_fnRelease(IRichEditOle *me)
135 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
136 ULONG ref = InterlockedDecrement(&This->ref);
138 TRACE ("%p ref=%u\n", This, ref);
140 if (!ref)
142 ITextRangeImpl *txtRge;
143 TRACE ("Destroying %p\n", This);
144 This->txtSel->reOle = NULL;
145 ITextSelection_Release(&This->txtSel->ITextSelection_iface);
146 IOleClientSite_Release(&This->clientSite->IOleClientSite_iface);
147 LIST_FOR_EACH_ENTRY(txtRge, &This->rangelist, ITextRangeImpl, entry)
148 txtRge->reOle = NULL;
149 heap_free(This);
151 return ref;
154 static HRESULT WINAPI
155 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
157 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
158 FIXME("stub %p\n",This);
159 return E_NOTIMPL;
162 static HRESULT WINAPI
163 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
165 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
166 FIXME("stub %p\n",This);
167 return E_NOTIMPL;
170 static HRESULT WINAPI
171 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
172 REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
174 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
175 FIXME("stub %p\n",This);
176 return E_NOTIMPL;
179 static inline IOleClientSiteImpl *impl_from_IOleClientSite(IOleClientSite *iface)
181 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleClientSite_iface);
184 static HRESULT WINAPI
185 IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
187 TRACE("%p %s\n", me, debugstr_guid(riid) );
189 *ppvObj = NULL;
190 if (IsEqualGUID(riid, &IID_IUnknown) ||
191 IsEqualGUID(riid, &IID_IOleClientSite))
192 *ppvObj = me;
193 if (*ppvObj)
195 IOleClientSite_AddRef(me);
196 return S_OK;
198 FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );
200 return E_NOINTERFACE;
203 static ULONG WINAPI IOleClientSite_fnAddRef(IOleClientSite *iface)
205 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
206 return InterlockedIncrement(&This->ref);
209 static ULONG WINAPI IOleClientSite_fnRelease(IOleClientSite *iface)
211 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
212 ULONG ref = InterlockedDecrement(&This->ref);
213 if (ref == 0)
214 heap_free(This);
215 return ref;
218 static HRESULT WINAPI IOleClientSite_fnSaveObject(IOleClientSite *iface)
220 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
221 if (!This->reOle)
222 return CO_E_RELEASED;
224 FIXME("stub %p\n", iface);
225 return E_NOTIMPL;
229 static HRESULT WINAPI IOleClientSite_fnGetMoniker(IOleClientSite *iface, DWORD dwAssign,
230 DWORD dwWhichMoniker, IMoniker **ppmk)
232 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
233 if (!This->reOle)
234 return CO_E_RELEASED;
236 FIXME("stub %p\n", iface);
237 return E_NOTIMPL;
240 static HRESULT WINAPI IOleClientSite_fnGetContainer(IOleClientSite *iface,
241 IOleContainer **ppContainer)
243 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
244 if (!This->reOle)
245 return CO_E_RELEASED;
247 FIXME("stub %p\n", iface);
248 return E_NOTIMPL;
251 static HRESULT WINAPI IOleClientSite_fnShowObject(IOleClientSite *iface)
253 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
254 if (!This->reOle)
255 return CO_E_RELEASED;
257 FIXME("stub %p\n", iface);
258 return E_NOTIMPL;
261 static HRESULT WINAPI IOleClientSite_fnOnShowWindow(IOleClientSite *iface, BOOL fShow)
263 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
264 if (!This->reOle)
265 return CO_E_RELEASED;
267 FIXME("stub %p\n", iface);
268 return E_NOTIMPL;
271 static HRESULT WINAPI IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *iface)
273 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
274 if (!This->reOle)
275 return CO_E_RELEASED;
277 FIXME("stub %p\n", iface);
278 return E_NOTIMPL;
281 static const IOleClientSiteVtbl ocst = {
282 IOleClientSite_fnQueryInterface,
283 IOleClientSite_fnAddRef,
284 IOleClientSite_fnRelease,
285 IOleClientSite_fnSaveObject,
286 IOleClientSite_fnGetMoniker,
287 IOleClientSite_fnGetContainer,
288 IOleClientSite_fnShowObject,
289 IOleClientSite_fnOnShowWindow,
290 IOleClientSite_fnRequestNewObjectLayout
293 static IOleClientSiteImpl *
294 CreateOleClientSite(IRichEditOleImpl *reOle)
296 IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
297 if (!clientSite)
298 return NULL;
300 clientSite->IOleClientSite_iface.lpVtbl = &ocst;
301 clientSite->ref = 1;
302 clientSite->reOle = reOle;
303 return clientSite;
306 static HRESULT WINAPI
307 IRichEditOle_fnGetClientSite(IRichEditOle *me,
308 LPOLECLIENTSITE *lplpolesite)
310 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
312 TRACE("%p,%p\n",This, lplpolesite);
314 if(!lplpolesite)
315 return E_INVALIDARG;
316 *lplpolesite = &This->clientSite->IOleClientSite_iface;
317 IOleClientSite_AddRef(*lplpolesite);
318 return S_OK;
321 static HRESULT WINAPI
322 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
323 DWORD reco, LPDATAOBJECT *lplpdataobj)
325 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
326 ME_Cursor start;
327 int nChars;
329 TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
330 if(!lplpdataobj)
331 return E_INVALIDARG;
332 if(!lpchrg) {
333 int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
334 start = This->editor->pCursors[nStartCur];
335 nChars = nTo - nFrom;
336 } else {
337 ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
338 nChars = lpchrg->cpMax - lpchrg->cpMin;
340 return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
343 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
345 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
346 FIXME("stub %p\n",This);
347 return E_NOTIMPL;
350 static HRESULT WINAPI
351 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
352 REOBJECT *lpreobject, DWORD dwFlags)
354 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
355 FIXME("stub %p\n",This);
356 return E_NOTIMPL;
359 static LONG WINAPI
360 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
362 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
363 FIXME("stub %p\n",This);
364 return 0;
367 static HRESULT WINAPI
368 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
370 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
371 FIXME("stub %p\n",This);
372 return E_NOTIMPL;
375 static HRESULT WINAPI
376 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
377 CLIPFORMAT cf, HGLOBAL hMetaPict)
379 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
380 FIXME("stub %p\n",This);
381 return E_NOTIMPL;
384 static HRESULT WINAPI
385 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
387 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
388 FIXME("stub %p\n",This);
389 return E_NOTIMPL;
392 static HRESULT WINAPI
393 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
395 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
396 TRACE("(%p,%p)\n", This, reo);
398 if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
400 ME_InsertOLEFromCursor(This->editor, reo, 0);
401 ME_CommitUndo(This->editor);
402 ME_UpdateRepaint(This->editor, FALSE);
403 return S_OK;
406 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
407 LPSTORAGE lpstg)
409 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
410 FIXME("stub %p\n",This);
411 return E_NOTIMPL;
414 static HRESULT WINAPI
415 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
417 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
418 FIXME("stub %p\n",This);
419 return E_NOTIMPL;
422 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
423 LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
425 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
426 FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
427 return E_NOTIMPL;
430 static HRESULT WINAPI
431 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
433 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
434 FIXME("stub %p\n",This);
435 return E_NOTIMPL;
438 static const IRichEditOleVtbl revt = {
439 IRichEditOle_fnQueryInterface,
440 IRichEditOle_fnAddRef,
441 IRichEditOle_fnRelease,
442 IRichEditOle_fnGetClientSite,
443 IRichEditOle_fnGetObjectCount,
444 IRichEditOle_fnGetLinkCount,
445 IRichEditOle_fnGetObject,
446 IRichEditOle_fnInsertObject,
447 IRichEditOle_fnConvertObject,
448 IRichEditOle_fnActivateAs,
449 IRichEditOle_fnSetHostNames,
450 IRichEditOle_fnSetLinkAvailable,
451 IRichEditOle_fnSetDvaspect,
452 IRichEditOle_fnHandsOffStorage,
453 IRichEditOle_fnSaveCompleted,
454 IRichEditOle_fnInPlaceDeactivate,
455 IRichEditOle_fnContextSensitiveHelp,
456 IRichEditOle_fnGetClipboardData,
457 IRichEditOle_fnImportDataObject
460 /* ITextRange interface */
461 static inline ITextRangeImpl *impl_from_ITextRange(ITextRange *iface)
463 return CONTAINING_RECORD(iface, ITextRangeImpl, ITextRange_iface);
466 static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
468 *ppvObj = NULL;
469 if (IsEqualGUID(riid, &IID_IUnknown)
470 || IsEqualGUID(riid, &IID_IDispatch)
471 || IsEqualGUID(riid, &IID_ITextRange))
473 *ppvObj = me;
474 ITextRange_AddRef(me);
475 return S_OK;
478 return E_NOINTERFACE;
481 static ULONG WINAPI ITextRange_fnAddRef(ITextRange *me)
483 ITextRangeImpl *This = impl_from_ITextRange(me);
484 return InterlockedIncrement(&This->ref);
487 static ULONG WINAPI ITextRange_fnRelease(ITextRange *me)
489 ITextRangeImpl *This = impl_from_ITextRange(me);
490 ULONG ref = InterlockedDecrement(&This->ref);
492 TRACE ("%p ref=%u\n", This, ref);
493 if (ref == 0)
495 if (This->reOle)
497 list_remove(&This->entry);
498 This->reOle = NULL;
500 heap_free(This);
502 return ref;
505 static HRESULT WINAPI ITextRange_fnGetTypeInfoCount(ITextRange *me, UINT *pctinfo)
507 ITextRangeImpl *This = impl_from_ITextRange(me);
508 if (!This->reOle)
509 return CO_E_RELEASED;
511 FIXME("not implemented %p\n", This);
512 return E_NOTIMPL;
515 static HRESULT WINAPI ITextRange_fnGetTypeInfo(ITextRange *me, UINT iTInfo, LCID lcid,
516 ITypeInfo **ppTInfo)
518 ITextRangeImpl *This = impl_from_ITextRange(me);
519 if (!This->reOle)
520 return CO_E_RELEASED;
522 FIXME("not implemented %p\n", This);
523 return E_NOTIMPL;
526 static HRESULT WINAPI ITextRange_fnGetIDsOfNames(ITextRange *me, REFIID riid, LPOLESTR *rgszNames,
527 UINT cNames, LCID lcid, DISPID *rgDispId)
529 ITextRangeImpl *This = impl_from_ITextRange(me);
530 if (!This->reOle)
531 return CO_E_RELEASED;
533 FIXME("not implemented %p\n", This);
534 return E_NOTIMPL;
537 static HRESULT WINAPI ITextRange_fnInvoke(ITextRange *me, DISPID dispIdMember, REFIID riid,
538 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
539 VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
540 UINT *puArgErr)
542 ITextRangeImpl *This = impl_from_ITextRange(me);
543 if (!This->reOle)
544 return CO_E_RELEASED;
546 FIXME("not implemented %p\n", This);
547 return E_NOTIMPL;
550 static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *pbstr)
552 ITextRangeImpl *This = impl_from_ITextRange(me);
553 if (!This->reOle)
554 return CO_E_RELEASED;
556 FIXME("not implemented %p\n", This);
557 return E_NOTIMPL;
560 static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR bstr)
562 ITextRangeImpl *This = impl_from_ITextRange(me);
563 if (!This->reOle)
564 return CO_E_RELEASED;
566 FIXME("not implemented %p\n", This);
567 return E_NOTIMPL;
570 static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch)
572 WCHAR wch[2];
574 ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, cursor->pRun->next->type == diTextEnd);
575 *pch = wch[0];
577 return S_OK;
580 static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
582 ITextRangeImpl *This = impl_from_ITextRange(me);
583 ME_Cursor cursor;
585 if (!This->reOle)
586 return CO_E_RELEASED;
587 TRACE("%p\n", pch);
588 if (!pch)
589 return E_INVALIDARG;
591 ME_CursorFromCharOfs(This->reOle->editor, This->start, &cursor);
592 return range_GetChar(This->reOle->editor, &cursor, pch);
595 static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch)
597 ITextRangeImpl *This = impl_from_ITextRange(me);
598 if (!This->reOle)
599 return CO_E_RELEASED;
601 FIXME("not implemented %p\n", This);
602 return E_NOTIMPL;
605 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
607 ITextRangeImpl *This = impl_from_ITextRange(me);
608 if (!This->reOle)
609 return CO_E_RELEASED;
611 FIXME("not implemented %p\n", This);
612 return E_NOTIMPL;
615 static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **ppRange)
617 ITextRangeImpl *This = impl_from_ITextRange(me);
618 if (!This->reOle)
619 return CO_E_RELEASED;
621 FIXME("not implemented %p\n", This);
622 return E_NOTIMPL;
625 static HRESULT WINAPI ITextRange_fnSetFormattedText(ITextRange *me, ITextRange *pRange)
627 ITextRangeImpl *This = impl_from_ITextRange(me);
628 if (!This->reOle)
629 return CO_E_RELEASED;
631 FIXME("not implemented %p\n", This);
632 return E_NOTIMPL;
635 static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *pcpFirst)
637 ITextRangeImpl *This = impl_from_ITextRange(me);
638 if (!This->reOle)
639 return CO_E_RELEASED;
641 FIXME("not implemented %p\n", This);
642 return E_NOTIMPL;
645 static HRESULT WINAPI ITextRange_fnSetStart(ITextRange *me, LONG cpFirst)
647 ITextRangeImpl *This = impl_from_ITextRange(me);
648 if (!This->reOle)
649 return CO_E_RELEASED;
651 FIXME("not implemented %p\n", This);
652 return E_NOTIMPL;
655 static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *pcpLim)
657 ITextRangeImpl *This = impl_from_ITextRange(me);
658 if (!This->reOle)
659 return CO_E_RELEASED;
661 FIXME("not implemented %p\n", This);
662 return E_NOTIMPL;
665 static HRESULT WINAPI ITextRange_fnSetEnd(ITextRange *me, LONG cpLim)
667 ITextRangeImpl *This = impl_from_ITextRange(me);
668 if (!This->reOle)
669 return CO_E_RELEASED;
671 FIXME("not implemented %p\n", This);
672 return E_NOTIMPL;
675 static HRESULT WINAPI ITextRange_fnGetFont(ITextRange *me, ITextFont **pFont)
677 ITextRangeImpl *This = impl_from_ITextRange(me);
678 if (!This->reOle)
679 return CO_E_RELEASED;
681 FIXME("not implemented %p\n", This);
682 return E_NOTIMPL;
685 static HRESULT WINAPI ITextRange_fnSetFont(ITextRange *me, ITextFont *pFont)
687 ITextRangeImpl *This = impl_from_ITextRange(me);
688 if (!This->reOle)
689 return CO_E_RELEASED;
691 FIXME("not implemented %p\n", This);
692 return E_NOTIMPL;
695 static HRESULT WINAPI ITextRange_fnGetPara(ITextRange *me, ITextPara **ppPara)
697 ITextRangeImpl *This = impl_from_ITextRange(me);
698 if (!This->reOle)
699 return CO_E_RELEASED;
701 FIXME("not implemented %p\n", This);
702 return E_NOTIMPL;
705 static HRESULT WINAPI ITextRange_fnSetPara(ITextRange *me, ITextPara *pPara)
707 ITextRangeImpl *This = impl_from_ITextRange(me);
708 if (!This->reOle)
709 return CO_E_RELEASED;
711 FIXME("not implemented %p\n", This);
712 return E_NOTIMPL;
715 static HRESULT WINAPI ITextRange_fnGetStoryLength(ITextRange *me, LONG *pcch)
717 ITextRangeImpl *This = impl_from_ITextRange(me);
718 if (!This->reOle)
719 return CO_E_RELEASED;
721 FIXME("not implemented %p\n", This);
722 return E_NOTIMPL;
725 static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *pValue)
727 ITextRangeImpl *This = impl_from_ITextRange(me);
728 if (!This->reOle)
729 return CO_E_RELEASED;
731 FIXME("not implemented %p\n", This);
732 return E_NOTIMPL;
735 static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
737 ITextRangeImpl *This = impl_from_ITextRange(me);
738 if (!This->reOle)
739 return CO_E_RELEASED;
741 FIXME("not implemented %p\n", This);
742 return E_NOTIMPL;
745 static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG Unit, LONG *pDelta)
747 ITextRangeImpl *This = impl_from_ITextRange(me);
748 if (!This->reOle)
749 return CO_E_RELEASED;
751 FIXME("not implemented %p\n", This);
752 return E_NOTIMPL;
755 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG Unit, LONG *pIndex)
757 ITextRangeImpl *This = impl_from_ITextRange(me);
758 if (!This->reOle)
759 return CO_E_RELEASED;
761 FIXME("not implemented %p\n", This);
762 return E_NOTIMPL;
765 static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG Unit, LONG Index,
766 LONG Extend)
768 ITextRangeImpl *This = impl_from_ITextRange(me);
769 if (!This->reOle)
770 return CO_E_RELEASED;
772 FIXME("not implemented %p\n", This);
773 return E_NOTIMPL;
776 static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG cpActive, LONG cpOther)
778 ITextRangeImpl *This = impl_from_ITextRange(me);
779 if (!This->reOle)
780 return CO_E_RELEASED;
782 FIXME("not implemented %p\n", This);
783 return E_NOTIMPL;
786 static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *pRange, LONG *pb)
788 ITextRangeImpl *This = impl_from_ITextRange(me);
789 if (!This->reOle)
790 return CO_E_RELEASED;
792 FIXME("not implemented %p\n", This);
793 return E_NOTIMPL;
796 static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *pb)
798 ITextRangeImpl *This = impl_from_ITextRange(me);
799 if (!This->reOle)
800 return CO_E_RELEASED;
802 FIXME("not implemented %p\n", This);
803 return E_NOTIMPL;
806 static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *pRange, LONG *pb)
808 ITextRangeImpl *This = impl_from_ITextRange(me);
809 if (!This->reOle)
810 return CO_E_RELEASED;
812 FIXME("not implemented %p\n", This);
813 return E_NOTIMPL;
816 static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me)
818 ITextRangeImpl *This = impl_from_ITextRange(me);
819 if (!This->reOle)
820 return CO_E_RELEASED;
822 FIXME("not implemented %p\n", This);
823 return E_NOTIMPL;
826 static HRESULT WINAPI ITextRange_fnStartOf(ITextRange *me, LONG Unit, LONG Extend,
827 LONG *pDelta)
829 ITextRangeImpl *This = impl_from_ITextRange(me);
830 if (!This->reOle)
831 return CO_E_RELEASED;
833 FIXME("not implemented %p\n", This);
834 return E_NOTIMPL;
837 static HRESULT WINAPI ITextRange_fnEndOf(ITextRange *me, LONG Unit, LONG Extend,
838 LONG *pDelta)
840 ITextRangeImpl *This = impl_from_ITextRange(me);
841 if (!This->reOle)
842 return CO_E_RELEASED;
844 FIXME("not implemented %p\n", This);
845 return E_NOTIMPL;
848 static HRESULT WINAPI ITextRange_fnMove(ITextRange *me, LONG Unit, LONG Count, LONG *pDelta)
850 ITextRangeImpl *This = impl_from_ITextRange(me);
851 if (!This->reOle)
852 return CO_E_RELEASED;
854 FIXME("not implemented %p\n", This);
855 return E_NOTIMPL;
858 static HRESULT WINAPI ITextRange_fnMoveStart(ITextRange *me, LONG Unit, LONG Count,
859 LONG *pDelta)
861 ITextRangeImpl *This = impl_from_ITextRange(me);
862 if (!This->reOle)
863 return CO_E_RELEASED;
865 FIXME("not implemented %p\n", This);
866 return E_NOTIMPL;
869 static HRESULT WINAPI ITextRange_fnMoveEnd(ITextRange *me, LONG Unit, LONG Count,
870 LONG *pDelta)
872 ITextRangeImpl *This = impl_from_ITextRange(me);
873 if (!This->reOle)
874 return CO_E_RELEASED;
876 FIXME("not implemented %p\n", This);
877 return E_NOTIMPL;
880 static HRESULT WINAPI ITextRange_fnMoveWhile(ITextRange *me, VARIANT *Cset, LONG Count,
881 LONG *pDelta)
883 ITextRangeImpl *This = impl_from_ITextRange(me);
884 if (!This->reOle)
885 return CO_E_RELEASED;
887 FIXME("not implemented %p\n", This);
888 return E_NOTIMPL;
891 static HRESULT WINAPI ITextRange_fnMoveStartWhile(ITextRange *me, VARIANT *Cset, LONG Count,
892 LONG *pDelta)
894 ITextRangeImpl *This = impl_from_ITextRange(me);
895 if (!This->reOle)
896 return CO_E_RELEASED;
898 FIXME("not implemented %p\n", This);
899 return E_NOTIMPL;
902 static HRESULT WINAPI ITextRange_fnMoveEndWhile(ITextRange *me, VARIANT *Cset, LONG Count,
903 LONG *pDelta)
905 ITextRangeImpl *This = impl_from_ITextRange(me);
906 if (!This->reOle)
907 return CO_E_RELEASED;
909 FIXME("not implemented %p\n", This);
910 return E_NOTIMPL;
913 static HRESULT WINAPI ITextRange_fnMoveUntil(ITextRange *me, VARIANT *Cset, LONG Count,
914 LONG *pDelta)
916 ITextRangeImpl *This = impl_from_ITextRange(me);
917 if (!This->reOle)
918 return CO_E_RELEASED;
920 FIXME("not implemented %p\n", This);
921 return E_NOTIMPL;
924 static HRESULT WINAPI ITextRange_fnMoveStartUntil(ITextRange *me, VARIANT *Cset, LONG Count,
925 LONG *pDelta)
927 ITextRangeImpl *This = impl_from_ITextRange(me);
928 if (!This->reOle)
929 return CO_E_RELEASED;
931 FIXME("not implemented %p\n", This);
932 return E_NOTIMPL;
935 static HRESULT WINAPI ITextRange_fnMoveEndUntil(ITextRange *me, VARIANT *Cset, LONG Count,
936 LONG *pDelta)
938 ITextRangeImpl *This = impl_from_ITextRange(me);
939 if (!This->reOle)
940 return CO_E_RELEASED;
942 FIXME("not implemented %p\n", This);
943 return E_NOTIMPL;
946 static HRESULT WINAPI ITextRange_fnFindText(ITextRange *me, BSTR bstr, LONG cch, LONG Flags,
947 LONG *pLength)
949 ITextRangeImpl *This = impl_from_ITextRange(me);
950 if (!This->reOle)
951 return CO_E_RELEASED;
953 FIXME("not implemented %p\n", This);
954 return E_NOTIMPL;
957 static HRESULT WINAPI ITextRange_fnFindTextStart(ITextRange *me, BSTR bstr, LONG cch,
958 LONG Flags, LONG *pLength)
960 ITextRangeImpl *This = impl_from_ITextRange(me);
961 if (!This->reOle)
962 return CO_E_RELEASED;
964 FIXME("not implemented %p\n", This);
965 return E_NOTIMPL;
968 static HRESULT WINAPI ITextRange_fnFindTextEnd(ITextRange *me, BSTR bstr, LONG cch,
969 LONG Flags, LONG *pLength)
971 ITextRangeImpl *This = impl_from_ITextRange(me);
972 if (!This->reOle)
973 return CO_E_RELEASED;
975 FIXME("not implemented %p\n", This);
976 return E_NOTIMPL;
979 static HRESULT WINAPI ITextRange_fnDelete(ITextRange *me, LONG Unit, LONG Count,
980 LONG *pDelta)
982 ITextRangeImpl *This = impl_from_ITextRange(me);
983 if (!This->reOle)
984 return CO_E_RELEASED;
986 FIXME("not implemented %p\n", This);
987 return E_NOTIMPL;
990 static HRESULT WINAPI ITextRange_fnCut(ITextRange *me, VARIANT *pVar)
992 ITextRangeImpl *This = impl_from_ITextRange(me);
993 if (!This->reOle)
994 return CO_E_RELEASED;
996 FIXME("not implemented %p\n", This);
997 return E_NOTIMPL;
1000 static HRESULT WINAPI ITextRange_fnCopy(ITextRange *me, VARIANT *pVar)
1002 ITextRangeImpl *This = impl_from_ITextRange(me);
1003 if (!This->reOle)
1004 return CO_E_RELEASED;
1006 FIXME("not implemented %p\n", This);
1007 return E_NOTIMPL;
1010 static HRESULT WINAPI ITextRange_fnPaste(ITextRange *me, VARIANT *pVar, LONG Format)
1012 ITextRangeImpl *This = impl_from_ITextRange(me);
1013 if (!This->reOle)
1014 return CO_E_RELEASED;
1016 FIXME("not implemented %p\n", This);
1017 return E_NOTIMPL;
1020 static HRESULT WINAPI ITextRange_fnCanPaste(ITextRange *me, VARIANT *pVar, LONG Format,
1021 LONG *pb)
1023 ITextRangeImpl *This = impl_from_ITextRange(me);
1024 if (!This->reOle)
1025 return CO_E_RELEASED;
1027 FIXME("not implemented %p\n", This);
1028 return E_NOTIMPL;
1031 static HRESULT WINAPI ITextRange_fnCanEdit(ITextRange *me, LONG *pb)
1033 ITextRangeImpl *This = impl_from_ITextRange(me);
1034 if (!This->reOle)
1035 return CO_E_RELEASED;
1037 FIXME("not implemented %p\n", This);
1038 return E_NOTIMPL;
1041 static HRESULT WINAPI ITextRange_fnChangeCase(ITextRange *me, LONG Type)
1043 ITextRangeImpl *This = impl_from_ITextRange(me);
1044 if (!This->reOle)
1045 return CO_E_RELEASED;
1047 FIXME("not implemented %p\n", This);
1048 return E_NOTIMPL;
1051 static HRESULT WINAPI ITextRange_fnGetPoint(ITextRange *me, LONG Type, LONG *cx, LONG *cy)
1053 ITextRangeImpl *This = impl_from_ITextRange(me);
1054 if (!This->reOle)
1055 return CO_E_RELEASED;
1057 FIXME("not implemented %p\n", This);
1058 return E_NOTIMPL;
1061 static HRESULT WINAPI ITextRange_fnSetPoint(ITextRange *me, LONG x, LONG y, LONG Type,
1062 LONG Extend)
1064 ITextRangeImpl *This = impl_from_ITextRange(me);
1065 if (!This->reOle)
1066 return CO_E_RELEASED;
1068 FIXME("not implemented %p\n", This);
1069 return E_NOTIMPL;
1072 static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG Value)
1074 ITextRangeImpl *This = impl_from_ITextRange(me);
1075 if (!This->reOle)
1076 return CO_E_RELEASED;
1078 FIXME("not implemented %p\n", This);
1079 return E_NOTIMPL;
1082 static HRESULT WINAPI ITextRange_fnGetEmbeddedObject(ITextRange *me, IUnknown **ppv)
1084 ITextRangeImpl *This = impl_from_ITextRange(me);
1085 if (!This->reOle)
1086 return CO_E_RELEASED;
1088 FIXME("not implemented %p\n", This);
1089 return E_NOTIMPL;
1092 static const ITextRangeVtbl trvt = {
1093 ITextRange_fnQueryInterface,
1094 ITextRange_fnAddRef,
1095 ITextRange_fnRelease,
1096 ITextRange_fnGetTypeInfoCount,
1097 ITextRange_fnGetTypeInfo,
1098 ITextRange_fnGetIDsOfNames,
1099 ITextRange_fnInvoke,
1100 ITextRange_fnGetText,
1101 ITextRange_fnSetText,
1102 ITextRange_fnGetChar,
1103 ITextRange_fnSetChar,
1104 ITextRange_fnGetDuplicate,
1105 ITextRange_fnGetFormattedText,
1106 ITextRange_fnSetFormattedText,
1107 ITextRange_fnGetStart,
1108 ITextRange_fnSetStart,
1109 ITextRange_fnGetEnd,
1110 ITextRange_fnSetEnd,
1111 ITextRange_fnGetFont,
1112 ITextRange_fnSetFont,
1113 ITextRange_fnGetPara,
1114 ITextRange_fnSetPara,
1115 ITextRange_fnGetStoryLength,
1116 ITextRange_fnGetStoryType,
1117 ITextRange_fnCollapse,
1118 ITextRange_fnExpand,
1119 ITextRange_fnGetIndex,
1120 ITextRange_fnSetIndex,
1121 ITextRange_fnSetRange,
1122 ITextRange_fnInRange,
1123 ITextRange_fnInStory,
1124 ITextRange_fnIsEqual,
1125 ITextRange_fnSelect,
1126 ITextRange_fnStartOf,
1127 ITextRange_fnEndOf,
1128 ITextRange_fnMove,
1129 ITextRange_fnMoveStart,
1130 ITextRange_fnMoveEnd,
1131 ITextRange_fnMoveWhile,
1132 ITextRange_fnMoveStartWhile,
1133 ITextRange_fnMoveEndWhile,
1134 ITextRange_fnMoveUntil,
1135 ITextRange_fnMoveStartUntil,
1136 ITextRange_fnMoveEndUntil,
1137 ITextRange_fnFindText,
1138 ITextRange_fnFindTextStart,
1139 ITextRange_fnFindTextEnd,
1140 ITextRange_fnDelete,
1141 ITextRange_fnCut,
1142 ITextRange_fnCopy,
1143 ITextRange_fnPaste,
1144 ITextRange_fnCanPaste,
1145 ITextRange_fnCanEdit,
1146 ITextRange_fnChangeCase,
1147 ITextRange_fnGetPoint,
1148 ITextRange_fnSetPoint,
1149 ITextRange_fnScrollIntoView,
1150 ITextRange_fnGetEmbeddedObject
1152 /* ITextRange interface */
1154 static HRESULT WINAPI
1155 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
1156 void** ppvObject)
1158 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1159 return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
1162 static ULONG WINAPI
1163 ITextDocument_fnAddRef(ITextDocument* me)
1165 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1166 return IRichEditOle_AddRef(&This->IRichEditOle_iface);
1169 static ULONG WINAPI
1170 ITextDocument_fnRelease(ITextDocument* me)
1172 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1173 return IRichEditOle_Release(&This->IRichEditOle_iface);
1176 static HRESULT WINAPI
1177 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
1178 UINT* pctinfo)
1180 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1181 FIXME("stub %p\n",This);
1182 return E_NOTIMPL;
1185 static HRESULT WINAPI
1186 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
1187 ITypeInfo** ppTInfo)
1189 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1190 FIXME("stub %p\n",This);
1191 return E_NOTIMPL;
1194 static HRESULT WINAPI
1195 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
1196 LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
1198 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1199 FIXME("stub %p\n",This);
1200 return E_NOTIMPL;
1203 static HRESULT WINAPI
1204 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
1205 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1206 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1208 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1209 FIXME("stub %p\n",This);
1210 return E_NOTIMPL;
1213 static HRESULT WINAPI
1214 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
1216 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1217 FIXME("stub %p\n",This);
1218 return E_NOTIMPL;
1221 static HRESULT WINAPI
1222 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
1224 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1225 TRACE("(%p)\n", me);
1227 if(!ppSel)
1228 return E_INVALIDARG;
1229 *ppSel = &This->txtSel->ITextSelection_iface;
1230 ITextSelection_AddRef(*ppSel);
1231 return S_OK;
1234 static HRESULT WINAPI
1235 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
1237 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1238 FIXME("stub %p\n",This);
1239 return E_NOTIMPL;
1242 static HRESULT WINAPI
1243 ITextDocument_fnGetStoryRanges(ITextDocument* me,
1244 ITextStoryRanges** ppStories)
1246 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1247 FIXME("stub %p\n",This);
1248 return E_NOTIMPL;
1251 static HRESULT WINAPI
1252 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
1254 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1255 FIXME("stub %p\n",This);
1256 return E_NOTIMPL;
1259 static HRESULT WINAPI
1260 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
1262 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1263 FIXME("stub %p\n",This);
1264 return E_NOTIMPL;
1267 static HRESULT WINAPI
1268 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
1270 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1271 FIXME("stub %p\n",This);
1272 return E_NOTIMPL;
1275 static HRESULT WINAPI
1276 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
1278 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1279 FIXME("stub %p\n",This);
1280 return E_NOTIMPL;
1283 static HRESULT WINAPI
1284 ITextDocument_fnNew(ITextDocument* me)
1286 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1287 FIXME("stub %p\n",This);
1288 return E_NOTIMPL;
1291 static HRESULT WINAPI
1292 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
1293 LONG CodePage)
1295 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1296 FIXME("stub %p\n",This);
1297 return E_NOTIMPL;
1300 static HRESULT WINAPI
1301 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
1302 LONG CodePage)
1304 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1305 FIXME("stub %p\n",This);
1306 return E_NOTIMPL;
1309 static HRESULT WINAPI
1310 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
1312 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1313 FIXME("stub %p\n",This);
1314 return E_NOTIMPL;
1317 static HRESULT WINAPI
1318 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
1320 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1321 FIXME("stub %p\n",This);
1322 return E_NOTIMPL;
1325 static HRESULT WINAPI
1326 ITextDocument_fnBeginEditCollection(ITextDocument* me)
1328 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1329 FIXME("stub %p\n",This);
1330 return E_NOTIMPL;
1333 static HRESULT WINAPI
1334 ITextDocument_fnEndEditCollection(ITextDocument* me)
1336 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1337 FIXME("stub %p\n",This);
1338 return E_NOTIMPL;
1341 static HRESULT WINAPI
1342 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
1344 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1345 FIXME("stub %p\n",This);
1346 return E_NOTIMPL;
1349 static HRESULT WINAPI
1350 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
1352 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1353 FIXME("stub %p\n",This);
1354 return E_NOTIMPL;
1357 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
1359 ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
1361 if (!txtRge)
1362 return E_OUTOFMEMORY;
1363 txtRge->ITextRange_iface.lpVtbl = &trvt;
1364 txtRge->ref = 1;
1365 txtRge->reOle = reOle;
1366 txtRge->start = start;
1367 txtRge->end = end;
1368 list_add_head(&reOle->rangelist, &txtRge->entry);
1369 *ppRange = &txtRge->ITextRange_iface;
1370 return S_OK;
1373 static HRESULT WINAPI
1374 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
1375 ITextRange** ppRange)
1377 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1378 const int len = ME_GetTextLength(This->editor) + 1;
1380 TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
1381 if (!ppRange)
1382 return E_INVALIDARG;
1384 cp1 = max(cp1, 0);
1385 cp2 = max(cp2, 0);
1386 cp1 = min(cp1, len);
1387 cp2 = min(cp2, len);
1388 if (cp1 > cp2)
1390 LONG tmp;
1391 tmp = cp1;
1392 cp1 = cp2;
1393 cp2 = tmp;
1395 if (cp1 == len)
1396 cp1 = cp2 = len - 1;
1398 return CreateITextRange(This, cp1, cp2, ppRange);
1401 static HRESULT WINAPI
1402 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
1403 ITextRange** ppRange)
1405 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1406 FIXME("stub %p\n",This);
1407 return E_NOTIMPL;
1410 static const ITextDocumentVtbl tdvt = {
1411 ITextDocument_fnQueryInterface,
1412 ITextDocument_fnAddRef,
1413 ITextDocument_fnRelease,
1414 ITextDocument_fnGetTypeInfoCount,
1415 ITextDocument_fnGetTypeInfo,
1416 ITextDocument_fnGetIDsOfNames,
1417 ITextDocument_fnInvoke,
1418 ITextDocument_fnGetName,
1419 ITextDocument_fnGetSelection,
1420 ITextDocument_fnGetStoryCount,
1421 ITextDocument_fnGetStoryRanges,
1422 ITextDocument_fnGetSaved,
1423 ITextDocument_fnSetSaved,
1424 ITextDocument_fnGetDefaultTabStop,
1425 ITextDocument_fnSetDefaultTabStop,
1426 ITextDocument_fnNew,
1427 ITextDocument_fnOpen,
1428 ITextDocument_fnSave,
1429 ITextDocument_fnFreeze,
1430 ITextDocument_fnUnfreeze,
1431 ITextDocument_fnBeginEditCollection,
1432 ITextDocument_fnEndEditCollection,
1433 ITextDocument_fnUndo,
1434 ITextDocument_fnRedo,
1435 ITextDocument_fnRange,
1436 ITextDocument_fnRangeFromPoint
1439 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
1441 return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
1444 static HRESULT WINAPI ITextSelection_fnQueryInterface(
1445 ITextSelection *me,
1446 REFIID riid,
1447 void **ppvObj)
1449 *ppvObj = NULL;
1450 if (IsEqualGUID(riid, &IID_IUnknown)
1451 || IsEqualGUID(riid, &IID_IDispatch)
1452 || IsEqualGUID(riid, &IID_ITextRange)
1453 || IsEqualGUID(riid, &IID_ITextSelection))
1455 *ppvObj = me;
1456 ITextSelection_AddRef(me);
1457 return S_OK;
1460 return E_NOINTERFACE;
1463 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
1465 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1466 return InterlockedIncrement(&This->ref);
1469 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
1471 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1472 ULONG ref = InterlockedDecrement(&This->ref);
1473 if (ref == 0)
1474 heap_free(This);
1475 return ref;
1478 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
1480 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1481 if (!This->reOle)
1482 return CO_E_RELEASED;
1484 FIXME("not implemented\n");
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
1489 ITypeInfo **ppTInfo)
1491 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1492 if (!This->reOle)
1493 return CO_E_RELEASED;
1495 FIXME("not implemented\n");
1496 return E_NOTIMPL;
1499 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
1500 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1502 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1503 if (!This->reOle)
1504 return CO_E_RELEASED;
1506 FIXME("not implemented\n");
1507 return E_NOTIMPL;
1510 static HRESULT WINAPI ITextSelection_fnInvoke(
1511 ITextSelection *me,
1512 DISPID dispIdMember,
1513 REFIID riid,
1514 LCID lcid,
1515 WORD wFlags,
1516 DISPPARAMS *pDispParams,
1517 VARIANT *pVarResult,
1518 EXCEPINFO *pExcepInfo,
1519 UINT *puArgErr)
1521 FIXME("not implemented\n");
1522 return E_NOTIMPL;
1525 /*** ITextRange methods ***/
1526 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
1528 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1529 ME_Cursor *start = NULL, *end = NULL;
1530 int nChars, endOfs;
1531 BOOL bEOP;
1533 if (!This->reOle)
1534 return CO_E_RELEASED;
1535 TRACE("%p\n", pbstr);
1536 if (!pbstr)
1537 return E_INVALIDARG;
1539 ME_GetSelection(This->reOle->editor, &start, &end);
1540 endOfs = ME_GetCursorOfs(end);
1541 nChars = endOfs - ME_GetCursorOfs(start);
1542 if (!nChars)
1544 *pbstr = NULL;
1545 return S_OK;
1548 *pbstr = SysAllocStringLen(NULL, nChars);
1549 if (!*pbstr)
1550 return E_OUTOFMEMORY;
1552 bEOP = (end->pRun->next->type == diTextEnd && endOfs > ME_GetTextLength(This->reOle->editor));
1553 ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
1554 TRACE("%s\n", wine_dbgstr_w(*pbstr));
1556 return S_OK;
1559 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
1561 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1562 if (!This->reOle)
1563 return CO_E_RELEASED;
1565 FIXME("not implemented\n");
1566 return E_NOTIMPL;
1569 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
1571 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1572 if (!This->reOle)
1573 return CO_E_RELEASED;
1575 FIXME("not implemented\n");
1576 return E_NOTIMPL;
1579 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
1581 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1582 if (!This->reOle)
1583 return CO_E_RELEASED;
1585 FIXME("not implemented\n");
1586 return E_NOTIMPL;
1589 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
1591 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1592 if (!This->reOle)
1593 return CO_E_RELEASED;
1595 FIXME("not implemented\n");
1596 return E_NOTIMPL;
1599 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)
1601 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1602 if (!This->reOle)
1603 return CO_E_RELEASED;
1605 FIXME("not implemented\n");
1606 return E_NOTIMPL;
1609 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *pRange)
1611 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1612 if (!This->reOle)
1613 return CO_E_RELEASED;
1615 FIXME("not implemented\n");
1616 return E_NOTIMPL;
1619 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
1621 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1622 if (!This->reOle)
1623 return CO_E_RELEASED;
1625 FIXME("not implemented\n");
1626 return E_NOTIMPL;
1629 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst)
1631 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1632 if (!This->reOle)
1633 return CO_E_RELEASED;
1635 FIXME("not implemented\n");
1636 return E_NOTIMPL;
1639 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
1641 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1642 if (!This->reOle)
1643 return CO_E_RELEASED;
1645 FIXME("not implemented\n");
1646 return E_NOTIMPL;
1649 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
1651 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1652 if (!This->reOle)
1653 return CO_E_RELEASED;
1655 FIXME("not implemented\n");
1656 return E_NOTIMPL;
1659 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **pFont)
1661 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1662 if (!This->reOle)
1663 return CO_E_RELEASED;
1665 FIXME("not implemented\n");
1666 return E_NOTIMPL;
1669 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
1671 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1672 if (!This->reOle)
1673 return CO_E_RELEASED;
1675 FIXME("not implemented\n");
1676 return E_NOTIMPL;
1679 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **ppPara)
1681 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1682 if (!This->reOle)
1683 return CO_E_RELEASED;
1685 FIXME("not implemented\n");
1686 return E_NOTIMPL;
1689 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pPara)
1691 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1692 if (!This->reOle)
1693 return CO_E_RELEASED;
1695 FIXME("not implemented\n");
1696 return E_NOTIMPL;
1699 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *pcch)
1701 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1702 if (!This->reOle)
1703 return CO_E_RELEASED;
1705 FIXME("not implemented\n");
1706 return E_NOTIMPL;
1709 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pValue)
1711 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1712 if (!This->reOle)
1713 return CO_E_RELEASED;
1715 FIXME("not implemented\n");
1716 return E_NOTIMPL;
1719 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
1721 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1722 if (!This->reOle)
1723 return CO_E_RELEASED;
1725 FIXME("not implemented\n");
1726 return E_NOTIMPL;
1729 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
1731 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1732 if (!This->reOle)
1733 return CO_E_RELEASED;
1735 FIXME("not implemented\n");
1736 return E_NOTIMPL;
1739 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
1741 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1742 if (!This->reOle)
1743 return CO_E_RELEASED;
1745 FIXME("not implemented\n");
1746 return E_NOTIMPL;
1749 static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG Unit, LONG Index,
1750 LONG Extend)
1752 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1753 if (!This->reOle)
1754 return CO_E_RELEASED;
1756 FIXME("not implemented\n");
1757 return E_NOTIMPL;
1760 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActive, LONG cpOther)
1762 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1763 if (!This->reOle)
1764 return CO_E_RELEASED;
1766 FIXME("not implemented\n");
1767 return E_NOTIMPL;
1770 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
1772 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1773 if (!This->reOle)
1774 return CO_E_RELEASED;
1776 FIXME("not implemented\n");
1777 return E_NOTIMPL;
1780 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)
1782 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1783 if (!This->reOle)
1784 return CO_E_RELEASED;
1786 FIXME("not implemented\n");
1787 return E_NOTIMPL;
1790 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb)
1792 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1793 if (!This->reOle)
1794 return CO_E_RELEASED;
1796 FIXME("not implemented\n");
1797 return E_NOTIMPL;
1800 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
1802 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1803 if (!This->reOle)
1804 return CO_E_RELEASED;
1806 FIXME("not implemented\n");
1807 return E_NOTIMPL;
1810 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG Unit, LONG Extend,
1811 LONG *pDelta)
1813 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1814 if (!This->reOle)
1815 return CO_E_RELEASED;
1817 FIXME("not implemented\n");
1818 return E_NOTIMPL;
1821 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG Extend,
1822 LONG *pDelta)
1824 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1825 if (!This->reOle)
1826 return CO_E_RELEASED;
1828 FIXME("not implemented\n");
1829 return E_NOTIMPL;
1832 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG Unit, LONG Count, LONG *pDelta)
1834 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1835 if (!This->reOle)
1836 return CO_E_RELEASED;
1838 FIXME("not implemented\n");
1839 return E_NOTIMPL;
1842 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG Unit, LONG Count,
1843 LONG *pDelta)
1845 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1846 if (!This->reOle)
1847 return CO_E_RELEASED;
1849 FIXME("not implemented\n");
1850 return E_NOTIMPL;
1853 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG Unit, LONG Count,
1854 LONG *pDelta)
1856 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1857 if (!This->reOle)
1858 return CO_E_RELEASED;
1860 FIXME("not implemented\n");
1861 return E_NOTIMPL;
1864 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1865 LONG *pDelta)
1867 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1868 if (!This->reOle)
1869 return CO_E_RELEASED;
1871 FIXME("not implemented\n");
1872 return E_NOTIMPL;
1875 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1876 LONG *pDelta)
1878 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1879 if (!This->reOle)
1880 return CO_E_RELEASED;
1882 FIXME("not implemented\n");
1883 return E_NOTIMPL;
1886 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1887 LONG *pDelta)
1889 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1890 if (!This->reOle)
1891 return CO_E_RELEASED;
1893 FIXME("not implemented\n");
1894 return E_NOTIMPL;
1897 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1898 LONG *pDelta)
1900 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1901 if (!This->reOle)
1902 return CO_E_RELEASED;
1904 FIXME("not implemented\n");
1905 return E_NOTIMPL;
1908 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1909 LONG *pDelta)
1911 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1912 if (!This->reOle)
1913 return CO_E_RELEASED;
1915 FIXME("not implemented\n");
1916 return E_NOTIMPL;
1919 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1920 LONG *pDelta)
1922 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1923 if (!This->reOle)
1924 return CO_E_RELEASED;
1926 FIXME("not implemented\n");
1927 return E_NOTIMPL;
1930 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR bstr, LONG cch, LONG Flags,
1931 LONG *pLength)
1933 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1934 if (!This->reOle)
1935 return CO_E_RELEASED;
1937 FIXME("not implemented\n");
1938 return E_NOTIMPL;
1941 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR bstr, LONG cch,
1942 LONG Flags, LONG *pLength)
1944 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1945 if (!This->reOle)
1946 return CO_E_RELEASED;
1948 FIXME("not implemented\n");
1949 return E_NOTIMPL;
1952 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR bstr, LONG cch,
1953 LONG Flags, LONG *pLength)
1955 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1956 if (!This->reOle)
1957 return CO_E_RELEASED;
1959 FIXME("not implemented\n");
1960 return E_NOTIMPL;
1963 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG Unit, LONG Count,
1964 LONG *pDelta)
1966 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1967 if (!This->reOle)
1968 return CO_E_RELEASED;
1970 FIXME("not implemented\n");
1971 return E_NOTIMPL;
1974 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *pVar)
1976 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1977 if (!This->reOle)
1978 return CO_E_RELEASED;
1980 FIXME("not implemented\n");
1981 return E_NOTIMPL;
1984 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *pVar)
1986 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1987 if (!This->reOle)
1988 return CO_E_RELEASED;
1990 FIXME("not implemented\n");
1991 return E_NOTIMPL;
1994 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *pVar, LONG Format)
1996 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1997 if (!This->reOle)
1998 return CO_E_RELEASED;
2000 FIXME("not implemented\n");
2001 return E_NOTIMPL;
2004 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *pVar, LONG Format,
2005 LONG *pb)
2007 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2008 if (!This->reOle)
2009 return CO_E_RELEASED;
2011 FIXME("not implemented\n");
2012 return E_NOTIMPL;
2015 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *pb)
2017 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2018 if (!This->reOle)
2019 return CO_E_RELEASED;
2021 FIXME("not implemented\n");
2022 return E_NOTIMPL;
2025 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG Type)
2027 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2028 if (!This->reOle)
2029 return CO_E_RELEASED;
2031 FIXME("not implemented\n");
2032 return E_NOTIMPL;
2035 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG Type, LONG *cx, LONG *cy)
2037 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2038 if (!This->reOle)
2039 return CO_E_RELEASED;
2041 FIXME("not implemented\n");
2042 return E_NOTIMPL;
2045 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG Type,
2046 LONG Extend)
2048 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2049 if (!This->reOle)
2050 return CO_E_RELEASED;
2052 FIXME("not implemented\n");
2053 return E_NOTIMPL;
2056 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG Value)
2058 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2059 if (!This->reOle)
2060 return CO_E_RELEASED;
2062 FIXME("not implemented\n");
2063 return E_NOTIMPL;
2066 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
2068 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2069 if (!This->reOle)
2070 return CO_E_RELEASED;
2072 FIXME("not implemented\n");
2073 return E_NOTIMPL;
2076 /*** ITextSelection methods ***/
2077 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags)
2079 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2080 if (!This->reOle)
2081 return CO_E_RELEASED;
2083 FIXME("not implemented\n");
2084 return E_NOTIMPL;
2087 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
2089 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2090 if (!This->reOle)
2091 return CO_E_RELEASED;
2093 FIXME("not implemented\n");
2094 return E_NOTIMPL;
2097 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *pType)
2099 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2100 if (!This->reOle)
2101 return CO_E_RELEASED;
2103 FIXME("not implemented\n");
2104 return E_NOTIMPL;
2107 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG Unit, LONG Count,
2108 LONG Extend, LONG *pDelta)
2110 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2111 if (!This->reOle)
2112 return CO_E_RELEASED;
2114 FIXME("not implemented\n");
2115 return E_NOTIMPL;
2118 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG Unit, LONG Count,
2119 LONG Extend, LONG *pDelta)
2121 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2122 if (!This->reOle)
2123 return CO_E_RELEASED;
2125 FIXME("not implemented\n");
2126 return E_NOTIMPL;
2129 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG Unit, LONG Count,
2130 LONG Extend, LONG *pDelta)
2132 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2133 if (!This->reOle)
2134 return CO_E_RELEASED;
2136 FIXME("not implemented\n");
2137 return E_NOTIMPL;
2140 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG Unit, LONG Count,
2141 LONG Extend, LONG *pDelta)
2143 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2144 if (!This->reOle)
2145 return CO_E_RELEASED;
2147 FIXME("not implemented\n");
2148 return E_NOTIMPL;
2151 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG Unit, LONG Extend,
2152 LONG *pDelta)
2154 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2155 if (!This->reOle)
2156 return CO_E_RELEASED;
2158 FIXME("not implemented\n");
2159 return E_NOTIMPL;
2162 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LONG Extend,
2163 LONG *pDelta)
2165 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2166 if (!This->reOle)
2167 return CO_E_RELEASED;
2169 FIXME("not implemented\n");
2170 return E_NOTIMPL;
2173 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR bstr)
2175 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2176 if (!This->reOle)
2177 return CO_E_RELEASED;
2179 FIXME("not implemented\n");
2180 return E_NOTIMPL;
2183 static const ITextSelectionVtbl tsvt = {
2184 ITextSelection_fnQueryInterface,
2185 ITextSelection_fnAddRef,
2186 ITextSelection_fnRelease,
2187 ITextSelection_fnGetTypeInfoCount,
2188 ITextSelection_fnGetTypeInfo,
2189 ITextSelection_fnGetIDsOfNames,
2190 ITextSelection_fnInvoke,
2191 ITextSelection_fnGetText,
2192 ITextSelection_fnSetText,
2193 ITextSelection_fnGetChar,
2194 ITextSelection_fnSetChar,
2195 ITextSelection_fnGetDuplicate,
2196 ITextSelection_fnGetFormattedText,
2197 ITextSelection_fnSetFormattedText,
2198 ITextSelection_fnGetStart,
2199 ITextSelection_fnSetStart,
2200 ITextSelection_fnGetEnd,
2201 ITextSelection_fnSetEnd,
2202 ITextSelection_fnGetFont,
2203 ITextSelection_fnSetFont,
2204 ITextSelection_fnGetPara,
2205 ITextSelection_fnSetPara,
2206 ITextSelection_fnGetStoryLength,
2207 ITextSelection_fnGetStoryType,
2208 ITextSelection_fnCollapse,
2209 ITextSelection_fnExpand,
2210 ITextSelection_fnGetIndex,
2211 ITextSelection_fnSetIndex,
2212 ITextSelection_fnSetRange,
2213 ITextSelection_fnInRange,
2214 ITextSelection_fnInStory,
2215 ITextSelection_fnIsEqual,
2216 ITextSelection_fnSelect,
2217 ITextSelection_fnStartOf,
2218 ITextSelection_fnEndOf,
2219 ITextSelection_fnMove,
2220 ITextSelection_fnMoveStart,
2221 ITextSelection_fnMoveEnd,
2222 ITextSelection_fnMoveWhile,
2223 ITextSelection_fnMoveStartWhile,
2224 ITextSelection_fnMoveEndWhile,
2225 ITextSelection_fnMoveUntil,
2226 ITextSelection_fnMoveStartUntil,
2227 ITextSelection_fnMoveEndUntil,
2228 ITextSelection_fnFindText,
2229 ITextSelection_fnFindTextStart,
2230 ITextSelection_fnFindTextEnd,
2231 ITextSelection_fnDelete,
2232 ITextSelection_fnCut,
2233 ITextSelection_fnCopy,
2234 ITextSelection_fnPaste,
2235 ITextSelection_fnCanPaste,
2236 ITextSelection_fnCanEdit,
2237 ITextSelection_fnChangeCase,
2238 ITextSelection_fnGetPoint,
2239 ITextSelection_fnSetPoint,
2240 ITextSelection_fnScrollIntoView,
2241 ITextSelection_fnGetEmbeddedObject,
2242 ITextSelection_fnGetFlags,
2243 ITextSelection_fnSetFlags,
2244 ITextSelection_fnGetType,
2245 ITextSelection_fnMoveLeft,
2246 ITextSelection_fnMoveRight,
2247 ITextSelection_fnMoveUp,
2248 ITextSelection_fnMoveDown,
2249 ITextSelection_fnHomeKey,
2250 ITextSelection_fnEndKey,
2251 ITextSelection_fnTypeText
2254 static ITextSelectionImpl *
2255 CreateTextSelection(IRichEditOleImpl *reOle)
2257 ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
2258 if (!txtSel)
2259 return NULL;
2261 txtSel->ITextSelection_iface.lpVtbl = &tsvt;
2262 txtSel->ref = 1;
2263 txtSel->reOle = reOle;
2264 return txtSel;
2267 LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
2269 IRichEditOleImpl *reo;
2271 reo = heap_alloc(sizeof(IRichEditOleImpl));
2272 if (!reo)
2273 return 0;
2275 reo->IRichEditOle_iface.lpVtbl = &revt;
2276 reo->ITextDocument_iface.lpVtbl = &tdvt;
2277 reo->ref = 1;
2278 reo->editor = editor;
2279 reo->txtSel = CreateTextSelection(reo);
2280 if (!reo->txtSel)
2282 heap_free(reo);
2283 return 0;
2285 reo->clientSite = CreateOleClientSite(reo);
2286 if (!reo->clientSite)
2288 ITextSelection_Release(&reo->txtSel->ITextSelection_iface);
2289 heap_free(reo);
2290 return 0;
2292 TRACE("Created %p\n",reo);
2293 *ppObj = reo;
2294 list_init(&reo->rangelist);
2296 return 1;
2299 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
2301 /* sizel is in .01 millimeters, sz in pixels */
2302 sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
2303 sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
2306 /******************************************************************************
2307 * ME_GetOLEObjectSize
2309 * Sets run extent for OLE objects.
2311 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
2313 IDataObject* ido;
2314 FORMATETC fmt;
2315 STGMEDIUM stgm;
2316 DIBSECTION dibsect;
2317 ENHMETAHEADER emh;
2319 assert(run->nFlags & MERF_GRAPHICS);
2320 assert(run->ole_obj);
2322 if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
2324 convert_sizel(c, &run->ole_obj->sizel, pSize);
2325 if (c->editor->nZoomNumerator != 0)
2327 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2328 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2330 return;
2333 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
2335 FIXME("Query Interface IID_IDataObject failed!\n");
2336 pSize->cx = pSize->cy = 0;
2337 return;
2339 fmt.cfFormat = CF_BITMAP;
2340 fmt.ptd = NULL;
2341 fmt.dwAspect = DVASPECT_CONTENT;
2342 fmt.lindex = -1;
2343 fmt.tymed = TYMED_GDI;
2344 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2346 fmt.cfFormat = CF_ENHMETAFILE;
2347 fmt.tymed = TYMED_ENHMF;
2348 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2350 FIXME("unsupported format\n");
2351 pSize->cx = pSize->cy = 0;
2352 IDataObject_Release(ido);
2353 return;
2357 switch (stgm.tymed)
2359 case TYMED_GDI:
2360 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
2361 pSize->cx = dibsect.dsBm.bmWidth;
2362 pSize->cy = dibsect.dsBm.bmHeight;
2363 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
2364 break;
2365 case TYMED_ENHMF:
2366 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
2367 pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
2368 pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
2369 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
2370 break;
2371 default:
2372 FIXME("Unsupported tymed %d\n", stgm.tymed);
2373 break;
2375 IDataObject_Release(ido);
2376 if (c->editor->nZoomNumerator != 0)
2378 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2379 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2383 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
2384 ME_Paragraph *para, BOOL selected)
2386 IDataObject* ido;
2387 FORMATETC fmt;
2388 STGMEDIUM stgm;
2389 DIBSECTION dibsect;
2390 ENHMETAHEADER emh;
2391 HDC hMemDC;
2392 SIZE sz;
2393 BOOL has_size;
2395 assert(run->nFlags & MERF_GRAPHICS);
2396 assert(run->ole_obj);
2397 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
2399 FIXME("Couldn't get interface\n");
2400 return;
2402 has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
2403 fmt.cfFormat = CF_BITMAP;
2404 fmt.ptd = NULL;
2405 fmt.dwAspect = DVASPECT_CONTENT;
2406 fmt.lindex = -1;
2407 fmt.tymed = TYMED_GDI;
2408 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2410 fmt.cfFormat = CF_ENHMETAFILE;
2411 fmt.tymed = TYMED_ENHMF;
2412 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2414 FIXME("Couldn't get storage medium\n");
2415 IDataObject_Release(ido);
2416 return;
2419 switch (stgm.tymed)
2421 case TYMED_GDI:
2422 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
2423 hMemDC = CreateCompatibleDC(c->hDC);
2424 SelectObject(hMemDC, stgm.u.hBitmap);
2425 if (has_size)
2427 convert_sizel(c, &run->ole_obj->sizel, &sz);
2428 } else {
2429 sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
2430 sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
2432 if (c->editor->nZoomNumerator != 0)
2434 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2435 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2437 if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
2439 BitBlt(c->hDC, x, y - sz.cy,
2440 dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
2441 hMemDC, 0, 0, SRCCOPY);
2442 } else {
2443 StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
2444 hMemDC, 0, 0, dibsect.dsBm.bmWidth,
2445 dibsect.dsBm.bmHeight, SRCCOPY);
2447 DeleteDC(hMemDC);
2448 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
2449 break;
2450 case TYMED_ENHMF:
2451 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
2452 if (has_size)
2454 convert_sizel(c, &run->ole_obj->sizel, &sz);
2455 } else {
2456 sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
2457 sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
2459 if (c->editor->nZoomNumerator != 0)
2461 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2462 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2466 RECT rc;
2468 rc.left = x;
2469 rc.top = y - sz.cy;
2470 rc.right = x + sz.cx;
2471 rc.bottom = y;
2472 PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
2474 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
2475 break;
2476 default:
2477 FIXME("Unsupported tymed %d\n", stgm.tymed);
2478 selected = FALSE;
2479 break;
2481 if (selected && !c->editor->bHideSelection)
2482 PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
2483 IDataObject_Release(ido);
2486 void ME_DeleteReObject(REOBJECT* reo)
2488 if (reo->poleobj) IOleObject_Release(reo->poleobj);
2489 if (reo->pstg) IStorage_Release(reo->pstg);
2490 if (reo->polesite) IOleClientSite_Release(reo->polesite);
2491 FREE_OBJ(reo);
2494 void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
2496 *dst = *src;
2498 if (dst->poleobj) IOleObject_AddRef(dst->poleobj);
2499 if (dst->pstg) IStorage_AddRef(dst->pstg);
2500 if (dst->polesite) IOleClientSite_AddRef(dst->polesite);