dwrite: Implement CreateFontFaceFromHdc().
[wine.git] / dlls / riched20 / richole.c
blob9e7c123cde676ab2a2b776863b65eeb713a69073
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 This->editor->reOle = NULL;
146 ITextSelection_Release(&This->txtSel->ITextSelection_iface);
147 IOleClientSite_Release(&This->clientSite->IOleClientSite_iface);
148 LIST_FOR_EACH_ENTRY(txtRge, &This->rangelist, ITextRangeImpl, entry)
149 txtRge->reOle = NULL;
150 heap_free(This);
152 return ref;
155 static HRESULT WINAPI
156 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
158 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
159 FIXME("stub %p\n",This);
160 return E_NOTIMPL;
163 static HRESULT WINAPI
164 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
166 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
167 FIXME("stub %p\n",This);
168 return E_NOTIMPL;
171 static HRESULT WINAPI
172 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
173 REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
175 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
176 FIXME("stub %p\n",This);
177 return E_NOTIMPL;
180 static inline IOleClientSiteImpl *impl_from_IOleClientSite(IOleClientSite *iface)
182 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleClientSite_iface);
185 static HRESULT WINAPI
186 IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
188 TRACE("%p %s\n", me, debugstr_guid(riid) );
190 *ppvObj = NULL;
191 if (IsEqualGUID(riid, &IID_IUnknown) ||
192 IsEqualGUID(riid, &IID_IOleClientSite))
193 *ppvObj = me;
194 if (*ppvObj)
196 IOleClientSite_AddRef(me);
197 return S_OK;
199 FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );
201 return E_NOINTERFACE;
204 static ULONG WINAPI IOleClientSite_fnAddRef(IOleClientSite *iface)
206 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
207 return InterlockedIncrement(&This->ref);
210 static ULONG WINAPI IOleClientSite_fnRelease(IOleClientSite *iface)
212 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
213 ULONG ref = InterlockedDecrement(&This->ref);
214 if (ref == 0)
215 heap_free(This);
216 return ref;
219 static HRESULT WINAPI IOleClientSite_fnSaveObject(IOleClientSite *iface)
221 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
222 if (!This->reOle)
223 return CO_E_RELEASED;
225 FIXME("stub %p\n", iface);
226 return E_NOTIMPL;
230 static HRESULT WINAPI IOleClientSite_fnGetMoniker(IOleClientSite *iface, DWORD dwAssign,
231 DWORD dwWhichMoniker, IMoniker **ppmk)
233 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
234 if (!This->reOle)
235 return CO_E_RELEASED;
237 FIXME("stub %p\n", iface);
238 return E_NOTIMPL;
241 static HRESULT WINAPI IOleClientSite_fnGetContainer(IOleClientSite *iface,
242 IOleContainer **ppContainer)
244 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
245 if (!This->reOle)
246 return CO_E_RELEASED;
248 FIXME("stub %p\n", iface);
249 return E_NOTIMPL;
252 static HRESULT WINAPI IOleClientSite_fnShowObject(IOleClientSite *iface)
254 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
255 if (!This->reOle)
256 return CO_E_RELEASED;
258 FIXME("stub %p\n", iface);
259 return E_NOTIMPL;
262 static HRESULT WINAPI IOleClientSite_fnOnShowWindow(IOleClientSite *iface, BOOL fShow)
264 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
265 if (!This->reOle)
266 return CO_E_RELEASED;
268 FIXME("stub %p\n", iface);
269 return E_NOTIMPL;
272 static HRESULT WINAPI IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *iface)
274 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
275 if (!This->reOle)
276 return CO_E_RELEASED;
278 FIXME("stub %p\n", iface);
279 return E_NOTIMPL;
282 static const IOleClientSiteVtbl ocst = {
283 IOleClientSite_fnQueryInterface,
284 IOleClientSite_fnAddRef,
285 IOleClientSite_fnRelease,
286 IOleClientSite_fnSaveObject,
287 IOleClientSite_fnGetMoniker,
288 IOleClientSite_fnGetContainer,
289 IOleClientSite_fnShowObject,
290 IOleClientSite_fnOnShowWindow,
291 IOleClientSite_fnRequestNewObjectLayout
294 static IOleClientSiteImpl *
295 CreateOleClientSite(IRichEditOleImpl *reOle)
297 IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
298 if (!clientSite)
299 return NULL;
301 clientSite->IOleClientSite_iface.lpVtbl = &ocst;
302 clientSite->ref = 1;
303 clientSite->reOle = reOle;
304 return clientSite;
307 static HRESULT WINAPI
308 IRichEditOle_fnGetClientSite(IRichEditOle *me,
309 LPOLECLIENTSITE *lplpolesite)
311 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
313 TRACE("%p,%p\n",This, lplpolesite);
315 if(!lplpolesite)
316 return E_INVALIDARG;
317 *lplpolesite = &This->clientSite->IOleClientSite_iface;
318 IOleClientSite_AddRef(*lplpolesite);
319 return S_OK;
322 static HRESULT WINAPI
323 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
324 DWORD reco, LPDATAOBJECT *lplpdataobj)
326 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
327 ME_Cursor start;
328 int nChars;
330 TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
331 if(!lplpdataobj)
332 return E_INVALIDARG;
333 if(!lpchrg) {
334 int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
335 start = This->editor->pCursors[nStartCur];
336 nChars = nTo - nFrom;
337 } else {
338 ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
339 nChars = lpchrg->cpMax - lpchrg->cpMin;
341 return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
344 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
346 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
347 FIXME("stub %p\n",This);
348 return E_NOTIMPL;
351 static HRESULT WINAPI
352 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
353 REOBJECT *lpreobject, DWORD dwFlags)
355 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
356 FIXME("stub %p\n",This);
357 return E_NOTIMPL;
360 static LONG WINAPI
361 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
363 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
364 FIXME("stub %p\n",This);
365 return 0;
368 static HRESULT WINAPI
369 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
371 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
372 FIXME("stub %p\n",This);
373 return E_NOTIMPL;
376 static HRESULT WINAPI
377 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
378 CLIPFORMAT cf, HGLOBAL hMetaPict)
380 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
381 FIXME("stub %p\n",This);
382 return E_NOTIMPL;
385 static HRESULT WINAPI
386 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
388 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
389 FIXME("stub %p\n",This);
390 return E_NOTIMPL;
393 static HRESULT WINAPI
394 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
396 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
397 TRACE("(%p,%p)\n", This, reo);
399 if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
401 ME_InsertOLEFromCursor(This->editor, reo, 0);
402 ME_CommitUndo(This->editor);
403 ME_UpdateRepaint(This->editor, FALSE);
404 return S_OK;
407 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
408 LPSTORAGE lpstg)
410 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
411 FIXME("stub %p\n",This);
412 return E_NOTIMPL;
415 static HRESULT WINAPI
416 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
418 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
419 FIXME("stub %p\n",This);
420 return E_NOTIMPL;
423 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
424 LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
426 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
427 FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
428 return E_NOTIMPL;
431 static HRESULT WINAPI
432 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
434 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
435 FIXME("stub %p\n",This);
436 return E_NOTIMPL;
439 static const IRichEditOleVtbl revt = {
440 IRichEditOle_fnQueryInterface,
441 IRichEditOle_fnAddRef,
442 IRichEditOle_fnRelease,
443 IRichEditOle_fnGetClientSite,
444 IRichEditOle_fnGetObjectCount,
445 IRichEditOle_fnGetLinkCount,
446 IRichEditOle_fnGetObject,
447 IRichEditOle_fnInsertObject,
448 IRichEditOle_fnConvertObject,
449 IRichEditOle_fnActivateAs,
450 IRichEditOle_fnSetHostNames,
451 IRichEditOle_fnSetLinkAvailable,
452 IRichEditOle_fnSetDvaspect,
453 IRichEditOle_fnHandsOffStorage,
454 IRichEditOle_fnSaveCompleted,
455 IRichEditOle_fnInPlaceDeactivate,
456 IRichEditOle_fnContextSensitiveHelp,
457 IRichEditOle_fnGetClipboardData,
458 IRichEditOle_fnImportDataObject
461 /* ITextRange interface */
462 static inline ITextRangeImpl *impl_from_ITextRange(ITextRange *iface)
464 return CONTAINING_RECORD(iface, ITextRangeImpl, ITextRange_iface);
467 static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
469 *ppvObj = NULL;
470 if (IsEqualGUID(riid, &IID_IUnknown)
471 || IsEqualGUID(riid, &IID_IDispatch)
472 || IsEqualGUID(riid, &IID_ITextRange))
474 *ppvObj = me;
475 ITextRange_AddRef(me);
476 return S_OK;
479 return E_NOINTERFACE;
482 static ULONG WINAPI ITextRange_fnAddRef(ITextRange *me)
484 ITextRangeImpl *This = impl_from_ITextRange(me);
485 return InterlockedIncrement(&This->ref);
488 static ULONG WINAPI ITextRange_fnRelease(ITextRange *me)
490 ITextRangeImpl *This = impl_from_ITextRange(me);
491 ULONG ref = InterlockedDecrement(&This->ref);
493 TRACE ("%p ref=%u\n", This, ref);
494 if (ref == 0)
496 if (This->reOle)
498 list_remove(&This->entry);
499 This->reOle = NULL;
501 heap_free(This);
503 return ref;
506 static HRESULT WINAPI ITextRange_fnGetTypeInfoCount(ITextRange *me, UINT *pctinfo)
508 ITextRangeImpl *This = impl_from_ITextRange(me);
509 if (!This->reOle)
510 return CO_E_RELEASED;
512 FIXME("not implemented %p\n", This);
513 return E_NOTIMPL;
516 static HRESULT WINAPI ITextRange_fnGetTypeInfo(ITextRange *me, UINT iTInfo, LCID lcid,
517 ITypeInfo **ppTInfo)
519 ITextRangeImpl *This = impl_from_ITextRange(me);
520 if (!This->reOle)
521 return CO_E_RELEASED;
523 FIXME("not implemented %p\n", This);
524 return E_NOTIMPL;
527 static HRESULT WINAPI ITextRange_fnGetIDsOfNames(ITextRange *me, REFIID riid, LPOLESTR *rgszNames,
528 UINT cNames, LCID lcid, DISPID *rgDispId)
530 ITextRangeImpl *This = impl_from_ITextRange(me);
531 if (!This->reOle)
532 return CO_E_RELEASED;
534 FIXME("not implemented %p\n", This);
535 return E_NOTIMPL;
538 static HRESULT WINAPI ITextRange_fnInvoke(ITextRange *me, DISPID dispIdMember, REFIID riid,
539 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
540 VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
541 UINT *puArgErr)
543 ITextRangeImpl *This = impl_from_ITextRange(me);
544 if (!This->reOle)
545 return CO_E_RELEASED;
547 FIXME("not implemented %p\n", This);
548 return E_NOTIMPL;
551 static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *pbstr)
553 ITextRangeImpl *This = impl_from_ITextRange(me);
554 if (!This->reOle)
555 return CO_E_RELEASED;
557 FIXME("not implemented %p\n", This);
558 return E_NOTIMPL;
561 static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR bstr)
563 ITextRangeImpl *This = impl_from_ITextRange(me);
564 if (!This->reOle)
565 return CO_E_RELEASED;
567 FIXME("not implemented %p\n", This);
568 return E_NOTIMPL;
571 static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch)
573 WCHAR wch[2];
575 ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, cursor->pRun->next->type == diTextEnd);
576 *pch = wch[0];
578 return S_OK;
581 static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
583 ITextRangeImpl *This = impl_from_ITextRange(me);
584 ME_Cursor cursor;
586 if (!This->reOle)
587 return CO_E_RELEASED;
588 TRACE("%p\n", pch);
589 if (!pch)
590 return E_INVALIDARG;
592 ME_CursorFromCharOfs(This->reOle->editor, This->start, &cursor);
593 return range_GetChar(This->reOle->editor, &cursor, pch);
596 static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch)
598 ITextRangeImpl *This = impl_from_ITextRange(me);
599 if (!This->reOle)
600 return CO_E_RELEASED;
602 FIXME("not implemented %p\n", This);
603 return E_NOTIMPL;
606 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange);
608 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
610 ITextRangeImpl *This = impl_from_ITextRange(me);
611 if (!This->reOle)
612 return CO_E_RELEASED;
614 TRACE("%p %p\n", This, ppRange);
615 if (!ppRange)
616 return E_INVALIDARG;
618 return CreateITextRange(This->reOle, This->start, This->end, ppRange);
621 static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **ppRange)
623 ITextRangeImpl *This = impl_from_ITextRange(me);
624 if (!This->reOle)
625 return CO_E_RELEASED;
627 FIXME("not implemented %p\n", This);
628 return E_NOTIMPL;
631 static HRESULT WINAPI ITextRange_fnSetFormattedText(ITextRange *me, ITextRange *pRange)
633 ITextRangeImpl *This = impl_from_ITextRange(me);
634 if (!This->reOle)
635 return CO_E_RELEASED;
637 FIXME("not implemented %p\n", This);
638 return E_NOTIMPL;
641 static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *pcpFirst)
643 ITextRangeImpl *This = impl_from_ITextRange(me);
644 if (!This->reOle)
645 return CO_E_RELEASED;
647 if (!pcpFirst)
648 return E_INVALIDARG;
649 *pcpFirst = This->start;
650 TRACE("%d\n", *pcpFirst);
651 return S_OK;
654 static HRESULT WINAPI ITextRange_fnSetStart(ITextRange *me, LONG cpFirst)
656 ITextRangeImpl *This = impl_from_ITextRange(me);
657 if (!This->reOle)
658 return CO_E_RELEASED;
660 FIXME("not implemented %p\n", This);
661 return E_NOTIMPL;
664 static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *pcpLim)
666 ITextRangeImpl *This = impl_from_ITextRange(me);
667 if (!This->reOle)
668 return CO_E_RELEASED;
670 if (!pcpLim)
671 return E_INVALIDARG;
672 *pcpLim = This->end;
673 TRACE("%d\n", *pcpLim);
674 return S_OK;
677 static HRESULT WINAPI ITextRange_fnSetEnd(ITextRange *me, LONG cpLim)
679 ITextRangeImpl *This = impl_from_ITextRange(me);
680 if (!This->reOle)
681 return CO_E_RELEASED;
683 FIXME("not implemented %p\n", This);
684 return E_NOTIMPL;
687 static HRESULT WINAPI ITextRange_fnGetFont(ITextRange *me, ITextFont **pFont)
689 ITextRangeImpl *This = impl_from_ITextRange(me);
690 if (!This->reOle)
691 return CO_E_RELEASED;
693 FIXME("not implemented %p\n", This);
694 return E_NOTIMPL;
697 static HRESULT WINAPI ITextRange_fnSetFont(ITextRange *me, ITextFont *pFont)
699 ITextRangeImpl *This = impl_from_ITextRange(me);
700 if (!This->reOle)
701 return CO_E_RELEASED;
703 FIXME("not implemented %p\n", This);
704 return E_NOTIMPL;
707 static HRESULT WINAPI ITextRange_fnGetPara(ITextRange *me, ITextPara **ppPara)
709 ITextRangeImpl *This = impl_from_ITextRange(me);
710 if (!This->reOle)
711 return CO_E_RELEASED;
713 FIXME("not implemented %p\n", This);
714 return E_NOTIMPL;
717 static HRESULT WINAPI ITextRange_fnSetPara(ITextRange *me, ITextPara *pPara)
719 ITextRangeImpl *This = impl_from_ITextRange(me);
720 if (!This->reOle)
721 return CO_E_RELEASED;
723 FIXME("not implemented %p\n", This);
724 return E_NOTIMPL;
727 static HRESULT WINAPI ITextRange_fnGetStoryLength(ITextRange *me, LONG *pcch)
729 ITextRangeImpl *This = impl_from_ITextRange(me);
730 if (!This->reOle)
731 return CO_E_RELEASED;
733 FIXME("not implemented %p\n", This);
734 return E_NOTIMPL;
737 static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *pValue)
739 ITextRangeImpl *This = impl_from_ITextRange(me);
740 if (!This->reOle)
741 return CO_E_RELEASED;
743 FIXME("not implemented %p\n", This);
744 return E_NOTIMPL;
747 static HRESULT range_Collapse(LONG bStart, LONG *start, LONG *end)
749 if (*end == *start)
750 return S_FALSE;
752 if (bStart == tomEnd || bStart == tomFalse)
753 *start = *end;
754 else
755 *end = *start;
756 return S_OK;
759 static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
761 ITextRangeImpl *This = impl_from_ITextRange(me);
762 if (!This->reOle)
763 return CO_E_RELEASED;
765 return range_Collapse(bStart, &This->start, &This->end);
768 static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG Unit, LONG *pDelta)
770 ITextRangeImpl *This = impl_from_ITextRange(me);
771 if (!This->reOle)
772 return CO_E_RELEASED;
774 FIXME("not implemented %p\n", This);
775 return E_NOTIMPL;
778 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG Unit, LONG *pIndex)
780 ITextRangeImpl *This = impl_from_ITextRange(me);
781 if (!This->reOle)
782 return CO_E_RELEASED;
784 FIXME("not implemented %p\n", This);
785 return E_NOTIMPL;
788 static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG Unit, LONG Index,
789 LONG Extend)
791 ITextRangeImpl *This = impl_from_ITextRange(me);
792 if (!This->reOle)
793 return CO_E_RELEASED;
795 FIXME("not implemented %p\n", This);
796 return E_NOTIMPL;
799 static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG cpActive, LONG cpOther)
801 ITextRangeImpl *This = impl_from_ITextRange(me);
802 if (!This->reOle)
803 return CO_E_RELEASED;
805 FIXME("not implemented %p\n", This);
806 return E_NOTIMPL;
809 static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *pRange, LONG *pb)
811 ITextRangeImpl *This = impl_from_ITextRange(me);
812 if (!This->reOle)
813 return CO_E_RELEASED;
815 FIXME("not implemented %p\n", This);
816 return E_NOTIMPL;
819 static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *pb)
821 ITextRangeImpl *This = impl_from_ITextRange(me);
822 if (!This->reOle)
823 return CO_E_RELEASED;
825 FIXME("not implemented %p\n", This);
826 return E_NOTIMPL;
829 static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *pRange, LONG *pb)
831 ITextRangeImpl *This = impl_from_ITextRange(me);
832 if (!This->reOle)
833 return CO_E_RELEASED;
835 FIXME("not implemented %p\n", This);
836 return E_NOTIMPL;
839 static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me)
841 ITextRangeImpl *This = impl_from_ITextRange(me);
842 if (!This->reOle)
843 return CO_E_RELEASED;
845 FIXME("not implemented %p\n", This);
846 return E_NOTIMPL;
849 static HRESULT WINAPI ITextRange_fnStartOf(ITextRange *me, LONG Unit, LONG Extend,
850 LONG *pDelta)
852 ITextRangeImpl *This = impl_from_ITextRange(me);
853 if (!This->reOle)
854 return CO_E_RELEASED;
856 FIXME("not implemented %p\n", This);
857 return E_NOTIMPL;
860 static HRESULT WINAPI ITextRange_fnEndOf(ITextRange *me, LONG Unit, LONG Extend,
861 LONG *pDelta)
863 ITextRangeImpl *This = impl_from_ITextRange(me);
864 if (!This->reOle)
865 return CO_E_RELEASED;
867 FIXME("not implemented %p\n", This);
868 return E_NOTIMPL;
871 static HRESULT WINAPI ITextRange_fnMove(ITextRange *me, LONG Unit, LONG Count, LONG *pDelta)
873 ITextRangeImpl *This = impl_from_ITextRange(me);
874 if (!This->reOle)
875 return CO_E_RELEASED;
877 FIXME("not implemented %p\n", This);
878 return E_NOTIMPL;
881 static HRESULT WINAPI ITextRange_fnMoveStart(ITextRange *me, LONG Unit, LONG Count,
882 LONG *pDelta)
884 ITextRangeImpl *This = impl_from_ITextRange(me);
885 if (!This->reOle)
886 return CO_E_RELEASED;
888 FIXME("not implemented %p\n", This);
889 return E_NOTIMPL;
892 static HRESULT WINAPI ITextRange_fnMoveEnd(ITextRange *me, LONG Unit, LONG Count,
893 LONG *pDelta)
895 ITextRangeImpl *This = impl_from_ITextRange(me);
896 if (!This->reOle)
897 return CO_E_RELEASED;
899 FIXME("not implemented %p\n", This);
900 return E_NOTIMPL;
903 static HRESULT WINAPI ITextRange_fnMoveWhile(ITextRange *me, VARIANT *Cset, LONG Count,
904 LONG *pDelta)
906 ITextRangeImpl *This = impl_from_ITextRange(me);
907 if (!This->reOle)
908 return CO_E_RELEASED;
910 FIXME("not implemented %p\n", This);
911 return E_NOTIMPL;
914 static HRESULT WINAPI ITextRange_fnMoveStartWhile(ITextRange *me, VARIANT *Cset, LONG Count,
915 LONG *pDelta)
917 ITextRangeImpl *This = impl_from_ITextRange(me);
918 if (!This->reOle)
919 return CO_E_RELEASED;
921 FIXME("not implemented %p\n", This);
922 return E_NOTIMPL;
925 static HRESULT WINAPI ITextRange_fnMoveEndWhile(ITextRange *me, VARIANT *Cset, LONG Count,
926 LONG *pDelta)
928 ITextRangeImpl *This = impl_from_ITextRange(me);
929 if (!This->reOle)
930 return CO_E_RELEASED;
932 FIXME("not implemented %p\n", This);
933 return E_NOTIMPL;
936 static HRESULT WINAPI ITextRange_fnMoveUntil(ITextRange *me, VARIANT *Cset, LONG Count,
937 LONG *pDelta)
939 ITextRangeImpl *This = impl_from_ITextRange(me);
940 if (!This->reOle)
941 return CO_E_RELEASED;
943 FIXME("not implemented %p\n", This);
944 return E_NOTIMPL;
947 static HRESULT WINAPI ITextRange_fnMoveStartUntil(ITextRange *me, VARIANT *Cset, LONG Count,
948 LONG *pDelta)
950 ITextRangeImpl *This = impl_from_ITextRange(me);
951 if (!This->reOle)
952 return CO_E_RELEASED;
954 FIXME("not implemented %p\n", This);
955 return E_NOTIMPL;
958 static HRESULT WINAPI ITextRange_fnMoveEndUntil(ITextRange *me, VARIANT *Cset, LONG Count,
959 LONG *pDelta)
961 ITextRangeImpl *This = impl_from_ITextRange(me);
962 if (!This->reOle)
963 return CO_E_RELEASED;
965 FIXME("not implemented %p\n", This);
966 return E_NOTIMPL;
969 static HRESULT WINAPI ITextRange_fnFindText(ITextRange *me, BSTR bstr, LONG cch, LONG Flags,
970 LONG *pLength)
972 ITextRangeImpl *This = impl_from_ITextRange(me);
973 if (!This->reOle)
974 return CO_E_RELEASED;
976 FIXME("not implemented %p\n", This);
977 return E_NOTIMPL;
980 static HRESULT WINAPI ITextRange_fnFindTextStart(ITextRange *me, BSTR bstr, LONG cch,
981 LONG Flags, LONG *pLength)
983 ITextRangeImpl *This = impl_from_ITextRange(me);
984 if (!This->reOle)
985 return CO_E_RELEASED;
987 FIXME("not implemented %p\n", This);
988 return E_NOTIMPL;
991 static HRESULT WINAPI ITextRange_fnFindTextEnd(ITextRange *me, BSTR bstr, LONG cch,
992 LONG Flags, LONG *pLength)
994 ITextRangeImpl *This = impl_from_ITextRange(me);
995 if (!This->reOle)
996 return CO_E_RELEASED;
998 FIXME("not implemented %p\n", This);
999 return E_NOTIMPL;
1002 static HRESULT WINAPI ITextRange_fnDelete(ITextRange *me, LONG Unit, LONG Count,
1003 LONG *pDelta)
1005 ITextRangeImpl *This = impl_from_ITextRange(me);
1006 if (!This->reOle)
1007 return CO_E_RELEASED;
1009 FIXME("not implemented %p\n", This);
1010 return E_NOTIMPL;
1013 static HRESULT WINAPI ITextRange_fnCut(ITextRange *me, VARIANT *pVar)
1015 ITextRangeImpl *This = impl_from_ITextRange(me);
1016 if (!This->reOle)
1017 return CO_E_RELEASED;
1019 FIXME("not implemented %p\n", This);
1020 return E_NOTIMPL;
1023 static HRESULT WINAPI ITextRange_fnCopy(ITextRange *me, VARIANT *pVar)
1025 ITextRangeImpl *This = impl_from_ITextRange(me);
1026 if (!This->reOle)
1027 return CO_E_RELEASED;
1029 FIXME("not implemented %p\n", This);
1030 return E_NOTIMPL;
1033 static HRESULT WINAPI ITextRange_fnPaste(ITextRange *me, VARIANT *pVar, LONG Format)
1035 ITextRangeImpl *This = impl_from_ITextRange(me);
1036 if (!This->reOle)
1037 return CO_E_RELEASED;
1039 FIXME("not implemented %p\n", This);
1040 return E_NOTIMPL;
1043 static HRESULT WINAPI ITextRange_fnCanPaste(ITextRange *me, VARIANT *pVar, LONG Format,
1044 LONG *pb)
1046 ITextRangeImpl *This = impl_from_ITextRange(me);
1047 if (!This->reOle)
1048 return CO_E_RELEASED;
1050 FIXME("not implemented %p\n", This);
1051 return E_NOTIMPL;
1054 static HRESULT WINAPI ITextRange_fnCanEdit(ITextRange *me, LONG *pb)
1056 ITextRangeImpl *This = impl_from_ITextRange(me);
1057 if (!This->reOle)
1058 return CO_E_RELEASED;
1060 FIXME("not implemented %p\n", This);
1061 return E_NOTIMPL;
1064 static HRESULT WINAPI ITextRange_fnChangeCase(ITextRange *me, LONG Type)
1066 ITextRangeImpl *This = impl_from_ITextRange(me);
1067 if (!This->reOle)
1068 return CO_E_RELEASED;
1070 FIXME("not implemented %p\n", This);
1071 return E_NOTIMPL;
1074 static HRESULT WINAPI ITextRange_fnGetPoint(ITextRange *me, LONG Type, LONG *cx, LONG *cy)
1076 ITextRangeImpl *This = impl_from_ITextRange(me);
1077 if (!This->reOle)
1078 return CO_E_RELEASED;
1080 FIXME("not implemented %p\n", This);
1081 return E_NOTIMPL;
1084 static HRESULT WINAPI ITextRange_fnSetPoint(ITextRange *me, LONG x, LONG y, LONG Type,
1085 LONG Extend)
1087 ITextRangeImpl *This = impl_from_ITextRange(me);
1088 if (!This->reOle)
1089 return CO_E_RELEASED;
1091 FIXME("not implemented %p\n", This);
1092 return E_NOTIMPL;
1095 static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG Value)
1097 ITextRangeImpl *This = impl_from_ITextRange(me);
1098 if (!This->reOle)
1099 return CO_E_RELEASED;
1101 FIXME("not implemented %p\n", This);
1102 return E_NOTIMPL;
1105 static HRESULT WINAPI ITextRange_fnGetEmbeddedObject(ITextRange *me, IUnknown **ppv)
1107 ITextRangeImpl *This = impl_from_ITextRange(me);
1108 if (!This->reOle)
1109 return CO_E_RELEASED;
1111 FIXME("not implemented %p\n", This);
1112 return E_NOTIMPL;
1115 static const ITextRangeVtbl trvt = {
1116 ITextRange_fnQueryInterface,
1117 ITextRange_fnAddRef,
1118 ITextRange_fnRelease,
1119 ITextRange_fnGetTypeInfoCount,
1120 ITextRange_fnGetTypeInfo,
1121 ITextRange_fnGetIDsOfNames,
1122 ITextRange_fnInvoke,
1123 ITextRange_fnGetText,
1124 ITextRange_fnSetText,
1125 ITextRange_fnGetChar,
1126 ITextRange_fnSetChar,
1127 ITextRange_fnGetDuplicate,
1128 ITextRange_fnGetFormattedText,
1129 ITextRange_fnSetFormattedText,
1130 ITextRange_fnGetStart,
1131 ITextRange_fnSetStart,
1132 ITextRange_fnGetEnd,
1133 ITextRange_fnSetEnd,
1134 ITextRange_fnGetFont,
1135 ITextRange_fnSetFont,
1136 ITextRange_fnGetPara,
1137 ITextRange_fnSetPara,
1138 ITextRange_fnGetStoryLength,
1139 ITextRange_fnGetStoryType,
1140 ITextRange_fnCollapse,
1141 ITextRange_fnExpand,
1142 ITextRange_fnGetIndex,
1143 ITextRange_fnSetIndex,
1144 ITextRange_fnSetRange,
1145 ITextRange_fnInRange,
1146 ITextRange_fnInStory,
1147 ITextRange_fnIsEqual,
1148 ITextRange_fnSelect,
1149 ITextRange_fnStartOf,
1150 ITextRange_fnEndOf,
1151 ITextRange_fnMove,
1152 ITextRange_fnMoveStart,
1153 ITextRange_fnMoveEnd,
1154 ITextRange_fnMoveWhile,
1155 ITextRange_fnMoveStartWhile,
1156 ITextRange_fnMoveEndWhile,
1157 ITextRange_fnMoveUntil,
1158 ITextRange_fnMoveStartUntil,
1159 ITextRange_fnMoveEndUntil,
1160 ITextRange_fnFindText,
1161 ITextRange_fnFindTextStart,
1162 ITextRange_fnFindTextEnd,
1163 ITextRange_fnDelete,
1164 ITextRange_fnCut,
1165 ITextRange_fnCopy,
1166 ITextRange_fnPaste,
1167 ITextRange_fnCanPaste,
1168 ITextRange_fnCanEdit,
1169 ITextRange_fnChangeCase,
1170 ITextRange_fnGetPoint,
1171 ITextRange_fnSetPoint,
1172 ITextRange_fnScrollIntoView,
1173 ITextRange_fnGetEmbeddedObject
1175 /* ITextRange interface */
1177 static HRESULT WINAPI
1178 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
1179 void** ppvObject)
1181 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1182 return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
1185 static ULONG WINAPI
1186 ITextDocument_fnAddRef(ITextDocument* me)
1188 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1189 return IRichEditOle_AddRef(&This->IRichEditOle_iface);
1192 static ULONG WINAPI
1193 ITextDocument_fnRelease(ITextDocument* me)
1195 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1196 return IRichEditOle_Release(&This->IRichEditOle_iface);
1199 static HRESULT WINAPI
1200 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
1201 UINT* pctinfo)
1203 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1204 FIXME("stub %p\n",This);
1205 return E_NOTIMPL;
1208 static HRESULT WINAPI
1209 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
1210 ITypeInfo** ppTInfo)
1212 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1213 FIXME("stub %p\n",This);
1214 return E_NOTIMPL;
1217 static HRESULT WINAPI
1218 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
1219 LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
1221 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1222 FIXME("stub %p\n",This);
1223 return E_NOTIMPL;
1226 static HRESULT WINAPI
1227 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
1228 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1229 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1231 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1232 FIXME("stub %p\n",This);
1233 return E_NOTIMPL;
1236 static HRESULT WINAPI
1237 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
1239 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1240 FIXME("stub %p\n",This);
1241 return E_NOTIMPL;
1244 static HRESULT WINAPI
1245 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
1247 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1248 TRACE("(%p)\n", me);
1250 if(!ppSel)
1251 return E_INVALIDARG;
1252 *ppSel = &This->txtSel->ITextSelection_iface;
1253 ITextSelection_AddRef(*ppSel);
1254 return S_OK;
1257 static HRESULT WINAPI
1258 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
1260 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1261 FIXME("stub %p\n",This);
1262 return E_NOTIMPL;
1265 static HRESULT WINAPI
1266 ITextDocument_fnGetStoryRanges(ITextDocument* me,
1267 ITextStoryRanges** ppStories)
1269 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1270 FIXME("stub %p\n",This);
1271 return E_NOTIMPL;
1274 static HRESULT WINAPI
1275 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
1277 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1278 FIXME("stub %p\n",This);
1279 return E_NOTIMPL;
1282 static HRESULT WINAPI
1283 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
1285 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1286 FIXME("stub %p\n",This);
1287 return E_NOTIMPL;
1290 static HRESULT WINAPI
1291 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
1293 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1294 FIXME("stub %p\n",This);
1295 return E_NOTIMPL;
1298 static HRESULT WINAPI
1299 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
1301 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1302 FIXME("stub %p\n",This);
1303 return E_NOTIMPL;
1306 static HRESULT WINAPI
1307 ITextDocument_fnNew(ITextDocument* me)
1309 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1310 FIXME("stub %p\n",This);
1311 return E_NOTIMPL;
1314 static HRESULT WINAPI
1315 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
1316 LONG CodePage)
1318 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1319 FIXME("stub %p\n",This);
1320 return E_NOTIMPL;
1323 static HRESULT WINAPI
1324 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
1325 LONG CodePage)
1327 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1328 FIXME("stub %p\n",This);
1329 return E_NOTIMPL;
1332 static HRESULT WINAPI
1333 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
1335 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1336 FIXME("stub %p\n",This);
1337 return E_NOTIMPL;
1340 static HRESULT WINAPI
1341 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
1343 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1344 FIXME("stub %p\n",This);
1345 return E_NOTIMPL;
1348 static HRESULT WINAPI
1349 ITextDocument_fnBeginEditCollection(ITextDocument* me)
1351 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1352 FIXME("stub %p\n",This);
1353 return E_NOTIMPL;
1356 static HRESULT WINAPI
1357 ITextDocument_fnEndEditCollection(ITextDocument* me)
1359 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1360 FIXME("stub %p\n",This);
1361 return E_NOTIMPL;
1364 static HRESULT WINAPI
1365 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
1367 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1368 FIXME("stub %p\n",This);
1369 return E_NOTIMPL;
1372 static HRESULT WINAPI
1373 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
1375 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1376 FIXME("stub %p\n",This);
1377 return E_NOTIMPL;
1380 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
1382 ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
1384 if (!txtRge)
1385 return E_OUTOFMEMORY;
1386 txtRge->ITextRange_iface.lpVtbl = &trvt;
1387 txtRge->ref = 1;
1388 txtRge->reOle = reOle;
1389 txtRge->start = start;
1390 txtRge->end = end;
1391 list_add_head(&reOle->rangelist, &txtRge->entry);
1392 *ppRange = &txtRge->ITextRange_iface;
1393 return S_OK;
1396 static HRESULT WINAPI
1397 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
1398 ITextRange** ppRange)
1400 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1401 const int len = ME_GetTextLength(This->editor) + 1;
1403 TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
1404 if (!ppRange)
1405 return E_INVALIDARG;
1407 cp1 = max(cp1, 0);
1408 cp2 = max(cp2, 0);
1409 cp1 = min(cp1, len);
1410 cp2 = min(cp2, len);
1411 if (cp1 > cp2)
1413 LONG tmp;
1414 tmp = cp1;
1415 cp1 = cp2;
1416 cp2 = tmp;
1418 if (cp1 == len)
1419 cp1 = cp2 = len - 1;
1421 return CreateITextRange(This, cp1, cp2, ppRange);
1424 static HRESULT WINAPI
1425 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
1426 ITextRange** ppRange)
1428 IRichEditOleImpl *This = impl_from_ITextDocument(me);
1429 FIXME("stub %p\n",This);
1430 return E_NOTIMPL;
1433 static const ITextDocumentVtbl tdvt = {
1434 ITextDocument_fnQueryInterface,
1435 ITextDocument_fnAddRef,
1436 ITextDocument_fnRelease,
1437 ITextDocument_fnGetTypeInfoCount,
1438 ITextDocument_fnGetTypeInfo,
1439 ITextDocument_fnGetIDsOfNames,
1440 ITextDocument_fnInvoke,
1441 ITextDocument_fnGetName,
1442 ITextDocument_fnGetSelection,
1443 ITextDocument_fnGetStoryCount,
1444 ITextDocument_fnGetStoryRanges,
1445 ITextDocument_fnGetSaved,
1446 ITextDocument_fnSetSaved,
1447 ITextDocument_fnGetDefaultTabStop,
1448 ITextDocument_fnSetDefaultTabStop,
1449 ITextDocument_fnNew,
1450 ITextDocument_fnOpen,
1451 ITextDocument_fnSave,
1452 ITextDocument_fnFreeze,
1453 ITextDocument_fnUnfreeze,
1454 ITextDocument_fnBeginEditCollection,
1455 ITextDocument_fnEndEditCollection,
1456 ITextDocument_fnUndo,
1457 ITextDocument_fnRedo,
1458 ITextDocument_fnRange,
1459 ITextDocument_fnRangeFromPoint
1462 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
1464 return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
1467 static HRESULT WINAPI ITextSelection_fnQueryInterface(
1468 ITextSelection *me,
1469 REFIID riid,
1470 void **ppvObj)
1472 *ppvObj = NULL;
1473 if (IsEqualGUID(riid, &IID_IUnknown)
1474 || IsEqualGUID(riid, &IID_IDispatch)
1475 || IsEqualGUID(riid, &IID_ITextRange)
1476 || IsEqualGUID(riid, &IID_ITextSelection))
1478 *ppvObj = me;
1479 ITextSelection_AddRef(me);
1480 return S_OK;
1483 return E_NOINTERFACE;
1486 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
1488 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1489 return InterlockedIncrement(&This->ref);
1492 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
1494 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1495 ULONG ref = InterlockedDecrement(&This->ref);
1496 if (ref == 0)
1497 heap_free(This);
1498 return ref;
1501 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
1503 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1504 if (!This->reOle)
1505 return CO_E_RELEASED;
1507 FIXME("not implemented\n");
1508 return E_NOTIMPL;
1511 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
1512 ITypeInfo **ppTInfo)
1514 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1515 if (!This->reOle)
1516 return CO_E_RELEASED;
1518 FIXME("not implemented\n");
1519 return E_NOTIMPL;
1522 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
1523 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1525 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1526 if (!This->reOle)
1527 return CO_E_RELEASED;
1529 FIXME("not implemented\n");
1530 return E_NOTIMPL;
1533 static HRESULT WINAPI ITextSelection_fnInvoke(
1534 ITextSelection *me,
1535 DISPID dispIdMember,
1536 REFIID riid,
1537 LCID lcid,
1538 WORD wFlags,
1539 DISPPARAMS *pDispParams,
1540 VARIANT *pVarResult,
1541 EXCEPINFO *pExcepInfo,
1542 UINT *puArgErr)
1544 FIXME("not implemented\n");
1545 return E_NOTIMPL;
1548 /*** ITextRange methods ***/
1549 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
1551 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1552 ME_Cursor *start = NULL, *end = NULL;
1553 int nChars, endOfs;
1554 BOOL bEOP;
1556 if (!This->reOle)
1557 return CO_E_RELEASED;
1558 TRACE("%p\n", pbstr);
1559 if (!pbstr)
1560 return E_INVALIDARG;
1562 ME_GetSelection(This->reOle->editor, &start, &end);
1563 endOfs = ME_GetCursorOfs(end);
1564 nChars = endOfs - ME_GetCursorOfs(start);
1565 if (!nChars)
1567 *pbstr = NULL;
1568 return S_OK;
1571 *pbstr = SysAllocStringLen(NULL, nChars);
1572 if (!*pbstr)
1573 return E_OUTOFMEMORY;
1575 bEOP = (end->pRun->next->type == diTextEnd && endOfs > ME_GetTextLength(This->reOle->editor));
1576 ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
1577 TRACE("%s\n", wine_dbgstr_w(*pbstr));
1579 return S_OK;
1582 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
1584 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1585 if (!This->reOle)
1586 return CO_E_RELEASED;
1588 FIXME("not implemented\n");
1589 return E_NOTIMPL;
1592 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
1594 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1595 ME_Cursor *start = NULL, *end = NULL;
1597 if (!This->reOle)
1598 return CO_E_RELEASED;
1599 TRACE("%p\n", pch);
1600 if (!pch)
1601 return E_INVALIDARG;
1603 ME_GetSelection(This->reOle->editor, &start, &end);
1604 return range_GetChar(This->reOle->editor, start, pch);
1607 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
1609 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1610 if (!This->reOle)
1611 return CO_E_RELEASED;
1613 FIXME("not implemented\n");
1614 return E_NOTIMPL;
1617 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
1619 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1620 if (!This->reOle)
1621 return CO_E_RELEASED;
1623 FIXME("not implemented\n");
1624 return E_NOTIMPL;
1627 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)
1629 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1630 if (!This->reOle)
1631 return CO_E_RELEASED;
1633 FIXME("not implemented\n");
1634 return E_NOTIMPL;
1637 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *pRange)
1639 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1640 if (!This->reOle)
1641 return CO_E_RELEASED;
1643 FIXME("not implemented\n");
1644 return E_NOTIMPL;
1647 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
1649 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1650 LONG lim;
1651 if (!This->reOle)
1652 return CO_E_RELEASED;
1654 if (!pcpFirst)
1655 return E_INVALIDARG;
1656 ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim);
1657 TRACE("%d\n", *pcpFirst);
1658 return S_OK;
1661 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst)
1663 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1664 if (!This->reOle)
1665 return CO_E_RELEASED;
1667 FIXME("not implemented\n");
1668 return E_NOTIMPL;
1671 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
1673 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1674 LONG first;
1675 if (!This->reOle)
1676 return CO_E_RELEASED;
1678 if (!pcpLim)
1679 return E_INVALIDARG;
1680 ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim);
1681 TRACE("%d\n", *pcpLim);
1682 return S_OK;
1685 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
1687 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1688 if (!This->reOle)
1689 return CO_E_RELEASED;
1691 FIXME("not implemented\n");
1692 return E_NOTIMPL;
1695 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **pFont)
1697 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1698 if (!This->reOle)
1699 return CO_E_RELEASED;
1701 FIXME("not implemented\n");
1702 return E_NOTIMPL;
1705 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
1707 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1708 if (!This->reOle)
1709 return CO_E_RELEASED;
1711 FIXME("not implemented\n");
1712 return E_NOTIMPL;
1715 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **ppPara)
1717 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1718 if (!This->reOle)
1719 return CO_E_RELEASED;
1721 FIXME("not implemented\n");
1722 return E_NOTIMPL;
1725 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pPara)
1727 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1728 if (!This->reOle)
1729 return CO_E_RELEASED;
1731 FIXME("not implemented\n");
1732 return E_NOTIMPL;
1735 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *pcch)
1737 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1738 if (!This->reOle)
1739 return CO_E_RELEASED;
1741 FIXME("not implemented\n");
1742 return E_NOTIMPL;
1745 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pValue)
1747 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1748 if (!This->reOle)
1749 return CO_E_RELEASED;
1751 FIXME("not implemented\n");
1752 return E_NOTIMPL;
1755 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
1757 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1758 LONG start, end;
1759 HRESULT hres;
1760 if (!This->reOle)
1761 return CO_E_RELEASED;
1763 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
1764 hres = range_Collapse(bStart, &start, &end);
1765 if (SUCCEEDED(hres))
1766 ME_SetSelection(This->reOle->editor, start, end);
1767 return hres;
1770 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
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_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
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_fnSetIndex(ITextSelection *me, LONG Unit, LONG Index,
1791 LONG Extend)
1793 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1794 if (!This->reOle)
1795 return CO_E_RELEASED;
1797 FIXME("not implemented\n");
1798 return E_NOTIMPL;
1801 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActive, LONG cpOther)
1803 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1804 if (!This->reOle)
1805 return CO_E_RELEASED;
1807 FIXME("not implemented\n");
1808 return E_NOTIMPL;
1811 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
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_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)
1823 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1824 if (!This->reOle)
1825 return CO_E_RELEASED;
1827 FIXME("not implemented\n");
1828 return E_NOTIMPL;
1831 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb)
1833 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1834 if (!This->reOle)
1835 return CO_E_RELEASED;
1837 FIXME("not implemented\n");
1838 return E_NOTIMPL;
1841 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
1843 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1844 if (!This->reOle)
1845 return CO_E_RELEASED;
1847 FIXME("not implemented\n");
1848 return E_NOTIMPL;
1851 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG Unit, LONG Extend,
1852 LONG *pDelta)
1854 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1855 if (!This->reOle)
1856 return CO_E_RELEASED;
1858 FIXME("not implemented\n");
1859 return E_NOTIMPL;
1862 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG Extend,
1863 LONG *pDelta)
1865 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1866 if (!This->reOle)
1867 return CO_E_RELEASED;
1869 FIXME("not implemented\n");
1870 return E_NOTIMPL;
1873 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG Unit, LONG Count, LONG *pDelta)
1875 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1876 if (!This->reOle)
1877 return CO_E_RELEASED;
1879 FIXME("not implemented\n");
1880 return E_NOTIMPL;
1883 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG Unit, LONG Count,
1884 LONG *pDelta)
1886 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1887 if (!This->reOle)
1888 return CO_E_RELEASED;
1890 FIXME("not implemented\n");
1891 return E_NOTIMPL;
1894 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG Unit, LONG Count,
1895 LONG *pDelta)
1897 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1898 if (!This->reOle)
1899 return CO_E_RELEASED;
1901 FIXME("not implemented\n");
1902 return E_NOTIMPL;
1905 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1906 LONG *pDelta)
1908 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1909 if (!This->reOle)
1910 return CO_E_RELEASED;
1912 FIXME("not implemented\n");
1913 return E_NOTIMPL;
1916 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1917 LONG *pDelta)
1919 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1920 if (!This->reOle)
1921 return CO_E_RELEASED;
1923 FIXME("not implemented\n");
1924 return E_NOTIMPL;
1927 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
1928 LONG *pDelta)
1930 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1931 if (!This->reOle)
1932 return CO_E_RELEASED;
1934 FIXME("not implemented\n");
1935 return E_NOTIMPL;
1938 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1939 LONG *pDelta)
1941 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1942 if (!This->reOle)
1943 return CO_E_RELEASED;
1945 FIXME("not implemented\n");
1946 return E_NOTIMPL;
1949 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1950 LONG *pDelta)
1952 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1953 if (!This->reOle)
1954 return CO_E_RELEASED;
1956 FIXME("not implemented\n");
1957 return E_NOTIMPL;
1960 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
1961 LONG *pDelta)
1963 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1964 if (!This->reOle)
1965 return CO_E_RELEASED;
1967 FIXME("not implemented\n");
1968 return E_NOTIMPL;
1971 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR bstr, LONG cch, LONG Flags,
1972 LONG *pLength)
1974 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1975 if (!This->reOle)
1976 return CO_E_RELEASED;
1978 FIXME("not implemented\n");
1979 return E_NOTIMPL;
1982 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR bstr, LONG cch,
1983 LONG Flags, LONG *pLength)
1985 ITextSelectionImpl *This = impl_from_ITextSelection(me);
1986 if (!This->reOle)
1987 return CO_E_RELEASED;
1989 FIXME("not implemented\n");
1990 return E_NOTIMPL;
1993 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR bstr, LONG cch,
1994 LONG Flags, LONG *pLength)
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_fnDelete(ITextSelection *me, LONG Unit, LONG Count,
2005 LONG *pDelta)
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_fnCut(ITextSelection *me, VARIANT *pVar)
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_fnCopy(ITextSelection *me, VARIANT *pVar)
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_fnPaste(ITextSelection *me, VARIANT *pVar, LONG Format)
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_fnCanPaste(ITextSelection *me, VARIANT *pVar, LONG Format,
2046 LONG *pb)
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_fnCanEdit(ITextSelection *me, LONG *pb)
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_fnChangeCase(ITextSelection *me, LONG Type)
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 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG Type, LONG *cx, LONG *cy)
2078 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2079 if (!This->reOle)
2080 return CO_E_RELEASED;
2082 FIXME("not implemented\n");
2083 return E_NOTIMPL;
2086 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG Type,
2087 LONG Extend)
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_fnScrollIntoView(ITextSelection *me, LONG Value)
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_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
2109 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2110 if (!This->reOle)
2111 return CO_E_RELEASED;
2113 FIXME("not implemented\n");
2114 return E_NOTIMPL;
2117 /*** ITextSelection methods ***/
2118 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags)
2120 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2121 if (!This->reOle)
2122 return CO_E_RELEASED;
2124 FIXME("not implemented\n");
2125 return E_NOTIMPL;
2128 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
2130 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2131 if (!This->reOle)
2132 return CO_E_RELEASED;
2134 FIXME("not implemented\n");
2135 return E_NOTIMPL;
2138 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *pType)
2140 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2141 if (!This->reOle)
2142 return CO_E_RELEASED;
2144 FIXME("not implemented\n");
2145 return E_NOTIMPL;
2148 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG Unit, LONG Count,
2149 LONG Extend, LONG *pDelta)
2151 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2152 if (!This->reOle)
2153 return CO_E_RELEASED;
2155 FIXME("not implemented\n");
2156 return E_NOTIMPL;
2159 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG Unit, LONG Count,
2160 LONG Extend, LONG *pDelta)
2162 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2163 if (!This->reOle)
2164 return CO_E_RELEASED;
2166 FIXME("not implemented\n");
2167 return E_NOTIMPL;
2170 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG Unit, LONG Count,
2171 LONG Extend, LONG *pDelta)
2173 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2174 if (!This->reOle)
2175 return CO_E_RELEASED;
2177 FIXME("not implemented\n");
2178 return E_NOTIMPL;
2181 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG Unit, LONG Count,
2182 LONG Extend, LONG *pDelta)
2184 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2185 if (!This->reOle)
2186 return CO_E_RELEASED;
2188 FIXME("not implemented\n");
2189 return E_NOTIMPL;
2192 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG Unit, LONG Extend,
2193 LONG *pDelta)
2195 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2196 if (!This->reOle)
2197 return CO_E_RELEASED;
2199 FIXME("not implemented\n");
2200 return E_NOTIMPL;
2203 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LONG Extend,
2204 LONG *pDelta)
2206 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2207 if (!This->reOle)
2208 return CO_E_RELEASED;
2210 FIXME("not implemented\n");
2211 return E_NOTIMPL;
2214 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR bstr)
2216 ITextSelectionImpl *This = impl_from_ITextSelection(me);
2217 if (!This->reOle)
2218 return CO_E_RELEASED;
2220 FIXME("not implemented\n");
2221 return E_NOTIMPL;
2224 static const ITextSelectionVtbl tsvt = {
2225 ITextSelection_fnQueryInterface,
2226 ITextSelection_fnAddRef,
2227 ITextSelection_fnRelease,
2228 ITextSelection_fnGetTypeInfoCount,
2229 ITextSelection_fnGetTypeInfo,
2230 ITextSelection_fnGetIDsOfNames,
2231 ITextSelection_fnInvoke,
2232 ITextSelection_fnGetText,
2233 ITextSelection_fnSetText,
2234 ITextSelection_fnGetChar,
2235 ITextSelection_fnSetChar,
2236 ITextSelection_fnGetDuplicate,
2237 ITextSelection_fnGetFormattedText,
2238 ITextSelection_fnSetFormattedText,
2239 ITextSelection_fnGetStart,
2240 ITextSelection_fnSetStart,
2241 ITextSelection_fnGetEnd,
2242 ITextSelection_fnSetEnd,
2243 ITextSelection_fnGetFont,
2244 ITextSelection_fnSetFont,
2245 ITextSelection_fnGetPara,
2246 ITextSelection_fnSetPara,
2247 ITextSelection_fnGetStoryLength,
2248 ITextSelection_fnGetStoryType,
2249 ITextSelection_fnCollapse,
2250 ITextSelection_fnExpand,
2251 ITextSelection_fnGetIndex,
2252 ITextSelection_fnSetIndex,
2253 ITextSelection_fnSetRange,
2254 ITextSelection_fnInRange,
2255 ITextSelection_fnInStory,
2256 ITextSelection_fnIsEqual,
2257 ITextSelection_fnSelect,
2258 ITextSelection_fnStartOf,
2259 ITextSelection_fnEndOf,
2260 ITextSelection_fnMove,
2261 ITextSelection_fnMoveStart,
2262 ITextSelection_fnMoveEnd,
2263 ITextSelection_fnMoveWhile,
2264 ITextSelection_fnMoveStartWhile,
2265 ITextSelection_fnMoveEndWhile,
2266 ITextSelection_fnMoveUntil,
2267 ITextSelection_fnMoveStartUntil,
2268 ITextSelection_fnMoveEndUntil,
2269 ITextSelection_fnFindText,
2270 ITextSelection_fnFindTextStart,
2271 ITextSelection_fnFindTextEnd,
2272 ITextSelection_fnDelete,
2273 ITextSelection_fnCut,
2274 ITextSelection_fnCopy,
2275 ITextSelection_fnPaste,
2276 ITextSelection_fnCanPaste,
2277 ITextSelection_fnCanEdit,
2278 ITextSelection_fnChangeCase,
2279 ITextSelection_fnGetPoint,
2280 ITextSelection_fnSetPoint,
2281 ITextSelection_fnScrollIntoView,
2282 ITextSelection_fnGetEmbeddedObject,
2283 ITextSelection_fnGetFlags,
2284 ITextSelection_fnSetFlags,
2285 ITextSelection_fnGetType,
2286 ITextSelection_fnMoveLeft,
2287 ITextSelection_fnMoveRight,
2288 ITextSelection_fnMoveUp,
2289 ITextSelection_fnMoveDown,
2290 ITextSelection_fnHomeKey,
2291 ITextSelection_fnEndKey,
2292 ITextSelection_fnTypeText
2295 static ITextSelectionImpl *
2296 CreateTextSelection(IRichEditOleImpl *reOle)
2298 ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
2299 if (!txtSel)
2300 return NULL;
2302 txtSel->ITextSelection_iface.lpVtbl = &tsvt;
2303 txtSel->ref = 1;
2304 txtSel->reOle = reOle;
2305 return txtSel;
2308 LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
2310 IRichEditOleImpl *reo;
2312 reo = heap_alloc(sizeof(IRichEditOleImpl));
2313 if (!reo)
2314 return 0;
2316 reo->IRichEditOle_iface.lpVtbl = &revt;
2317 reo->ITextDocument_iface.lpVtbl = &tdvt;
2318 reo->ref = 1;
2319 reo->editor = editor;
2320 reo->txtSel = CreateTextSelection(reo);
2321 if (!reo->txtSel)
2323 heap_free(reo);
2324 return 0;
2326 reo->clientSite = CreateOleClientSite(reo);
2327 if (!reo->clientSite)
2329 ITextSelection_Release(&reo->txtSel->ITextSelection_iface);
2330 heap_free(reo);
2331 return 0;
2333 TRACE("Created %p\n",reo);
2334 *ppObj = reo;
2335 list_init(&reo->rangelist);
2337 return 1;
2340 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
2342 /* sizel is in .01 millimeters, sz in pixels */
2343 sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
2344 sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
2347 /******************************************************************************
2348 * ME_GetOLEObjectSize
2350 * Sets run extent for OLE objects.
2352 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
2354 IDataObject* ido;
2355 FORMATETC fmt;
2356 STGMEDIUM stgm;
2357 DIBSECTION dibsect;
2358 ENHMETAHEADER emh;
2360 assert(run->nFlags & MERF_GRAPHICS);
2361 assert(run->ole_obj);
2363 if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
2365 convert_sizel(c, &run->ole_obj->sizel, pSize);
2366 if (c->editor->nZoomNumerator != 0)
2368 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2369 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2371 return;
2374 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
2376 FIXME("Query Interface IID_IDataObject failed!\n");
2377 pSize->cx = pSize->cy = 0;
2378 return;
2380 fmt.cfFormat = CF_BITMAP;
2381 fmt.ptd = NULL;
2382 fmt.dwAspect = DVASPECT_CONTENT;
2383 fmt.lindex = -1;
2384 fmt.tymed = TYMED_GDI;
2385 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2387 fmt.cfFormat = CF_ENHMETAFILE;
2388 fmt.tymed = TYMED_ENHMF;
2389 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2391 FIXME("unsupported format\n");
2392 pSize->cx = pSize->cy = 0;
2393 IDataObject_Release(ido);
2394 return;
2398 switch (stgm.tymed)
2400 case TYMED_GDI:
2401 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
2402 pSize->cx = dibsect.dsBm.bmWidth;
2403 pSize->cy = dibsect.dsBm.bmHeight;
2404 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
2405 break;
2406 case TYMED_ENHMF:
2407 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
2408 pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
2409 pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
2410 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
2411 break;
2412 default:
2413 FIXME("Unsupported tymed %d\n", stgm.tymed);
2414 break;
2416 IDataObject_Release(ido);
2417 if (c->editor->nZoomNumerator != 0)
2419 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2420 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2424 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
2425 ME_Paragraph *para, BOOL selected)
2427 IDataObject* ido;
2428 FORMATETC fmt;
2429 STGMEDIUM stgm;
2430 DIBSECTION dibsect;
2431 ENHMETAHEADER emh;
2432 HDC hMemDC;
2433 SIZE sz;
2434 BOOL has_size;
2436 assert(run->nFlags & MERF_GRAPHICS);
2437 assert(run->ole_obj);
2438 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
2440 FIXME("Couldn't get interface\n");
2441 return;
2443 has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
2444 fmt.cfFormat = CF_BITMAP;
2445 fmt.ptd = NULL;
2446 fmt.dwAspect = DVASPECT_CONTENT;
2447 fmt.lindex = -1;
2448 fmt.tymed = TYMED_GDI;
2449 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2451 fmt.cfFormat = CF_ENHMETAFILE;
2452 fmt.tymed = TYMED_ENHMF;
2453 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
2455 FIXME("Couldn't get storage medium\n");
2456 IDataObject_Release(ido);
2457 return;
2460 switch (stgm.tymed)
2462 case TYMED_GDI:
2463 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
2464 hMemDC = CreateCompatibleDC(c->hDC);
2465 SelectObject(hMemDC, stgm.u.hBitmap);
2466 if (has_size)
2468 convert_sizel(c, &run->ole_obj->sizel, &sz);
2469 } else {
2470 sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
2471 sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
2473 if (c->editor->nZoomNumerator != 0)
2475 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2476 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2478 if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
2480 BitBlt(c->hDC, x, y - sz.cy,
2481 dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
2482 hMemDC, 0, 0, SRCCOPY);
2483 } else {
2484 StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
2485 hMemDC, 0, 0, dibsect.dsBm.bmWidth,
2486 dibsect.dsBm.bmHeight, SRCCOPY);
2488 DeleteDC(hMemDC);
2489 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
2490 break;
2491 case TYMED_ENHMF:
2492 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
2493 if (has_size)
2495 convert_sizel(c, &run->ole_obj->sizel, &sz);
2496 } else {
2497 sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
2498 sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
2500 if (c->editor->nZoomNumerator != 0)
2502 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2503 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
2507 RECT rc;
2509 rc.left = x;
2510 rc.top = y - sz.cy;
2511 rc.right = x + sz.cx;
2512 rc.bottom = y;
2513 PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
2515 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
2516 break;
2517 default:
2518 FIXME("Unsupported tymed %d\n", stgm.tymed);
2519 selected = FALSE;
2520 break;
2522 if (selected && !c->editor->bHideSelection)
2523 PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
2524 IDataObject_Release(ido);
2527 void ME_DeleteReObject(REOBJECT* reo)
2529 if (reo->poleobj) IOleObject_Release(reo->poleobj);
2530 if (reo->pstg) IStorage_Release(reo->pstg);
2531 if (reo->polesite) IOleClientSite_Release(reo->polesite);
2532 FREE_OBJ(reo);
2535 void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
2537 *dst = *src;
2539 if (dst->poleobj) IOleObject_AddRef(dst->poleobj);
2540 if (dst->pstg) IStorage_AddRef(dst->pstg);
2541 if (dst->polesite) IOleClientSite_AddRef(dst->polesite);