riched20: Implement ITextSelection::Collapse.
[wine/multimedia.git] / dlls / riched20 / richole.c
blobf7e7870f5e5ad3ae9e22f042e0a93dbc0183f96c
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 CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange);
607 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
609 ITextRangeImpl *This = impl_from_ITextRange(me);
610 if (!This->reOle)
611 return CO_E_RELEASED;
613 TRACE("%p %p\n", This, ppRange);
614 if (!ppRange)
615 return E_INVALIDARG;
617 return CreateITextRange(This->reOle, This->start, This->end, ppRange);
620 static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **ppRange)
622 ITextRangeImpl *This = impl_from_ITextRange(me);
623 if (!This->reOle)
624 return CO_E_RELEASED;
626 FIXME("not implemented %p\n", This);
627 return E_NOTIMPL;
630 static HRESULT WINAPI ITextRange_fnSetFormattedText(ITextRange *me, ITextRange *pRange)
632 ITextRangeImpl *This = impl_from_ITextRange(me);
633 if (!This->reOle)
634 return CO_E_RELEASED;
636 FIXME("not implemented %p\n", This);
637 return E_NOTIMPL;
640 static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *pcpFirst)
642 ITextRangeImpl *This = impl_from_ITextRange(me);
643 if (!This->reOle)
644 return CO_E_RELEASED;
646 if (!pcpFirst)
647 return E_INVALIDARG;
648 *pcpFirst = This->start;
649 TRACE("%d\n", *pcpFirst);
650 return S_OK;
653 static HRESULT WINAPI ITextRange_fnSetStart(ITextRange *me, LONG cpFirst)
655 ITextRangeImpl *This = impl_from_ITextRange(me);
656 if (!This->reOle)
657 return CO_E_RELEASED;
659 FIXME("not implemented %p\n", This);
660 return E_NOTIMPL;
663 static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *pcpLim)
665 ITextRangeImpl *This = impl_from_ITextRange(me);
666 if (!This->reOle)
667 return CO_E_RELEASED;
669 if (!pcpLim)
670 return E_INVALIDARG;
671 *pcpLim = This->end;
672 TRACE("%d\n", *pcpLim);
673 return S_OK;
676 static HRESULT WINAPI ITextRange_fnSetEnd(ITextRange *me, LONG cpLim)
678 ITextRangeImpl *This = impl_from_ITextRange(me);
679 if (!This->reOle)
680 return CO_E_RELEASED;
682 FIXME("not implemented %p\n", This);
683 return E_NOTIMPL;
686 static HRESULT WINAPI ITextRange_fnGetFont(ITextRange *me, ITextFont **pFont)
688 ITextRangeImpl *This = impl_from_ITextRange(me);
689 if (!This->reOle)
690 return CO_E_RELEASED;
692 FIXME("not implemented %p\n", This);
693 return E_NOTIMPL;
696 static HRESULT WINAPI ITextRange_fnSetFont(ITextRange *me, ITextFont *pFont)
698 ITextRangeImpl *This = impl_from_ITextRange(me);
699 if (!This->reOle)
700 return CO_E_RELEASED;
702 FIXME("not implemented %p\n", This);
703 return E_NOTIMPL;
706 static HRESULT WINAPI ITextRange_fnGetPara(ITextRange *me, ITextPara **ppPara)
708 ITextRangeImpl *This = impl_from_ITextRange(me);
709 if (!This->reOle)
710 return CO_E_RELEASED;
712 FIXME("not implemented %p\n", This);
713 return E_NOTIMPL;
716 static HRESULT WINAPI ITextRange_fnSetPara(ITextRange *me, ITextPara *pPara)
718 ITextRangeImpl *This = impl_from_ITextRange(me);
719 if (!This->reOle)
720 return CO_E_RELEASED;
722 FIXME("not implemented %p\n", This);
723 return E_NOTIMPL;
726 static HRESULT WINAPI ITextRange_fnGetStoryLength(ITextRange *me, LONG *pcch)
728 ITextRangeImpl *This = impl_from_ITextRange(me);
729 if (!This->reOle)
730 return CO_E_RELEASED;
732 FIXME("not implemented %p\n", This);
733 return E_NOTIMPL;
736 static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *pValue)
738 ITextRangeImpl *This = impl_from_ITextRange(me);
739 if (!This->reOle)
740 return CO_E_RELEASED;
742 FIXME("not implemented %p\n", This);
743 return E_NOTIMPL;
746 static HRESULT range_Collapse(LONG bStart, LONG *start, LONG *end)
748 if (*end == *start)
749 return S_FALSE;
751 if (bStart == tomEnd || bStart == tomFalse)
752 *start = *end;
753 else
754 *end = *start;
755 return S_OK;
758 static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
760 ITextRangeImpl *This = impl_from_ITextRange(me);
761 if (!This->reOle)
762 return CO_E_RELEASED;
764 return range_Collapse(bStart, &This->start, &This->end);
767 static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG Unit, LONG *pDelta)
769 ITextRangeImpl *This = impl_from_ITextRange(me);
770 if (!This->reOle)
771 return CO_E_RELEASED;
773 FIXME("not implemented %p\n", This);
774 return E_NOTIMPL;
777 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG Unit, LONG *pIndex)
779 ITextRangeImpl *This = impl_from_ITextRange(me);
780 if (!This->reOle)
781 return CO_E_RELEASED;
783 FIXME("not implemented %p\n", This);
784 return E_NOTIMPL;
787 static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG Unit, LONG Index,
788 LONG Extend)
790 ITextRangeImpl *This = impl_from_ITextRange(me);
791 if (!This->reOle)
792 return CO_E_RELEASED;
794 FIXME("not implemented %p\n", This);
795 return E_NOTIMPL;
798 static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG cpActive, LONG cpOther)
800 ITextRangeImpl *This = impl_from_ITextRange(me);
801 if (!This->reOle)
802 return CO_E_RELEASED;
804 FIXME("not implemented %p\n", This);
805 return E_NOTIMPL;
808 static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *pRange, LONG *pb)
810 ITextRangeImpl *This = impl_from_ITextRange(me);
811 if (!This->reOle)
812 return CO_E_RELEASED;
814 FIXME("not implemented %p\n", This);
815 return E_NOTIMPL;
818 static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *pb)
820 ITextRangeImpl *This = impl_from_ITextRange(me);
821 if (!This->reOle)
822 return CO_E_RELEASED;
824 FIXME("not implemented %p\n", This);
825 return E_NOTIMPL;
828 static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *pRange, LONG *pb)
830 ITextRangeImpl *This = impl_from_ITextRange(me);
831 if (!This->reOle)
832 return CO_E_RELEASED;
834 FIXME("not implemented %p\n", This);
835 return E_NOTIMPL;
838 static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me)
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_fnStartOf(ITextRange *me, LONG Unit, LONG Extend,
849 LONG *pDelta)
851 ITextRangeImpl *This = impl_from_ITextRange(me);
852 if (!This->reOle)
853 return CO_E_RELEASED;
855 FIXME("not implemented %p\n", This);
856 return E_NOTIMPL;
859 static HRESULT WINAPI ITextRange_fnEndOf(ITextRange *me, LONG Unit, LONG Extend,
860 LONG *pDelta)
862 ITextRangeImpl *This = impl_from_ITextRange(me);
863 if (!This->reOle)
864 return CO_E_RELEASED;
866 FIXME("not implemented %p\n", This);
867 return E_NOTIMPL;
870 static HRESULT WINAPI ITextRange_fnMove(ITextRange *me, LONG Unit, LONG Count, 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_fnMoveStart(ITextRange *me, LONG Unit, 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_fnMoveEnd(ITextRange *me, LONG Unit, 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_fnMoveWhile(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_fnMoveStartWhile(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_fnMoveEndWhile(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_fnMoveUntil(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_fnMoveStartUntil(ITextRange *me, VARIANT *Cset, LONG Count,
947 LONG *pDelta)
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_fnMoveEndUntil(ITextRange *me, VARIANT *Cset, LONG Count,
958 LONG *pDelta)
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_fnFindText(ITextRange *me, BSTR bstr, LONG cch, LONG Flags,
969 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_fnFindTextStart(ITextRange *me, BSTR bstr, LONG cch,
980 LONG Flags, LONG *pLength)
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_fnFindTextEnd(ITextRange *me, BSTR bstr, LONG cch,
991 LONG Flags, LONG *pLength)
993 ITextRangeImpl *This = impl_from_ITextRange(me);
994 if (!This->reOle)
995 return CO_E_RELEASED;
997 FIXME("not implemented %p\n", This);
998 return E_NOTIMPL;
1001 static HRESULT WINAPI ITextRange_fnDelete(ITextRange *me, LONG Unit, LONG Count,
1002 LONG *pDelta)
1004 ITextRangeImpl *This = impl_from_ITextRange(me);
1005 if (!This->reOle)
1006 return CO_E_RELEASED;
1008 FIXME("not implemented %p\n", This);
1009 return E_NOTIMPL;
1012 static HRESULT WINAPI ITextRange_fnCut(ITextRange *me, VARIANT *pVar)
1014 ITextRangeImpl *This = impl_from_ITextRange(me);
1015 if (!This->reOle)
1016 return CO_E_RELEASED;
1018 FIXME("not implemented %p\n", This);
1019 return E_NOTIMPL;
1022 static HRESULT WINAPI ITextRange_fnCopy(ITextRange *me, VARIANT *pVar)
1024 ITextRangeImpl *This = impl_from_ITextRange(me);
1025 if (!This->reOle)
1026 return CO_E_RELEASED;
1028 FIXME("not implemented %p\n", This);
1029 return E_NOTIMPL;
1032 static HRESULT WINAPI ITextRange_fnPaste(ITextRange *me, VARIANT *pVar, LONG Format)
1034 ITextRangeImpl *This = impl_from_ITextRange(me);
1035 if (!This->reOle)
1036 return CO_E_RELEASED;
1038 FIXME("not implemented %p\n", This);
1039 return E_NOTIMPL;
1042 static HRESULT WINAPI ITextRange_fnCanPaste(ITextRange *me, VARIANT *pVar, LONG Format,
1043 LONG *pb)
1045 ITextRangeImpl *This = impl_from_ITextRange(me);
1046 if (!This->reOle)
1047 return CO_E_RELEASED;
1049 FIXME("not implemented %p\n", This);
1050 return E_NOTIMPL;
1053 static HRESULT WINAPI ITextRange_fnCanEdit(ITextRange *me, LONG *pb)
1055 ITextRangeImpl *This = impl_from_ITextRange(me);
1056 if (!This->reOle)
1057 return CO_E_RELEASED;
1059 FIXME("not implemented %p\n", This);
1060 return E_NOTIMPL;
1063 static HRESULT WINAPI ITextRange_fnChangeCase(ITextRange *me, LONG Type)
1065 ITextRangeImpl *This = impl_from_ITextRange(me);
1066 if (!This->reOle)
1067 return CO_E_RELEASED;
1069 FIXME("not implemented %p\n", This);
1070 return E_NOTIMPL;
1073 static HRESULT WINAPI ITextRange_fnGetPoint(ITextRange *me, LONG Type, LONG *cx, LONG *cy)
1075 ITextRangeImpl *This = impl_from_ITextRange(me);
1076 if (!This->reOle)
1077 return CO_E_RELEASED;
1079 FIXME("not implemented %p\n", This);
1080 return E_NOTIMPL;
1083 static HRESULT WINAPI ITextRange_fnSetPoint(ITextRange *me, LONG x, LONG y, LONG Type,
1084 LONG Extend)
1086 ITextRangeImpl *This = impl_from_ITextRange(me);
1087 if (!This->reOle)
1088 return CO_E_RELEASED;
1090 FIXME("not implemented %p\n", This);
1091 return E_NOTIMPL;
1094 static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG Value)
1096 ITextRangeImpl *This = impl_from_ITextRange(me);
1097 if (!This->reOle)
1098 return CO_E_RELEASED;
1100 FIXME("not implemented %p\n", This);
1101 return E_NOTIMPL;
1104 static HRESULT WINAPI ITextRange_fnGetEmbeddedObject(ITextRange *me, IUnknown **ppv)
1106 ITextRangeImpl *This = impl_from_ITextRange(me);
1107 if (!This->reOle)
1108 return CO_E_RELEASED;
1110 FIXME("not implemented %p\n", This);
1111 return E_NOTIMPL;
1114 static const ITextRangeVtbl trvt = {
1115 ITextRange_fnQueryInterface,
1116 ITextRange_fnAddRef,
1117 ITextRange_fnRelease,
1118 ITextRange_fnGetTypeInfoCount,
1119 ITextRange_fnGetTypeInfo,
1120 ITextRange_fnGetIDsOfNames,
1121 ITextRange_fnInvoke,
1122 ITextRange_fnGetText,
1123 ITextRange_fnSetText,
1124 ITextRange_fnGetChar,
1125 ITextRange_fnSetChar,
1126 ITextRange_fnGetDuplicate,
1127 ITextRange_fnGetFormattedText,
1128 ITextRange_fnSetFormattedText,
1129 ITextRange_fnGetStart,
1130 ITextRange_fnSetStart,
1131 ITextRange_fnGetEnd,
1132 ITextRange_fnSetEnd,
1133 ITextRange_fnGetFont,
1134 ITextRange_fnSetFont,
1135 ITextRange_fnGetPara,
1136 ITextRange_fnSetPara,
1137 ITextRange_fnGetStoryLength,
1138 ITextRange_fnGetStoryType,
1139 ITextRange_fnCollapse,
1140 ITextRange_fnExpand,
1141 ITextRange_fnGetIndex,
1142 ITextRange_fnSetIndex,
1143 ITextRange_fnSetRange,
1144 ITextRange_fnInRange,
1145 ITextRange_fnInStory,
1146 ITextRange_fnIsEqual,
1147 ITextRange_fnSelect,
1148 ITextRange_fnStartOf,
1149 ITextRange_fnEndOf,
1150 ITextRange_fnMove,
1151 ITextRange_fnMoveStart,
1152 ITextRange_fnMoveEnd,
1153 ITextRange_fnMoveWhile,
1154 ITextRange_fnMoveStartWhile,
1155 ITextRange_fnMoveEndWhile,
1156 ITextRange_fnMoveUntil,
1157 ITextRange_fnMoveStartUntil,
1158 ITextRange_fnMoveEndUntil,
1159 ITextRange_fnFindText,
1160 ITextRange_fnFindTextStart,
1161 ITextRange_fnFindTextEnd,
1162 ITextRange_fnDelete,
1163 ITextRange_fnCut,
1164 ITextRange_fnCopy,
1165 ITextRange_fnPaste,
1166 ITextRange_fnCanPaste,
1167 ITextRange_fnCanEdit,
1168 ITextRange_fnChangeCase,
1169 ITextRange_fnGetPoint,
1170 ITextRange_fnSetPoint,
1171 ITextRange_fnScrollIntoView,
1172 ITextRange_fnGetEmbeddedObject
1174 /* ITextRange interface */
1176 static HRESULT WINAPI
1177 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
1178 void** ppvObject)
1180 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1181 return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
1184 static ULONG WINAPI
1185 ITextDocument_fnAddRef(ITextDocument* me)
1187 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1188 return IRichEditOle_AddRef(&This->IRichEditOle_iface);
1191 static ULONG WINAPI
1192 ITextDocument_fnRelease(ITextDocument* me)
1194 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1195 return IRichEditOle_Release(&This->IRichEditOle_iface);
1198 static HRESULT WINAPI
1199 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
1200 UINT* pctinfo)
1202 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1203 FIXME("stub %p\n",This);
1204 return E_NOTIMPL;
1207 static HRESULT WINAPI
1208 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
1209 ITypeInfo** ppTInfo)
1211 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1212 FIXME("stub %p\n",This);
1213 return E_NOTIMPL;
1216 static HRESULT WINAPI
1217 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
1218 LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
1220 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1221 FIXME("stub %p\n",This);
1222 return E_NOTIMPL;
1225 static HRESULT WINAPI
1226 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
1227 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1228 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1230 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1231 FIXME("stub %p\n",This);
1232 return E_NOTIMPL;
1235 static HRESULT WINAPI
1236 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
1238 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1239 FIXME("stub %p\n",This);
1240 return E_NOTIMPL;
1243 static HRESULT WINAPI
1244 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
1246 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1247 TRACE("(%p)\n", me);
1249 if(!ppSel)
1250 return E_INVALIDARG;
1251 *ppSel = &This->txtSel->ITextSelection_iface;
1252 ITextSelection_AddRef(*ppSel);
1253 return S_OK;
1256 static HRESULT WINAPI
1257 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
1259 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1260 FIXME("stub %p\n",This);
1261 return E_NOTIMPL;
1264 static HRESULT WINAPI
1265 ITextDocument_fnGetStoryRanges(ITextDocument* me,
1266 ITextStoryRanges** ppStories)
1268 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1269 FIXME("stub %p\n",This);
1270 return E_NOTIMPL;
1273 static HRESULT WINAPI
1274 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
1276 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1277 FIXME("stub %p\n",This);
1278 return E_NOTIMPL;
1281 static HRESULT WINAPI
1282 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
1284 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1285 FIXME("stub %p\n",This);
1286 return E_NOTIMPL;
1289 static HRESULT WINAPI
1290 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
1292 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1293 FIXME("stub %p\n",This);
1294 return E_NOTIMPL;
1297 static HRESULT WINAPI
1298 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
1300 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1301 FIXME("stub %p\n",This);
1302 return E_NOTIMPL;
1305 static HRESULT WINAPI
1306 ITextDocument_fnNew(ITextDocument* me)
1308 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1309 FIXME("stub %p\n",This);
1310 return E_NOTIMPL;
1313 static HRESULT WINAPI
1314 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
1315 LONG CodePage)
1317 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1318 FIXME("stub %p\n",This);
1319 return E_NOTIMPL;
1322 static HRESULT WINAPI
1323 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
1324 LONG CodePage)
1326 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1327 FIXME("stub %p\n",This);
1328 return E_NOTIMPL;
1331 static HRESULT WINAPI
1332 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
1334 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1335 FIXME("stub %p\n",This);
1336 return E_NOTIMPL;
1339 static HRESULT WINAPI
1340 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
1342 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1343 FIXME("stub %p\n",This);
1344 return E_NOTIMPL;
1347 static HRESULT WINAPI
1348 ITextDocument_fnBeginEditCollection(ITextDocument* me)
1350 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1351 FIXME("stub %p\n",This);
1352 return E_NOTIMPL;
1355 static HRESULT WINAPI
1356 ITextDocument_fnEndEditCollection(ITextDocument* me)
1358 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1359 FIXME("stub %p\n",This);
1360 return E_NOTIMPL;
1363 static HRESULT WINAPI
1364 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
1366 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1367 FIXME("stub %p\n",This);
1368 return E_NOTIMPL;
1371 static HRESULT WINAPI
1372 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
1374 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1375 FIXME("stub %p\n",This);
1376 return E_NOTIMPL;
1379 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
1381 ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
1383 if (!txtRge)
1384 return E_OUTOFMEMORY;
1385 txtRge->ITextRange_iface.lpVtbl = &trvt;
1386 txtRge->ref = 1;
1387 txtRge->reOle = reOle;
1388 txtRge->start = start;
1389 txtRge->end = end;
1390 list_add_head(&reOle->rangelist, &txtRge->entry);
1391 *ppRange = &txtRge->ITextRange_iface;
1392 return S_OK;
1395 static HRESULT WINAPI
1396 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
1397 ITextRange** ppRange)
1399 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1400 const int len = ME_GetTextLength(This->editor) + 1;
1402 TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
1403 if (!ppRange)
1404 return E_INVALIDARG;
1406 cp1 = max(cp1, 0);
1407 cp2 = max(cp2, 0);
1408 cp1 = min(cp1, len);
1409 cp2 = min(cp2, len);
1410 if (cp1 > cp2)
1412 LONG tmp;
1413 tmp = cp1;
1414 cp1 = cp2;
1415 cp2 = tmp;
1417 if (cp1 == len)
1418 cp1 = cp2 = len - 1;
1420 return CreateITextRange(This, cp1, cp2, ppRange);
1423 static HRESULT WINAPI
1424 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
1425 ITextRange** ppRange)
1427 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1428 FIXME("stub %p\n",This);
1429 return E_NOTIMPL;
1432 static const ITextDocumentVtbl tdvt = {
1433 ITextDocument_fnQueryInterface,
1434 ITextDocument_fnAddRef,
1435 ITextDocument_fnRelease,
1436 ITextDocument_fnGetTypeInfoCount,
1437 ITextDocument_fnGetTypeInfo,
1438 ITextDocument_fnGetIDsOfNames,
1439 ITextDocument_fnInvoke,
1440 ITextDocument_fnGetName,
1441 ITextDocument_fnGetSelection,
1442 ITextDocument_fnGetStoryCount,
1443 ITextDocument_fnGetStoryRanges,
1444 ITextDocument_fnGetSaved,
1445 ITextDocument_fnSetSaved,
1446 ITextDocument_fnGetDefaultTabStop,
1447 ITextDocument_fnSetDefaultTabStop,
1448 ITextDocument_fnNew,
1449 ITextDocument_fnOpen,
1450 ITextDocument_fnSave,
1451 ITextDocument_fnFreeze,
1452 ITextDocument_fnUnfreeze,
1453 ITextDocument_fnBeginEditCollection,
1454 ITextDocument_fnEndEditCollection,
1455 ITextDocument_fnUndo,
1456 ITextDocument_fnRedo,
1457 ITextDocument_fnRange,
1458 ITextDocument_fnRangeFromPoint
1461 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
1463 return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
1466 static HRESULT WINAPI ITextSelection_fnQueryInterface(
1467 ITextSelection *me,
1468 REFIID riid,
1469 void **ppvObj)
1471 *ppvObj = NULL;
1472 if (IsEqualGUID(riid, &IID_IUnknown)
1473 || IsEqualGUID(riid, &IID_IDispatch)
1474 || IsEqualGUID(riid, &IID_ITextRange)
1475 || IsEqualGUID(riid, &IID_ITextSelection))
1477 *ppvObj = me;
1478 ITextSelection_AddRef(me);
1479 return S_OK;
1482 return E_NOINTERFACE;
1485 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
1487 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1488 return InterlockedIncrement(&This->ref);
1491 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
1493 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1494 ULONG ref = InterlockedDecrement(&This->ref);
1495 if (ref == 0)
1496 heap_free(This);
1497 return ref;
1500 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
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_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
1511 ITypeInfo **ppTInfo)
1513 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1514 if (!This->reOle)
1515 return CO_E_RELEASED;
1517 FIXME("not implemented\n");
1518 return E_NOTIMPL;
1521 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
1522 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1524 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1525 if (!This->reOle)
1526 return CO_E_RELEASED;
1528 FIXME("not implemented\n");
1529 return E_NOTIMPL;
1532 static HRESULT WINAPI ITextSelection_fnInvoke(
1533 ITextSelection *me,
1534 DISPID dispIdMember,
1535 REFIID riid,
1536 LCID lcid,
1537 WORD wFlags,
1538 DISPPARAMS *pDispParams,
1539 VARIANT *pVarResult,
1540 EXCEPINFO *pExcepInfo,
1541 UINT *puArgErr)
1543 FIXME("not implemented\n");
1544 return E_NOTIMPL;
1547 /*** ITextRange methods ***/
1548 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
1550 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1551 ME_Cursor *start = NULL, *end = NULL;
1552 int nChars, endOfs;
1553 BOOL bEOP;
1555 if (!This->reOle)
1556 return CO_E_RELEASED;
1557 TRACE("%p\n", pbstr);
1558 if (!pbstr)
1559 return E_INVALIDARG;
1561 ME_GetSelection(This->reOle->editor, &start, &end);
1562 endOfs = ME_GetCursorOfs(end);
1563 nChars = endOfs - ME_GetCursorOfs(start);
1564 if (!nChars)
1566 *pbstr = NULL;
1567 return S_OK;
1570 *pbstr = SysAllocStringLen(NULL, nChars);
1571 if (!*pbstr)
1572 return E_OUTOFMEMORY;
1574 bEOP = (end->pRun->next->type == diTextEnd && endOfs > ME_GetTextLength(This->reOle->editor));
1575 ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
1576 TRACE("%s\n", wine_dbgstr_w(*pbstr));
1578 return S_OK;
1581 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
1583 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1584 if (!This->reOle)
1585 return CO_E_RELEASED;
1587 FIXME("not implemented\n");
1588 return E_NOTIMPL;
1591 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
1593 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1594 ME_Cursor *start = NULL, *end = NULL;
1596 if (!This->reOle)
1597 return CO_E_RELEASED;
1598 TRACE("%p\n", pch);
1599 if (!pch)
1600 return E_INVALIDARG;
1602 ME_GetSelection(This->reOle->editor, &start, &end);
1603 return range_GetChar(This->reOle->editor, start, pch);
1606 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
1608 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1609 if (!This->reOle)
1610 return CO_E_RELEASED;
1612 FIXME("not implemented\n");
1613 return E_NOTIMPL;
1616 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
1618 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1619 if (!This->reOle)
1620 return CO_E_RELEASED;
1622 FIXME("not implemented\n");
1623 return E_NOTIMPL;
1626 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)
1628 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1629 if (!This->reOle)
1630 return CO_E_RELEASED;
1632 FIXME("not implemented\n");
1633 return E_NOTIMPL;
1636 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *pRange)
1638 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1639 if (!This->reOle)
1640 return CO_E_RELEASED;
1642 FIXME("not implemented\n");
1643 return E_NOTIMPL;
1646 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
1648 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1649 LONG lim;
1650 if (!This->reOle)
1651 return CO_E_RELEASED;
1653 if (!pcpFirst)
1654 return E_INVALIDARG;
1655 ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim);
1656 TRACE("%d\n", *pcpFirst);
1657 return S_OK;
1660 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst)
1662 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1663 if (!This->reOle)
1664 return CO_E_RELEASED;
1666 FIXME("not implemented\n");
1667 return E_NOTIMPL;
1670 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
1672 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1673 LONG first;
1674 if (!This->reOle)
1675 return CO_E_RELEASED;
1677 if (!pcpLim)
1678 return E_INVALIDARG;
1679 ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim);
1680 TRACE("%d\n", *pcpLim);
1681 return S_OK;
1684 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
1686 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1687 if (!This->reOle)
1688 return CO_E_RELEASED;
1690 FIXME("not implemented\n");
1691 return E_NOTIMPL;
1694 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **pFont)
1696 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1697 if (!This->reOle)
1698 return CO_E_RELEASED;
1700 FIXME("not implemented\n");
1701 return E_NOTIMPL;
1704 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
1706 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1707 if (!This->reOle)
1708 return CO_E_RELEASED;
1710 FIXME("not implemented\n");
1711 return E_NOTIMPL;
1714 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **ppPara)
1716 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1717 if (!This->reOle)
1718 return CO_E_RELEASED;
1720 FIXME("not implemented\n");
1721 return E_NOTIMPL;
1724 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pPara)
1726 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1727 if (!This->reOle)
1728 return CO_E_RELEASED;
1730 FIXME("not implemented\n");
1731 return E_NOTIMPL;
1734 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *pcch)
1736 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1737 if (!This->reOle)
1738 return CO_E_RELEASED;
1740 FIXME("not implemented\n");
1741 return E_NOTIMPL;
1744 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pValue)
1746 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1747 if (!This->reOle)
1748 return CO_E_RELEASED;
1750 FIXME("not implemented\n");
1751 return E_NOTIMPL;
1754 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
1756 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1757 LONG start, end;
1758 HRESULT hres;
1759 if (!This->reOle)
1760 return CO_E_RELEASED;
1762 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
1763 hres = range_Collapse(bStart, &start, &end);
1764 if (SUCCEEDED(hres))
1765 ME_SetSelection(This->reOle->editor, start, end);
1766 return hres;
1769 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
1771 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1772 if (!This->reOle)
1773 return CO_E_RELEASED;
1775 FIXME("not implemented\n");
1776 return E_NOTIMPL;
1779 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
1781 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1782 if (!This->reOle)
1783 return CO_E_RELEASED;
1785 FIXME("not implemented\n");
1786 return E_NOTIMPL;
1789 static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG Unit, LONG Index,
1790 LONG Extend)
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_fnSetRange(ITextSelection *me, LONG cpActive, LONG cpOther)
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_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
1812 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1813 if (!This->reOle)
1814 return CO_E_RELEASED;
1816 FIXME("not implemented\n");
1817 return E_NOTIMPL;
1820 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)
1822 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1823 if (!This->reOle)
1824 return CO_E_RELEASED;
1826 FIXME("not implemented\n");
1827 return E_NOTIMPL;
1830 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb)
1832 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1833 if (!This->reOle)
1834 return CO_E_RELEASED;
1836 FIXME("not implemented\n");
1837 return E_NOTIMPL;
1840 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
1842 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1843 if (!This->reOle)
1844 return CO_E_RELEASED;
1846 FIXME("not implemented\n");
1847 return E_NOTIMPL;
1850 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG Unit, LONG Extend,
1851 LONG *pDelta)
1853 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1854 if (!This->reOle)
1855 return CO_E_RELEASED;
1857 FIXME("not implemented\n");
1858 return E_NOTIMPL;
1861 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG Extend,
1862 LONG *pDelta)
1864 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1865 if (!This->reOle)
1866 return CO_E_RELEASED;
1868 FIXME("not implemented\n");
1869 return E_NOTIMPL;
1872 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG Unit, LONG Count, LONG *pDelta)
1874 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1875 if (!This->reOle)
1876 return CO_E_RELEASED;
1878 FIXME("not implemented\n");
1879 return E_NOTIMPL;
1882 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG Unit, LONG Count,
1883 LONG *pDelta)
1885 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1886 if (!This->reOle)
1887 return CO_E_RELEASED;
1889 FIXME("not implemented\n");
1890 return E_NOTIMPL;
1893 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG Unit, LONG Count,
1894 LONG *pDelta)
1896 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1897 if (!This->reOle)
1898 return CO_E_RELEASED;
1900 FIXME("not implemented\n");
1901 return E_NOTIMPL;
1904 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1905 LONG *pDelta)
1907 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1908 if (!This->reOle)
1909 return CO_E_RELEASED;
1911 FIXME("not implemented\n");
1912 return E_NOTIMPL;
1915 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1916 LONG *pDelta)
1918 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1919 if (!This->reOle)
1920 return CO_E_RELEASED;
1922 FIXME("not implemented\n");
1923 return E_NOTIMPL;
1926 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1927 LONG *pDelta)
1929 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1930 if (!This->reOle)
1931 return CO_E_RELEASED;
1933 FIXME("not implemented\n");
1934 return E_NOTIMPL;
1937 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1938 LONG *pDelta)
1940 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1941 if (!This->reOle)
1942 return CO_E_RELEASED;
1944 FIXME("not implemented\n");
1945 return E_NOTIMPL;
1948 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1949 LONG *pDelta)
1951 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1952 if (!This->reOle)
1953 return CO_E_RELEASED;
1955 FIXME("not implemented\n");
1956 return E_NOTIMPL;
1959 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1960 LONG *pDelta)
1962 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1963 if (!This->reOle)
1964 return CO_E_RELEASED;
1966 FIXME("not implemented\n");
1967 return E_NOTIMPL;
1970 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR bstr, LONG cch, LONG Flags,
1971 LONG *pLength)
1973 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1974 if (!This->reOle)
1975 return CO_E_RELEASED;
1977 FIXME("not implemented\n");
1978 return E_NOTIMPL;
1981 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR bstr, LONG cch,
1982 LONG Flags, LONG *pLength)
1984 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1985 if (!This->reOle)
1986 return CO_E_RELEASED;
1988 FIXME("not implemented\n");
1989 return E_NOTIMPL;
1992 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR bstr, LONG cch,
1993 LONG Flags, LONG *pLength)
1995 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1996 if (!This->reOle)
1997 return CO_E_RELEASED;
1999 FIXME("not implemented\n");
2000 return E_NOTIMPL;
2003 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG Unit, LONG Count,
2004 LONG *pDelta)
2006 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2007 if (!This->reOle)
2008 return CO_E_RELEASED;
2010 FIXME("not implemented\n");
2011 return E_NOTIMPL;
2014 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *pVar)
2016 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2017 if (!This->reOle)
2018 return CO_E_RELEASED;
2020 FIXME("not implemented\n");
2021 return E_NOTIMPL;
2024 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *pVar)
2026 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2027 if (!This->reOle)
2028 return CO_E_RELEASED;
2030 FIXME("not implemented\n");
2031 return E_NOTIMPL;
2034 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *pVar, LONG Format)
2036 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2037 if (!This->reOle)
2038 return CO_E_RELEASED;
2040 FIXME("not implemented\n");
2041 return E_NOTIMPL;
2044 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *pVar, LONG Format,
2045 LONG *pb)
2047 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2048 if (!This->reOle)
2049 return CO_E_RELEASED;
2051 FIXME("not implemented\n");
2052 return E_NOTIMPL;
2055 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *pb)
2057 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2058 if (!This->reOle)
2059 return CO_E_RELEASED;
2061 FIXME("not implemented\n");
2062 return E_NOTIMPL;
2065 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG Type)
2067 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2068 if (!This->reOle)
2069 return CO_E_RELEASED;
2071 FIXME("not implemented\n");
2072 return E_NOTIMPL;
2075 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG Type, LONG *cx, LONG *cy)
2077 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2078 if (!This->reOle)
2079 return CO_E_RELEASED;
2081 FIXME("not implemented\n");
2082 return E_NOTIMPL;
2085 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG Type,
2086 LONG Extend)
2088 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2089 if (!This->reOle)
2090 return CO_E_RELEASED;
2092 FIXME("not implemented\n");
2093 return E_NOTIMPL;
2096 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG Value)
2098 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2099 if (!This->reOle)
2100 return CO_E_RELEASED;
2102 FIXME("not implemented\n");
2103 return E_NOTIMPL;
2106 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
2108 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2109 if (!This->reOle)
2110 return CO_E_RELEASED;
2112 FIXME("not implemented\n");
2113 return E_NOTIMPL;
2116 /*** ITextSelection methods ***/
2117 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags)
2119 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2120 if (!This->reOle)
2121 return CO_E_RELEASED;
2123 FIXME("not implemented\n");
2124 return E_NOTIMPL;
2127 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
2129 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2130 if (!This->reOle)
2131 return CO_E_RELEASED;
2133 FIXME("not implemented\n");
2134 return E_NOTIMPL;
2137 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *pType)
2139 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2140 if (!This->reOle)
2141 return CO_E_RELEASED;
2143 FIXME("not implemented\n");
2144 return E_NOTIMPL;
2147 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG Unit, LONG Count,
2148 LONG Extend, LONG *pDelta)
2150 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2151 if (!This->reOle)
2152 return CO_E_RELEASED;
2154 FIXME("not implemented\n");
2155 return E_NOTIMPL;
2158 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG Unit, LONG Count,
2159 LONG Extend, LONG *pDelta)
2161 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2162 if (!This->reOle)
2163 return CO_E_RELEASED;
2165 FIXME("not implemented\n");
2166 return E_NOTIMPL;
2169 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG Unit, LONG Count,
2170 LONG Extend, LONG *pDelta)
2172 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2173 if (!This->reOle)
2174 return CO_E_RELEASED;
2176 FIXME("not implemented\n");
2177 return E_NOTIMPL;
2180 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG Unit, LONG Count,
2181 LONG Extend, LONG *pDelta)
2183 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2184 if (!This->reOle)
2185 return CO_E_RELEASED;
2187 FIXME("not implemented\n");
2188 return E_NOTIMPL;
2191 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG Unit, LONG Extend,
2192 LONG *pDelta)
2194 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2195 if (!This->reOle)
2196 return CO_E_RELEASED;
2198 FIXME("not implemented\n");
2199 return E_NOTIMPL;
2202 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LONG Extend,
2203 LONG *pDelta)
2205 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2206 if (!This->reOle)
2207 return CO_E_RELEASED;
2209 FIXME("not implemented\n");
2210 return E_NOTIMPL;
2213 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR bstr)
2215 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2216 if (!This->reOle)
2217 return CO_E_RELEASED;
2219 FIXME("not implemented\n");
2220 return E_NOTIMPL;
2223 static const ITextSelectionVtbl tsvt = {
2224 ITextSelection_fnQueryInterface,
2225 ITextSelection_fnAddRef,
2226 ITextSelection_fnRelease,
2227 ITextSelection_fnGetTypeInfoCount,
2228 ITextSelection_fnGetTypeInfo,
2229 ITextSelection_fnGetIDsOfNames,
2230 ITextSelection_fnInvoke,
2231 ITextSelection_fnGetText,
2232 ITextSelection_fnSetText,
2233 ITextSelection_fnGetChar,
2234 ITextSelection_fnSetChar,
2235 ITextSelection_fnGetDuplicate,
2236 ITextSelection_fnGetFormattedText,
2237 ITextSelection_fnSetFormattedText,
2238 ITextSelection_fnGetStart,
2239 ITextSelection_fnSetStart,
2240 ITextSelection_fnGetEnd,
2241 ITextSelection_fnSetEnd,
2242 ITextSelection_fnGetFont,
2243 ITextSelection_fnSetFont,
2244 ITextSelection_fnGetPara,
2245 ITextSelection_fnSetPara,
2246 ITextSelection_fnGetStoryLength,
2247 ITextSelection_fnGetStoryType,
2248 ITextSelection_fnCollapse,
2249 ITextSelection_fnExpand,
2250 ITextSelection_fnGetIndex,
2251 ITextSelection_fnSetIndex,
2252 ITextSelection_fnSetRange,
2253 ITextSelection_fnInRange,
2254 ITextSelection_fnInStory,
2255 ITextSelection_fnIsEqual,
2256 ITextSelection_fnSelect,
2257 ITextSelection_fnStartOf,
2258 ITextSelection_fnEndOf,
2259 ITextSelection_fnMove,
2260 ITextSelection_fnMoveStart,
2261 ITextSelection_fnMoveEnd,
2262 ITextSelection_fnMoveWhile,
2263 ITextSelection_fnMoveStartWhile,
2264 ITextSelection_fnMoveEndWhile,
2265 ITextSelection_fnMoveUntil,
2266 ITextSelection_fnMoveStartUntil,
2267 ITextSelection_fnMoveEndUntil,
2268 ITextSelection_fnFindText,
2269 ITextSelection_fnFindTextStart,
2270 ITextSelection_fnFindTextEnd,
2271 ITextSelection_fnDelete,
2272 ITextSelection_fnCut,
2273 ITextSelection_fnCopy,
2274 ITextSelection_fnPaste,
2275 ITextSelection_fnCanPaste,
2276 ITextSelection_fnCanEdit,
2277 ITextSelection_fnChangeCase,
2278 ITextSelection_fnGetPoint,
2279 ITextSelection_fnSetPoint,
2280 ITextSelection_fnScrollIntoView,
2281 ITextSelection_fnGetEmbeddedObject,
2282 ITextSelection_fnGetFlags,
2283 ITextSelection_fnSetFlags,
2284 ITextSelection_fnGetType,
2285 ITextSelection_fnMoveLeft,
2286 ITextSelection_fnMoveRight,
2287 ITextSelection_fnMoveUp,
2288 ITextSelection_fnMoveDown,
2289 ITextSelection_fnHomeKey,
2290 ITextSelection_fnEndKey,
2291 ITextSelection_fnTypeText
2294 static ITextSelectionImpl *
2295 CreateTextSelection(IRichEditOleImpl *reOle)
2297 ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
2298 if (!txtSel)
2299 return NULL;
2301 txtSel->ITextSelection_iface.lpVtbl = &tsvt;
2302 txtSel->ref = 1;
2303 txtSel->reOle = reOle;
2304 return txtSel;
2307 LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
2309 IRichEditOleImpl *reo;
2311 reo = heap_alloc(sizeof(IRichEditOleImpl));
2312 if (!reo)
2313 return 0;
2315 reo->IRichEditOle_iface.lpVtbl = &revt;
2316 reo->ITextDocument_iface.lpVtbl = &tdvt;
2317 reo->ref = 1;
2318 reo->editor = editor;
2319 reo->txtSel = CreateTextSelection(reo);
2320 if (!reo->txtSel)
2322 heap_free(reo);
2323 return 0;
2325 reo->clientSite = CreateOleClientSite(reo);
2326 if (!reo->clientSite)
2328 ITextSelection_Release(&reo->txtSel->ITextSelection_iface);
2329 heap_free(reo);
2330 return 0;
2332 TRACE("Created %p\n",reo);
2333 *ppObj = reo;
2334 list_init(&reo->rangelist);
2336 return 1;
2339 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
2341 /* sizel is in .01 millimeters, sz in pixels */
2342 sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
2343 sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
2346 /******************************************************************************
2347 * ME_GetOLEObjectSize
2349 * Sets run extent for OLE objects.
2351 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
2353 IDataObject* ido;
2354 FORMATETC fmt;
2355 STGMEDIUM stgm;
2356 DIBSECTION dibsect;
2357 ENHMETAHEADER emh;
2359 assert(run->nFlags & MERF_GRAPHICS);
2360 assert(run->ole_obj);
2362 if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
2364 convert_sizel(c, &run->ole_obj->sizel, pSize);
2365 if (c->editor->nZoomNumerator != 0)
2367 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2368 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2370 return;
2373 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
2375 FIXME("Query Interface IID_IDataObject failed!\n");
2376 pSize->cx = pSize->cy = 0;
2377 return;
2379 fmt.cfFormat = CF_BITMAP;
2380 fmt.ptd = NULL;
2381 fmt.dwAspect = DVASPECT_CONTENT;
2382 fmt.lindex = -1;
2383 fmt.tymed = TYMED_GDI;
2384 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2386 fmt.cfFormat = CF_ENHMETAFILE;
2387 fmt.tymed = TYMED_ENHMF;
2388 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2390 FIXME("unsupported format\n");
2391 pSize->cx = pSize->cy = 0;
2392 IDataObject_Release(ido);
2393 return;
2397 switch (stgm.tymed)
2399 case TYMED_GDI:
2400 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
2401 pSize->cx = dibsect.dsBm.bmWidth;
2402 pSize->cy = dibsect.dsBm.bmHeight;
2403 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
2404 break;
2405 case TYMED_ENHMF:
2406 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
2407 pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
2408 pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
2409 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
2410 break;
2411 default:
2412 FIXME("Unsupported tymed %d\n", stgm.tymed);
2413 break;
2415 IDataObject_Release(ido);
2416 if (c->editor->nZoomNumerator != 0)
2418 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2419 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2423 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
2424 ME_Paragraph *para, BOOL selected)
2426 IDataObject* ido;
2427 FORMATETC fmt;
2428 STGMEDIUM stgm;
2429 DIBSECTION dibsect;
2430 ENHMETAHEADER emh;
2431 HDC hMemDC;
2432 SIZE sz;
2433 BOOL has_size;
2435 assert(run->nFlags & MERF_GRAPHICS);
2436 assert(run->ole_obj);
2437 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
2439 FIXME("Couldn't get interface\n");
2440 return;
2442 has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
2443 fmt.cfFormat = CF_BITMAP;
2444 fmt.ptd = NULL;
2445 fmt.dwAspect = DVASPECT_CONTENT;
2446 fmt.lindex = -1;
2447 fmt.tymed = TYMED_GDI;
2448 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2450 fmt.cfFormat = CF_ENHMETAFILE;
2451 fmt.tymed = TYMED_ENHMF;
2452 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2454 FIXME("Couldn't get storage medium\n");
2455 IDataObject_Release(ido);
2456 return;
2459 switch (stgm.tymed)
2461 case TYMED_GDI:
2462 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
2463 hMemDC = CreateCompatibleDC(c->hDC);
2464 SelectObject(hMemDC, stgm.u.hBitmap);
2465 if (has_size)
2467 convert_sizel(c, &run->ole_obj->sizel, &sz);
2468 } else {
2469 sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
2470 sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
2472 if (c->editor->nZoomNumerator != 0)
2474 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2475 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2477 if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
2479 BitBlt(c->hDC, x, y - sz.cy,
2480 dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
2481 hMemDC, 0, 0, SRCCOPY);
2482 } else {
2483 StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
2484 hMemDC, 0, 0, dibsect.dsBm.bmWidth,
2485 dibsect.dsBm.bmHeight, SRCCOPY);
2487 DeleteDC(hMemDC);
2488 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
2489 break;
2490 case TYMED_ENHMF:
2491 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
2492 if (has_size)
2494 convert_sizel(c, &run->ole_obj->sizel, &sz);
2495 } else {
2496 sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
2497 sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
2499 if (c->editor->nZoomNumerator != 0)
2501 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2502 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2506 RECT rc;
2508 rc.left = x;
2509 rc.top = y - sz.cy;
2510 rc.right = x + sz.cx;
2511 rc.bottom = y;
2512 PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
2514 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
2515 break;
2516 default:
2517 FIXME("Unsupported tymed %d\n", stgm.tymed);
2518 selected = FALSE;
2519 break;
2521 if (selected && !c->editor->bHideSelection)
2522 PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
2523 IDataObject_Release(ido);
2526 void ME_DeleteReObject(REOBJECT* reo)
2528 if (reo->poleobj) IOleObject_Release(reo->poleobj);
2529 if (reo->pstg) IStorage_Release(reo->pstg);
2530 if (reo->polesite) IOleClientSite_Release(reo->polesite);
2531 FREE_OBJ(reo);
2534 void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
2536 *dst = *src;
2538 if (dst->poleobj) IOleObject_AddRef(dst->poleobj);
2539 if (dst->pstg) IStorage_AddRef(dst->pstg);
2540 if (dst->polesite) IOleClientSite_AddRef(dst->polesite);