xactengine3_0: New DLL.
[wine.git] / dlls / riched20 / richole.c
blob7c281ab364ecac80d811759afdeaef24fb5b70c8
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_ITextDocument2Old, 0x01c25500, 0x4268, 0x11d1, 0x88, 0x3a, 0x3c, 0x8b, 0x00, 0xc1, 0x00, 0x00);
50 DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
51 DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
52 DEFINE_GUID(IID_ITextFont, 0x8cc497c3, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
53 DEFINE_GUID(IID_ITextPara, 0x8cc497c4, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
55 static ITypeLib *typelib;
57 enum tid_t {
58 NULL_tid,
59 ITextDocument_tid,
60 ITextRange_tid,
61 ITextSelection_tid,
62 ITextFont_tid,
63 ITextPara_tid,
64 LAST_tid
67 static const IID * const tid_ids[] =
69 &IID_NULL,
70 &IID_ITextDocument,
71 &IID_ITextRange,
72 &IID_ITextSelection,
73 &IID_ITextFont,
74 &IID_ITextPara,
76 static ITypeInfo *typeinfos[LAST_tid];
78 static HRESULT load_typelib(void)
80 ITypeLib *tl;
81 HRESULT hr;
83 hr = LoadRegTypeLib(&LIBID_tom, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
84 if (FAILED(hr)) {
85 ERR("LoadRegTypeLib failed: %08x\n", hr);
86 return hr;
89 if (InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
90 ITypeLib_Release(tl);
91 return hr;
94 void release_typelib(void)
96 unsigned i;
98 if (!typelib)
99 return;
101 for (i = 0; i < ARRAY_SIZE(typeinfos); i++)
102 if (typeinfos[i])
103 ITypeInfo_Release(typeinfos[i]);
105 ITypeLib_Release(typelib);
108 static HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo)
110 HRESULT hr;
112 if (!typelib)
113 hr = load_typelib();
114 if (!typelib)
115 return hr;
117 if (!typeinfos[tid])
119 ITypeInfo *ti;
121 hr = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
122 if (FAILED(hr))
124 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hr);
125 return hr;
128 if (InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
129 ITypeInfo_Release(ti);
132 *typeinfo = typeinfos[tid];
133 return S_OK;
136 /* private IID used to get back IRichEditOleImpl pointer */
137 DEFINE_GUID(IID_Igetrichole, 0xe3ce5c7a, 0x8247, 0x4622, 0x81, 0xad, 0x11, 0x81, 0x02, 0xaa, 0x01, 0x30);
139 typedef struct ITextSelectionImpl ITextSelectionImpl;
140 typedef struct IOleClientSiteImpl IOleClientSiteImpl;
141 typedef struct ITextRangeImpl ITextRangeImpl;
143 enum textfont_prop_id {
144 FONT_ALLCAPS = 0,
145 FONT_ANIMATION,
146 FONT_BACKCOLOR,
147 FONT_BOLD,
148 FONT_EMBOSS,
149 FONT_FORECOLOR,
150 FONT_HIDDEN,
151 FONT_ENGRAVE,
152 FONT_ITALIC,
153 FONT_KERNING,
154 FONT_LANGID,
155 FONT_NAME,
156 FONT_OUTLINE,
157 FONT_POSITION,
158 FONT_PROTECTED,
159 FONT_SHADOW,
160 FONT_SIZE,
161 FONT_SMALLCAPS,
162 FONT_SPACING,
163 FONT_STRIKETHROUGH,
164 FONT_SUBSCRIPT,
165 FONT_SUPERSCRIPT,
166 FONT_UNDERLINE,
167 FONT_WEIGHT,
168 FONT_PROPID_LAST,
169 FONT_PROPID_FIRST = FONT_ALLCAPS
172 static const DWORD textfont_prop_masks[][2] = {
173 { CFM_ALLCAPS, CFE_ALLCAPS },
174 { CFM_ANIMATION },
175 { CFM_BACKCOLOR, CFE_AUTOBACKCOLOR },
176 { CFM_BOLD, CFE_BOLD },
177 { CFM_EMBOSS, CFE_EMBOSS },
178 { CFM_COLOR, CFE_AUTOCOLOR },
179 { CFM_HIDDEN, CFE_HIDDEN },
180 { CFM_IMPRINT, CFE_IMPRINT },
181 { CFM_ITALIC, CFE_ITALIC },
182 { CFM_KERNING },
183 { CFM_LCID },
184 { CFM_FACE },
185 { CFM_OUTLINE, CFE_OUTLINE },
186 { CFM_OFFSET },
187 { CFM_PROTECTED, CFE_PROTECTED },
188 { CFM_SHADOW, CFE_SHADOW },
189 { CFM_SIZE },
190 { CFM_SMALLCAPS, CFE_SMALLCAPS },
191 { CFM_SPACING },
192 { CFM_STRIKEOUT, CFE_STRIKEOUT },
193 { CFM_SUBSCRIPT, CFE_SUBSCRIPT },
194 { CFM_SUPERSCRIPT, CFE_SUPERSCRIPT },
195 { CFM_UNDERLINE, CFE_UNDERLINE },
196 { CFM_WEIGHT }
199 typedef union {
200 FLOAT f;
201 LONG l;
202 BSTR str;
203 } textfont_prop_val;
205 enum range_update_op {
206 RANGE_UPDATE_DELETE
209 typedef struct IRichEditOleImpl {
210 IUnknown IUnknown_inner;
211 IRichEditOle IRichEditOle_iface;
212 ITextDocument2Old ITextDocument2Old_iface;
213 IUnknown *outer_unk;
214 LONG ref;
216 ME_TextEditor *editor;
217 ITextSelectionImpl *txtSel;
219 struct list rangelist;
220 struct list clientsites;
221 } IRichEditOleImpl;
223 struct reole_child {
224 struct list entry;
225 IRichEditOleImpl *reole;
228 struct ITextRangeImpl {
229 struct reole_child child;
230 ITextRange ITextRange_iface;
231 LONG ref;
232 LONG start, end;
235 struct ITextSelectionImpl {
236 ITextSelection ITextSelection_iface;
237 LONG ref;
239 IRichEditOleImpl *reOle;
242 typedef struct ITextFontImpl {
243 ITextFont ITextFont_iface;
244 LONG ref;
246 ITextRange *range;
247 textfont_prop_val props[FONT_PROPID_LAST];
248 BOOL get_cache_enabled;
249 BOOL set_cache_enabled;
250 } ITextFontImpl;
252 typedef struct ITextParaImpl {
253 ITextPara ITextPara_iface;
254 LONG ref;
256 ITextRange *range;
257 } ITextParaImpl;
259 struct IOleClientSiteImpl {
260 struct reole_child child;
261 IOleClientSite IOleClientSite_iface;
262 IOleInPlaceSite IOleInPlaceSite_iface;
263 LONG ref;
266 static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
268 return CONTAINING_RECORD(iface, IRichEditOleImpl, IRichEditOle_iface);
271 static inline IRichEditOleImpl *impl_from_ITextDocument2Old(ITextDocument2Old *iface)
273 return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument2Old_iface);
276 static inline IRichEditOleImpl *impl_from_IUnknown(IUnknown *iface)
278 return CONTAINING_RECORD(iface, IRichEditOleImpl, IUnknown_inner);
281 static inline IOleClientSiteImpl *impl_from_IOleInPlaceSite(IOleInPlaceSite *iface)
283 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleInPlaceSite_iface);
286 static inline ITextRangeImpl *impl_from_ITextRange(ITextRange *iface)
288 return CONTAINING_RECORD(iface, ITextRangeImpl, ITextRange_iface);
291 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
293 return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
296 static inline ITextFontImpl *impl_from_ITextFont(ITextFont *iface)
298 return CONTAINING_RECORD(iface, ITextFontImpl, ITextFont_iface);
301 static inline ITextParaImpl *impl_from_ITextPara(ITextPara *iface)
303 return CONTAINING_RECORD(iface, ITextParaImpl, ITextPara_iface);
306 static HRESULT create_textfont(ITextRange*, const ITextFontImpl*, ITextFont**);
307 static HRESULT create_textpara(ITextRange*, ITextPara**);
308 static ITextSelectionImpl *CreateTextSelection(IRichEditOleImpl*);
310 static HRESULT textrange_get_storylength(ME_TextEditor *editor, LONG *length)
312 if (!length)
313 return E_INVALIDARG;
315 *length = ME_GetTextLength(editor) + 1;
316 return S_OK;
319 static void textranges_update_ranges(IRichEditOleImpl *reole, LONG start, LONG end, enum range_update_op op)
321 ITextRangeImpl *range;
323 LIST_FOR_EACH_ENTRY(range, &reole->rangelist, ITextRangeImpl, child.entry) {
324 switch (op)
326 case RANGE_UPDATE_DELETE:
327 /* range fully covered by deleted range - collapse to insertion point */
328 if (range->start >= start && range->end <= end)
329 range->start = range->end = start;
330 /* deleted range cuts from the right */
331 else if (range->start < start && range->end <= end)
332 range->end = start;
333 /* deleted range cuts from the left */
334 else if (range->start >= start && range->end > end) {
335 range->start = start;
336 range->end -= end - start;
338 /* deleted range cuts within */
339 else
340 range->end -= end - start;
341 break;
342 default:
343 FIXME("unknown update op, %d\n", op);
348 static inline BOOL is_equal_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *left,
349 textfont_prop_val *right)
351 switch (propid)
353 case FONT_ALLCAPS:
354 case FONT_ANIMATION:
355 case FONT_BACKCOLOR:
356 case FONT_BOLD:
357 case FONT_EMBOSS:
358 case FONT_FORECOLOR:
359 case FONT_HIDDEN:
360 case FONT_ENGRAVE:
361 case FONT_ITALIC:
362 case FONT_KERNING:
363 case FONT_LANGID:
364 case FONT_OUTLINE:
365 case FONT_PROTECTED:
366 case FONT_SHADOW:
367 case FONT_SMALLCAPS:
368 case FONT_STRIKETHROUGH:
369 case FONT_SUBSCRIPT:
370 case FONT_SUPERSCRIPT:
371 case FONT_UNDERLINE:
372 case FONT_WEIGHT:
373 return left->l == right->l;
374 case FONT_NAME:
375 return !wcscmp(left->str, right->str);
376 case FONT_POSITION:
377 case FONT_SIZE:
378 case FONT_SPACING:
379 return left->f == right->f;
380 default:
381 FIXME("unhandled font property %d\n", propid);
382 return FALSE;
386 static inline void init_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *v)
388 switch (propid)
390 case FONT_ALLCAPS:
391 case FONT_ANIMATION:
392 case FONT_BACKCOLOR:
393 case FONT_BOLD:
394 case FONT_EMBOSS:
395 case FONT_FORECOLOR:
396 case FONT_HIDDEN:
397 case FONT_ENGRAVE:
398 case FONT_ITALIC:
399 case FONT_KERNING:
400 case FONT_LANGID:
401 case FONT_OUTLINE:
402 case FONT_PROTECTED:
403 case FONT_SHADOW:
404 case FONT_SMALLCAPS:
405 case FONT_STRIKETHROUGH:
406 case FONT_SUBSCRIPT:
407 case FONT_SUPERSCRIPT:
408 case FONT_UNDERLINE:
409 case FONT_WEIGHT:
410 v->l = tomUndefined;
411 return;
412 case FONT_NAME:
413 v->str = NULL;
414 return;
415 case FONT_POSITION:
416 case FONT_SIZE:
417 case FONT_SPACING:
418 v->f = tomUndefined;
419 return;
420 default:
421 FIXME("unhandled font property %d\n", propid);
422 v->l = tomUndefined;
423 return;
427 static inline FLOAT twips_to_points(LONG value)
429 return value * 72.0 / 1440;
432 static inline FLOAT points_to_twips(FLOAT value)
434 return value * 1440 / 72.0;
437 static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid,
438 textfont_prop_val *value)
440 ME_Cursor from, to;
441 CHARFORMAT2W fmt;
443 memset(&fmt, 0, sizeof(fmt));
444 fmt.cbSize = sizeof(fmt);
445 fmt.dwMask = textfont_prop_masks[propid][0];
447 ME_CursorFromCharOfs(reole->editor, pos, &from);
448 to = from;
449 ME_MoveCursorChars(reole->editor, &to, 1, FALSE);
450 ME_GetCharFormat(reole->editor, &from, &to, &fmt);
452 switch (propid)
454 case FONT_ALLCAPS:
455 case FONT_BOLD:
456 case FONT_EMBOSS:
457 case FONT_HIDDEN:
458 case FONT_ENGRAVE:
459 case FONT_ITALIC:
460 case FONT_OUTLINE:
461 case FONT_PROTECTED:
462 case FONT_SHADOW:
463 case FONT_SMALLCAPS:
464 case FONT_STRIKETHROUGH:
465 case FONT_SUBSCRIPT:
466 case FONT_SUPERSCRIPT:
467 case FONT_UNDERLINE:
468 value->l = fmt.dwEffects & textfont_prop_masks[propid][1] ? tomTrue : tomFalse;
469 break;
470 case FONT_ANIMATION:
471 value->l = fmt.bAnimation;
472 break;
473 case FONT_BACKCOLOR:
474 value->l = fmt.dwEffects & CFE_AUTOBACKCOLOR ? GetSysColor(COLOR_WINDOW) : fmt.crBackColor;
475 break;
476 case FONT_FORECOLOR:
477 value->l = fmt.dwEffects & CFE_AUTOCOLOR ? GetSysColor(COLOR_WINDOWTEXT) : fmt.crTextColor;
478 break;
479 case FONT_KERNING:
480 value->f = twips_to_points(fmt.wKerning);
481 break;
482 case FONT_LANGID:
483 value->l = fmt.lcid;
484 break;
485 case FONT_NAME:
486 /* this case is used exclusively by GetName() */
487 value->str = SysAllocString(fmt.szFaceName);
488 if (!value->str)
489 return E_OUTOFMEMORY;
490 break;
491 case FONT_POSITION:
492 value->f = twips_to_points(fmt.yOffset);
493 break;
494 case FONT_SIZE:
495 value->f = twips_to_points(fmt.yHeight);
496 break;
497 case FONT_SPACING:
498 value->f = fmt.sSpacing;
499 break;
500 case FONT_WEIGHT:
501 value->l = fmt.wWeight;
502 break;
503 default:
504 FIXME("unhandled font property %d\n", propid);
505 return E_FAIL;
508 return S_OK;
511 static inline const IRichEditOleImpl *get_range_reole(ITextRange *range)
513 IRichEditOleImpl *reole = NULL;
514 ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&reole);
515 return reole;
518 static void textrange_set_font(ITextRange *range, ITextFont *font)
520 CHARFORMAT2W fmt;
521 HRESULT hr;
522 LONG value;
523 BSTR str;
524 FLOAT f;
526 #define CHARFORMAT_SET_B_FIELD(mask, value) \
527 if (hr == S_OK && value != tomUndefined) { \
528 fmt.dwMask |= CFM_##mask; \
529 if (value == tomTrue) fmt.dwEffects |= CFE_##mask; \
532 /* fill format data from font */
533 memset(&fmt, 0, sizeof(fmt));
534 fmt.cbSize = sizeof(fmt);
536 value = tomUndefined;
537 hr = ITextFont_GetAllCaps(font, &value);
538 CHARFORMAT_SET_B_FIELD(ALLCAPS, value);
540 value = tomUndefined;
541 hr = ITextFont_GetBold(font, &value);
542 CHARFORMAT_SET_B_FIELD(BOLD, value);
544 value = tomUndefined;
545 hr = ITextFont_GetEmboss(font, &value);
546 CHARFORMAT_SET_B_FIELD(EMBOSS, value);
548 value = tomUndefined;
549 hr = ITextFont_GetHidden(font, &value);
550 CHARFORMAT_SET_B_FIELD(HIDDEN, value);
552 value = tomUndefined;
553 hr = ITextFont_GetEngrave(font, &value);
554 CHARFORMAT_SET_B_FIELD(IMPRINT, value);
556 value = tomUndefined;
557 hr = ITextFont_GetItalic(font, &value);
558 CHARFORMAT_SET_B_FIELD(ITALIC, value);
560 value = tomUndefined;
561 hr = ITextFont_GetOutline(font, &value);
562 CHARFORMAT_SET_B_FIELD(OUTLINE, value);
564 value = tomUndefined;
565 hr = ITextFont_GetProtected(font, &value);
566 CHARFORMAT_SET_B_FIELD(PROTECTED, value);
568 value = tomUndefined;
569 hr = ITextFont_GetShadow(font, &value);
570 CHARFORMAT_SET_B_FIELD(SHADOW, value);
572 value = tomUndefined;
573 hr = ITextFont_GetSmallCaps(font, &value);
574 CHARFORMAT_SET_B_FIELD(SMALLCAPS, value);
576 value = tomUndefined;
577 hr = ITextFont_GetStrikeThrough(font, &value);
578 CHARFORMAT_SET_B_FIELD(STRIKEOUT, value);
580 value = tomUndefined;
581 hr = ITextFont_GetSubscript(font, &value);
582 CHARFORMAT_SET_B_FIELD(SUBSCRIPT, value);
584 value = tomUndefined;
585 hr = ITextFont_GetSuperscript(font, &value);
586 CHARFORMAT_SET_B_FIELD(SUPERSCRIPT, value);
588 value = tomUndefined;
589 hr = ITextFont_GetUnderline(font, &value);
590 CHARFORMAT_SET_B_FIELD(UNDERLINE, value);
592 #undef CHARFORMAT_SET_B_FIELD
594 value = tomUndefined;
595 hr = ITextFont_GetAnimation(font, &value);
596 if (hr == S_OK && value != tomUndefined) {
597 fmt.dwMask |= CFM_ANIMATION;
598 fmt.bAnimation = value;
601 value = tomUndefined;
602 hr = ITextFont_GetBackColor(font, &value);
603 if (hr == S_OK && value != tomUndefined) {
604 fmt.dwMask |= CFM_BACKCOLOR;
605 if (value == tomAutoColor)
606 fmt.dwEffects |= CFE_AUTOBACKCOLOR;
607 else
608 fmt.crBackColor = value;
611 value = tomUndefined;
612 hr = ITextFont_GetForeColor(font, &value);
613 if (hr == S_OK && value != tomUndefined) {
614 fmt.dwMask |= CFM_COLOR;
615 if (value == tomAutoColor)
616 fmt.dwEffects |= CFE_AUTOCOLOR;
617 else
618 fmt.crTextColor = value;
621 value = tomUndefined;
622 hr = ITextFont_GetKerning(font, &f);
623 if (hr == S_OK && f != tomUndefined) {
624 fmt.dwMask |= CFM_KERNING;
625 fmt.wKerning = points_to_twips(f);
628 value = tomUndefined;
629 hr = ITextFont_GetLanguageID(font, &value);
630 if (hr == S_OK && value != tomUndefined) {
631 fmt.dwMask |= CFM_LCID;
632 fmt.lcid = value;
635 if (ITextFont_GetName(font, &str) == S_OK) {
636 fmt.dwMask |= CFM_FACE;
637 lstrcpynW(fmt.szFaceName, str, ARRAY_SIZE(fmt.szFaceName));
638 SysFreeString(str);
641 hr = ITextFont_GetPosition(font, &f);
642 if (hr == S_OK && f != tomUndefined) {
643 fmt.dwMask |= CFM_OFFSET;
644 fmt.yOffset = points_to_twips(f);
647 hr = ITextFont_GetSize(font, &f);
648 if (hr == S_OK && f != tomUndefined) {
649 fmt.dwMask |= CFM_SIZE;
650 fmt.yHeight = points_to_twips(f);
653 hr = ITextFont_GetSpacing(font, &f);
654 if (hr == S_OK && f != tomUndefined) {
655 fmt.dwMask |= CFM_SPACING;
656 fmt.sSpacing = f;
659 hr = ITextFont_GetWeight(font, &value);
660 if (hr == S_OK && value != tomUndefined) {
661 fmt.dwMask |= CFM_WEIGHT;
662 fmt.wWeight = value;
665 if (fmt.dwMask) {
666 const IRichEditOleImpl *reole = get_range_reole(range);
667 ME_Cursor from, to;
668 LONG start, end;
670 ITextRange_GetStart(range, &start);
671 ITextRange_GetEnd(range, &end);
673 ME_CursorFromCharOfs(reole->editor, start, &from);
674 ME_CursorFromCharOfs(reole->editor, end, &to);
675 ME_SetCharFormat(reole->editor, &from, &to, &fmt);
679 static HRESULT get_textfont_prop(const ITextFontImpl *font, enum textfont_prop_id propid, textfont_prop_val *value)
681 const IRichEditOleImpl *reole;
682 textfont_prop_val v;
683 LONG start, end, i;
684 HRESULT hr;
686 /* when font is not attached to any range use cached values */
687 if (!font->range || font->get_cache_enabled) {
688 *value = font->props[propid];
689 return S_OK;
692 if (!(reole = get_range_reole(font->range)))
693 return CO_E_RELEASED;
695 init_textfont_prop_value(propid, value);
697 ITextRange_GetStart(font->range, &start);
698 ITextRange_GetEnd(font->range, &end);
700 /* iterate trough a range to see if property value is consistent */
701 hr = get_textfont_prop_for_pos(reole, start, propid, &v);
702 if (FAILED(hr))
703 return hr;
705 for (i = start + 1; i < end; i++) {
706 textfont_prop_val cur;
708 hr = get_textfont_prop_for_pos(reole, i, propid, &cur);
709 if (FAILED(hr))
710 return hr;
712 if (!is_equal_textfont_prop_value(propid, &v, &cur))
713 return S_OK;
716 *value = v;
717 return S_OK;
720 static HRESULT get_textfont_propf(const ITextFontImpl *font, enum textfont_prop_id propid, FLOAT *value)
722 textfont_prop_val v;
723 HRESULT hr;
725 if (!value)
726 return E_INVALIDARG;
728 hr = get_textfont_prop(font, propid, &v);
729 *value = v.f;
730 return hr;
733 static HRESULT get_textfont_propl(const ITextFontImpl *font, enum textfont_prop_id propid, LONG *value)
735 textfont_prop_val v;
736 HRESULT hr;
738 if (!value)
739 return E_INVALIDARG;
741 hr = get_textfont_prop(font, propid, &v);
742 *value = v.l;
743 return hr;
746 /* Value should already have a terminal value, for boolean properties it means tomToggle is not handled */
747 static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id propid, const textfont_prop_val *value)
749 const IRichEditOleImpl *reole;
750 ME_Cursor from, to;
751 CHARFORMAT2W fmt;
752 LONG start, end;
754 /* when font is not attached to any range use cache */
755 if (!font->range || font->set_cache_enabled) {
756 if (propid == FONT_NAME) {
757 SysFreeString(font->props[propid].str);
758 font->props[propid].str = SysAllocString(value->str);
760 else
761 font->props[propid] = *value;
762 return S_OK;
765 if (!(reole = get_range_reole(font->range)))
766 return CO_E_RELEASED;
768 memset(&fmt, 0, sizeof(fmt));
769 fmt.cbSize = sizeof(fmt);
770 fmt.dwMask = textfont_prop_masks[propid][0];
772 switch (propid)
774 case FONT_ALLCAPS:
775 case FONT_BOLD:
776 case FONT_EMBOSS:
777 case FONT_HIDDEN:
778 case FONT_ENGRAVE:
779 case FONT_ITALIC:
780 case FONT_OUTLINE:
781 case FONT_PROTECTED:
782 case FONT_SHADOW:
783 case FONT_SMALLCAPS:
784 case FONT_STRIKETHROUGH:
785 case FONT_SUBSCRIPT:
786 case FONT_SUPERSCRIPT:
787 case FONT_UNDERLINE:
788 fmt.dwEffects = value->l == tomTrue ? textfont_prop_masks[propid][1] : 0;
789 break;
790 case FONT_ANIMATION:
791 fmt.bAnimation = value->l;
792 break;
793 case FONT_BACKCOLOR:
794 case FONT_FORECOLOR:
795 if (value->l == tomAutoColor)
796 fmt.dwEffects = textfont_prop_masks[propid][1];
797 else if (propid == FONT_BACKCOLOR)
798 fmt.crBackColor = value->l;
799 else
800 fmt.crTextColor = value->l;
801 break;
802 case FONT_KERNING:
803 fmt.wKerning = value->f;
804 break;
805 case FONT_LANGID:
806 fmt.lcid = value->l;
807 break;
808 case FONT_POSITION:
809 fmt.yOffset = value->f;
810 break;
811 case FONT_SIZE:
812 fmt.yHeight = value->f;
813 break;
814 case FONT_SPACING:
815 fmt.sSpacing = value->f;
816 break;
817 case FONT_WEIGHT:
818 fmt.wWeight = value->l;
819 break;
820 case FONT_NAME:
821 lstrcpynW(fmt.szFaceName, value->str, ARRAY_SIZE(fmt.szFaceName));
822 break;
823 default:
824 FIXME("unhandled font property %d\n", propid);
825 return E_FAIL;
828 ITextRange_GetStart(font->range, &start);
829 ITextRange_GetEnd(font->range, &end);
831 ME_CursorFromCharOfs(reole->editor, start, &from);
832 ME_CursorFromCharOfs(reole->editor, end, &to);
833 ME_SetCharFormat(reole->editor, &from, &to, &fmt);
835 return S_OK;
838 static inline HRESULT set_textfont_propl(ITextFontImpl *font, enum textfont_prop_id propid, LONG value)
840 textfont_prop_val v;
841 v.l = value;
842 return set_textfont_prop(font, propid, &v);
845 static inline HRESULT set_textfont_propf(ITextFontImpl *font, enum textfont_prop_id propid, FLOAT value)
847 textfont_prop_val v;
848 v.f = value;
849 return set_textfont_prop(font, propid, &v);
852 static HRESULT set_textfont_propd(ITextFontImpl *font, enum textfont_prop_id propid, LONG value)
854 textfont_prop_val v;
856 switch (value)
858 case tomUndefined:
859 return S_OK;
860 case tomToggle: {
861 LONG oldvalue;
862 get_textfont_propl(font, propid, &oldvalue);
863 if (oldvalue == tomFalse)
864 value = tomTrue;
865 else if (oldvalue == tomTrue)
866 value = tomFalse;
867 else
868 return E_INVALIDARG;
869 /* fallthrough */
871 case tomTrue:
872 case tomFalse:
873 v.l = value;
874 return set_textfont_prop(font, propid, &v);
875 default:
876 return E_INVALIDARG;
880 static HRESULT textfont_getname_from_range(ITextRange *range, BSTR *ret)
882 const IRichEditOleImpl *reole;
883 textfont_prop_val v;
884 HRESULT hr;
885 LONG start;
887 if (!(reole = get_range_reole(range)))
888 return CO_E_RELEASED;
890 ITextRange_GetStart(range, &start);
891 hr = get_textfont_prop_for_pos(reole, start, FONT_NAME, &v);
892 *ret = v.str;
893 return hr;
896 static void textfont_cache_range_props(ITextFontImpl *font)
898 enum textfont_prop_id propid;
899 for (propid = FONT_PROPID_FIRST; propid < FONT_PROPID_LAST; propid++) {
900 if (propid == FONT_NAME)
901 textfont_getname_from_range(font->range, &font->props[propid].str);
902 else
903 get_textfont_prop(font, propid, &font->props[propid]);
907 static HRESULT textrange_expand(ITextRange *range, LONG unit, LONG *delta)
909 LONG expand_start, expand_end;
911 switch (unit)
913 case tomStory:
914 expand_start = 0;
915 ITextRange_GetStoryLength(range, &expand_end);
916 break;
917 default:
918 FIXME("unit %d is not supported\n", unit);
919 return E_NOTIMPL;
922 if (delta) {
923 LONG start, end;
925 ITextRange_GetStart(range, &start);
926 ITextRange_GetEnd(range, &end);
927 *delta = expand_end - expand_start - (end - start);
930 ITextRange_SetStart(range, expand_start);
931 ITextRange_SetEnd(range, expand_end);
933 return S_OK;
936 static HRESULT WINAPI IRichEditOleImpl_inner_fnQueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppvObj)
938 IRichEditOleImpl *This = impl_from_IUnknown(iface);
940 TRACE("%p %s\n", This, debugstr_guid(riid));
942 *ppvObj = NULL;
943 if (IsEqualGUID(riid, &IID_IUnknown))
944 *ppvObj = &This->IUnknown_inner;
945 else if (IsEqualGUID(riid, &IID_IRichEditOle))
946 *ppvObj = &This->IRichEditOle_iface;
947 else if (IsEqualGUID(riid, &IID_ITextDocument) || IsEqualGUID(riid, &IID_ITextDocument2Old))
948 *ppvObj = &This->ITextDocument2Old_iface;
949 if (*ppvObj)
951 IUnknown_AddRef((IUnknown *)*ppvObj);
952 return S_OK;
954 FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid));
956 return E_NOINTERFACE;
959 static ULONG WINAPI IRichEditOleImpl_inner_fnAddRef(IUnknown *iface)
961 IRichEditOleImpl *This = impl_from_IUnknown(iface);
962 ULONG ref = InterlockedIncrement(&This->ref);
964 TRACE("%p ref = %u\n", This, ref);
966 return ref;
969 static ULONG WINAPI IRichEditOleImpl_inner_fnRelease(IUnknown *iface)
971 IRichEditOleImpl *This = impl_from_IUnknown(iface);
972 ULONG ref = InterlockedDecrement(&This->ref);
974 TRACE ("%p ref=%u\n", This, ref);
976 if (!ref)
978 IOleClientSiteImpl *clientsite;
979 ITextRangeImpl *txtRge;
981 This->editor->reOle = NULL;
982 if (This->txtSel) {
983 This->txtSel->reOle = NULL;
984 ITextSelection_Release(&This->txtSel->ITextSelection_iface);
987 LIST_FOR_EACH_ENTRY(txtRge, &This->rangelist, ITextRangeImpl, child.entry)
988 txtRge->child.reole = NULL;
990 LIST_FOR_EACH_ENTRY(clientsite, &This->clientsites, IOleClientSiteImpl, child.entry)
991 clientsite->child.reole = NULL;
993 heap_free(This);
995 return ref;
998 static const IUnknownVtbl reo_unk_vtbl =
1000 IRichEditOleImpl_inner_fnQueryInterface,
1001 IRichEditOleImpl_inner_fnAddRef,
1002 IRichEditOleImpl_inner_fnRelease
1005 static HRESULT WINAPI
1006 IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
1008 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1009 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1012 static ULONG WINAPI
1013 IRichEditOle_fnAddRef(IRichEditOle *me)
1015 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1016 return IUnknown_AddRef(This->outer_unk);
1019 static ULONG WINAPI
1020 IRichEditOle_fnRelease(IRichEditOle *me)
1022 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1023 return IUnknown_Release(This->outer_unk);
1026 static HRESULT WINAPI
1027 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
1029 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1030 FIXME("stub %p\n",This);
1031 return E_NOTIMPL;
1034 static HRESULT WINAPI
1035 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
1037 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1038 FIXME("stub %p\n",This);
1039 return E_NOTIMPL;
1042 static HRESULT WINAPI
1043 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
1044 REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
1046 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1047 FIXME("stub %p\n",This);
1048 return E_NOTIMPL;
1051 static inline IOleClientSiteImpl *impl_from_IOleClientSite(IOleClientSite *iface)
1053 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleClientSite_iface);
1056 static HRESULT WINAPI
1057 IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
1059 IOleClientSiteImpl *This = impl_from_IOleClientSite(me);
1060 TRACE("%p %s\n", me, debugstr_guid(riid) );
1062 *ppvObj = NULL;
1063 if (IsEqualGUID(riid, &IID_IUnknown) ||
1064 IsEqualGUID(riid, &IID_IOleClientSite))
1065 *ppvObj = me;
1066 else if (IsEqualGUID(riid, &IID_IOleWindow) ||
1067 IsEqualGUID(riid, &IID_IOleInPlaceSite))
1068 *ppvObj = &This->IOleInPlaceSite_iface;
1069 if (*ppvObj)
1071 IOleClientSite_AddRef(me);
1072 return S_OK;
1074 FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );
1076 return E_NOINTERFACE;
1079 static ULONG WINAPI IOleClientSite_fnAddRef(IOleClientSite *iface)
1081 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1082 ULONG ref = InterlockedIncrement(&This->ref);
1083 TRACE("(%p)->(%u)\n", This, ref);
1084 return ref;
1087 static ULONG WINAPI IOleClientSite_fnRelease(IOleClientSite *iface)
1089 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1090 ULONG ref = InterlockedDecrement(&This->ref);
1092 TRACE("(%p)->(%u)\n", This, ref);
1094 if (ref == 0) {
1095 if (This->child.reole) {
1096 list_remove(&This->child.entry);
1097 This->child.reole = NULL;
1099 heap_free(This);
1101 return ref;
1104 static HRESULT WINAPI IOleClientSite_fnSaveObject(IOleClientSite *iface)
1106 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1107 if (!This->child.reole)
1108 return CO_E_RELEASED;
1110 FIXME("stub %p\n", iface);
1111 return E_NOTIMPL;
1114 static HRESULT WINAPI IOleClientSite_fnGetMoniker(IOleClientSite *iface, DWORD dwAssign,
1115 DWORD dwWhichMoniker, IMoniker **ppmk)
1117 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1118 if (!This->child.reole)
1119 return CO_E_RELEASED;
1121 FIXME("stub %p\n", iface);
1122 return E_NOTIMPL;
1125 static HRESULT WINAPI IOleClientSite_fnGetContainer(IOleClientSite *iface,
1126 IOleContainer **ppContainer)
1128 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1129 if (!This->child.reole)
1130 return CO_E_RELEASED;
1132 FIXME("stub %p\n", iface);
1133 return E_NOTIMPL;
1136 static HRESULT WINAPI IOleClientSite_fnShowObject(IOleClientSite *iface)
1138 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1139 if (!This->child.reole)
1140 return CO_E_RELEASED;
1142 FIXME("stub %p\n", iface);
1143 return E_NOTIMPL;
1146 static HRESULT WINAPI IOleClientSite_fnOnShowWindow(IOleClientSite *iface, BOOL fShow)
1148 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1149 if (!This->child.reole)
1150 return CO_E_RELEASED;
1152 FIXME("stub %p\n", iface);
1153 return E_NOTIMPL;
1156 static HRESULT WINAPI IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *iface)
1158 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1159 if (!This->child.reole)
1160 return CO_E_RELEASED;
1162 FIXME("stub %p\n", iface);
1163 return E_NOTIMPL;
1166 static const IOleClientSiteVtbl ocst = {
1167 IOleClientSite_fnQueryInterface,
1168 IOleClientSite_fnAddRef,
1169 IOleClientSite_fnRelease,
1170 IOleClientSite_fnSaveObject,
1171 IOleClientSite_fnGetMoniker,
1172 IOleClientSite_fnGetContainer,
1173 IOleClientSite_fnShowObject,
1174 IOleClientSite_fnOnShowWindow,
1175 IOleClientSite_fnRequestNewObjectLayout
1178 /* IOleInPlaceSite interface */
1179 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnQueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppvObj)
1181 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1182 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppvObj);
1185 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnAddRef(IOleInPlaceSite *iface)
1187 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1188 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1191 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnRelease(IOleInPlaceSite *iface)
1193 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1194 return IOleClientSite_Release(&This->IOleClientSite_iface);
1197 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindow(IOleInPlaceSite *iface, HWND *phwnd)
1199 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1201 TRACE("(%p)->(%p)\n", This, phwnd);
1203 if (!This->child.reole)
1204 return CO_E_RELEASED;
1206 if (!phwnd)
1207 return E_INVALIDARG;
1209 *phwnd = This->child.reole->editor->hWnd;
1210 return S_OK;
1213 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1215 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1216 FIXME("not implemented: (%p)->(%d)\n", This, fEnterMode);
1217 return E_NOTIMPL;
1220 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnCanInPlaceActivate(IOleInPlaceSite *iface)
1222 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1223 FIXME("not implemented: (%p)\n", This);
1224 return E_NOTIMPL;
1227 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceActivate(IOleInPlaceSite *iface)
1229 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1230 FIXME("not implemented: (%p)\n", This);
1231 return E_NOTIMPL;
1234 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIActivate(IOleInPlaceSite *iface)
1236 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1237 FIXME("not implemented: (%p)\n", This);
1238 return E_NOTIMPL;
1241 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindowContext(IOleInPlaceSite *iface, IOleInPlaceFrame **ppFrame,
1242 IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1243 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1245 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1246 FIXME("not implemented: (%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
1247 return E_NOTIMPL;
1250 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnScroll(IOleInPlaceSite *iface, SIZE scrollExtent)
1252 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1253 FIXME("not implemented: (%p)\n", This);
1254 return E_NOTIMPL;
1257 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1259 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1260 FIXME("not implemented: (%p)->(%d)\n", This, fUndoable);
1261 return E_NOTIMPL;
1264 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceDeactivate(IOleInPlaceSite *iface)
1266 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1267 FIXME("not implemented: (%p)\n", This);
1268 return E_NOTIMPL;
1271 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDiscardUndoState(IOleInPlaceSite *iface)
1273 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1274 FIXME("not implemented: (%p)\n", This);
1275 return E_NOTIMPL;
1278 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDeactivateAndUndo(IOleInPlaceSite *iface)
1280 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1281 FIXME("not implemented: (%p)\n", This);
1282 return E_NOTIMPL;
1285 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1287 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1288 FIXME("not implemented: (%p)->(%p)\n", This, lprcPosRect);
1289 return E_NOTIMPL;
1292 static const IOleInPlaceSiteVtbl olestvt =
1294 IOleInPlaceSite_fnQueryInterface,
1295 IOleInPlaceSite_fnAddRef,
1296 IOleInPlaceSite_fnRelease,
1297 IOleInPlaceSite_fnGetWindow,
1298 IOleInPlaceSite_fnContextSensitiveHelp,
1299 IOleInPlaceSite_fnCanInPlaceActivate,
1300 IOleInPlaceSite_fnOnInPlaceActivate,
1301 IOleInPlaceSite_fnOnUIActivate,
1302 IOleInPlaceSite_fnGetWindowContext,
1303 IOleInPlaceSite_fnScroll,
1304 IOleInPlaceSite_fnOnUIDeactivate,
1305 IOleInPlaceSite_fnOnInPlaceDeactivate,
1306 IOleInPlaceSite_fnDiscardUndoState,
1307 IOleInPlaceSite_fnDeactivateAndUndo,
1308 IOleInPlaceSite_fnOnPosRectChange
1311 static HRESULT CreateOleClientSite(IRichEditOleImpl *reOle, IOleClientSite **ret)
1313 IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
1315 if (!clientSite)
1316 return E_OUTOFMEMORY;
1318 clientSite->IOleClientSite_iface.lpVtbl = &ocst;
1319 clientSite->IOleInPlaceSite_iface.lpVtbl = &olestvt;
1320 clientSite->ref = 1;
1321 clientSite->child.reole = reOle;
1322 list_add_head(&reOle->clientsites, &clientSite->child.entry);
1324 *ret = &clientSite->IOleClientSite_iface;
1325 return S_OK;
1328 static HRESULT WINAPI
1329 IRichEditOle_fnGetClientSite(IRichEditOle *me, IOleClientSite **clientsite)
1331 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1333 TRACE("(%p)->(%p)\n", This, clientsite);
1335 if (!clientsite)
1336 return E_INVALIDARG;
1338 return CreateOleClientSite(This, clientsite);
1341 static HRESULT WINAPI
1342 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
1343 DWORD reco, LPDATAOBJECT *lplpdataobj)
1345 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1346 ME_Cursor start;
1347 int nChars;
1349 TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
1350 if(!lplpdataobj)
1351 return E_INVALIDARG;
1352 if(!lpchrg) {
1353 int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
1354 start = This->editor->pCursors[nStartCur];
1355 nChars = nTo - nFrom;
1356 } else {
1357 ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
1358 nChars = lpchrg->cpMax - lpchrg->cpMin;
1360 return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
1363 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
1365 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1366 FIXME("stub %p\n",This);
1367 return E_NOTIMPL;
1370 static HRESULT WINAPI
1371 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
1372 REOBJECT *lpreobject, DWORD dwFlags)
1374 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1375 struct re_object *reobj = NULL;
1376 LONG count = 0;
1378 TRACE("(%p)->(%x, %p, %x)\n", This, iob, lpreobject, dwFlags);
1380 if (!lpreobject || !lpreobject->cbStruct)
1381 return E_INVALIDARG;
1383 if (iob == REO_IOB_USE_CP)
1385 ME_Cursor cursor;
1387 TRACE("character offset: %d\n", lpreobject->cp);
1388 ME_CursorFromCharOfs(This->editor, lpreobject->cp, &cursor);
1389 if (!cursor.pRun->member.run.reobj)
1390 return E_INVALIDARG;
1391 else
1392 reobj = cursor.pRun->member.run.reobj;
1394 else if (iob == REO_IOB_SELECTION)
1396 ME_Cursor *from, *to;
1398 ME_GetSelection(This->editor, &from, &to);
1399 if (!from->pRun->member.run.reobj)
1400 return E_INVALIDARG;
1401 else
1402 reobj = from->pRun->member.run.reobj;
1404 else
1406 if (iob > IRichEditOle_GetObjectCount(me))
1407 return E_INVALIDARG;
1408 LIST_FOR_EACH_ENTRY(reobj, &This->editor->reobj_list, struct re_object, entry)
1410 if (count == iob)
1411 break;
1412 count++;
1415 ME_CopyReObject(lpreobject, &reobj->obj, dwFlags);
1416 return S_OK;
1419 static LONG WINAPI
1420 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
1422 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1423 TRACE("(%p)\n",This);
1424 return list_count(&This->editor->reobj_list);
1427 static HRESULT WINAPI
1428 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
1430 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1431 FIXME("stub %p\n",This);
1432 return E_NOTIMPL;
1435 static HRESULT WINAPI
1436 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
1437 CLIPFORMAT cf, HGLOBAL hMetaPict)
1439 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1440 FIXME("stub %p\n",This);
1441 return E_NOTIMPL;
1444 static HRESULT WINAPI
1445 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
1447 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1448 FIXME("stub %p\n",This);
1449 return E_NOTIMPL;
1452 static HRESULT WINAPI
1453 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
1455 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1457 TRACE("(%p,%p)\n", This, reo);
1459 if (!reo)
1460 return E_INVALIDARG;
1462 if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
1464 ME_InsertOLEFromCursor(This->editor, reo, 0);
1465 ME_CommitUndo(This->editor);
1466 ME_UpdateRepaint(This->editor, FALSE);
1467 return S_OK;
1470 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
1471 LPSTORAGE lpstg)
1473 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1474 FIXME("stub %p\n",This);
1475 return E_NOTIMPL;
1478 static HRESULT WINAPI
1479 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
1481 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1482 FIXME("stub %p\n",This);
1483 return E_NOTIMPL;
1486 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
1487 LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
1489 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1490 FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
1491 return E_NOTIMPL;
1494 static HRESULT WINAPI
1495 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
1497 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1498 FIXME("stub %p\n",This);
1499 return E_NOTIMPL;
1502 static const IRichEditOleVtbl revt = {
1503 IRichEditOle_fnQueryInterface,
1504 IRichEditOle_fnAddRef,
1505 IRichEditOle_fnRelease,
1506 IRichEditOle_fnGetClientSite,
1507 IRichEditOle_fnGetObjectCount,
1508 IRichEditOle_fnGetLinkCount,
1509 IRichEditOle_fnGetObject,
1510 IRichEditOle_fnInsertObject,
1511 IRichEditOle_fnConvertObject,
1512 IRichEditOle_fnActivateAs,
1513 IRichEditOle_fnSetHostNames,
1514 IRichEditOle_fnSetLinkAvailable,
1515 IRichEditOle_fnSetDvaspect,
1516 IRichEditOle_fnHandsOffStorage,
1517 IRichEditOle_fnSaveCompleted,
1518 IRichEditOle_fnInPlaceDeactivate,
1519 IRichEditOle_fnContextSensitiveHelp,
1520 IRichEditOle_fnGetClipboardData,
1521 IRichEditOle_fnImportDataObject
1524 /* ITextRange interface */
1525 static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
1527 ITextRangeImpl *This = impl_from_ITextRange(me);
1529 *ppvObj = NULL;
1530 if (IsEqualGUID(riid, &IID_IUnknown)
1531 || IsEqualGUID(riid, &IID_IDispatch)
1532 || IsEqualGUID(riid, &IID_ITextRange))
1534 *ppvObj = me;
1535 ITextRange_AddRef(me);
1536 return S_OK;
1538 else if (IsEqualGUID(riid, &IID_Igetrichole))
1540 *ppvObj = This->child.reole;
1541 return S_OK;
1544 return E_NOINTERFACE;
1547 static ULONG WINAPI ITextRange_fnAddRef(ITextRange *me)
1549 ITextRangeImpl *This = impl_from_ITextRange(me);
1550 return InterlockedIncrement(&This->ref);
1553 static ULONG WINAPI ITextRange_fnRelease(ITextRange *me)
1555 ITextRangeImpl *This = impl_from_ITextRange(me);
1556 ULONG ref = InterlockedDecrement(&This->ref);
1558 TRACE ("%p ref=%u\n", This, ref);
1559 if (ref == 0)
1561 if (This->child.reole)
1563 list_remove(&This->child.entry);
1564 This->child.reole = NULL;
1566 heap_free(This);
1568 return ref;
1571 static HRESULT WINAPI ITextRange_fnGetTypeInfoCount(ITextRange *me, UINT *pctinfo)
1573 ITextRangeImpl *This = impl_from_ITextRange(me);
1574 TRACE("(%p)->(%p)\n", This, pctinfo);
1575 *pctinfo = 1;
1576 return S_OK;
1579 static HRESULT WINAPI ITextRange_fnGetTypeInfo(ITextRange *me, UINT iTInfo, LCID lcid,
1580 ITypeInfo **ppTInfo)
1582 ITextRangeImpl *This = impl_from_ITextRange(me);
1583 HRESULT hr;
1585 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
1587 hr = get_typeinfo(ITextRange_tid, ppTInfo);
1588 if (SUCCEEDED(hr))
1589 ITypeInfo_AddRef(*ppTInfo);
1590 return hr;
1593 static HRESULT WINAPI ITextRange_fnGetIDsOfNames(ITextRange *me, REFIID riid, LPOLESTR *rgszNames,
1594 UINT cNames, LCID lcid, DISPID *rgDispId)
1596 ITextRangeImpl *This = impl_from_ITextRange(me);
1597 ITypeInfo *ti;
1598 HRESULT hr;
1600 TRACE("(%p)->(%s, %p, %u, %d, %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid,
1601 rgDispId);
1603 hr = get_typeinfo(ITextRange_tid, &ti);
1604 if (SUCCEEDED(hr))
1605 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
1606 return hr;
1609 static HRESULT WINAPI ITextRange_fnInvoke(ITextRange *me, DISPID dispIdMember, REFIID riid,
1610 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1611 VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
1612 UINT *puArgErr)
1614 ITextRangeImpl *This = impl_from_ITextRange(me);
1615 ITypeInfo *ti;
1616 HRESULT hr;
1618 TRACE("(%p)->(%d, %s, %d, %u, %p, %p, %p, %p)\n", This, dispIdMember, debugstr_guid(riid),
1619 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1621 hr = get_typeinfo(ITextRange_tid, &ti);
1622 if (SUCCEEDED(hr))
1623 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1624 return hr;
1627 static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *str)
1629 ITextRangeImpl *This = impl_from_ITextRange(me);
1630 ME_TextEditor *editor;
1631 ME_Cursor start, end;
1632 int length;
1633 BOOL bEOP;
1635 TRACE("(%p)->(%p)\n", This, str);
1637 if (!This->child.reole)
1638 return CO_E_RELEASED;
1640 if (!str)
1641 return E_INVALIDARG;
1643 /* return early for degenerate range */
1644 if (This->start == This->end) {
1645 *str = NULL;
1646 return S_OK;
1649 editor = This->child.reole->editor;
1650 ME_CursorFromCharOfs(editor, This->start, &start);
1651 ME_CursorFromCharOfs(editor, This->end, &end);
1653 length = This->end - This->start;
1654 *str = SysAllocStringLen(NULL, length);
1655 if (!*str)
1656 return E_OUTOFMEMORY;
1658 bEOP = (end.pRun->next->type == diTextEnd && This->end > ME_GetTextLength(editor));
1659 ME_GetTextW(editor, *str, length, &start, length, FALSE, bEOP);
1660 return S_OK;
1663 static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
1665 ITextRangeImpl *This = impl_from_ITextRange(me);
1666 ME_TextEditor *editor;
1667 ME_Cursor cursor;
1668 ME_Style *style;
1669 int len;
1671 TRACE("(%p)->(%s)\n", This, debugstr_w(str));
1673 if (!This->child.reole)
1674 return CO_E_RELEASED;
1676 editor = This->child.reole->editor;
1678 /* delete only where's something to delete */
1679 if (This->start != This->end) {
1680 ME_CursorFromCharOfs(editor, This->start, &cursor);
1681 ME_InternalDeleteText(editor, &cursor, This->end - This->start, FALSE);
1684 if (!str || !*str) {
1685 /* will update this range as well */
1686 textranges_update_ranges(This->child.reole, This->start, This->end, RANGE_UPDATE_DELETE);
1687 return S_OK;
1690 /* it's safer not to rely on stored BSTR length */
1691 len = lstrlenW(str);
1692 cursor = editor->pCursors[0];
1693 ME_CursorFromCharOfs(editor, This->start, &editor->pCursors[0]);
1694 style = ME_GetInsertStyle(editor, 0);
1695 ME_InsertTextFromCursor(editor, 0, str, len, style);
1696 ME_ReleaseStyle(style);
1697 editor->pCursors[0] = cursor;
1699 if (len < This->end - This->start)
1700 textranges_update_ranges(This->child.reole, This->start + len, This->end, RANGE_UPDATE_DELETE);
1701 else
1702 This->end = len - This->start;
1704 return S_OK;
1707 static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch)
1709 WCHAR wch[2];
1711 ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, cursor->pRun->next->type == diTextEnd);
1712 *pch = wch[0];
1714 return S_OK;
1717 static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
1719 ITextRangeImpl *This = impl_from_ITextRange(me);
1720 ME_TextEditor *editor;
1721 ME_Cursor cursor;
1723 TRACE("(%p)->(%p)\n", This, pch);
1725 if (!This->child.reole)
1726 return CO_E_RELEASED;
1728 if (!pch)
1729 return E_INVALIDARG;
1731 editor = This->child.reole->editor;
1732 ME_CursorFromCharOfs(editor, This->start, &cursor);
1733 return range_GetChar(editor, &cursor, pch);
1736 static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch)
1738 ITextRangeImpl *This = impl_from_ITextRange(me);
1740 FIXME("(%p)->(%x): stub\n", This, ch);
1742 if (!This->child.reole)
1743 return CO_E_RELEASED;
1745 return E_NOTIMPL;
1748 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange);
1750 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
1752 ITextRangeImpl *This = impl_from_ITextRange(me);
1754 TRACE("(%p)->(%p)\n", This, ppRange);
1756 if (!This->child.reole)
1757 return CO_E_RELEASED;
1759 if (!ppRange)
1760 return E_INVALIDARG;
1762 return CreateITextRange(This->child.reole, This->start, This->end, ppRange);
1765 static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **range)
1767 ITextRangeImpl *This = impl_from_ITextRange(me);
1769 FIXME("(%p)->(%p): stub\n", This, range);
1771 if (!This->child.reole)
1772 return CO_E_RELEASED;
1774 return E_NOTIMPL;
1777 static HRESULT WINAPI ITextRange_fnSetFormattedText(ITextRange *me, ITextRange *range)
1779 ITextRangeImpl *This = impl_from_ITextRange(me);
1781 FIXME("(%p)->(%p): stub\n", This, range);
1783 if (!This->child.reole)
1784 return CO_E_RELEASED;
1786 return E_NOTIMPL;
1789 static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *start)
1791 ITextRangeImpl *This = impl_from_ITextRange(me);
1793 TRACE("(%p)->(%p)\n", This, start);
1795 if (!This->child.reole)
1796 return CO_E_RELEASED;
1798 if (!start)
1799 return E_INVALIDARG;
1801 *start = This->start;
1802 return S_OK;
1805 static HRESULT textrange_setstart(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1807 int len;
1809 if (value < 0)
1810 value = 0;
1812 if (value == *start)
1813 return S_FALSE;
1815 if (value <= *end) {
1816 *start = value;
1817 return S_OK;
1820 len = ME_GetTextLength(reole->editor);
1821 *start = *end = value > len ? len : value;
1822 return S_OK;
1825 static HRESULT WINAPI ITextRange_fnSetStart(ITextRange *me, LONG value)
1827 ITextRangeImpl *This = impl_from_ITextRange(me);
1829 TRACE("(%p)->(%d)\n", This, value);
1831 if (!This->child.reole)
1832 return CO_E_RELEASED;
1834 return textrange_setstart(This->child.reole, value, &This->start, &This->end);
1837 static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *end)
1839 ITextRangeImpl *This = impl_from_ITextRange(me);
1841 TRACE("(%p)->(%p)\n", This, end);
1843 if (!This->child.reole)
1844 return CO_E_RELEASED;
1846 if (!end)
1847 return E_INVALIDARG;
1849 *end = This->end;
1850 return S_OK;
1853 static HRESULT textrange_setend(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1855 int len;
1857 if (value == *end)
1858 return S_FALSE;
1860 if (value < *start) {
1861 *start = *end = max(0, value);
1862 return S_OK;
1865 len = ME_GetTextLength(reole->editor);
1866 *end = value > len ? len + 1 : value;
1867 return S_OK;
1870 static HRESULT WINAPI ITextRange_fnSetEnd(ITextRange *me, LONG value)
1872 ITextRangeImpl *This = impl_from_ITextRange(me);
1874 TRACE("(%p)->(%d)\n", This, value);
1876 if (!This->child.reole)
1877 return CO_E_RELEASED;
1879 return textrange_setend(This->child.reole, value, &This->start, &This->end);
1882 static HRESULT WINAPI ITextRange_fnGetFont(ITextRange *me, ITextFont **font)
1884 ITextRangeImpl *This = impl_from_ITextRange(me);
1886 TRACE("(%p)->(%p)\n", This, font);
1888 if (!This->child.reole)
1889 return CO_E_RELEASED;
1891 if (!font)
1892 return E_INVALIDARG;
1894 return create_textfont(me, NULL, font);
1897 static HRESULT WINAPI ITextRange_fnSetFont(ITextRange *me, ITextFont *font)
1899 ITextRangeImpl *This = impl_from_ITextRange(me);
1901 TRACE("(%p)->(%p)\n", This, font);
1903 if (!font)
1904 return E_INVALIDARG;
1906 if (!This->child.reole)
1907 return CO_E_RELEASED;
1909 textrange_set_font(me, font);
1910 return S_OK;
1913 static HRESULT WINAPI ITextRange_fnGetPara(ITextRange *me, ITextPara **para)
1915 ITextRangeImpl *This = impl_from_ITextRange(me);
1917 TRACE("(%p)->(%p)\n", This, para);
1919 if (!This->child.reole)
1920 return CO_E_RELEASED;
1922 if (!para)
1923 return E_INVALIDARG;
1925 return create_textpara(me, para);
1928 static HRESULT WINAPI ITextRange_fnSetPara(ITextRange *me, ITextPara *para)
1930 ITextRangeImpl *This = impl_from_ITextRange(me);
1932 FIXME("(%p)->(%p): stub\n", This, para);
1934 if (!This->child.reole)
1935 return CO_E_RELEASED;
1937 return E_NOTIMPL;
1940 static HRESULT WINAPI ITextRange_fnGetStoryLength(ITextRange *me, LONG *length)
1942 ITextRangeImpl *This = impl_from_ITextRange(me);
1944 TRACE("(%p)->(%p)\n", This, length);
1946 if (!This->child.reole)
1947 return CO_E_RELEASED;
1949 return textrange_get_storylength(This->child.reole->editor, length);
1952 static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *value)
1954 ITextRangeImpl *This = impl_from_ITextRange(me);
1956 TRACE("(%p)->(%p)\n", This, value);
1958 if (!This->child.reole)
1959 return CO_E_RELEASED;
1961 if (!value)
1962 return E_INVALIDARG;
1964 *value = tomUnknownStory;
1965 return S_OK;
1968 static HRESULT range_Collapse(LONG bStart, LONG *start, LONG *end)
1970 if (*end == *start)
1971 return S_FALSE;
1973 if (bStart == tomEnd)
1974 *start = *end;
1975 else
1976 *end = *start;
1977 return S_OK;
1980 static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
1982 ITextRangeImpl *This = impl_from_ITextRange(me);
1984 TRACE("(%p)->(%d)\n", This, bStart);
1986 if (!This->child.reole)
1987 return CO_E_RELEASED;
1989 return range_Collapse(bStart, &This->start, &This->end);
1992 static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG unit, LONG *delta)
1994 ITextRangeImpl *This = impl_from_ITextRange(me);
1996 TRACE("(%p)->(%d %p)\n", This, unit, delta);
1998 if (!This->child.reole)
1999 return CO_E_RELEASED;
2001 return textrange_expand(me, unit, delta);
2004 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG unit, LONG *index)
2006 ITextRangeImpl *This = impl_from_ITextRange(me);
2008 FIXME("(%p)->(%d %p): stub\n", This, unit, index);
2010 if (!This->child.reole)
2011 return CO_E_RELEASED;
2013 return E_NOTIMPL;
2016 static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG unit, LONG index,
2017 LONG extend)
2019 ITextRangeImpl *This = impl_from_ITextRange(me);
2021 FIXME("(%p)->(%d %d %d): stub\n", This, unit, index, extend);
2023 if (!This->child.reole)
2024 return CO_E_RELEASED;
2026 return E_NOTIMPL;
2029 static void cp2range(ME_TextEditor *editor, LONG *cp1, LONG *cp2)
2031 int len = ME_GetTextLength(editor) + 1;
2033 *cp1 = max(*cp1, 0);
2034 *cp2 = max(*cp2, 0);
2035 *cp1 = min(*cp1, len);
2036 *cp2 = min(*cp2, len);
2037 if (*cp1 > *cp2)
2039 int tmp = *cp1;
2040 *cp1 = *cp2;
2041 *cp2 = tmp;
2043 if (*cp1 == len)
2044 *cp1 = *cp2 = len - 1;
2047 static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG anchor, LONG active)
2049 ITextRangeImpl *This = impl_from_ITextRange(me);
2051 TRACE("(%p)->(%d %d)\n", This, anchor, active);
2053 if (!This->child.reole)
2054 return CO_E_RELEASED;
2056 cp2range(This->child.reole->editor, &anchor, &active);
2057 if (anchor == This->start && active == This->end)
2058 return S_FALSE;
2060 This->start = anchor;
2061 This->end = active;
2062 return S_OK;
2065 static HRESULT textrange_inrange(LONG start, LONG end, ITextRange *range, LONG *ret)
2067 LONG from, to, v;
2069 if (!ret)
2070 ret = &v;
2072 if (FAILED(ITextRange_GetStart(range, &from)) || FAILED(ITextRange_GetEnd(range, &to))) {
2073 *ret = tomFalse;
2075 else
2076 *ret = (start >= from && end <= to) ? tomTrue : tomFalse;
2077 return *ret == tomTrue ? S_OK : S_FALSE;
2080 static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *range, LONG *ret)
2082 ITextRangeImpl *This = impl_from_ITextRange(me);
2084 TRACE("(%p)->(%p %p)\n", This, range, ret);
2086 if (ret)
2087 *ret = tomFalse;
2089 if (!This->child.reole)
2090 return CO_E_RELEASED;
2092 if (!range)
2093 return S_FALSE;
2095 return textrange_inrange(This->start, This->end, range, ret);
2098 static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *ret)
2100 ITextRangeImpl *This = impl_from_ITextRange(me);
2102 FIXME("(%p)->(%p): stub\n", This, ret);
2104 if (!This->child.reole)
2105 return CO_E_RELEASED;
2107 return E_NOTIMPL;
2110 static HRESULT textrange_isequal(LONG start, LONG end, ITextRange *range, LONG *ret)
2112 LONG from, to, v;
2114 if (!ret)
2115 ret = &v;
2117 if (FAILED(ITextRange_GetStart(range, &from)) || FAILED(ITextRange_GetEnd(range, &to))) {
2118 *ret = tomFalse;
2120 else
2121 *ret = (start == from && end == to) ? tomTrue : tomFalse;
2122 return *ret == tomTrue ? S_OK : S_FALSE;
2125 static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *range, LONG *ret)
2127 ITextRangeImpl *This = impl_from_ITextRange(me);
2129 TRACE("(%p)->(%p %p)\n", This, range, ret);
2131 if (ret)
2132 *ret = tomFalse;
2134 if (!This->child.reole)
2135 return CO_E_RELEASED;
2137 if (!range)
2138 return S_FALSE;
2140 return textrange_isequal(This->start, This->end, range, ret);
2143 static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me)
2145 ITextRangeImpl *This = impl_from_ITextRange(me);
2147 TRACE("(%p)\n", This);
2149 if (!This->child.reole)
2150 return CO_E_RELEASED;
2152 set_selection(This->child.reole->editor, This->start, This->end);
2153 return S_OK;
2156 static HRESULT WINAPI ITextRange_fnStartOf(ITextRange *me, LONG unit, LONG extend,
2157 LONG *delta)
2159 ITextRangeImpl *This = impl_from_ITextRange(me);
2161 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
2163 if (!This->child.reole)
2164 return CO_E_RELEASED;
2166 return E_NOTIMPL;
2169 static HRESULT WINAPI ITextRange_fnEndOf(ITextRange *me, LONG unit, LONG extend,
2170 LONG *delta)
2172 ITextRangeImpl *This = impl_from_ITextRange(me);
2174 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
2176 if (!This->child.reole)
2177 return CO_E_RELEASED;
2179 return E_NOTIMPL;
2182 static HRESULT WINAPI ITextRange_fnMove(ITextRange *me, LONG unit, LONG count, LONG *delta)
2184 ITextRangeImpl *This = impl_from_ITextRange(me);
2186 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
2188 if (!This->child.reole)
2189 return CO_E_RELEASED;
2191 return E_NOTIMPL;
2194 static HRESULT WINAPI ITextRange_fnMoveStart(ITextRange *me, LONG unit, LONG count,
2195 LONG *delta)
2197 ITextRangeImpl *This = impl_from_ITextRange(me);
2199 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
2201 if (!This->child.reole)
2202 return CO_E_RELEASED;
2204 return E_NOTIMPL;
2207 static HRESULT textrange_moveend(ITextRange *range, LONG unit, LONG count, LONG *delta)
2209 LONG old_start, old_end, new_start, new_end;
2210 HRESULT hr = S_OK;
2212 if (!count)
2214 if (delta)
2215 *delta = 0;
2216 return S_FALSE;
2219 ITextRange_GetStart(range, &old_start);
2220 ITextRange_GetEnd(range, &old_end);
2221 switch (unit)
2223 case tomStory:
2224 if (count < 0)
2225 new_start = new_end = 0;
2226 else
2228 new_start = old_start;
2229 ITextRange_GetStoryLength(range, &new_end);
2231 if (delta)
2233 if (new_end < old_end)
2234 *delta = -1;
2235 else if (new_end == old_end)
2236 *delta = 0;
2237 else
2238 *delta = 1;
2240 break;
2241 default:
2242 FIXME("unit %d is not supported\n", unit);
2243 return E_NOTIMPL;
2245 if (new_end == old_end)
2246 hr = S_FALSE;
2247 ITextRange_SetStart(range, new_start);
2248 ITextRange_SetEnd(range, new_end);
2250 return hr;
2253 static HRESULT WINAPI ITextRange_fnMoveEnd(ITextRange *me, LONG unit, LONG count,
2254 LONG *delta)
2256 ITextRangeImpl *This = impl_from_ITextRange(me);
2258 TRACE("(%p)->(%d %d %p)\n", This, unit, count, delta);
2260 if (!This->child.reole)
2261 return CO_E_RELEASED;
2263 return textrange_moveend(me, unit, count, delta);
2266 static HRESULT WINAPI ITextRange_fnMoveWhile(ITextRange *me, VARIANT *charset, LONG count,
2267 LONG *delta)
2269 ITextRangeImpl *This = impl_from_ITextRange(me);
2271 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2273 if (!This->child.reole)
2274 return CO_E_RELEASED;
2276 return E_NOTIMPL;
2279 static HRESULT WINAPI ITextRange_fnMoveStartWhile(ITextRange *me, VARIANT *charset, LONG count,
2280 LONG *delta)
2282 ITextRangeImpl *This = impl_from_ITextRange(me);
2284 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2286 if (!This->child.reole)
2287 return CO_E_RELEASED;
2289 return E_NOTIMPL;
2292 static HRESULT WINAPI ITextRange_fnMoveEndWhile(ITextRange *me, VARIANT *charset, LONG count,
2293 LONG *delta)
2295 ITextRangeImpl *This = impl_from_ITextRange(me);
2297 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2299 if (!This->child.reole)
2300 return CO_E_RELEASED;
2302 return E_NOTIMPL;
2305 static HRESULT WINAPI ITextRange_fnMoveUntil(ITextRange *me, VARIANT *charset, LONG count,
2306 LONG *delta)
2308 ITextRangeImpl *This = impl_from_ITextRange(me);
2310 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2312 if (!This->child.reole)
2313 return CO_E_RELEASED;
2315 return E_NOTIMPL;
2318 static HRESULT WINAPI ITextRange_fnMoveStartUntil(ITextRange *me, VARIANT *charset, LONG count,
2319 LONG *delta)
2321 ITextRangeImpl *This = impl_from_ITextRange(me);
2323 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2325 if (!This->child.reole)
2326 return CO_E_RELEASED;
2328 return E_NOTIMPL;
2331 static HRESULT WINAPI ITextRange_fnMoveEndUntil(ITextRange *me, VARIANT *charset, LONG count,
2332 LONG *delta)
2334 ITextRangeImpl *This = impl_from_ITextRange(me);
2336 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2338 if (!This->child.reole)
2339 return CO_E_RELEASED;
2341 return E_NOTIMPL;
2344 static HRESULT WINAPI ITextRange_fnFindText(ITextRange *me, BSTR text, LONG count, LONG flags,
2345 LONG *length)
2347 ITextRangeImpl *This = impl_from_ITextRange(me);
2349 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
2351 if (!This->child.reole)
2352 return CO_E_RELEASED;
2354 return E_NOTIMPL;
2357 static HRESULT WINAPI ITextRange_fnFindTextStart(ITextRange *me, BSTR text, LONG count,
2358 LONG flags, LONG *length)
2360 ITextRangeImpl *This = impl_from_ITextRange(me);
2362 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
2364 if (!This->child.reole)
2365 return CO_E_RELEASED;
2367 return E_NOTIMPL;
2370 static HRESULT WINAPI ITextRange_fnFindTextEnd(ITextRange *me, BSTR text, LONG count,
2371 LONG flags, LONG *length)
2373 ITextRangeImpl *This = impl_from_ITextRange(me);
2375 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
2377 if (!This->child.reole)
2378 return CO_E_RELEASED;
2380 return E_NOTIMPL;
2383 static HRESULT WINAPI ITextRange_fnDelete(ITextRange *me, LONG unit, LONG count, LONG *delta)
2385 ITextRangeImpl *This = impl_from_ITextRange(me);
2387 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
2389 if (!This->child.reole)
2390 return CO_E_RELEASED;
2392 return E_NOTIMPL;
2395 static HRESULT WINAPI ITextRange_fnCut(ITextRange *me, VARIANT *v)
2397 ITextRangeImpl *This = impl_from_ITextRange(me);
2399 FIXME("(%p)->(%p): stub\n", This, v);
2401 if (!This->child.reole)
2402 return CO_E_RELEASED;
2404 return E_NOTIMPL;
2407 static HRESULT WINAPI ITextRange_fnCopy(ITextRange *me, VARIANT *v)
2409 ITextRangeImpl *This = impl_from_ITextRange(me);
2411 FIXME("(%p)->(%p): stub\n", This, v);
2413 if (!This->child.reole)
2414 return CO_E_RELEASED;
2416 return E_NOTIMPL;
2419 static HRESULT WINAPI ITextRange_fnPaste(ITextRange *me, VARIANT *v, LONG format)
2421 ITextRangeImpl *This = impl_from_ITextRange(me);
2423 FIXME("(%p)->(%s %x): stub\n", This, debugstr_variant(v), format);
2425 if (!This->child.reole)
2426 return CO_E_RELEASED;
2428 return E_NOTIMPL;
2431 static HRESULT WINAPI ITextRange_fnCanPaste(ITextRange *me, VARIANT *v, LONG format, LONG *ret)
2433 ITextRangeImpl *This = impl_from_ITextRange(me);
2435 FIXME("(%p)->(%s %x %p): stub\n", This, debugstr_variant(v), format, ret);
2437 if (!This->child.reole)
2438 return CO_E_RELEASED;
2440 return E_NOTIMPL;
2443 static HRESULT WINAPI ITextRange_fnCanEdit(ITextRange *me, LONG *ret)
2445 ITextRangeImpl *This = impl_from_ITextRange(me);
2447 FIXME("(%p)->(%p): stub\n", This, ret);
2449 if (!This->child.reole)
2450 return CO_E_RELEASED;
2452 return E_NOTIMPL;
2455 static HRESULT WINAPI ITextRange_fnChangeCase(ITextRange *me, LONG type)
2457 ITextRangeImpl *This = impl_from_ITextRange(me);
2459 FIXME("(%p)->(%d): stub\n", This, type);
2461 if (!This->child.reole)
2462 return CO_E_RELEASED;
2464 return E_NOTIMPL;
2467 static HRESULT WINAPI ITextRange_fnGetPoint(ITextRange *me, LONG type, LONG *cx, LONG *cy)
2469 ITextRangeImpl *This = impl_from_ITextRange(me);
2471 FIXME("(%p)->(%d %p %p): stub\n", This, type, cx, cy);
2473 if (!This->child.reole)
2474 return CO_E_RELEASED;
2476 return E_NOTIMPL;
2479 static HRESULT WINAPI ITextRange_fnSetPoint(ITextRange *me, LONG x, LONG y, LONG type,
2480 LONG extend)
2482 ITextRangeImpl *This = impl_from_ITextRange(me);
2484 FIXME("(%p)->(%d %d %d %d): stub\n", This, x, y, type, extend);
2486 if (!This->child.reole)
2487 return CO_E_RELEASED;
2489 return E_NOTIMPL;
2492 static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG value)
2494 ITextRangeImpl *This = impl_from_ITextRange(me);
2495 ME_TextEditor *editor;
2496 ME_Cursor cursor;
2497 int x, y, height;
2499 TRACE("(%p)->(%d)\n", This, value);
2501 if (!This->child.reole)
2502 return CO_E_RELEASED;
2504 editor = This->child.reole->editor;
2506 switch (value)
2508 case tomStart:
2509 ME_CursorFromCharOfs(editor, This->start, &cursor);
2510 ME_GetCursorCoordinates(editor, &cursor, &x, &y, &height);
2511 break;
2512 case tomEnd:
2513 ME_CursorFromCharOfs(editor, This->end, &cursor);
2514 ME_GetCursorCoordinates(editor, &cursor, &x, &y, &height);
2515 break;
2516 default:
2517 FIXME("bStart value %d not handled\n", value);
2518 return E_NOTIMPL;
2520 ME_ScrollAbs(editor, x, y);
2521 return S_OK;
2524 static HRESULT WINAPI ITextRange_fnGetEmbeddedObject(ITextRange *me, IUnknown **ppv)
2526 ITextRangeImpl *This = impl_from_ITextRange(me);
2528 FIXME("(%p)->(%p): stub\n", This, ppv);
2530 if (!This->child.reole)
2531 return CO_E_RELEASED;
2533 return E_NOTIMPL;
2536 static const ITextRangeVtbl trvt = {
2537 ITextRange_fnQueryInterface,
2538 ITextRange_fnAddRef,
2539 ITextRange_fnRelease,
2540 ITextRange_fnGetTypeInfoCount,
2541 ITextRange_fnGetTypeInfo,
2542 ITextRange_fnGetIDsOfNames,
2543 ITextRange_fnInvoke,
2544 ITextRange_fnGetText,
2545 ITextRange_fnSetText,
2546 ITextRange_fnGetChar,
2547 ITextRange_fnSetChar,
2548 ITextRange_fnGetDuplicate,
2549 ITextRange_fnGetFormattedText,
2550 ITextRange_fnSetFormattedText,
2551 ITextRange_fnGetStart,
2552 ITextRange_fnSetStart,
2553 ITextRange_fnGetEnd,
2554 ITextRange_fnSetEnd,
2555 ITextRange_fnGetFont,
2556 ITextRange_fnSetFont,
2557 ITextRange_fnGetPara,
2558 ITextRange_fnSetPara,
2559 ITextRange_fnGetStoryLength,
2560 ITextRange_fnGetStoryType,
2561 ITextRange_fnCollapse,
2562 ITextRange_fnExpand,
2563 ITextRange_fnGetIndex,
2564 ITextRange_fnSetIndex,
2565 ITextRange_fnSetRange,
2566 ITextRange_fnInRange,
2567 ITextRange_fnInStory,
2568 ITextRange_fnIsEqual,
2569 ITextRange_fnSelect,
2570 ITextRange_fnStartOf,
2571 ITextRange_fnEndOf,
2572 ITextRange_fnMove,
2573 ITextRange_fnMoveStart,
2574 ITextRange_fnMoveEnd,
2575 ITextRange_fnMoveWhile,
2576 ITextRange_fnMoveStartWhile,
2577 ITextRange_fnMoveEndWhile,
2578 ITextRange_fnMoveUntil,
2579 ITextRange_fnMoveStartUntil,
2580 ITextRange_fnMoveEndUntil,
2581 ITextRange_fnFindText,
2582 ITextRange_fnFindTextStart,
2583 ITextRange_fnFindTextEnd,
2584 ITextRange_fnDelete,
2585 ITextRange_fnCut,
2586 ITextRange_fnCopy,
2587 ITextRange_fnPaste,
2588 ITextRange_fnCanPaste,
2589 ITextRange_fnCanEdit,
2590 ITextRange_fnChangeCase,
2591 ITextRange_fnGetPoint,
2592 ITextRange_fnSetPoint,
2593 ITextRange_fnScrollIntoView,
2594 ITextRange_fnGetEmbeddedObject
2597 /* ITextFont */
2598 static HRESULT WINAPI TextFont_QueryInterface(ITextFont *iface, REFIID riid, void **ppv)
2600 ITextFontImpl *This = impl_from_ITextFont(iface);
2602 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2604 if (IsEqualIID(riid, &IID_ITextFont) ||
2605 IsEqualIID(riid, &IID_IDispatch) ||
2606 IsEqualIID(riid, &IID_IUnknown))
2608 *ppv = iface;
2609 ITextFont_AddRef(iface);
2610 return S_OK;
2613 *ppv = NULL;
2614 return E_NOINTERFACE;
2617 static ULONG WINAPI TextFont_AddRef(ITextFont *iface)
2619 ITextFontImpl *This = impl_from_ITextFont(iface);
2620 ULONG ref = InterlockedIncrement(&This->ref);
2621 TRACE("(%p)->(%u)\n", This, ref);
2622 return ref;
2625 static ULONG WINAPI TextFont_Release(ITextFont *iface)
2627 ITextFontImpl *This = impl_from_ITextFont(iface);
2628 ULONG ref = InterlockedDecrement(&This->ref);
2630 TRACE("(%p)->(%u)\n", This, ref);
2632 if (!ref)
2634 if (This->range)
2635 ITextRange_Release(This->range);
2636 SysFreeString(This->props[FONT_NAME].str);
2637 heap_free(This);
2640 return ref;
2643 static HRESULT WINAPI TextFont_GetTypeInfoCount(ITextFont *iface, UINT *pctinfo)
2645 ITextFontImpl *This = impl_from_ITextFont(iface);
2646 TRACE("(%p)->(%p)\n", This, pctinfo);
2647 *pctinfo = 1;
2648 return S_OK;
2651 static HRESULT WINAPI TextFont_GetTypeInfo(ITextFont *iface, UINT iTInfo, LCID lcid,
2652 ITypeInfo **ppTInfo)
2654 ITextFontImpl *This = impl_from_ITextFont(iface);
2655 HRESULT hr;
2657 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
2659 hr = get_typeinfo(ITextFont_tid, ppTInfo);
2660 if (SUCCEEDED(hr))
2661 ITypeInfo_AddRef(*ppTInfo);
2662 return hr;
2665 static HRESULT WINAPI TextFont_GetIDsOfNames(ITextFont *iface, REFIID riid,
2666 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2668 ITextFontImpl *This = impl_from_ITextFont(iface);
2669 ITypeInfo *ti;
2670 HRESULT hr;
2672 TRACE("(%p)->(%s, %p, %u, %d, %p)\n", This, debugstr_guid(riid),
2673 rgszNames, cNames, lcid, rgDispId);
2675 hr = get_typeinfo(ITextFont_tid, &ti);
2676 if (SUCCEEDED(hr))
2677 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
2678 return hr;
2681 static HRESULT WINAPI TextFont_Invoke(
2682 ITextFont *iface,
2683 DISPID dispIdMember,
2684 REFIID riid,
2685 LCID lcid,
2686 WORD wFlags,
2687 DISPPARAMS *pDispParams,
2688 VARIANT *pVarResult,
2689 EXCEPINFO *pExcepInfo,
2690 UINT *puArgErr)
2692 ITextFontImpl *This = impl_from_ITextFont(iface);
2693 ITypeInfo *ti;
2694 HRESULT hr;
2696 TRACE("(%p)->(%d, %s, %d, %u, %p, %p, %p, %p)\n", This, dispIdMember, debugstr_guid(riid),
2697 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2699 hr = get_typeinfo(ITextFont_tid, &ti);
2700 if (SUCCEEDED(hr))
2701 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2702 return hr;
2705 static HRESULT WINAPI TextFont_GetDuplicate(ITextFont *iface, ITextFont **ret)
2707 ITextFontImpl *This = impl_from_ITextFont(iface);
2709 TRACE("(%p)->(%p)\n", This, ret);
2711 if (!ret)
2712 return E_INVALIDARG;
2714 *ret = NULL;
2715 if (This->range && !get_range_reole(This->range))
2716 return CO_E_RELEASED;
2718 return create_textfont(NULL, This, ret);
2721 static HRESULT WINAPI TextFont_SetDuplicate(ITextFont *iface, ITextFont *pFont)
2723 ITextFontImpl *This = impl_from_ITextFont(iface);
2724 FIXME("(%p)->(%p): stub\n", This, pFont);
2725 return E_NOTIMPL;
2728 static HRESULT WINAPI TextFont_CanChange(ITextFont *iface, LONG *ret)
2730 ITextFontImpl *This = impl_from_ITextFont(iface);
2731 FIXME("(%p)->(%p): stub\n", This, ret);
2732 return E_NOTIMPL;
2735 static HRESULT WINAPI TextFont_IsEqual(ITextFont *iface, ITextFont *font, LONG *ret)
2737 ITextFontImpl *This = impl_from_ITextFont(iface);
2738 FIXME("(%p)->(%p %p): stub\n", This, font, ret);
2739 return E_NOTIMPL;
2742 static void textfont_reset_to_default(ITextFontImpl *font)
2744 enum textfont_prop_id id;
2746 for (id = FONT_PROPID_FIRST; id < FONT_PROPID_LAST; id++) {
2747 switch (id)
2749 case FONT_ALLCAPS:
2750 case FONT_ANIMATION:
2751 case FONT_BOLD:
2752 case FONT_EMBOSS:
2753 case FONT_HIDDEN:
2754 case FONT_ENGRAVE:
2755 case FONT_ITALIC:
2756 case FONT_OUTLINE:
2757 case FONT_PROTECTED:
2758 case FONT_SHADOW:
2759 case FONT_SMALLCAPS:
2760 case FONT_STRIKETHROUGH:
2761 case FONT_SUBSCRIPT:
2762 case FONT_SUPERSCRIPT:
2763 case FONT_UNDERLINE:
2764 font->props[id].l = tomFalse;
2765 break;
2766 case FONT_BACKCOLOR:
2767 case FONT_FORECOLOR:
2768 font->props[id].l = tomAutoColor;
2769 break;
2770 case FONT_KERNING:
2771 case FONT_POSITION:
2772 case FONT_SIZE:
2773 case FONT_SPACING:
2774 font->props[id].f = 0.0;
2775 break;
2776 case FONT_LANGID:
2777 font->props[id].l = GetSystemDefaultLCID();
2778 break;
2779 case FONT_NAME: {
2780 static const WCHAR sysW[] = {'S','y','s','t','e','m',0};
2781 SysFreeString(font->props[id].str);
2782 font->props[id].str = SysAllocString(sysW);
2783 break;
2785 case FONT_WEIGHT:
2786 font->props[id].l = FW_NORMAL;
2787 break;
2788 default:
2789 FIXME("font property %d not handled\n", id);
2794 static void textfont_reset_to_undefined(ITextFontImpl *font)
2796 enum textfont_prop_id id;
2798 for (id = FONT_PROPID_FIRST; id < FONT_PROPID_LAST; id++) {
2799 switch (id)
2801 case FONT_ALLCAPS:
2802 case FONT_ANIMATION:
2803 case FONT_BOLD:
2804 case FONT_EMBOSS:
2805 case FONT_HIDDEN:
2806 case FONT_ENGRAVE:
2807 case FONT_ITALIC:
2808 case FONT_OUTLINE:
2809 case FONT_PROTECTED:
2810 case FONT_SHADOW:
2811 case FONT_SMALLCAPS:
2812 case FONT_STRIKETHROUGH:
2813 case FONT_SUBSCRIPT:
2814 case FONT_SUPERSCRIPT:
2815 case FONT_UNDERLINE:
2816 case FONT_BACKCOLOR:
2817 case FONT_FORECOLOR:
2818 case FONT_LANGID:
2819 case FONT_WEIGHT:
2820 font->props[id].l = tomUndefined;
2821 break;
2822 case FONT_KERNING:
2823 case FONT_POSITION:
2824 case FONT_SIZE:
2825 case FONT_SPACING:
2826 font->props[id].f = tomUndefined;
2827 break;
2828 case FONT_NAME:
2829 break;
2830 default:
2831 FIXME("font property %d not handled\n", id);
2836 static void textfont_apply_range_props(ITextFontImpl *font)
2838 enum textfont_prop_id propid;
2839 for (propid = FONT_PROPID_FIRST; propid < FONT_PROPID_LAST; propid++)
2840 set_textfont_prop(font, propid, &font->props[propid]);
2843 static HRESULT WINAPI TextFont_Reset(ITextFont *iface, LONG value)
2845 ITextFontImpl *This = impl_from_ITextFont(iface);
2847 TRACE("(%p)->(%d)\n", This, value);
2849 /* If font is attached to a range, released or not, we can't
2850 reset to undefined */
2851 if (This->range) {
2852 if (!get_range_reole(This->range))
2853 return CO_E_RELEASED;
2855 switch (value)
2857 case tomUndefined:
2858 return E_INVALIDARG;
2859 case tomCacheParms:
2860 textfont_cache_range_props(This);
2861 This->get_cache_enabled = TRUE;
2862 break;
2863 case tomTrackParms:
2864 This->get_cache_enabled = FALSE;
2865 break;
2866 case tomApplyLater:
2867 This->set_cache_enabled = TRUE;
2868 break;
2869 case tomApplyNow:
2870 This->set_cache_enabled = FALSE;
2871 textfont_apply_range_props(This);
2872 break;
2873 case tomUsePoints:
2874 case tomUseTwips:
2875 return E_INVALIDARG;
2876 default:
2877 FIXME("reset mode %d not supported\n", value);
2880 return S_OK;
2882 else {
2883 switch (value)
2885 /* reset to global defaults */
2886 case tomDefault:
2887 textfont_reset_to_default(This);
2888 return S_OK;
2889 /* all properties are set to tomUndefined, font name is retained */
2890 case tomUndefined:
2891 textfont_reset_to_undefined(This);
2892 return S_OK;
2893 case tomApplyNow:
2894 case tomApplyLater:
2895 case tomTrackParms:
2896 case tomCacheParms:
2897 return S_OK;
2898 case tomUsePoints:
2899 case tomUseTwips:
2900 return E_INVALIDARG;
2904 FIXME("reset mode %d not supported\n", value);
2905 return E_NOTIMPL;
2908 static HRESULT WINAPI TextFont_GetStyle(ITextFont *iface, LONG *value)
2910 ITextFontImpl *This = impl_from_ITextFont(iface);
2911 FIXME("(%p)->(%p): stub\n", This, value);
2912 return E_NOTIMPL;
2915 static HRESULT WINAPI TextFont_SetStyle(ITextFont *iface, LONG value)
2917 ITextFontImpl *This = impl_from_ITextFont(iface);
2918 FIXME("(%p)->(%d): stub\n", This, value);
2919 return E_NOTIMPL;
2922 static HRESULT WINAPI TextFont_GetAllCaps(ITextFont *iface, LONG *value)
2924 ITextFontImpl *This = impl_from_ITextFont(iface);
2925 TRACE("(%p)->(%p)\n", This, value);
2926 return get_textfont_propl(This, FONT_ALLCAPS, value);
2929 static HRESULT WINAPI TextFont_SetAllCaps(ITextFont *iface, LONG value)
2931 ITextFontImpl *This = impl_from_ITextFont(iface);
2932 TRACE("(%p)->(%d)\n", This, value);
2933 return set_textfont_propd(This, FONT_ALLCAPS, value);
2936 static HRESULT WINAPI TextFont_GetAnimation(ITextFont *iface, LONG *value)
2938 ITextFontImpl *This = impl_from_ITextFont(iface);
2939 TRACE("(%p)->(%p)\n", This, value);
2940 return get_textfont_propl(This, FONT_ANIMATION, value);
2943 static HRESULT WINAPI TextFont_SetAnimation(ITextFont *iface, LONG value)
2945 ITextFontImpl *This = impl_from_ITextFont(iface);
2947 TRACE("(%p)->(%d)\n", This, value);
2949 if (value < tomNoAnimation || value > tomAnimationMax)
2950 return E_INVALIDARG;
2952 return set_textfont_propl(This, FONT_ANIMATION, value);
2955 static HRESULT WINAPI TextFont_GetBackColor(ITextFont *iface, LONG *value)
2957 ITextFontImpl *This = impl_from_ITextFont(iface);
2958 TRACE("(%p)->(%p)\n", This, value);
2959 return get_textfont_propl(This, FONT_BACKCOLOR, value);
2962 static HRESULT WINAPI TextFont_SetBackColor(ITextFont *iface, LONG value)
2964 ITextFontImpl *This = impl_from_ITextFont(iface);
2965 TRACE("(%p)->(%d)\n", This, value);
2966 return set_textfont_propl(This, FONT_BACKCOLOR, value);
2969 static HRESULT WINAPI TextFont_GetBold(ITextFont *iface, LONG *value)
2971 ITextFontImpl *This = impl_from_ITextFont(iface);
2972 TRACE("(%p)->(%p)\n", This, value);
2973 return get_textfont_propl(This, FONT_BOLD, value);
2976 static HRESULT WINAPI TextFont_SetBold(ITextFont *iface, LONG value)
2978 ITextFontImpl *This = impl_from_ITextFont(iface);
2979 TRACE("(%p)->(%d)\n", This, value);
2980 return set_textfont_propd(This, FONT_BOLD, value);
2983 static HRESULT WINAPI TextFont_GetEmboss(ITextFont *iface, LONG *value)
2985 ITextFontImpl *This = impl_from_ITextFont(iface);
2986 TRACE("(%p)->(%p)\n", This, value);
2987 return get_textfont_propl(This, FONT_EMBOSS, value);
2990 static HRESULT WINAPI TextFont_SetEmboss(ITextFont *iface, LONG value)
2992 ITextFontImpl *This = impl_from_ITextFont(iface);
2993 TRACE("(%p)->(%d)\n", This, value);
2994 return set_textfont_propd(This, FONT_EMBOSS, value);
2997 static HRESULT WINAPI TextFont_GetForeColor(ITextFont *iface, LONG *value)
2999 ITextFontImpl *This = impl_from_ITextFont(iface);
3000 TRACE("(%p)->(%p)\n", This, value);
3001 return get_textfont_propl(This, FONT_FORECOLOR, value);
3004 static HRESULT WINAPI TextFont_SetForeColor(ITextFont *iface, LONG value)
3006 ITextFontImpl *This = impl_from_ITextFont(iface);
3007 TRACE("(%p)->(%d)\n", This, value);
3008 return set_textfont_propl(This, FONT_FORECOLOR, value);
3011 static HRESULT WINAPI TextFont_GetHidden(ITextFont *iface, LONG *value)
3013 ITextFontImpl *This = impl_from_ITextFont(iface);
3014 TRACE("(%p)->(%p)\n", This, value);
3015 return get_textfont_propl(This, FONT_HIDDEN, value);
3018 static HRESULT WINAPI TextFont_SetHidden(ITextFont *iface, LONG value)
3020 ITextFontImpl *This = impl_from_ITextFont(iface);
3021 TRACE("(%p)->(%d)\n", This, value);
3022 return set_textfont_propd(This, FONT_HIDDEN, value);
3025 static HRESULT WINAPI TextFont_GetEngrave(ITextFont *iface, LONG *value)
3027 ITextFontImpl *This = impl_from_ITextFont(iface);
3028 TRACE("(%p)->(%p)\n", This, value);
3029 return get_textfont_propl(This, FONT_ENGRAVE, value);
3032 static HRESULT WINAPI TextFont_SetEngrave(ITextFont *iface, LONG value)
3034 ITextFontImpl *This = impl_from_ITextFont(iface);
3035 TRACE("(%p)->(%d)\n", This, value);
3036 return set_textfont_propd(This, FONT_ENGRAVE, value);
3039 static HRESULT WINAPI TextFont_GetItalic(ITextFont *iface, LONG *value)
3041 ITextFontImpl *This = impl_from_ITextFont(iface);
3042 TRACE("(%p)->(%p)\n", This, value);
3043 return get_textfont_propl(This, FONT_ITALIC, value);
3046 static HRESULT WINAPI TextFont_SetItalic(ITextFont *iface, LONG value)
3048 ITextFontImpl *This = impl_from_ITextFont(iface);
3049 TRACE("(%p)->(%d)\n", This, value);
3050 return set_textfont_propd(This, FONT_ITALIC, value);
3053 static HRESULT WINAPI TextFont_GetKerning(ITextFont *iface, FLOAT *value)
3055 ITextFontImpl *This = impl_from_ITextFont(iface);
3056 TRACE("(%p)->(%p)\n", This, value);
3057 return get_textfont_propf(This, FONT_KERNING, value);
3060 static HRESULT WINAPI TextFont_SetKerning(ITextFont *iface, FLOAT value)
3062 ITextFontImpl *This = impl_from_ITextFont(iface);
3063 TRACE("(%p)->(%.2f)\n", This, value);
3064 return set_textfont_propf(This, FONT_KERNING, value);
3067 static HRESULT WINAPI TextFont_GetLanguageID(ITextFont *iface, LONG *value)
3069 ITextFontImpl *This = impl_from_ITextFont(iface);
3070 TRACE("(%p)->(%p)\n", This, value);
3071 return get_textfont_propl(This, FONT_LANGID, value);
3074 static HRESULT WINAPI TextFont_SetLanguageID(ITextFont *iface, LONG value)
3076 ITextFontImpl *This = impl_from_ITextFont(iface);
3077 TRACE("(%p)->(%d)\n", This, value);
3078 return set_textfont_propl(This, FONT_LANGID, value);
3081 static HRESULT WINAPI TextFont_GetName(ITextFont *iface, BSTR *value)
3083 ITextFontImpl *This = impl_from_ITextFont(iface);
3085 TRACE("(%p)->(%p)\n", This, value);
3087 if (!value)
3088 return E_INVALIDARG;
3090 *value = NULL;
3092 if (!This->range) {
3093 if (This->props[FONT_NAME].str)
3094 *value = SysAllocString(This->props[FONT_NAME].str);
3095 else
3096 *value = SysAllocStringLen(NULL, 0);
3097 return *value ? S_OK : E_OUTOFMEMORY;
3100 return textfont_getname_from_range(This->range, value);
3103 static HRESULT WINAPI TextFont_SetName(ITextFont *iface, BSTR value)
3105 ITextFontImpl *This = impl_from_ITextFont(iface);
3106 textfont_prop_val v;
3108 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
3110 v.str = value;
3111 return set_textfont_prop(This, FONT_NAME, &v);
3114 static HRESULT WINAPI TextFont_GetOutline(ITextFont *iface, LONG *value)
3116 ITextFontImpl *This = impl_from_ITextFont(iface);
3117 TRACE("(%p)->(%p)\n", This, value);
3118 return get_textfont_propl(This, FONT_OUTLINE, value);
3121 static HRESULT WINAPI TextFont_SetOutline(ITextFont *iface, LONG value)
3123 ITextFontImpl *This = impl_from_ITextFont(iface);
3124 TRACE("(%p)->(%d)\n", This, value);
3125 return set_textfont_propd(This, FONT_OUTLINE, value);
3128 static HRESULT WINAPI TextFont_GetPosition(ITextFont *iface, FLOAT *value)
3130 ITextFontImpl *This = impl_from_ITextFont(iface);
3131 TRACE("(%p)->(%p)\n", This, value);
3132 return get_textfont_propf(This, FONT_POSITION, value);
3135 static HRESULT WINAPI TextFont_SetPosition(ITextFont *iface, FLOAT value)
3137 ITextFontImpl *This = impl_from_ITextFont(iface);
3138 TRACE("(%p)->(%.2f)\n", This, value);
3139 return set_textfont_propf(This, FONT_POSITION, value);
3142 static HRESULT WINAPI TextFont_GetProtected(ITextFont *iface, LONG *value)
3144 ITextFontImpl *This = impl_from_ITextFont(iface);
3145 TRACE("(%p)->(%p)\n", This, value);
3146 return get_textfont_propl(This, FONT_PROTECTED, value);
3149 static HRESULT WINAPI TextFont_SetProtected(ITextFont *iface, LONG value)
3151 ITextFontImpl *This = impl_from_ITextFont(iface);
3152 TRACE("(%p)->(%d)\n", This, value);
3153 return set_textfont_propd(This, FONT_PROTECTED, value);
3156 static HRESULT WINAPI TextFont_GetShadow(ITextFont *iface, LONG *value)
3158 ITextFontImpl *This = impl_from_ITextFont(iface);
3159 TRACE("(%p)->(%p)\n", This, value);
3160 return get_textfont_propl(This, FONT_SHADOW, value);
3163 static HRESULT WINAPI TextFont_SetShadow(ITextFont *iface, LONG value)
3165 ITextFontImpl *This = impl_from_ITextFont(iface);
3166 TRACE("(%p)->(%d)\n", This, value);
3167 return set_textfont_propd(This, FONT_SHADOW, value);
3170 static HRESULT WINAPI TextFont_GetSize(ITextFont *iface, FLOAT *value)
3172 ITextFontImpl *This = impl_from_ITextFont(iface);
3173 TRACE("(%p)->(%p)\n", This, value);
3174 return get_textfont_propf(This, FONT_SIZE, value);
3177 static HRESULT WINAPI TextFont_SetSize(ITextFont *iface, FLOAT value)
3179 ITextFontImpl *This = impl_from_ITextFont(iface);
3180 TRACE("(%p)->(%.2f)\n", This, value);
3181 return set_textfont_propf(This, FONT_SIZE, value);
3184 static HRESULT WINAPI TextFont_GetSmallCaps(ITextFont *iface, LONG *value)
3186 ITextFontImpl *This = impl_from_ITextFont(iface);
3187 TRACE("(%p)->(%p)\n", This, value);
3188 return get_textfont_propl(This, FONT_SMALLCAPS, value);
3191 static HRESULT WINAPI TextFont_SetSmallCaps(ITextFont *iface, LONG value)
3193 ITextFontImpl *This = impl_from_ITextFont(iface);
3194 TRACE("(%p)->(%d)\n", This, value);
3195 return set_textfont_propd(This, FONT_SMALLCAPS, value);
3198 static HRESULT WINAPI TextFont_GetSpacing(ITextFont *iface, FLOAT *value)
3200 ITextFontImpl *This = impl_from_ITextFont(iface);
3201 TRACE("(%p)->(%p)\n", This, value);
3202 return get_textfont_propf(This, FONT_SPACING, value);
3205 static HRESULT WINAPI TextFont_SetSpacing(ITextFont *iface, FLOAT value)
3207 ITextFontImpl *This = impl_from_ITextFont(iface);
3208 TRACE("(%p)->(%.2f)\n", This, value);
3209 return set_textfont_propf(This, FONT_SPACING, value);
3212 static HRESULT WINAPI TextFont_GetStrikeThrough(ITextFont *iface, LONG *value)
3214 ITextFontImpl *This = impl_from_ITextFont(iface);
3215 TRACE("(%p)->(%p)\n", This, value);
3216 return get_textfont_propl(This, FONT_STRIKETHROUGH, value);
3219 static HRESULT WINAPI TextFont_SetStrikeThrough(ITextFont *iface, LONG value)
3221 ITextFontImpl *This = impl_from_ITextFont(iface);
3222 TRACE("(%p)->(%d)\n", This, value);
3223 return set_textfont_propd(This, FONT_STRIKETHROUGH, value);
3226 static HRESULT WINAPI TextFont_GetSubscript(ITextFont *iface, LONG *value)
3228 ITextFontImpl *This = impl_from_ITextFont(iface);
3229 TRACE("(%p)->(%p)\n", This, value);
3230 return get_textfont_propl(This, FONT_SUBSCRIPT, value);
3233 static HRESULT WINAPI TextFont_SetSubscript(ITextFont *iface, LONG value)
3235 ITextFontImpl *This = impl_from_ITextFont(iface);
3236 TRACE("(%p)->(%d)\n", This, value);
3237 return set_textfont_propd(This, FONT_SUBSCRIPT, value);
3240 static HRESULT WINAPI TextFont_GetSuperscript(ITextFont *iface, LONG *value)
3242 ITextFontImpl *This = impl_from_ITextFont(iface);
3243 TRACE("(%p)->(%p)\n", This, value);
3244 return get_textfont_propl(This, FONT_SUPERSCRIPT, value);
3247 static HRESULT WINAPI TextFont_SetSuperscript(ITextFont *iface, LONG value)
3249 ITextFontImpl *This = impl_from_ITextFont(iface);
3250 TRACE("(%p)->(%d)\n", This, value);
3251 return set_textfont_propd(This, FONT_SUPERSCRIPT, value);
3254 static HRESULT WINAPI TextFont_GetUnderline(ITextFont *iface, LONG *value)
3256 ITextFontImpl *This = impl_from_ITextFont(iface);
3257 TRACE("(%p)->(%p)\n", This, value);
3258 return get_textfont_propl(This, FONT_UNDERLINE, value);
3261 static HRESULT WINAPI TextFont_SetUnderline(ITextFont *iface, LONG value)
3263 ITextFontImpl *This = impl_from_ITextFont(iface);
3264 TRACE("(%p)->(%d)\n", This, value);
3265 return set_textfont_propd(This, FONT_UNDERLINE, value);
3268 static HRESULT WINAPI TextFont_GetWeight(ITextFont *iface, LONG *value)
3270 ITextFontImpl *This = impl_from_ITextFont(iface);
3271 TRACE("(%p)->(%p)\n", This, value);
3272 return get_textfont_propl(This, FONT_WEIGHT, value);
3275 static HRESULT WINAPI TextFont_SetWeight(ITextFont *iface, LONG value)
3277 ITextFontImpl *This = impl_from_ITextFont(iface);
3278 TRACE("(%p)->(%d)\n", This, value);
3279 return set_textfont_propl(This, FONT_WEIGHT, value);
3282 static ITextFontVtbl textfontvtbl = {
3283 TextFont_QueryInterface,
3284 TextFont_AddRef,
3285 TextFont_Release,
3286 TextFont_GetTypeInfoCount,
3287 TextFont_GetTypeInfo,
3288 TextFont_GetIDsOfNames,
3289 TextFont_Invoke,
3290 TextFont_GetDuplicate,
3291 TextFont_SetDuplicate,
3292 TextFont_CanChange,
3293 TextFont_IsEqual,
3294 TextFont_Reset,
3295 TextFont_GetStyle,
3296 TextFont_SetStyle,
3297 TextFont_GetAllCaps,
3298 TextFont_SetAllCaps,
3299 TextFont_GetAnimation,
3300 TextFont_SetAnimation,
3301 TextFont_GetBackColor,
3302 TextFont_SetBackColor,
3303 TextFont_GetBold,
3304 TextFont_SetBold,
3305 TextFont_GetEmboss,
3306 TextFont_SetEmboss,
3307 TextFont_GetForeColor,
3308 TextFont_SetForeColor,
3309 TextFont_GetHidden,
3310 TextFont_SetHidden,
3311 TextFont_GetEngrave,
3312 TextFont_SetEngrave,
3313 TextFont_GetItalic,
3314 TextFont_SetItalic,
3315 TextFont_GetKerning,
3316 TextFont_SetKerning,
3317 TextFont_GetLanguageID,
3318 TextFont_SetLanguageID,
3319 TextFont_GetName,
3320 TextFont_SetName,
3321 TextFont_GetOutline,
3322 TextFont_SetOutline,
3323 TextFont_GetPosition,
3324 TextFont_SetPosition,
3325 TextFont_GetProtected,
3326 TextFont_SetProtected,
3327 TextFont_GetShadow,
3328 TextFont_SetShadow,
3329 TextFont_GetSize,
3330 TextFont_SetSize,
3331 TextFont_GetSmallCaps,
3332 TextFont_SetSmallCaps,
3333 TextFont_GetSpacing,
3334 TextFont_SetSpacing,
3335 TextFont_GetStrikeThrough,
3336 TextFont_SetStrikeThrough,
3337 TextFont_GetSubscript,
3338 TextFont_SetSubscript,
3339 TextFont_GetSuperscript,
3340 TextFont_SetSuperscript,
3341 TextFont_GetUnderline,
3342 TextFont_SetUnderline,
3343 TextFont_GetWeight,
3344 TextFont_SetWeight
3347 static HRESULT create_textfont(ITextRange *range, const ITextFontImpl *src, ITextFont **ret)
3349 ITextFontImpl *font;
3351 *ret = NULL;
3352 font = heap_alloc(sizeof(*font));
3353 if (!font)
3354 return E_OUTOFMEMORY;
3356 font->ITextFont_iface.lpVtbl = &textfontvtbl;
3357 font->ref = 1;
3359 if (src) {
3360 font->range = NULL;
3361 font->get_cache_enabled = TRUE;
3362 font->set_cache_enabled = TRUE;
3363 memcpy(&font->props, &src->props, sizeof(font->props));
3364 if (font->props[FONT_NAME].str)
3365 font->props[FONT_NAME].str = SysAllocString(font->props[FONT_NAME].str);
3367 else {
3368 font->range = range;
3369 ITextRange_AddRef(range);
3371 /* cache current properties */
3372 font->get_cache_enabled = FALSE;
3373 font->set_cache_enabled = FALSE;
3374 textfont_cache_range_props(font);
3377 *ret = &font->ITextFont_iface;
3378 return S_OK;
3381 /* ITextPara */
3382 static HRESULT WINAPI TextPara_QueryInterface(ITextPara *iface, REFIID riid, void **ppv)
3384 ITextParaImpl *This = impl_from_ITextPara(iface);
3386 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
3388 if (IsEqualIID(riid, &IID_ITextPara) ||
3389 IsEqualIID(riid, &IID_IDispatch) ||
3390 IsEqualIID(riid, &IID_IUnknown))
3392 *ppv = iface;
3393 ITextPara_AddRef(iface);
3394 return S_OK;
3397 *ppv = NULL;
3398 return E_NOINTERFACE;
3401 static ULONG WINAPI TextPara_AddRef(ITextPara *iface)
3403 ITextParaImpl *This = impl_from_ITextPara(iface);
3404 ULONG ref = InterlockedIncrement(&This->ref);
3405 TRACE("(%p)->(%u)\n", This, ref);
3406 return ref;
3409 static ULONG WINAPI TextPara_Release(ITextPara *iface)
3411 ITextParaImpl *This = impl_from_ITextPara(iface);
3412 ULONG ref = InterlockedDecrement(&This->ref);
3414 TRACE("(%p)->(%u)\n", This, ref);
3416 if (!ref)
3418 ITextRange_Release(This->range);
3419 heap_free(This);
3422 return ref;
3425 static HRESULT WINAPI TextPara_GetTypeInfoCount(ITextPara *iface, UINT *pctinfo)
3427 ITextParaImpl *This = impl_from_ITextPara(iface);
3428 TRACE("(%p)->(%p)\n", This, pctinfo);
3429 *pctinfo = 1;
3430 return S_OK;
3433 static HRESULT WINAPI TextPara_GetTypeInfo(ITextPara *iface, UINT iTInfo, LCID lcid,
3434 ITypeInfo **ppTInfo)
3436 ITextParaImpl *This = impl_from_ITextPara(iface);
3437 HRESULT hr;
3439 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3441 hr = get_typeinfo(ITextPara_tid, ppTInfo);
3442 if (SUCCEEDED(hr))
3443 ITypeInfo_AddRef(*ppTInfo);
3444 return hr;
3447 static HRESULT WINAPI TextPara_GetIDsOfNames(ITextPara *iface, REFIID riid,
3448 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3450 ITextParaImpl *This = impl_from_ITextPara(iface);
3451 ITypeInfo *ti;
3452 HRESULT hr;
3454 TRACE("(%p)->(%s, %p, %u, %d, %p)\n", This, debugstr_guid(riid), rgszNames,
3455 cNames, lcid, rgDispId);
3457 hr = get_typeinfo(ITextPara_tid, &ti);
3458 if (SUCCEEDED(hr))
3459 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3460 return hr;
3463 static HRESULT WINAPI TextPara_Invoke(
3464 ITextPara *iface,
3465 DISPID dispIdMember,
3466 REFIID riid,
3467 LCID lcid,
3468 WORD wFlags,
3469 DISPPARAMS *pDispParams,
3470 VARIANT *pVarResult,
3471 EXCEPINFO *pExcepInfo,
3472 UINT *puArgErr)
3474 ITextParaImpl *This = impl_from_ITextPara(iface);
3475 ITypeInfo *ti;
3476 HRESULT hr;
3478 TRACE("(%p)->(%d, %s, %d, %u, %p, %p, %p, %p)\n", This, dispIdMember,
3479 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult,
3480 pExcepInfo, puArgErr);
3482 hr = get_typeinfo(ITextPara_tid, &ti);
3483 if (SUCCEEDED(hr))
3484 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3485 return hr;
3488 static HRESULT WINAPI TextPara_GetDuplicate(ITextPara *iface, ITextPara **ret)
3490 ITextParaImpl *This = impl_from_ITextPara(iface);
3491 FIXME("(%p)->(%p)\n", This, ret);
3492 return E_NOTIMPL;
3495 static HRESULT WINAPI TextPara_SetDuplicate(ITextPara *iface, ITextPara *para)
3497 ITextParaImpl *This = impl_from_ITextPara(iface);
3498 FIXME("(%p)->(%p)\n", This, para);
3499 return E_NOTIMPL;
3502 static HRESULT WINAPI TextPara_CanChange(ITextPara *iface, LONG *ret)
3504 ITextParaImpl *This = impl_from_ITextPara(iface);
3505 FIXME("(%p)->(%p)\n", This, ret);
3506 return E_NOTIMPL;
3509 static HRESULT WINAPI TextPara_IsEqual(ITextPara *iface, ITextPara *para, LONG *ret)
3511 ITextParaImpl *This = impl_from_ITextPara(iface);
3512 FIXME("(%p)->(%p %p)\n", This, para, ret);
3513 return E_NOTIMPL;
3516 static HRESULT WINAPI TextPara_Reset(ITextPara *iface, LONG value)
3518 ITextParaImpl *This = impl_from_ITextPara(iface);
3519 FIXME("(%p)->(%d)\n", This, value);
3520 return E_NOTIMPL;
3523 static HRESULT WINAPI TextPara_GetStyle(ITextPara *iface, LONG *value)
3525 ITextParaImpl *This = impl_from_ITextPara(iface);
3526 FIXME("(%p)->(%p)\n", This, value);
3527 return E_NOTIMPL;
3530 static HRESULT WINAPI TextPara_SetStyle(ITextPara *iface, LONG value)
3532 ITextParaImpl *This = impl_from_ITextPara(iface);
3533 FIXME("(%p)->(%d)\n", This, value);
3534 return E_NOTIMPL;
3537 static HRESULT WINAPI TextPara_GetAlignment(ITextPara *iface, LONG *value)
3539 ITextParaImpl *This = impl_from_ITextPara(iface);
3540 FIXME("(%p)->(%p)\n", This, value);
3541 return E_NOTIMPL;
3544 static HRESULT WINAPI TextPara_SetAlignment(ITextPara *iface, LONG value)
3546 ITextParaImpl *This = impl_from_ITextPara(iface);
3547 FIXME("(%p)->(%d)\n", This, value);
3548 return E_NOTIMPL;
3551 static HRESULT WINAPI TextPara_GetHyphenation(ITextPara *iface, LONG *value)
3553 ITextParaImpl *This = impl_from_ITextPara(iface);
3554 FIXME("(%p)->(%p)\n", This, value);
3555 return E_NOTIMPL;
3558 static HRESULT WINAPI TextPara_SetHyphenation(ITextPara *iface, LONG value)
3560 ITextParaImpl *This = impl_from_ITextPara(iface);
3561 FIXME("(%p)->(%d)\n", This, value);
3562 return E_NOTIMPL;
3565 static HRESULT WINAPI TextPara_GetFirstLineIndent(ITextPara *iface, FLOAT *value)
3567 ITextParaImpl *This = impl_from_ITextPara(iface);
3568 FIXME("(%p)->(%p)\n", This, value);
3569 return E_NOTIMPL;
3572 static HRESULT WINAPI TextPara_GetKeepTogether(ITextPara *iface, LONG *value)
3574 ITextParaImpl *This = impl_from_ITextPara(iface);
3575 FIXME("(%p)->(%p)\n", This, value);
3576 return E_NOTIMPL;
3579 static HRESULT WINAPI TextPara_SetKeepTogether(ITextPara *iface, LONG value)
3581 ITextParaImpl *This = impl_from_ITextPara(iface);
3582 FIXME("(%p)->(%d)\n", This, value);
3583 return E_NOTIMPL;
3586 static HRESULT WINAPI TextPara_GetKeepWithNext(ITextPara *iface, LONG *value)
3588 ITextParaImpl *This = impl_from_ITextPara(iface);
3589 FIXME("(%p)->(%p)\n", This, value);
3590 return E_NOTIMPL;
3593 static HRESULT WINAPI TextPara_SetKeepWithNext(ITextPara *iface, LONG value)
3595 ITextParaImpl *This = impl_from_ITextPara(iface);
3596 FIXME("(%p)->(%d)\n", This, value);
3597 return E_NOTIMPL;
3600 static HRESULT WINAPI TextPara_GetLeftIndent(ITextPara *iface, FLOAT *value)
3602 ITextParaImpl *This = impl_from_ITextPara(iface);
3603 FIXME("(%p)->(%p)\n", This, value);
3604 return E_NOTIMPL;
3607 static HRESULT WINAPI TextPara_GetLineSpacing(ITextPara *iface, FLOAT *value)
3609 ITextParaImpl *This = impl_from_ITextPara(iface);
3610 FIXME("(%p)->(%p)\n", This, value);
3611 return E_NOTIMPL;
3614 static HRESULT WINAPI TextPara_GetLineSpacingRule(ITextPara *iface, LONG *value)
3616 ITextParaImpl *This = impl_from_ITextPara(iface);
3617 FIXME("(%p)->(%p)\n", This, value);
3618 return E_NOTIMPL;
3621 static HRESULT WINAPI TextPara_GetListAlignment(ITextPara *iface, LONG *value)
3623 ITextParaImpl *This = impl_from_ITextPara(iface);
3624 FIXME("(%p)->(%p)\n", This, value);
3625 return E_NOTIMPL;
3628 static HRESULT WINAPI TextPara_SetListAlignment(ITextPara *iface, LONG value)
3630 ITextParaImpl *This = impl_from_ITextPara(iface);
3631 FIXME("(%p)->(%d)\n", This, value);
3632 return E_NOTIMPL;
3635 static HRESULT WINAPI TextPara_GetListLevelIndex(ITextPara *iface, LONG *value)
3637 ITextParaImpl *This = impl_from_ITextPara(iface);
3638 FIXME("(%p)->(%p)\n", This, value);
3639 return E_NOTIMPL;
3642 static HRESULT WINAPI TextPara_SetListLevelIndex(ITextPara *iface, LONG value)
3644 ITextParaImpl *This = impl_from_ITextPara(iface);
3645 FIXME("(%p)->(%d)\n", This, value);
3646 return E_NOTIMPL;
3649 static HRESULT WINAPI TextPara_GetListStart(ITextPara *iface, LONG *value)
3651 ITextParaImpl *This = impl_from_ITextPara(iface);
3652 FIXME("(%p)->(%p)\n", This, value);
3653 return E_NOTIMPL;
3656 static HRESULT WINAPI TextPara_SetListStart(ITextPara *iface, LONG value)
3658 ITextParaImpl *This = impl_from_ITextPara(iface);
3659 FIXME("(%p)->(%d)\n", This, value);
3660 return E_NOTIMPL;
3663 static HRESULT WINAPI TextPara_GetListTab(ITextPara *iface, FLOAT *value)
3665 ITextParaImpl *This = impl_from_ITextPara(iface);
3666 FIXME("(%p)->(%p)\n", This, value);
3667 return E_NOTIMPL;
3670 static HRESULT WINAPI TextPara_SetListTab(ITextPara *iface, FLOAT value)
3672 ITextParaImpl *This = impl_from_ITextPara(iface);
3673 FIXME("(%p)->(%.2f)\n", This, value);
3674 return E_NOTIMPL;
3677 static HRESULT WINAPI TextPara_GetListType(ITextPara *iface, LONG *value)
3679 ITextParaImpl *This = impl_from_ITextPara(iface);
3680 FIXME("(%p)->(%p)\n", This, value);
3681 return E_NOTIMPL;
3684 static HRESULT WINAPI TextPara_SetListType(ITextPara *iface, LONG value)
3686 ITextParaImpl *This = impl_from_ITextPara(iface);
3687 FIXME("(%p)->(%d)\n", This, value);
3688 return E_NOTIMPL;
3691 static HRESULT WINAPI TextPara_GetNoLineNumber(ITextPara *iface, LONG *value)
3693 ITextParaImpl *This = impl_from_ITextPara(iface);
3694 FIXME("(%p)->(%p)\n", This, value);
3695 return E_NOTIMPL;
3698 static HRESULT WINAPI TextPara_SetNoLineNumber(ITextPara *iface, LONG value)
3700 ITextParaImpl *This = impl_from_ITextPara(iface);
3701 FIXME("(%p)->(%d)\n", This, value);
3702 return E_NOTIMPL;
3705 static HRESULT WINAPI TextPara_GetPageBreakBefore(ITextPara *iface, LONG *value)
3707 ITextParaImpl *This = impl_from_ITextPara(iface);
3708 FIXME("(%p)->(%p)\n", This, value);
3709 return E_NOTIMPL;
3712 static HRESULT WINAPI TextPara_SetPageBreakBefore(ITextPara *iface, LONG value)
3714 ITextParaImpl *This = impl_from_ITextPara(iface);
3715 FIXME("(%p)->(%d)\n", This, value);
3716 return E_NOTIMPL;
3719 static HRESULT WINAPI TextPara_GetRightIndent(ITextPara *iface, FLOAT *value)
3721 ITextParaImpl *This = impl_from_ITextPara(iface);
3722 FIXME("(%p)->(%p)\n", This, value);
3723 return E_NOTIMPL;
3726 static HRESULT WINAPI TextPara_SetRightIndent(ITextPara *iface, FLOAT value)
3728 ITextParaImpl *This = impl_from_ITextPara(iface);
3729 FIXME("(%p)->(%.2f)\n", This, value);
3730 return E_NOTIMPL;
3733 static HRESULT WINAPI TextPara_SetIndents(ITextPara *iface, FLOAT StartIndent, FLOAT LeftIndent, FLOAT RightIndent)
3735 ITextParaImpl *This = impl_from_ITextPara(iface);
3736 FIXME("(%p)->(%.2f %.2f %.2f)\n", This, StartIndent, LeftIndent, RightIndent);
3737 return E_NOTIMPL;
3740 static HRESULT WINAPI TextPara_SetLineSpacing(ITextPara *iface, LONG LineSpacingRule, FLOAT LineSpacing)
3742 ITextParaImpl *This = impl_from_ITextPara(iface);
3743 FIXME("(%p)->(%d %.2f)\n", This, LineSpacingRule, LineSpacing);
3744 return E_NOTIMPL;
3747 static HRESULT WINAPI TextPara_GetSpaceAfter(ITextPara *iface, FLOAT *value)
3749 ITextParaImpl *This = impl_from_ITextPara(iface);
3750 FIXME("(%p)->(%p)\n", This, value);
3751 return E_NOTIMPL;
3754 static HRESULT WINAPI TextPara_SetSpaceAfter(ITextPara *iface, FLOAT value)
3756 ITextParaImpl *This = impl_from_ITextPara(iface);
3757 FIXME("(%p)->(%.2f)\n", This, value);
3758 return E_NOTIMPL;
3761 static HRESULT WINAPI TextPara_GetSpaceBefore(ITextPara *iface, FLOAT *value)
3763 ITextParaImpl *This = impl_from_ITextPara(iface);
3764 FIXME("(%p)->(%p)\n", This, value);
3765 return E_NOTIMPL;
3768 static HRESULT WINAPI TextPara_SetSpaceBefore(ITextPara *iface, FLOAT value)
3770 ITextParaImpl *This = impl_from_ITextPara(iface);
3771 FIXME("(%p)->(%.2f)\n", This, value);
3772 return E_NOTIMPL;
3775 static HRESULT WINAPI TextPara_GetWidowControl(ITextPara *iface, LONG *value)
3777 ITextParaImpl *This = impl_from_ITextPara(iface);
3778 FIXME("(%p)->(%p)\n", This, value);
3779 return E_NOTIMPL;
3782 static HRESULT WINAPI TextPara_SetWidowControl(ITextPara *iface, LONG value)
3784 ITextParaImpl *This = impl_from_ITextPara(iface);
3785 FIXME("(%p)->(%d)\n", This, value);
3786 return E_NOTIMPL;
3789 static HRESULT WINAPI TextPara_GetTabCount(ITextPara *iface, LONG *value)
3791 ITextParaImpl *This = impl_from_ITextPara(iface);
3792 FIXME("(%p)->(%p)\n", This, value);
3793 return E_NOTIMPL;
3796 static HRESULT WINAPI TextPara_AddTab(ITextPara *iface, FLOAT tbPos, LONG tbAlign, LONG tbLeader)
3798 ITextParaImpl *This = impl_from_ITextPara(iface);
3799 FIXME("(%p)->(%.2f %d %d)\n", This, tbPos, tbAlign, tbLeader);
3800 return E_NOTIMPL;
3803 static HRESULT WINAPI TextPara_ClearAllTabs(ITextPara *iface)
3805 ITextParaImpl *This = impl_from_ITextPara(iface);
3806 FIXME("(%p)\n", This);
3807 return E_NOTIMPL;
3810 static HRESULT WINAPI TextPara_DeleteTab(ITextPara *iface, FLOAT pos)
3812 ITextParaImpl *This = impl_from_ITextPara(iface);
3813 FIXME("(%p)->(%.2f)\n", This, pos);
3814 return E_NOTIMPL;
3817 static HRESULT WINAPI TextPara_GetTab(ITextPara *iface, LONG iTab, FLOAT *ptbPos, LONG *ptbAlign, LONG *ptbLeader)
3819 ITextParaImpl *This = impl_from_ITextPara(iface);
3820 FIXME("(%p)->(%d %p %p %p)\n", This, iTab, ptbPos, ptbAlign, ptbLeader);
3821 return E_NOTIMPL;
3824 static ITextParaVtbl textparavtbl = {
3825 TextPara_QueryInterface,
3826 TextPara_AddRef,
3827 TextPara_Release,
3828 TextPara_GetTypeInfoCount,
3829 TextPara_GetTypeInfo,
3830 TextPara_GetIDsOfNames,
3831 TextPara_Invoke,
3832 TextPara_GetDuplicate,
3833 TextPara_SetDuplicate,
3834 TextPara_CanChange,
3835 TextPara_IsEqual,
3836 TextPara_Reset,
3837 TextPara_GetStyle,
3838 TextPara_SetStyle,
3839 TextPara_GetAlignment,
3840 TextPara_SetAlignment,
3841 TextPara_GetHyphenation,
3842 TextPara_SetHyphenation,
3843 TextPara_GetFirstLineIndent,
3844 TextPara_GetKeepTogether,
3845 TextPara_SetKeepTogether,
3846 TextPara_GetKeepWithNext,
3847 TextPara_SetKeepWithNext,
3848 TextPara_GetLeftIndent,
3849 TextPara_GetLineSpacing,
3850 TextPara_GetLineSpacingRule,
3851 TextPara_GetListAlignment,
3852 TextPara_SetListAlignment,
3853 TextPara_GetListLevelIndex,
3854 TextPara_SetListLevelIndex,
3855 TextPara_GetListStart,
3856 TextPara_SetListStart,
3857 TextPara_GetListTab,
3858 TextPara_SetListTab,
3859 TextPara_GetListType,
3860 TextPara_SetListType,
3861 TextPara_GetNoLineNumber,
3862 TextPara_SetNoLineNumber,
3863 TextPara_GetPageBreakBefore,
3864 TextPara_SetPageBreakBefore,
3865 TextPara_GetRightIndent,
3866 TextPara_SetRightIndent,
3867 TextPara_SetIndents,
3868 TextPara_SetLineSpacing,
3869 TextPara_GetSpaceAfter,
3870 TextPara_SetSpaceAfter,
3871 TextPara_GetSpaceBefore,
3872 TextPara_SetSpaceBefore,
3873 TextPara_GetWidowControl,
3874 TextPara_SetWidowControl,
3875 TextPara_GetTabCount,
3876 TextPara_AddTab,
3877 TextPara_ClearAllTabs,
3878 TextPara_DeleteTab,
3879 TextPara_GetTab
3882 static HRESULT create_textpara(ITextRange *range, ITextPara **ret)
3884 ITextParaImpl *para;
3886 *ret = NULL;
3887 para = heap_alloc(sizeof(*para));
3888 if (!para)
3889 return E_OUTOFMEMORY;
3891 para->ITextPara_iface.lpVtbl = &textparavtbl;
3892 para->ref = 1;
3893 para->range = range;
3894 ITextRange_AddRef(range);
3896 *ret = &para->ITextPara_iface;
3897 return S_OK;
3900 /* ITextDocument */
3901 static HRESULT WINAPI ITextDocument2Old_fnQueryInterface(ITextDocument2Old* iface, REFIID riid,
3902 void **ppvObject)
3904 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3905 return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
3908 static ULONG WINAPI ITextDocument2Old_fnAddRef(ITextDocument2Old *iface)
3910 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3911 return IRichEditOle_AddRef(&This->IRichEditOle_iface);
3914 static ULONG WINAPI ITextDocument2Old_fnRelease(ITextDocument2Old *iface)
3916 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3917 return IRichEditOle_Release(&This->IRichEditOle_iface);
3920 static HRESULT WINAPI ITextDocument2Old_fnGetTypeInfoCount(ITextDocument2Old *iface,
3921 UINT *pctinfo)
3923 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3924 TRACE("(%p)->(%p)\n", This, pctinfo);
3925 *pctinfo = 1;
3926 return S_OK;
3929 static HRESULT WINAPI ITextDocument2Old_fnGetTypeInfo(ITextDocument2Old *iface, UINT iTInfo, LCID lcid,
3930 ITypeInfo **ppTInfo)
3932 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3933 HRESULT hr;
3935 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3937 hr = get_typeinfo(ITextDocument_tid, ppTInfo);
3938 if (SUCCEEDED(hr))
3939 ITypeInfo_AddRef(*ppTInfo);
3940 return hr;
3943 static HRESULT WINAPI ITextDocument2Old_fnGetIDsOfNames(ITextDocument2Old *iface, REFIID riid,
3944 LPOLESTR *rgszNames, UINT cNames,
3945 LCID lcid, DISPID *rgDispId)
3947 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3948 ITypeInfo *ti;
3949 HRESULT hr;
3951 TRACE("(%p)->(%s, %p, %u, %d, %p)\n", This, debugstr_guid(riid),
3952 rgszNames, cNames, lcid, rgDispId);
3954 hr = get_typeinfo(ITextDocument_tid, &ti);
3955 if (SUCCEEDED(hr))
3956 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3957 return hr;
3960 static HRESULT WINAPI ITextDocument2Old_fnInvoke(ITextDocument2Old *iface, DISPID dispIdMember,
3961 REFIID riid, LCID lcid, WORD wFlags,
3962 DISPPARAMS *pDispParams, VARIANT *pVarResult,
3963 EXCEPINFO *pExcepInfo, UINT *puArgErr)
3965 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3966 ITypeInfo *ti;
3967 HRESULT hr;
3969 TRACE("(%p)->(%d, %s, %d, %u, %p, %p, %p, %p)\n", This, dispIdMember,
3970 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult,
3971 pExcepInfo, puArgErr);
3973 hr = get_typeinfo(ITextDocument_tid, &ti);
3974 if (SUCCEEDED(hr))
3975 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3976 return hr;
3979 static HRESULT WINAPI ITextDocument2Old_fnGetName(ITextDocument2Old *iface, BSTR *pName)
3981 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3982 FIXME("stub %p\n",This);
3983 return E_NOTIMPL;
3986 static HRESULT WINAPI ITextDocument2Old_fnGetSelection(ITextDocument2Old *iface, ITextSelection **selection)
3988 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
3990 TRACE("(%p)->(%p)\n", iface, selection);
3992 if (!selection)
3993 return E_INVALIDARG;
3995 if (!This->txtSel) {
3996 This->txtSel = CreateTextSelection(This);
3997 if (!This->txtSel) {
3998 *selection = NULL;
3999 return E_OUTOFMEMORY;
4003 *selection = &This->txtSel->ITextSelection_iface;
4004 ITextSelection_AddRef(*selection);
4005 return S_OK;
4008 static HRESULT WINAPI ITextDocument2Old_fnGetStoryCount(ITextDocument2Old *iface, LONG *pCount)
4010 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4011 FIXME("stub %p\n",This);
4012 return E_NOTIMPL;
4015 static HRESULT WINAPI ITextDocument2Old_fnGetStoryRanges(ITextDocument2Old *iface,
4016 ITextStoryRanges **ppStories)
4018 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4019 FIXME("stub %p\n",This);
4020 return E_NOTIMPL;
4023 static HRESULT WINAPI ITextDocument2Old_fnGetSaved(ITextDocument2Old *iface, LONG *pValue)
4025 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4026 FIXME("stub %p\n",This);
4027 return E_NOTIMPL;
4030 static HRESULT WINAPI ITextDocument2Old_fnSetSaved(ITextDocument2Old *iface, LONG Value)
4032 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4033 FIXME("stub %p\n",This);
4034 return E_NOTIMPL;
4037 static HRESULT WINAPI ITextDocument2Old_fnGetDefaultTabStop(ITextDocument2Old *iface, float *pValue)
4039 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4040 FIXME("stub %p\n",This);
4041 return E_NOTIMPL;
4044 static HRESULT WINAPI ITextDocument2Old_fnSetDefaultTabStop(ITextDocument2Old *iface, float Value)
4046 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4047 FIXME("stub %p\n",This);
4048 return E_NOTIMPL;
4051 static HRESULT WINAPI ITextDocument2Old_fnNew(ITextDocument2Old *iface)
4053 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4054 FIXME("stub %p\n",This);
4055 return E_NOTIMPL;
4058 static HRESULT WINAPI ITextDocument2Old_fnOpen(ITextDocument2Old *iface, VARIANT *pVar,
4059 LONG Flags, LONG CodePage)
4061 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4062 FIXME("stub %p\n",This);
4063 return E_NOTIMPL;
4066 static HRESULT WINAPI ITextDocument2Old_fnSave(ITextDocument2Old *iface, VARIANT *pVar,
4067 LONG Flags, LONG CodePage)
4069 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4070 FIXME("stub %p\n",This);
4071 return E_NOTIMPL;
4074 static HRESULT WINAPI ITextDocument2Old_fnFreeze(ITextDocument2Old *iface, LONG *pCount)
4076 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4077 FIXME("stub %p\n",This);
4078 return E_NOTIMPL;
4081 static HRESULT WINAPI ITextDocument2Old_fnUnfreeze(ITextDocument2Old *iface, LONG *pCount)
4083 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4084 FIXME("stub %p\n",This);
4085 return E_NOTIMPL;
4088 static HRESULT WINAPI ITextDocument2Old_fnBeginEditCollection(ITextDocument2Old *iface)
4090 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4091 FIXME("stub %p\n",This);
4092 return E_NOTIMPL;
4095 static HRESULT WINAPI ITextDocument2Old_fnEndEditCollection(ITextDocument2Old *iface)
4097 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4098 FIXME("stub %p\n",This);
4099 return E_NOTIMPL;
4102 static HRESULT WINAPI ITextDocument2Old_fnUndo(ITextDocument2Old *iface, LONG Count, LONG *prop)
4104 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4105 FIXME("stub %p\n",This);
4106 return E_NOTIMPL;
4109 static HRESULT WINAPI ITextDocument2Old_fnRedo(ITextDocument2Old *iface, LONG Count, LONG *prop)
4111 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4112 FIXME("stub %p\n",This);
4113 return E_NOTIMPL;
4116 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
4118 ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
4120 if (!txtRge)
4121 return E_OUTOFMEMORY;
4122 txtRge->ITextRange_iface.lpVtbl = &trvt;
4123 txtRge->ref = 1;
4124 txtRge->child.reole = reOle;
4125 txtRge->start = start;
4126 txtRge->end = end;
4127 list_add_head(&reOle->rangelist, &txtRge->child.entry);
4128 *ppRange = &txtRge->ITextRange_iface;
4129 return S_OK;
4132 static HRESULT WINAPI ITextDocument2Old_fnRange(ITextDocument2Old *iface, LONG cp1, LONG cp2,
4133 ITextRange **ppRange)
4135 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4137 TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
4138 if (!ppRange)
4139 return E_INVALIDARG;
4141 cp2range(This->editor, &cp1, &cp2);
4142 return CreateITextRange(This, cp1, cp2, ppRange);
4145 static HRESULT WINAPI ITextDocument2Old_fnRangeFromPoint(ITextDocument2Old *iface, LONG x, LONG y,
4146 ITextRange **ppRange)
4148 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4149 FIXME("stub %p\n",This);
4150 return E_NOTIMPL;
4153 /* ITextDocument2Old methods */
4154 static HRESULT WINAPI ITextDocument2Old_fnAttachMsgFilter(ITextDocument2Old *iface, IUnknown *filter)
4156 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4158 FIXME("(%p)->(%p): stub\n", This, filter);
4160 return E_NOTIMPL;
4163 static HRESULT WINAPI ITextDocument2Old_fnSetEffectColor(ITextDocument2Old *iface, LONG index, COLORREF cr)
4165 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4167 FIXME("(%p)->(%d, 0x%x): stub\n", This, index, cr);
4169 return E_NOTIMPL;
4172 static HRESULT WINAPI ITextDocument2Old_fnGetEffectColor(ITextDocument2Old *iface, LONG index, COLORREF *cr)
4174 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4176 FIXME("(%p)->(%d, %p): stub\n", This, index, cr);
4178 return E_NOTIMPL;
4181 static HRESULT WINAPI ITextDocument2Old_fnGetCaretType(ITextDocument2Old *iface, LONG *type)
4183 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4185 FIXME("(%p)->(%p): stub\n", This, type);
4187 return E_NOTIMPL;
4190 static HRESULT WINAPI ITextDocument2Old_fnSetCaretType(ITextDocument2Old *iface, LONG type)
4192 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4194 FIXME("(%p)->(%d): stub\n", This, type);
4196 return E_NOTIMPL;
4199 static HRESULT WINAPI ITextDocument2Old_fnGetImmContext(ITextDocument2Old *iface, LONG *context)
4201 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4203 FIXME("(%p)->(%p): stub\n", This, context);
4205 return E_NOTIMPL;
4208 static HRESULT WINAPI ITextDocument2Old_fnReleaseImmContext(ITextDocument2Old *iface, LONG context)
4210 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4212 FIXME("(%p)->(%d): stub\n", This, context);
4214 return E_NOTIMPL;
4217 static HRESULT WINAPI ITextDocument2Old_fnGetPreferredFont(ITextDocument2Old *iface, LONG cp, LONG charrep,
4218 LONG options, LONG current_charrep, LONG current_fontsize,
4219 BSTR *bstr, LONG *pitch_family, LONG *new_fontsize)
4221 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4223 FIXME("(%p)->(%d, %d, %d, %d, %d, %p, %p, %p): stub\n", This, cp, charrep, options, current_charrep,
4224 current_fontsize, bstr, pitch_family, new_fontsize);
4226 return E_NOTIMPL;
4229 static HRESULT WINAPI ITextDocument2Old_fnGetNotificationMode(ITextDocument2Old *iface, LONG *mode)
4231 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4233 FIXME("(%p)->(%p): stub\n", This, mode);
4235 return E_NOTIMPL;
4238 static HRESULT WINAPI ITextDocument2Old_fnSetNotificationMode(ITextDocument2Old *iface, LONG mode)
4240 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4242 FIXME("(%p)->(0x%x): stub\n", This, mode);
4244 return E_NOTIMPL;
4247 static HRESULT WINAPI ITextDocument2Old_fnGetClientRect(ITextDocument2Old *iface, LONG type, LONG *left, LONG *top,
4248 LONG *right, LONG *bottom)
4250 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4252 FIXME("(%p)->(%d, %p, %p, %p, %p): stub\n", This, type, left, top, right, bottom);
4254 return E_NOTIMPL;
4257 static HRESULT WINAPI ITextDocument2Old_fnGetSelectionEx(ITextDocument2Old *iface, ITextSelection **selection)
4259 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4261 FIXME("(%p)->(%p): stub\n", This, selection);
4263 return E_NOTIMPL;
4266 static HRESULT WINAPI ITextDocument2Old_fnGetWindow(ITextDocument2Old *iface, LONG *hwnd)
4268 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4270 FIXME("(%p)->(%p): stub\n", This, hwnd);
4272 return E_NOTIMPL;
4275 static HRESULT WINAPI ITextDocument2Old_fnGetFEFlags(ITextDocument2Old *iface, LONG *flags)
4277 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4279 FIXME("(%p)->(%p): stub\n", This, flags);
4281 return E_NOTIMPL;
4284 static HRESULT WINAPI ITextDocument2Old_fnUpdateWindow(ITextDocument2Old *iface)
4286 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4288 FIXME("(%p): stub\n", This);
4290 return E_NOTIMPL;
4293 static HRESULT WINAPI ITextDocument2Old_fnCheckTextLimit(ITextDocument2Old *iface, LONG cch, LONG *exceed)
4295 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4297 FIXME("(%p)->(%d, %p): stub\n", This, cch, exceed);
4299 return E_NOTIMPL;
4302 static HRESULT WINAPI ITextDocument2Old_fnIMEInProgress(ITextDocument2Old *iface, LONG mode)
4304 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4306 FIXME("(%p)->(0x%x): stub\n", This, mode);
4308 return E_NOTIMPL;
4311 static HRESULT WINAPI ITextDocument2Old_fnSysBeep(ITextDocument2Old *iface)
4313 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4315 FIXME("(%p): stub\n", This);
4317 return E_NOTIMPL;
4320 static HRESULT WINAPI ITextDocument2Old_fnUpdate(ITextDocument2Old *iface, LONG mode)
4322 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4324 FIXME("(%p)->(0x%x): stub\n", This, mode);
4326 return E_NOTIMPL;
4329 static HRESULT WINAPI ITextDocument2Old_fnNotify(ITextDocument2Old *iface, LONG notify)
4331 IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
4333 FIXME("(%p)->(%d): stub\n", This, notify);
4335 return E_NOTIMPL;
4338 static const ITextDocument2OldVtbl tdvt = {
4339 ITextDocument2Old_fnQueryInterface,
4340 ITextDocument2Old_fnAddRef,
4341 ITextDocument2Old_fnRelease,
4342 ITextDocument2Old_fnGetTypeInfoCount,
4343 ITextDocument2Old_fnGetTypeInfo,
4344 ITextDocument2Old_fnGetIDsOfNames,
4345 ITextDocument2Old_fnInvoke,
4346 ITextDocument2Old_fnGetName,
4347 ITextDocument2Old_fnGetSelection,
4348 ITextDocument2Old_fnGetStoryCount,
4349 ITextDocument2Old_fnGetStoryRanges,
4350 ITextDocument2Old_fnGetSaved,
4351 ITextDocument2Old_fnSetSaved,
4352 ITextDocument2Old_fnGetDefaultTabStop,
4353 ITextDocument2Old_fnSetDefaultTabStop,
4354 ITextDocument2Old_fnNew,
4355 ITextDocument2Old_fnOpen,
4356 ITextDocument2Old_fnSave,
4357 ITextDocument2Old_fnFreeze,
4358 ITextDocument2Old_fnUnfreeze,
4359 ITextDocument2Old_fnBeginEditCollection,
4360 ITextDocument2Old_fnEndEditCollection,
4361 ITextDocument2Old_fnUndo,
4362 ITextDocument2Old_fnRedo,
4363 ITextDocument2Old_fnRange,
4364 ITextDocument2Old_fnRangeFromPoint,
4365 /* ITextDocument2Old methods */
4366 ITextDocument2Old_fnAttachMsgFilter,
4367 ITextDocument2Old_fnSetEffectColor,
4368 ITextDocument2Old_fnGetEffectColor,
4369 ITextDocument2Old_fnGetCaretType,
4370 ITextDocument2Old_fnSetCaretType,
4371 ITextDocument2Old_fnGetImmContext,
4372 ITextDocument2Old_fnReleaseImmContext,
4373 ITextDocument2Old_fnGetPreferredFont,
4374 ITextDocument2Old_fnGetNotificationMode,
4375 ITextDocument2Old_fnSetNotificationMode,
4376 ITextDocument2Old_fnGetClientRect,
4377 ITextDocument2Old_fnGetSelectionEx,
4378 ITextDocument2Old_fnGetWindow,
4379 ITextDocument2Old_fnGetFEFlags,
4380 ITextDocument2Old_fnUpdateWindow,
4381 ITextDocument2Old_fnCheckTextLimit,
4382 ITextDocument2Old_fnIMEInProgress,
4383 ITextDocument2Old_fnSysBeep,
4384 ITextDocument2Old_fnUpdate,
4385 ITextDocument2Old_fnNotify
4388 /* ITextSelection */
4389 static HRESULT WINAPI ITextSelection_fnQueryInterface(
4390 ITextSelection *me,
4391 REFIID riid,
4392 void **ppvObj)
4394 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4396 *ppvObj = NULL;
4397 if (IsEqualGUID(riid, &IID_IUnknown)
4398 || IsEqualGUID(riid, &IID_IDispatch)
4399 || IsEqualGUID(riid, &IID_ITextRange)
4400 || IsEqualGUID(riid, &IID_ITextSelection))
4402 *ppvObj = me;
4403 ITextSelection_AddRef(me);
4404 return S_OK;
4406 else if (IsEqualGUID(riid, &IID_Igetrichole))
4408 *ppvObj = This->reOle;
4409 return S_OK;
4412 return E_NOINTERFACE;
4415 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
4417 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4418 return InterlockedIncrement(&This->ref);
4421 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
4423 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4424 ULONG ref = InterlockedDecrement(&This->ref);
4425 if (ref == 0)
4426 heap_free(This);
4427 return ref;
4430 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
4432 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4433 TRACE("(%p)->(%p)\n", This, pctinfo);
4434 *pctinfo = 1;
4435 return S_OK;
4438 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
4439 ITypeInfo **ppTInfo)
4441 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4442 HRESULT hr;
4444 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
4446 hr = get_typeinfo(ITextSelection_tid, ppTInfo);
4447 if (SUCCEEDED(hr))
4448 ITypeInfo_AddRef(*ppTInfo);
4449 return hr;
4452 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
4453 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4455 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4456 ITypeInfo *ti;
4457 HRESULT hr;
4459 TRACE("(%p)->(%s, %p, %u, %d, %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid,
4460 rgDispId);
4462 hr = get_typeinfo(ITextSelection_tid, &ti);
4463 if (SUCCEEDED(hr))
4464 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
4465 return hr;
4468 static HRESULT WINAPI ITextSelection_fnInvoke(
4469 ITextSelection *me,
4470 DISPID dispIdMember,
4471 REFIID riid,
4472 LCID lcid,
4473 WORD wFlags,
4474 DISPPARAMS *pDispParams,
4475 VARIANT *pVarResult,
4476 EXCEPINFO *pExcepInfo,
4477 UINT *puArgErr)
4479 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4480 ITypeInfo *ti;
4481 HRESULT hr;
4483 TRACE("(%p)->(%d, %s, %d, %u, %p, %p, %p, %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
4484 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
4486 hr = get_typeinfo(ITextSelection_tid, &ti);
4487 if (SUCCEEDED(hr))
4488 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
4489 return hr;
4492 /*** ITextRange methods ***/
4493 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
4495 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4496 ME_Cursor *start = NULL, *end = NULL;
4497 int nChars, endOfs;
4498 BOOL bEOP;
4500 TRACE("(%p)->(%p)\n", This, pbstr);
4502 if (!This->reOle)
4503 return CO_E_RELEASED;
4505 if (!pbstr)
4506 return E_INVALIDARG;
4508 ME_GetSelection(This->reOle->editor, &start, &end);
4509 endOfs = ME_GetCursorOfs(end);
4510 nChars = endOfs - ME_GetCursorOfs(start);
4511 if (!nChars)
4513 *pbstr = NULL;
4514 return S_OK;
4517 *pbstr = SysAllocStringLen(NULL, nChars);
4518 if (!*pbstr)
4519 return E_OUTOFMEMORY;
4521 bEOP = (end->pRun->next->type == diTextEnd && endOfs > ME_GetTextLength(This->reOle->editor));
4522 ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
4523 TRACE("%s\n", wine_dbgstr_w(*pbstr));
4525 return S_OK;
4528 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR str)
4530 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4531 ME_TextEditor *editor;
4532 int len, to, from;
4534 TRACE("(%p)->(%s)\n", This, debugstr_w(str));
4536 if (!This->reOle)
4537 return CO_E_RELEASED;
4539 editor = This->reOle->editor;
4540 len = lstrlenW(str);
4541 ME_GetSelectionOfs(editor, &from, &to);
4542 ME_ReplaceSel(editor, FALSE, str, len);
4544 if (len < to - from)
4545 textranges_update_ranges(This->reOle, from, len, RANGE_UPDATE_DELETE);
4547 return S_OK;
4550 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
4552 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4553 ME_Cursor *start = NULL, *end = NULL;
4555 TRACE("(%p)->(%p)\n", This, pch);
4557 if (!This->reOle)
4558 return CO_E_RELEASED;
4560 if (!pch)
4561 return E_INVALIDARG;
4563 ME_GetSelection(This->reOle->editor, &start, &end);
4564 return range_GetChar(This->reOle->editor, start, pch);
4567 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
4569 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4571 FIXME("(%p)->(%x): stub\n", This, ch);
4573 if (!This->reOle)
4574 return CO_E_RELEASED;
4576 return E_NOTIMPL;
4579 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **range)
4581 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4582 LONG start, end;
4584 TRACE("(%p)->(%p)\n", This, range);
4586 if (!This->reOle)
4587 return CO_E_RELEASED;
4589 if (!range)
4590 return E_INVALIDARG;
4592 ITextSelection_GetStart(me, &start);
4593 ITextSelection_GetEnd(me, &end);
4594 return CreateITextRange(This->reOle, start, end, range);
4597 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **range)
4599 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4601 FIXME("(%p)->(%p): stub\n", This, range);
4603 if (!This->reOle)
4604 return CO_E_RELEASED;
4606 return E_NOTIMPL;
4609 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *range)
4611 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4613 FIXME("(%p)->(%p): stub\n", This, range);
4615 if (!This->reOle)
4616 return CO_E_RELEASED;
4618 FIXME("not implemented\n");
4619 return E_NOTIMPL;
4622 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
4624 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4625 LONG lim;
4627 TRACE("(%p)->(%p)\n", This, pcpFirst);
4629 if (!This->reOle)
4630 return CO_E_RELEASED;
4632 if (!pcpFirst)
4633 return E_INVALIDARG;
4634 ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim);
4635 return S_OK;
4638 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG value)
4640 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4641 LONG start, end;
4642 HRESULT hr;
4644 TRACE("(%p)->(%d)\n", This, value);
4646 if (!This->reOle)
4647 return CO_E_RELEASED;
4649 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
4650 hr = textrange_setstart(This->reOle, value, &start, &end);
4651 if (hr == S_OK)
4652 set_selection(This->reOle->editor, start, end);
4654 return hr;
4657 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
4659 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4660 LONG first;
4662 TRACE("(%p)->(%p)\n", This, pcpLim);
4664 if (!This->reOle)
4665 return CO_E_RELEASED;
4667 if (!pcpLim)
4668 return E_INVALIDARG;
4669 ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim);
4670 return S_OK;
4673 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG value)
4675 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4676 LONG start, end;
4677 HRESULT hr;
4679 TRACE("(%p)->(%d)\n", This, value);
4681 if (!This->reOle)
4682 return CO_E_RELEASED;
4684 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
4685 hr = textrange_setend(This->reOle, value, &start, &end);
4686 if (hr == S_OK)
4687 set_selection(This->reOle->editor, start, end);
4689 return hr;
4692 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **font)
4694 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4695 ITextRange *range = NULL;
4696 HRESULT hr;
4698 TRACE("(%p)->(%p)\n", This, font);
4700 if (!This->reOle)
4701 return CO_E_RELEASED;
4703 if (!font)
4704 return E_INVALIDARG;
4706 ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
4707 hr = create_textfont(range, NULL, font);
4708 ITextRange_Release(range);
4709 return hr;
4712 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *font)
4714 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4715 ITextRange *range = NULL;
4717 TRACE("(%p)->(%p)\n", This, font);
4719 if (!font)
4720 return E_INVALIDARG;
4722 if (!This->reOle)
4723 return CO_E_RELEASED;
4725 ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
4726 textrange_set_font(range, font);
4727 ITextRange_Release(range);
4728 return S_OK;
4731 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **para)
4733 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4734 ITextRange *range = NULL;
4735 HRESULT hr;
4737 TRACE("(%p)->(%p)\n", This, para);
4739 if (!This->reOle)
4740 return CO_E_RELEASED;
4742 if (!para)
4743 return E_INVALIDARG;
4745 ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
4746 hr = create_textpara(range, para);
4747 ITextRange_Release(range);
4748 return hr;
4751 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *para)
4753 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4755 FIXME("(%p)->(%p): stub\n", This, para);
4757 if (!This->reOle)
4758 return CO_E_RELEASED;
4760 FIXME("not implemented\n");
4761 return E_NOTIMPL;
4764 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *length)
4766 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4768 TRACE("(%p)->(%p)\n", This, length);
4770 if (!This->reOle)
4771 return CO_E_RELEASED;
4773 return textrange_get_storylength(This->reOle->editor, length);
4776 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *value)
4778 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4780 TRACE("(%p)->(%p)\n", This, value);
4782 if (!This->reOle)
4783 return CO_E_RELEASED;
4785 if (!value)
4786 return E_INVALIDARG;
4788 *value = tomUnknownStory;
4789 return S_OK;
4792 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
4794 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4795 LONG start, end;
4796 HRESULT hres;
4798 TRACE("(%p)->(%d)\n", This, bStart);
4800 if (!This->reOle)
4801 return CO_E_RELEASED;
4803 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
4804 hres = range_Collapse(bStart, &start, &end);
4805 if (SUCCEEDED(hres))
4806 set_selection(This->reOle->editor, start, end);
4807 return hres;
4810 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG unit, LONG *delta)
4812 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4813 ITextRange *range = NULL;
4814 HRESULT hr;
4816 TRACE("(%p)->(%d %p)\n", This, unit, delta);
4818 if (!This->reOle)
4819 return CO_E_RELEASED;
4821 ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
4822 hr = textrange_expand(range, unit, delta);
4823 ITextRange_Release(range);
4824 return hr;
4827 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG unit, LONG *index)
4829 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4831 FIXME("(%p)->(%d %p): stub\n", This, unit, index);
4833 if (!This->reOle)
4834 return CO_E_RELEASED;
4836 return E_NOTIMPL;
4839 static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG unit, LONG index,
4840 LONG extend)
4842 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4844 FIXME("(%p)->(%d %d %d): stub\n", This, unit, index, extend);
4846 if (!This->reOle)
4847 return CO_E_RELEASED;
4849 return E_NOTIMPL;
4852 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG anchor, LONG active)
4854 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4856 FIXME("(%p)->(%d %d): stub\n", This, anchor, active);
4858 if (!This->reOle)
4859 return CO_E_RELEASED;
4861 return E_NOTIMPL;
4864 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *range, LONG *ret)
4866 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4867 ITextSelection *selection = NULL;
4868 LONG start, end;
4870 TRACE("(%p)->(%p %p)\n", This, range, ret);
4872 if (ret)
4873 *ret = tomFalse;
4875 if (!This->reOle)
4876 return CO_E_RELEASED;
4878 if (!range)
4879 return S_FALSE;
4881 ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&selection);
4882 if (!selection)
4883 return S_FALSE;
4884 ITextSelection_Release(selection);
4886 ITextSelection_GetStart(me, &start);
4887 ITextSelection_GetEnd(me, &end);
4888 return textrange_inrange(start, end, range, ret);
4891 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *range, LONG *ret)
4893 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4895 FIXME("(%p)->(%p %p): stub\n", This, range, ret);
4897 if (!This->reOle)
4898 return CO_E_RELEASED;
4900 return E_NOTIMPL;
4903 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *range, LONG *ret)
4905 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4906 ITextSelection *selection = NULL;
4907 LONG start, end;
4909 TRACE("(%p)->(%p %p)\n", This, range, ret);
4911 if (ret)
4912 *ret = tomFalse;
4914 if (!This->reOle)
4915 return CO_E_RELEASED;
4917 if (!range)
4918 return S_FALSE;
4920 ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&selection);
4921 if (!selection)
4922 return S_FALSE;
4923 ITextSelection_Release(selection);
4925 ITextSelection_GetStart(me, &start);
4926 ITextSelection_GetEnd(me, &end);
4927 return textrange_isequal(start, end, range, ret);
4930 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
4932 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4934 TRACE("(%p)\n", This);
4936 if (!This->reOle)
4937 return CO_E_RELEASED;
4939 /* nothing to do */
4940 return S_OK;
4943 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG unit, LONG extend,
4944 LONG *delta)
4946 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4948 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
4950 if (!This->reOle)
4951 return CO_E_RELEASED;
4953 return E_NOTIMPL;
4956 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG unit, LONG extend,
4957 LONG *delta)
4959 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4961 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
4963 if (!This->reOle)
4964 return CO_E_RELEASED;
4966 return E_NOTIMPL;
4969 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG unit, LONG count, LONG *delta)
4971 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4973 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
4975 if (!This->reOle)
4976 return CO_E_RELEASED;
4978 return E_NOTIMPL;
4981 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG unit, LONG count,
4982 LONG *delta)
4984 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4986 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
4988 if (!This->reOle)
4989 return CO_E_RELEASED;
4991 return E_NOTIMPL;
4994 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG unit, LONG count,
4995 LONG *delta)
4997 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4998 ITextRange *range = NULL;
4999 HRESULT hr;
5001 TRACE("(%p)->(%d %d %p)\n", This, unit, count, delta);
5003 if (!This->reOle)
5004 return CO_E_RELEASED;
5006 ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
5007 hr = textrange_moveend(range, unit, count, delta);
5008 ITextRange_Release(range);
5009 return hr;
5012 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *charset, LONG count,
5013 LONG *delta)
5015 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5017 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
5019 if (!This->reOle)
5020 return CO_E_RELEASED;
5022 return E_NOTIMPL;
5025 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *charset, LONG count,
5026 LONG *delta)
5028 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5030 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
5032 if (!This->reOle)
5033 return CO_E_RELEASED;
5035 return E_NOTIMPL;
5038 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *charset, LONG count,
5039 LONG *delta)
5041 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5043 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
5045 if (!This->reOle)
5046 return CO_E_RELEASED;
5048 return E_NOTIMPL;
5051 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *charset, LONG count,
5052 LONG *delta)
5054 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5056 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
5058 if (!This->reOle)
5059 return CO_E_RELEASED;
5061 return E_NOTIMPL;
5064 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *charset, LONG count,
5065 LONG *delta)
5067 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5069 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
5071 if (!This->reOle)
5072 return CO_E_RELEASED;
5074 return E_NOTIMPL;
5077 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *charset, LONG count,
5078 LONG *delta)
5080 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5082 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
5084 if (!This->reOle)
5085 return CO_E_RELEASED;
5087 return E_NOTIMPL;
5090 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR text, LONG count, LONG flags,
5091 LONG *length)
5093 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5095 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
5097 if (!This->reOle)
5098 return CO_E_RELEASED;
5100 FIXME("not implemented\n");
5101 return E_NOTIMPL;
5104 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR text, LONG count,
5105 LONG flags, LONG *length)
5107 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5109 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
5111 if (!This->reOle)
5112 return CO_E_RELEASED;
5114 return E_NOTIMPL;
5117 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR text, LONG count,
5118 LONG flags, LONG *length)
5120 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5122 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
5124 if (!This->reOle)
5125 return CO_E_RELEASED;
5127 return E_NOTIMPL;
5130 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG unit, LONG count,
5131 LONG *delta)
5133 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5135 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
5137 if (!This->reOle)
5138 return CO_E_RELEASED;
5140 return E_NOTIMPL;
5143 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *v)
5145 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5147 FIXME("(%p)->(%p): stub\n", This, v);
5149 if (!This->reOle)
5150 return CO_E_RELEASED;
5152 return E_NOTIMPL;
5155 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *v)
5157 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5159 FIXME("(%p)->(%p): stub\n", This, v);
5161 if (!This->reOle)
5162 return CO_E_RELEASED;
5164 return E_NOTIMPL;
5167 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *v, LONG format)
5169 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5171 FIXME("(%p)->(%s %x): stub\n", This, debugstr_variant(v), format);
5173 if (!This->reOle)
5174 return CO_E_RELEASED;
5176 return E_NOTIMPL;
5179 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *v, LONG format,
5180 LONG *ret)
5182 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5184 FIXME("(%p)->(%s %x %p): stub\n", This, debugstr_variant(v), format, ret);
5186 if (!This->reOle)
5187 return CO_E_RELEASED;
5189 return E_NOTIMPL;
5192 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *ret)
5194 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5196 FIXME("(%p)->(%p): stub\n", This, ret);
5198 if (!This->reOle)
5199 return CO_E_RELEASED;
5201 return E_NOTIMPL;
5204 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG type)
5206 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5208 FIXME("(%p)->(%d): stub\n", This, type);
5210 if (!This->reOle)
5211 return CO_E_RELEASED;
5213 return E_NOTIMPL;
5216 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG type, LONG *cx, LONG *cy)
5218 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5220 FIXME("(%p)->(%d %p %p): stub\n", This, type, cx, cy);
5222 if (!This->reOle)
5223 return CO_E_RELEASED;
5225 return E_NOTIMPL;
5228 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG type,
5229 LONG extend)
5231 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5233 FIXME("(%p)->(%d %d %d %d): stub\n", This, x, y, type, extend);
5235 if (!This->reOle)
5236 return CO_E_RELEASED;
5238 return E_NOTIMPL;
5241 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG value)
5243 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5245 FIXME("(%p)->(%d): stub\n", This, value);
5247 if (!This->reOle)
5248 return CO_E_RELEASED;
5250 return E_NOTIMPL;
5253 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
5255 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5257 FIXME("(%p)->(%p): stub\n", This, ppv);
5259 if (!This->reOle)
5260 return CO_E_RELEASED;
5262 return E_NOTIMPL;
5265 /*** ITextSelection methods ***/
5266 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *flags)
5268 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5270 FIXME("(%p)->(%p): stub\n", This, flags);
5272 if (!This->reOle)
5273 return CO_E_RELEASED;
5275 return E_NOTIMPL;
5278 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG flags)
5280 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5282 FIXME("(%p)->(%x): stub\n", This, flags);
5284 if (!This->reOle)
5285 return CO_E_RELEASED;
5287 return E_NOTIMPL;
5290 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *type)
5292 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5294 FIXME("(%p)->(%p): stub\n", This, type);
5296 if (!This->reOle)
5297 return CO_E_RELEASED;
5299 return E_NOTIMPL;
5302 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG unit, LONG count,
5303 LONG extend, LONG *delta)
5305 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5307 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5309 if (!This->reOle)
5310 return CO_E_RELEASED;
5312 return E_NOTIMPL;
5315 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG unit, LONG count,
5316 LONG extend, LONG *delta)
5318 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5320 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5322 if (!This->reOle)
5323 return CO_E_RELEASED;
5325 return E_NOTIMPL;
5328 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG unit, LONG count,
5329 LONG extend, LONG *delta)
5331 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5333 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5335 if (!This->reOle)
5336 return CO_E_RELEASED;
5338 return E_NOTIMPL;
5341 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG unit, LONG count,
5342 LONG extend, LONG *delta)
5344 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5346 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5348 if (!This->reOle)
5349 return CO_E_RELEASED;
5351 return E_NOTIMPL;
5354 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG unit, LONG extend,
5355 LONG *delta)
5357 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5359 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
5361 if (!This->reOle)
5362 return CO_E_RELEASED;
5364 return E_NOTIMPL;
5367 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG unit, LONG extend,
5368 LONG *delta)
5370 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5372 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
5374 if (!This->reOle)
5375 return CO_E_RELEASED;
5377 return E_NOTIMPL;
5380 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR text)
5382 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5384 FIXME("(%p)->(%s): stub\n", This, debugstr_w(text));
5386 if (!This->reOle)
5387 return CO_E_RELEASED;
5389 return E_NOTIMPL;
5392 static const ITextSelectionVtbl tsvt = {
5393 ITextSelection_fnQueryInterface,
5394 ITextSelection_fnAddRef,
5395 ITextSelection_fnRelease,
5396 ITextSelection_fnGetTypeInfoCount,
5397 ITextSelection_fnGetTypeInfo,
5398 ITextSelection_fnGetIDsOfNames,
5399 ITextSelection_fnInvoke,
5400 ITextSelection_fnGetText,
5401 ITextSelection_fnSetText,
5402 ITextSelection_fnGetChar,
5403 ITextSelection_fnSetChar,
5404 ITextSelection_fnGetDuplicate,
5405 ITextSelection_fnGetFormattedText,
5406 ITextSelection_fnSetFormattedText,
5407 ITextSelection_fnGetStart,
5408 ITextSelection_fnSetStart,
5409 ITextSelection_fnGetEnd,
5410 ITextSelection_fnSetEnd,
5411 ITextSelection_fnGetFont,
5412 ITextSelection_fnSetFont,
5413 ITextSelection_fnGetPara,
5414 ITextSelection_fnSetPara,
5415 ITextSelection_fnGetStoryLength,
5416 ITextSelection_fnGetStoryType,
5417 ITextSelection_fnCollapse,
5418 ITextSelection_fnExpand,
5419 ITextSelection_fnGetIndex,
5420 ITextSelection_fnSetIndex,
5421 ITextSelection_fnSetRange,
5422 ITextSelection_fnInRange,
5423 ITextSelection_fnInStory,
5424 ITextSelection_fnIsEqual,
5425 ITextSelection_fnSelect,
5426 ITextSelection_fnStartOf,
5427 ITextSelection_fnEndOf,
5428 ITextSelection_fnMove,
5429 ITextSelection_fnMoveStart,
5430 ITextSelection_fnMoveEnd,
5431 ITextSelection_fnMoveWhile,
5432 ITextSelection_fnMoveStartWhile,
5433 ITextSelection_fnMoveEndWhile,
5434 ITextSelection_fnMoveUntil,
5435 ITextSelection_fnMoveStartUntil,
5436 ITextSelection_fnMoveEndUntil,
5437 ITextSelection_fnFindText,
5438 ITextSelection_fnFindTextStart,
5439 ITextSelection_fnFindTextEnd,
5440 ITextSelection_fnDelete,
5441 ITextSelection_fnCut,
5442 ITextSelection_fnCopy,
5443 ITextSelection_fnPaste,
5444 ITextSelection_fnCanPaste,
5445 ITextSelection_fnCanEdit,
5446 ITextSelection_fnChangeCase,
5447 ITextSelection_fnGetPoint,
5448 ITextSelection_fnSetPoint,
5449 ITextSelection_fnScrollIntoView,
5450 ITextSelection_fnGetEmbeddedObject,
5451 ITextSelection_fnGetFlags,
5452 ITextSelection_fnSetFlags,
5453 ITextSelection_fnGetType,
5454 ITextSelection_fnMoveLeft,
5455 ITextSelection_fnMoveRight,
5456 ITextSelection_fnMoveUp,
5457 ITextSelection_fnMoveDown,
5458 ITextSelection_fnHomeKey,
5459 ITextSelection_fnEndKey,
5460 ITextSelection_fnTypeText
5463 static ITextSelectionImpl *
5464 CreateTextSelection(IRichEditOleImpl *reOle)
5466 ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
5467 if (!txtSel)
5468 return NULL;
5470 txtSel->ITextSelection_iface.lpVtbl = &tsvt;
5471 txtSel->ref = 1;
5472 txtSel->reOle = reOle;
5473 return txtSel;
5476 LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *ppvObj)
5478 IRichEditOleImpl *reo;
5480 reo = heap_alloc(sizeof(IRichEditOleImpl));
5481 if (!reo)
5482 return 0;
5484 reo->IUnknown_inner.lpVtbl = &reo_unk_vtbl;
5485 reo->IRichEditOle_iface.lpVtbl = &revt;
5486 reo->ITextDocument2Old_iface.lpVtbl = &tdvt;
5487 reo->ref = 1;
5488 reo->editor = editor;
5489 reo->txtSel = NULL;
5491 TRACE("Created %p\n",reo);
5492 list_init(&reo->rangelist);
5493 list_init(&reo->clientsites);
5494 if (outer_unk)
5495 reo->outer_unk = outer_unk;
5496 else
5497 reo->outer_unk = &reo->IUnknown_inner;
5498 *ppvObj = &reo->IUnknown_inner;
5500 return 1;
5503 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
5505 /* sizel is in .01 millimeters, sz in pixels */
5506 sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
5507 sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
5510 /******************************************************************************
5511 * ME_GetOLEObjectSize
5513 * Sets run extent for OLE objects.
5515 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
5517 IDataObject* ido;
5518 FORMATETC fmt;
5519 STGMEDIUM stgm;
5520 DIBSECTION dibsect;
5521 ENHMETAHEADER emh;
5523 assert(run->nFlags & MERF_GRAPHICS);
5524 assert(run->reobj);
5526 if (run->reobj->obj.sizel.cx != 0 || run->reobj->obj.sizel.cy != 0)
5528 convert_sizel(c, &run->reobj->obj.sizel, pSize);
5529 if (c->editor->nZoomNumerator != 0)
5531 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5532 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5534 return;
5537 if (!run->reobj->obj.poleobj)
5539 pSize->cx = pSize->cy = 0;
5540 return;
5543 if (IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
5545 FIXME("Query Interface IID_IDataObject failed!\n");
5546 pSize->cx = pSize->cy = 0;
5547 return;
5549 fmt.cfFormat = CF_BITMAP;
5550 fmt.ptd = NULL;
5551 fmt.dwAspect = DVASPECT_CONTENT;
5552 fmt.lindex = -1;
5553 fmt.tymed = TYMED_GDI;
5554 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5556 fmt.cfFormat = CF_ENHMETAFILE;
5557 fmt.tymed = TYMED_ENHMF;
5558 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5560 FIXME("unsupported format\n");
5561 pSize->cx = pSize->cy = 0;
5562 IDataObject_Release(ido);
5563 return;
5566 IDataObject_Release(ido);
5568 switch (stgm.tymed)
5570 case TYMED_GDI:
5571 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
5572 pSize->cx = dibsect.dsBm.bmWidth;
5573 pSize->cy = dibsect.dsBm.bmHeight;
5574 break;
5575 case TYMED_ENHMF:
5576 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
5577 pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
5578 pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
5579 break;
5580 default:
5581 FIXME("Unsupported tymed %d\n", stgm.tymed);
5582 break;
5584 ReleaseStgMedium(&stgm);
5585 if (c->editor->nZoomNumerator != 0)
5587 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5588 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5592 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run, BOOL selected)
5594 IDataObject* ido;
5595 FORMATETC fmt;
5596 STGMEDIUM stgm;
5597 DIBSECTION dibsect;
5598 ENHMETAHEADER emh;
5599 HDC hMemDC;
5600 SIZE sz;
5601 BOOL has_size;
5602 HBITMAP old_bm;
5603 RECT rc;
5605 assert(run->nFlags & MERF_GRAPHICS);
5606 assert(run->reobj);
5607 if (IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
5609 FIXME("Couldn't get interface\n");
5610 return;
5612 has_size = run->reobj->obj.sizel.cx != 0 || run->reobj->obj.sizel.cy != 0;
5613 fmt.cfFormat = CF_BITMAP;
5614 fmt.ptd = NULL;
5615 fmt.dwAspect = DVASPECT_CONTENT;
5616 fmt.lindex = -1;
5617 fmt.tymed = TYMED_GDI;
5618 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5620 fmt.cfFormat = CF_ENHMETAFILE;
5621 fmt.tymed = TYMED_ENHMF;
5622 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5624 FIXME("Couldn't get storage medium\n");
5625 IDataObject_Release(ido);
5626 return;
5629 IDataObject_Release(ido);
5631 switch (stgm.tymed)
5633 case TYMED_GDI:
5634 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
5635 hMemDC = CreateCompatibleDC(c->hDC);
5636 old_bm = SelectObject(hMemDC, stgm.u.hBitmap);
5637 if (has_size)
5639 convert_sizel(c, &run->reobj->obj.sizel, &sz);
5640 } else {
5641 sz.cx = dibsect.dsBm.bmWidth;
5642 sz.cy = dibsect.dsBm.bmHeight;
5644 if (c->editor->nZoomNumerator != 0)
5646 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5647 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5649 StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
5650 hMemDC, 0, 0, dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight, SRCCOPY);
5652 SelectObject(hMemDC, old_bm);
5653 DeleteDC(hMemDC);
5654 break;
5655 case TYMED_ENHMF:
5656 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
5657 if (has_size)
5659 convert_sizel(c, &run->reobj->obj.sizel, &sz);
5660 } else {
5661 sz.cx = emh.rclBounds.right - emh.rclBounds.left;
5662 sz.cy = emh.rclBounds.bottom - emh.rclBounds.top;
5664 if (c->editor->nZoomNumerator != 0)
5666 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5667 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5670 rc.left = x;
5671 rc.top = y - sz.cy;
5672 rc.right = x + sz.cx;
5673 rc.bottom = y;
5674 PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
5675 break;
5676 default:
5677 FIXME("Unsupported tymed %d\n", stgm.tymed);
5678 selected = FALSE;
5679 break;
5681 ReleaseStgMedium(&stgm);
5683 if (selected && !c->editor->bHideSelection)
5684 PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
5687 void ME_DeleteReObject(struct re_object *reobj)
5689 if (reobj->obj.poleobj) IOleObject_Release(reobj->obj.poleobj);
5690 if (reobj->obj.pstg) IStorage_Release(reobj->obj.pstg);
5691 if (reobj->obj.polesite) IOleClientSite_Release(reobj->obj.polesite);
5692 heap_free(reobj);
5695 void ME_CopyReObject(REOBJECT *dst, const REOBJECT *src, DWORD flags)
5697 *dst = *src;
5698 dst->poleobj = NULL;
5699 dst->pstg = NULL;
5700 dst->polesite = NULL;
5702 if ((flags & REO_GETOBJ_POLEOBJ) && src->poleobj)
5704 dst->poleobj = src->poleobj;
5705 IOleObject_AddRef(dst->poleobj);
5707 if ((flags & REO_GETOBJ_PSTG) && src->pstg)
5709 dst->pstg = src->pstg;
5710 IStorage_AddRef(dst->pstg);
5712 if ((flags & REO_GETOBJ_POLESITE) && src->polesite)
5714 dst->polesite = src->polesite;
5715 IOleClientSite_AddRef(dst->polesite);