riched20: Support ITextFont instances detached from a range.
[wine.git] / dlls / riched20 / richole.c
blob016f8708cac29e83fb3ee4ca4c5261fe68eaaaf7
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 COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "richole.h"
33 #include "editor.h"
34 #include "richedit.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"
44 DEFINE_GUID(LIBID_tom, 0x8cc497c9, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
45 DEFINE_GUID(IID_ITextServices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
46 DEFINE_GUID(IID_ITextHost, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
47 DEFINE_GUID(IID_ITextHost2, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
48 DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
49 DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
50 DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
51 DEFINE_GUID(IID_ITextFont, 0x8cc497c3, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
52 DEFINE_GUID(IID_ITextPara, 0x8cc497c4, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
54 static ITypeLib *typelib;
56 enum tid_t {
57 NULL_tid,
58 ITextDocument_tid,
59 ITextRange_tid,
60 ITextSelection_tid,
61 ITextFont_tid,
62 ITextPara_tid,
63 LAST_tid
66 static const IID * const tid_ids[] =
68 &IID_NULL,
69 &IID_ITextDocument,
70 &IID_ITextRange,
71 &IID_ITextSelection,
72 &IID_ITextFont,
73 &IID_ITextPara,
75 static ITypeInfo *typeinfos[LAST_tid];
77 static HRESULT load_typelib(void)
79 ITypeLib *tl;
80 HRESULT hr;
82 hr = LoadRegTypeLib(&LIBID_tom, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
83 if (FAILED(hr)) {
84 ERR("LoadRegTypeLib failed: %08x\n", hr);
85 return hr;
88 if (InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
89 ITypeLib_Release(tl);
90 return hr;
93 void release_typelib(void)
95 unsigned i;
97 if (!typelib)
98 return;
100 for (i = 0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
101 if (typeinfos[i])
102 ITypeInfo_Release(typeinfos[i]);
104 ITypeLib_Release(typelib);
107 static HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo)
109 HRESULT hr;
111 if (!typelib)
112 hr = load_typelib();
113 if (!typelib)
114 return hr;
116 if (!typeinfos[tid])
118 ITypeInfo *ti;
120 hr = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
121 if (FAILED(hr))
123 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hr);
124 return hr;
127 if (InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
128 ITypeInfo_Release(ti);
131 *typeinfo = typeinfos[tid];
132 return S_OK;
135 /* private IID used to get back IRichEditOleImpl pointer */
136 DEFINE_GUID(IID_Igetrichole, 0xe3ce5c7a, 0x8247, 0x4622, 0x81, 0xad, 0x11, 0x81, 0x02, 0xaa, 0x01, 0x30);
138 typedef struct ITextSelectionImpl ITextSelectionImpl;
139 typedef struct IOleClientSiteImpl IOleClientSiteImpl;
140 typedef struct ITextRangeImpl ITextRangeImpl;
142 enum textfont_prop_id {
143 FONT_ALLCAPS = 0,
144 FONT_ANIMATION,
145 FONT_BACKCOLOR,
146 FONT_BOLD,
147 FONT_EMBOSS,
148 FONT_FORECOLOR,
149 FONT_HIDDEN,
150 FONT_ENGRAVE,
151 FONT_ITALIC,
152 FONT_KERNING,
153 FONT_LANGID,
154 FONT_NAME,
155 FONT_OUTLINE,
156 FONT_POSITION,
157 FONT_PROTECTED,
158 FONT_SHADOW,
159 FONT_SIZE,
160 FONT_SMALLCAPS,
161 FONT_SPACING,
162 FONT_STRIKETHROUGH,
163 FONT_SUBSCRIPT,
164 FONT_SUPERSCRIPT,
165 FONT_UNDERLINE,
166 FONT_WEIGHT,
167 FONT_PROPID_LAST
170 static const DWORD textfont_prop_masks[] = {
171 CFM_ALLCAPS,
172 CFM_ANIMATION,
173 CFM_BACKCOLOR,
174 CFM_BOLD,
175 CFM_EMBOSS,
176 CFM_COLOR,
177 CFM_HIDDEN,
178 CFM_IMPRINT,
179 CFM_ITALIC,
180 CFM_KERNING,
181 CFM_LCID,
182 CFM_FACE,
183 CFM_OUTLINE,
184 CFM_OFFSET,
185 CFM_PROTECTED,
186 CFM_SHADOW,
187 CFM_SIZE,
188 CFM_SMALLCAPS,
189 CFM_SPACING,
190 CFM_STRIKEOUT,
191 CFM_SUBSCRIPT,
192 CFM_SUPERSCRIPT,
193 CFM_UNDERLINE,
194 CFM_WEIGHT
197 typedef union {
198 FLOAT f;
199 LONG l;
200 BSTR str;
201 } textfont_prop_val;
203 typedef struct IRichEditOleImpl {
204 IUnknown IUnknown_inner;
205 IRichEditOle IRichEditOle_iface;
206 ITextDocument ITextDocument_iface;
207 IUnknown *outer_unk;
208 LONG ref;
210 ME_TextEditor *editor;
211 ITextSelectionImpl *txtSel;
212 IOleClientSiteImpl *clientSite;
213 struct list rangelist;
214 } IRichEditOleImpl;
216 struct ITextRangeImpl {
217 ITextRange ITextRange_iface;
218 LONG ref;
219 LONG start, end;
220 struct list entry;
222 IRichEditOleImpl *reOle;
225 struct ITextSelectionImpl {
226 ITextSelection ITextSelection_iface;
227 LONG ref;
229 IRichEditOleImpl *reOle;
232 typedef struct ITextFontImpl {
233 ITextFont ITextFont_iface;
234 LONG ref;
236 ITextRange *range;
237 textfont_prop_val props[FONT_PROPID_LAST];
238 } ITextFontImpl;
240 typedef struct ITextParaImpl {
241 ITextPara ITextPara_iface;
242 LONG ref;
244 ITextRange *range;
245 } ITextParaImpl;
247 struct IOleClientSiteImpl {
248 IOleClientSite IOleClientSite_iface;
249 IOleWindow IOleWindow_iface;
250 IOleInPlaceSite IOleInPlaceSite_iface;
251 LONG ref;
253 IRichEditOleImpl *reOle;
256 static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
258 return CONTAINING_RECORD(iface, IRichEditOleImpl, IRichEditOle_iface);
261 static inline IRichEditOleImpl *impl_from_ITextDocument(ITextDocument *iface)
263 return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument_iface);
266 static inline IRichEditOleImpl *impl_from_IUnknown(IUnknown *iface)
268 return CONTAINING_RECORD(iface, IRichEditOleImpl, IUnknown_inner);
271 static inline IOleClientSiteImpl *impl_from_IOleWindow(IOleWindow *iface)
273 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleWindow_iface);
276 static inline IOleClientSiteImpl *impl_from_IOleInPlaceSite(IOleInPlaceSite *iface)
278 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleInPlaceSite_iface);
281 static inline ITextRangeImpl *impl_from_ITextRange(ITextRange *iface)
283 return CONTAINING_RECORD(iface, ITextRangeImpl, ITextRange_iface);
286 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
288 return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
291 static inline ITextFontImpl *impl_from_ITextFont(ITextFont *iface)
293 return CONTAINING_RECORD(iface, ITextFontImpl, ITextFont_iface);
296 static inline ITextParaImpl *impl_from_ITextPara(ITextPara *iface)
298 return CONTAINING_RECORD(iface, ITextParaImpl, ITextPara_iface);
301 static HRESULT create_textfont(ITextRange*, const ITextFontImpl*, ITextFont**);
302 static HRESULT create_textpara(ITextRange*, ITextPara**);
304 static inline BOOL is_equal_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *left,
305 textfont_prop_val *right)
307 switch (propid)
309 case FONT_BOLD:
310 case FONT_FORECOLOR:
311 case FONT_ITALIC:
312 case FONT_LANGID:
313 case FONT_STRIKETHROUGH:
314 case FONT_SUBSCRIPT:
315 case FONT_SUPERSCRIPT:
316 case FONT_UNDERLINE:
317 return left->l == right->l;
318 case FONT_NAME:
319 return !strcmpW(left->str, right->str);
320 case FONT_SIZE:
321 return left->f == right->f;
322 default:
323 FIXME("unhandled font property %d\n", propid);
324 return FALSE;
328 static inline void init_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *v)
330 switch (propid)
332 case FONT_BOLD:
333 case FONT_FORECOLOR:
334 case FONT_ITALIC:
335 case FONT_LANGID:
336 case FONT_STRIKETHROUGH:
337 case FONT_SUBSCRIPT:
338 case FONT_SUPERSCRIPT:
339 case FONT_UNDERLINE:
340 v->l = tomUndefined;
341 return;
342 case FONT_NAME:
343 v->str = NULL;
344 return;
345 case FONT_SIZE:
346 v->f = tomUndefined;
347 return;
348 default:
349 FIXME("unhandled font property %d\n", propid);
350 v->l = tomUndefined;
351 return;
355 static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid,
356 textfont_prop_val *value)
358 ME_Cursor from, to;
359 CHARFORMAT2W fmt;
361 memset(&fmt, 0, sizeof(fmt));
362 fmt.cbSize = sizeof(fmt);
363 fmt.dwMask = textfont_prop_masks[propid];
365 ME_CursorFromCharOfs(reole->editor, pos, &from);
366 to = from;
367 ME_MoveCursorChars(reole->editor, &to, 1);
368 ME_GetCharFormat(reole->editor, &from, &to, &fmt);
370 switch (propid)
372 case FONT_BOLD:
373 value->l = fmt.dwEffects & CFE_BOLD ? tomTrue : tomFalse;
374 break;
375 case FONT_FORECOLOR:
376 value->l = fmt.dwEffects & CFE_AUTOCOLOR ? GetSysColor(COLOR_WINDOWTEXT) : fmt.crTextColor;
377 break;
378 case FONT_ITALIC:
379 value->l = fmt.dwEffects & CFE_ITALIC ? tomTrue : tomFalse;
380 break;
381 case FONT_LANGID:
382 value->l = fmt.lcid;
383 break;
384 case FONT_NAME:
385 /* this case is used exclusively by GetName() */
386 value->str = SysAllocString(fmt.szFaceName);
387 if (!value->str)
388 return E_OUTOFMEMORY;
389 break;
390 case FONT_SIZE:
391 value->f = fmt.yHeight;
392 break;
393 case FONT_STRIKETHROUGH:
394 value->l = fmt.dwEffects & CFE_STRIKEOUT ? tomTrue : tomFalse;
395 break;
396 case FONT_SUBSCRIPT:
397 value->l = fmt.dwEffects & CFE_SUBSCRIPT ? tomTrue : tomFalse;
398 break;
399 case FONT_SUPERSCRIPT:
400 value->l = fmt.dwEffects & CFE_SUPERSCRIPT ? tomTrue : tomFalse;
401 break;
402 case FONT_UNDERLINE:
403 value->l = fmt.dwEffects & CFE_UNDERLINE ? tomTrue : tomFalse;
404 break;
405 default:
406 FIXME("unhandled font property %d\n", propid);
407 return E_FAIL;
410 return S_OK;
413 static inline const IRichEditOleImpl *get_range_reole(ITextRange *range)
415 IRichEditOleImpl *reole = NULL;
416 ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&reole);
417 return reole;
420 static HRESULT get_textfont_prop(const ITextFontImpl *font, enum textfont_prop_id propid, textfont_prop_val *value)
422 const IRichEditOleImpl *reole;
423 textfont_prop_val v;
424 LONG start, end, i;
425 HRESULT hr;
427 /* when font is not attached to any range use cached values */
428 if (!font->range) {
429 *value = font->props[propid];
430 return S_OK;
433 if (!(reole = get_range_reole(font->range)))
434 return CO_E_RELEASED;
436 init_textfont_prop_value(propid, value);
438 ITextRange_GetStart(font->range, &start);
439 ITextRange_GetEnd(font->range, &end);
441 /* iterate trough a range to see if property value is consistent */
442 hr = get_textfont_prop_for_pos(reole, start, propid, &v);
443 if (FAILED(hr))
444 return hr;
446 for (i = start + 1; i < end; i++) {
447 textfont_prop_val cur;
449 hr = get_textfont_prop_for_pos(reole, i, propid, &cur);
450 if (FAILED(hr))
451 return hr;
453 if (!is_equal_textfont_prop_value(propid, &v, &cur))
454 return S_OK;
457 *value = v;
458 return S_OK;
461 static HRESULT get_textfont_propf(const ITextFontImpl *font, enum textfont_prop_id propid, FLOAT *value)
463 textfont_prop_val v;
464 HRESULT hr;
466 if (!value)
467 return E_INVALIDARG;
469 hr = get_textfont_prop(font, propid, &v);
470 *value = v.f;
471 return hr;
474 static HRESULT get_textfont_propl(const ITextFontImpl *font, enum textfont_prop_id propid, LONG *value)
476 textfont_prop_val v;
477 HRESULT hr;
479 if (!value)
480 return E_INVALIDARG;
482 hr = get_textfont_prop(font, propid, &v);
483 *value = v.l;
484 return hr;
487 static HRESULT WINAPI IRichEditOleImpl_inner_fnQueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppvObj)
489 IRichEditOleImpl *This = impl_from_IUnknown(iface);
491 TRACE("%p %s\n", This, debugstr_guid(riid));
493 *ppvObj = NULL;
494 if (IsEqualGUID(riid, &IID_IUnknown))
495 *ppvObj = &This->IUnknown_inner;
496 else if (IsEqualGUID(riid, &IID_IRichEditOle))
497 *ppvObj = &This->IRichEditOle_iface;
498 else if (IsEqualGUID(riid, &IID_ITextDocument))
499 *ppvObj = &This->ITextDocument_iface;
500 if (*ppvObj)
502 IUnknown_AddRef((IUnknown *)*ppvObj);
503 return S_OK;
505 FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid));
507 return E_NOINTERFACE;
510 static ULONG WINAPI IRichEditOleImpl_inner_fnAddRef(IUnknown *iface)
512 IRichEditOleImpl *This = impl_from_IUnknown(iface);
513 ULONG ref = InterlockedIncrement(&This->ref);
515 TRACE("%p ref = %u\n", This, ref);
517 return ref;
520 static ULONG WINAPI IRichEditOleImpl_inner_fnRelease(IUnknown *iface)
522 IRichEditOleImpl *This = impl_from_IUnknown(iface);
523 ULONG ref = InterlockedDecrement(&This->ref);
525 TRACE ("%p ref=%u\n", This, ref);
527 if (!ref)
529 ITextRangeImpl *txtRge;
531 TRACE("Destroying %p\n", This);
532 This->txtSel->reOle = NULL;
533 This->editor->reOle = NULL;
534 ITextSelection_Release(&This->txtSel->ITextSelection_iface);
535 IOleClientSite_Release(&This->clientSite->IOleClientSite_iface);
536 LIST_FOR_EACH_ENTRY(txtRge, &This->rangelist, ITextRangeImpl, entry)
537 txtRge->reOle = NULL;
538 heap_free(This);
540 return ref;
543 static const IUnknownVtbl reo_unk_vtbl =
545 IRichEditOleImpl_inner_fnQueryInterface,
546 IRichEditOleImpl_inner_fnAddRef,
547 IRichEditOleImpl_inner_fnRelease
550 static HRESULT WINAPI
551 IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
553 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
554 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
557 static ULONG WINAPI
558 IRichEditOle_fnAddRef(IRichEditOle *me)
560 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
561 return IUnknown_AddRef(This->outer_unk);
564 static ULONG WINAPI
565 IRichEditOle_fnRelease(IRichEditOle *me)
567 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
568 return IUnknown_Release(This->outer_unk);
571 static HRESULT WINAPI
572 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
574 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
575 FIXME("stub %p\n",This);
576 return E_NOTIMPL;
579 static HRESULT WINAPI
580 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
582 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
583 FIXME("stub %p\n",This);
584 return E_NOTIMPL;
587 static HRESULT WINAPI
588 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
589 REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
591 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
592 FIXME("stub %p\n",This);
593 return E_NOTIMPL;
596 static inline IOleClientSiteImpl *impl_from_IOleClientSite(IOleClientSite *iface)
598 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleClientSite_iface);
601 static HRESULT WINAPI
602 IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
604 IOleClientSiteImpl *This = impl_from_IOleClientSite(me);
605 TRACE("%p %s\n", me, debugstr_guid(riid) );
607 *ppvObj = NULL;
608 if (IsEqualGUID(riid, &IID_IUnknown) ||
609 IsEqualGUID(riid, &IID_IOleClientSite))
610 *ppvObj = me;
611 else if (IsEqualGUID(riid, &IID_IOleWindow))
612 *ppvObj = &This->IOleWindow_iface;
613 else if (IsEqualGUID(riid, &IID_IOleInPlaceSite))
614 *ppvObj = &This->IOleInPlaceSite_iface;
615 if (*ppvObj)
617 IOleClientSite_AddRef(me);
618 return S_OK;
620 FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );
622 return E_NOINTERFACE;
625 static ULONG WINAPI IOleClientSite_fnAddRef(IOleClientSite *iface)
627 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
628 return InterlockedIncrement(&This->ref);
631 static ULONG WINAPI IOleClientSite_fnRelease(IOleClientSite *iface)
633 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
634 ULONG ref = InterlockedDecrement(&This->ref);
635 if (ref == 0)
636 heap_free(This);
637 return ref;
640 static HRESULT WINAPI IOleClientSite_fnSaveObject(IOleClientSite *iface)
642 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
643 if (!This->reOle)
644 return CO_E_RELEASED;
646 FIXME("stub %p\n", iface);
647 return E_NOTIMPL;
651 static HRESULT WINAPI IOleClientSite_fnGetMoniker(IOleClientSite *iface, DWORD dwAssign,
652 DWORD dwWhichMoniker, IMoniker **ppmk)
654 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
655 if (!This->reOle)
656 return CO_E_RELEASED;
658 FIXME("stub %p\n", iface);
659 return E_NOTIMPL;
662 static HRESULT WINAPI IOleClientSite_fnGetContainer(IOleClientSite *iface,
663 IOleContainer **ppContainer)
665 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
666 if (!This->reOle)
667 return CO_E_RELEASED;
669 FIXME("stub %p\n", iface);
670 return E_NOTIMPL;
673 static HRESULT WINAPI IOleClientSite_fnShowObject(IOleClientSite *iface)
675 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
676 if (!This->reOle)
677 return CO_E_RELEASED;
679 FIXME("stub %p\n", iface);
680 return E_NOTIMPL;
683 static HRESULT WINAPI IOleClientSite_fnOnShowWindow(IOleClientSite *iface, BOOL fShow)
685 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
686 if (!This->reOle)
687 return CO_E_RELEASED;
689 FIXME("stub %p\n", iface);
690 return E_NOTIMPL;
693 static HRESULT WINAPI IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *iface)
695 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
696 if (!This->reOle)
697 return CO_E_RELEASED;
699 FIXME("stub %p\n", iface);
700 return E_NOTIMPL;
703 static const IOleClientSiteVtbl ocst = {
704 IOleClientSite_fnQueryInterface,
705 IOleClientSite_fnAddRef,
706 IOleClientSite_fnRelease,
707 IOleClientSite_fnSaveObject,
708 IOleClientSite_fnGetMoniker,
709 IOleClientSite_fnGetContainer,
710 IOleClientSite_fnShowObject,
711 IOleClientSite_fnOnShowWindow,
712 IOleClientSite_fnRequestNewObjectLayout
715 /* IOleWindow interface */
716 static HRESULT WINAPI IOleWindow_fnQueryInterface(IOleWindow *iface, REFIID riid, void **ppvObj)
718 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
719 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppvObj);
722 static ULONG WINAPI IOleWindow_fnAddRef(IOleWindow *iface)
724 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
725 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
728 static ULONG WINAPI IOleWindow_fnRelease(IOleWindow *iface)
730 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
731 return IOleClientSite_Release(&This->IOleClientSite_iface);
734 static HRESULT WINAPI IOleWindow_fnContextSensitiveHelp(IOleWindow *iface, BOOL fEnterMode)
736 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
737 FIXME("not implemented: (%p)->(%d)\n", This, fEnterMode);
738 return E_NOTIMPL;
741 static HRESULT WINAPI IOleWindow_fnGetWindow(IOleWindow *iface, HWND *phwnd)
743 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
744 TRACE("(%p)->(%p)\n", This, phwnd);
746 if (!phwnd)
747 return E_INVALIDARG;
749 *phwnd = This->reOle->editor->hWnd;
750 return S_OK;
753 static const IOleWindowVtbl olewinvt = {
754 IOleWindow_fnQueryInterface,
755 IOleWindow_fnAddRef,
756 IOleWindow_fnRelease,
757 IOleWindow_fnGetWindow,
758 IOleWindow_fnContextSensitiveHelp
761 /* IOleInPlaceSite interface */
762 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnQueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppvObj)
764 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
765 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppvObj);
768 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnAddRef(IOleInPlaceSite *iface)
770 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
771 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
774 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnRelease(IOleInPlaceSite *iface)
776 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
777 return IOleClientSite_Release(&This->IOleClientSite_iface);
780 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindow(IOleInPlaceSite *iface, HWND *phwnd)
782 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
783 return IOleWindow_GetWindow(&This->IOleWindow_iface, phwnd);
786 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
788 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
789 return IOleWindow_ContextSensitiveHelp(&This->IOleWindow_iface, fEnterMode);
792 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnCanInPlaceActivate(IOleInPlaceSite *iface)
794 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
795 FIXME("not implemented: (%p)\n", This);
796 return E_NOTIMPL;
799 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceActivate(IOleInPlaceSite *iface)
801 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
802 FIXME("not implemented: (%p)\n", This);
803 return E_NOTIMPL;
806 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIActivate(IOleInPlaceSite *iface)
808 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
809 FIXME("not implemented: (%p)\n", This);
810 return E_NOTIMPL;
813 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindowContext(IOleInPlaceSite *iface, IOleInPlaceFrame **ppFrame,
814 IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
815 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
817 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
818 FIXME("not implemented: (%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
819 return E_NOTIMPL;
822 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnScroll(IOleInPlaceSite *iface, SIZE scrollExtent)
824 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
825 FIXME("not implemented: (%p)\n", This);
826 return E_NOTIMPL;
829 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
831 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
832 FIXME("not implemented: (%p)->(%d)\n", This, fUndoable);
833 return E_NOTIMPL;
836 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceDeactivate(IOleInPlaceSite *iface)
838 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
839 FIXME("not implemented: (%p)\n", This);
840 return E_NOTIMPL;
843 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDiscardUndoState(IOleInPlaceSite *iface)
845 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
846 FIXME("not implemented: (%p)\n", This);
847 return E_NOTIMPL;
850 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDeactivateAndUndo(IOleInPlaceSite *iface)
852 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
853 FIXME("not implemented: (%p)\n", This);
854 return E_NOTIMPL;
857 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
859 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
860 FIXME("not implemented: (%p)->(%p)\n", This, lprcPosRect);
861 return E_NOTIMPL;
864 static const IOleInPlaceSiteVtbl olestvt =
866 IOleInPlaceSite_fnQueryInterface,
867 IOleInPlaceSite_fnAddRef,
868 IOleInPlaceSite_fnRelease,
869 IOleInPlaceSite_fnGetWindow,
870 IOleInPlaceSite_fnContextSensitiveHelp,
871 IOleInPlaceSite_fnCanInPlaceActivate,
872 IOleInPlaceSite_fnOnInPlaceActivate,
873 IOleInPlaceSite_fnOnUIActivate,
874 IOleInPlaceSite_fnGetWindowContext,
875 IOleInPlaceSite_fnScroll,
876 IOleInPlaceSite_fnOnUIDeactivate,
877 IOleInPlaceSite_fnOnInPlaceDeactivate,
878 IOleInPlaceSite_fnDiscardUndoState,
879 IOleInPlaceSite_fnDeactivateAndUndo,
880 IOleInPlaceSite_fnOnPosRectChange
883 static IOleClientSiteImpl *
884 CreateOleClientSite(IRichEditOleImpl *reOle)
886 IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
887 if (!clientSite)
888 return NULL;
890 clientSite->IOleClientSite_iface.lpVtbl = &ocst;
891 clientSite->IOleWindow_iface.lpVtbl = &olewinvt;
892 clientSite->IOleInPlaceSite_iface.lpVtbl = &olestvt;
893 clientSite->ref = 1;
894 clientSite->reOle = reOle;
895 return clientSite;
898 static HRESULT WINAPI
899 IRichEditOle_fnGetClientSite(IRichEditOle *me,
900 LPOLECLIENTSITE *lplpolesite)
902 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
904 TRACE("%p,%p\n",This, lplpolesite);
906 if(!lplpolesite)
907 return E_INVALIDARG;
908 *lplpolesite = &This->clientSite->IOleClientSite_iface;
909 IOleClientSite_AddRef(*lplpolesite);
910 return S_OK;
913 static HRESULT WINAPI
914 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
915 DWORD reco, LPDATAOBJECT *lplpdataobj)
917 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
918 ME_Cursor start;
919 int nChars;
921 TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
922 if(!lplpdataobj)
923 return E_INVALIDARG;
924 if(!lpchrg) {
925 int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
926 start = This->editor->pCursors[nStartCur];
927 nChars = nTo - nFrom;
928 } else {
929 ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
930 nChars = lpchrg->cpMax - lpchrg->cpMin;
932 return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
935 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
937 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
938 FIXME("stub %p\n",This);
939 return E_NOTIMPL;
942 static HRESULT WINAPI
943 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
944 REOBJECT *lpreobject, DWORD dwFlags)
946 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
947 FIXME("stub %p\n",This);
948 return E_NOTIMPL;
951 static LONG WINAPI
952 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
954 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
955 FIXME("stub %p\n",This);
956 return 0;
959 static HRESULT WINAPI
960 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
962 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
963 FIXME("stub %p\n",This);
964 return E_NOTIMPL;
967 static HRESULT WINAPI
968 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
969 CLIPFORMAT cf, HGLOBAL hMetaPict)
971 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
972 FIXME("stub %p\n",This);
973 return E_NOTIMPL;
976 static HRESULT WINAPI
977 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
979 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
980 FIXME("stub %p\n",This);
981 return E_NOTIMPL;
984 static HRESULT WINAPI
985 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
987 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
988 TRACE("(%p,%p)\n", This, reo);
990 if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
992 ME_InsertOLEFromCursor(This->editor, reo, 0);
993 ME_CommitUndo(This->editor);
994 ME_UpdateRepaint(This->editor, FALSE);
995 return S_OK;
998 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
999 LPSTORAGE lpstg)
1001 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1002 FIXME("stub %p\n",This);
1003 return E_NOTIMPL;
1006 static HRESULT WINAPI
1007 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
1009 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1010 FIXME("stub %p\n",This);
1011 return E_NOTIMPL;
1014 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
1015 LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
1017 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1018 FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
1019 return E_NOTIMPL;
1022 static HRESULT WINAPI
1023 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
1025 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1026 FIXME("stub %p\n",This);
1027 return E_NOTIMPL;
1030 static const IRichEditOleVtbl revt = {
1031 IRichEditOle_fnQueryInterface,
1032 IRichEditOle_fnAddRef,
1033 IRichEditOle_fnRelease,
1034 IRichEditOle_fnGetClientSite,
1035 IRichEditOle_fnGetObjectCount,
1036 IRichEditOle_fnGetLinkCount,
1037 IRichEditOle_fnGetObject,
1038 IRichEditOle_fnInsertObject,
1039 IRichEditOle_fnConvertObject,
1040 IRichEditOle_fnActivateAs,
1041 IRichEditOle_fnSetHostNames,
1042 IRichEditOle_fnSetLinkAvailable,
1043 IRichEditOle_fnSetDvaspect,
1044 IRichEditOle_fnHandsOffStorage,
1045 IRichEditOle_fnSaveCompleted,
1046 IRichEditOle_fnInPlaceDeactivate,
1047 IRichEditOle_fnContextSensitiveHelp,
1048 IRichEditOle_fnGetClipboardData,
1049 IRichEditOle_fnImportDataObject
1052 /* ITextRange interface */
1053 static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
1055 ITextRangeImpl *This = impl_from_ITextRange(me);
1057 *ppvObj = NULL;
1058 if (IsEqualGUID(riid, &IID_IUnknown)
1059 || IsEqualGUID(riid, &IID_IDispatch)
1060 || IsEqualGUID(riid, &IID_ITextRange))
1062 *ppvObj = me;
1063 ITextRange_AddRef(me);
1064 return S_OK;
1066 else if (IsEqualGUID(riid, &IID_Igetrichole))
1068 *ppvObj = This->reOle;
1069 return S_OK;
1072 return E_NOINTERFACE;
1075 static ULONG WINAPI ITextRange_fnAddRef(ITextRange *me)
1077 ITextRangeImpl *This = impl_from_ITextRange(me);
1078 return InterlockedIncrement(&This->ref);
1081 static ULONG WINAPI ITextRange_fnRelease(ITextRange *me)
1083 ITextRangeImpl *This = impl_from_ITextRange(me);
1084 ULONG ref = InterlockedDecrement(&This->ref);
1086 TRACE ("%p ref=%u\n", This, ref);
1087 if (ref == 0)
1089 if (This->reOle)
1091 list_remove(&This->entry);
1092 This->reOle = NULL;
1094 heap_free(This);
1096 return ref;
1099 static HRESULT WINAPI ITextRange_fnGetTypeInfoCount(ITextRange *me, UINT *pctinfo)
1101 ITextRangeImpl *This = impl_from_ITextRange(me);
1102 TRACE("(%p)->(%p)\n", This, pctinfo);
1103 *pctinfo = 1;
1104 return S_OK;
1107 static HRESULT WINAPI ITextRange_fnGetTypeInfo(ITextRange *me, UINT iTInfo, LCID lcid,
1108 ITypeInfo **ppTInfo)
1110 ITextRangeImpl *This = impl_from_ITextRange(me);
1111 HRESULT hr;
1113 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
1115 hr = get_typeinfo(ITextRange_tid, ppTInfo);
1116 if (SUCCEEDED(hr))
1117 ITypeInfo_AddRef(*ppTInfo);
1118 return hr;
1121 static HRESULT WINAPI ITextRange_fnGetIDsOfNames(ITextRange *me, REFIID riid, LPOLESTR *rgszNames,
1122 UINT cNames, LCID lcid, DISPID *rgDispId)
1124 ITextRangeImpl *This = impl_from_ITextRange(me);
1125 ITypeInfo *ti;
1126 HRESULT hr;
1128 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
1129 rgDispId);
1131 hr = get_typeinfo(ITextRange_tid, &ti);
1132 if (SUCCEEDED(hr))
1133 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
1134 return hr;
1137 static HRESULT WINAPI ITextRange_fnInvoke(ITextRange *me, DISPID dispIdMember, REFIID riid,
1138 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1139 VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
1140 UINT *puArgErr)
1142 ITextRangeImpl *This = impl_from_ITextRange(me);
1143 ITypeInfo *ti;
1144 HRESULT hr;
1146 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
1147 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1149 hr = get_typeinfo(ITextRange_tid, &ti);
1150 if (SUCCEEDED(hr))
1151 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1152 return hr;
1155 static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *pbstr)
1157 ITextRangeImpl *This = impl_from_ITextRange(me);
1159 FIXME("(%p)->(%p): stub\n", This, pbstr);
1161 if (!This->reOle)
1162 return CO_E_RELEASED;
1164 if (!pbstr)
1165 return E_INVALIDARG;
1167 *pbstr = NULL;
1168 return E_NOTIMPL;
1171 static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR bstr)
1173 ITextRangeImpl *This = impl_from_ITextRange(me);
1174 if (!This->reOle)
1175 return CO_E_RELEASED;
1177 FIXME("not implemented %p\n", This);
1178 return E_NOTIMPL;
1181 static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch)
1183 WCHAR wch[2];
1185 ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, cursor->pRun->next->type == diTextEnd);
1186 *pch = wch[0];
1188 return S_OK;
1191 static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
1193 ITextRangeImpl *This = impl_from_ITextRange(me);
1194 ME_Cursor cursor;
1196 if (!This->reOle)
1197 return CO_E_RELEASED;
1198 TRACE("%p\n", pch);
1199 if (!pch)
1200 return E_INVALIDARG;
1202 ME_CursorFromCharOfs(This->reOle->editor, This->start, &cursor);
1203 return range_GetChar(This->reOle->editor, &cursor, pch);
1206 static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch)
1208 ITextRangeImpl *This = impl_from_ITextRange(me);
1209 if (!This->reOle)
1210 return CO_E_RELEASED;
1212 FIXME("not implemented %p\n", This);
1213 return E_NOTIMPL;
1216 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange);
1218 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
1220 ITextRangeImpl *This = impl_from_ITextRange(me);
1221 if (!This->reOle)
1222 return CO_E_RELEASED;
1224 TRACE("%p %p\n", This, ppRange);
1225 if (!ppRange)
1226 return E_INVALIDARG;
1228 return CreateITextRange(This->reOle, This->start, This->end, ppRange);
1231 static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **ppRange)
1233 ITextRangeImpl *This = impl_from_ITextRange(me);
1234 if (!This->reOle)
1235 return CO_E_RELEASED;
1237 FIXME("not implemented %p\n", This);
1238 return E_NOTIMPL;
1241 static HRESULT WINAPI ITextRange_fnSetFormattedText(ITextRange *me, ITextRange *pRange)
1243 ITextRangeImpl *This = impl_from_ITextRange(me);
1244 if (!This->reOle)
1245 return CO_E_RELEASED;
1247 FIXME("not implemented %p\n", This);
1248 return E_NOTIMPL;
1251 static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *start)
1253 ITextRangeImpl *This = impl_from_ITextRange(me);
1255 TRACE("(%p)->(%p)\n", This, start);
1257 if (!This->reOle)
1258 return CO_E_RELEASED;
1260 if (!start)
1261 return E_INVALIDARG;
1263 *start = This->start;
1264 return S_OK;
1267 static HRESULT textrange_setstart(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1269 int len;
1271 if (value < 0)
1272 value = 0;
1274 if (value == *start)
1275 return S_FALSE;
1277 if (value <= *end) {
1278 *start = value;
1279 return S_OK;
1282 len = ME_GetTextLength(reole->editor);
1283 *start = *end = value > len ? len : value;
1284 return S_OK;
1287 static HRESULT WINAPI ITextRange_fnSetStart(ITextRange *me, LONG value)
1289 ITextRangeImpl *This = impl_from_ITextRange(me);
1291 TRACE("(%p)->(%d)\n", This, value);
1293 if (!This->reOle)
1294 return CO_E_RELEASED;
1296 return textrange_setstart(This->reOle, value, &This->start, &This->end);
1299 static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *end)
1301 ITextRangeImpl *This = impl_from_ITextRange(me);
1303 TRACE("(%p)->(%p)\n", This, end);
1305 if (!This->reOle)
1306 return CO_E_RELEASED;
1308 if (!end)
1309 return E_INVALIDARG;
1311 *end = This->end;
1312 return S_OK;
1315 static HRESULT textrange_setend(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1317 int len;
1319 if (value == *end)
1320 return S_FALSE;
1322 if (value < *start) {
1323 *start = *end = max(0, value);
1324 return S_OK;
1327 len = ME_GetTextLength(reole->editor);
1328 *end = value > len ? len + 1 : value;
1329 return S_OK;
1332 static HRESULT WINAPI ITextRange_fnSetEnd(ITextRange *me, LONG value)
1334 ITextRangeImpl *This = impl_from_ITextRange(me);
1336 TRACE("(%p)->(%d)\n", This, value);
1338 if (!This->reOle)
1339 return CO_E_RELEASED;
1341 return textrange_setend(This->reOle, value, &This->start, &This->end);
1344 static HRESULT WINAPI ITextRange_fnGetFont(ITextRange *me, ITextFont **font)
1346 ITextRangeImpl *This = impl_from_ITextRange(me);
1348 TRACE("(%p)->(%p)\n", This, font);
1350 if (!This->reOle)
1351 return CO_E_RELEASED;
1353 if (!font)
1354 return E_INVALIDARG;
1356 return create_textfont(me, NULL, font);
1359 static HRESULT WINAPI ITextRange_fnSetFont(ITextRange *me, ITextFont *pFont)
1361 ITextRangeImpl *This = impl_from_ITextRange(me);
1362 if (!This->reOle)
1363 return CO_E_RELEASED;
1365 FIXME("not implemented %p\n", This);
1366 return E_NOTIMPL;
1369 static HRESULT WINAPI ITextRange_fnGetPara(ITextRange *me, ITextPara **para)
1371 ITextRangeImpl *This = impl_from_ITextRange(me);
1373 TRACE("(%p)->(%p)\n", This, para);
1375 if (!This->reOle)
1376 return CO_E_RELEASED;
1378 if (!para)
1379 return E_INVALIDARG;
1381 return create_textpara(me, para);
1384 static HRESULT WINAPI ITextRange_fnSetPara(ITextRange *me, ITextPara *pPara)
1386 ITextRangeImpl *This = impl_from_ITextRange(me);
1387 if (!This->reOle)
1388 return CO_E_RELEASED;
1390 FIXME("not implemented %p\n", This);
1391 return E_NOTIMPL;
1394 static HRESULT WINAPI ITextRange_fnGetStoryLength(ITextRange *me, LONG *pcch)
1396 ITextRangeImpl *This = impl_from_ITextRange(me);
1397 if (!This->reOle)
1398 return CO_E_RELEASED;
1400 FIXME("not implemented %p\n", This);
1401 return E_NOTIMPL;
1404 static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *pValue)
1406 ITextRangeImpl *This = impl_from_ITextRange(me);
1407 if (!This->reOle)
1408 return CO_E_RELEASED;
1410 FIXME("not implemented %p\n", This);
1411 return E_NOTIMPL;
1414 static HRESULT range_Collapse(LONG bStart, LONG *start, LONG *end)
1416 if (*end == *start)
1417 return S_FALSE;
1419 if (bStart == tomEnd || bStart == tomFalse)
1420 *start = *end;
1421 else
1422 *end = *start;
1423 return S_OK;
1426 static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
1428 ITextRangeImpl *This = impl_from_ITextRange(me);
1429 if (!This->reOle)
1430 return CO_E_RELEASED;
1432 return range_Collapse(bStart, &This->start, &This->end);
1435 static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG Unit, LONG *pDelta)
1437 ITextRangeImpl *This = impl_from_ITextRange(me);
1438 if (!This->reOle)
1439 return CO_E_RELEASED;
1441 FIXME("not implemented %p\n", This);
1442 return E_NOTIMPL;
1445 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG Unit, LONG *pIndex)
1447 ITextRangeImpl *This = impl_from_ITextRange(me);
1448 if (!This->reOle)
1449 return CO_E_RELEASED;
1451 FIXME("not implemented %p\n", This);
1452 return E_NOTIMPL;
1455 static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG Unit, LONG Index,
1456 LONG Extend)
1458 ITextRangeImpl *This = impl_from_ITextRange(me);
1459 if (!This->reOle)
1460 return CO_E_RELEASED;
1462 FIXME("not implemented %p\n", This);
1463 return E_NOTIMPL;
1466 static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG cpActive, LONG cpOther)
1468 ITextRangeImpl *This = impl_from_ITextRange(me);
1469 if (!This->reOle)
1470 return CO_E_RELEASED;
1472 FIXME("not implemented %p\n", This);
1473 return E_NOTIMPL;
1476 static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *pRange, LONG *pb)
1478 ITextRangeImpl *This = impl_from_ITextRange(me);
1479 if (!This->reOle)
1480 return CO_E_RELEASED;
1482 FIXME("not implemented %p\n", This);
1483 return E_NOTIMPL;
1486 static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *pb)
1488 ITextRangeImpl *This = impl_from_ITextRange(me);
1489 if (!This->reOle)
1490 return CO_E_RELEASED;
1492 FIXME("not implemented %p\n", This);
1493 return E_NOTIMPL;
1496 static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *pRange, LONG *pb)
1498 ITextRangeImpl *This = impl_from_ITextRange(me);
1499 if (!This->reOle)
1500 return CO_E_RELEASED;
1502 FIXME("not implemented %p\n", This);
1503 return E_NOTIMPL;
1506 static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me)
1508 ITextRangeImpl *This = impl_from_ITextRange(me);
1509 if (!This->reOle)
1510 return CO_E_RELEASED;
1512 FIXME("not implemented %p\n", This);
1513 return E_NOTIMPL;
1516 static HRESULT WINAPI ITextRange_fnStartOf(ITextRange *me, LONG Unit, LONG Extend,
1517 LONG *pDelta)
1519 ITextRangeImpl *This = impl_from_ITextRange(me);
1520 if (!This->reOle)
1521 return CO_E_RELEASED;
1523 FIXME("not implemented %p\n", This);
1524 return E_NOTIMPL;
1527 static HRESULT WINAPI ITextRange_fnEndOf(ITextRange *me, LONG Unit, LONG Extend,
1528 LONG *pDelta)
1530 ITextRangeImpl *This = impl_from_ITextRange(me);
1531 if (!This->reOle)
1532 return CO_E_RELEASED;
1534 FIXME("not implemented %p\n", This);
1535 return E_NOTIMPL;
1538 static HRESULT WINAPI ITextRange_fnMove(ITextRange *me, LONG Unit, LONG Count, LONG *pDelta)
1540 ITextRangeImpl *This = impl_from_ITextRange(me);
1541 if (!This->reOle)
1542 return CO_E_RELEASED;
1544 FIXME("not implemented %p\n", This);
1545 return E_NOTIMPL;
1548 static HRESULT WINAPI ITextRange_fnMoveStart(ITextRange *me, LONG Unit, LONG Count,
1549 LONG *pDelta)
1551 ITextRangeImpl *This = impl_from_ITextRange(me);
1552 if (!This->reOle)
1553 return CO_E_RELEASED;
1555 FIXME("not implemented %p\n", This);
1556 return E_NOTIMPL;
1559 static HRESULT WINAPI ITextRange_fnMoveEnd(ITextRange *me, LONG Unit, LONG Count,
1560 LONG *pDelta)
1562 ITextRangeImpl *This = impl_from_ITextRange(me);
1563 if (!This->reOle)
1564 return CO_E_RELEASED;
1566 FIXME("not implemented %p\n", This);
1567 return E_NOTIMPL;
1570 static HRESULT WINAPI ITextRange_fnMoveWhile(ITextRange *me, VARIANT *Cset, LONG Count,
1571 LONG *pDelta)
1573 ITextRangeImpl *This = impl_from_ITextRange(me);
1574 if (!This->reOle)
1575 return CO_E_RELEASED;
1577 FIXME("not implemented %p\n", This);
1578 return E_NOTIMPL;
1581 static HRESULT WINAPI ITextRange_fnMoveStartWhile(ITextRange *me, VARIANT *Cset, LONG Count,
1582 LONG *pDelta)
1584 ITextRangeImpl *This = impl_from_ITextRange(me);
1585 if (!This->reOle)
1586 return CO_E_RELEASED;
1588 FIXME("not implemented %p\n", This);
1589 return E_NOTIMPL;
1592 static HRESULT WINAPI ITextRange_fnMoveEndWhile(ITextRange *me, VARIANT *Cset, LONG Count,
1593 LONG *pDelta)
1595 ITextRangeImpl *This = impl_from_ITextRange(me);
1596 if (!This->reOle)
1597 return CO_E_RELEASED;
1599 FIXME("not implemented %p\n", This);
1600 return E_NOTIMPL;
1603 static HRESULT WINAPI ITextRange_fnMoveUntil(ITextRange *me, VARIANT *Cset, LONG Count,
1604 LONG *pDelta)
1606 ITextRangeImpl *This = impl_from_ITextRange(me);
1607 if (!This->reOle)
1608 return CO_E_RELEASED;
1610 FIXME("not implemented %p\n", This);
1611 return E_NOTIMPL;
1614 static HRESULT WINAPI ITextRange_fnMoveStartUntil(ITextRange *me, VARIANT *Cset, LONG Count,
1615 LONG *pDelta)
1617 ITextRangeImpl *This = impl_from_ITextRange(me);
1618 if (!This->reOle)
1619 return CO_E_RELEASED;
1621 FIXME("not implemented %p\n", This);
1622 return E_NOTIMPL;
1625 static HRESULT WINAPI ITextRange_fnMoveEndUntil(ITextRange *me, VARIANT *Cset, LONG Count,
1626 LONG *pDelta)
1628 ITextRangeImpl *This = impl_from_ITextRange(me);
1629 if (!This->reOle)
1630 return CO_E_RELEASED;
1632 FIXME("not implemented %p\n", This);
1633 return E_NOTIMPL;
1636 static HRESULT WINAPI ITextRange_fnFindText(ITextRange *me, BSTR bstr, LONG cch, LONG Flags,
1637 LONG *pLength)
1639 ITextRangeImpl *This = impl_from_ITextRange(me);
1640 if (!This->reOle)
1641 return CO_E_RELEASED;
1643 FIXME("not implemented %p\n", This);
1644 return E_NOTIMPL;
1647 static HRESULT WINAPI ITextRange_fnFindTextStart(ITextRange *me, BSTR bstr, LONG cch,
1648 LONG Flags, LONG *pLength)
1650 ITextRangeImpl *This = impl_from_ITextRange(me);
1651 if (!This->reOle)
1652 return CO_E_RELEASED;
1654 FIXME("not implemented %p\n", This);
1655 return E_NOTIMPL;
1658 static HRESULT WINAPI ITextRange_fnFindTextEnd(ITextRange *me, BSTR bstr, LONG cch,
1659 LONG Flags, LONG *pLength)
1661 ITextRangeImpl *This = impl_from_ITextRange(me);
1662 if (!This->reOle)
1663 return CO_E_RELEASED;
1665 FIXME("not implemented %p\n", This);
1666 return E_NOTIMPL;
1669 static HRESULT WINAPI ITextRange_fnDelete(ITextRange *me, LONG Unit, LONG Count,
1670 LONG *pDelta)
1672 ITextRangeImpl *This = impl_from_ITextRange(me);
1673 if (!This->reOle)
1674 return CO_E_RELEASED;
1676 FIXME("not implemented %p\n", This);
1677 return E_NOTIMPL;
1680 static HRESULT WINAPI ITextRange_fnCut(ITextRange *me, VARIANT *pVar)
1682 ITextRangeImpl *This = impl_from_ITextRange(me);
1683 if (!This->reOle)
1684 return CO_E_RELEASED;
1686 FIXME("not implemented %p\n", This);
1687 return E_NOTIMPL;
1690 static HRESULT WINAPI ITextRange_fnCopy(ITextRange *me, VARIANT *pVar)
1692 ITextRangeImpl *This = impl_from_ITextRange(me);
1693 if (!This->reOle)
1694 return CO_E_RELEASED;
1696 FIXME("not implemented %p\n", This);
1697 return E_NOTIMPL;
1700 static HRESULT WINAPI ITextRange_fnPaste(ITextRange *me, VARIANT *pVar, LONG Format)
1702 ITextRangeImpl *This = impl_from_ITextRange(me);
1703 if (!This->reOle)
1704 return CO_E_RELEASED;
1706 FIXME("not implemented %p\n", This);
1707 return E_NOTIMPL;
1710 static HRESULT WINAPI ITextRange_fnCanPaste(ITextRange *me, VARIANT *pVar, LONG Format,
1711 LONG *pb)
1713 ITextRangeImpl *This = impl_from_ITextRange(me);
1714 if (!This->reOle)
1715 return CO_E_RELEASED;
1717 FIXME("not implemented %p\n", This);
1718 return E_NOTIMPL;
1721 static HRESULT WINAPI ITextRange_fnCanEdit(ITextRange *me, LONG *pb)
1723 ITextRangeImpl *This = impl_from_ITextRange(me);
1724 if (!This->reOle)
1725 return CO_E_RELEASED;
1727 FIXME("not implemented %p\n", This);
1728 return E_NOTIMPL;
1731 static HRESULT WINAPI ITextRange_fnChangeCase(ITextRange *me, LONG Type)
1733 ITextRangeImpl *This = impl_from_ITextRange(me);
1734 if (!This->reOle)
1735 return CO_E_RELEASED;
1737 FIXME("not implemented %p\n", This);
1738 return E_NOTIMPL;
1741 static HRESULT WINAPI ITextRange_fnGetPoint(ITextRange *me, LONG Type, LONG *cx, LONG *cy)
1743 ITextRangeImpl *This = impl_from_ITextRange(me);
1744 if (!This->reOle)
1745 return CO_E_RELEASED;
1747 FIXME("not implemented %p\n", This);
1748 return E_NOTIMPL;
1751 static HRESULT WINAPI ITextRange_fnSetPoint(ITextRange *me, LONG x, LONG y, LONG Type,
1752 LONG Extend)
1754 ITextRangeImpl *This = impl_from_ITextRange(me);
1755 if (!This->reOle)
1756 return CO_E_RELEASED;
1758 FIXME("not implemented %p\n", This);
1759 return E_NOTIMPL;
1762 static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG Value)
1764 ITextRangeImpl *This = impl_from_ITextRange(me);
1765 if (!This->reOle)
1766 return CO_E_RELEASED;
1768 FIXME("not implemented %p\n", This);
1769 return E_NOTIMPL;
1772 static HRESULT WINAPI ITextRange_fnGetEmbeddedObject(ITextRange *me, IUnknown **ppv)
1774 ITextRangeImpl *This = impl_from_ITextRange(me);
1775 if (!This->reOle)
1776 return CO_E_RELEASED;
1778 FIXME("not implemented %p\n", This);
1779 return E_NOTIMPL;
1782 static const ITextRangeVtbl trvt = {
1783 ITextRange_fnQueryInterface,
1784 ITextRange_fnAddRef,
1785 ITextRange_fnRelease,
1786 ITextRange_fnGetTypeInfoCount,
1787 ITextRange_fnGetTypeInfo,
1788 ITextRange_fnGetIDsOfNames,
1789 ITextRange_fnInvoke,
1790 ITextRange_fnGetText,
1791 ITextRange_fnSetText,
1792 ITextRange_fnGetChar,
1793 ITextRange_fnSetChar,
1794 ITextRange_fnGetDuplicate,
1795 ITextRange_fnGetFormattedText,
1796 ITextRange_fnSetFormattedText,
1797 ITextRange_fnGetStart,
1798 ITextRange_fnSetStart,
1799 ITextRange_fnGetEnd,
1800 ITextRange_fnSetEnd,
1801 ITextRange_fnGetFont,
1802 ITextRange_fnSetFont,
1803 ITextRange_fnGetPara,
1804 ITextRange_fnSetPara,
1805 ITextRange_fnGetStoryLength,
1806 ITextRange_fnGetStoryType,
1807 ITextRange_fnCollapse,
1808 ITextRange_fnExpand,
1809 ITextRange_fnGetIndex,
1810 ITextRange_fnSetIndex,
1811 ITextRange_fnSetRange,
1812 ITextRange_fnInRange,
1813 ITextRange_fnInStory,
1814 ITextRange_fnIsEqual,
1815 ITextRange_fnSelect,
1816 ITextRange_fnStartOf,
1817 ITextRange_fnEndOf,
1818 ITextRange_fnMove,
1819 ITextRange_fnMoveStart,
1820 ITextRange_fnMoveEnd,
1821 ITextRange_fnMoveWhile,
1822 ITextRange_fnMoveStartWhile,
1823 ITextRange_fnMoveEndWhile,
1824 ITextRange_fnMoveUntil,
1825 ITextRange_fnMoveStartUntil,
1826 ITextRange_fnMoveEndUntil,
1827 ITextRange_fnFindText,
1828 ITextRange_fnFindTextStart,
1829 ITextRange_fnFindTextEnd,
1830 ITextRange_fnDelete,
1831 ITextRange_fnCut,
1832 ITextRange_fnCopy,
1833 ITextRange_fnPaste,
1834 ITextRange_fnCanPaste,
1835 ITextRange_fnCanEdit,
1836 ITextRange_fnChangeCase,
1837 ITextRange_fnGetPoint,
1838 ITextRange_fnSetPoint,
1839 ITextRange_fnScrollIntoView,
1840 ITextRange_fnGetEmbeddedObject
1843 /* ITextFont */
1844 static HRESULT WINAPI TextFont_QueryInterface(ITextFont *iface, REFIID riid, void **ppv)
1846 ITextFontImpl *This = impl_from_ITextFont(iface);
1848 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1850 if (IsEqualIID(riid, &IID_ITextFont) ||
1851 IsEqualIID(riid, &IID_IDispatch) ||
1852 IsEqualIID(riid, &IID_IUnknown))
1854 *ppv = iface;
1855 ITextFont_AddRef(iface);
1856 return S_OK;
1859 *ppv = NULL;
1860 return E_NOINTERFACE;
1863 static ULONG WINAPI TextFont_AddRef(ITextFont *iface)
1865 ITextFontImpl *This = impl_from_ITextFont(iface);
1866 ULONG ref = InterlockedIncrement(&This->ref);
1867 TRACE("(%p)->(%u)\n", This, ref);
1868 return ref;
1871 static ULONG WINAPI TextFont_Release(ITextFont *iface)
1873 ITextFontImpl *This = impl_from_ITextFont(iface);
1874 ULONG ref = InterlockedDecrement(&This->ref);
1876 TRACE("(%p)->(%u)\n", This, ref);
1878 if (!ref)
1880 if (This->range)
1881 ITextRange_Release(This->range);
1882 SysFreeString(This->props[FONT_NAME].str);
1883 heap_free(This);
1886 return ref;
1889 static HRESULT WINAPI TextFont_GetTypeInfoCount(ITextFont *iface, UINT *pctinfo)
1891 ITextFontImpl *This = impl_from_ITextFont(iface);
1892 TRACE("(%p)->(%p)\n", This, pctinfo);
1893 *pctinfo = 1;
1894 return S_OK;
1897 static HRESULT WINAPI TextFont_GetTypeInfo(ITextFont *iface, UINT iTInfo, LCID lcid,
1898 ITypeInfo **ppTInfo)
1900 ITextFontImpl *This = impl_from_ITextFont(iface);
1901 HRESULT hr;
1903 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
1905 hr = get_typeinfo(ITextFont_tid, ppTInfo);
1906 if (SUCCEEDED(hr))
1907 ITypeInfo_AddRef(*ppTInfo);
1908 return hr;
1911 static HRESULT WINAPI TextFont_GetIDsOfNames(ITextFont *iface, REFIID riid,
1912 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1914 ITextFontImpl *This = impl_from_ITextFont(iface);
1915 ITypeInfo *ti;
1916 HRESULT hr;
1918 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
1919 rgDispId);
1921 hr = get_typeinfo(ITextFont_tid, &ti);
1922 if (SUCCEEDED(hr))
1923 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
1924 return hr;
1927 static HRESULT WINAPI TextFont_Invoke(
1928 ITextFont *iface,
1929 DISPID dispIdMember,
1930 REFIID riid,
1931 LCID lcid,
1932 WORD wFlags,
1933 DISPPARAMS *pDispParams,
1934 VARIANT *pVarResult,
1935 EXCEPINFO *pExcepInfo,
1936 UINT *puArgErr)
1938 ITextFontImpl *This = impl_from_ITextFont(iface);
1939 ITypeInfo *ti;
1940 HRESULT hr;
1942 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
1943 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1945 hr = get_typeinfo(ITextFont_tid, &ti);
1946 if (SUCCEEDED(hr))
1947 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1948 return hr;
1951 static HRESULT WINAPI TextFont_GetDuplicate(ITextFont *iface, ITextFont **ret)
1953 ITextFontImpl *This = impl_from_ITextFont(iface);
1955 TRACE("(%p)->(%p)\n", This, ret);
1957 if (!ret)
1958 return E_INVALIDARG;
1960 *ret = NULL;
1961 if (This->range && !get_range_reole(This->range))
1962 return CO_E_RELEASED;
1964 return create_textfont(NULL, This, ret);
1967 static HRESULT WINAPI TextFont_SetDuplicate(ITextFont *iface, ITextFont *pFont)
1969 ITextFontImpl *This = impl_from_ITextFont(iface);
1970 FIXME("(%p)->(%p): stub\n", This, pFont);
1971 return E_NOTIMPL;
1974 static HRESULT WINAPI TextFont_CanChange(ITextFont *iface, LONG *ret)
1976 ITextFontImpl *This = impl_from_ITextFont(iface);
1977 FIXME("(%p)->(%p): stub\n", This, ret);
1978 return E_NOTIMPL;
1981 static HRESULT WINAPI TextFont_IsEqual(ITextFont *iface, ITextFont *font, LONG *ret)
1983 ITextFontImpl *This = impl_from_ITextFont(iface);
1984 FIXME("(%p)->(%p %p): stub\n", This, font, ret);
1985 return E_NOTIMPL;
1988 static void textfont_reset_to_default(ITextFontImpl *font)
1990 enum textfont_prop_id id;
1992 for (id = FONT_ALLCAPS; id < FONT_PROPID_LAST; id++) {
1993 switch (id)
1995 case FONT_ALLCAPS:
1996 case FONT_ANIMATION:
1997 case FONT_BOLD:
1998 case FONT_EMBOSS:
1999 case FONT_HIDDEN:
2000 case FONT_ENGRAVE:
2001 case FONT_ITALIC:
2002 case FONT_OUTLINE:
2003 case FONT_PROTECTED:
2004 case FONT_SHADOW:
2005 case FONT_SMALLCAPS:
2006 case FONT_STRIKETHROUGH:
2007 case FONT_SUBSCRIPT:
2008 case FONT_SUPERSCRIPT:
2009 case FONT_UNDERLINE:
2010 font->props[id].l = tomFalse;
2011 break;
2012 case FONT_BACKCOLOR:
2013 case FONT_FORECOLOR:
2014 font->props[id].l = tomAutoColor;
2015 break;
2016 case FONT_KERNING:
2017 case FONT_POSITION:
2018 case FONT_SIZE:
2019 case FONT_SPACING:
2020 font->props[id].f = 0.0;
2021 break;
2022 case FONT_LANGID:
2023 font->props[id].l = GetSystemDefaultLCID();
2024 break;
2025 case FONT_NAME: {
2026 static const WCHAR sysW[] = {'S','y','s','t','e','m',0};
2027 SysFreeString(font->props[id].str);
2028 font->props[id].str = SysAllocString(sysW);
2029 break;
2031 case FONT_WEIGHT:
2032 font->props[id].l = FW_NORMAL;
2033 break;
2034 default:
2035 FIXME("font property %d not handled\n", id);
2040 static void textfont_reset_to_undefined(ITextFontImpl *font)
2042 enum textfont_prop_id id;
2044 for (id = FONT_ALLCAPS; id < FONT_PROPID_LAST; id++) {
2045 switch (id)
2047 case FONT_ALLCAPS:
2048 case FONT_ANIMATION:
2049 case FONT_BOLD:
2050 case FONT_EMBOSS:
2051 case FONT_HIDDEN:
2052 case FONT_ENGRAVE:
2053 case FONT_ITALIC:
2054 case FONT_OUTLINE:
2055 case FONT_PROTECTED:
2056 case FONT_SHADOW:
2057 case FONT_SMALLCAPS:
2058 case FONT_STRIKETHROUGH:
2059 case FONT_SUBSCRIPT:
2060 case FONT_SUPERSCRIPT:
2061 case FONT_UNDERLINE:
2062 case FONT_BACKCOLOR:
2063 case FONT_FORECOLOR:
2064 case FONT_LANGID:
2065 case FONT_WEIGHT:
2066 font->props[id].l = tomUndefined;
2067 break;
2068 case FONT_KERNING:
2069 case FONT_POSITION:
2070 case FONT_SIZE:
2071 case FONT_SPACING:
2072 font->props[id].f = tomUndefined;
2073 break;
2074 case FONT_NAME:
2075 break;
2076 default:
2077 FIXME("font property %d not handled\n", id);
2082 static HRESULT WINAPI TextFont_Reset(ITextFont *iface, LONG value)
2084 ITextFontImpl *This = impl_from_ITextFont(iface);
2086 TRACE("(%p)->(%d)\n", This, value);
2088 /* If font is attached to a range, released or not, we can't
2089 reset to undefined */
2090 if (This->range) {
2091 if (!get_range_reole(This->range))
2092 return CO_E_RELEASED;
2094 if (value == tomUndefined)
2095 return E_INVALIDARG;
2097 else {
2098 switch (value)
2100 /* reset to global defaults */
2101 case tomDefault:
2102 textfont_reset_to_default(This);
2103 return S_OK;
2104 /* all properties are set to tomUndefined, font name is retained */
2105 case tomUndefined:
2106 textfont_reset_to_undefined(This);
2107 return S_OK;
2111 FIXME("reset mode %d not supported\n", value);
2112 return E_NOTIMPL;
2115 static HRESULT WINAPI TextFont_GetStyle(ITextFont *iface, LONG *value)
2117 ITextFontImpl *This = impl_from_ITextFont(iface);
2118 FIXME("(%p)->(%p): stub\n", This, value);
2119 return E_NOTIMPL;
2122 static HRESULT WINAPI TextFont_SetStyle(ITextFont *iface, LONG value)
2124 ITextFontImpl *This = impl_from_ITextFont(iface);
2125 FIXME("(%p)->(%d): stub\n", This, value);
2126 return E_NOTIMPL;
2129 static HRESULT WINAPI TextFont_GetAllCaps(ITextFont *iface, LONG *value)
2131 ITextFontImpl *This = impl_from_ITextFont(iface);
2132 TRACE("(%p)->(%p)\n", This, value);
2133 return get_textfont_propl(This, FONT_ALLCAPS, value);
2136 static HRESULT WINAPI TextFont_SetAllCaps(ITextFont *iface, LONG value)
2138 ITextFontImpl *This = impl_from_ITextFont(iface);
2139 FIXME("(%p)->(%d): stub\n", This, value);
2140 return E_NOTIMPL;
2143 static HRESULT WINAPI TextFont_GetAnimation(ITextFont *iface, LONG *value)
2145 ITextFontImpl *This = impl_from_ITextFont(iface);
2146 TRACE("(%p)->(%p)\n", This, value);
2147 return get_textfont_propl(This, FONT_ANIMATION, value);
2150 static HRESULT WINAPI TextFont_SetAnimation(ITextFont *iface, LONG value)
2152 ITextFontImpl *This = impl_from_ITextFont(iface);
2153 FIXME("(%p)->(%d): stub\n", This, value);
2154 return E_NOTIMPL;
2157 static HRESULT WINAPI TextFont_GetBackColor(ITextFont *iface, LONG *value)
2159 ITextFontImpl *This = impl_from_ITextFont(iface);
2160 TRACE("(%p)->(%p)\n", This, value);
2161 return get_textfont_propl(This, FONT_BACKCOLOR, value);
2164 static HRESULT WINAPI TextFont_SetBackColor(ITextFont *iface, LONG value)
2166 ITextFontImpl *This = impl_from_ITextFont(iface);
2167 FIXME("(%p)->(%d): stub\n", This, value);
2168 return E_NOTIMPL;
2171 static HRESULT WINAPI TextFont_GetBold(ITextFont *iface, LONG *value)
2173 ITextFontImpl *This = impl_from_ITextFont(iface);
2174 TRACE("(%p)->(%p)\n", This, value);
2175 return get_textfont_propl(This, FONT_BOLD, value);
2178 static HRESULT WINAPI TextFont_SetBold(ITextFont *iface, LONG value)
2180 ITextFontImpl *This = impl_from_ITextFont(iface);
2181 FIXME("(%p)->(%d): stub\n", This, value);
2182 return E_NOTIMPL;
2185 static HRESULT WINAPI TextFont_GetEmboss(ITextFont *iface, LONG *value)
2187 ITextFontImpl *This = impl_from_ITextFont(iface);
2188 TRACE("(%p)->(%p)\n", This, value);
2189 return get_textfont_propl(This, FONT_EMBOSS, value);
2192 static HRESULT WINAPI TextFont_SetEmboss(ITextFont *iface, LONG value)
2194 ITextFontImpl *This = impl_from_ITextFont(iface);
2195 FIXME("(%p)->(%d): stub\n", This, value);
2196 return E_NOTIMPL;
2199 static HRESULT WINAPI TextFont_GetForeColor(ITextFont *iface, LONG *value)
2201 ITextFontImpl *This = impl_from_ITextFont(iface);
2202 TRACE("(%p)->(%p)\n", This, value);
2203 return get_textfont_propl(This, FONT_FORECOLOR, value);
2206 static HRESULT WINAPI TextFont_SetForeColor(ITextFont *iface, LONG value)
2208 ITextFontImpl *This = impl_from_ITextFont(iface);
2209 FIXME("(%p)->(%d): stub\n", This, value);
2210 return E_NOTIMPL;
2213 static HRESULT WINAPI TextFont_GetHidden(ITextFont *iface, LONG *value)
2215 ITextFontImpl *This = impl_from_ITextFont(iface);
2216 TRACE("(%p)->(%p)\n", This, value);
2217 return get_textfont_propl(This, FONT_HIDDEN, value);
2220 static HRESULT WINAPI TextFont_SetHidden(ITextFont *iface, LONG value)
2222 ITextFontImpl *This = impl_from_ITextFont(iface);
2223 FIXME("(%p)->(%d): stub\n", This, value);
2224 return E_NOTIMPL;
2227 static HRESULT WINAPI TextFont_GetEngrave(ITextFont *iface, LONG *value)
2229 ITextFontImpl *This = impl_from_ITextFont(iface);
2230 TRACE("(%p)->(%p)\n", This, value);
2231 return get_textfont_propl(This, FONT_ENGRAVE, value);
2234 static HRESULT WINAPI TextFont_SetEngrave(ITextFont *iface, LONG value)
2236 ITextFontImpl *This = impl_from_ITextFont(iface);
2237 FIXME("(%p)->(%d): stub\n", This, value);
2238 return E_NOTIMPL;
2241 static HRESULT WINAPI TextFont_GetItalic(ITextFont *iface, LONG *value)
2243 ITextFontImpl *This = impl_from_ITextFont(iface);
2244 TRACE("(%p)->(%p)\n", This, value);
2245 return get_textfont_propl(This, FONT_ITALIC, value);
2248 static HRESULT WINAPI TextFont_SetItalic(ITextFont *iface, LONG value)
2250 ITextFontImpl *This = impl_from_ITextFont(iface);
2251 FIXME("(%p)->(%d): stub\n", This, value);
2252 return E_NOTIMPL;
2255 static HRESULT WINAPI TextFont_GetKerning(ITextFont *iface, FLOAT *value)
2257 ITextFontImpl *This = impl_from_ITextFont(iface);
2258 TRACE("(%p)->(%p)\n", This, value);
2259 return get_textfont_propf(This, FONT_KERNING, value);
2262 static HRESULT WINAPI TextFont_SetKerning(ITextFont *iface, FLOAT value)
2264 ITextFontImpl *This = impl_from_ITextFont(iface);
2265 FIXME("(%p)->(%.2f): stub\n", This, value);
2266 return E_NOTIMPL;
2269 static HRESULT WINAPI TextFont_GetLanguageID(ITextFont *iface, LONG *value)
2271 ITextFontImpl *This = impl_from_ITextFont(iface);
2272 TRACE("(%p)->(%p)\n", This, value);
2273 return get_textfont_propl(This, FONT_LANGID, value);
2276 static HRESULT WINAPI TextFont_SetLanguageID(ITextFont *iface, LONG value)
2278 ITextFontImpl *This = impl_from_ITextFont(iface);
2279 FIXME("(%p)->(%d): stub\n", This, value);
2280 return E_NOTIMPL;
2283 static HRESULT WINAPI TextFont_GetName(ITextFont *iface, BSTR *value)
2285 ITextFontImpl *This = impl_from_ITextFont(iface);
2286 const IRichEditOleImpl *reole;
2287 textfont_prop_val v;
2288 LONG start;
2289 HRESULT hr;
2291 TRACE("(%p)->(%p)\n", This, value);
2293 if (!value)
2294 return E_INVALIDARG;
2296 *value = NULL;
2298 if (!This->range) {
2299 if (This->props[FONT_NAME].str)
2300 *value = SysAllocString(This->props[FONT_NAME].str);
2301 else
2302 *value = SysAllocStringLen(NULL, 0);
2303 return *value ? S_OK : E_OUTOFMEMORY;
2306 if (!(reole = get_range_reole(This->range)))
2307 return CO_E_RELEASED;
2309 init_textfont_prop_value(FONT_NAME, &v);
2311 ITextRange_GetStart(This->range, &start);
2312 hr = get_textfont_prop_for_pos(reole, start, FONT_NAME, &v);
2313 if (FAILED(hr))
2314 return hr;
2316 *value = v.str;
2317 return S_OK;
2320 static HRESULT WINAPI TextFont_SetName(ITextFont *iface, BSTR value)
2322 ITextFontImpl *This = impl_from_ITextFont(iface);
2323 FIXME("(%p)->(%s): stub\n", This, debugstr_w(value));
2324 return E_NOTIMPL;
2327 static HRESULT WINAPI TextFont_GetOutline(ITextFont *iface, LONG *value)
2329 ITextFontImpl *This = impl_from_ITextFont(iface);
2330 TRACE("(%p)->(%p)\n", This, value);
2331 return get_textfont_propl(This, FONT_OUTLINE, value);
2334 static HRESULT WINAPI TextFont_SetOutline(ITextFont *iface, LONG value)
2336 ITextFontImpl *This = impl_from_ITextFont(iface);
2337 FIXME("(%p)->(%d): stub\n", This, value);
2338 return E_NOTIMPL;
2341 static HRESULT WINAPI TextFont_GetPosition(ITextFont *iface, FLOAT *value)
2343 ITextFontImpl *This = impl_from_ITextFont(iface);
2344 TRACE("(%p)->(%p)\n", This, value);
2345 return get_textfont_propf(This, FONT_POSITION, value);
2348 static HRESULT WINAPI TextFont_SetPosition(ITextFont *iface, FLOAT value)
2350 ITextFontImpl *This = impl_from_ITextFont(iface);
2351 FIXME("(%p)->(%.2f): stub\n", This, value);
2352 return E_NOTIMPL;
2355 static HRESULT WINAPI TextFont_GetProtected(ITextFont *iface, LONG *value)
2357 ITextFontImpl *This = impl_from_ITextFont(iface);
2358 TRACE("(%p)->(%p)\n", This, value);
2359 return get_textfont_propl(This, FONT_PROTECTED, value);
2362 static HRESULT WINAPI TextFont_SetProtected(ITextFont *iface, LONG value)
2364 ITextFontImpl *This = impl_from_ITextFont(iface);
2365 FIXME("(%p)->(%d): stub\n", This, value);
2366 return E_NOTIMPL;
2369 static HRESULT WINAPI TextFont_GetShadow(ITextFont *iface, LONG *value)
2371 ITextFontImpl *This = impl_from_ITextFont(iface);
2372 TRACE("(%p)->(%p)\n", This, value);
2373 return get_textfont_propl(This, FONT_SHADOW, value);
2376 static HRESULT WINAPI TextFont_SetShadow(ITextFont *iface, LONG value)
2378 ITextFontImpl *This = impl_from_ITextFont(iface);
2379 FIXME("(%p)->(%d): stub\n", This, value);
2380 return E_NOTIMPL;
2383 static HRESULT WINAPI TextFont_GetSize(ITextFont *iface, FLOAT *value)
2385 ITextFontImpl *This = impl_from_ITextFont(iface);
2386 TRACE("(%p)->(%p)\n", This, value);
2387 return get_textfont_propf(This, FONT_SIZE, value);
2390 static HRESULT WINAPI TextFont_SetSize(ITextFont *iface, FLOAT value)
2392 ITextFontImpl *This = impl_from_ITextFont(iface);
2393 FIXME("(%p)->(%.2f): stub\n", This, value);
2394 return E_NOTIMPL;
2397 static HRESULT WINAPI TextFont_GetSmallCaps(ITextFont *iface, LONG *value)
2399 ITextFontImpl *This = impl_from_ITextFont(iface);
2400 TRACE("(%p)->(%p)\n", This, value);
2401 return get_textfont_propl(This, FONT_SMALLCAPS, value);
2404 static HRESULT WINAPI TextFont_SetSmallCaps(ITextFont *iface, LONG value)
2406 ITextFontImpl *This = impl_from_ITextFont(iface);
2407 FIXME("(%p)->(%d): stub\n", This, value);
2408 return E_NOTIMPL;
2411 static HRESULT WINAPI TextFont_GetSpacing(ITextFont *iface, FLOAT *value)
2413 ITextFontImpl *This = impl_from_ITextFont(iface);
2414 TRACE("(%p)->(%p)\n", This, value);
2415 return get_textfont_propf(This, FONT_SPACING, value);
2418 static HRESULT WINAPI TextFont_SetSpacing(ITextFont *iface, FLOAT value)
2420 ITextFontImpl *This = impl_from_ITextFont(iface);
2421 FIXME("(%p)->(%.2f): stub\n", This, value);
2422 return E_NOTIMPL;
2425 static HRESULT WINAPI TextFont_GetStrikeThrough(ITextFont *iface, LONG *value)
2427 ITextFontImpl *This = impl_from_ITextFont(iface);
2428 TRACE("(%p)->(%p)\n", This, value);
2429 return get_textfont_propl(This, FONT_STRIKETHROUGH, value);
2432 static HRESULT WINAPI TextFont_SetStrikeThrough(ITextFont *iface, LONG value)
2434 ITextFontImpl *This = impl_from_ITextFont(iface);
2435 FIXME("(%p)->(%d): stub\n", This, value);
2436 return E_NOTIMPL;
2439 static HRESULT WINAPI TextFont_GetSubscript(ITextFont *iface, LONG *value)
2441 ITextFontImpl *This = impl_from_ITextFont(iface);
2442 TRACE("(%p)->(%p)\n", This, value);
2443 return get_textfont_propl(This, FONT_SUBSCRIPT, value);
2446 static HRESULT WINAPI TextFont_SetSubscript(ITextFont *iface, LONG value)
2448 ITextFontImpl *This = impl_from_ITextFont(iface);
2449 FIXME("(%p)->(%d): stub\n", This, value);
2450 return E_NOTIMPL;
2453 static HRESULT WINAPI TextFont_GetSuperscript(ITextFont *iface, LONG *value)
2455 ITextFontImpl *This = impl_from_ITextFont(iface);
2456 TRACE("(%p)->(%p)\n", This, value);
2457 return get_textfont_propl(This, FONT_SUPERSCRIPT, value);
2460 static HRESULT WINAPI TextFont_SetSuperscript(ITextFont *iface, LONG value)
2462 ITextFontImpl *This = impl_from_ITextFont(iface);
2463 FIXME("(%p)->(%d): stub\n", This, value);
2464 return E_NOTIMPL;
2467 static HRESULT WINAPI TextFont_GetUnderline(ITextFont *iface, LONG *value)
2469 ITextFontImpl *This = impl_from_ITextFont(iface);
2470 TRACE("(%p)->(%p)\n", This, value);
2471 return get_textfont_propl(This, FONT_UNDERLINE, value);
2474 static HRESULT WINAPI TextFont_SetUnderline(ITextFont *iface, LONG value)
2476 ITextFontImpl *This = impl_from_ITextFont(iface);
2477 FIXME("(%p)->(%d): stub\n", This, value);
2478 return E_NOTIMPL;
2481 static HRESULT WINAPI TextFont_GetWeight(ITextFont *iface, LONG *value)
2483 ITextFontImpl *This = impl_from_ITextFont(iface);
2484 TRACE("(%p)->(%p)\n", This, value);
2485 return get_textfont_propl(This, FONT_WEIGHT, value);
2488 static HRESULT WINAPI TextFont_SetWeight(ITextFont *iface, LONG value)
2490 ITextFontImpl *This = impl_from_ITextFont(iface);
2491 FIXME("(%p)->(%d): stub\n", This, value);
2492 return E_NOTIMPL;
2495 static ITextFontVtbl textfontvtbl = {
2496 TextFont_QueryInterface,
2497 TextFont_AddRef,
2498 TextFont_Release,
2499 TextFont_GetTypeInfoCount,
2500 TextFont_GetTypeInfo,
2501 TextFont_GetIDsOfNames,
2502 TextFont_Invoke,
2503 TextFont_GetDuplicate,
2504 TextFont_SetDuplicate,
2505 TextFont_CanChange,
2506 TextFont_IsEqual,
2507 TextFont_Reset,
2508 TextFont_GetStyle,
2509 TextFont_SetStyle,
2510 TextFont_GetAllCaps,
2511 TextFont_SetAllCaps,
2512 TextFont_GetAnimation,
2513 TextFont_SetAnimation,
2514 TextFont_GetBackColor,
2515 TextFont_SetBackColor,
2516 TextFont_GetBold,
2517 TextFont_SetBold,
2518 TextFont_GetEmboss,
2519 TextFont_SetEmboss,
2520 TextFont_GetForeColor,
2521 TextFont_SetForeColor,
2522 TextFont_GetHidden,
2523 TextFont_SetHidden,
2524 TextFont_GetEngrave,
2525 TextFont_SetEngrave,
2526 TextFont_GetItalic,
2527 TextFont_SetItalic,
2528 TextFont_GetKerning,
2529 TextFont_SetKerning,
2530 TextFont_GetLanguageID,
2531 TextFont_SetLanguageID,
2532 TextFont_GetName,
2533 TextFont_SetName,
2534 TextFont_GetOutline,
2535 TextFont_SetOutline,
2536 TextFont_GetPosition,
2537 TextFont_SetPosition,
2538 TextFont_GetProtected,
2539 TextFont_SetProtected,
2540 TextFont_GetShadow,
2541 TextFont_SetShadow,
2542 TextFont_GetSize,
2543 TextFont_SetSize,
2544 TextFont_GetSmallCaps,
2545 TextFont_SetSmallCaps,
2546 TextFont_GetSpacing,
2547 TextFont_SetSpacing,
2548 TextFont_GetStrikeThrough,
2549 TextFont_SetStrikeThrough,
2550 TextFont_GetSubscript,
2551 TextFont_SetSubscript,
2552 TextFont_GetSuperscript,
2553 TextFont_SetSuperscript,
2554 TextFont_GetUnderline,
2555 TextFont_SetUnderline,
2556 TextFont_GetWeight,
2557 TextFont_SetWeight
2560 static HRESULT create_textfont(ITextRange *range, const ITextFontImpl *src, ITextFont **ret)
2562 ITextFontImpl *font;
2564 *ret = NULL;
2565 font = heap_alloc(sizeof(*font));
2566 if (!font)
2567 return E_OUTOFMEMORY;
2569 font->ITextFont_iface.lpVtbl = &textfontvtbl;
2570 font->ref = 1;
2572 if (src) {
2573 font->range = NULL;
2574 memcpy(&font->props, &src->props, sizeof(font->props));
2575 if (font->props[FONT_NAME].str)
2576 font->props[FONT_NAME].str = SysAllocString(font->props[FONT_NAME].str);
2578 else {
2579 font->range = range;
2580 ITextRange_AddRef(range);
2581 /* FIXME: copy current range attributes to a cache */
2582 memset(&font->props, 0, sizeof(font->props));
2585 *ret = &font->ITextFont_iface;
2586 return S_OK;
2589 /* ITextPara */
2590 static HRESULT WINAPI TextPara_QueryInterface(ITextPara *iface, REFIID riid, void **ppv)
2592 ITextParaImpl *This = impl_from_ITextPara(iface);
2594 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2596 if (IsEqualIID(riid, &IID_ITextPara) ||
2597 IsEqualIID(riid, &IID_IDispatch) ||
2598 IsEqualIID(riid, &IID_IUnknown))
2600 *ppv = iface;
2601 ITextPara_AddRef(iface);
2602 return S_OK;
2605 *ppv = NULL;
2606 return E_NOINTERFACE;
2609 static ULONG WINAPI TextPara_AddRef(ITextPara *iface)
2611 ITextParaImpl *This = impl_from_ITextPara(iface);
2612 ULONG ref = InterlockedIncrement(&This->ref);
2613 TRACE("(%p)->(%u)\n", This, ref);
2614 return ref;
2617 static ULONG WINAPI TextPara_Release(ITextPara *iface)
2619 ITextParaImpl *This = impl_from_ITextPara(iface);
2620 ULONG ref = InterlockedDecrement(&This->ref);
2622 TRACE("(%p)->(%u)\n", This, ref);
2624 if (!ref)
2626 ITextRange_Release(This->range);
2627 heap_free(This);
2630 return ref;
2633 static HRESULT WINAPI TextPara_GetTypeInfoCount(ITextPara *iface, UINT *pctinfo)
2635 ITextParaImpl *This = impl_from_ITextPara(iface);
2636 TRACE("(%p)->(%p)\n", This, pctinfo);
2637 *pctinfo = 1;
2638 return S_OK;
2641 static HRESULT WINAPI TextPara_GetTypeInfo(ITextPara *iface, UINT iTInfo, LCID lcid,
2642 ITypeInfo **ppTInfo)
2644 ITextParaImpl *This = impl_from_ITextPara(iface);
2645 HRESULT hr;
2647 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
2649 hr = get_typeinfo(ITextPara_tid, ppTInfo);
2650 if (SUCCEEDED(hr))
2651 ITypeInfo_AddRef(*ppTInfo);
2652 return hr;
2655 static HRESULT WINAPI TextPara_GetIDsOfNames(ITextPara *iface, REFIID riid,
2656 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2658 ITextParaImpl *This = impl_from_ITextPara(iface);
2659 ITypeInfo *ti;
2660 HRESULT hr;
2662 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
2663 rgDispId);
2665 hr = get_typeinfo(ITextPara_tid, &ti);
2666 if (SUCCEEDED(hr))
2667 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
2668 return hr;
2671 static HRESULT WINAPI TextPara_Invoke(
2672 ITextPara *iface,
2673 DISPID dispIdMember,
2674 REFIID riid,
2675 LCID lcid,
2676 WORD wFlags,
2677 DISPPARAMS *pDispParams,
2678 VARIANT *pVarResult,
2679 EXCEPINFO *pExcepInfo,
2680 UINT *puArgErr)
2682 ITextParaImpl *This = impl_from_ITextPara(iface);
2683 ITypeInfo *ti;
2684 HRESULT hr;
2686 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
2687 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2689 hr = get_typeinfo(ITextPara_tid, &ti);
2690 if (SUCCEEDED(hr))
2691 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2692 return hr;
2695 static HRESULT WINAPI TextPara_GetDuplicate(ITextPara *iface, ITextPara **ret)
2697 ITextParaImpl *This = impl_from_ITextPara(iface);
2698 FIXME("(%p)->(%p)\n", This, ret);
2699 return E_NOTIMPL;
2702 static HRESULT WINAPI TextPara_SetDuplicate(ITextPara *iface, ITextPara *para)
2704 ITextParaImpl *This = impl_from_ITextPara(iface);
2705 FIXME("(%p)->(%p)\n", This, para);
2706 return E_NOTIMPL;
2709 static HRESULT WINAPI TextPara_CanChange(ITextPara *iface, LONG *ret)
2711 ITextParaImpl *This = impl_from_ITextPara(iface);
2712 FIXME("(%p)->(%p)\n", This, ret);
2713 return E_NOTIMPL;
2716 static HRESULT WINAPI TextPara_IsEqual(ITextPara *iface, ITextPara *para, LONG *ret)
2718 ITextParaImpl *This = impl_from_ITextPara(iface);
2719 FIXME("(%p)->(%p %p)\n", This, para, ret);
2720 return E_NOTIMPL;
2723 static HRESULT WINAPI TextPara_Reset(ITextPara *iface, LONG value)
2725 ITextParaImpl *This = impl_from_ITextPara(iface);
2726 FIXME("(%p)->(%d)\n", This, value);
2727 return E_NOTIMPL;
2730 static HRESULT WINAPI TextPara_GetStyle(ITextPara *iface, LONG *value)
2732 ITextParaImpl *This = impl_from_ITextPara(iface);
2733 FIXME("(%p)->(%p)\n", This, value);
2734 return E_NOTIMPL;
2737 static HRESULT WINAPI TextPara_SetStyle(ITextPara *iface, LONG value)
2739 ITextParaImpl *This = impl_from_ITextPara(iface);
2740 FIXME("(%p)->(%d)\n", This, value);
2741 return E_NOTIMPL;
2744 static HRESULT WINAPI TextPara_GetAlignment(ITextPara *iface, LONG *value)
2746 ITextParaImpl *This = impl_from_ITextPara(iface);
2747 FIXME("(%p)->(%p)\n", This, value);
2748 return E_NOTIMPL;
2751 static HRESULT WINAPI TextPara_SetAlignment(ITextPara *iface, LONG value)
2753 ITextParaImpl *This = impl_from_ITextPara(iface);
2754 FIXME("(%p)->(%d)\n", This, value);
2755 return E_NOTIMPL;
2758 static HRESULT WINAPI TextPara_GetHyphenation(ITextPara *iface, LONG *value)
2760 ITextParaImpl *This = impl_from_ITextPara(iface);
2761 FIXME("(%p)->(%p)\n", This, value);
2762 return E_NOTIMPL;
2765 static HRESULT WINAPI TextPara_SetHyphenation(ITextPara *iface, LONG value)
2767 ITextParaImpl *This = impl_from_ITextPara(iface);
2768 FIXME("(%p)->(%d)\n", This, value);
2769 return E_NOTIMPL;
2772 static HRESULT WINAPI TextPara_GetFirstLineIndent(ITextPara *iface, FLOAT *value)
2774 ITextParaImpl *This = impl_from_ITextPara(iface);
2775 FIXME("(%p)->(%p)\n", This, value);
2776 return E_NOTIMPL;
2779 static HRESULT WINAPI TextPara_GetKeepTogether(ITextPara *iface, LONG *value)
2781 ITextParaImpl *This = impl_from_ITextPara(iface);
2782 FIXME("(%p)->(%p)\n", This, value);
2783 return E_NOTIMPL;
2786 static HRESULT WINAPI TextPara_SetKeepTogether(ITextPara *iface, LONG value)
2788 ITextParaImpl *This = impl_from_ITextPara(iface);
2789 FIXME("(%p)->(%d)\n", This, value);
2790 return E_NOTIMPL;
2793 static HRESULT WINAPI TextPara_GetKeepWithNext(ITextPara *iface, LONG *value)
2795 ITextParaImpl *This = impl_from_ITextPara(iface);
2796 FIXME("(%p)->(%p)\n", This, value);
2797 return E_NOTIMPL;
2800 static HRESULT WINAPI TextPara_SetKeepWithNext(ITextPara *iface, LONG value)
2802 ITextParaImpl *This = impl_from_ITextPara(iface);
2803 FIXME("(%p)->(%d)\n", This, value);
2804 return E_NOTIMPL;
2807 static HRESULT WINAPI TextPara_GetLeftIndent(ITextPara *iface, FLOAT *value)
2809 ITextParaImpl *This = impl_from_ITextPara(iface);
2810 FIXME("(%p)->(%p)\n", This, value);
2811 return E_NOTIMPL;
2814 static HRESULT WINAPI TextPara_GetLineSpacing(ITextPara *iface, FLOAT *value)
2816 ITextParaImpl *This = impl_from_ITextPara(iface);
2817 FIXME("(%p)->(%p)\n", This, value);
2818 return E_NOTIMPL;
2821 static HRESULT WINAPI TextPara_GetLineSpacingRule(ITextPara *iface, LONG *value)
2823 ITextParaImpl *This = impl_from_ITextPara(iface);
2824 FIXME("(%p)->(%p)\n", This, value);
2825 return E_NOTIMPL;
2828 static HRESULT WINAPI TextPara_GetListAlignment(ITextPara *iface, LONG *value)
2830 ITextParaImpl *This = impl_from_ITextPara(iface);
2831 FIXME("(%p)->(%p)\n", This, value);
2832 return E_NOTIMPL;
2835 static HRESULT WINAPI TextPara_SetListAlignment(ITextPara *iface, LONG value)
2837 ITextParaImpl *This = impl_from_ITextPara(iface);
2838 FIXME("(%p)->(%d)\n", This, value);
2839 return E_NOTIMPL;
2842 static HRESULT WINAPI TextPara_GetListLevelIndex(ITextPara *iface, LONG *value)
2844 ITextParaImpl *This = impl_from_ITextPara(iface);
2845 FIXME("(%p)->(%p)\n", This, value);
2846 return E_NOTIMPL;
2849 static HRESULT WINAPI TextPara_SetListLevelIndex(ITextPara *iface, LONG value)
2851 ITextParaImpl *This = impl_from_ITextPara(iface);
2852 FIXME("(%p)->(%d)\n", This, value);
2853 return E_NOTIMPL;
2856 static HRESULT WINAPI TextPara_GetListStart(ITextPara *iface, LONG *value)
2858 ITextParaImpl *This = impl_from_ITextPara(iface);
2859 FIXME("(%p)->(%p)\n", This, value);
2860 return E_NOTIMPL;
2863 static HRESULT WINAPI TextPara_SetListStart(ITextPara *iface, LONG value)
2865 ITextParaImpl *This = impl_from_ITextPara(iface);
2866 FIXME("(%p)->(%d)\n", This, value);
2867 return E_NOTIMPL;
2870 static HRESULT WINAPI TextPara_GetListTab(ITextPara *iface, FLOAT *value)
2872 ITextParaImpl *This = impl_from_ITextPara(iface);
2873 FIXME("(%p)->(%p)\n", This, value);
2874 return E_NOTIMPL;
2877 static HRESULT WINAPI TextPara_SetListTab(ITextPara *iface, FLOAT value)
2879 ITextParaImpl *This = impl_from_ITextPara(iface);
2880 FIXME("(%p)->(%.2f)\n", This, value);
2881 return E_NOTIMPL;
2884 static HRESULT WINAPI TextPara_GetListType(ITextPara *iface, LONG *value)
2886 ITextParaImpl *This = impl_from_ITextPara(iface);
2887 FIXME("(%p)->(%p)\n", This, value);
2888 return E_NOTIMPL;
2891 static HRESULT WINAPI TextPara_SetListType(ITextPara *iface, LONG value)
2893 ITextParaImpl *This = impl_from_ITextPara(iface);
2894 FIXME("(%p)->(%d)\n", This, value);
2895 return E_NOTIMPL;
2898 static HRESULT WINAPI TextPara_GetNoLineNumber(ITextPara *iface, LONG *value)
2900 ITextParaImpl *This = impl_from_ITextPara(iface);
2901 FIXME("(%p)->(%p)\n", This, value);
2902 return E_NOTIMPL;
2905 static HRESULT WINAPI TextPara_SetNoLineNumber(ITextPara *iface, LONG value)
2907 ITextParaImpl *This = impl_from_ITextPara(iface);
2908 FIXME("(%p)->(%d)\n", This, value);
2909 return E_NOTIMPL;
2912 static HRESULT WINAPI TextPara_GetPageBreakBefore(ITextPara *iface, LONG *value)
2914 ITextParaImpl *This = impl_from_ITextPara(iface);
2915 FIXME("(%p)->(%p)\n", This, value);
2916 return E_NOTIMPL;
2919 static HRESULT WINAPI TextPara_SetPageBreakBefore(ITextPara *iface, LONG value)
2921 ITextParaImpl *This = impl_from_ITextPara(iface);
2922 FIXME("(%p)->(%d)\n", This, value);
2923 return E_NOTIMPL;
2926 static HRESULT WINAPI TextPara_GetRightIndent(ITextPara *iface, FLOAT *value)
2928 ITextParaImpl *This = impl_from_ITextPara(iface);
2929 FIXME("(%p)->(%p)\n", This, value);
2930 return E_NOTIMPL;
2933 static HRESULT WINAPI TextPara_SetRightIndent(ITextPara *iface, FLOAT value)
2935 ITextParaImpl *This = impl_from_ITextPara(iface);
2936 FIXME("(%p)->(%.2f)\n", This, value);
2937 return E_NOTIMPL;
2940 static HRESULT WINAPI TextPara_SetIndents(ITextPara *iface, FLOAT StartIndent, FLOAT LeftIndent, FLOAT RightIndent)
2942 ITextParaImpl *This = impl_from_ITextPara(iface);
2943 FIXME("(%p)->(%.2f %.2f %.2f)\n", This, StartIndent, LeftIndent, RightIndent);
2944 return E_NOTIMPL;
2947 static HRESULT WINAPI TextPara_SetLineSpacing(ITextPara *iface, LONG LineSpacingRule, FLOAT LineSpacing)
2949 ITextParaImpl *This = impl_from_ITextPara(iface);
2950 FIXME("(%p)->(%d %.2f)\n", This, LineSpacingRule, LineSpacing);
2951 return E_NOTIMPL;
2954 static HRESULT WINAPI TextPara_GetSpaceAfter(ITextPara *iface, FLOAT *value)
2956 ITextParaImpl *This = impl_from_ITextPara(iface);
2957 FIXME("(%p)->(%p)\n", This, value);
2958 return E_NOTIMPL;
2961 static HRESULT WINAPI TextPara_SetSpaceAfter(ITextPara *iface, FLOAT value)
2963 ITextParaImpl *This = impl_from_ITextPara(iface);
2964 FIXME("(%p)->(%.2f)\n", This, value);
2965 return E_NOTIMPL;
2968 static HRESULT WINAPI TextPara_GetSpaceBefore(ITextPara *iface, FLOAT *value)
2970 ITextParaImpl *This = impl_from_ITextPara(iface);
2971 FIXME("(%p)->(%p)\n", This, value);
2972 return E_NOTIMPL;
2975 static HRESULT WINAPI TextPara_SetSpaceBefore(ITextPara *iface, FLOAT value)
2977 ITextParaImpl *This = impl_from_ITextPara(iface);
2978 FIXME("(%p)->(%.2f)\n", This, value);
2979 return E_NOTIMPL;
2982 static HRESULT WINAPI TextPara_GetWidowControl(ITextPara *iface, LONG *value)
2984 ITextParaImpl *This = impl_from_ITextPara(iface);
2985 FIXME("(%p)->(%p)\n", This, value);
2986 return E_NOTIMPL;
2989 static HRESULT WINAPI TextPara_SetWidowControl(ITextPara *iface, LONG value)
2991 ITextParaImpl *This = impl_from_ITextPara(iface);
2992 FIXME("(%p)->(%d)\n", This, value);
2993 return E_NOTIMPL;
2996 static HRESULT WINAPI TextPara_GetTabCount(ITextPara *iface, LONG *value)
2998 ITextParaImpl *This = impl_from_ITextPara(iface);
2999 FIXME("(%p)->(%p)\n", This, value);
3000 return E_NOTIMPL;
3003 static HRESULT WINAPI TextPara_AddTab(ITextPara *iface, FLOAT tbPos, LONG tbAlign, LONG tbLeader)
3005 ITextParaImpl *This = impl_from_ITextPara(iface);
3006 FIXME("(%p)->(%.2f %d %d)\n", This, tbPos, tbAlign, tbLeader);
3007 return E_NOTIMPL;
3010 static HRESULT WINAPI TextPara_ClearAllTabs(ITextPara *iface)
3012 ITextParaImpl *This = impl_from_ITextPara(iface);
3013 FIXME("(%p)\n", This);
3014 return E_NOTIMPL;
3017 static HRESULT WINAPI TextPara_DeleteTab(ITextPara *iface, FLOAT pos)
3019 ITextParaImpl *This = impl_from_ITextPara(iface);
3020 FIXME("(%p)->(%.2f)\n", This, pos);
3021 return E_NOTIMPL;
3024 static HRESULT WINAPI TextPara_GetTab(ITextPara *iface, LONG iTab, FLOAT *ptbPos, LONG *ptbAlign, LONG *ptbLeader)
3026 ITextParaImpl *This = impl_from_ITextPara(iface);
3027 FIXME("(%p)->(%d %p %p %p)\n", This, iTab, ptbPos, ptbAlign, ptbLeader);
3028 return E_NOTIMPL;
3031 static ITextParaVtbl textparavtbl = {
3032 TextPara_QueryInterface,
3033 TextPara_AddRef,
3034 TextPara_Release,
3035 TextPara_GetTypeInfoCount,
3036 TextPara_GetTypeInfo,
3037 TextPara_GetIDsOfNames,
3038 TextPara_Invoke,
3039 TextPara_GetDuplicate,
3040 TextPara_SetDuplicate,
3041 TextPara_CanChange,
3042 TextPara_IsEqual,
3043 TextPara_Reset,
3044 TextPara_GetStyle,
3045 TextPara_SetStyle,
3046 TextPara_GetAlignment,
3047 TextPara_SetAlignment,
3048 TextPara_GetHyphenation,
3049 TextPara_SetHyphenation,
3050 TextPara_GetFirstLineIndent,
3051 TextPara_GetKeepTogether,
3052 TextPara_SetKeepTogether,
3053 TextPara_GetKeepWithNext,
3054 TextPara_SetKeepWithNext,
3055 TextPara_GetLeftIndent,
3056 TextPara_GetLineSpacing,
3057 TextPara_GetLineSpacingRule,
3058 TextPara_GetListAlignment,
3059 TextPara_SetListAlignment,
3060 TextPara_GetListLevelIndex,
3061 TextPara_SetListLevelIndex,
3062 TextPara_GetListStart,
3063 TextPara_SetListStart,
3064 TextPara_GetListTab,
3065 TextPara_SetListTab,
3066 TextPara_GetListType,
3067 TextPara_SetListType,
3068 TextPara_GetNoLineNumber,
3069 TextPara_SetNoLineNumber,
3070 TextPara_GetPageBreakBefore,
3071 TextPara_SetPageBreakBefore,
3072 TextPara_GetRightIndent,
3073 TextPara_SetRightIndent,
3074 TextPara_SetIndents,
3075 TextPara_SetLineSpacing,
3076 TextPara_GetSpaceAfter,
3077 TextPara_SetSpaceAfter,
3078 TextPara_GetSpaceBefore,
3079 TextPara_SetSpaceBefore,
3080 TextPara_GetWidowControl,
3081 TextPara_SetWidowControl,
3082 TextPara_GetTabCount,
3083 TextPara_AddTab,
3084 TextPara_ClearAllTabs,
3085 TextPara_DeleteTab,
3086 TextPara_GetTab
3089 static HRESULT create_textpara(ITextRange *range, ITextPara **ret)
3091 ITextParaImpl *para;
3093 *ret = NULL;
3094 para = heap_alloc(sizeof(*para));
3095 if (!para)
3096 return E_OUTOFMEMORY;
3098 para->ITextPara_iface.lpVtbl = &textparavtbl;
3099 para->ref = 1;
3100 para->range = range;
3101 ITextRange_AddRef(range);
3103 *ret = &para->ITextPara_iface;
3104 return S_OK;
3107 /* ITextDocument */
3108 static HRESULT WINAPI
3109 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
3110 void** ppvObject)
3112 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3113 return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
3116 static ULONG WINAPI
3117 ITextDocument_fnAddRef(ITextDocument* me)
3119 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3120 return IRichEditOle_AddRef(&This->IRichEditOle_iface);
3123 static ULONG WINAPI
3124 ITextDocument_fnRelease(ITextDocument* me)
3126 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3127 return IRichEditOle_Release(&This->IRichEditOle_iface);
3130 static HRESULT WINAPI
3131 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
3132 UINT* pctinfo)
3134 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3135 TRACE("(%p)->(%p)\n", This, pctinfo);
3136 *pctinfo = 1;
3137 return S_OK;
3140 static HRESULT WINAPI
3141 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
3142 ITypeInfo** ppTInfo)
3144 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3145 HRESULT hr;
3147 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3149 hr = get_typeinfo(ITextDocument_tid, ppTInfo);
3150 if (SUCCEEDED(hr))
3151 ITypeInfo_AddRef(*ppTInfo);
3152 return hr;
3155 static HRESULT WINAPI
3156 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
3157 LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
3159 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3160 ITypeInfo *ti;
3161 HRESULT hr;
3163 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
3164 rgDispId);
3166 hr = get_typeinfo(ITextDocument_tid, &ti);
3167 if (SUCCEEDED(hr))
3168 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3169 return hr;
3172 static HRESULT WINAPI
3173 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
3174 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
3175 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
3177 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3178 ITypeInfo *ti;
3179 HRESULT hr;
3181 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
3182 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3184 hr = get_typeinfo(ITextDocument_tid, &ti);
3185 if (SUCCEEDED(hr))
3186 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3187 return hr;
3190 static HRESULT WINAPI
3191 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
3193 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3194 FIXME("stub %p\n",This);
3195 return E_NOTIMPL;
3198 static HRESULT WINAPI
3199 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
3201 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3202 TRACE("(%p)\n", me);
3204 if(!ppSel)
3205 return E_INVALIDARG;
3206 *ppSel = &This->txtSel->ITextSelection_iface;
3207 ITextSelection_AddRef(*ppSel);
3208 return S_OK;
3211 static HRESULT WINAPI
3212 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
3214 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3215 FIXME("stub %p\n",This);
3216 return E_NOTIMPL;
3219 static HRESULT WINAPI
3220 ITextDocument_fnGetStoryRanges(ITextDocument* me,
3221 ITextStoryRanges** ppStories)
3223 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3224 FIXME("stub %p\n",This);
3225 return E_NOTIMPL;
3228 static HRESULT WINAPI
3229 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
3231 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3232 FIXME("stub %p\n",This);
3233 return E_NOTIMPL;
3236 static HRESULT WINAPI
3237 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
3239 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3240 FIXME("stub %p\n",This);
3241 return E_NOTIMPL;
3244 static HRESULT WINAPI
3245 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
3247 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3248 FIXME("stub %p\n",This);
3249 return E_NOTIMPL;
3252 static HRESULT WINAPI
3253 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
3255 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3256 FIXME("stub %p\n",This);
3257 return E_NOTIMPL;
3260 static HRESULT WINAPI
3261 ITextDocument_fnNew(ITextDocument* me)
3263 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3264 FIXME("stub %p\n",This);
3265 return E_NOTIMPL;
3268 static HRESULT WINAPI
3269 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
3270 LONG CodePage)
3272 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3273 FIXME("stub %p\n",This);
3274 return E_NOTIMPL;
3277 static HRESULT WINAPI
3278 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
3279 LONG CodePage)
3281 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3282 FIXME("stub %p\n",This);
3283 return E_NOTIMPL;
3286 static HRESULT WINAPI
3287 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
3289 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3290 FIXME("stub %p\n",This);
3291 return E_NOTIMPL;
3294 static HRESULT WINAPI
3295 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
3297 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3298 FIXME("stub %p\n",This);
3299 return E_NOTIMPL;
3302 static HRESULT WINAPI
3303 ITextDocument_fnBeginEditCollection(ITextDocument* me)
3305 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3306 FIXME("stub %p\n",This);
3307 return E_NOTIMPL;
3310 static HRESULT WINAPI
3311 ITextDocument_fnEndEditCollection(ITextDocument* me)
3313 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3314 FIXME("stub %p\n",This);
3315 return E_NOTIMPL;
3318 static HRESULT WINAPI
3319 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
3321 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3322 FIXME("stub %p\n",This);
3323 return E_NOTIMPL;
3326 static HRESULT WINAPI
3327 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
3329 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3330 FIXME("stub %p\n",This);
3331 return E_NOTIMPL;
3334 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
3336 ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
3338 if (!txtRge)
3339 return E_OUTOFMEMORY;
3340 txtRge->ITextRange_iface.lpVtbl = &trvt;
3341 txtRge->ref = 1;
3342 txtRge->reOle = reOle;
3343 txtRge->start = start;
3344 txtRge->end = end;
3345 list_add_head(&reOle->rangelist, &txtRge->entry);
3346 *ppRange = &txtRge->ITextRange_iface;
3347 return S_OK;
3350 static HRESULT WINAPI
3351 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
3352 ITextRange** ppRange)
3354 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3355 const int len = ME_GetTextLength(This->editor) + 1;
3357 TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
3358 if (!ppRange)
3359 return E_INVALIDARG;
3361 cp1 = max(cp1, 0);
3362 cp2 = max(cp2, 0);
3363 cp1 = min(cp1, len);
3364 cp2 = min(cp2, len);
3365 if (cp1 > cp2)
3367 LONG tmp;
3368 tmp = cp1;
3369 cp1 = cp2;
3370 cp2 = tmp;
3372 if (cp1 == len)
3373 cp1 = cp2 = len - 1;
3375 return CreateITextRange(This, cp1, cp2, ppRange);
3378 static HRESULT WINAPI
3379 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
3380 ITextRange** ppRange)
3382 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3383 FIXME("stub %p\n",This);
3384 return E_NOTIMPL;
3387 static const ITextDocumentVtbl tdvt = {
3388 ITextDocument_fnQueryInterface,
3389 ITextDocument_fnAddRef,
3390 ITextDocument_fnRelease,
3391 ITextDocument_fnGetTypeInfoCount,
3392 ITextDocument_fnGetTypeInfo,
3393 ITextDocument_fnGetIDsOfNames,
3394 ITextDocument_fnInvoke,
3395 ITextDocument_fnGetName,
3396 ITextDocument_fnGetSelection,
3397 ITextDocument_fnGetStoryCount,
3398 ITextDocument_fnGetStoryRanges,
3399 ITextDocument_fnGetSaved,
3400 ITextDocument_fnSetSaved,
3401 ITextDocument_fnGetDefaultTabStop,
3402 ITextDocument_fnSetDefaultTabStop,
3403 ITextDocument_fnNew,
3404 ITextDocument_fnOpen,
3405 ITextDocument_fnSave,
3406 ITextDocument_fnFreeze,
3407 ITextDocument_fnUnfreeze,
3408 ITextDocument_fnBeginEditCollection,
3409 ITextDocument_fnEndEditCollection,
3410 ITextDocument_fnUndo,
3411 ITextDocument_fnRedo,
3412 ITextDocument_fnRange,
3413 ITextDocument_fnRangeFromPoint
3416 /* ITextSelection */
3417 static HRESULT WINAPI ITextSelection_fnQueryInterface(
3418 ITextSelection *me,
3419 REFIID riid,
3420 void **ppvObj)
3422 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3424 *ppvObj = NULL;
3425 if (IsEqualGUID(riid, &IID_IUnknown)
3426 || IsEqualGUID(riid, &IID_IDispatch)
3427 || IsEqualGUID(riid, &IID_ITextRange)
3428 || IsEqualGUID(riid, &IID_ITextSelection))
3430 *ppvObj = me;
3431 ITextSelection_AddRef(me);
3432 return S_OK;
3434 else if (IsEqualGUID(riid, &IID_Igetrichole))
3436 *ppvObj = This->reOle;
3437 return S_OK;
3440 return E_NOINTERFACE;
3443 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
3445 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3446 return InterlockedIncrement(&This->ref);
3449 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
3451 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3452 ULONG ref = InterlockedDecrement(&This->ref);
3453 if (ref == 0)
3454 heap_free(This);
3455 return ref;
3458 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
3460 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3461 TRACE("(%p)->(%p)\n", This, pctinfo);
3462 *pctinfo = 1;
3463 return S_OK;
3466 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
3467 ITypeInfo **ppTInfo)
3469 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3470 HRESULT hr;
3472 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3474 hr = get_typeinfo(ITextSelection_tid, ppTInfo);
3475 if (SUCCEEDED(hr))
3476 ITypeInfo_AddRef(*ppTInfo);
3477 return hr;
3480 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
3481 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3483 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3484 ITypeInfo *ti;
3485 HRESULT hr;
3487 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
3488 rgDispId);
3490 hr = get_typeinfo(ITextSelection_tid, &ti);
3491 if (SUCCEEDED(hr))
3492 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3493 return hr;
3496 static HRESULT WINAPI ITextSelection_fnInvoke(
3497 ITextSelection *me,
3498 DISPID dispIdMember,
3499 REFIID riid,
3500 LCID lcid,
3501 WORD wFlags,
3502 DISPPARAMS *pDispParams,
3503 VARIANT *pVarResult,
3504 EXCEPINFO *pExcepInfo,
3505 UINT *puArgErr)
3507 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3508 ITypeInfo *ti;
3509 HRESULT hr;
3511 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
3512 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3514 hr = get_typeinfo(ITextSelection_tid, &ti);
3515 if (SUCCEEDED(hr))
3516 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3517 return hr;
3520 /*** ITextRange methods ***/
3521 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
3523 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3524 ME_Cursor *start = NULL, *end = NULL;
3525 int nChars, endOfs;
3526 BOOL bEOP;
3528 TRACE("(%p)->(%p)\n", This, pbstr);
3530 if (!This->reOle)
3531 return CO_E_RELEASED;
3533 if (!pbstr)
3534 return E_INVALIDARG;
3536 ME_GetSelection(This->reOle->editor, &start, &end);
3537 endOfs = ME_GetCursorOfs(end);
3538 nChars = endOfs - ME_GetCursorOfs(start);
3539 if (!nChars)
3541 *pbstr = NULL;
3542 return S_OK;
3545 *pbstr = SysAllocStringLen(NULL, nChars);
3546 if (!*pbstr)
3547 return E_OUTOFMEMORY;
3549 bEOP = (end->pRun->next->type == diTextEnd && endOfs > ME_GetTextLength(This->reOle->editor));
3550 ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
3551 TRACE("%s\n", wine_dbgstr_w(*pbstr));
3553 return S_OK;
3556 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
3558 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3559 if (!This->reOle)
3560 return CO_E_RELEASED;
3562 FIXME("not implemented\n");
3563 return E_NOTIMPL;
3566 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
3568 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3569 ME_Cursor *start = NULL, *end = NULL;
3571 if (!This->reOle)
3572 return CO_E_RELEASED;
3573 TRACE("%p\n", pch);
3574 if (!pch)
3575 return E_INVALIDARG;
3577 ME_GetSelection(This->reOle->editor, &start, &end);
3578 return range_GetChar(This->reOle->editor, start, pch);
3581 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
3583 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3584 if (!This->reOle)
3585 return CO_E_RELEASED;
3587 FIXME("not implemented\n");
3588 return E_NOTIMPL;
3591 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
3593 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3594 if (!This->reOle)
3595 return CO_E_RELEASED;
3597 FIXME("not implemented\n");
3598 return E_NOTIMPL;
3601 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)
3603 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3604 if (!This->reOle)
3605 return CO_E_RELEASED;
3607 FIXME("not implemented\n");
3608 return E_NOTIMPL;
3611 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *pRange)
3613 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3614 if (!This->reOle)
3615 return CO_E_RELEASED;
3617 FIXME("not implemented\n");
3618 return E_NOTIMPL;
3621 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
3623 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3624 LONG lim;
3625 if (!This->reOle)
3626 return CO_E_RELEASED;
3628 if (!pcpFirst)
3629 return E_INVALIDARG;
3630 ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim);
3631 TRACE("%d\n", *pcpFirst);
3632 return S_OK;
3635 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG value)
3637 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3638 LONG start, end;
3639 HRESULT hr;
3641 TRACE("(%p)->(%d)\n", This, value);
3643 if (!This->reOle)
3644 return CO_E_RELEASED;
3646 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
3647 hr = textrange_setstart(This->reOle, value, &start, &end);
3648 if (hr == S_OK)
3649 ME_SetSelection(This->reOle->editor, start, end);
3651 return hr;
3654 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
3656 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3657 LONG first;
3658 if (!This->reOle)
3659 return CO_E_RELEASED;
3661 if (!pcpLim)
3662 return E_INVALIDARG;
3663 ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim);
3664 TRACE("%d\n", *pcpLim);
3665 return S_OK;
3668 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG value)
3670 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3671 LONG start, end;
3672 HRESULT hr;
3674 TRACE("(%p)->(%d)\n", This, value);
3676 if (!This->reOle)
3677 return CO_E_RELEASED;
3679 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
3680 hr = textrange_setend(This->reOle, value, &start, &end);
3681 if (hr == S_OK)
3682 ME_SetSelection(This->reOle->editor, start, end);
3684 return hr;
3687 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **font)
3689 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3691 TRACE("(%p)->(%p)\n", This, font);
3693 if (!This->reOle)
3694 return CO_E_RELEASED;
3696 if (!font)
3697 return E_INVALIDARG;
3699 return create_textfont((ITextRange*)me, NULL, font);
3702 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
3704 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3705 if (!This->reOle)
3706 return CO_E_RELEASED;
3708 FIXME("not implemented\n");
3709 return E_NOTIMPL;
3712 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **para)
3714 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3715 if (!This->reOle)
3716 return CO_E_RELEASED;
3718 FIXME("not implemented\n");
3719 return E_NOTIMPL;
3722 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pPara)
3724 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3725 if (!This->reOle)
3726 return CO_E_RELEASED;
3728 FIXME("not implemented\n");
3729 return E_NOTIMPL;
3732 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *pcch)
3734 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3735 if (!This->reOle)
3736 return CO_E_RELEASED;
3738 FIXME("not implemented\n");
3739 return E_NOTIMPL;
3742 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pValue)
3744 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3745 if (!This->reOle)
3746 return CO_E_RELEASED;
3748 FIXME("not implemented\n");
3749 return E_NOTIMPL;
3752 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
3754 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3755 LONG start, end;
3756 HRESULT hres;
3757 if (!This->reOle)
3758 return CO_E_RELEASED;
3760 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
3761 hres = range_Collapse(bStart, &start, &end);
3762 if (SUCCEEDED(hres))
3763 ME_SetSelection(This->reOle->editor, start, end);
3764 return hres;
3767 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
3769 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3770 if (!This->reOle)
3771 return CO_E_RELEASED;
3773 FIXME("not implemented\n");
3774 return E_NOTIMPL;
3777 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
3779 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3780 if (!This->reOle)
3781 return CO_E_RELEASED;
3783 FIXME("not implemented\n");
3784 return E_NOTIMPL;
3787 static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG Unit, LONG Index,
3788 LONG Extend)
3790 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3791 if (!This->reOle)
3792 return CO_E_RELEASED;
3794 FIXME("not implemented\n");
3795 return E_NOTIMPL;
3798 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActive, LONG cpOther)
3800 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3801 if (!This->reOle)
3802 return CO_E_RELEASED;
3804 FIXME("not implemented\n");
3805 return E_NOTIMPL;
3808 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
3810 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3811 if (!This->reOle)
3812 return CO_E_RELEASED;
3814 FIXME("not implemented\n");
3815 return E_NOTIMPL;
3818 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)
3820 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3821 if (!This->reOle)
3822 return CO_E_RELEASED;
3824 FIXME("not implemented\n");
3825 return E_NOTIMPL;
3828 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb)
3830 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3831 if (!This->reOle)
3832 return CO_E_RELEASED;
3834 FIXME("not implemented\n");
3835 return E_NOTIMPL;
3838 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
3840 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3841 if (!This->reOle)
3842 return CO_E_RELEASED;
3844 FIXME("not implemented\n");
3845 return E_NOTIMPL;
3848 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG Unit, LONG Extend,
3849 LONG *pDelta)
3851 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3852 if (!This->reOle)
3853 return CO_E_RELEASED;
3855 FIXME("not implemented\n");
3856 return E_NOTIMPL;
3859 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG Extend,
3860 LONG *pDelta)
3862 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3863 if (!This->reOle)
3864 return CO_E_RELEASED;
3866 FIXME("not implemented\n");
3867 return E_NOTIMPL;
3870 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG Unit, LONG Count, LONG *pDelta)
3872 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3873 if (!This->reOle)
3874 return CO_E_RELEASED;
3876 FIXME("not implemented\n");
3877 return E_NOTIMPL;
3880 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG Unit, LONG Count,
3881 LONG *pDelta)
3883 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3884 if (!This->reOle)
3885 return CO_E_RELEASED;
3887 FIXME("not implemented\n");
3888 return E_NOTIMPL;
3891 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG Unit, LONG Count,
3892 LONG *pDelta)
3894 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3895 if (!This->reOle)
3896 return CO_E_RELEASED;
3898 FIXME("not implemented\n");
3899 return E_NOTIMPL;
3902 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
3903 LONG *pDelta)
3905 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3906 if (!This->reOle)
3907 return CO_E_RELEASED;
3909 FIXME("not implemented\n");
3910 return E_NOTIMPL;
3913 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
3914 LONG *pDelta)
3916 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3917 if (!This->reOle)
3918 return CO_E_RELEASED;
3920 FIXME("not implemented\n");
3921 return E_NOTIMPL;
3924 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
3925 LONG *pDelta)
3927 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3928 if (!This->reOle)
3929 return CO_E_RELEASED;
3931 FIXME("not implemented\n");
3932 return E_NOTIMPL;
3935 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
3936 LONG *pDelta)
3938 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3939 if (!This->reOle)
3940 return CO_E_RELEASED;
3942 FIXME("not implemented\n");
3943 return E_NOTIMPL;
3946 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
3947 LONG *pDelta)
3949 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3950 if (!This->reOle)
3951 return CO_E_RELEASED;
3953 FIXME("not implemented\n");
3954 return E_NOTIMPL;
3957 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
3958 LONG *pDelta)
3960 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3961 if (!This->reOle)
3962 return CO_E_RELEASED;
3964 FIXME("not implemented\n");
3965 return E_NOTIMPL;
3968 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR bstr, LONG cch, LONG Flags,
3969 LONG *pLength)
3971 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3972 if (!This->reOle)
3973 return CO_E_RELEASED;
3975 FIXME("not implemented\n");
3976 return E_NOTIMPL;
3979 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR bstr, LONG cch,
3980 LONG Flags, LONG *pLength)
3982 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3983 if (!This->reOle)
3984 return CO_E_RELEASED;
3986 FIXME("not implemented\n");
3987 return E_NOTIMPL;
3990 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR bstr, LONG cch,
3991 LONG Flags, LONG *pLength)
3993 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3994 if (!This->reOle)
3995 return CO_E_RELEASED;
3997 FIXME("not implemented\n");
3998 return E_NOTIMPL;
4001 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG Unit, LONG Count,
4002 LONG *pDelta)
4004 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4005 if (!This->reOle)
4006 return CO_E_RELEASED;
4008 FIXME("not implemented\n");
4009 return E_NOTIMPL;
4012 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *pVar)
4014 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4015 if (!This->reOle)
4016 return CO_E_RELEASED;
4018 FIXME("not implemented\n");
4019 return E_NOTIMPL;
4022 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *pVar)
4024 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4025 if (!This->reOle)
4026 return CO_E_RELEASED;
4028 FIXME("not implemented\n");
4029 return E_NOTIMPL;
4032 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *pVar, LONG Format)
4034 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4035 if (!This->reOle)
4036 return CO_E_RELEASED;
4038 FIXME("not implemented\n");
4039 return E_NOTIMPL;
4042 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *pVar, LONG Format,
4043 LONG *pb)
4045 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4046 if (!This->reOle)
4047 return CO_E_RELEASED;
4049 FIXME("not implemented\n");
4050 return E_NOTIMPL;
4053 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *pb)
4055 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4056 if (!This->reOle)
4057 return CO_E_RELEASED;
4059 FIXME("not implemented\n");
4060 return E_NOTIMPL;
4063 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG Type)
4065 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4066 if (!This->reOle)
4067 return CO_E_RELEASED;
4069 FIXME("not implemented\n");
4070 return E_NOTIMPL;
4073 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG Type, LONG *cx, LONG *cy)
4075 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4076 if (!This->reOle)
4077 return CO_E_RELEASED;
4079 FIXME("not implemented\n");
4080 return E_NOTIMPL;
4083 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG Type,
4084 LONG Extend)
4086 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4087 if (!This->reOle)
4088 return CO_E_RELEASED;
4090 FIXME("not implemented\n");
4091 return E_NOTIMPL;
4094 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG Value)
4096 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4097 if (!This->reOle)
4098 return CO_E_RELEASED;
4100 FIXME("not implemented\n");
4101 return E_NOTIMPL;
4104 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
4106 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4107 if (!This->reOle)
4108 return CO_E_RELEASED;
4110 FIXME("not implemented\n");
4111 return E_NOTIMPL;
4114 /*** ITextSelection methods ***/
4115 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags)
4117 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4118 if (!This->reOle)
4119 return CO_E_RELEASED;
4121 FIXME("not implemented\n");
4122 return E_NOTIMPL;
4125 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
4127 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4128 if (!This->reOle)
4129 return CO_E_RELEASED;
4131 FIXME("not implemented\n");
4132 return E_NOTIMPL;
4135 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *pType)
4137 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4138 if (!This->reOle)
4139 return CO_E_RELEASED;
4141 FIXME("not implemented\n");
4142 return E_NOTIMPL;
4145 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG Unit, LONG Count,
4146 LONG Extend, LONG *pDelta)
4148 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4149 if (!This->reOle)
4150 return CO_E_RELEASED;
4152 FIXME("not implemented\n");
4153 return E_NOTIMPL;
4156 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG Unit, LONG Count,
4157 LONG Extend, LONG *pDelta)
4159 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4160 if (!This->reOle)
4161 return CO_E_RELEASED;
4163 FIXME("not implemented\n");
4164 return E_NOTIMPL;
4167 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG Unit, LONG Count,
4168 LONG Extend, LONG *pDelta)
4170 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4171 if (!This->reOle)
4172 return CO_E_RELEASED;
4174 FIXME("not implemented\n");
4175 return E_NOTIMPL;
4178 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG Unit, LONG Count,
4179 LONG Extend, LONG *pDelta)
4181 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4182 if (!This->reOle)
4183 return CO_E_RELEASED;
4185 FIXME("not implemented\n");
4186 return E_NOTIMPL;
4189 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG Unit, LONG Extend,
4190 LONG *pDelta)
4192 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4193 if (!This->reOle)
4194 return CO_E_RELEASED;
4196 FIXME("not implemented\n");
4197 return E_NOTIMPL;
4200 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LONG Extend,
4201 LONG *pDelta)
4203 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4204 if (!This->reOle)
4205 return CO_E_RELEASED;
4207 FIXME("not implemented\n");
4208 return E_NOTIMPL;
4211 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR bstr)
4213 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4214 if (!This->reOle)
4215 return CO_E_RELEASED;
4217 FIXME("not implemented\n");
4218 return E_NOTIMPL;
4221 static const ITextSelectionVtbl tsvt = {
4222 ITextSelection_fnQueryInterface,
4223 ITextSelection_fnAddRef,
4224 ITextSelection_fnRelease,
4225 ITextSelection_fnGetTypeInfoCount,
4226 ITextSelection_fnGetTypeInfo,
4227 ITextSelection_fnGetIDsOfNames,
4228 ITextSelection_fnInvoke,
4229 ITextSelection_fnGetText,
4230 ITextSelection_fnSetText,
4231 ITextSelection_fnGetChar,
4232 ITextSelection_fnSetChar,
4233 ITextSelection_fnGetDuplicate,
4234 ITextSelection_fnGetFormattedText,
4235 ITextSelection_fnSetFormattedText,
4236 ITextSelection_fnGetStart,
4237 ITextSelection_fnSetStart,
4238 ITextSelection_fnGetEnd,
4239 ITextSelection_fnSetEnd,
4240 ITextSelection_fnGetFont,
4241 ITextSelection_fnSetFont,
4242 ITextSelection_fnGetPara,
4243 ITextSelection_fnSetPara,
4244 ITextSelection_fnGetStoryLength,
4245 ITextSelection_fnGetStoryType,
4246 ITextSelection_fnCollapse,
4247 ITextSelection_fnExpand,
4248 ITextSelection_fnGetIndex,
4249 ITextSelection_fnSetIndex,
4250 ITextSelection_fnSetRange,
4251 ITextSelection_fnInRange,
4252 ITextSelection_fnInStory,
4253 ITextSelection_fnIsEqual,
4254 ITextSelection_fnSelect,
4255 ITextSelection_fnStartOf,
4256 ITextSelection_fnEndOf,
4257 ITextSelection_fnMove,
4258 ITextSelection_fnMoveStart,
4259 ITextSelection_fnMoveEnd,
4260 ITextSelection_fnMoveWhile,
4261 ITextSelection_fnMoveStartWhile,
4262 ITextSelection_fnMoveEndWhile,
4263 ITextSelection_fnMoveUntil,
4264 ITextSelection_fnMoveStartUntil,
4265 ITextSelection_fnMoveEndUntil,
4266 ITextSelection_fnFindText,
4267 ITextSelection_fnFindTextStart,
4268 ITextSelection_fnFindTextEnd,
4269 ITextSelection_fnDelete,
4270 ITextSelection_fnCut,
4271 ITextSelection_fnCopy,
4272 ITextSelection_fnPaste,
4273 ITextSelection_fnCanPaste,
4274 ITextSelection_fnCanEdit,
4275 ITextSelection_fnChangeCase,
4276 ITextSelection_fnGetPoint,
4277 ITextSelection_fnSetPoint,
4278 ITextSelection_fnScrollIntoView,
4279 ITextSelection_fnGetEmbeddedObject,
4280 ITextSelection_fnGetFlags,
4281 ITextSelection_fnSetFlags,
4282 ITextSelection_fnGetType,
4283 ITextSelection_fnMoveLeft,
4284 ITextSelection_fnMoveRight,
4285 ITextSelection_fnMoveUp,
4286 ITextSelection_fnMoveDown,
4287 ITextSelection_fnHomeKey,
4288 ITextSelection_fnEndKey,
4289 ITextSelection_fnTypeText
4292 static ITextSelectionImpl *
4293 CreateTextSelection(IRichEditOleImpl *reOle)
4295 ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
4296 if (!txtSel)
4297 return NULL;
4299 txtSel->ITextSelection_iface.lpVtbl = &tsvt;
4300 txtSel->ref = 1;
4301 txtSel->reOle = reOle;
4302 return txtSel;
4305 LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *ppvObj)
4307 IRichEditOleImpl *reo;
4309 reo = heap_alloc(sizeof(IRichEditOleImpl));
4310 if (!reo)
4311 return 0;
4313 reo->IUnknown_inner.lpVtbl = &reo_unk_vtbl;
4314 reo->IRichEditOle_iface.lpVtbl = &revt;
4315 reo->ITextDocument_iface.lpVtbl = &tdvt;
4316 reo->ref = 1;
4317 reo->editor = editor;
4318 reo->txtSel = CreateTextSelection(reo);
4319 if (!reo->txtSel)
4321 heap_free(reo);
4322 return 0;
4324 reo->clientSite = CreateOleClientSite(reo);
4325 if (!reo->clientSite)
4327 ITextSelection_Release(&reo->txtSel->ITextSelection_iface);
4328 heap_free(reo);
4329 return 0;
4331 TRACE("Created %p\n",reo);
4332 list_init(&reo->rangelist);
4333 if (outer_unk)
4334 reo->outer_unk = outer_unk;
4335 else
4336 reo->outer_unk = &reo->IUnknown_inner;
4337 *ppvObj = &reo->IRichEditOle_iface;
4339 return 1;
4342 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
4344 /* sizel is in .01 millimeters, sz in pixels */
4345 sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
4346 sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
4349 /******************************************************************************
4350 * ME_GetOLEObjectSize
4352 * Sets run extent for OLE objects.
4354 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
4356 IDataObject* ido;
4357 FORMATETC fmt;
4358 STGMEDIUM stgm;
4359 DIBSECTION dibsect;
4360 ENHMETAHEADER emh;
4362 assert(run->nFlags & MERF_GRAPHICS);
4363 assert(run->ole_obj);
4365 if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
4367 convert_sizel(c, &run->ole_obj->sizel, pSize);
4368 if (c->editor->nZoomNumerator != 0)
4370 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4371 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4373 return;
4376 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
4378 FIXME("Query Interface IID_IDataObject failed!\n");
4379 pSize->cx = pSize->cy = 0;
4380 return;
4382 fmt.cfFormat = CF_BITMAP;
4383 fmt.ptd = NULL;
4384 fmt.dwAspect = DVASPECT_CONTENT;
4385 fmt.lindex = -1;
4386 fmt.tymed = TYMED_GDI;
4387 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4389 fmt.cfFormat = CF_ENHMETAFILE;
4390 fmt.tymed = TYMED_ENHMF;
4391 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4393 FIXME("unsupported format\n");
4394 pSize->cx = pSize->cy = 0;
4395 IDataObject_Release(ido);
4396 return;
4400 switch (stgm.tymed)
4402 case TYMED_GDI:
4403 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
4404 pSize->cx = dibsect.dsBm.bmWidth;
4405 pSize->cy = dibsect.dsBm.bmHeight;
4406 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
4407 break;
4408 case TYMED_ENHMF:
4409 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
4410 pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
4411 pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
4412 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
4413 break;
4414 default:
4415 FIXME("Unsupported tymed %d\n", stgm.tymed);
4416 break;
4418 IDataObject_Release(ido);
4419 if (c->editor->nZoomNumerator != 0)
4421 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4422 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4426 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
4427 ME_Paragraph *para, BOOL selected)
4429 IDataObject* ido;
4430 FORMATETC fmt;
4431 STGMEDIUM stgm;
4432 DIBSECTION dibsect;
4433 ENHMETAHEADER emh;
4434 HDC hMemDC;
4435 SIZE sz;
4436 BOOL has_size;
4438 assert(run->nFlags & MERF_GRAPHICS);
4439 assert(run->ole_obj);
4440 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
4442 FIXME("Couldn't get interface\n");
4443 return;
4445 has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
4446 fmt.cfFormat = CF_BITMAP;
4447 fmt.ptd = NULL;
4448 fmt.dwAspect = DVASPECT_CONTENT;
4449 fmt.lindex = -1;
4450 fmt.tymed = TYMED_GDI;
4451 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4453 fmt.cfFormat = CF_ENHMETAFILE;
4454 fmt.tymed = TYMED_ENHMF;
4455 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4457 FIXME("Couldn't get storage medium\n");
4458 IDataObject_Release(ido);
4459 return;
4462 switch (stgm.tymed)
4464 case TYMED_GDI:
4465 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
4466 hMemDC = CreateCompatibleDC(c->hDC);
4467 SelectObject(hMemDC, stgm.u.hBitmap);
4468 if (has_size)
4470 convert_sizel(c, &run->ole_obj->sizel, &sz);
4471 } else {
4472 sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
4473 sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
4475 if (c->editor->nZoomNumerator != 0)
4477 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4478 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4480 if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
4482 BitBlt(c->hDC, x, y - sz.cy,
4483 dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
4484 hMemDC, 0, 0, SRCCOPY);
4485 } else {
4486 StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
4487 hMemDC, 0, 0, dibsect.dsBm.bmWidth,
4488 dibsect.dsBm.bmHeight, SRCCOPY);
4490 DeleteDC(hMemDC);
4491 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
4492 break;
4493 case TYMED_ENHMF:
4494 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
4495 if (has_size)
4497 convert_sizel(c, &run->ole_obj->sizel, &sz);
4498 } else {
4499 sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
4500 sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
4502 if (c->editor->nZoomNumerator != 0)
4504 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4505 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4509 RECT rc;
4511 rc.left = x;
4512 rc.top = y - sz.cy;
4513 rc.right = x + sz.cx;
4514 rc.bottom = y;
4515 PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
4517 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
4518 break;
4519 default:
4520 FIXME("Unsupported tymed %d\n", stgm.tymed);
4521 selected = FALSE;
4522 break;
4524 if (selected && !c->editor->bHideSelection)
4525 PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
4526 IDataObject_Release(ido);
4529 void ME_DeleteReObject(REOBJECT* reo)
4531 if (reo->poleobj) IOleObject_Release(reo->poleobj);
4532 if (reo->pstg) IStorage_Release(reo->pstg);
4533 if (reo->polesite) IOleClientSite_Release(reo->polesite);
4534 FREE_OBJ(reo);
4537 void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
4539 *dst = *src;
4541 if (dst->poleobj) IOleObject_AddRef(dst->poleobj);
4542 if (dst->pstg) IStorage_AddRef(dst->pstg);
4543 if (dst->polesite) IOleClientSite_AddRef(dst->polesite);
4546 void ME_GetITextDocumentInterface(IRichEditOle *iface, LPVOID *ppvObj)
4548 IRichEditOleImpl *This = impl_from_IRichEditOle(iface);
4549 *ppvObj = &This->ITextDocument_iface;