riched20: Implement SetText for regular range.
[wine/multimedia.git] / dlls / riched20 / richole.c
blob06ff9aadf5613f2dec6b727e507a07430977e9d5
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,
168 FONT_PROPID_FIRST = FONT_ALLCAPS
171 static const DWORD textfont_prop_masks[][2] = {
172 { CFM_ALLCAPS, CFE_ALLCAPS },
173 { CFM_ANIMATION },
174 { CFM_BACKCOLOR, CFE_AUTOBACKCOLOR },
175 { CFM_BOLD, CFE_BOLD },
176 { CFM_EMBOSS, CFE_EMBOSS },
177 { CFM_COLOR, CFE_AUTOCOLOR },
178 { CFM_HIDDEN, CFE_HIDDEN },
179 { CFM_IMPRINT, CFE_IMPRINT },
180 { CFM_ITALIC, CFE_ITALIC },
181 { CFM_KERNING },
182 { CFM_LCID },
183 { CFM_FACE },
184 { CFM_OUTLINE, CFE_OUTLINE },
185 { CFM_OFFSET },
186 { CFM_PROTECTED, CFE_PROTECTED },
187 { CFM_SHADOW, CFE_SHADOW },
188 { CFM_SIZE },
189 { CFM_SMALLCAPS, CFE_SMALLCAPS },
190 { CFM_SPACING },
191 { CFM_STRIKEOUT, CFE_STRIKEOUT },
192 { CFM_SUBSCRIPT, CFE_SUBSCRIPT },
193 { CFM_SUPERSCRIPT, CFE_SUPERSCRIPT },
194 { CFM_UNDERLINE, CFE_UNDERLINE },
195 { CFM_WEIGHT }
198 typedef union {
199 FLOAT f;
200 LONG l;
201 BSTR str;
202 } textfont_prop_val;
204 enum range_update_op {
205 RANGE_UPDATE_DELETE
208 typedef struct IRichEditOleImpl {
209 IUnknown IUnknown_inner;
210 IRichEditOle IRichEditOle_iface;
211 ITextDocument ITextDocument_iface;
212 IUnknown *outer_unk;
213 LONG ref;
215 ME_TextEditor *editor;
216 ITextSelectionImpl *txtSel;
217 IOleClientSiteImpl *clientSite;
218 struct list rangelist;
219 } IRichEditOleImpl;
221 struct ITextRangeImpl {
222 ITextRange ITextRange_iface;
223 LONG ref;
224 LONG start, end;
225 struct list entry;
227 IRichEditOleImpl *reOle;
230 struct ITextSelectionImpl {
231 ITextSelection ITextSelection_iface;
232 LONG ref;
234 IRichEditOleImpl *reOle;
237 typedef struct ITextFontImpl {
238 ITextFont ITextFont_iface;
239 LONG ref;
241 ITextRange *range;
242 textfont_prop_val props[FONT_PROPID_LAST];
243 BOOL get_cache_enabled;
244 BOOL set_cache_enabled;
245 } ITextFontImpl;
247 typedef struct ITextParaImpl {
248 ITextPara ITextPara_iface;
249 LONG ref;
251 ITextRange *range;
252 } ITextParaImpl;
254 struct IOleClientSiteImpl {
255 IOleClientSite IOleClientSite_iface;
256 IOleWindow IOleWindow_iface;
257 IOleInPlaceSite IOleInPlaceSite_iface;
258 LONG ref;
260 IRichEditOleImpl *reOle;
263 static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
265 return CONTAINING_RECORD(iface, IRichEditOleImpl, IRichEditOle_iface);
268 static inline IRichEditOleImpl *impl_from_ITextDocument(ITextDocument *iface)
270 return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument_iface);
273 static inline IRichEditOleImpl *impl_from_IUnknown(IUnknown *iface)
275 return CONTAINING_RECORD(iface, IRichEditOleImpl, IUnknown_inner);
278 static inline IOleClientSiteImpl *impl_from_IOleWindow(IOleWindow *iface)
280 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleWindow_iface);
283 static inline IOleClientSiteImpl *impl_from_IOleInPlaceSite(IOleInPlaceSite *iface)
285 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleInPlaceSite_iface);
288 static inline ITextRangeImpl *impl_from_ITextRange(ITextRange *iface)
290 return CONTAINING_RECORD(iface, ITextRangeImpl, ITextRange_iface);
293 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
295 return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
298 static inline ITextFontImpl *impl_from_ITextFont(ITextFont *iface)
300 return CONTAINING_RECORD(iface, ITextFontImpl, ITextFont_iface);
303 static inline ITextParaImpl *impl_from_ITextPara(ITextPara *iface)
305 return CONTAINING_RECORD(iface, ITextParaImpl, ITextPara_iface);
308 static HRESULT create_textfont(ITextRange*, const ITextFontImpl*, ITextFont**);
309 static HRESULT create_textpara(ITextRange*, ITextPara**);
311 static void textranges_update_ranges(IRichEditOleImpl *reole, LONG start, LONG end, enum range_update_op op)
313 ITextRangeImpl *range;
315 LIST_FOR_EACH_ENTRY(range, &reole->rangelist, ITextRangeImpl, entry) {
316 switch (op)
318 case RANGE_UPDATE_DELETE:
319 /* range fully covered by deleted range - collapse to insertion point */
320 if (range->start >= start && range->end <= end)
321 range->start = range->end = start;
322 /* deleted range cuts from the right */
323 else if (range->start < start && range->end <= end)
324 range->end = start;
325 /* deleted range cuts from the left */
326 else if (range->start >= start && range->end > end) {
327 range->start = start;
328 range->end -= end - start;
330 /* deleted range cuts within */
331 else
332 range->end -= end - start;
333 break;
334 default:
335 FIXME("unknown update op, %d\n", op);
340 static inline BOOL is_equal_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *left,
341 textfont_prop_val *right)
343 switch (propid)
345 case FONT_ALLCAPS:
346 case FONT_ANIMATION:
347 case FONT_BACKCOLOR:
348 case FONT_BOLD:
349 case FONT_EMBOSS:
350 case FONT_FORECOLOR:
351 case FONT_HIDDEN:
352 case FONT_ENGRAVE:
353 case FONT_ITALIC:
354 case FONT_KERNING:
355 case FONT_LANGID:
356 case FONT_OUTLINE:
357 case FONT_PROTECTED:
358 case FONT_SHADOW:
359 case FONT_SMALLCAPS:
360 case FONT_STRIKETHROUGH:
361 case FONT_SUBSCRIPT:
362 case FONT_SUPERSCRIPT:
363 case FONT_UNDERLINE:
364 case FONT_WEIGHT:
365 return left->l == right->l;
366 case FONT_NAME:
367 return !strcmpW(left->str, right->str);
368 case FONT_POSITION:
369 case FONT_SIZE:
370 case FONT_SPACING:
371 return left->f == right->f;
372 default:
373 FIXME("unhandled font property %d\n", propid);
374 return FALSE;
378 static inline void init_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *v)
380 switch (propid)
382 case FONT_ALLCAPS:
383 case FONT_ANIMATION:
384 case FONT_BACKCOLOR:
385 case FONT_BOLD:
386 case FONT_EMBOSS:
387 case FONT_FORECOLOR:
388 case FONT_HIDDEN:
389 case FONT_ENGRAVE:
390 case FONT_ITALIC:
391 case FONT_KERNING:
392 case FONT_LANGID:
393 case FONT_OUTLINE:
394 case FONT_PROTECTED:
395 case FONT_SHADOW:
396 case FONT_SMALLCAPS:
397 case FONT_STRIKETHROUGH:
398 case FONT_SUBSCRIPT:
399 case FONT_SUPERSCRIPT:
400 case FONT_UNDERLINE:
401 case FONT_WEIGHT:
402 v->l = tomUndefined;
403 return;
404 case FONT_NAME:
405 v->str = NULL;
406 return;
407 case FONT_POSITION:
408 case FONT_SIZE:
409 case FONT_SPACING:
410 v->f = tomUndefined;
411 return;
412 default:
413 FIXME("unhandled font property %d\n", propid);
414 v->l = tomUndefined;
415 return;
419 static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid,
420 textfont_prop_val *value)
422 ME_Cursor from, to;
423 CHARFORMAT2W fmt;
425 memset(&fmt, 0, sizeof(fmt));
426 fmt.cbSize = sizeof(fmt);
427 fmt.dwMask = textfont_prop_masks[propid][0];
429 ME_CursorFromCharOfs(reole->editor, pos, &from);
430 to = from;
431 ME_MoveCursorChars(reole->editor, &to, 1);
432 ME_GetCharFormat(reole->editor, &from, &to, &fmt);
434 switch (propid)
436 case FONT_ALLCAPS:
437 case FONT_BOLD:
438 case FONT_EMBOSS:
439 case FONT_HIDDEN:
440 case FONT_ENGRAVE:
441 case FONT_ITALIC:
442 case FONT_OUTLINE:
443 case FONT_PROTECTED:
444 case FONT_SHADOW:
445 case FONT_SMALLCAPS:
446 case FONT_STRIKETHROUGH:
447 case FONT_SUBSCRIPT:
448 case FONT_SUPERSCRIPT:
449 case FONT_UNDERLINE:
450 value->l = fmt.dwEffects & textfont_prop_masks[propid][1] ? tomTrue : tomFalse;
451 break;
452 case FONT_ANIMATION:
453 value->l = fmt.bAnimation;
454 break;
455 case FONT_BACKCOLOR:
456 value->l = fmt.dwEffects & CFE_AUTOBACKCOLOR ? GetSysColor(COLOR_WINDOW) : fmt.crBackColor;
457 break;
458 case FONT_FORECOLOR:
459 value->l = fmt.dwEffects & CFE_AUTOCOLOR ? GetSysColor(COLOR_WINDOWTEXT) : fmt.crTextColor;
460 break;
461 case FONT_KERNING:
462 value->f = fmt.wKerning;
463 break;
464 case FONT_LANGID:
465 value->l = fmt.lcid;
466 break;
467 case FONT_NAME:
468 /* this case is used exclusively by GetName() */
469 value->str = SysAllocString(fmt.szFaceName);
470 if (!value->str)
471 return E_OUTOFMEMORY;
472 break;
473 case FONT_POSITION:
474 value->f = fmt.yOffset;
475 break;
476 case FONT_SIZE:
477 value->f = fmt.yHeight;
478 break;
479 case FONT_SPACING:
480 value->f = fmt.sSpacing;
481 break;
482 case FONT_WEIGHT:
483 value->l = fmt.wWeight;
484 break;
485 default:
486 FIXME("unhandled font property %d\n", propid);
487 return E_FAIL;
490 return S_OK;
493 static inline const IRichEditOleImpl *get_range_reole(ITextRange *range)
495 IRichEditOleImpl *reole = NULL;
496 ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&reole);
497 return reole;
500 static HRESULT get_textfont_prop(const ITextFontImpl *font, enum textfont_prop_id propid, textfont_prop_val *value)
502 const IRichEditOleImpl *reole;
503 textfont_prop_val v;
504 LONG start, end, i;
505 HRESULT hr;
507 /* when font is not attached to any range use cached values */
508 if (!font->range || font->get_cache_enabled) {
509 *value = font->props[propid];
510 return S_OK;
513 if (!(reole = get_range_reole(font->range)))
514 return CO_E_RELEASED;
516 init_textfont_prop_value(propid, value);
518 ITextRange_GetStart(font->range, &start);
519 ITextRange_GetEnd(font->range, &end);
521 /* iterate trough a range to see if property value is consistent */
522 hr = get_textfont_prop_for_pos(reole, start, propid, &v);
523 if (FAILED(hr))
524 return hr;
526 for (i = start + 1; i < end; i++) {
527 textfont_prop_val cur;
529 hr = get_textfont_prop_for_pos(reole, i, propid, &cur);
530 if (FAILED(hr))
531 return hr;
533 if (!is_equal_textfont_prop_value(propid, &v, &cur))
534 return S_OK;
537 *value = v;
538 return S_OK;
541 static HRESULT get_textfont_propf(const ITextFontImpl *font, enum textfont_prop_id propid, FLOAT *value)
543 textfont_prop_val v;
544 HRESULT hr;
546 if (!value)
547 return E_INVALIDARG;
549 hr = get_textfont_prop(font, propid, &v);
550 *value = v.f;
551 return hr;
554 static HRESULT get_textfont_propl(const ITextFontImpl *font, enum textfont_prop_id propid, LONG *value)
556 textfont_prop_val v;
557 HRESULT hr;
559 if (!value)
560 return E_INVALIDARG;
562 hr = get_textfont_prop(font, propid, &v);
563 *value = v.l;
564 return hr;
567 /* Value should already have a terminal value, for boolean properties it means tomToggle is not handled */
568 static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id propid, const textfont_prop_val *value)
570 const IRichEditOleImpl *reole;
571 ME_Cursor from, to;
572 CHARFORMAT2W fmt;
573 LONG start, end;
575 /* when font is not attached to any range use cache */
576 if (!font->range || font->set_cache_enabled) {
577 if (propid == FONT_NAME) {
578 SysFreeString(font->props[propid].str);
579 font->props[propid].str = SysAllocString(value->str);
581 else
582 font->props[propid] = *value;
583 return S_OK;
586 if (!(reole = get_range_reole(font->range)))
587 return CO_E_RELEASED;
589 memset(&fmt, 0, sizeof(fmt));
590 fmt.cbSize = sizeof(fmt);
591 fmt.dwMask = textfont_prop_masks[propid][0];
593 switch (propid)
595 case FONT_ALLCAPS:
596 case FONT_BOLD:
597 case FONT_EMBOSS:
598 case FONT_HIDDEN:
599 case FONT_ENGRAVE:
600 case FONT_ITALIC:
601 case FONT_OUTLINE:
602 case FONT_PROTECTED:
603 case FONT_SHADOW:
604 case FONT_SMALLCAPS:
605 case FONT_STRIKETHROUGH:
606 case FONT_SUBSCRIPT:
607 case FONT_SUPERSCRIPT:
608 case FONT_UNDERLINE:
609 fmt.dwEffects = value->l == tomTrue ? textfont_prop_masks[propid][1] : 0;
610 break;
611 case FONT_ANIMATION:
612 fmt.bAnimation = value->l;
613 break;
614 case FONT_BACKCOLOR:
615 case FONT_FORECOLOR:
616 if (value->l == tomAutoColor)
617 fmt.dwEffects = textfont_prop_masks[propid][1];
618 else if (propid == FONT_BACKCOLOR)
619 fmt.crBackColor = value->l;
620 else
621 fmt.crTextColor = value->l;
622 break;
623 case FONT_KERNING:
624 fmt.wKerning = value->f;
625 break;
626 case FONT_LANGID:
627 fmt.lcid = value->l;
628 break;
629 case FONT_POSITION:
630 fmt.yOffset = value->f;
631 break;
632 case FONT_SIZE:
633 fmt.yHeight = value->f;
634 break;
635 case FONT_SPACING:
636 fmt.sSpacing = value->f;
637 break;
638 case FONT_WEIGHT:
639 fmt.wWeight = value->l;
640 break;
641 case FONT_NAME:
642 lstrcpynW(fmt.szFaceName, value->str, sizeof(fmt.szFaceName)/sizeof(WCHAR));
643 break;
644 default:
645 FIXME("unhandled font property %d\n", propid);
646 return E_FAIL;
649 ITextRange_GetStart(font->range, &start);
650 ITextRange_GetEnd(font->range, &end);
652 ME_CursorFromCharOfs(reole->editor, start, &from);
653 ME_CursorFromCharOfs(reole->editor, end, &to);
654 ME_SetCharFormat(reole->editor, &from, &to, &fmt);
656 return S_OK;
659 static inline HRESULT set_textfont_propl(ITextFontImpl *font, enum textfont_prop_id propid, LONG value)
661 textfont_prop_val v;
662 v.l = value;
663 return set_textfont_prop(font, propid, &v);
666 static inline HRESULT set_textfont_propf(ITextFontImpl *font, enum textfont_prop_id propid, FLOAT value)
668 textfont_prop_val v;
669 v.f = value;
670 return set_textfont_prop(font, propid, &v);
673 static HRESULT set_textfont_propd(ITextFontImpl *font, enum textfont_prop_id propid, LONG value)
675 textfont_prop_val v;
677 switch (value)
679 case tomUndefined:
680 return S_OK;
681 case tomToggle: {
682 LONG oldvalue;
683 get_textfont_propl(font, propid, &oldvalue);
684 if (oldvalue == tomFalse)
685 value = tomTrue;
686 else if (oldvalue == tomTrue)
687 value = tomFalse;
688 else
689 return E_INVALIDARG;
690 /* fallthrough */
692 case tomTrue:
693 case tomFalse:
694 v.l = value;
695 return set_textfont_prop(font, propid, &v);
696 default:
697 return E_INVALIDARG;
701 static HRESULT textfont_getname_from_range(ITextRange *range, BSTR *ret)
703 const IRichEditOleImpl *reole;
704 textfont_prop_val v;
705 HRESULT hr;
706 LONG start;
708 if (!(reole = get_range_reole(range)))
709 return CO_E_RELEASED;
711 ITextRange_GetStart(range, &start);
712 hr = get_textfont_prop_for_pos(reole, start, FONT_NAME, &v);
713 *ret = v.str;
714 return hr;
717 static void textfont_cache_range_props(ITextFontImpl *font)
719 enum textfont_prop_id propid;
720 for (propid = FONT_PROPID_FIRST; propid < FONT_PROPID_LAST; propid++) {
721 if (propid == FONT_NAME)
722 textfont_getname_from_range(font->range, &font->props[propid].str);
723 else
724 get_textfont_prop(font, propid, &font->props[propid]);
728 static HRESULT WINAPI IRichEditOleImpl_inner_fnQueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppvObj)
730 IRichEditOleImpl *This = impl_from_IUnknown(iface);
732 TRACE("%p %s\n", This, debugstr_guid(riid));
734 *ppvObj = NULL;
735 if (IsEqualGUID(riid, &IID_IUnknown))
736 *ppvObj = &This->IUnknown_inner;
737 else if (IsEqualGUID(riid, &IID_IRichEditOle))
738 *ppvObj = &This->IRichEditOle_iface;
739 else if (IsEqualGUID(riid, &IID_ITextDocument))
740 *ppvObj = &This->ITextDocument_iface;
741 if (*ppvObj)
743 IUnknown_AddRef((IUnknown *)*ppvObj);
744 return S_OK;
746 FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid));
748 return E_NOINTERFACE;
751 static ULONG WINAPI IRichEditOleImpl_inner_fnAddRef(IUnknown *iface)
753 IRichEditOleImpl *This = impl_from_IUnknown(iface);
754 ULONG ref = InterlockedIncrement(&This->ref);
756 TRACE("%p ref = %u\n", This, ref);
758 return ref;
761 static ULONG WINAPI IRichEditOleImpl_inner_fnRelease(IUnknown *iface)
763 IRichEditOleImpl *This = impl_from_IUnknown(iface);
764 ULONG ref = InterlockedDecrement(&This->ref);
766 TRACE ("%p ref=%u\n", This, ref);
768 if (!ref)
770 ITextRangeImpl *txtRge;
772 TRACE("Destroying %p\n", This);
773 This->txtSel->reOle = NULL;
774 This->editor->reOle = NULL;
775 ITextSelection_Release(&This->txtSel->ITextSelection_iface);
776 IOleClientSite_Release(&This->clientSite->IOleClientSite_iface);
777 LIST_FOR_EACH_ENTRY(txtRge, &This->rangelist, ITextRangeImpl, entry)
778 txtRge->reOle = NULL;
779 heap_free(This);
781 return ref;
784 static const IUnknownVtbl reo_unk_vtbl =
786 IRichEditOleImpl_inner_fnQueryInterface,
787 IRichEditOleImpl_inner_fnAddRef,
788 IRichEditOleImpl_inner_fnRelease
791 static HRESULT WINAPI
792 IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
794 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
795 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
798 static ULONG WINAPI
799 IRichEditOle_fnAddRef(IRichEditOle *me)
801 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
802 return IUnknown_AddRef(This->outer_unk);
805 static ULONG WINAPI
806 IRichEditOle_fnRelease(IRichEditOle *me)
808 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
809 return IUnknown_Release(This->outer_unk);
812 static HRESULT WINAPI
813 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
815 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
816 FIXME("stub %p\n",This);
817 return E_NOTIMPL;
820 static HRESULT WINAPI
821 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
823 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
824 FIXME("stub %p\n",This);
825 return E_NOTIMPL;
828 static HRESULT WINAPI
829 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
830 REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
832 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
833 FIXME("stub %p\n",This);
834 return E_NOTIMPL;
837 static inline IOleClientSiteImpl *impl_from_IOleClientSite(IOleClientSite *iface)
839 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleClientSite_iface);
842 static HRESULT WINAPI
843 IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
845 IOleClientSiteImpl *This = impl_from_IOleClientSite(me);
846 TRACE("%p %s\n", me, debugstr_guid(riid) );
848 *ppvObj = NULL;
849 if (IsEqualGUID(riid, &IID_IUnknown) ||
850 IsEqualGUID(riid, &IID_IOleClientSite))
851 *ppvObj = me;
852 else if (IsEqualGUID(riid, &IID_IOleWindow))
853 *ppvObj = &This->IOleWindow_iface;
854 else if (IsEqualGUID(riid, &IID_IOleInPlaceSite))
855 *ppvObj = &This->IOleInPlaceSite_iface;
856 if (*ppvObj)
858 IOleClientSite_AddRef(me);
859 return S_OK;
861 FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );
863 return E_NOINTERFACE;
866 static ULONG WINAPI IOleClientSite_fnAddRef(IOleClientSite *iface)
868 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
869 return InterlockedIncrement(&This->ref);
872 static ULONG WINAPI IOleClientSite_fnRelease(IOleClientSite *iface)
874 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
875 ULONG ref = InterlockedDecrement(&This->ref);
876 if (ref == 0)
877 heap_free(This);
878 return ref;
881 static HRESULT WINAPI IOleClientSite_fnSaveObject(IOleClientSite *iface)
883 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
884 if (!This->reOle)
885 return CO_E_RELEASED;
887 FIXME("stub %p\n", iface);
888 return E_NOTIMPL;
892 static HRESULT WINAPI IOleClientSite_fnGetMoniker(IOleClientSite *iface, DWORD dwAssign,
893 DWORD dwWhichMoniker, IMoniker **ppmk)
895 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
896 if (!This->reOle)
897 return CO_E_RELEASED;
899 FIXME("stub %p\n", iface);
900 return E_NOTIMPL;
903 static HRESULT WINAPI IOleClientSite_fnGetContainer(IOleClientSite *iface,
904 IOleContainer **ppContainer)
906 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
907 if (!This->reOle)
908 return CO_E_RELEASED;
910 FIXME("stub %p\n", iface);
911 return E_NOTIMPL;
914 static HRESULT WINAPI IOleClientSite_fnShowObject(IOleClientSite *iface)
916 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
917 if (!This->reOle)
918 return CO_E_RELEASED;
920 FIXME("stub %p\n", iface);
921 return E_NOTIMPL;
924 static HRESULT WINAPI IOleClientSite_fnOnShowWindow(IOleClientSite *iface, BOOL fShow)
926 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
927 if (!This->reOle)
928 return CO_E_RELEASED;
930 FIXME("stub %p\n", iface);
931 return E_NOTIMPL;
934 static HRESULT WINAPI IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *iface)
936 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
937 if (!This->reOle)
938 return CO_E_RELEASED;
940 FIXME("stub %p\n", iface);
941 return E_NOTIMPL;
944 static const IOleClientSiteVtbl ocst = {
945 IOleClientSite_fnQueryInterface,
946 IOleClientSite_fnAddRef,
947 IOleClientSite_fnRelease,
948 IOleClientSite_fnSaveObject,
949 IOleClientSite_fnGetMoniker,
950 IOleClientSite_fnGetContainer,
951 IOleClientSite_fnShowObject,
952 IOleClientSite_fnOnShowWindow,
953 IOleClientSite_fnRequestNewObjectLayout
956 /* IOleWindow interface */
957 static HRESULT WINAPI IOleWindow_fnQueryInterface(IOleWindow *iface, REFIID riid, void **ppvObj)
959 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
960 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppvObj);
963 static ULONG WINAPI IOleWindow_fnAddRef(IOleWindow *iface)
965 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
966 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
969 static ULONG WINAPI IOleWindow_fnRelease(IOleWindow *iface)
971 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
972 return IOleClientSite_Release(&This->IOleClientSite_iface);
975 static HRESULT WINAPI IOleWindow_fnContextSensitiveHelp(IOleWindow *iface, BOOL fEnterMode)
977 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
978 FIXME("not implemented: (%p)->(%d)\n", This, fEnterMode);
979 return E_NOTIMPL;
982 static HRESULT WINAPI IOleWindow_fnGetWindow(IOleWindow *iface, HWND *phwnd)
984 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
985 TRACE("(%p)->(%p)\n", This, phwnd);
987 if (!phwnd)
988 return E_INVALIDARG;
990 *phwnd = This->reOle->editor->hWnd;
991 return S_OK;
994 static const IOleWindowVtbl olewinvt = {
995 IOleWindow_fnQueryInterface,
996 IOleWindow_fnAddRef,
997 IOleWindow_fnRelease,
998 IOleWindow_fnGetWindow,
999 IOleWindow_fnContextSensitiveHelp
1002 /* IOleInPlaceSite interface */
1003 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnQueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppvObj)
1005 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1006 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppvObj);
1009 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnAddRef(IOleInPlaceSite *iface)
1011 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1012 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1015 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnRelease(IOleInPlaceSite *iface)
1017 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1018 return IOleClientSite_Release(&This->IOleClientSite_iface);
1021 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindow(IOleInPlaceSite *iface, HWND *phwnd)
1023 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1024 return IOleWindow_GetWindow(&This->IOleWindow_iface, phwnd);
1027 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1029 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1030 return IOleWindow_ContextSensitiveHelp(&This->IOleWindow_iface, fEnterMode);
1033 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnCanInPlaceActivate(IOleInPlaceSite *iface)
1035 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1036 FIXME("not implemented: (%p)\n", This);
1037 return E_NOTIMPL;
1040 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceActivate(IOleInPlaceSite *iface)
1042 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1043 FIXME("not implemented: (%p)\n", This);
1044 return E_NOTIMPL;
1047 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIActivate(IOleInPlaceSite *iface)
1049 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1050 FIXME("not implemented: (%p)\n", This);
1051 return E_NOTIMPL;
1054 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindowContext(IOleInPlaceSite *iface, IOleInPlaceFrame **ppFrame,
1055 IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1056 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1058 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1059 FIXME("not implemented: (%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
1060 return E_NOTIMPL;
1063 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnScroll(IOleInPlaceSite *iface, SIZE scrollExtent)
1065 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1066 FIXME("not implemented: (%p)\n", This);
1067 return E_NOTIMPL;
1070 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1072 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1073 FIXME("not implemented: (%p)->(%d)\n", This, fUndoable);
1074 return E_NOTIMPL;
1077 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceDeactivate(IOleInPlaceSite *iface)
1079 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1080 FIXME("not implemented: (%p)\n", This);
1081 return E_NOTIMPL;
1084 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDiscardUndoState(IOleInPlaceSite *iface)
1086 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1087 FIXME("not implemented: (%p)\n", This);
1088 return E_NOTIMPL;
1091 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDeactivateAndUndo(IOleInPlaceSite *iface)
1093 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1094 FIXME("not implemented: (%p)\n", This);
1095 return E_NOTIMPL;
1098 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1100 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1101 FIXME("not implemented: (%p)->(%p)\n", This, lprcPosRect);
1102 return E_NOTIMPL;
1105 static const IOleInPlaceSiteVtbl olestvt =
1107 IOleInPlaceSite_fnQueryInterface,
1108 IOleInPlaceSite_fnAddRef,
1109 IOleInPlaceSite_fnRelease,
1110 IOleInPlaceSite_fnGetWindow,
1111 IOleInPlaceSite_fnContextSensitiveHelp,
1112 IOleInPlaceSite_fnCanInPlaceActivate,
1113 IOleInPlaceSite_fnOnInPlaceActivate,
1114 IOleInPlaceSite_fnOnUIActivate,
1115 IOleInPlaceSite_fnGetWindowContext,
1116 IOleInPlaceSite_fnScroll,
1117 IOleInPlaceSite_fnOnUIDeactivate,
1118 IOleInPlaceSite_fnOnInPlaceDeactivate,
1119 IOleInPlaceSite_fnDiscardUndoState,
1120 IOleInPlaceSite_fnDeactivateAndUndo,
1121 IOleInPlaceSite_fnOnPosRectChange
1124 static IOleClientSiteImpl *
1125 CreateOleClientSite(IRichEditOleImpl *reOle)
1127 IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
1128 if (!clientSite)
1129 return NULL;
1131 clientSite->IOleClientSite_iface.lpVtbl = &ocst;
1132 clientSite->IOleWindow_iface.lpVtbl = &olewinvt;
1133 clientSite->IOleInPlaceSite_iface.lpVtbl = &olestvt;
1134 clientSite->ref = 1;
1135 clientSite->reOle = reOle;
1136 return clientSite;
1139 static HRESULT WINAPI
1140 IRichEditOle_fnGetClientSite(IRichEditOle *me,
1141 LPOLECLIENTSITE *lplpolesite)
1143 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1145 TRACE("%p,%p\n",This, lplpolesite);
1147 if(!lplpolesite)
1148 return E_INVALIDARG;
1149 *lplpolesite = &This->clientSite->IOleClientSite_iface;
1150 IOleClientSite_AddRef(*lplpolesite);
1151 return S_OK;
1154 static HRESULT WINAPI
1155 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
1156 DWORD reco, LPDATAOBJECT *lplpdataobj)
1158 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1159 ME_Cursor start;
1160 int nChars;
1162 TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
1163 if(!lplpdataobj)
1164 return E_INVALIDARG;
1165 if(!lpchrg) {
1166 int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
1167 start = This->editor->pCursors[nStartCur];
1168 nChars = nTo - nFrom;
1169 } else {
1170 ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
1171 nChars = lpchrg->cpMax - lpchrg->cpMin;
1173 return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
1176 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
1178 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1179 FIXME("stub %p\n",This);
1180 return E_NOTIMPL;
1183 static HRESULT WINAPI
1184 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
1185 REOBJECT *lpreobject, DWORD dwFlags)
1187 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1188 FIXME("stub %p\n",This);
1189 return E_NOTIMPL;
1192 static LONG WINAPI
1193 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
1195 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1196 FIXME("stub %p\n",This);
1197 return 0;
1200 static HRESULT WINAPI
1201 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
1203 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1204 FIXME("stub %p\n",This);
1205 return E_NOTIMPL;
1208 static HRESULT WINAPI
1209 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
1210 CLIPFORMAT cf, HGLOBAL hMetaPict)
1212 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1213 FIXME("stub %p\n",This);
1214 return E_NOTIMPL;
1217 static HRESULT WINAPI
1218 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
1220 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1221 FIXME("stub %p\n",This);
1222 return E_NOTIMPL;
1225 static HRESULT WINAPI
1226 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
1228 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1229 TRACE("(%p,%p)\n", This, reo);
1231 if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
1233 ME_InsertOLEFromCursor(This->editor, reo, 0);
1234 ME_CommitUndo(This->editor);
1235 ME_UpdateRepaint(This->editor, FALSE);
1236 return S_OK;
1239 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
1240 LPSTORAGE lpstg)
1242 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1243 FIXME("stub %p\n",This);
1244 return E_NOTIMPL;
1247 static HRESULT WINAPI
1248 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
1250 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1251 FIXME("stub %p\n",This);
1252 return E_NOTIMPL;
1255 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
1256 LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
1258 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1259 FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
1260 return E_NOTIMPL;
1263 static HRESULT WINAPI
1264 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
1266 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1267 FIXME("stub %p\n",This);
1268 return E_NOTIMPL;
1271 static const IRichEditOleVtbl revt = {
1272 IRichEditOle_fnQueryInterface,
1273 IRichEditOle_fnAddRef,
1274 IRichEditOle_fnRelease,
1275 IRichEditOle_fnGetClientSite,
1276 IRichEditOle_fnGetObjectCount,
1277 IRichEditOle_fnGetLinkCount,
1278 IRichEditOle_fnGetObject,
1279 IRichEditOle_fnInsertObject,
1280 IRichEditOle_fnConvertObject,
1281 IRichEditOle_fnActivateAs,
1282 IRichEditOle_fnSetHostNames,
1283 IRichEditOle_fnSetLinkAvailable,
1284 IRichEditOle_fnSetDvaspect,
1285 IRichEditOle_fnHandsOffStorage,
1286 IRichEditOle_fnSaveCompleted,
1287 IRichEditOle_fnInPlaceDeactivate,
1288 IRichEditOle_fnContextSensitiveHelp,
1289 IRichEditOle_fnGetClipboardData,
1290 IRichEditOle_fnImportDataObject
1293 /* ITextRange interface */
1294 static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
1296 ITextRangeImpl *This = impl_from_ITextRange(me);
1298 *ppvObj = NULL;
1299 if (IsEqualGUID(riid, &IID_IUnknown)
1300 || IsEqualGUID(riid, &IID_IDispatch)
1301 || IsEqualGUID(riid, &IID_ITextRange))
1303 *ppvObj = me;
1304 ITextRange_AddRef(me);
1305 return S_OK;
1307 else if (IsEqualGUID(riid, &IID_Igetrichole))
1309 *ppvObj = This->reOle;
1310 return S_OK;
1313 return E_NOINTERFACE;
1316 static ULONG WINAPI ITextRange_fnAddRef(ITextRange *me)
1318 ITextRangeImpl *This = impl_from_ITextRange(me);
1319 return InterlockedIncrement(&This->ref);
1322 static ULONG WINAPI ITextRange_fnRelease(ITextRange *me)
1324 ITextRangeImpl *This = impl_from_ITextRange(me);
1325 ULONG ref = InterlockedDecrement(&This->ref);
1327 TRACE ("%p ref=%u\n", This, ref);
1328 if (ref == 0)
1330 if (This->reOle)
1332 list_remove(&This->entry);
1333 This->reOle = NULL;
1335 heap_free(This);
1337 return ref;
1340 static HRESULT WINAPI ITextRange_fnGetTypeInfoCount(ITextRange *me, UINT *pctinfo)
1342 ITextRangeImpl *This = impl_from_ITextRange(me);
1343 TRACE("(%p)->(%p)\n", This, pctinfo);
1344 *pctinfo = 1;
1345 return S_OK;
1348 static HRESULT WINAPI ITextRange_fnGetTypeInfo(ITextRange *me, UINT iTInfo, LCID lcid,
1349 ITypeInfo **ppTInfo)
1351 ITextRangeImpl *This = impl_from_ITextRange(me);
1352 HRESULT hr;
1354 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
1356 hr = get_typeinfo(ITextRange_tid, ppTInfo);
1357 if (SUCCEEDED(hr))
1358 ITypeInfo_AddRef(*ppTInfo);
1359 return hr;
1362 static HRESULT WINAPI ITextRange_fnGetIDsOfNames(ITextRange *me, REFIID riid, LPOLESTR *rgszNames,
1363 UINT cNames, LCID lcid, DISPID *rgDispId)
1365 ITextRangeImpl *This = impl_from_ITextRange(me);
1366 ITypeInfo *ti;
1367 HRESULT hr;
1369 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
1370 rgDispId);
1372 hr = get_typeinfo(ITextRange_tid, &ti);
1373 if (SUCCEEDED(hr))
1374 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
1375 return hr;
1378 static HRESULT WINAPI ITextRange_fnInvoke(ITextRange *me, DISPID dispIdMember, REFIID riid,
1379 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1380 VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
1381 UINT *puArgErr)
1383 ITextRangeImpl *This = impl_from_ITextRange(me);
1384 ITypeInfo *ti;
1385 HRESULT hr;
1387 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
1388 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1390 hr = get_typeinfo(ITextRange_tid, &ti);
1391 if (SUCCEEDED(hr))
1392 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1393 return hr;
1396 static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *pbstr)
1398 ITextRangeImpl *This = impl_from_ITextRange(me);
1400 FIXME("(%p)->(%p): stub\n", This, pbstr);
1402 if (!This->reOle)
1403 return CO_E_RELEASED;
1405 if (!pbstr)
1406 return E_INVALIDARG;
1408 *pbstr = NULL;
1409 return E_NOTIMPL;
1412 static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
1414 ITextRangeImpl *This = impl_from_ITextRange(me);
1415 ME_TextEditor *editor;
1416 ME_Cursor cursor;
1417 ME_Style *style;
1418 int len;
1420 TRACE("(%p)->(%s)\n", This, debugstr_w(str));
1422 if (!This->reOle)
1423 return CO_E_RELEASED;
1425 editor = This->reOle->editor;
1427 /* delete only where's something to delete */
1428 if (This->start != This->end) {
1429 ME_CursorFromCharOfs(editor, This->start, &cursor);
1430 ME_InternalDeleteText(editor, &cursor, This->end - This->start, FALSE);
1433 if (!str || !*str) {
1434 /* will update this range as well */
1435 textranges_update_ranges(This->reOle, This->start, This->end, RANGE_UPDATE_DELETE);
1436 return S_OK;
1439 /* it's safer not to rely on stored BSTR length */
1440 len = strlenW(str);
1441 cursor = editor->pCursors[0];
1442 ME_CursorFromCharOfs(editor, This->start, &editor->pCursors[0]);
1443 style = ME_GetInsertStyle(editor, 0);
1444 ME_InsertTextFromCursor(editor, 0, str, len, style);
1445 ME_ReleaseStyle(style);
1446 editor->pCursors[0] = cursor;
1448 if (len < This->end - This->start)
1449 textranges_update_ranges(This->reOle, This->start + len, This->end, RANGE_UPDATE_DELETE);
1450 else
1451 This->end = len - This->start;
1453 return S_OK;
1456 static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch)
1458 WCHAR wch[2];
1460 ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, cursor->pRun->next->type == diTextEnd);
1461 *pch = wch[0];
1463 return S_OK;
1466 static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
1468 ITextRangeImpl *This = impl_from_ITextRange(me);
1469 ME_Cursor cursor;
1471 if (!This->reOle)
1472 return CO_E_RELEASED;
1473 TRACE("%p\n", pch);
1474 if (!pch)
1475 return E_INVALIDARG;
1477 ME_CursorFromCharOfs(This->reOle->editor, This->start, &cursor);
1478 return range_GetChar(This->reOle->editor, &cursor, pch);
1481 static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch)
1483 ITextRangeImpl *This = impl_from_ITextRange(me);
1484 if (!This->reOle)
1485 return CO_E_RELEASED;
1487 FIXME("not implemented %p\n", This);
1488 return E_NOTIMPL;
1491 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange);
1493 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
1495 ITextRangeImpl *This = impl_from_ITextRange(me);
1496 if (!This->reOle)
1497 return CO_E_RELEASED;
1499 TRACE("%p %p\n", This, ppRange);
1500 if (!ppRange)
1501 return E_INVALIDARG;
1503 return CreateITextRange(This->reOle, This->start, This->end, ppRange);
1506 static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **ppRange)
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_fnSetFormattedText(ITextRange *me, ITextRange *pRange)
1518 ITextRangeImpl *This = impl_from_ITextRange(me);
1519 if (!This->reOle)
1520 return CO_E_RELEASED;
1522 FIXME("not implemented %p\n", This);
1523 return E_NOTIMPL;
1526 static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *start)
1528 ITextRangeImpl *This = impl_from_ITextRange(me);
1530 TRACE("(%p)->(%p)\n", This, start);
1532 if (!This->reOle)
1533 return CO_E_RELEASED;
1535 if (!start)
1536 return E_INVALIDARG;
1538 *start = This->start;
1539 return S_OK;
1542 static HRESULT textrange_setstart(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1544 int len;
1546 if (value < 0)
1547 value = 0;
1549 if (value == *start)
1550 return S_FALSE;
1552 if (value <= *end) {
1553 *start = value;
1554 return S_OK;
1557 len = ME_GetTextLength(reole->editor);
1558 *start = *end = value > len ? len : value;
1559 return S_OK;
1562 static HRESULT WINAPI ITextRange_fnSetStart(ITextRange *me, LONG value)
1564 ITextRangeImpl *This = impl_from_ITextRange(me);
1566 TRACE("(%p)->(%d)\n", This, value);
1568 if (!This->reOle)
1569 return CO_E_RELEASED;
1571 return textrange_setstart(This->reOle, value, &This->start, &This->end);
1574 static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *end)
1576 ITextRangeImpl *This = impl_from_ITextRange(me);
1578 TRACE("(%p)->(%p)\n", This, end);
1580 if (!This->reOle)
1581 return CO_E_RELEASED;
1583 if (!end)
1584 return E_INVALIDARG;
1586 *end = This->end;
1587 return S_OK;
1590 static HRESULT textrange_setend(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1592 int len;
1594 if (value == *end)
1595 return S_FALSE;
1597 if (value < *start) {
1598 *start = *end = max(0, value);
1599 return S_OK;
1602 len = ME_GetTextLength(reole->editor);
1603 *end = value > len ? len + 1 : value;
1604 return S_OK;
1607 static HRESULT WINAPI ITextRange_fnSetEnd(ITextRange *me, LONG value)
1609 ITextRangeImpl *This = impl_from_ITextRange(me);
1611 TRACE("(%p)->(%d)\n", This, value);
1613 if (!This->reOle)
1614 return CO_E_RELEASED;
1616 return textrange_setend(This->reOle, value, &This->start, &This->end);
1619 static HRESULT WINAPI ITextRange_fnGetFont(ITextRange *me, ITextFont **font)
1621 ITextRangeImpl *This = impl_from_ITextRange(me);
1623 TRACE("(%p)->(%p)\n", This, font);
1625 if (!This->reOle)
1626 return CO_E_RELEASED;
1628 if (!font)
1629 return E_INVALIDARG;
1631 return create_textfont(me, NULL, font);
1634 static HRESULT WINAPI ITextRange_fnSetFont(ITextRange *me, ITextFont *pFont)
1636 ITextRangeImpl *This = impl_from_ITextRange(me);
1637 if (!This->reOle)
1638 return CO_E_RELEASED;
1640 FIXME("not implemented %p\n", This);
1641 return E_NOTIMPL;
1644 static HRESULT WINAPI ITextRange_fnGetPara(ITextRange *me, ITextPara **para)
1646 ITextRangeImpl *This = impl_from_ITextRange(me);
1648 TRACE("(%p)->(%p)\n", This, para);
1650 if (!This->reOle)
1651 return CO_E_RELEASED;
1653 if (!para)
1654 return E_INVALIDARG;
1656 return create_textpara(me, para);
1659 static HRESULT WINAPI ITextRange_fnSetPara(ITextRange *me, ITextPara *pPara)
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_fnGetStoryLength(ITextRange *me, LONG *pcch)
1671 ITextRangeImpl *This = impl_from_ITextRange(me);
1672 if (!This->reOle)
1673 return CO_E_RELEASED;
1675 FIXME("not implemented %p\n", This);
1676 return E_NOTIMPL;
1679 static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *pValue)
1681 ITextRangeImpl *This = impl_from_ITextRange(me);
1682 if (!This->reOle)
1683 return CO_E_RELEASED;
1685 FIXME("not implemented %p\n", This);
1686 return E_NOTIMPL;
1689 static HRESULT range_Collapse(LONG bStart, LONG *start, LONG *end)
1691 if (*end == *start)
1692 return S_FALSE;
1694 if (bStart == tomEnd || bStart == tomFalse)
1695 *start = *end;
1696 else
1697 *end = *start;
1698 return S_OK;
1701 static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
1703 ITextRangeImpl *This = impl_from_ITextRange(me);
1704 if (!This->reOle)
1705 return CO_E_RELEASED;
1707 return range_Collapse(bStart, &This->start, &This->end);
1710 static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG Unit, LONG *pDelta)
1712 ITextRangeImpl *This = impl_from_ITextRange(me);
1713 if (!This->reOle)
1714 return CO_E_RELEASED;
1716 FIXME("not implemented %p\n", This);
1717 return E_NOTIMPL;
1720 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG Unit, LONG *pIndex)
1722 ITextRangeImpl *This = impl_from_ITextRange(me);
1723 if (!This->reOle)
1724 return CO_E_RELEASED;
1726 FIXME("not implemented %p\n", This);
1727 return E_NOTIMPL;
1730 static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG Unit, LONG Index,
1731 LONG Extend)
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_fnSetRange(ITextRange *me, LONG cpActive, LONG cpOther)
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_fnInRange(ITextRange *me, ITextRange *pRange, LONG *pb)
1753 ITextRangeImpl *This = impl_from_ITextRange(me);
1754 if (!This->reOle)
1755 return CO_E_RELEASED;
1757 FIXME("not implemented %p\n", This);
1758 return E_NOTIMPL;
1761 static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *pb)
1763 ITextRangeImpl *This = impl_from_ITextRange(me);
1764 if (!This->reOle)
1765 return CO_E_RELEASED;
1767 FIXME("not implemented %p\n", This);
1768 return E_NOTIMPL;
1771 static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *pRange, LONG *pb)
1773 ITextRangeImpl *This = impl_from_ITextRange(me);
1774 if (!This->reOle)
1775 return CO_E_RELEASED;
1777 FIXME("not implemented %p\n", This);
1778 return E_NOTIMPL;
1781 static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me)
1783 ITextRangeImpl *This = impl_from_ITextRange(me);
1784 if (!This->reOle)
1785 return CO_E_RELEASED;
1787 FIXME("not implemented %p\n", This);
1788 return E_NOTIMPL;
1791 static HRESULT WINAPI ITextRange_fnStartOf(ITextRange *me, LONG Unit, LONG Extend,
1792 LONG *pDelta)
1794 ITextRangeImpl *This = impl_from_ITextRange(me);
1795 if (!This->reOle)
1796 return CO_E_RELEASED;
1798 FIXME("not implemented %p\n", This);
1799 return E_NOTIMPL;
1802 static HRESULT WINAPI ITextRange_fnEndOf(ITextRange *me, LONG Unit, LONG Extend,
1803 LONG *pDelta)
1805 ITextRangeImpl *This = impl_from_ITextRange(me);
1806 if (!This->reOle)
1807 return CO_E_RELEASED;
1809 FIXME("not implemented %p\n", This);
1810 return E_NOTIMPL;
1813 static HRESULT WINAPI ITextRange_fnMove(ITextRange *me, LONG Unit, LONG Count, LONG *pDelta)
1815 ITextRangeImpl *This = impl_from_ITextRange(me);
1816 if (!This->reOle)
1817 return CO_E_RELEASED;
1819 FIXME("not implemented %p\n", This);
1820 return E_NOTIMPL;
1823 static HRESULT WINAPI ITextRange_fnMoveStart(ITextRange *me, LONG Unit, LONG Count,
1824 LONG *pDelta)
1826 ITextRangeImpl *This = impl_from_ITextRange(me);
1827 if (!This->reOle)
1828 return CO_E_RELEASED;
1830 FIXME("not implemented %p\n", This);
1831 return E_NOTIMPL;
1834 static HRESULT WINAPI ITextRange_fnMoveEnd(ITextRange *me, LONG Unit, LONG Count,
1835 LONG *pDelta)
1837 ITextRangeImpl *This = impl_from_ITextRange(me);
1838 if (!This->reOle)
1839 return CO_E_RELEASED;
1841 FIXME("not implemented %p\n", This);
1842 return E_NOTIMPL;
1845 static HRESULT WINAPI ITextRange_fnMoveWhile(ITextRange *me, VARIANT *Cset, LONG Count,
1846 LONG *pDelta)
1848 ITextRangeImpl *This = impl_from_ITextRange(me);
1849 if (!This->reOle)
1850 return CO_E_RELEASED;
1852 FIXME("not implemented %p\n", This);
1853 return E_NOTIMPL;
1856 static HRESULT WINAPI ITextRange_fnMoveStartWhile(ITextRange *me, VARIANT *Cset, LONG Count,
1857 LONG *pDelta)
1859 ITextRangeImpl *This = impl_from_ITextRange(me);
1860 if (!This->reOle)
1861 return CO_E_RELEASED;
1863 FIXME("not implemented %p\n", This);
1864 return E_NOTIMPL;
1867 static HRESULT WINAPI ITextRange_fnMoveEndWhile(ITextRange *me, VARIANT *Cset, LONG Count,
1868 LONG *pDelta)
1870 ITextRangeImpl *This = impl_from_ITextRange(me);
1871 if (!This->reOle)
1872 return CO_E_RELEASED;
1874 FIXME("not implemented %p\n", This);
1875 return E_NOTIMPL;
1878 static HRESULT WINAPI ITextRange_fnMoveUntil(ITextRange *me, VARIANT *Cset, LONG Count,
1879 LONG *pDelta)
1881 ITextRangeImpl *This = impl_from_ITextRange(me);
1882 if (!This->reOle)
1883 return CO_E_RELEASED;
1885 FIXME("not implemented %p\n", This);
1886 return E_NOTIMPL;
1889 static HRESULT WINAPI ITextRange_fnMoveStartUntil(ITextRange *me, VARIANT *Cset, LONG Count,
1890 LONG *pDelta)
1892 ITextRangeImpl *This = impl_from_ITextRange(me);
1893 if (!This->reOle)
1894 return CO_E_RELEASED;
1896 FIXME("not implemented %p\n", This);
1897 return E_NOTIMPL;
1900 static HRESULT WINAPI ITextRange_fnMoveEndUntil(ITextRange *me, VARIANT *Cset, LONG Count,
1901 LONG *pDelta)
1903 ITextRangeImpl *This = impl_from_ITextRange(me);
1904 if (!This->reOle)
1905 return CO_E_RELEASED;
1907 FIXME("not implemented %p\n", This);
1908 return E_NOTIMPL;
1911 static HRESULT WINAPI ITextRange_fnFindText(ITextRange *me, BSTR bstr, LONG cch, LONG Flags,
1912 LONG *pLength)
1914 ITextRangeImpl *This = impl_from_ITextRange(me);
1915 if (!This->reOle)
1916 return CO_E_RELEASED;
1918 FIXME("not implemented %p\n", This);
1919 return E_NOTIMPL;
1922 static HRESULT WINAPI ITextRange_fnFindTextStart(ITextRange *me, BSTR bstr, LONG cch,
1923 LONG Flags, LONG *pLength)
1925 ITextRangeImpl *This = impl_from_ITextRange(me);
1926 if (!This->reOle)
1927 return CO_E_RELEASED;
1929 FIXME("not implemented %p\n", This);
1930 return E_NOTIMPL;
1933 static HRESULT WINAPI ITextRange_fnFindTextEnd(ITextRange *me, BSTR bstr, LONG cch,
1934 LONG Flags, LONG *pLength)
1936 ITextRangeImpl *This = impl_from_ITextRange(me);
1937 if (!This->reOle)
1938 return CO_E_RELEASED;
1940 FIXME("not implemented %p\n", This);
1941 return E_NOTIMPL;
1944 static HRESULT WINAPI ITextRange_fnDelete(ITextRange *me, LONG Unit, LONG Count,
1945 LONG *pDelta)
1947 ITextRangeImpl *This = impl_from_ITextRange(me);
1948 if (!This->reOle)
1949 return CO_E_RELEASED;
1951 FIXME("not implemented %p\n", This);
1952 return E_NOTIMPL;
1955 static HRESULT WINAPI ITextRange_fnCut(ITextRange *me, VARIANT *pVar)
1957 ITextRangeImpl *This = impl_from_ITextRange(me);
1958 if (!This->reOle)
1959 return CO_E_RELEASED;
1961 FIXME("not implemented %p\n", This);
1962 return E_NOTIMPL;
1965 static HRESULT WINAPI ITextRange_fnCopy(ITextRange *me, VARIANT *pVar)
1967 ITextRangeImpl *This = impl_from_ITextRange(me);
1968 if (!This->reOle)
1969 return CO_E_RELEASED;
1971 FIXME("not implemented %p\n", This);
1972 return E_NOTIMPL;
1975 static HRESULT WINAPI ITextRange_fnPaste(ITextRange *me, VARIANT *pVar, LONG Format)
1977 ITextRangeImpl *This = impl_from_ITextRange(me);
1978 if (!This->reOle)
1979 return CO_E_RELEASED;
1981 FIXME("not implemented %p\n", This);
1982 return E_NOTIMPL;
1985 static HRESULT WINAPI ITextRange_fnCanPaste(ITextRange *me, VARIANT *pVar, LONG Format,
1986 LONG *pb)
1988 ITextRangeImpl *This = impl_from_ITextRange(me);
1989 if (!This->reOle)
1990 return CO_E_RELEASED;
1992 FIXME("not implemented %p\n", This);
1993 return E_NOTIMPL;
1996 static HRESULT WINAPI ITextRange_fnCanEdit(ITextRange *me, LONG *pb)
1998 ITextRangeImpl *This = impl_from_ITextRange(me);
1999 if (!This->reOle)
2000 return CO_E_RELEASED;
2002 FIXME("not implemented %p\n", This);
2003 return E_NOTIMPL;
2006 static HRESULT WINAPI ITextRange_fnChangeCase(ITextRange *me, LONG Type)
2008 ITextRangeImpl *This = impl_from_ITextRange(me);
2009 if (!This->reOle)
2010 return CO_E_RELEASED;
2012 FIXME("not implemented %p\n", This);
2013 return E_NOTIMPL;
2016 static HRESULT WINAPI ITextRange_fnGetPoint(ITextRange *me, LONG Type, LONG *cx, LONG *cy)
2018 ITextRangeImpl *This = impl_from_ITextRange(me);
2019 if (!This->reOle)
2020 return CO_E_RELEASED;
2022 FIXME("not implemented %p\n", This);
2023 return E_NOTIMPL;
2026 static HRESULT WINAPI ITextRange_fnSetPoint(ITextRange *me, LONG x, LONG y, LONG Type,
2027 LONG Extend)
2029 ITextRangeImpl *This = impl_from_ITextRange(me);
2030 if (!This->reOle)
2031 return CO_E_RELEASED;
2033 FIXME("not implemented %p\n", This);
2034 return E_NOTIMPL;
2037 static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG Value)
2039 ITextRangeImpl *This = impl_from_ITextRange(me);
2040 if (!This->reOle)
2041 return CO_E_RELEASED;
2043 FIXME("not implemented %p\n", This);
2044 return E_NOTIMPL;
2047 static HRESULT WINAPI ITextRange_fnGetEmbeddedObject(ITextRange *me, IUnknown **ppv)
2049 ITextRangeImpl *This = impl_from_ITextRange(me);
2050 if (!This->reOle)
2051 return CO_E_RELEASED;
2053 FIXME("not implemented %p\n", This);
2054 return E_NOTIMPL;
2057 static const ITextRangeVtbl trvt = {
2058 ITextRange_fnQueryInterface,
2059 ITextRange_fnAddRef,
2060 ITextRange_fnRelease,
2061 ITextRange_fnGetTypeInfoCount,
2062 ITextRange_fnGetTypeInfo,
2063 ITextRange_fnGetIDsOfNames,
2064 ITextRange_fnInvoke,
2065 ITextRange_fnGetText,
2066 ITextRange_fnSetText,
2067 ITextRange_fnGetChar,
2068 ITextRange_fnSetChar,
2069 ITextRange_fnGetDuplicate,
2070 ITextRange_fnGetFormattedText,
2071 ITextRange_fnSetFormattedText,
2072 ITextRange_fnGetStart,
2073 ITextRange_fnSetStart,
2074 ITextRange_fnGetEnd,
2075 ITextRange_fnSetEnd,
2076 ITextRange_fnGetFont,
2077 ITextRange_fnSetFont,
2078 ITextRange_fnGetPara,
2079 ITextRange_fnSetPara,
2080 ITextRange_fnGetStoryLength,
2081 ITextRange_fnGetStoryType,
2082 ITextRange_fnCollapse,
2083 ITextRange_fnExpand,
2084 ITextRange_fnGetIndex,
2085 ITextRange_fnSetIndex,
2086 ITextRange_fnSetRange,
2087 ITextRange_fnInRange,
2088 ITextRange_fnInStory,
2089 ITextRange_fnIsEqual,
2090 ITextRange_fnSelect,
2091 ITextRange_fnStartOf,
2092 ITextRange_fnEndOf,
2093 ITextRange_fnMove,
2094 ITextRange_fnMoveStart,
2095 ITextRange_fnMoveEnd,
2096 ITextRange_fnMoveWhile,
2097 ITextRange_fnMoveStartWhile,
2098 ITextRange_fnMoveEndWhile,
2099 ITextRange_fnMoveUntil,
2100 ITextRange_fnMoveStartUntil,
2101 ITextRange_fnMoveEndUntil,
2102 ITextRange_fnFindText,
2103 ITextRange_fnFindTextStart,
2104 ITextRange_fnFindTextEnd,
2105 ITextRange_fnDelete,
2106 ITextRange_fnCut,
2107 ITextRange_fnCopy,
2108 ITextRange_fnPaste,
2109 ITextRange_fnCanPaste,
2110 ITextRange_fnCanEdit,
2111 ITextRange_fnChangeCase,
2112 ITextRange_fnGetPoint,
2113 ITextRange_fnSetPoint,
2114 ITextRange_fnScrollIntoView,
2115 ITextRange_fnGetEmbeddedObject
2118 /* ITextFont */
2119 static HRESULT WINAPI TextFont_QueryInterface(ITextFont *iface, REFIID riid, void **ppv)
2121 ITextFontImpl *This = impl_from_ITextFont(iface);
2123 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2125 if (IsEqualIID(riid, &IID_ITextFont) ||
2126 IsEqualIID(riid, &IID_IDispatch) ||
2127 IsEqualIID(riid, &IID_IUnknown))
2129 *ppv = iface;
2130 ITextFont_AddRef(iface);
2131 return S_OK;
2134 *ppv = NULL;
2135 return E_NOINTERFACE;
2138 static ULONG WINAPI TextFont_AddRef(ITextFont *iface)
2140 ITextFontImpl *This = impl_from_ITextFont(iface);
2141 ULONG ref = InterlockedIncrement(&This->ref);
2142 TRACE("(%p)->(%u)\n", This, ref);
2143 return ref;
2146 static ULONG WINAPI TextFont_Release(ITextFont *iface)
2148 ITextFontImpl *This = impl_from_ITextFont(iface);
2149 ULONG ref = InterlockedDecrement(&This->ref);
2151 TRACE("(%p)->(%u)\n", This, ref);
2153 if (!ref)
2155 if (This->range)
2156 ITextRange_Release(This->range);
2157 SysFreeString(This->props[FONT_NAME].str);
2158 heap_free(This);
2161 return ref;
2164 static HRESULT WINAPI TextFont_GetTypeInfoCount(ITextFont *iface, UINT *pctinfo)
2166 ITextFontImpl *This = impl_from_ITextFont(iface);
2167 TRACE("(%p)->(%p)\n", This, pctinfo);
2168 *pctinfo = 1;
2169 return S_OK;
2172 static HRESULT WINAPI TextFont_GetTypeInfo(ITextFont *iface, UINT iTInfo, LCID lcid,
2173 ITypeInfo **ppTInfo)
2175 ITextFontImpl *This = impl_from_ITextFont(iface);
2176 HRESULT hr;
2178 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
2180 hr = get_typeinfo(ITextFont_tid, ppTInfo);
2181 if (SUCCEEDED(hr))
2182 ITypeInfo_AddRef(*ppTInfo);
2183 return hr;
2186 static HRESULT WINAPI TextFont_GetIDsOfNames(ITextFont *iface, REFIID riid,
2187 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2189 ITextFontImpl *This = impl_from_ITextFont(iface);
2190 ITypeInfo *ti;
2191 HRESULT hr;
2193 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
2194 rgDispId);
2196 hr = get_typeinfo(ITextFont_tid, &ti);
2197 if (SUCCEEDED(hr))
2198 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
2199 return hr;
2202 static HRESULT WINAPI TextFont_Invoke(
2203 ITextFont *iface,
2204 DISPID dispIdMember,
2205 REFIID riid,
2206 LCID lcid,
2207 WORD wFlags,
2208 DISPPARAMS *pDispParams,
2209 VARIANT *pVarResult,
2210 EXCEPINFO *pExcepInfo,
2211 UINT *puArgErr)
2213 ITextFontImpl *This = impl_from_ITextFont(iface);
2214 ITypeInfo *ti;
2215 HRESULT hr;
2217 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
2218 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2220 hr = get_typeinfo(ITextFont_tid, &ti);
2221 if (SUCCEEDED(hr))
2222 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2223 return hr;
2226 static HRESULT WINAPI TextFont_GetDuplicate(ITextFont *iface, ITextFont **ret)
2228 ITextFontImpl *This = impl_from_ITextFont(iface);
2230 TRACE("(%p)->(%p)\n", This, ret);
2232 if (!ret)
2233 return E_INVALIDARG;
2235 *ret = NULL;
2236 if (This->range && !get_range_reole(This->range))
2237 return CO_E_RELEASED;
2239 return create_textfont(NULL, This, ret);
2242 static HRESULT WINAPI TextFont_SetDuplicate(ITextFont *iface, ITextFont *pFont)
2244 ITextFontImpl *This = impl_from_ITextFont(iface);
2245 FIXME("(%p)->(%p): stub\n", This, pFont);
2246 return E_NOTIMPL;
2249 static HRESULT WINAPI TextFont_CanChange(ITextFont *iface, LONG *ret)
2251 ITextFontImpl *This = impl_from_ITextFont(iface);
2252 FIXME("(%p)->(%p): stub\n", This, ret);
2253 return E_NOTIMPL;
2256 static HRESULT WINAPI TextFont_IsEqual(ITextFont *iface, ITextFont *font, LONG *ret)
2258 ITextFontImpl *This = impl_from_ITextFont(iface);
2259 FIXME("(%p)->(%p %p): stub\n", This, font, ret);
2260 return E_NOTIMPL;
2263 static void textfont_reset_to_default(ITextFontImpl *font)
2265 enum textfont_prop_id id;
2267 for (id = FONT_PROPID_FIRST; id < FONT_PROPID_LAST; id++) {
2268 switch (id)
2270 case FONT_ALLCAPS:
2271 case FONT_ANIMATION:
2272 case FONT_BOLD:
2273 case FONT_EMBOSS:
2274 case FONT_HIDDEN:
2275 case FONT_ENGRAVE:
2276 case FONT_ITALIC:
2277 case FONT_OUTLINE:
2278 case FONT_PROTECTED:
2279 case FONT_SHADOW:
2280 case FONT_SMALLCAPS:
2281 case FONT_STRIKETHROUGH:
2282 case FONT_SUBSCRIPT:
2283 case FONT_SUPERSCRIPT:
2284 case FONT_UNDERLINE:
2285 font->props[id].l = tomFalse;
2286 break;
2287 case FONT_BACKCOLOR:
2288 case FONT_FORECOLOR:
2289 font->props[id].l = tomAutoColor;
2290 break;
2291 case FONT_KERNING:
2292 case FONT_POSITION:
2293 case FONT_SIZE:
2294 case FONT_SPACING:
2295 font->props[id].f = 0.0;
2296 break;
2297 case FONT_LANGID:
2298 font->props[id].l = GetSystemDefaultLCID();
2299 break;
2300 case FONT_NAME: {
2301 static const WCHAR sysW[] = {'S','y','s','t','e','m',0};
2302 SysFreeString(font->props[id].str);
2303 font->props[id].str = SysAllocString(sysW);
2304 break;
2306 case FONT_WEIGHT:
2307 font->props[id].l = FW_NORMAL;
2308 break;
2309 default:
2310 FIXME("font property %d not handled\n", id);
2315 static void textfont_reset_to_undefined(ITextFontImpl *font)
2317 enum textfont_prop_id id;
2319 for (id = FONT_PROPID_FIRST; id < FONT_PROPID_LAST; id++) {
2320 switch (id)
2322 case FONT_ALLCAPS:
2323 case FONT_ANIMATION:
2324 case FONT_BOLD:
2325 case FONT_EMBOSS:
2326 case FONT_HIDDEN:
2327 case FONT_ENGRAVE:
2328 case FONT_ITALIC:
2329 case FONT_OUTLINE:
2330 case FONT_PROTECTED:
2331 case FONT_SHADOW:
2332 case FONT_SMALLCAPS:
2333 case FONT_STRIKETHROUGH:
2334 case FONT_SUBSCRIPT:
2335 case FONT_SUPERSCRIPT:
2336 case FONT_UNDERLINE:
2337 case FONT_BACKCOLOR:
2338 case FONT_FORECOLOR:
2339 case FONT_LANGID:
2340 case FONT_WEIGHT:
2341 font->props[id].l = tomUndefined;
2342 break;
2343 case FONT_KERNING:
2344 case FONT_POSITION:
2345 case FONT_SIZE:
2346 case FONT_SPACING:
2347 font->props[id].f = tomUndefined;
2348 break;
2349 case FONT_NAME:
2350 break;
2351 default:
2352 FIXME("font property %d not handled\n", id);
2357 static void textfont_apply_range_props(ITextFontImpl *font)
2359 enum textfont_prop_id propid;
2360 for (propid = FONT_PROPID_FIRST; propid < FONT_PROPID_LAST; propid++)
2361 set_textfont_prop(font, propid, &font->props[propid]);
2364 static HRESULT WINAPI TextFont_Reset(ITextFont *iface, LONG value)
2366 ITextFontImpl *This = impl_from_ITextFont(iface);
2368 TRACE("(%p)->(%d)\n", This, value);
2370 /* If font is attached to a range, released or not, we can't
2371 reset to undefined */
2372 if (This->range) {
2373 if (!get_range_reole(This->range))
2374 return CO_E_RELEASED;
2376 switch (value)
2378 case tomUndefined:
2379 return E_INVALIDARG;
2380 case tomCacheParms:
2381 textfont_cache_range_props(This);
2382 This->get_cache_enabled = TRUE;
2383 break;
2384 case tomTrackParms:
2385 This->get_cache_enabled = FALSE;
2386 break;
2387 case tomApplyLater:
2388 This->set_cache_enabled = TRUE;
2389 break;
2390 case tomApplyNow:
2391 This->set_cache_enabled = FALSE;
2392 textfont_apply_range_props(This);
2393 break;
2394 default:
2395 FIXME("reset mode %d not supported\n", value);
2398 return S_OK;
2400 else {
2401 switch (value)
2403 /* reset to global defaults */
2404 case tomDefault:
2405 textfont_reset_to_default(This);
2406 return S_OK;
2407 /* all properties are set to tomUndefined, font name is retained */
2408 case tomUndefined:
2409 textfont_reset_to_undefined(This);
2410 return S_OK;
2411 case tomApplyNow:
2412 case tomApplyLater:
2413 case tomTrackParms:
2414 case tomCacheParms:
2415 return S_OK;
2419 FIXME("reset mode %d not supported\n", value);
2420 return E_NOTIMPL;
2423 static HRESULT WINAPI TextFont_GetStyle(ITextFont *iface, LONG *value)
2425 ITextFontImpl *This = impl_from_ITextFont(iface);
2426 FIXME("(%p)->(%p): stub\n", This, value);
2427 return E_NOTIMPL;
2430 static HRESULT WINAPI TextFont_SetStyle(ITextFont *iface, LONG value)
2432 ITextFontImpl *This = impl_from_ITextFont(iface);
2433 FIXME("(%p)->(%d): stub\n", This, value);
2434 return E_NOTIMPL;
2437 static HRESULT WINAPI TextFont_GetAllCaps(ITextFont *iface, LONG *value)
2439 ITextFontImpl *This = impl_from_ITextFont(iface);
2440 TRACE("(%p)->(%p)\n", This, value);
2441 return get_textfont_propl(This, FONT_ALLCAPS, value);
2444 static HRESULT WINAPI TextFont_SetAllCaps(ITextFont *iface, LONG value)
2446 ITextFontImpl *This = impl_from_ITextFont(iface);
2447 TRACE("(%p)->(%d)\n", This, value);
2448 return set_textfont_propd(This, FONT_ALLCAPS, value);
2451 static HRESULT WINAPI TextFont_GetAnimation(ITextFont *iface, LONG *value)
2453 ITextFontImpl *This = impl_from_ITextFont(iface);
2454 TRACE("(%p)->(%p)\n", This, value);
2455 return get_textfont_propl(This, FONT_ANIMATION, value);
2458 static HRESULT WINAPI TextFont_SetAnimation(ITextFont *iface, LONG value)
2460 ITextFontImpl *This = impl_from_ITextFont(iface);
2462 TRACE("(%p)->(%d)\n", This, value);
2464 if (value < tomNoAnimation || value > tomAnimationMax)
2465 return E_INVALIDARG;
2467 return set_textfont_propl(This, FONT_ANIMATION, value);
2470 static HRESULT WINAPI TextFont_GetBackColor(ITextFont *iface, LONG *value)
2472 ITextFontImpl *This = impl_from_ITextFont(iface);
2473 TRACE("(%p)->(%p)\n", This, value);
2474 return get_textfont_propl(This, FONT_BACKCOLOR, value);
2477 static HRESULT WINAPI TextFont_SetBackColor(ITextFont *iface, LONG value)
2479 ITextFontImpl *This = impl_from_ITextFont(iface);
2480 TRACE("(%p)->(%d)\n", This, value);
2481 return set_textfont_propl(This, FONT_BACKCOLOR, value);
2484 static HRESULT WINAPI TextFont_GetBold(ITextFont *iface, LONG *value)
2486 ITextFontImpl *This = impl_from_ITextFont(iface);
2487 TRACE("(%p)->(%p)\n", This, value);
2488 return get_textfont_propl(This, FONT_BOLD, value);
2491 static HRESULT WINAPI TextFont_SetBold(ITextFont *iface, LONG value)
2493 ITextFontImpl *This = impl_from_ITextFont(iface);
2494 TRACE("(%p)->(%d)\n", This, value);
2495 return set_textfont_propd(This, FONT_BOLD, value);
2498 static HRESULT WINAPI TextFont_GetEmboss(ITextFont *iface, LONG *value)
2500 ITextFontImpl *This = impl_from_ITextFont(iface);
2501 TRACE("(%p)->(%p)\n", This, value);
2502 return get_textfont_propl(This, FONT_EMBOSS, value);
2505 static HRESULT WINAPI TextFont_SetEmboss(ITextFont *iface, LONG value)
2507 ITextFontImpl *This = impl_from_ITextFont(iface);
2508 TRACE("(%p)->(%d)\n", This, value);
2509 return set_textfont_propd(This, FONT_EMBOSS, value);
2512 static HRESULT WINAPI TextFont_GetForeColor(ITextFont *iface, LONG *value)
2514 ITextFontImpl *This = impl_from_ITextFont(iface);
2515 TRACE("(%p)->(%p)\n", This, value);
2516 return get_textfont_propl(This, FONT_FORECOLOR, value);
2519 static HRESULT WINAPI TextFont_SetForeColor(ITextFont *iface, LONG value)
2521 ITextFontImpl *This = impl_from_ITextFont(iface);
2522 TRACE("(%p)->(%d)\n", This, value);
2523 return set_textfont_propl(This, FONT_FORECOLOR, value);
2526 static HRESULT WINAPI TextFont_GetHidden(ITextFont *iface, LONG *value)
2528 ITextFontImpl *This = impl_from_ITextFont(iface);
2529 TRACE("(%p)->(%p)\n", This, value);
2530 return get_textfont_propl(This, FONT_HIDDEN, value);
2533 static HRESULT WINAPI TextFont_SetHidden(ITextFont *iface, LONG value)
2535 ITextFontImpl *This = impl_from_ITextFont(iface);
2536 TRACE("(%p)->(%d)\n", This, value);
2537 return set_textfont_propd(This, FONT_HIDDEN, value);
2540 static HRESULT WINAPI TextFont_GetEngrave(ITextFont *iface, LONG *value)
2542 ITextFontImpl *This = impl_from_ITextFont(iface);
2543 TRACE("(%p)->(%p)\n", This, value);
2544 return get_textfont_propl(This, FONT_ENGRAVE, value);
2547 static HRESULT WINAPI TextFont_SetEngrave(ITextFont *iface, LONG value)
2549 ITextFontImpl *This = impl_from_ITextFont(iface);
2550 TRACE("(%p)->(%d)\n", This, value);
2551 return set_textfont_propd(This, FONT_ENGRAVE, value);
2554 static HRESULT WINAPI TextFont_GetItalic(ITextFont *iface, LONG *value)
2556 ITextFontImpl *This = impl_from_ITextFont(iface);
2557 TRACE("(%p)->(%p)\n", This, value);
2558 return get_textfont_propl(This, FONT_ITALIC, value);
2561 static HRESULT WINAPI TextFont_SetItalic(ITextFont *iface, LONG value)
2563 ITextFontImpl *This = impl_from_ITextFont(iface);
2564 TRACE("(%p)->(%d)\n", This, value);
2565 return set_textfont_propd(This, FONT_ITALIC, value);
2568 static HRESULT WINAPI TextFont_GetKerning(ITextFont *iface, FLOAT *value)
2570 ITextFontImpl *This = impl_from_ITextFont(iface);
2571 TRACE("(%p)->(%p)\n", This, value);
2572 return get_textfont_propf(This, FONT_KERNING, value);
2575 static HRESULT WINAPI TextFont_SetKerning(ITextFont *iface, FLOAT value)
2577 ITextFontImpl *This = impl_from_ITextFont(iface);
2578 TRACE("(%p)->(%.2f)\n", This, value);
2579 return set_textfont_propf(This, FONT_KERNING, value);
2582 static HRESULT WINAPI TextFont_GetLanguageID(ITextFont *iface, LONG *value)
2584 ITextFontImpl *This = impl_from_ITextFont(iface);
2585 TRACE("(%p)->(%p)\n", This, value);
2586 return get_textfont_propl(This, FONT_LANGID, value);
2589 static HRESULT WINAPI TextFont_SetLanguageID(ITextFont *iface, LONG value)
2591 ITextFontImpl *This = impl_from_ITextFont(iface);
2592 TRACE("(%p)->(%d)\n", This, value);
2593 return set_textfont_propl(This, FONT_LANGID, value);
2596 static HRESULT WINAPI TextFont_GetName(ITextFont *iface, BSTR *value)
2598 ITextFontImpl *This = impl_from_ITextFont(iface);
2600 TRACE("(%p)->(%p)\n", This, value);
2602 if (!value)
2603 return E_INVALIDARG;
2605 *value = NULL;
2607 if (!This->range) {
2608 if (This->props[FONT_NAME].str)
2609 *value = SysAllocString(This->props[FONT_NAME].str);
2610 else
2611 *value = SysAllocStringLen(NULL, 0);
2612 return *value ? S_OK : E_OUTOFMEMORY;
2615 return textfont_getname_from_range(This->range, value);
2618 static HRESULT WINAPI TextFont_SetName(ITextFont *iface, BSTR value)
2620 ITextFontImpl *This = impl_from_ITextFont(iface);
2621 textfont_prop_val v;
2623 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
2625 v.str = value;
2626 return set_textfont_prop(This, FONT_NAME, &v);
2629 static HRESULT WINAPI TextFont_GetOutline(ITextFont *iface, LONG *value)
2631 ITextFontImpl *This = impl_from_ITextFont(iface);
2632 TRACE("(%p)->(%p)\n", This, value);
2633 return get_textfont_propl(This, FONT_OUTLINE, value);
2636 static HRESULT WINAPI TextFont_SetOutline(ITextFont *iface, LONG value)
2638 ITextFontImpl *This = impl_from_ITextFont(iface);
2639 TRACE("(%p)->(%d)\n", This, value);
2640 return set_textfont_propd(This, FONT_OUTLINE, value);
2643 static HRESULT WINAPI TextFont_GetPosition(ITextFont *iface, FLOAT *value)
2645 ITextFontImpl *This = impl_from_ITextFont(iface);
2646 TRACE("(%p)->(%p)\n", This, value);
2647 return get_textfont_propf(This, FONT_POSITION, value);
2650 static HRESULT WINAPI TextFont_SetPosition(ITextFont *iface, FLOAT value)
2652 ITextFontImpl *This = impl_from_ITextFont(iface);
2653 TRACE("(%p)->(%.2f)\n", This, value);
2654 return set_textfont_propf(This, FONT_POSITION, value);
2657 static HRESULT WINAPI TextFont_GetProtected(ITextFont *iface, LONG *value)
2659 ITextFontImpl *This = impl_from_ITextFont(iface);
2660 TRACE("(%p)->(%p)\n", This, value);
2661 return get_textfont_propl(This, FONT_PROTECTED, value);
2664 static HRESULT WINAPI TextFont_SetProtected(ITextFont *iface, LONG value)
2666 ITextFontImpl *This = impl_from_ITextFont(iface);
2667 TRACE("(%p)->(%d)\n", This, value);
2668 return set_textfont_propd(This, FONT_PROTECTED, value);
2671 static HRESULT WINAPI TextFont_GetShadow(ITextFont *iface, LONG *value)
2673 ITextFontImpl *This = impl_from_ITextFont(iface);
2674 TRACE("(%p)->(%p)\n", This, value);
2675 return get_textfont_propl(This, FONT_SHADOW, value);
2678 static HRESULT WINAPI TextFont_SetShadow(ITextFont *iface, LONG value)
2680 ITextFontImpl *This = impl_from_ITextFont(iface);
2681 TRACE("(%p)->(%d)\n", This, value);
2682 return set_textfont_propd(This, FONT_SHADOW, value);
2685 static HRESULT WINAPI TextFont_GetSize(ITextFont *iface, FLOAT *value)
2687 ITextFontImpl *This = impl_from_ITextFont(iface);
2688 TRACE("(%p)->(%p)\n", This, value);
2689 return get_textfont_propf(This, FONT_SIZE, value);
2692 static HRESULT WINAPI TextFont_SetSize(ITextFont *iface, FLOAT value)
2694 ITextFontImpl *This = impl_from_ITextFont(iface);
2695 TRACE("(%p)->(%.2f)\n", This, value);
2696 return set_textfont_propf(This, FONT_SIZE, value);
2699 static HRESULT WINAPI TextFont_GetSmallCaps(ITextFont *iface, LONG *value)
2701 ITextFontImpl *This = impl_from_ITextFont(iface);
2702 TRACE("(%p)->(%p)\n", This, value);
2703 return get_textfont_propl(This, FONT_SMALLCAPS, value);
2706 static HRESULT WINAPI TextFont_SetSmallCaps(ITextFont *iface, LONG value)
2708 ITextFontImpl *This = impl_from_ITextFont(iface);
2709 TRACE("(%p)->(%d)\n", This, value);
2710 return set_textfont_propd(This, FONT_SMALLCAPS, value);
2713 static HRESULT WINAPI TextFont_GetSpacing(ITextFont *iface, FLOAT *value)
2715 ITextFontImpl *This = impl_from_ITextFont(iface);
2716 TRACE("(%p)->(%p)\n", This, value);
2717 return get_textfont_propf(This, FONT_SPACING, value);
2720 static HRESULT WINAPI TextFont_SetSpacing(ITextFont *iface, FLOAT value)
2722 ITextFontImpl *This = impl_from_ITextFont(iface);
2723 TRACE("(%p)->(%.2f)\n", This, value);
2724 return set_textfont_propf(This, FONT_SPACING, value);
2727 static HRESULT WINAPI TextFont_GetStrikeThrough(ITextFont *iface, LONG *value)
2729 ITextFontImpl *This = impl_from_ITextFont(iface);
2730 TRACE("(%p)->(%p)\n", This, value);
2731 return get_textfont_propl(This, FONT_STRIKETHROUGH, value);
2734 static HRESULT WINAPI TextFont_SetStrikeThrough(ITextFont *iface, LONG value)
2736 ITextFontImpl *This = impl_from_ITextFont(iface);
2737 TRACE("(%p)->(%d)\n", This, value);
2738 return set_textfont_propd(This, FONT_STRIKETHROUGH, value);
2741 static HRESULT WINAPI TextFont_GetSubscript(ITextFont *iface, LONG *value)
2743 ITextFontImpl *This = impl_from_ITextFont(iface);
2744 TRACE("(%p)->(%p)\n", This, value);
2745 return get_textfont_propl(This, FONT_SUBSCRIPT, value);
2748 static HRESULT WINAPI TextFont_SetSubscript(ITextFont *iface, LONG value)
2750 ITextFontImpl *This = impl_from_ITextFont(iface);
2751 TRACE("(%p)->(%d)\n", This, value);
2752 return set_textfont_propd(This, FONT_SUBSCRIPT, value);
2755 static HRESULT WINAPI TextFont_GetSuperscript(ITextFont *iface, LONG *value)
2757 ITextFontImpl *This = impl_from_ITextFont(iface);
2758 TRACE("(%p)->(%p)\n", This, value);
2759 return get_textfont_propl(This, FONT_SUPERSCRIPT, value);
2762 static HRESULT WINAPI TextFont_SetSuperscript(ITextFont *iface, LONG value)
2764 ITextFontImpl *This = impl_from_ITextFont(iface);
2765 TRACE("(%p)->(%d)\n", This, value);
2766 return set_textfont_propd(This, FONT_SUPERSCRIPT, value);
2769 static HRESULT WINAPI TextFont_GetUnderline(ITextFont *iface, LONG *value)
2771 ITextFontImpl *This = impl_from_ITextFont(iface);
2772 TRACE("(%p)->(%p)\n", This, value);
2773 return get_textfont_propl(This, FONT_UNDERLINE, value);
2776 static HRESULT WINAPI TextFont_SetUnderline(ITextFont *iface, LONG value)
2778 ITextFontImpl *This = impl_from_ITextFont(iface);
2779 TRACE("(%p)->(%d)\n", This, value);
2780 return set_textfont_propd(This, FONT_UNDERLINE, value);
2783 static HRESULT WINAPI TextFont_GetWeight(ITextFont *iface, LONG *value)
2785 ITextFontImpl *This = impl_from_ITextFont(iface);
2786 TRACE("(%p)->(%p)\n", This, value);
2787 return get_textfont_propl(This, FONT_WEIGHT, value);
2790 static HRESULT WINAPI TextFont_SetWeight(ITextFont *iface, LONG value)
2792 ITextFontImpl *This = impl_from_ITextFont(iface);
2793 TRACE("(%p)->(%d)\n", This, value);
2794 return set_textfont_propl(This, FONT_WEIGHT, value);
2797 static ITextFontVtbl textfontvtbl = {
2798 TextFont_QueryInterface,
2799 TextFont_AddRef,
2800 TextFont_Release,
2801 TextFont_GetTypeInfoCount,
2802 TextFont_GetTypeInfo,
2803 TextFont_GetIDsOfNames,
2804 TextFont_Invoke,
2805 TextFont_GetDuplicate,
2806 TextFont_SetDuplicate,
2807 TextFont_CanChange,
2808 TextFont_IsEqual,
2809 TextFont_Reset,
2810 TextFont_GetStyle,
2811 TextFont_SetStyle,
2812 TextFont_GetAllCaps,
2813 TextFont_SetAllCaps,
2814 TextFont_GetAnimation,
2815 TextFont_SetAnimation,
2816 TextFont_GetBackColor,
2817 TextFont_SetBackColor,
2818 TextFont_GetBold,
2819 TextFont_SetBold,
2820 TextFont_GetEmboss,
2821 TextFont_SetEmboss,
2822 TextFont_GetForeColor,
2823 TextFont_SetForeColor,
2824 TextFont_GetHidden,
2825 TextFont_SetHidden,
2826 TextFont_GetEngrave,
2827 TextFont_SetEngrave,
2828 TextFont_GetItalic,
2829 TextFont_SetItalic,
2830 TextFont_GetKerning,
2831 TextFont_SetKerning,
2832 TextFont_GetLanguageID,
2833 TextFont_SetLanguageID,
2834 TextFont_GetName,
2835 TextFont_SetName,
2836 TextFont_GetOutline,
2837 TextFont_SetOutline,
2838 TextFont_GetPosition,
2839 TextFont_SetPosition,
2840 TextFont_GetProtected,
2841 TextFont_SetProtected,
2842 TextFont_GetShadow,
2843 TextFont_SetShadow,
2844 TextFont_GetSize,
2845 TextFont_SetSize,
2846 TextFont_GetSmallCaps,
2847 TextFont_SetSmallCaps,
2848 TextFont_GetSpacing,
2849 TextFont_SetSpacing,
2850 TextFont_GetStrikeThrough,
2851 TextFont_SetStrikeThrough,
2852 TextFont_GetSubscript,
2853 TextFont_SetSubscript,
2854 TextFont_GetSuperscript,
2855 TextFont_SetSuperscript,
2856 TextFont_GetUnderline,
2857 TextFont_SetUnderline,
2858 TextFont_GetWeight,
2859 TextFont_SetWeight
2862 static HRESULT create_textfont(ITextRange *range, const ITextFontImpl *src, ITextFont **ret)
2864 ITextFontImpl *font;
2866 *ret = NULL;
2867 font = heap_alloc(sizeof(*font));
2868 if (!font)
2869 return E_OUTOFMEMORY;
2871 font->ITextFont_iface.lpVtbl = &textfontvtbl;
2872 font->ref = 1;
2874 if (src) {
2875 font->range = NULL;
2876 font->get_cache_enabled = TRUE;
2877 font->set_cache_enabled = TRUE;
2878 memcpy(&font->props, &src->props, sizeof(font->props));
2879 if (font->props[FONT_NAME].str)
2880 font->props[FONT_NAME].str = SysAllocString(font->props[FONT_NAME].str);
2882 else {
2883 font->range = range;
2884 ITextRange_AddRef(range);
2886 /* cache current properties */
2887 font->get_cache_enabled = FALSE;
2888 font->set_cache_enabled = FALSE;
2889 textfont_cache_range_props(font);
2892 *ret = &font->ITextFont_iface;
2893 return S_OK;
2896 /* ITextPara */
2897 static HRESULT WINAPI TextPara_QueryInterface(ITextPara *iface, REFIID riid, void **ppv)
2899 ITextParaImpl *This = impl_from_ITextPara(iface);
2901 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2903 if (IsEqualIID(riid, &IID_ITextPara) ||
2904 IsEqualIID(riid, &IID_IDispatch) ||
2905 IsEqualIID(riid, &IID_IUnknown))
2907 *ppv = iface;
2908 ITextPara_AddRef(iface);
2909 return S_OK;
2912 *ppv = NULL;
2913 return E_NOINTERFACE;
2916 static ULONG WINAPI TextPara_AddRef(ITextPara *iface)
2918 ITextParaImpl *This = impl_from_ITextPara(iface);
2919 ULONG ref = InterlockedIncrement(&This->ref);
2920 TRACE("(%p)->(%u)\n", This, ref);
2921 return ref;
2924 static ULONG WINAPI TextPara_Release(ITextPara *iface)
2926 ITextParaImpl *This = impl_from_ITextPara(iface);
2927 ULONG ref = InterlockedDecrement(&This->ref);
2929 TRACE("(%p)->(%u)\n", This, ref);
2931 if (!ref)
2933 ITextRange_Release(This->range);
2934 heap_free(This);
2937 return ref;
2940 static HRESULT WINAPI TextPara_GetTypeInfoCount(ITextPara *iface, UINT *pctinfo)
2942 ITextParaImpl *This = impl_from_ITextPara(iface);
2943 TRACE("(%p)->(%p)\n", This, pctinfo);
2944 *pctinfo = 1;
2945 return S_OK;
2948 static HRESULT WINAPI TextPara_GetTypeInfo(ITextPara *iface, UINT iTInfo, LCID lcid,
2949 ITypeInfo **ppTInfo)
2951 ITextParaImpl *This = impl_from_ITextPara(iface);
2952 HRESULT hr;
2954 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
2956 hr = get_typeinfo(ITextPara_tid, ppTInfo);
2957 if (SUCCEEDED(hr))
2958 ITypeInfo_AddRef(*ppTInfo);
2959 return hr;
2962 static HRESULT WINAPI TextPara_GetIDsOfNames(ITextPara *iface, REFIID riid,
2963 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2965 ITextParaImpl *This = impl_from_ITextPara(iface);
2966 ITypeInfo *ti;
2967 HRESULT hr;
2969 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
2970 rgDispId);
2972 hr = get_typeinfo(ITextPara_tid, &ti);
2973 if (SUCCEEDED(hr))
2974 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
2975 return hr;
2978 static HRESULT WINAPI TextPara_Invoke(
2979 ITextPara *iface,
2980 DISPID dispIdMember,
2981 REFIID riid,
2982 LCID lcid,
2983 WORD wFlags,
2984 DISPPARAMS *pDispParams,
2985 VARIANT *pVarResult,
2986 EXCEPINFO *pExcepInfo,
2987 UINT *puArgErr)
2989 ITextParaImpl *This = impl_from_ITextPara(iface);
2990 ITypeInfo *ti;
2991 HRESULT hr;
2993 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
2994 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2996 hr = get_typeinfo(ITextPara_tid, &ti);
2997 if (SUCCEEDED(hr))
2998 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2999 return hr;
3002 static HRESULT WINAPI TextPara_GetDuplicate(ITextPara *iface, ITextPara **ret)
3004 ITextParaImpl *This = impl_from_ITextPara(iface);
3005 FIXME("(%p)->(%p)\n", This, ret);
3006 return E_NOTIMPL;
3009 static HRESULT WINAPI TextPara_SetDuplicate(ITextPara *iface, ITextPara *para)
3011 ITextParaImpl *This = impl_from_ITextPara(iface);
3012 FIXME("(%p)->(%p)\n", This, para);
3013 return E_NOTIMPL;
3016 static HRESULT WINAPI TextPara_CanChange(ITextPara *iface, LONG *ret)
3018 ITextParaImpl *This = impl_from_ITextPara(iface);
3019 FIXME("(%p)->(%p)\n", This, ret);
3020 return E_NOTIMPL;
3023 static HRESULT WINAPI TextPara_IsEqual(ITextPara *iface, ITextPara *para, LONG *ret)
3025 ITextParaImpl *This = impl_from_ITextPara(iface);
3026 FIXME("(%p)->(%p %p)\n", This, para, ret);
3027 return E_NOTIMPL;
3030 static HRESULT WINAPI TextPara_Reset(ITextPara *iface, LONG value)
3032 ITextParaImpl *This = impl_from_ITextPara(iface);
3033 FIXME("(%p)->(%d)\n", This, value);
3034 return E_NOTIMPL;
3037 static HRESULT WINAPI TextPara_GetStyle(ITextPara *iface, LONG *value)
3039 ITextParaImpl *This = impl_from_ITextPara(iface);
3040 FIXME("(%p)->(%p)\n", This, value);
3041 return E_NOTIMPL;
3044 static HRESULT WINAPI TextPara_SetStyle(ITextPara *iface, LONG value)
3046 ITextParaImpl *This = impl_from_ITextPara(iface);
3047 FIXME("(%p)->(%d)\n", This, value);
3048 return E_NOTIMPL;
3051 static HRESULT WINAPI TextPara_GetAlignment(ITextPara *iface, LONG *value)
3053 ITextParaImpl *This = impl_from_ITextPara(iface);
3054 FIXME("(%p)->(%p)\n", This, value);
3055 return E_NOTIMPL;
3058 static HRESULT WINAPI TextPara_SetAlignment(ITextPara *iface, LONG value)
3060 ITextParaImpl *This = impl_from_ITextPara(iface);
3061 FIXME("(%p)->(%d)\n", This, value);
3062 return E_NOTIMPL;
3065 static HRESULT WINAPI TextPara_GetHyphenation(ITextPara *iface, LONG *value)
3067 ITextParaImpl *This = impl_from_ITextPara(iface);
3068 FIXME("(%p)->(%p)\n", This, value);
3069 return E_NOTIMPL;
3072 static HRESULT WINAPI TextPara_SetHyphenation(ITextPara *iface, LONG value)
3074 ITextParaImpl *This = impl_from_ITextPara(iface);
3075 FIXME("(%p)->(%d)\n", This, value);
3076 return E_NOTIMPL;
3079 static HRESULT WINAPI TextPara_GetFirstLineIndent(ITextPara *iface, FLOAT *value)
3081 ITextParaImpl *This = impl_from_ITextPara(iface);
3082 FIXME("(%p)->(%p)\n", This, value);
3083 return E_NOTIMPL;
3086 static HRESULT WINAPI TextPara_GetKeepTogether(ITextPara *iface, LONG *value)
3088 ITextParaImpl *This = impl_from_ITextPara(iface);
3089 FIXME("(%p)->(%p)\n", This, value);
3090 return E_NOTIMPL;
3093 static HRESULT WINAPI TextPara_SetKeepTogether(ITextPara *iface, LONG value)
3095 ITextParaImpl *This = impl_from_ITextPara(iface);
3096 FIXME("(%p)->(%d)\n", This, value);
3097 return E_NOTIMPL;
3100 static HRESULT WINAPI TextPara_GetKeepWithNext(ITextPara *iface, LONG *value)
3102 ITextParaImpl *This = impl_from_ITextPara(iface);
3103 FIXME("(%p)->(%p)\n", This, value);
3104 return E_NOTIMPL;
3107 static HRESULT WINAPI TextPara_SetKeepWithNext(ITextPara *iface, LONG value)
3109 ITextParaImpl *This = impl_from_ITextPara(iface);
3110 FIXME("(%p)->(%d)\n", This, value);
3111 return E_NOTIMPL;
3114 static HRESULT WINAPI TextPara_GetLeftIndent(ITextPara *iface, FLOAT *value)
3116 ITextParaImpl *This = impl_from_ITextPara(iface);
3117 FIXME("(%p)->(%p)\n", This, value);
3118 return E_NOTIMPL;
3121 static HRESULT WINAPI TextPara_GetLineSpacing(ITextPara *iface, FLOAT *value)
3123 ITextParaImpl *This = impl_from_ITextPara(iface);
3124 FIXME("(%p)->(%p)\n", This, value);
3125 return E_NOTIMPL;
3128 static HRESULT WINAPI TextPara_GetLineSpacingRule(ITextPara *iface, LONG *value)
3130 ITextParaImpl *This = impl_from_ITextPara(iface);
3131 FIXME("(%p)->(%p)\n", This, value);
3132 return E_NOTIMPL;
3135 static HRESULT WINAPI TextPara_GetListAlignment(ITextPara *iface, LONG *value)
3137 ITextParaImpl *This = impl_from_ITextPara(iface);
3138 FIXME("(%p)->(%p)\n", This, value);
3139 return E_NOTIMPL;
3142 static HRESULT WINAPI TextPara_SetListAlignment(ITextPara *iface, LONG value)
3144 ITextParaImpl *This = impl_from_ITextPara(iface);
3145 FIXME("(%p)->(%d)\n", This, value);
3146 return E_NOTIMPL;
3149 static HRESULT WINAPI TextPara_GetListLevelIndex(ITextPara *iface, LONG *value)
3151 ITextParaImpl *This = impl_from_ITextPara(iface);
3152 FIXME("(%p)->(%p)\n", This, value);
3153 return E_NOTIMPL;
3156 static HRESULT WINAPI TextPara_SetListLevelIndex(ITextPara *iface, LONG value)
3158 ITextParaImpl *This = impl_from_ITextPara(iface);
3159 FIXME("(%p)->(%d)\n", This, value);
3160 return E_NOTIMPL;
3163 static HRESULT WINAPI TextPara_GetListStart(ITextPara *iface, LONG *value)
3165 ITextParaImpl *This = impl_from_ITextPara(iface);
3166 FIXME("(%p)->(%p)\n", This, value);
3167 return E_NOTIMPL;
3170 static HRESULT WINAPI TextPara_SetListStart(ITextPara *iface, LONG value)
3172 ITextParaImpl *This = impl_from_ITextPara(iface);
3173 FIXME("(%p)->(%d)\n", This, value);
3174 return E_NOTIMPL;
3177 static HRESULT WINAPI TextPara_GetListTab(ITextPara *iface, FLOAT *value)
3179 ITextParaImpl *This = impl_from_ITextPara(iface);
3180 FIXME("(%p)->(%p)\n", This, value);
3181 return E_NOTIMPL;
3184 static HRESULT WINAPI TextPara_SetListTab(ITextPara *iface, FLOAT value)
3186 ITextParaImpl *This = impl_from_ITextPara(iface);
3187 FIXME("(%p)->(%.2f)\n", This, value);
3188 return E_NOTIMPL;
3191 static HRESULT WINAPI TextPara_GetListType(ITextPara *iface, LONG *value)
3193 ITextParaImpl *This = impl_from_ITextPara(iface);
3194 FIXME("(%p)->(%p)\n", This, value);
3195 return E_NOTIMPL;
3198 static HRESULT WINAPI TextPara_SetListType(ITextPara *iface, LONG value)
3200 ITextParaImpl *This = impl_from_ITextPara(iface);
3201 FIXME("(%p)->(%d)\n", This, value);
3202 return E_NOTIMPL;
3205 static HRESULT WINAPI TextPara_GetNoLineNumber(ITextPara *iface, LONG *value)
3207 ITextParaImpl *This = impl_from_ITextPara(iface);
3208 FIXME("(%p)->(%p)\n", This, value);
3209 return E_NOTIMPL;
3212 static HRESULT WINAPI TextPara_SetNoLineNumber(ITextPara *iface, LONG value)
3214 ITextParaImpl *This = impl_from_ITextPara(iface);
3215 FIXME("(%p)->(%d)\n", This, value);
3216 return E_NOTIMPL;
3219 static HRESULT WINAPI TextPara_GetPageBreakBefore(ITextPara *iface, LONG *value)
3221 ITextParaImpl *This = impl_from_ITextPara(iface);
3222 FIXME("(%p)->(%p)\n", This, value);
3223 return E_NOTIMPL;
3226 static HRESULT WINAPI TextPara_SetPageBreakBefore(ITextPara *iface, LONG value)
3228 ITextParaImpl *This = impl_from_ITextPara(iface);
3229 FIXME("(%p)->(%d)\n", This, value);
3230 return E_NOTIMPL;
3233 static HRESULT WINAPI TextPara_GetRightIndent(ITextPara *iface, FLOAT *value)
3235 ITextParaImpl *This = impl_from_ITextPara(iface);
3236 FIXME("(%p)->(%p)\n", This, value);
3237 return E_NOTIMPL;
3240 static HRESULT WINAPI TextPara_SetRightIndent(ITextPara *iface, FLOAT value)
3242 ITextParaImpl *This = impl_from_ITextPara(iface);
3243 FIXME("(%p)->(%.2f)\n", This, value);
3244 return E_NOTIMPL;
3247 static HRESULT WINAPI TextPara_SetIndents(ITextPara *iface, FLOAT StartIndent, FLOAT LeftIndent, FLOAT RightIndent)
3249 ITextParaImpl *This = impl_from_ITextPara(iface);
3250 FIXME("(%p)->(%.2f %.2f %.2f)\n", This, StartIndent, LeftIndent, RightIndent);
3251 return E_NOTIMPL;
3254 static HRESULT WINAPI TextPara_SetLineSpacing(ITextPara *iface, LONG LineSpacingRule, FLOAT LineSpacing)
3256 ITextParaImpl *This = impl_from_ITextPara(iface);
3257 FIXME("(%p)->(%d %.2f)\n", This, LineSpacingRule, LineSpacing);
3258 return E_NOTIMPL;
3261 static HRESULT WINAPI TextPara_GetSpaceAfter(ITextPara *iface, FLOAT *value)
3263 ITextParaImpl *This = impl_from_ITextPara(iface);
3264 FIXME("(%p)->(%p)\n", This, value);
3265 return E_NOTIMPL;
3268 static HRESULT WINAPI TextPara_SetSpaceAfter(ITextPara *iface, FLOAT value)
3270 ITextParaImpl *This = impl_from_ITextPara(iface);
3271 FIXME("(%p)->(%.2f)\n", This, value);
3272 return E_NOTIMPL;
3275 static HRESULT WINAPI TextPara_GetSpaceBefore(ITextPara *iface, FLOAT *value)
3277 ITextParaImpl *This = impl_from_ITextPara(iface);
3278 FIXME("(%p)->(%p)\n", This, value);
3279 return E_NOTIMPL;
3282 static HRESULT WINAPI TextPara_SetSpaceBefore(ITextPara *iface, FLOAT value)
3284 ITextParaImpl *This = impl_from_ITextPara(iface);
3285 FIXME("(%p)->(%.2f)\n", This, value);
3286 return E_NOTIMPL;
3289 static HRESULT WINAPI TextPara_GetWidowControl(ITextPara *iface, LONG *value)
3291 ITextParaImpl *This = impl_from_ITextPara(iface);
3292 FIXME("(%p)->(%p)\n", This, value);
3293 return E_NOTIMPL;
3296 static HRESULT WINAPI TextPara_SetWidowControl(ITextPara *iface, LONG value)
3298 ITextParaImpl *This = impl_from_ITextPara(iface);
3299 FIXME("(%p)->(%d)\n", This, value);
3300 return E_NOTIMPL;
3303 static HRESULT WINAPI TextPara_GetTabCount(ITextPara *iface, LONG *value)
3305 ITextParaImpl *This = impl_from_ITextPara(iface);
3306 FIXME("(%p)->(%p)\n", This, value);
3307 return E_NOTIMPL;
3310 static HRESULT WINAPI TextPara_AddTab(ITextPara *iface, FLOAT tbPos, LONG tbAlign, LONG tbLeader)
3312 ITextParaImpl *This = impl_from_ITextPara(iface);
3313 FIXME("(%p)->(%.2f %d %d)\n", This, tbPos, tbAlign, tbLeader);
3314 return E_NOTIMPL;
3317 static HRESULT WINAPI TextPara_ClearAllTabs(ITextPara *iface)
3319 ITextParaImpl *This = impl_from_ITextPara(iface);
3320 FIXME("(%p)\n", This);
3321 return E_NOTIMPL;
3324 static HRESULT WINAPI TextPara_DeleteTab(ITextPara *iface, FLOAT pos)
3326 ITextParaImpl *This = impl_from_ITextPara(iface);
3327 FIXME("(%p)->(%.2f)\n", This, pos);
3328 return E_NOTIMPL;
3331 static HRESULT WINAPI TextPara_GetTab(ITextPara *iface, LONG iTab, FLOAT *ptbPos, LONG *ptbAlign, LONG *ptbLeader)
3333 ITextParaImpl *This = impl_from_ITextPara(iface);
3334 FIXME("(%p)->(%d %p %p %p)\n", This, iTab, ptbPos, ptbAlign, ptbLeader);
3335 return E_NOTIMPL;
3338 static ITextParaVtbl textparavtbl = {
3339 TextPara_QueryInterface,
3340 TextPara_AddRef,
3341 TextPara_Release,
3342 TextPara_GetTypeInfoCount,
3343 TextPara_GetTypeInfo,
3344 TextPara_GetIDsOfNames,
3345 TextPara_Invoke,
3346 TextPara_GetDuplicate,
3347 TextPara_SetDuplicate,
3348 TextPara_CanChange,
3349 TextPara_IsEqual,
3350 TextPara_Reset,
3351 TextPara_GetStyle,
3352 TextPara_SetStyle,
3353 TextPara_GetAlignment,
3354 TextPara_SetAlignment,
3355 TextPara_GetHyphenation,
3356 TextPara_SetHyphenation,
3357 TextPara_GetFirstLineIndent,
3358 TextPara_GetKeepTogether,
3359 TextPara_SetKeepTogether,
3360 TextPara_GetKeepWithNext,
3361 TextPara_SetKeepWithNext,
3362 TextPara_GetLeftIndent,
3363 TextPara_GetLineSpacing,
3364 TextPara_GetLineSpacingRule,
3365 TextPara_GetListAlignment,
3366 TextPara_SetListAlignment,
3367 TextPara_GetListLevelIndex,
3368 TextPara_SetListLevelIndex,
3369 TextPara_GetListStart,
3370 TextPara_SetListStart,
3371 TextPara_GetListTab,
3372 TextPara_SetListTab,
3373 TextPara_GetListType,
3374 TextPara_SetListType,
3375 TextPara_GetNoLineNumber,
3376 TextPara_SetNoLineNumber,
3377 TextPara_GetPageBreakBefore,
3378 TextPara_SetPageBreakBefore,
3379 TextPara_GetRightIndent,
3380 TextPara_SetRightIndent,
3381 TextPara_SetIndents,
3382 TextPara_SetLineSpacing,
3383 TextPara_GetSpaceAfter,
3384 TextPara_SetSpaceAfter,
3385 TextPara_GetSpaceBefore,
3386 TextPara_SetSpaceBefore,
3387 TextPara_GetWidowControl,
3388 TextPara_SetWidowControl,
3389 TextPara_GetTabCount,
3390 TextPara_AddTab,
3391 TextPara_ClearAllTabs,
3392 TextPara_DeleteTab,
3393 TextPara_GetTab
3396 static HRESULT create_textpara(ITextRange *range, ITextPara **ret)
3398 ITextParaImpl *para;
3400 *ret = NULL;
3401 para = heap_alloc(sizeof(*para));
3402 if (!para)
3403 return E_OUTOFMEMORY;
3405 para->ITextPara_iface.lpVtbl = &textparavtbl;
3406 para->ref = 1;
3407 para->range = range;
3408 ITextRange_AddRef(range);
3410 *ret = &para->ITextPara_iface;
3411 return S_OK;
3414 /* ITextDocument */
3415 static HRESULT WINAPI
3416 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
3417 void** ppvObject)
3419 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3420 return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
3423 static ULONG WINAPI
3424 ITextDocument_fnAddRef(ITextDocument* me)
3426 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3427 return IRichEditOle_AddRef(&This->IRichEditOle_iface);
3430 static ULONG WINAPI
3431 ITextDocument_fnRelease(ITextDocument* me)
3433 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3434 return IRichEditOle_Release(&This->IRichEditOle_iface);
3437 static HRESULT WINAPI
3438 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
3439 UINT* pctinfo)
3441 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3442 TRACE("(%p)->(%p)\n", This, pctinfo);
3443 *pctinfo = 1;
3444 return S_OK;
3447 static HRESULT WINAPI
3448 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
3449 ITypeInfo** ppTInfo)
3451 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3452 HRESULT hr;
3454 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3456 hr = get_typeinfo(ITextDocument_tid, ppTInfo);
3457 if (SUCCEEDED(hr))
3458 ITypeInfo_AddRef(*ppTInfo);
3459 return hr;
3462 static HRESULT WINAPI
3463 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
3464 LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
3466 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3467 ITypeInfo *ti;
3468 HRESULT hr;
3470 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
3471 rgDispId);
3473 hr = get_typeinfo(ITextDocument_tid, &ti);
3474 if (SUCCEEDED(hr))
3475 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3476 return hr;
3479 static HRESULT WINAPI
3480 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
3481 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
3482 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
3484 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3485 ITypeInfo *ti;
3486 HRESULT hr;
3488 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
3489 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3491 hr = get_typeinfo(ITextDocument_tid, &ti);
3492 if (SUCCEEDED(hr))
3493 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3494 return hr;
3497 static HRESULT WINAPI
3498 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
3500 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3501 FIXME("stub %p\n",This);
3502 return E_NOTIMPL;
3505 static HRESULT WINAPI
3506 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
3508 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3509 TRACE("(%p)\n", me);
3511 if(!ppSel)
3512 return E_INVALIDARG;
3513 *ppSel = &This->txtSel->ITextSelection_iface;
3514 ITextSelection_AddRef(*ppSel);
3515 return S_OK;
3518 static HRESULT WINAPI
3519 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
3521 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3522 FIXME("stub %p\n",This);
3523 return E_NOTIMPL;
3526 static HRESULT WINAPI
3527 ITextDocument_fnGetStoryRanges(ITextDocument* me,
3528 ITextStoryRanges** ppStories)
3530 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3531 FIXME("stub %p\n",This);
3532 return E_NOTIMPL;
3535 static HRESULT WINAPI
3536 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
3538 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3539 FIXME("stub %p\n",This);
3540 return E_NOTIMPL;
3543 static HRESULT WINAPI
3544 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
3546 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3547 FIXME("stub %p\n",This);
3548 return E_NOTIMPL;
3551 static HRESULT WINAPI
3552 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
3554 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3555 FIXME("stub %p\n",This);
3556 return E_NOTIMPL;
3559 static HRESULT WINAPI
3560 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
3562 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3563 FIXME("stub %p\n",This);
3564 return E_NOTIMPL;
3567 static HRESULT WINAPI
3568 ITextDocument_fnNew(ITextDocument* me)
3570 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3571 FIXME("stub %p\n",This);
3572 return E_NOTIMPL;
3575 static HRESULT WINAPI
3576 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
3577 LONG CodePage)
3579 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3580 FIXME("stub %p\n",This);
3581 return E_NOTIMPL;
3584 static HRESULT WINAPI
3585 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
3586 LONG CodePage)
3588 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3589 FIXME("stub %p\n",This);
3590 return E_NOTIMPL;
3593 static HRESULT WINAPI
3594 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
3596 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3597 FIXME("stub %p\n",This);
3598 return E_NOTIMPL;
3601 static HRESULT WINAPI
3602 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
3604 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3605 FIXME("stub %p\n",This);
3606 return E_NOTIMPL;
3609 static HRESULT WINAPI
3610 ITextDocument_fnBeginEditCollection(ITextDocument* me)
3612 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3613 FIXME("stub %p\n",This);
3614 return E_NOTIMPL;
3617 static HRESULT WINAPI
3618 ITextDocument_fnEndEditCollection(ITextDocument* me)
3620 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3621 FIXME("stub %p\n",This);
3622 return E_NOTIMPL;
3625 static HRESULT WINAPI
3626 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
3628 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3629 FIXME("stub %p\n",This);
3630 return E_NOTIMPL;
3633 static HRESULT WINAPI
3634 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
3636 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3637 FIXME("stub %p\n",This);
3638 return E_NOTIMPL;
3641 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
3643 ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
3645 if (!txtRge)
3646 return E_OUTOFMEMORY;
3647 txtRge->ITextRange_iface.lpVtbl = &trvt;
3648 txtRge->ref = 1;
3649 txtRge->reOle = reOle;
3650 txtRge->start = start;
3651 txtRge->end = end;
3652 list_add_head(&reOle->rangelist, &txtRge->entry);
3653 *ppRange = &txtRge->ITextRange_iface;
3654 return S_OK;
3657 static HRESULT WINAPI
3658 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
3659 ITextRange** ppRange)
3661 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3662 const int len = ME_GetTextLength(This->editor) + 1;
3664 TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
3665 if (!ppRange)
3666 return E_INVALIDARG;
3668 cp1 = max(cp1, 0);
3669 cp2 = max(cp2, 0);
3670 cp1 = min(cp1, len);
3671 cp2 = min(cp2, len);
3672 if (cp1 > cp2)
3674 LONG tmp;
3675 tmp = cp1;
3676 cp1 = cp2;
3677 cp2 = tmp;
3679 if (cp1 == len)
3680 cp1 = cp2 = len - 1;
3682 return CreateITextRange(This, cp1, cp2, ppRange);
3685 static HRESULT WINAPI
3686 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
3687 ITextRange** ppRange)
3689 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3690 FIXME("stub %p\n",This);
3691 return E_NOTIMPL;
3694 static const ITextDocumentVtbl tdvt = {
3695 ITextDocument_fnQueryInterface,
3696 ITextDocument_fnAddRef,
3697 ITextDocument_fnRelease,
3698 ITextDocument_fnGetTypeInfoCount,
3699 ITextDocument_fnGetTypeInfo,
3700 ITextDocument_fnGetIDsOfNames,
3701 ITextDocument_fnInvoke,
3702 ITextDocument_fnGetName,
3703 ITextDocument_fnGetSelection,
3704 ITextDocument_fnGetStoryCount,
3705 ITextDocument_fnGetStoryRanges,
3706 ITextDocument_fnGetSaved,
3707 ITextDocument_fnSetSaved,
3708 ITextDocument_fnGetDefaultTabStop,
3709 ITextDocument_fnSetDefaultTabStop,
3710 ITextDocument_fnNew,
3711 ITextDocument_fnOpen,
3712 ITextDocument_fnSave,
3713 ITextDocument_fnFreeze,
3714 ITextDocument_fnUnfreeze,
3715 ITextDocument_fnBeginEditCollection,
3716 ITextDocument_fnEndEditCollection,
3717 ITextDocument_fnUndo,
3718 ITextDocument_fnRedo,
3719 ITextDocument_fnRange,
3720 ITextDocument_fnRangeFromPoint
3723 /* ITextSelection */
3724 static HRESULT WINAPI ITextSelection_fnQueryInterface(
3725 ITextSelection *me,
3726 REFIID riid,
3727 void **ppvObj)
3729 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3731 *ppvObj = NULL;
3732 if (IsEqualGUID(riid, &IID_IUnknown)
3733 || IsEqualGUID(riid, &IID_IDispatch)
3734 || IsEqualGUID(riid, &IID_ITextRange)
3735 || IsEqualGUID(riid, &IID_ITextSelection))
3737 *ppvObj = me;
3738 ITextSelection_AddRef(me);
3739 return S_OK;
3741 else if (IsEqualGUID(riid, &IID_Igetrichole))
3743 *ppvObj = This->reOle;
3744 return S_OK;
3747 return E_NOINTERFACE;
3750 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
3752 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3753 return InterlockedIncrement(&This->ref);
3756 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
3758 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3759 ULONG ref = InterlockedDecrement(&This->ref);
3760 if (ref == 0)
3761 heap_free(This);
3762 return ref;
3765 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
3767 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3768 TRACE("(%p)->(%p)\n", This, pctinfo);
3769 *pctinfo = 1;
3770 return S_OK;
3773 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
3774 ITypeInfo **ppTInfo)
3776 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3777 HRESULT hr;
3779 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3781 hr = get_typeinfo(ITextSelection_tid, ppTInfo);
3782 if (SUCCEEDED(hr))
3783 ITypeInfo_AddRef(*ppTInfo);
3784 return hr;
3787 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
3788 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3790 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3791 ITypeInfo *ti;
3792 HRESULT hr;
3794 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
3795 rgDispId);
3797 hr = get_typeinfo(ITextSelection_tid, &ti);
3798 if (SUCCEEDED(hr))
3799 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3800 return hr;
3803 static HRESULT WINAPI ITextSelection_fnInvoke(
3804 ITextSelection *me,
3805 DISPID dispIdMember,
3806 REFIID riid,
3807 LCID lcid,
3808 WORD wFlags,
3809 DISPPARAMS *pDispParams,
3810 VARIANT *pVarResult,
3811 EXCEPINFO *pExcepInfo,
3812 UINT *puArgErr)
3814 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3815 ITypeInfo *ti;
3816 HRESULT hr;
3818 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
3819 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3821 hr = get_typeinfo(ITextSelection_tid, &ti);
3822 if (SUCCEEDED(hr))
3823 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3824 return hr;
3827 /*** ITextRange methods ***/
3828 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
3830 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3831 ME_Cursor *start = NULL, *end = NULL;
3832 int nChars, endOfs;
3833 BOOL bEOP;
3835 TRACE("(%p)->(%p)\n", This, pbstr);
3837 if (!This->reOle)
3838 return CO_E_RELEASED;
3840 if (!pbstr)
3841 return E_INVALIDARG;
3843 ME_GetSelection(This->reOle->editor, &start, &end);
3844 endOfs = ME_GetCursorOfs(end);
3845 nChars = endOfs - ME_GetCursorOfs(start);
3846 if (!nChars)
3848 *pbstr = NULL;
3849 return S_OK;
3852 *pbstr = SysAllocStringLen(NULL, nChars);
3853 if (!*pbstr)
3854 return E_OUTOFMEMORY;
3856 bEOP = (end->pRun->next->type == diTextEnd && endOfs > ME_GetTextLength(This->reOle->editor));
3857 ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
3858 TRACE("%s\n", wine_dbgstr_w(*pbstr));
3860 return S_OK;
3863 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
3865 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3866 if (!This->reOle)
3867 return CO_E_RELEASED;
3869 FIXME("not implemented\n");
3870 return E_NOTIMPL;
3873 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
3875 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3876 ME_Cursor *start = NULL, *end = NULL;
3878 if (!This->reOle)
3879 return CO_E_RELEASED;
3880 TRACE("%p\n", pch);
3881 if (!pch)
3882 return E_INVALIDARG;
3884 ME_GetSelection(This->reOle->editor, &start, &end);
3885 return range_GetChar(This->reOle->editor, start, pch);
3888 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
3890 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3891 if (!This->reOle)
3892 return CO_E_RELEASED;
3894 FIXME("not implemented\n");
3895 return E_NOTIMPL;
3898 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
3900 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3901 if (!This->reOle)
3902 return CO_E_RELEASED;
3904 FIXME("not implemented\n");
3905 return E_NOTIMPL;
3908 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)
3910 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3911 if (!This->reOle)
3912 return CO_E_RELEASED;
3914 FIXME("not implemented\n");
3915 return E_NOTIMPL;
3918 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *pRange)
3920 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3921 if (!This->reOle)
3922 return CO_E_RELEASED;
3924 FIXME("not implemented\n");
3925 return E_NOTIMPL;
3928 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
3930 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3931 LONG lim;
3932 if (!This->reOle)
3933 return CO_E_RELEASED;
3935 if (!pcpFirst)
3936 return E_INVALIDARG;
3937 ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim);
3938 TRACE("%d\n", *pcpFirst);
3939 return S_OK;
3942 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG value)
3944 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3945 LONG start, end;
3946 HRESULT hr;
3948 TRACE("(%p)->(%d)\n", This, value);
3950 if (!This->reOle)
3951 return CO_E_RELEASED;
3953 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
3954 hr = textrange_setstart(This->reOle, value, &start, &end);
3955 if (hr == S_OK)
3956 ME_SetSelection(This->reOle->editor, start, end);
3958 return hr;
3961 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
3963 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3964 LONG first;
3965 if (!This->reOle)
3966 return CO_E_RELEASED;
3968 if (!pcpLim)
3969 return E_INVALIDARG;
3970 ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim);
3971 TRACE("%d\n", *pcpLim);
3972 return S_OK;
3975 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG value)
3977 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3978 LONG start, end;
3979 HRESULT hr;
3981 TRACE("(%p)->(%d)\n", This, value);
3983 if (!This->reOle)
3984 return CO_E_RELEASED;
3986 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
3987 hr = textrange_setend(This->reOle, value, &start, &end);
3988 if (hr == S_OK)
3989 ME_SetSelection(This->reOle->editor, start, end);
3991 return hr;
3994 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **font)
3996 ITextSelectionImpl *This = impl_from_ITextSelection(me);
3998 TRACE("(%p)->(%p)\n", This, font);
4000 if (!This->reOle)
4001 return CO_E_RELEASED;
4003 if (!font)
4004 return E_INVALIDARG;
4006 return create_textfont((ITextRange*)me, NULL, font);
4009 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
4011 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4012 if (!This->reOle)
4013 return CO_E_RELEASED;
4015 FIXME("not implemented\n");
4016 return E_NOTIMPL;
4019 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **para)
4021 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4022 if (!This->reOle)
4023 return CO_E_RELEASED;
4025 FIXME("not implemented\n");
4026 return E_NOTIMPL;
4029 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pPara)
4031 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4032 if (!This->reOle)
4033 return CO_E_RELEASED;
4035 FIXME("not implemented\n");
4036 return E_NOTIMPL;
4039 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *pcch)
4041 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4042 if (!This->reOle)
4043 return CO_E_RELEASED;
4045 FIXME("not implemented\n");
4046 return E_NOTIMPL;
4049 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pValue)
4051 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4052 if (!This->reOle)
4053 return CO_E_RELEASED;
4055 FIXME("not implemented\n");
4056 return E_NOTIMPL;
4059 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
4061 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4062 LONG start, end;
4063 HRESULT hres;
4064 if (!This->reOle)
4065 return CO_E_RELEASED;
4067 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
4068 hres = range_Collapse(bStart, &start, &end);
4069 if (SUCCEEDED(hres))
4070 ME_SetSelection(This->reOle->editor, start, end);
4071 return hres;
4074 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
4076 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4077 if (!This->reOle)
4078 return CO_E_RELEASED;
4080 FIXME("not implemented\n");
4081 return E_NOTIMPL;
4084 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
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_fnSetIndex(ITextSelection *me, LONG Unit, LONG Index,
4095 LONG Extend)
4097 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4098 if (!This->reOle)
4099 return CO_E_RELEASED;
4101 FIXME("not implemented\n");
4102 return E_NOTIMPL;
4105 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActive, LONG cpOther)
4107 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4108 if (!This->reOle)
4109 return CO_E_RELEASED;
4111 FIXME("not implemented\n");
4112 return E_NOTIMPL;
4115 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
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_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)
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_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb)
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_fnSelect(ITextSelection *me)
4147 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4148 if (!This->reOle)
4149 return CO_E_RELEASED;
4151 FIXME("not implemented\n");
4152 return E_NOTIMPL;
4155 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG Unit, LONG Extend,
4156 LONG *pDelta)
4158 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4159 if (!This->reOle)
4160 return CO_E_RELEASED;
4162 FIXME("not implemented\n");
4163 return E_NOTIMPL;
4166 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG Extend,
4167 LONG *pDelta)
4169 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4170 if (!This->reOle)
4171 return CO_E_RELEASED;
4173 FIXME("not implemented\n");
4174 return E_NOTIMPL;
4177 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG Unit, LONG Count, LONG *pDelta)
4179 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4180 if (!This->reOle)
4181 return CO_E_RELEASED;
4183 FIXME("not implemented\n");
4184 return E_NOTIMPL;
4187 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG Unit, LONG Count,
4188 LONG *pDelta)
4190 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4191 if (!This->reOle)
4192 return CO_E_RELEASED;
4194 FIXME("not implemented\n");
4195 return E_NOTIMPL;
4198 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG Unit, LONG Count,
4199 LONG *pDelta)
4201 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4202 if (!This->reOle)
4203 return CO_E_RELEASED;
4205 FIXME("not implemented\n");
4206 return E_NOTIMPL;
4209 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
4210 LONG *pDelta)
4212 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4213 if (!This->reOle)
4214 return CO_E_RELEASED;
4216 FIXME("not implemented\n");
4217 return E_NOTIMPL;
4220 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
4221 LONG *pDelta)
4223 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4224 if (!This->reOle)
4225 return CO_E_RELEASED;
4227 FIXME("not implemented\n");
4228 return E_NOTIMPL;
4231 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *Cset, LONG Count,
4232 LONG *pDelta)
4234 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4235 if (!This->reOle)
4236 return CO_E_RELEASED;
4238 FIXME("not implemented\n");
4239 return E_NOTIMPL;
4242 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
4243 LONG *pDelta)
4245 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4246 if (!This->reOle)
4247 return CO_E_RELEASED;
4249 FIXME("not implemented\n");
4250 return E_NOTIMPL;
4253 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
4254 LONG *pDelta)
4256 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4257 if (!This->reOle)
4258 return CO_E_RELEASED;
4260 FIXME("not implemented\n");
4261 return E_NOTIMPL;
4264 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *Cset, LONG Count,
4265 LONG *pDelta)
4267 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4268 if (!This->reOle)
4269 return CO_E_RELEASED;
4271 FIXME("not implemented\n");
4272 return E_NOTIMPL;
4275 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR bstr, LONG cch, LONG Flags,
4276 LONG *pLength)
4278 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4279 if (!This->reOle)
4280 return CO_E_RELEASED;
4282 FIXME("not implemented\n");
4283 return E_NOTIMPL;
4286 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR bstr, LONG cch,
4287 LONG Flags, LONG *pLength)
4289 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4290 if (!This->reOle)
4291 return CO_E_RELEASED;
4293 FIXME("not implemented\n");
4294 return E_NOTIMPL;
4297 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR bstr, LONG cch,
4298 LONG Flags, LONG *pLength)
4300 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4301 if (!This->reOle)
4302 return CO_E_RELEASED;
4304 FIXME("not implemented\n");
4305 return E_NOTIMPL;
4308 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG Unit, LONG Count,
4309 LONG *pDelta)
4311 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4312 if (!This->reOle)
4313 return CO_E_RELEASED;
4315 FIXME("not implemented\n");
4316 return E_NOTIMPL;
4319 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *pVar)
4321 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4322 if (!This->reOle)
4323 return CO_E_RELEASED;
4325 FIXME("not implemented\n");
4326 return E_NOTIMPL;
4329 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *pVar)
4331 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4332 if (!This->reOle)
4333 return CO_E_RELEASED;
4335 FIXME("not implemented\n");
4336 return E_NOTIMPL;
4339 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *pVar, LONG Format)
4341 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4342 if (!This->reOle)
4343 return CO_E_RELEASED;
4345 FIXME("not implemented\n");
4346 return E_NOTIMPL;
4349 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *pVar, LONG Format,
4350 LONG *pb)
4352 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4353 if (!This->reOle)
4354 return CO_E_RELEASED;
4356 FIXME("not implemented\n");
4357 return E_NOTIMPL;
4360 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *pb)
4362 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4363 if (!This->reOle)
4364 return CO_E_RELEASED;
4366 FIXME("not implemented\n");
4367 return E_NOTIMPL;
4370 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG Type)
4372 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4373 if (!This->reOle)
4374 return CO_E_RELEASED;
4376 FIXME("not implemented\n");
4377 return E_NOTIMPL;
4380 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG Type, LONG *cx, LONG *cy)
4382 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4383 if (!This->reOle)
4384 return CO_E_RELEASED;
4386 FIXME("not implemented\n");
4387 return E_NOTIMPL;
4390 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG Type,
4391 LONG Extend)
4393 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4394 if (!This->reOle)
4395 return CO_E_RELEASED;
4397 FIXME("not implemented\n");
4398 return E_NOTIMPL;
4401 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG Value)
4403 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4404 if (!This->reOle)
4405 return CO_E_RELEASED;
4407 FIXME("not implemented\n");
4408 return E_NOTIMPL;
4411 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
4413 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4414 if (!This->reOle)
4415 return CO_E_RELEASED;
4417 FIXME("not implemented\n");
4418 return E_NOTIMPL;
4421 /*** ITextSelection methods ***/
4422 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags)
4424 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4425 if (!This->reOle)
4426 return CO_E_RELEASED;
4428 FIXME("not implemented\n");
4429 return E_NOTIMPL;
4432 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
4434 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4435 if (!This->reOle)
4436 return CO_E_RELEASED;
4438 FIXME("not implemented\n");
4439 return E_NOTIMPL;
4442 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *pType)
4444 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4445 if (!This->reOle)
4446 return CO_E_RELEASED;
4448 FIXME("not implemented\n");
4449 return E_NOTIMPL;
4452 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG Unit, LONG Count,
4453 LONG Extend, LONG *pDelta)
4455 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4456 if (!This->reOle)
4457 return CO_E_RELEASED;
4459 FIXME("not implemented\n");
4460 return E_NOTIMPL;
4463 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG Unit, LONG Count,
4464 LONG Extend, LONG *pDelta)
4466 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4467 if (!This->reOle)
4468 return CO_E_RELEASED;
4470 FIXME("not implemented\n");
4471 return E_NOTIMPL;
4474 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG Unit, LONG Count,
4475 LONG Extend, LONG *pDelta)
4477 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4478 if (!This->reOle)
4479 return CO_E_RELEASED;
4481 FIXME("not implemented\n");
4482 return E_NOTIMPL;
4485 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG Unit, LONG Count,
4486 LONG Extend, LONG *pDelta)
4488 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4489 if (!This->reOle)
4490 return CO_E_RELEASED;
4492 FIXME("not implemented\n");
4493 return E_NOTIMPL;
4496 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG Unit, LONG Extend,
4497 LONG *pDelta)
4499 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4500 if (!This->reOle)
4501 return CO_E_RELEASED;
4503 FIXME("not implemented\n");
4504 return E_NOTIMPL;
4507 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LONG Extend,
4508 LONG *pDelta)
4510 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4511 if (!This->reOle)
4512 return CO_E_RELEASED;
4514 FIXME("not implemented\n");
4515 return E_NOTIMPL;
4518 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR bstr)
4520 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4521 if (!This->reOle)
4522 return CO_E_RELEASED;
4524 FIXME("not implemented\n");
4525 return E_NOTIMPL;
4528 static const ITextSelectionVtbl tsvt = {
4529 ITextSelection_fnQueryInterface,
4530 ITextSelection_fnAddRef,
4531 ITextSelection_fnRelease,
4532 ITextSelection_fnGetTypeInfoCount,
4533 ITextSelection_fnGetTypeInfo,
4534 ITextSelection_fnGetIDsOfNames,
4535 ITextSelection_fnInvoke,
4536 ITextSelection_fnGetText,
4537 ITextSelection_fnSetText,
4538 ITextSelection_fnGetChar,
4539 ITextSelection_fnSetChar,
4540 ITextSelection_fnGetDuplicate,
4541 ITextSelection_fnGetFormattedText,
4542 ITextSelection_fnSetFormattedText,
4543 ITextSelection_fnGetStart,
4544 ITextSelection_fnSetStart,
4545 ITextSelection_fnGetEnd,
4546 ITextSelection_fnSetEnd,
4547 ITextSelection_fnGetFont,
4548 ITextSelection_fnSetFont,
4549 ITextSelection_fnGetPara,
4550 ITextSelection_fnSetPara,
4551 ITextSelection_fnGetStoryLength,
4552 ITextSelection_fnGetStoryType,
4553 ITextSelection_fnCollapse,
4554 ITextSelection_fnExpand,
4555 ITextSelection_fnGetIndex,
4556 ITextSelection_fnSetIndex,
4557 ITextSelection_fnSetRange,
4558 ITextSelection_fnInRange,
4559 ITextSelection_fnInStory,
4560 ITextSelection_fnIsEqual,
4561 ITextSelection_fnSelect,
4562 ITextSelection_fnStartOf,
4563 ITextSelection_fnEndOf,
4564 ITextSelection_fnMove,
4565 ITextSelection_fnMoveStart,
4566 ITextSelection_fnMoveEnd,
4567 ITextSelection_fnMoveWhile,
4568 ITextSelection_fnMoveStartWhile,
4569 ITextSelection_fnMoveEndWhile,
4570 ITextSelection_fnMoveUntil,
4571 ITextSelection_fnMoveStartUntil,
4572 ITextSelection_fnMoveEndUntil,
4573 ITextSelection_fnFindText,
4574 ITextSelection_fnFindTextStart,
4575 ITextSelection_fnFindTextEnd,
4576 ITextSelection_fnDelete,
4577 ITextSelection_fnCut,
4578 ITextSelection_fnCopy,
4579 ITextSelection_fnPaste,
4580 ITextSelection_fnCanPaste,
4581 ITextSelection_fnCanEdit,
4582 ITextSelection_fnChangeCase,
4583 ITextSelection_fnGetPoint,
4584 ITextSelection_fnSetPoint,
4585 ITextSelection_fnScrollIntoView,
4586 ITextSelection_fnGetEmbeddedObject,
4587 ITextSelection_fnGetFlags,
4588 ITextSelection_fnSetFlags,
4589 ITextSelection_fnGetType,
4590 ITextSelection_fnMoveLeft,
4591 ITextSelection_fnMoveRight,
4592 ITextSelection_fnMoveUp,
4593 ITextSelection_fnMoveDown,
4594 ITextSelection_fnHomeKey,
4595 ITextSelection_fnEndKey,
4596 ITextSelection_fnTypeText
4599 static ITextSelectionImpl *
4600 CreateTextSelection(IRichEditOleImpl *reOle)
4602 ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
4603 if (!txtSel)
4604 return NULL;
4606 txtSel->ITextSelection_iface.lpVtbl = &tsvt;
4607 txtSel->ref = 1;
4608 txtSel->reOle = reOle;
4609 return txtSel;
4612 LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *ppvObj)
4614 IRichEditOleImpl *reo;
4616 reo = heap_alloc(sizeof(IRichEditOleImpl));
4617 if (!reo)
4618 return 0;
4620 reo->IUnknown_inner.lpVtbl = &reo_unk_vtbl;
4621 reo->IRichEditOle_iface.lpVtbl = &revt;
4622 reo->ITextDocument_iface.lpVtbl = &tdvt;
4623 reo->ref = 1;
4624 reo->editor = editor;
4625 reo->txtSel = CreateTextSelection(reo);
4626 if (!reo->txtSel)
4628 heap_free(reo);
4629 return 0;
4631 reo->clientSite = CreateOleClientSite(reo);
4632 if (!reo->clientSite)
4634 ITextSelection_Release(&reo->txtSel->ITextSelection_iface);
4635 heap_free(reo);
4636 return 0;
4638 TRACE("Created %p\n",reo);
4639 list_init(&reo->rangelist);
4640 if (outer_unk)
4641 reo->outer_unk = outer_unk;
4642 else
4643 reo->outer_unk = &reo->IUnknown_inner;
4644 *ppvObj = &reo->IRichEditOle_iface;
4646 return 1;
4649 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
4651 /* sizel is in .01 millimeters, sz in pixels */
4652 sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
4653 sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
4656 /******************************************************************************
4657 * ME_GetOLEObjectSize
4659 * Sets run extent for OLE objects.
4661 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
4663 IDataObject* ido;
4664 FORMATETC fmt;
4665 STGMEDIUM stgm;
4666 DIBSECTION dibsect;
4667 ENHMETAHEADER emh;
4669 assert(run->nFlags & MERF_GRAPHICS);
4670 assert(run->ole_obj);
4672 if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
4674 convert_sizel(c, &run->ole_obj->sizel, pSize);
4675 if (c->editor->nZoomNumerator != 0)
4677 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4678 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4680 return;
4683 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
4685 FIXME("Query Interface IID_IDataObject failed!\n");
4686 pSize->cx = pSize->cy = 0;
4687 return;
4689 fmt.cfFormat = CF_BITMAP;
4690 fmt.ptd = NULL;
4691 fmt.dwAspect = DVASPECT_CONTENT;
4692 fmt.lindex = -1;
4693 fmt.tymed = TYMED_GDI;
4694 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4696 fmt.cfFormat = CF_ENHMETAFILE;
4697 fmt.tymed = TYMED_ENHMF;
4698 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4700 FIXME("unsupported format\n");
4701 pSize->cx = pSize->cy = 0;
4702 IDataObject_Release(ido);
4703 return;
4707 switch (stgm.tymed)
4709 case TYMED_GDI:
4710 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
4711 pSize->cx = dibsect.dsBm.bmWidth;
4712 pSize->cy = dibsect.dsBm.bmHeight;
4713 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
4714 break;
4715 case TYMED_ENHMF:
4716 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
4717 pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
4718 pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
4719 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
4720 break;
4721 default:
4722 FIXME("Unsupported tymed %d\n", stgm.tymed);
4723 break;
4725 IDataObject_Release(ido);
4726 if (c->editor->nZoomNumerator != 0)
4728 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4729 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4733 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
4734 ME_Paragraph *para, BOOL selected)
4736 IDataObject* ido;
4737 FORMATETC fmt;
4738 STGMEDIUM stgm;
4739 DIBSECTION dibsect;
4740 ENHMETAHEADER emh;
4741 HDC hMemDC;
4742 SIZE sz;
4743 BOOL has_size;
4745 assert(run->nFlags & MERF_GRAPHICS);
4746 assert(run->ole_obj);
4747 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
4749 FIXME("Couldn't get interface\n");
4750 return;
4752 has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
4753 fmt.cfFormat = CF_BITMAP;
4754 fmt.ptd = NULL;
4755 fmt.dwAspect = DVASPECT_CONTENT;
4756 fmt.lindex = -1;
4757 fmt.tymed = TYMED_GDI;
4758 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4760 fmt.cfFormat = CF_ENHMETAFILE;
4761 fmt.tymed = TYMED_ENHMF;
4762 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
4764 FIXME("Couldn't get storage medium\n");
4765 IDataObject_Release(ido);
4766 return;
4769 switch (stgm.tymed)
4771 case TYMED_GDI:
4772 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
4773 hMemDC = CreateCompatibleDC(c->hDC);
4774 SelectObject(hMemDC, stgm.u.hBitmap);
4775 if (has_size)
4777 convert_sizel(c, &run->ole_obj->sizel, &sz);
4778 } else {
4779 sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
4780 sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
4782 if (c->editor->nZoomNumerator != 0)
4784 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4785 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4787 if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
4789 BitBlt(c->hDC, x, y - sz.cy,
4790 dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
4791 hMemDC, 0, 0, SRCCOPY);
4792 } else {
4793 StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
4794 hMemDC, 0, 0, dibsect.dsBm.bmWidth,
4795 dibsect.dsBm.bmHeight, SRCCOPY);
4797 DeleteDC(hMemDC);
4798 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
4799 break;
4800 case TYMED_ENHMF:
4801 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
4802 if (has_size)
4804 convert_sizel(c, &run->ole_obj->sizel, &sz);
4805 } else {
4806 sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
4807 sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
4809 if (c->editor->nZoomNumerator != 0)
4811 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4812 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
4816 RECT rc;
4818 rc.left = x;
4819 rc.top = y - sz.cy;
4820 rc.right = x + sz.cx;
4821 rc.bottom = y;
4822 PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
4824 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
4825 break;
4826 default:
4827 FIXME("Unsupported tymed %d\n", stgm.tymed);
4828 selected = FALSE;
4829 break;
4831 if (selected && !c->editor->bHideSelection)
4832 PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
4833 IDataObject_Release(ido);
4836 void ME_DeleteReObject(REOBJECT* reo)
4838 if (reo->poleobj) IOleObject_Release(reo->poleobj);
4839 if (reo->pstg) IStorage_Release(reo->pstg);
4840 if (reo->polesite) IOleClientSite_Release(reo->polesite);
4841 FREE_OBJ(reo);
4844 void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
4846 *dst = *src;
4848 if (dst->poleobj) IOleObject_AddRef(dst->poleobj);
4849 if (dst->pstg) IStorage_AddRef(dst->pstg);
4850 if (dst->polesite) IOleClientSite_AddRef(dst->polesite);
4853 void ME_GetITextDocumentInterface(IRichEditOle *iface, LPVOID *ppvObj)
4855 IRichEditOleImpl *This = impl_from_IRichEditOle(iface);
4856 *ppvObj = &This->ITextDocument_iface;