ntdll/tests: Add some tests for registry path names.
[wine.git] / dlls / riched20 / richole.c
blobbe35521e029bf58a5e37b1ef1b5e0e978f3c1488
1 /*
2 * RichEdit GUIDs and OLE interface
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2004 Aric Stewart
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
24 #define NONAMELESSUNION
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "richole.h"
33 #include "editor.h"
34 #include "richedit.h"
35 #include "tom.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
40 /* there is no way to be consistent across different sets of headers - mingw, Wine, Win32 SDK*/
42 #include "initguid.h"
44 DEFINE_GUID(LIBID_tom, 0x8cc497c9, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
45 DEFINE_GUID(IID_ITextServices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
46 DEFINE_GUID(IID_ITextHost, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
47 DEFINE_GUID(IID_ITextHost2, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
48 DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
49 DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
50 DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
51 DEFINE_GUID(IID_ITextFont, 0x8cc497c3, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
52 DEFINE_GUID(IID_ITextPara, 0x8cc497c4, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
54 static ITypeLib *typelib;
56 enum tid_t {
57 NULL_tid,
58 ITextDocument_tid,
59 ITextRange_tid,
60 ITextSelection_tid,
61 ITextFont_tid,
62 ITextPara_tid,
63 LAST_tid
66 static const IID * const tid_ids[] =
68 &IID_NULL,
69 &IID_ITextDocument,
70 &IID_ITextRange,
71 &IID_ITextSelection,
72 &IID_ITextFont,
73 &IID_ITextPara,
75 static ITypeInfo *typeinfos[LAST_tid];
77 static HRESULT load_typelib(void)
79 ITypeLib *tl;
80 HRESULT hr;
82 hr = LoadRegTypeLib(&LIBID_tom, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
83 if (FAILED(hr)) {
84 ERR("LoadRegTypeLib failed: %08x\n", hr);
85 return hr;
88 if (InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
89 ITypeLib_Release(tl);
90 return hr;
93 void release_typelib(void)
95 unsigned i;
97 if (!typelib)
98 return;
100 for (i = 0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
101 if (typeinfos[i])
102 ITypeInfo_Release(typeinfos[i]);
104 ITypeLib_Release(typelib);
107 static HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo)
109 HRESULT hr;
111 if (!typelib)
112 hr = load_typelib();
113 if (!typelib)
114 return hr;
116 if (!typeinfos[tid])
118 ITypeInfo *ti;
120 hr = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
121 if (FAILED(hr))
123 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hr);
124 return hr;
127 if (InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
128 ITypeInfo_Release(ti);
131 *typeinfo = typeinfos[tid];
132 return S_OK;
135 /* private IID used to get back IRichEditOleImpl pointer */
136 DEFINE_GUID(IID_Igetrichole, 0xe3ce5c7a, 0x8247, 0x4622, 0x81, 0xad, 0x11, 0x81, 0x02, 0xaa, 0x01, 0x30);
138 typedef struct ITextSelectionImpl ITextSelectionImpl;
139 typedef struct IOleClientSiteImpl IOleClientSiteImpl;
140 typedef struct ITextRangeImpl ITextRangeImpl;
142 enum textfont_prop_id {
143 FONT_ALLCAPS = 0,
144 FONT_ANIMATION,
145 FONT_BACKCOLOR,
146 FONT_BOLD,
147 FONT_EMBOSS,
148 FONT_FORECOLOR,
149 FONT_HIDDEN,
150 FONT_ENGRAVE,
151 FONT_ITALIC,
152 FONT_KERNING,
153 FONT_LANGID,
154 FONT_NAME,
155 FONT_OUTLINE,
156 FONT_POSITION,
157 FONT_PROTECTED,
158 FONT_SHADOW,
159 FONT_SIZE,
160 FONT_SMALLCAPS,
161 FONT_SPACING,
162 FONT_STRIKETHROUGH,
163 FONT_SUBSCRIPT,
164 FONT_SUPERSCRIPT,
165 FONT_UNDERLINE,
166 FONT_WEIGHT,
167 FONT_PROPID_LAST,
168 FONT_PROPID_FIRST = FONT_ALLCAPS
171 static const DWORD textfont_prop_masks[][2] = {
172 { CFM_ALLCAPS, CFE_ALLCAPS },
173 { CFM_ANIMATION },
174 { CFM_BACKCOLOR, CFE_AUTOBACKCOLOR },
175 { CFM_BOLD, CFE_BOLD },
176 { CFM_EMBOSS, CFE_EMBOSS },
177 { CFM_COLOR, CFE_AUTOCOLOR },
178 { CFM_HIDDEN, CFE_HIDDEN },
179 { CFM_IMPRINT, CFE_IMPRINT },
180 { CFM_ITALIC, CFE_ITALIC },
181 { CFM_KERNING },
182 { CFM_LCID },
183 { CFM_FACE },
184 { CFM_OUTLINE, CFE_OUTLINE },
185 { CFM_OFFSET },
186 { CFM_PROTECTED, CFE_PROTECTED },
187 { CFM_SHADOW, CFE_SHADOW },
188 { CFM_SIZE },
189 { CFM_SMALLCAPS, CFE_SMALLCAPS },
190 { CFM_SPACING },
191 { CFM_STRIKEOUT, CFE_STRIKEOUT },
192 { CFM_SUBSCRIPT, CFE_SUBSCRIPT },
193 { CFM_SUPERSCRIPT, CFE_SUPERSCRIPT },
194 { CFM_UNDERLINE, CFE_UNDERLINE },
195 { CFM_WEIGHT }
198 typedef union {
199 FLOAT f;
200 LONG l;
201 BSTR str;
202 } textfont_prop_val;
204 enum range_update_op {
205 RANGE_UPDATE_DELETE
208 typedef struct IRichEditOleImpl {
209 IUnknown IUnknown_inner;
210 IRichEditOle IRichEditOle_iface;
211 ITextDocument ITextDocument_iface;
212 IUnknown *outer_unk;
213 LONG ref;
215 ME_TextEditor *editor;
216 ITextSelectionImpl *txtSel;
218 struct list rangelist;
219 struct list clientsites;
220 } IRichEditOleImpl;
222 struct reole_child {
223 struct list entry;
224 IRichEditOleImpl *reole;
227 struct ITextRangeImpl {
228 struct reole_child child;
229 ITextRange ITextRange_iface;
230 LONG ref;
231 LONG start, end;
234 struct ITextSelectionImpl {
235 ITextSelection ITextSelection_iface;
236 LONG ref;
238 IRichEditOleImpl *reOle;
241 typedef struct ITextFontImpl {
242 ITextFont ITextFont_iface;
243 LONG ref;
245 ITextRange *range;
246 textfont_prop_val props[FONT_PROPID_LAST];
247 BOOL get_cache_enabled;
248 BOOL set_cache_enabled;
249 } ITextFontImpl;
251 typedef struct ITextParaImpl {
252 ITextPara ITextPara_iface;
253 LONG ref;
255 ITextRange *range;
256 } ITextParaImpl;
258 struct IOleClientSiteImpl {
259 struct reole_child child;
260 IOleClientSite IOleClientSite_iface;
261 IOleWindow IOleWindow_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_ITextDocument(ITextDocument *iface)
273 return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument_iface);
276 static inline IRichEditOleImpl *impl_from_IUnknown(IUnknown *iface)
278 return CONTAINING_RECORD(iface, IRichEditOleImpl, IUnknown_inner);
281 static inline IOleClientSiteImpl *impl_from_IOleWindow(IOleWindow *iface)
283 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleWindow_iface);
286 static inline IOleClientSiteImpl *impl_from_IOleInPlaceSite(IOleInPlaceSite *iface)
288 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleInPlaceSite_iface);
291 static inline ITextRangeImpl *impl_from_ITextRange(ITextRange *iface)
293 return CONTAINING_RECORD(iface, ITextRangeImpl, ITextRange_iface);
296 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
298 return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
301 static inline ITextFontImpl *impl_from_ITextFont(ITextFont *iface)
303 return CONTAINING_RECORD(iface, ITextFontImpl, ITextFont_iface);
306 static inline ITextParaImpl *impl_from_ITextPara(ITextPara *iface)
308 return CONTAINING_RECORD(iface, ITextParaImpl, ITextPara_iface);
311 static HRESULT create_textfont(ITextRange*, const ITextFontImpl*, ITextFont**);
312 static HRESULT create_textpara(ITextRange*, ITextPara**);
313 static ITextSelectionImpl *CreateTextSelection(IRichEditOleImpl*);
315 static HRESULT textrange_get_storylength(ME_TextEditor *editor, LONG *length)
317 if (!length)
318 return E_INVALIDARG;
320 *length = ME_GetTextLength(editor) + 1;
321 return S_OK;
324 static void textranges_update_ranges(IRichEditOleImpl *reole, LONG start, LONG end, enum range_update_op op)
326 ITextRangeImpl *range;
328 LIST_FOR_EACH_ENTRY(range, &reole->rangelist, ITextRangeImpl, child.entry) {
329 switch (op)
331 case RANGE_UPDATE_DELETE:
332 /* range fully covered by deleted range - collapse to insertion point */
333 if (range->start >= start && range->end <= end)
334 range->start = range->end = start;
335 /* deleted range cuts from the right */
336 else if (range->start < start && range->end <= end)
337 range->end = start;
338 /* deleted range cuts from the left */
339 else if (range->start >= start && range->end > end) {
340 range->start = start;
341 range->end -= end - start;
343 /* deleted range cuts within */
344 else
345 range->end -= end - start;
346 break;
347 default:
348 FIXME("unknown update op, %d\n", op);
353 static inline BOOL is_equal_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *left,
354 textfont_prop_val *right)
356 switch (propid)
358 case FONT_ALLCAPS:
359 case FONT_ANIMATION:
360 case FONT_BACKCOLOR:
361 case FONT_BOLD:
362 case FONT_EMBOSS:
363 case FONT_FORECOLOR:
364 case FONT_HIDDEN:
365 case FONT_ENGRAVE:
366 case FONT_ITALIC:
367 case FONT_KERNING:
368 case FONT_LANGID:
369 case FONT_OUTLINE:
370 case FONT_PROTECTED:
371 case FONT_SHADOW:
372 case FONT_SMALLCAPS:
373 case FONT_STRIKETHROUGH:
374 case FONT_SUBSCRIPT:
375 case FONT_SUPERSCRIPT:
376 case FONT_UNDERLINE:
377 case FONT_WEIGHT:
378 return left->l == right->l;
379 case FONT_NAME:
380 return !strcmpW(left->str, right->str);
381 case FONT_POSITION:
382 case FONT_SIZE:
383 case FONT_SPACING:
384 return left->f == right->f;
385 default:
386 FIXME("unhandled font property %d\n", propid);
387 return FALSE;
391 static inline void init_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *v)
393 switch (propid)
395 case FONT_ALLCAPS:
396 case FONT_ANIMATION:
397 case FONT_BACKCOLOR:
398 case FONT_BOLD:
399 case FONT_EMBOSS:
400 case FONT_FORECOLOR:
401 case FONT_HIDDEN:
402 case FONT_ENGRAVE:
403 case FONT_ITALIC:
404 case FONT_KERNING:
405 case FONT_LANGID:
406 case FONT_OUTLINE:
407 case FONT_PROTECTED:
408 case FONT_SHADOW:
409 case FONT_SMALLCAPS:
410 case FONT_STRIKETHROUGH:
411 case FONT_SUBSCRIPT:
412 case FONT_SUPERSCRIPT:
413 case FONT_UNDERLINE:
414 case FONT_WEIGHT:
415 v->l = tomUndefined;
416 return;
417 case FONT_NAME:
418 v->str = NULL;
419 return;
420 case FONT_POSITION:
421 case FONT_SIZE:
422 case FONT_SPACING:
423 v->f = tomUndefined;
424 return;
425 default:
426 FIXME("unhandled font property %d\n", propid);
427 v->l = tomUndefined;
428 return;
432 static inline FLOAT twips_to_points(LONG value)
434 return value * 72.0 / 1440;
437 static inline FLOAT points_to_twips(FLOAT value)
439 return value * 1440 / 72.0;
442 static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid,
443 textfont_prop_val *value)
445 ME_Cursor from, to;
446 CHARFORMAT2W fmt;
448 memset(&fmt, 0, sizeof(fmt));
449 fmt.cbSize = sizeof(fmt);
450 fmt.dwMask = textfont_prop_masks[propid][0];
452 ME_CursorFromCharOfs(reole->editor, pos, &from);
453 to = from;
454 ME_MoveCursorChars(reole->editor, &to, 1);
455 ME_GetCharFormat(reole->editor, &from, &to, &fmt);
457 switch (propid)
459 case FONT_ALLCAPS:
460 case FONT_BOLD:
461 case FONT_EMBOSS:
462 case FONT_HIDDEN:
463 case FONT_ENGRAVE:
464 case FONT_ITALIC:
465 case FONT_OUTLINE:
466 case FONT_PROTECTED:
467 case FONT_SHADOW:
468 case FONT_SMALLCAPS:
469 case FONT_STRIKETHROUGH:
470 case FONT_SUBSCRIPT:
471 case FONT_SUPERSCRIPT:
472 case FONT_UNDERLINE:
473 value->l = fmt.dwEffects & textfont_prop_masks[propid][1] ? tomTrue : tomFalse;
474 break;
475 case FONT_ANIMATION:
476 value->l = fmt.bAnimation;
477 break;
478 case FONT_BACKCOLOR:
479 value->l = fmt.dwEffects & CFE_AUTOBACKCOLOR ? GetSysColor(COLOR_WINDOW) : fmt.crBackColor;
480 break;
481 case FONT_FORECOLOR:
482 value->l = fmt.dwEffects & CFE_AUTOCOLOR ? GetSysColor(COLOR_WINDOWTEXT) : fmt.crTextColor;
483 break;
484 case FONT_KERNING:
485 value->f = twips_to_points(fmt.wKerning);
486 break;
487 case FONT_LANGID:
488 value->l = fmt.lcid;
489 break;
490 case FONT_NAME:
491 /* this case is used exclusively by GetName() */
492 value->str = SysAllocString(fmt.szFaceName);
493 if (!value->str)
494 return E_OUTOFMEMORY;
495 break;
496 case FONT_POSITION:
497 value->f = twips_to_points(fmt.yOffset);
498 break;
499 case FONT_SIZE:
500 value->f = twips_to_points(fmt.yHeight);
501 break;
502 case FONT_SPACING:
503 value->f = fmt.sSpacing;
504 break;
505 case FONT_WEIGHT:
506 value->l = fmt.wWeight;
507 break;
508 default:
509 FIXME("unhandled font property %d\n", propid);
510 return E_FAIL;
513 return S_OK;
516 static inline const IRichEditOleImpl *get_range_reole(ITextRange *range)
518 IRichEditOleImpl *reole = NULL;
519 ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&reole);
520 return reole;
523 static void textrange_set_font(ITextRange *range, ITextFont *font)
525 CHARFORMAT2W fmt;
526 HRESULT hr;
527 LONG value;
528 BSTR str;
529 FLOAT f;
531 #define CHARFORMAT_SET_B_FIELD(mask, value) \
532 if (hr == S_OK && value != tomUndefined) { \
533 fmt.dwMask |= CFM_##mask; \
534 if (value == tomTrue) fmt.dwEffects |= CFE_##mask; \
537 /* fill format data from font */
538 memset(&fmt, 0, sizeof(fmt));
539 fmt.cbSize = sizeof(fmt);
541 value = tomUndefined;
542 hr = ITextFont_GetAllCaps(font, &value);
543 CHARFORMAT_SET_B_FIELD(ALLCAPS, value);
545 value = tomUndefined;
546 hr = ITextFont_GetBold(font, &value);
547 CHARFORMAT_SET_B_FIELD(BOLD, value);
549 value = tomUndefined;
550 hr = ITextFont_GetEmboss(font, &value);
551 CHARFORMAT_SET_B_FIELD(EMBOSS, value);
553 value = tomUndefined;
554 hr = ITextFont_GetHidden(font, &value);
555 CHARFORMAT_SET_B_FIELD(HIDDEN, value);
557 value = tomUndefined;
558 hr = ITextFont_GetEngrave(font, &value);
559 CHARFORMAT_SET_B_FIELD(IMPRINT, value);
561 value = tomUndefined;
562 hr = ITextFont_GetItalic(font, &value);
563 CHARFORMAT_SET_B_FIELD(ITALIC, value);
565 value = tomUndefined;
566 hr = ITextFont_GetOutline(font, &value);
567 CHARFORMAT_SET_B_FIELD(OUTLINE, value);
569 value = tomUndefined;
570 hr = ITextFont_GetProtected(font, &value);
571 CHARFORMAT_SET_B_FIELD(PROTECTED, value);
573 value = tomUndefined;
574 hr = ITextFont_GetShadow(font, &value);
575 CHARFORMAT_SET_B_FIELD(SHADOW, value);
577 value = tomUndefined;
578 hr = ITextFont_GetSmallCaps(font, &value);
579 CHARFORMAT_SET_B_FIELD(SMALLCAPS, value);
581 value = tomUndefined;
582 hr = ITextFont_GetStrikeThrough(font, &value);
583 CHARFORMAT_SET_B_FIELD(STRIKEOUT, value);
585 value = tomUndefined;
586 hr = ITextFont_GetSubscript(font, &value);
587 CHARFORMAT_SET_B_FIELD(SUBSCRIPT, value);
589 value = tomUndefined;
590 hr = ITextFont_GetSuperscript(font, &value);
591 CHARFORMAT_SET_B_FIELD(SUPERSCRIPT, value);
593 value = tomUndefined;
594 hr = ITextFont_GetUnderline(font, &value);
595 CHARFORMAT_SET_B_FIELD(UNDERLINE, value);
597 #undef CHARFORMAT_SET_B_FIELD
599 value = tomUndefined;
600 hr = ITextFont_GetAnimation(font, &value);
601 if (hr == S_OK && value != tomUndefined) {
602 fmt.dwMask |= CFM_ANIMATION;
603 fmt.bAnimation = value;
606 value = tomUndefined;
607 hr = ITextFont_GetBackColor(font, &value);
608 if (hr == S_OK && value != tomUndefined) {
609 fmt.dwMask |= CFM_BACKCOLOR;
610 if (value == tomAutoColor)
611 fmt.dwEffects |= CFE_AUTOBACKCOLOR;
612 else
613 fmt.crBackColor = value;
616 value = tomUndefined;
617 hr = ITextFont_GetForeColor(font, &value);
618 if (hr == S_OK && value != tomUndefined) {
619 fmt.dwMask |= CFM_COLOR;
620 if (value == tomAutoColor)
621 fmt.dwEffects |= CFE_AUTOCOLOR;
622 else
623 fmt.crTextColor = value;
626 value = tomUndefined;
627 hr = ITextFont_GetKerning(font, &f);
628 if (hr == S_OK && f != tomUndefined) {
629 fmt.dwMask |= CFM_KERNING;
630 fmt.wKerning = points_to_twips(f);
633 value = tomUndefined;
634 hr = ITextFont_GetLanguageID(font, &value);
635 if (hr == S_OK && value != tomUndefined) {
636 fmt.dwMask |= CFM_LCID;
637 fmt.lcid = value;
640 if (ITextFont_GetName(font, &str) == S_OK) {
641 fmt.dwMask |= CFM_FACE;
642 lstrcpynW(fmt.szFaceName, str, sizeof(fmt.szFaceName)/sizeof(WCHAR));
643 SysFreeString(str);
646 hr = ITextFont_GetPosition(font, &f);
647 if (hr == S_OK && f != tomUndefined) {
648 fmt.dwMask |= CFM_OFFSET;
649 fmt.yOffset = points_to_twips(f);
652 hr = ITextFont_GetSize(font, &f);
653 if (hr == S_OK && f != tomUndefined) {
654 fmt.dwMask |= CFM_SIZE;
655 fmt.yHeight = points_to_twips(f);
658 hr = ITextFont_GetSpacing(font, &f);
659 if (hr == S_OK && f != tomUndefined) {
660 fmt.dwMask |= CFM_SPACING;
661 fmt.sSpacing = f;
664 hr = ITextFont_GetWeight(font, &value);
665 if (hr == S_OK && value != tomUndefined) {
666 fmt.dwMask |= CFM_WEIGHT;
667 fmt.wWeight = value;
670 if (fmt.dwMask) {
671 const IRichEditOleImpl *reole = get_range_reole(range);
672 ME_Cursor from, to;
673 LONG start, end;
675 ITextRange_GetStart(range, &start);
676 ITextRange_GetEnd(range, &end);
678 ME_CursorFromCharOfs(reole->editor, start, &from);
679 ME_CursorFromCharOfs(reole->editor, end, &to);
680 ME_SetCharFormat(reole->editor, &from, &to, &fmt);
684 static HRESULT get_textfont_prop(const ITextFontImpl *font, enum textfont_prop_id propid, textfont_prop_val *value)
686 const IRichEditOleImpl *reole;
687 textfont_prop_val v;
688 LONG start, end, i;
689 HRESULT hr;
691 /* when font is not attached to any range use cached values */
692 if (!font->range || font->get_cache_enabled) {
693 *value = font->props[propid];
694 return S_OK;
697 if (!(reole = get_range_reole(font->range)))
698 return CO_E_RELEASED;
700 init_textfont_prop_value(propid, value);
702 ITextRange_GetStart(font->range, &start);
703 ITextRange_GetEnd(font->range, &end);
705 /* iterate trough a range to see if property value is consistent */
706 hr = get_textfont_prop_for_pos(reole, start, propid, &v);
707 if (FAILED(hr))
708 return hr;
710 for (i = start + 1; i < end; i++) {
711 textfont_prop_val cur;
713 hr = get_textfont_prop_for_pos(reole, i, propid, &cur);
714 if (FAILED(hr))
715 return hr;
717 if (!is_equal_textfont_prop_value(propid, &v, &cur))
718 return S_OK;
721 *value = v;
722 return S_OK;
725 static HRESULT get_textfont_propf(const ITextFontImpl *font, enum textfont_prop_id propid, FLOAT *value)
727 textfont_prop_val v;
728 HRESULT hr;
730 if (!value)
731 return E_INVALIDARG;
733 hr = get_textfont_prop(font, propid, &v);
734 *value = v.f;
735 return hr;
738 static HRESULT get_textfont_propl(const ITextFontImpl *font, enum textfont_prop_id propid, LONG *value)
740 textfont_prop_val v;
741 HRESULT hr;
743 if (!value)
744 return E_INVALIDARG;
746 hr = get_textfont_prop(font, propid, &v);
747 *value = v.l;
748 return hr;
751 /* Value should already have a terminal value, for boolean properties it means tomToggle is not handled */
752 static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id propid, const textfont_prop_val *value)
754 const IRichEditOleImpl *reole;
755 ME_Cursor from, to;
756 CHARFORMAT2W fmt;
757 LONG start, end;
759 /* when font is not attached to any range use cache */
760 if (!font->range || font->set_cache_enabled) {
761 if (propid == FONT_NAME) {
762 SysFreeString(font->props[propid].str);
763 font->props[propid].str = SysAllocString(value->str);
765 else
766 font->props[propid] = *value;
767 return S_OK;
770 if (!(reole = get_range_reole(font->range)))
771 return CO_E_RELEASED;
773 memset(&fmt, 0, sizeof(fmt));
774 fmt.cbSize = sizeof(fmt);
775 fmt.dwMask = textfont_prop_masks[propid][0];
777 switch (propid)
779 case FONT_ALLCAPS:
780 case FONT_BOLD:
781 case FONT_EMBOSS:
782 case FONT_HIDDEN:
783 case FONT_ENGRAVE:
784 case FONT_ITALIC:
785 case FONT_OUTLINE:
786 case FONT_PROTECTED:
787 case FONT_SHADOW:
788 case FONT_SMALLCAPS:
789 case FONT_STRIKETHROUGH:
790 case FONT_SUBSCRIPT:
791 case FONT_SUPERSCRIPT:
792 case FONT_UNDERLINE:
793 fmt.dwEffects = value->l == tomTrue ? textfont_prop_masks[propid][1] : 0;
794 break;
795 case FONT_ANIMATION:
796 fmt.bAnimation = value->l;
797 break;
798 case FONT_BACKCOLOR:
799 case FONT_FORECOLOR:
800 if (value->l == tomAutoColor)
801 fmt.dwEffects = textfont_prop_masks[propid][1];
802 else if (propid == FONT_BACKCOLOR)
803 fmt.crBackColor = value->l;
804 else
805 fmt.crTextColor = value->l;
806 break;
807 case FONT_KERNING:
808 fmt.wKerning = value->f;
809 break;
810 case FONT_LANGID:
811 fmt.lcid = value->l;
812 break;
813 case FONT_POSITION:
814 fmt.yOffset = value->f;
815 break;
816 case FONT_SIZE:
817 fmt.yHeight = value->f;
818 break;
819 case FONT_SPACING:
820 fmt.sSpacing = value->f;
821 break;
822 case FONT_WEIGHT:
823 fmt.wWeight = value->l;
824 break;
825 case FONT_NAME:
826 lstrcpynW(fmt.szFaceName, value->str, sizeof(fmt.szFaceName)/sizeof(WCHAR));
827 break;
828 default:
829 FIXME("unhandled font property %d\n", propid);
830 return E_FAIL;
833 ITextRange_GetStart(font->range, &start);
834 ITextRange_GetEnd(font->range, &end);
836 ME_CursorFromCharOfs(reole->editor, start, &from);
837 ME_CursorFromCharOfs(reole->editor, end, &to);
838 ME_SetCharFormat(reole->editor, &from, &to, &fmt);
840 return S_OK;
843 static inline HRESULT set_textfont_propl(ITextFontImpl *font, enum textfont_prop_id propid, LONG value)
845 textfont_prop_val v;
846 v.l = value;
847 return set_textfont_prop(font, propid, &v);
850 static inline HRESULT set_textfont_propf(ITextFontImpl *font, enum textfont_prop_id propid, FLOAT value)
852 textfont_prop_val v;
853 v.f = value;
854 return set_textfont_prop(font, propid, &v);
857 static HRESULT set_textfont_propd(ITextFontImpl *font, enum textfont_prop_id propid, LONG value)
859 textfont_prop_val v;
861 switch (value)
863 case tomUndefined:
864 return S_OK;
865 case tomToggle: {
866 LONG oldvalue;
867 get_textfont_propl(font, propid, &oldvalue);
868 if (oldvalue == tomFalse)
869 value = tomTrue;
870 else if (oldvalue == tomTrue)
871 value = tomFalse;
872 else
873 return E_INVALIDARG;
874 /* fallthrough */
876 case tomTrue:
877 case tomFalse:
878 v.l = value;
879 return set_textfont_prop(font, propid, &v);
880 default:
881 return E_INVALIDARG;
885 static HRESULT textfont_getname_from_range(ITextRange *range, BSTR *ret)
887 const IRichEditOleImpl *reole;
888 textfont_prop_val v;
889 HRESULT hr;
890 LONG start;
892 if (!(reole = get_range_reole(range)))
893 return CO_E_RELEASED;
895 ITextRange_GetStart(range, &start);
896 hr = get_textfont_prop_for_pos(reole, start, FONT_NAME, &v);
897 *ret = v.str;
898 return hr;
901 static void textfont_cache_range_props(ITextFontImpl *font)
903 enum textfont_prop_id propid;
904 for (propid = FONT_PROPID_FIRST; propid < FONT_PROPID_LAST; propid++) {
905 if (propid == FONT_NAME)
906 textfont_getname_from_range(font->range, &font->props[propid].str);
907 else
908 get_textfont_prop(font, propid, &font->props[propid]);
912 static HRESULT textrange_expand(ITextRange *range, LONG unit, LONG *delta)
914 LONG expand_start, expand_end;
916 switch (unit)
918 case tomStory:
919 expand_start = 0;
920 ITextRange_GetStoryLength(range, &expand_end);
921 break;
922 default:
923 FIXME("unit %d is not supported\n", unit);
924 return E_NOTIMPL;
927 if (delta) {
928 LONG start, end;
930 ITextRange_GetStart(range, &start);
931 ITextRange_GetEnd(range, &end);
932 *delta = expand_end - expand_start - (end - start);
935 ITextRange_SetStart(range, expand_start);
936 ITextRange_SetEnd(range, expand_end);
938 return S_OK;
941 static HRESULT WINAPI IRichEditOleImpl_inner_fnQueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppvObj)
943 IRichEditOleImpl *This = impl_from_IUnknown(iface);
945 TRACE("%p %s\n", This, debugstr_guid(riid));
947 *ppvObj = NULL;
948 if (IsEqualGUID(riid, &IID_IUnknown))
949 *ppvObj = &This->IUnknown_inner;
950 else if (IsEqualGUID(riid, &IID_IRichEditOle))
951 *ppvObj = &This->IRichEditOle_iface;
952 else if (IsEqualGUID(riid, &IID_ITextDocument))
953 *ppvObj = &This->ITextDocument_iface;
954 if (*ppvObj)
956 IUnknown_AddRef((IUnknown *)*ppvObj);
957 return S_OK;
959 FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid));
961 return E_NOINTERFACE;
964 static ULONG WINAPI IRichEditOleImpl_inner_fnAddRef(IUnknown *iface)
966 IRichEditOleImpl *This = impl_from_IUnknown(iface);
967 ULONG ref = InterlockedIncrement(&This->ref);
969 TRACE("%p ref = %u\n", This, ref);
971 return ref;
974 static ULONG WINAPI IRichEditOleImpl_inner_fnRelease(IUnknown *iface)
976 IRichEditOleImpl *This = impl_from_IUnknown(iface);
977 ULONG ref = InterlockedDecrement(&This->ref);
979 TRACE ("%p ref=%u\n", This, ref);
981 if (!ref)
983 IOleClientSiteImpl *clientsite;
984 ITextRangeImpl *txtRge;
986 This->editor->reOle = NULL;
987 if (This->txtSel) {
988 This->txtSel->reOle = NULL;
989 ITextSelection_Release(&This->txtSel->ITextSelection_iface);
992 LIST_FOR_EACH_ENTRY(txtRge, &This->rangelist, ITextRangeImpl, child.entry)
993 txtRge->child.reole = NULL;
995 LIST_FOR_EACH_ENTRY(clientsite, &This->clientsites, IOleClientSiteImpl, child.entry)
996 clientsite->child.reole = NULL;
998 heap_free(This);
1000 return ref;
1003 static const IUnknownVtbl reo_unk_vtbl =
1005 IRichEditOleImpl_inner_fnQueryInterface,
1006 IRichEditOleImpl_inner_fnAddRef,
1007 IRichEditOleImpl_inner_fnRelease
1010 static HRESULT WINAPI
1011 IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
1013 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1014 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1017 static ULONG WINAPI
1018 IRichEditOle_fnAddRef(IRichEditOle *me)
1020 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1021 return IUnknown_AddRef(This->outer_unk);
1024 static ULONG WINAPI
1025 IRichEditOle_fnRelease(IRichEditOle *me)
1027 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1028 return IUnknown_Release(This->outer_unk);
1031 static HRESULT WINAPI
1032 IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
1034 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1035 FIXME("stub %p\n",This);
1036 return E_NOTIMPL;
1039 static HRESULT WINAPI
1040 IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
1042 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1043 FIXME("stub %p\n",This);
1044 return E_NOTIMPL;
1047 static HRESULT WINAPI
1048 IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
1049 REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
1051 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1052 FIXME("stub %p\n",This);
1053 return E_NOTIMPL;
1056 static inline IOleClientSiteImpl *impl_from_IOleClientSite(IOleClientSite *iface)
1058 return CONTAINING_RECORD(iface, IOleClientSiteImpl, IOleClientSite_iface);
1061 static HRESULT WINAPI
1062 IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
1064 IOleClientSiteImpl *This = impl_from_IOleClientSite(me);
1065 TRACE("%p %s\n", me, debugstr_guid(riid) );
1067 *ppvObj = NULL;
1068 if (IsEqualGUID(riid, &IID_IUnknown) ||
1069 IsEqualGUID(riid, &IID_IOleClientSite))
1070 *ppvObj = me;
1071 else if (IsEqualGUID(riid, &IID_IOleWindow))
1072 *ppvObj = &This->IOleWindow_iface;
1073 else if (IsEqualGUID(riid, &IID_IOleInPlaceSite))
1074 *ppvObj = &This->IOleInPlaceSite_iface;
1075 if (*ppvObj)
1077 IOleClientSite_AddRef(me);
1078 return S_OK;
1080 FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );
1082 return E_NOINTERFACE;
1085 static ULONG WINAPI IOleClientSite_fnAddRef(IOleClientSite *iface)
1087 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1088 ULONG ref = InterlockedIncrement(&This->ref);
1089 TRACE("(%p)->(%u)\n", This, ref);
1090 return ref;
1093 static ULONG WINAPI IOleClientSite_fnRelease(IOleClientSite *iface)
1095 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1096 ULONG ref = InterlockedDecrement(&This->ref);
1098 TRACE("(%p)->(%u)\n", This, ref);
1100 if (ref == 0) {
1101 if (This->child.reole) {
1102 list_remove(&This->child.entry);
1103 This->child.reole = NULL;
1105 heap_free(This);
1107 return ref;
1110 static HRESULT WINAPI IOleClientSite_fnSaveObject(IOleClientSite *iface)
1112 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1113 if (!This->child.reole)
1114 return CO_E_RELEASED;
1116 FIXME("stub %p\n", iface);
1117 return E_NOTIMPL;
1120 static HRESULT WINAPI IOleClientSite_fnGetMoniker(IOleClientSite *iface, DWORD dwAssign,
1121 DWORD dwWhichMoniker, IMoniker **ppmk)
1123 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1124 if (!This->child.reole)
1125 return CO_E_RELEASED;
1127 FIXME("stub %p\n", iface);
1128 return E_NOTIMPL;
1131 static HRESULT WINAPI IOleClientSite_fnGetContainer(IOleClientSite *iface,
1132 IOleContainer **ppContainer)
1134 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1135 if (!This->child.reole)
1136 return CO_E_RELEASED;
1138 FIXME("stub %p\n", iface);
1139 return E_NOTIMPL;
1142 static HRESULT WINAPI IOleClientSite_fnShowObject(IOleClientSite *iface)
1144 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1145 if (!This->child.reole)
1146 return CO_E_RELEASED;
1148 FIXME("stub %p\n", iface);
1149 return E_NOTIMPL;
1152 static HRESULT WINAPI IOleClientSite_fnOnShowWindow(IOleClientSite *iface, BOOL fShow)
1154 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1155 if (!This->child.reole)
1156 return CO_E_RELEASED;
1158 FIXME("stub %p\n", iface);
1159 return E_NOTIMPL;
1162 static HRESULT WINAPI IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *iface)
1164 IOleClientSiteImpl *This = impl_from_IOleClientSite(iface);
1165 if (!This->child.reole)
1166 return CO_E_RELEASED;
1168 FIXME("stub %p\n", iface);
1169 return E_NOTIMPL;
1172 static const IOleClientSiteVtbl ocst = {
1173 IOleClientSite_fnQueryInterface,
1174 IOleClientSite_fnAddRef,
1175 IOleClientSite_fnRelease,
1176 IOleClientSite_fnSaveObject,
1177 IOleClientSite_fnGetMoniker,
1178 IOleClientSite_fnGetContainer,
1179 IOleClientSite_fnShowObject,
1180 IOleClientSite_fnOnShowWindow,
1181 IOleClientSite_fnRequestNewObjectLayout
1184 /* IOleWindow interface */
1185 static HRESULT WINAPI IOleWindow_fnQueryInterface(IOleWindow *iface, REFIID riid, void **ppvObj)
1187 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
1188 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppvObj);
1191 static ULONG WINAPI IOleWindow_fnAddRef(IOleWindow *iface)
1193 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
1194 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1197 static ULONG WINAPI IOleWindow_fnRelease(IOleWindow *iface)
1199 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
1200 return IOleClientSite_Release(&This->IOleClientSite_iface);
1203 static HRESULT WINAPI IOleWindow_fnContextSensitiveHelp(IOleWindow *iface, BOOL fEnterMode)
1205 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
1206 FIXME("not implemented: (%p)->(%d)\n", This, fEnterMode);
1207 return E_NOTIMPL;
1210 static HRESULT WINAPI IOleWindow_fnGetWindow(IOleWindow *iface, HWND *phwnd)
1212 IOleClientSiteImpl *This = impl_from_IOleWindow(iface);
1214 TRACE("(%p)->(%p)\n", This, phwnd);
1216 if (!This->child.reole)
1217 return CO_E_RELEASED;
1219 if (!phwnd)
1220 return E_INVALIDARG;
1222 *phwnd = This->child.reole->editor->hWnd;
1223 return S_OK;
1226 static const IOleWindowVtbl olewinvt = {
1227 IOleWindow_fnQueryInterface,
1228 IOleWindow_fnAddRef,
1229 IOleWindow_fnRelease,
1230 IOleWindow_fnGetWindow,
1231 IOleWindow_fnContextSensitiveHelp
1234 /* IOleInPlaceSite interface */
1235 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnQueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppvObj)
1237 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1238 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppvObj);
1241 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnAddRef(IOleInPlaceSite *iface)
1243 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1244 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1247 static ULONG STDMETHODCALLTYPE IOleInPlaceSite_fnRelease(IOleInPlaceSite *iface)
1249 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1250 return IOleClientSite_Release(&This->IOleClientSite_iface);
1253 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindow(IOleInPlaceSite *iface, HWND *phwnd)
1255 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1256 return IOleWindow_GetWindow(&This->IOleWindow_iface, phwnd);
1259 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1261 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1262 return IOleWindow_ContextSensitiveHelp(&This->IOleWindow_iface, fEnterMode);
1265 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnCanInPlaceActivate(IOleInPlaceSite *iface)
1267 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1268 FIXME("not implemented: (%p)\n", This);
1269 return E_NOTIMPL;
1272 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceActivate(IOleInPlaceSite *iface)
1274 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1275 FIXME("not implemented: (%p)\n", This);
1276 return E_NOTIMPL;
1279 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIActivate(IOleInPlaceSite *iface)
1281 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1282 FIXME("not implemented: (%p)\n", This);
1283 return E_NOTIMPL;
1286 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnGetWindowContext(IOleInPlaceSite *iface, IOleInPlaceFrame **ppFrame,
1287 IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1288 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1290 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1291 FIXME("not implemented: (%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
1292 return E_NOTIMPL;
1295 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnScroll(IOleInPlaceSite *iface, SIZE scrollExtent)
1297 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1298 FIXME("not implemented: (%p)\n", This);
1299 return E_NOTIMPL;
1302 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1304 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1305 FIXME("not implemented: (%p)->(%d)\n", This, fUndoable);
1306 return E_NOTIMPL;
1309 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnInPlaceDeactivate(IOleInPlaceSite *iface)
1311 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1312 FIXME("not implemented: (%p)\n", This);
1313 return E_NOTIMPL;
1316 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDiscardUndoState(IOleInPlaceSite *iface)
1318 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1319 FIXME("not implemented: (%p)\n", This);
1320 return E_NOTIMPL;
1323 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnDeactivateAndUndo(IOleInPlaceSite *iface)
1325 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1326 FIXME("not implemented: (%p)\n", This);
1327 return E_NOTIMPL;
1330 static HRESULT STDMETHODCALLTYPE IOleInPlaceSite_fnOnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1332 IOleClientSiteImpl *This = impl_from_IOleInPlaceSite(iface);
1333 FIXME("not implemented: (%p)->(%p)\n", This, lprcPosRect);
1334 return E_NOTIMPL;
1337 static const IOleInPlaceSiteVtbl olestvt =
1339 IOleInPlaceSite_fnQueryInterface,
1340 IOleInPlaceSite_fnAddRef,
1341 IOleInPlaceSite_fnRelease,
1342 IOleInPlaceSite_fnGetWindow,
1343 IOleInPlaceSite_fnContextSensitiveHelp,
1344 IOleInPlaceSite_fnCanInPlaceActivate,
1345 IOleInPlaceSite_fnOnInPlaceActivate,
1346 IOleInPlaceSite_fnOnUIActivate,
1347 IOleInPlaceSite_fnGetWindowContext,
1348 IOleInPlaceSite_fnScroll,
1349 IOleInPlaceSite_fnOnUIDeactivate,
1350 IOleInPlaceSite_fnOnInPlaceDeactivate,
1351 IOleInPlaceSite_fnDiscardUndoState,
1352 IOleInPlaceSite_fnDeactivateAndUndo,
1353 IOleInPlaceSite_fnOnPosRectChange
1356 static HRESULT CreateOleClientSite(IRichEditOleImpl *reOle, IOleClientSite **ret)
1358 IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
1360 if (!clientSite)
1361 return E_OUTOFMEMORY;
1363 clientSite->IOleClientSite_iface.lpVtbl = &ocst;
1364 clientSite->IOleWindow_iface.lpVtbl = &olewinvt;
1365 clientSite->IOleInPlaceSite_iface.lpVtbl = &olestvt;
1366 clientSite->ref = 1;
1367 clientSite->child.reole = reOle;
1368 list_add_head(&reOle->clientsites, &clientSite->child.entry);
1370 *ret = &clientSite->IOleClientSite_iface;
1371 return S_OK;
1374 static HRESULT WINAPI
1375 IRichEditOle_fnGetClientSite(IRichEditOle *me, IOleClientSite **clientsite)
1377 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1379 TRACE("(%p)->(%p)\n", This, clientsite);
1381 if (!clientsite)
1382 return E_INVALIDARG;
1384 return CreateOleClientSite(This, clientsite);
1387 static HRESULT WINAPI
1388 IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
1389 DWORD reco, LPDATAOBJECT *lplpdataobj)
1391 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1392 ME_Cursor start;
1393 int nChars;
1395 TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
1396 if(!lplpdataobj)
1397 return E_INVALIDARG;
1398 if(!lpchrg) {
1399 int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
1400 start = This->editor->pCursors[nStartCur];
1401 nChars = nTo - nFrom;
1402 } else {
1403 ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
1404 nChars = lpchrg->cpMax - lpchrg->cpMin;
1406 return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
1409 static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
1411 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1412 FIXME("stub %p\n",This);
1413 return E_NOTIMPL;
1416 static HRESULT WINAPI
1417 IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
1418 REOBJECT *lpreobject, DWORD dwFlags)
1420 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1421 FIXME("stub %p\n",This);
1422 return E_NOTIMPL;
1425 static LONG WINAPI
1426 IRichEditOle_fnGetObjectCount(IRichEditOle *me)
1428 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1429 FIXME("stub %p\n",This);
1430 return 0;
1433 static HRESULT WINAPI
1434 IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
1436 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1437 FIXME("stub %p\n",This);
1438 return E_NOTIMPL;
1441 static HRESULT WINAPI
1442 IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
1443 CLIPFORMAT cf, HGLOBAL hMetaPict)
1445 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1446 FIXME("stub %p\n",This);
1447 return E_NOTIMPL;
1450 static HRESULT WINAPI
1451 IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
1453 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1454 FIXME("stub %p\n",This);
1455 return E_NOTIMPL;
1458 static HRESULT WINAPI
1459 IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
1461 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1463 TRACE("(%p,%p)\n", This, reo);
1465 if (!reo)
1466 return E_INVALIDARG;
1468 if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
1470 ME_InsertOLEFromCursor(This->editor, reo, 0);
1471 ME_CommitUndo(This->editor);
1472 ME_UpdateRepaint(This->editor, FALSE);
1473 return S_OK;
1476 static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
1477 LPSTORAGE lpstg)
1479 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1480 FIXME("stub %p\n",This);
1481 return E_NOTIMPL;
1484 static HRESULT WINAPI
1485 IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
1487 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1488 FIXME("stub %p\n",This);
1489 return E_NOTIMPL;
1492 static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
1493 LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
1495 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1496 FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
1497 return E_NOTIMPL;
1500 static HRESULT WINAPI
1501 IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
1503 IRichEditOleImpl *This = impl_from_IRichEditOle(me);
1504 FIXME("stub %p\n",This);
1505 return E_NOTIMPL;
1508 static const IRichEditOleVtbl revt = {
1509 IRichEditOle_fnQueryInterface,
1510 IRichEditOle_fnAddRef,
1511 IRichEditOle_fnRelease,
1512 IRichEditOle_fnGetClientSite,
1513 IRichEditOle_fnGetObjectCount,
1514 IRichEditOle_fnGetLinkCount,
1515 IRichEditOle_fnGetObject,
1516 IRichEditOle_fnInsertObject,
1517 IRichEditOle_fnConvertObject,
1518 IRichEditOle_fnActivateAs,
1519 IRichEditOle_fnSetHostNames,
1520 IRichEditOle_fnSetLinkAvailable,
1521 IRichEditOle_fnSetDvaspect,
1522 IRichEditOle_fnHandsOffStorage,
1523 IRichEditOle_fnSaveCompleted,
1524 IRichEditOle_fnInPlaceDeactivate,
1525 IRichEditOle_fnContextSensitiveHelp,
1526 IRichEditOle_fnGetClipboardData,
1527 IRichEditOle_fnImportDataObject
1530 /* ITextRange interface */
1531 static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
1533 ITextRangeImpl *This = impl_from_ITextRange(me);
1535 *ppvObj = NULL;
1536 if (IsEqualGUID(riid, &IID_IUnknown)
1537 || IsEqualGUID(riid, &IID_IDispatch)
1538 || IsEqualGUID(riid, &IID_ITextRange))
1540 *ppvObj = me;
1541 ITextRange_AddRef(me);
1542 return S_OK;
1544 else if (IsEqualGUID(riid, &IID_Igetrichole))
1546 *ppvObj = This->child.reole;
1547 return S_OK;
1550 return E_NOINTERFACE;
1553 static ULONG WINAPI ITextRange_fnAddRef(ITextRange *me)
1555 ITextRangeImpl *This = impl_from_ITextRange(me);
1556 return InterlockedIncrement(&This->ref);
1559 static ULONG WINAPI ITextRange_fnRelease(ITextRange *me)
1561 ITextRangeImpl *This = impl_from_ITextRange(me);
1562 ULONG ref = InterlockedDecrement(&This->ref);
1564 TRACE ("%p ref=%u\n", This, ref);
1565 if (ref == 0)
1567 if (This->child.reole)
1569 list_remove(&This->child.entry);
1570 This->child.reole = NULL;
1572 heap_free(This);
1574 return ref;
1577 static HRESULT WINAPI ITextRange_fnGetTypeInfoCount(ITextRange *me, UINT *pctinfo)
1579 ITextRangeImpl *This = impl_from_ITextRange(me);
1580 TRACE("(%p)->(%p)\n", This, pctinfo);
1581 *pctinfo = 1;
1582 return S_OK;
1585 static HRESULT WINAPI ITextRange_fnGetTypeInfo(ITextRange *me, UINT iTInfo, LCID lcid,
1586 ITypeInfo **ppTInfo)
1588 ITextRangeImpl *This = impl_from_ITextRange(me);
1589 HRESULT hr;
1591 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
1593 hr = get_typeinfo(ITextRange_tid, ppTInfo);
1594 if (SUCCEEDED(hr))
1595 ITypeInfo_AddRef(*ppTInfo);
1596 return hr;
1599 static HRESULT WINAPI ITextRange_fnGetIDsOfNames(ITextRange *me, REFIID riid, LPOLESTR *rgszNames,
1600 UINT cNames, LCID lcid, DISPID *rgDispId)
1602 ITextRangeImpl *This = impl_from_ITextRange(me);
1603 ITypeInfo *ti;
1604 HRESULT hr;
1606 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
1607 rgDispId);
1609 hr = get_typeinfo(ITextRange_tid, &ti);
1610 if (SUCCEEDED(hr))
1611 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
1612 return hr;
1615 static HRESULT WINAPI ITextRange_fnInvoke(ITextRange *me, DISPID dispIdMember, REFIID riid,
1616 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1617 VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
1618 UINT *puArgErr)
1620 ITextRangeImpl *This = impl_from_ITextRange(me);
1621 ITypeInfo *ti;
1622 HRESULT hr;
1624 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
1625 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1627 hr = get_typeinfo(ITextRange_tid, &ti);
1628 if (SUCCEEDED(hr))
1629 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1630 return hr;
1633 static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *str)
1635 ITextRangeImpl *This = impl_from_ITextRange(me);
1636 ME_TextEditor *editor;
1637 ME_Cursor start, end;
1638 int length;
1639 BOOL bEOP;
1641 TRACE("(%p)->(%p)\n", This, str);
1643 if (!This->child.reole)
1644 return CO_E_RELEASED;
1646 if (!str)
1647 return E_INVALIDARG;
1649 /* return early for degenerate range */
1650 if (This->start == This->end) {
1651 *str = NULL;
1652 return S_OK;
1655 editor = This->child.reole->editor;
1656 ME_CursorFromCharOfs(editor, This->start, &start);
1657 ME_CursorFromCharOfs(editor, This->end, &end);
1659 length = This->end - This->start;
1660 *str = SysAllocStringLen(NULL, length);
1661 if (!*str)
1662 return E_OUTOFMEMORY;
1664 bEOP = (end.pRun->next->type == diTextEnd && This->end > ME_GetTextLength(editor));
1665 ME_GetTextW(editor, *str, length, &start, length, FALSE, bEOP);
1666 return S_OK;
1669 static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
1671 ITextRangeImpl *This = impl_from_ITextRange(me);
1672 ME_TextEditor *editor;
1673 ME_Cursor cursor;
1674 ME_Style *style;
1675 int len;
1677 TRACE("(%p)->(%s)\n", This, debugstr_w(str));
1679 if (!This->child.reole)
1680 return CO_E_RELEASED;
1682 editor = This->child.reole->editor;
1684 /* delete only where's something to delete */
1685 if (This->start != This->end) {
1686 ME_CursorFromCharOfs(editor, This->start, &cursor);
1687 ME_InternalDeleteText(editor, &cursor, This->end - This->start, FALSE);
1690 if (!str || !*str) {
1691 /* will update this range as well */
1692 textranges_update_ranges(This->child.reole, This->start, This->end, RANGE_UPDATE_DELETE);
1693 return S_OK;
1696 /* it's safer not to rely on stored BSTR length */
1697 len = strlenW(str);
1698 cursor = editor->pCursors[0];
1699 ME_CursorFromCharOfs(editor, This->start, &editor->pCursors[0]);
1700 style = ME_GetInsertStyle(editor, 0);
1701 ME_InsertTextFromCursor(editor, 0, str, len, style);
1702 ME_ReleaseStyle(style);
1703 editor->pCursors[0] = cursor;
1705 if (len < This->end - This->start)
1706 textranges_update_ranges(This->child.reole, This->start + len, This->end, RANGE_UPDATE_DELETE);
1707 else
1708 This->end = len - This->start;
1710 return S_OK;
1713 static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch)
1715 WCHAR wch[2];
1717 ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, cursor->pRun->next->type == diTextEnd);
1718 *pch = wch[0];
1720 return S_OK;
1723 static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
1725 ITextRangeImpl *This = impl_from_ITextRange(me);
1726 ME_TextEditor *editor;
1727 ME_Cursor cursor;
1729 TRACE("(%p)->(%p)\n", This, pch);
1731 if (!This->child.reole)
1732 return CO_E_RELEASED;
1734 if (!pch)
1735 return E_INVALIDARG;
1737 editor = This->child.reole->editor;
1738 ME_CursorFromCharOfs(editor, This->start, &cursor);
1739 return range_GetChar(editor, &cursor, pch);
1742 static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch)
1744 ITextRangeImpl *This = impl_from_ITextRange(me);
1746 FIXME("(%p)->(%x): stub\n", This, ch);
1748 if (!This->child.reole)
1749 return CO_E_RELEASED;
1751 return E_NOTIMPL;
1754 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange);
1756 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
1758 ITextRangeImpl *This = impl_from_ITextRange(me);
1760 TRACE("(%p)->(%p)\n", This, ppRange);
1762 if (!This->child.reole)
1763 return CO_E_RELEASED;
1765 if (!ppRange)
1766 return E_INVALIDARG;
1768 return CreateITextRange(This->child.reole, This->start, This->end, ppRange);
1771 static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **range)
1773 ITextRangeImpl *This = impl_from_ITextRange(me);
1775 FIXME("(%p)->(%p): stub\n", This, range);
1777 if (!This->child.reole)
1778 return CO_E_RELEASED;
1780 return E_NOTIMPL;
1783 static HRESULT WINAPI ITextRange_fnSetFormattedText(ITextRange *me, ITextRange *range)
1785 ITextRangeImpl *This = impl_from_ITextRange(me);
1787 FIXME("(%p)->(%p): stub\n", This, range);
1789 if (!This->child.reole)
1790 return CO_E_RELEASED;
1792 return E_NOTIMPL;
1795 static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *start)
1797 ITextRangeImpl *This = impl_from_ITextRange(me);
1799 TRACE("(%p)->(%p)\n", This, start);
1801 if (!This->child.reole)
1802 return CO_E_RELEASED;
1804 if (!start)
1805 return E_INVALIDARG;
1807 *start = This->start;
1808 return S_OK;
1811 static HRESULT textrange_setstart(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1813 int len;
1815 if (value < 0)
1816 value = 0;
1818 if (value == *start)
1819 return S_FALSE;
1821 if (value <= *end) {
1822 *start = value;
1823 return S_OK;
1826 len = ME_GetTextLength(reole->editor);
1827 *start = *end = value > len ? len : value;
1828 return S_OK;
1831 static HRESULT WINAPI ITextRange_fnSetStart(ITextRange *me, LONG value)
1833 ITextRangeImpl *This = impl_from_ITextRange(me);
1835 TRACE("(%p)->(%d)\n", This, value);
1837 if (!This->child.reole)
1838 return CO_E_RELEASED;
1840 return textrange_setstart(This->child.reole, value, &This->start, &This->end);
1843 static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *end)
1845 ITextRangeImpl *This = impl_from_ITextRange(me);
1847 TRACE("(%p)->(%p)\n", This, end);
1849 if (!This->child.reole)
1850 return CO_E_RELEASED;
1852 if (!end)
1853 return E_INVALIDARG;
1855 *end = This->end;
1856 return S_OK;
1859 static HRESULT textrange_setend(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
1861 int len;
1863 if (value == *end)
1864 return S_FALSE;
1866 if (value < *start) {
1867 *start = *end = max(0, value);
1868 return S_OK;
1871 len = ME_GetTextLength(reole->editor);
1872 *end = value > len ? len + 1 : value;
1873 return S_OK;
1876 static HRESULT WINAPI ITextRange_fnSetEnd(ITextRange *me, LONG value)
1878 ITextRangeImpl *This = impl_from_ITextRange(me);
1880 TRACE("(%p)->(%d)\n", This, value);
1882 if (!This->child.reole)
1883 return CO_E_RELEASED;
1885 return textrange_setend(This->child.reole, value, &This->start, &This->end);
1888 static HRESULT WINAPI ITextRange_fnGetFont(ITextRange *me, ITextFont **font)
1890 ITextRangeImpl *This = impl_from_ITextRange(me);
1892 TRACE("(%p)->(%p)\n", This, font);
1894 if (!This->child.reole)
1895 return CO_E_RELEASED;
1897 if (!font)
1898 return E_INVALIDARG;
1900 return create_textfont(me, NULL, font);
1903 static HRESULT WINAPI ITextRange_fnSetFont(ITextRange *me, ITextFont *font)
1905 ITextRangeImpl *This = impl_from_ITextRange(me);
1907 TRACE("(%p)->(%p)\n", This, font);
1909 if (!font)
1910 return E_INVALIDARG;
1912 if (!This->child.reole)
1913 return CO_E_RELEASED;
1915 textrange_set_font(me, font);
1916 return S_OK;
1919 static HRESULT WINAPI ITextRange_fnGetPara(ITextRange *me, ITextPara **para)
1921 ITextRangeImpl *This = impl_from_ITextRange(me);
1923 TRACE("(%p)->(%p)\n", This, para);
1925 if (!This->child.reole)
1926 return CO_E_RELEASED;
1928 if (!para)
1929 return E_INVALIDARG;
1931 return create_textpara(me, para);
1934 static HRESULT WINAPI ITextRange_fnSetPara(ITextRange *me, ITextPara *para)
1936 ITextRangeImpl *This = impl_from_ITextRange(me);
1938 FIXME("(%p)->(%p): stub\n", This, para);
1940 if (!This->child.reole)
1941 return CO_E_RELEASED;
1943 return E_NOTIMPL;
1946 static HRESULT WINAPI ITextRange_fnGetStoryLength(ITextRange *me, LONG *length)
1948 ITextRangeImpl *This = impl_from_ITextRange(me);
1950 TRACE("(%p)->(%p)\n", This, length);
1952 if (!This->child.reole)
1953 return CO_E_RELEASED;
1955 return textrange_get_storylength(This->child.reole->editor, length);
1958 static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *value)
1960 ITextRangeImpl *This = impl_from_ITextRange(me);
1962 TRACE("(%p)->(%p)\n", This, value);
1964 if (!This->child.reole)
1965 return CO_E_RELEASED;
1967 if (!value)
1968 return E_INVALIDARG;
1970 *value = tomUnknownStory;
1971 return S_OK;
1974 static HRESULT range_Collapse(LONG bStart, LONG *start, LONG *end)
1976 if (*end == *start)
1977 return S_FALSE;
1979 if (bStart == tomEnd || bStart == tomFalse)
1980 *start = *end;
1981 else
1982 *end = *start;
1983 return S_OK;
1986 static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
1988 ITextRangeImpl *This = impl_from_ITextRange(me);
1990 TRACE("(%p)->(%d)\n", This, bStart);
1992 if (!This->child.reole)
1993 return CO_E_RELEASED;
1995 return range_Collapse(bStart, &This->start, &This->end);
1998 static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG unit, LONG *delta)
2000 ITextRangeImpl *This = impl_from_ITextRange(me);
2002 TRACE("(%p)->(%d %p)\n", This, unit, delta);
2004 if (!This->child.reole)
2005 return CO_E_RELEASED;
2007 return textrange_expand(me, unit, delta);
2010 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG unit, LONG *index)
2012 ITextRangeImpl *This = impl_from_ITextRange(me);
2014 FIXME("(%p)->(%d %p): stub\n", This, unit, index);
2016 if (!This->child.reole)
2017 return CO_E_RELEASED;
2019 return E_NOTIMPL;
2022 static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG unit, LONG index,
2023 LONG extend)
2025 ITextRangeImpl *This = impl_from_ITextRange(me);
2027 FIXME("(%p)->(%d %d %d): stub\n", This, unit, index, extend);
2029 if (!This->child.reole)
2030 return CO_E_RELEASED;
2032 return E_NOTIMPL;
2035 static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG anchor, LONG active)
2037 ITextRangeImpl *This = impl_from_ITextRange(me);
2039 FIXME("(%p)->(%d %d): stub\n", This, anchor, active);
2041 if (!This->child.reole)
2042 return CO_E_RELEASED;
2044 return E_NOTIMPL;
2047 static HRESULT textrange_inrange(LONG start, LONG end, ITextRange *range, LONG *ret)
2049 LONG from, to, v;
2051 if (!ret)
2052 ret = &v;
2054 if (FAILED(ITextRange_GetStart(range, &from)) || FAILED(ITextRange_GetEnd(range, &to))) {
2055 *ret = tomFalse;
2057 else
2058 *ret = (start >= from && end <= to) ? tomTrue : tomFalse;
2059 return *ret == tomTrue ? S_OK : S_FALSE;
2062 static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *range, LONG *ret)
2064 ITextRangeImpl *This = impl_from_ITextRange(me);
2066 TRACE("(%p)->(%p %p)\n", This, range, ret);
2068 if (ret)
2069 *ret = tomFalse;
2071 if (!This->child.reole)
2072 return CO_E_RELEASED;
2074 if (!range)
2075 return S_FALSE;
2077 return textrange_inrange(This->start, This->end, range, ret);
2080 static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *ret)
2082 ITextRangeImpl *This = impl_from_ITextRange(me);
2084 FIXME("(%p)->(%p): stub\n", This, ret);
2086 if (!This->child.reole)
2087 return CO_E_RELEASED;
2089 return E_NOTIMPL;
2092 static HRESULT textrange_isequal(LONG start, LONG end, ITextRange *range, LONG *ret)
2094 LONG from, to, v;
2096 if (!ret)
2097 ret = &v;
2099 if (FAILED(ITextRange_GetStart(range, &from)) || FAILED(ITextRange_GetEnd(range, &to))) {
2100 *ret = tomFalse;
2102 else
2103 *ret = (start == from && end == to) ? tomTrue : tomFalse;
2104 return *ret == tomTrue ? S_OK : S_FALSE;
2107 static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *range, LONG *ret)
2109 ITextRangeImpl *This = impl_from_ITextRange(me);
2111 TRACE("(%p)->(%p %p)\n", This, range, ret);
2113 if (ret)
2114 *ret = tomFalse;
2116 if (!This->child.reole)
2117 return CO_E_RELEASED;
2119 if (!range)
2120 return S_FALSE;
2122 return textrange_isequal(This->start, This->end, range, ret);
2125 static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me)
2127 ITextRangeImpl *This = impl_from_ITextRange(me);
2129 TRACE("(%p)\n", This);
2131 if (!This->child.reole)
2132 return CO_E_RELEASED;
2134 ME_SetSelection(This->child.reole->editor, This->start, This->end);
2135 return S_OK;
2138 static HRESULT WINAPI ITextRange_fnStartOf(ITextRange *me, LONG unit, LONG extend,
2139 LONG *delta)
2141 ITextRangeImpl *This = impl_from_ITextRange(me);
2143 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
2145 if (!This->child.reole)
2146 return CO_E_RELEASED;
2148 return E_NOTIMPL;
2151 static HRESULT WINAPI ITextRange_fnEndOf(ITextRange *me, LONG unit, LONG extend,
2152 LONG *delta)
2154 ITextRangeImpl *This = impl_from_ITextRange(me);
2156 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
2158 if (!This->child.reole)
2159 return CO_E_RELEASED;
2161 return E_NOTIMPL;
2164 static HRESULT WINAPI ITextRange_fnMove(ITextRange *me, LONG unit, LONG count, LONG *delta)
2166 ITextRangeImpl *This = impl_from_ITextRange(me);
2168 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
2170 if (!This->child.reole)
2171 return CO_E_RELEASED;
2173 return E_NOTIMPL;
2176 static HRESULT WINAPI ITextRange_fnMoveStart(ITextRange *me, LONG unit, LONG count,
2177 LONG *delta)
2179 ITextRangeImpl *This = impl_from_ITextRange(me);
2181 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
2183 if (!This->child.reole)
2184 return CO_E_RELEASED;
2186 return E_NOTIMPL;
2189 static HRESULT WINAPI ITextRange_fnMoveEnd(ITextRange *me, LONG unit, LONG count,
2190 LONG *delta)
2192 ITextRangeImpl *This = impl_from_ITextRange(me);
2194 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
2196 if (!This->child.reole)
2197 return CO_E_RELEASED;
2199 return E_NOTIMPL;
2202 static HRESULT WINAPI ITextRange_fnMoveWhile(ITextRange *me, VARIANT *charset, LONG count,
2203 LONG *delta)
2205 ITextRangeImpl *This = impl_from_ITextRange(me);
2207 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2209 if (!This->child.reole)
2210 return CO_E_RELEASED;
2212 return E_NOTIMPL;
2215 static HRESULT WINAPI ITextRange_fnMoveStartWhile(ITextRange *me, VARIANT *charset, LONG count,
2216 LONG *delta)
2218 ITextRangeImpl *This = impl_from_ITextRange(me);
2220 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2222 if (!This->child.reole)
2223 return CO_E_RELEASED;
2225 return E_NOTIMPL;
2228 static HRESULT WINAPI ITextRange_fnMoveEndWhile(ITextRange *me, VARIANT *charset, LONG count,
2229 LONG *delta)
2231 ITextRangeImpl *This = impl_from_ITextRange(me);
2233 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2235 if (!This->child.reole)
2236 return CO_E_RELEASED;
2238 return E_NOTIMPL;
2241 static HRESULT WINAPI ITextRange_fnMoveUntil(ITextRange *me, VARIANT *charset, LONG count,
2242 LONG *delta)
2244 ITextRangeImpl *This = impl_from_ITextRange(me);
2246 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2248 if (!This->child.reole)
2249 return CO_E_RELEASED;
2251 return E_NOTIMPL;
2254 static HRESULT WINAPI ITextRange_fnMoveStartUntil(ITextRange *me, VARIANT *charset, LONG count,
2255 LONG *delta)
2257 ITextRangeImpl *This = impl_from_ITextRange(me);
2259 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2261 if (!This->child.reole)
2262 return CO_E_RELEASED;
2264 return E_NOTIMPL;
2267 static HRESULT WINAPI ITextRange_fnMoveEndUntil(ITextRange *me, VARIANT *charset, LONG count,
2268 LONG *delta)
2270 ITextRangeImpl *This = impl_from_ITextRange(me);
2272 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
2274 if (!This->child.reole)
2275 return CO_E_RELEASED;
2277 return E_NOTIMPL;
2280 static HRESULT WINAPI ITextRange_fnFindText(ITextRange *me, BSTR text, LONG count, LONG flags,
2281 LONG *length)
2283 ITextRangeImpl *This = impl_from_ITextRange(me);
2285 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
2287 if (!This->child.reole)
2288 return CO_E_RELEASED;
2290 return E_NOTIMPL;
2293 static HRESULT WINAPI ITextRange_fnFindTextStart(ITextRange *me, BSTR text, LONG count,
2294 LONG flags, LONG *length)
2296 ITextRangeImpl *This = impl_from_ITextRange(me);
2298 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
2300 if (!This->child.reole)
2301 return CO_E_RELEASED;
2303 return E_NOTIMPL;
2306 static HRESULT WINAPI ITextRange_fnFindTextEnd(ITextRange *me, BSTR text, LONG count,
2307 LONG flags, LONG *length)
2309 ITextRangeImpl *This = impl_from_ITextRange(me);
2311 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
2313 if (!This->child.reole)
2314 return CO_E_RELEASED;
2316 return E_NOTIMPL;
2319 static HRESULT WINAPI ITextRange_fnDelete(ITextRange *me, LONG unit, LONG count, LONG *delta)
2321 ITextRangeImpl *This = impl_from_ITextRange(me);
2323 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
2325 if (!This->child.reole)
2326 return CO_E_RELEASED;
2328 return E_NOTIMPL;
2331 static HRESULT WINAPI ITextRange_fnCut(ITextRange *me, VARIANT *v)
2333 ITextRangeImpl *This = impl_from_ITextRange(me);
2335 FIXME("(%p)->(%p): stub\n", This, v);
2337 if (!This->child.reole)
2338 return CO_E_RELEASED;
2340 return E_NOTIMPL;
2343 static HRESULT WINAPI ITextRange_fnCopy(ITextRange *me, VARIANT *v)
2345 ITextRangeImpl *This = impl_from_ITextRange(me);
2347 FIXME("(%p)->(%p): stub\n", This, v);
2349 if (!This->child.reole)
2350 return CO_E_RELEASED;
2352 return E_NOTIMPL;
2355 static HRESULT WINAPI ITextRange_fnPaste(ITextRange *me, VARIANT *v, LONG format)
2357 ITextRangeImpl *This = impl_from_ITextRange(me);
2359 FIXME("(%p)->(%s %x): stub\n", This, debugstr_variant(v), format);
2361 if (!This->child.reole)
2362 return CO_E_RELEASED;
2364 return E_NOTIMPL;
2367 static HRESULT WINAPI ITextRange_fnCanPaste(ITextRange *me, VARIANT *v, LONG format, LONG *ret)
2369 ITextRangeImpl *This = impl_from_ITextRange(me);
2371 FIXME("(%p)->(%s %x %p): stub\n", This, debugstr_variant(v), format, ret);
2373 if (!This->child.reole)
2374 return CO_E_RELEASED;
2376 return E_NOTIMPL;
2379 static HRESULT WINAPI ITextRange_fnCanEdit(ITextRange *me, LONG *ret)
2381 ITextRangeImpl *This = impl_from_ITextRange(me);
2383 FIXME("(%p)->(%p): stub\n", This, ret);
2385 if (!This->child.reole)
2386 return CO_E_RELEASED;
2388 return E_NOTIMPL;
2391 static HRESULT WINAPI ITextRange_fnChangeCase(ITextRange *me, LONG type)
2393 ITextRangeImpl *This = impl_from_ITextRange(me);
2395 FIXME("(%p)->(%d): stub\n", This, type);
2397 if (!This->child.reole)
2398 return CO_E_RELEASED;
2400 return E_NOTIMPL;
2403 static HRESULT WINAPI ITextRange_fnGetPoint(ITextRange *me, LONG type, LONG *cx, LONG *cy)
2405 ITextRangeImpl *This = impl_from_ITextRange(me);
2407 FIXME("(%p)->(%d %p %p): stub\n", This, type, cx, cy);
2409 if (!This->child.reole)
2410 return CO_E_RELEASED;
2412 return E_NOTIMPL;
2415 static HRESULT WINAPI ITextRange_fnSetPoint(ITextRange *me, LONG x, LONG y, LONG type,
2416 LONG extend)
2418 ITextRangeImpl *This = impl_from_ITextRange(me);
2420 FIXME("(%p)->(%d %d %d %d): stub\n", This, x, y, type, extend);
2422 if (!This->child.reole)
2423 return CO_E_RELEASED;
2425 return E_NOTIMPL;
2428 static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG value)
2430 ITextRangeImpl *This = impl_from_ITextRange(me);
2432 FIXME("(%p)->(%d): stub\n", This, value);
2434 if (!This->child.reole)
2435 return CO_E_RELEASED;
2437 return E_NOTIMPL;
2440 static HRESULT WINAPI ITextRange_fnGetEmbeddedObject(ITextRange *me, IUnknown **ppv)
2442 ITextRangeImpl *This = impl_from_ITextRange(me);
2444 FIXME("(%p)->(%p): stub\n", This, ppv);
2446 if (!This->child.reole)
2447 return CO_E_RELEASED;
2449 return E_NOTIMPL;
2452 static const ITextRangeVtbl trvt = {
2453 ITextRange_fnQueryInterface,
2454 ITextRange_fnAddRef,
2455 ITextRange_fnRelease,
2456 ITextRange_fnGetTypeInfoCount,
2457 ITextRange_fnGetTypeInfo,
2458 ITextRange_fnGetIDsOfNames,
2459 ITextRange_fnInvoke,
2460 ITextRange_fnGetText,
2461 ITextRange_fnSetText,
2462 ITextRange_fnGetChar,
2463 ITextRange_fnSetChar,
2464 ITextRange_fnGetDuplicate,
2465 ITextRange_fnGetFormattedText,
2466 ITextRange_fnSetFormattedText,
2467 ITextRange_fnGetStart,
2468 ITextRange_fnSetStart,
2469 ITextRange_fnGetEnd,
2470 ITextRange_fnSetEnd,
2471 ITextRange_fnGetFont,
2472 ITextRange_fnSetFont,
2473 ITextRange_fnGetPara,
2474 ITextRange_fnSetPara,
2475 ITextRange_fnGetStoryLength,
2476 ITextRange_fnGetStoryType,
2477 ITextRange_fnCollapse,
2478 ITextRange_fnExpand,
2479 ITextRange_fnGetIndex,
2480 ITextRange_fnSetIndex,
2481 ITextRange_fnSetRange,
2482 ITextRange_fnInRange,
2483 ITextRange_fnInStory,
2484 ITextRange_fnIsEqual,
2485 ITextRange_fnSelect,
2486 ITextRange_fnStartOf,
2487 ITextRange_fnEndOf,
2488 ITextRange_fnMove,
2489 ITextRange_fnMoveStart,
2490 ITextRange_fnMoveEnd,
2491 ITextRange_fnMoveWhile,
2492 ITextRange_fnMoveStartWhile,
2493 ITextRange_fnMoveEndWhile,
2494 ITextRange_fnMoveUntil,
2495 ITextRange_fnMoveStartUntil,
2496 ITextRange_fnMoveEndUntil,
2497 ITextRange_fnFindText,
2498 ITextRange_fnFindTextStart,
2499 ITextRange_fnFindTextEnd,
2500 ITextRange_fnDelete,
2501 ITextRange_fnCut,
2502 ITextRange_fnCopy,
2503 ITextRange_fnPaste,
2504 ITextRange_fnCanPaste,
2505 ITextRange_fnCanEdit,
2506 ITextRange_fnChangeCase,
2507 ITextRange_fnGetPoint,
2508 ITextRange_fnSetPoint,
2509 ITextRange_fnScrollIntoView,
2510 ITextRange_fnGetEmbeddedObject
2513 /* ITextFont */
2514 static HRESULT WINAPI TextFont_QueryInterface(ITextFont *iface, REFIID riid, void **ppv)
2516 ITextFontImpl *This = impl_from_ITextFont(iface);
2518 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2520 if (IsEqualIID(riid, &IID_ITextFont) ||
2521 IsEqualIID(riid, &IID_IDispatch) ||
2522 IsEqualIID(riid, &IID_IUnknown))
2524 *ppv = iface;
2525 ITextFont_AddRef(iface);
2526 return S_OK;
2529 *ppv = NULL;
2530 return E_NOINTERFACE;
2533 static ULONG WINAPI TextFont_AddRef(ITextFont *iface)
2535 ITextFontImpl *This = impl_from_ITextFont(iface);
2536 ULONG ref = InterlockedIncrement(&This->ref);
2537 TRACE("(%p)->(%u)\n", This, ref);
2538 return ref;
2541 static ULONG WINAPI TextFont_Release(ITextFont *iface)
2543 ITextFontImpl *This = impl_from_ITextFont(iface);
2544 ULONG ref = InterlockedDecrement(&This->ref);
2546 TRACE("(%p)->(%u)\n", This, ref);
2548 if (!ref)
2550 if (This->range)
2551 ITextRange_Release(This->range);
2552 SysFreeString(This->props[FONT_NAME].str);
2553 heap_free(This);
2556 return ref;
2559 static HRESULT WINAPI TextFont_GetTypeInfoCount(ITextFont *iface, UINT *pctinfo)
2561 ITextFontImpl *This = impl_from_ITextFont(iface);
2562 TRACE("(%p)->(%p)\n", This, pctinfo);
2563 *pctinfo = 1;
2564 return S_OK;
2567 static HRESULT WINAPI TextFont_GetTypeInfo(ITextFont *iface, UINT iTInfo, LCID lcid,
2568 ITypeInfo **ppTInfo)
2570 ITextFontImpl *This = impl_from_ITextFont(iface);
2571 HRESULT hr;
2573 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
2575 hr = get_typeinfo(ITextFont_tid, ppTInfo);
2576 if (SUCCEEDED(hr))
2577 ITypeInfo_AddRef(*ppTInfo);
2578 return hr;
2581 static HRESULT WINAPI TextFont_GetIDsOfNames(ITextFont *iface, REFIID riid,
2582 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2584 ITextFontImpl *This = impl_from_ITextFont(iface);
2585 ITypeInfo *ti;
2586 HRESULT hr;
2588 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
2589 rgDispId);
2591 hr = get_typeinfo(ITextFont_tid, &ti);
2592 if (SUCCEEDED(hr))
2593 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
2594 return hr;
2597 static HRESULT WINAPI TextFont_Invoke(
2598 ITextFont *iface,
2599 DISPID dispIdMember,
2600 REFIID riid,
2601 LCID lcid,
2602 WORD wFlags,
2603 DISPPARAMS *pDispParams,
2604 VARIANT *pVarResult,
2605 EXCEPINFO *pExcepInfo,
2606 UINT *puArgErr)
2608 ITextFontImpl *This = impl_from_ITextFont(iface);
2609 ITypeInfo *ti;
2610 HRESULT hr;
2612 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
2613 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2615 hr = get_typeinfo(ITextFont_tid, &ti);
2616 if (SUCCEEDED(hr))
2617 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2618 return hr;
2621 static HRESULT WINAPI TextFont_GetDuplicate(ITextFont *iface, ITextFont **ret)
2623 ITextFontImpl *This = impl_from_ITextFont(iface);
2625 TRACE("(%p)->(%p)\n", This, ret);
2627 if (!ret)
2628 return E_INVALIDARG;
2630 *ret = NULL;
2631 if (This->range && !get_range_reole(This->range))
2632 return CO_E_RELEASED;
2634 return create_textfont(NULL, This, ret);
2637 static HRESULT WINAPI TextFont_SetDuplicate(ITextFont *iface, ITextFont *pFont)
2639 ITextFontImpl *This = impl_from_ITextFont(iface);
2640 FIXME("(%p)->(%p): stub\n", This, pFont);
2641 return E_NOTIMPL;
2644 static HRESULT WINAPI TextFont_CanChange(ITextFont *iface, LONG *ret)
2646 ITextFontImpl *This = impl_from_ITextFont(iface);
2647 FIXME("(%p)->(%p): stub\n", This, ret);
2648 return E_NOTIMPL;
2651 static HRESULT WINAPI TextFont_IsEqual(ITextFont *iface, ITextFont *font, LONG *ret)
2653 ITextFontImpl *This = impl_from_ITextFont(iface);
2654 FIXME("(%p)->(%p %p): stub\n", This, font, ret);
2655 return E_NOTIMPL;
2658 static void textfont_reset_to_default(ITextFontImpl *font)
2660 enum textfont_prop_id id;
2662 for (id = FONT_PROPID_FIRST; id < FONT_PROPID_LAST; id++) {
2663 switch (id)
2665 case FONT_ALLCAPS:
2666 case FONT_ANIMATION:
2667 case FONT_BOLD:
2668 case FONT_EMBOSS:
2669 case FONT_HIDDEN:
2670 case FONT_ENGRAVE:
2671 case FONT_ITALIC:
2672 case FONT_OUTLINE:
2673 case FONT_PROTECTED:
2674 case FONT_SHADOW:
2675 case FONT_SMALLCAPS:
2676 case FONT_STRIKETHROUGH:
2677 case FONT_SUBSCRIPT:
2678 case FONT_SUPERSCRIPT:
2679 case FONT_UNDERLINE:
2680 font->props[id].l = tomFalse;
2681 break;
2682 case FONT_BACKCOLOR:
2683 case FONT_FORECOLOR:
2684 font->props[id].l = tomAutoColor;
2685 break;
2686 case FONT_KERNING:
2687 case FONT_POSITION:
2688 case FONT_SIZE:
2689 case FONT_SPACING:
2690 font->props[id].f = 0.0;
2691 break;
2692 case FONT_LANGID:
2693 font->props[id].l = GetSystemDefaultLCID();
2694 break;
2695 case FONT_NAME: {
2696 static const WCHAR sysW[] = {'S','y','s','t','e','m',0};
2697 SysFreeString(font->props[id].str);
2698 font->props[id].str = SysAllocString(sysW);
2699 break;
2701 case FONT_WEIGHT:
2702 font->props[id].l = FW_NORMAL;
2703 break;
2704 default:
2705 FIXME("font property %d not handled\n", id);
2710 static void textfont_reset_to_undefined(ITextFontImpl *font)
2712 enum textfont_prop_id id;
2714 for (id = FONT_PROPID_FIRST; id < FONT_PROPID_LAST; id++) {
2715 switch (id)
2717 case FONT_ALLCAPS:
2718 case FONT_ANIMATION:
2719 case FONT_BOLD:
2720 case FONT_EMBOSS:
2721 case FONT_HIDDEN:
2722 case FONT_ENGRAVE:
2723 case FONT_ITALIC:
2724 case FONT_OUTLINE:
2725 case FONT_PROTECTED:
2726 case FONT_SHADOW:
2727 case FONT_SMALLCAPS:
2728 case FONT_STRIKETHROUGH:
2729 case FONT_SUBSCRIPT:
2730 case FONT_SUPERSCRIPT:
2731 case FONT_UNDERLINE:
2732 case FONT_BACKCOLOR:
2733 case FONT_FORECOLOR:
2734 case FONT_LANGID:
2735 case FONT_WEIGHT:
2736 font->props[id].l = tomUndefined;
2737 break;
2738 case FONT_KERNING:
2739 case FONT_POSITION:
2740 case FONT_SIZE:
2741 case FONT_SPACING:
2742 font->props[id].f = tomUndefined;
2743 break;
2744 case FONT_NAME:
2745 break;
2746 default:
2747 FIXME("font property %d not handled\n", id);
2752 static void textfont_apply_range_props(ITextFontImpl *font)
2754 enum textfont_prop_id propid;
2755 for (propid = FONT_PROPID_FIRST; propid < FONT_PROPID_LAST; propid++)
2756 set_textfont_prop(font, propid, &font->props[propid]);
2759 static HRESULT WINAPI TextFont_Reset(ITextFont *iface, LONG value)
2761 ITextFontImpl *This = impl_from_ITextFont(iface);
2763 TRACE("(%p)->(%d)\n", This, value);
2765 /* If font is attached to a range, released or not, we can't
2766 reset to undefined */
2767 if (This->range) {
2768 if (!get_range_reole(This->range))
2769 return CO_E_RELEASED;
2771 switch (value)
2773 case tomUndefined:
2774 return E_INVALIDARG;
2775 case tomCacheParms:
2776 textfont_cache_range_props(This);
2777 This->get_cache_enabled = TRUE;
2778 break;
2779 case tomTrackParms:
2780 This->get_cache_enabled = FALSE;
2781 break;
2782 case tomApplyLater:
2783 This->set_cache_enabled = TRUE;
2784 break;
2785 case tomApplyNow:
2786 This->set_cache_enabled = FALSE;
2787 textfont_apply_range_props(This);
2788 break;
2789 case tomUsePoints:
2790 case tomUseTwips:
2791 return E_INVALIDARG;
2792 default:
2793 FIXME("reset mode %d not supported\n", value);
2796 return S_OK;
2798 else {
2799 switch (value)
2801 /* reset to global defaults */
2802 case tomDefault:
2803 textfont_reset_to_default(This);
2804 return S_OK;
2805 /* all properties are set to tomUndefined, font name is retained */
2806 case tomUndefined:
2807 textfont_reset_to_undefined(This);
2808 return S_OK;
2809 case tomApplyNow:
2810 case tomApplyLater:
2811 case tomTrackParms:
2812 case tomCacheParms:
2813 return S_OK;
2814 case tomUsePoints:
2815 case tomUseTwips:
2816 return E_INVALIDARG;
2820 FIXME("reset mode %d not supported\n", value);
2821 return E_NOTIMPL;
2824 static HRESULT WINAPI TextFont_GetStyle(ITextFont *iface, LONG *value)
2826 ITextFontImpl *This = impl_from_ITextFont(iface);
2827 FIXME("(%p)->(%p): stub\n", This, value);
2828 return E_NOTIMPL;
2831 static HRESULT WINAPI TextFont_SetStyle(ITextFont *iface, LONG value)
2833 ITextFontImpl *This = impl_from_ITextFont(iface);
2834 FIXME("(%p)->(%d): stub\n", This, value);
2835 return E_NOTIMPL;
2838 static HRESULT WINAPI TextFont_GetAllCaps(ITextFont *iface, LONG *value)
2840 ITextFontImpl *This = impl_from_ITextFont(iface);
2841 TRACE("(%p)->(%p)\n", This, value);
2842 return get_textfont_propl(This, FONT_ALLCAPS, value);
2845 static HRESULT WINAPI TextFont_SetAllCaps(ITextFont *iface, LONG value)
2847 ITextFontImpl *This = impl_from_ITextFont(iface);
2848 TRACE("(%p)->(%d)\n", This, value);
2849 return set_textfont_propd(This, FONT_ALLCAPS, value);
2852 static HRESULT WINAPI TextFont_GetAnimation(ITextFont *iface, LONG *value)
2854 ITextFontImpl *This = impl_from_ITextFont(iface);
2855 TRACE("(%p)->(%p)\n", This, value);
2856 return get_textfont_propl(This, FONT_ANIMATION, value);
2859 static HRESULT WINAPI TextFont_SetAnimation(ITextFont *iface, LONG value)
2861 ITextFontImpl *This = impl_from_ITextFont(iface);
2863 TRACE("(%p)->(%d)\n", This, value);
2865 if (value < tomNoAnimation || value > tomAnimationMax)
2866 return E_INVALIDARG;
2868 return set_textfont_propl(This, FONT_ANIMATION, value);
2871 static HRESULT WINAPI TextFont_GetBackColor(ITextFont *iface, LONG *value)
2873 ITextFontImpl *This = impl_from_ITextFont(iface);
2874 TRACE("(%p)->(%p)\n", This, value);
2875 return get_textfont_propl(This, FONT_BACKCOLOR, value);
2878 static HRESULT WINAPI TextFont_SetBackColor(ITextFont *iface, LONG value)
2880 ITextFontImpl *This = impl_from_ITextFont(iface);
2881 TRACE("(%p)->(%d)\n", This, value);
2882 return set_textfont_propl(This, FONT_BACKCOLOR, value);
2885 static HRESULT WINAPI TextFont_GetBold(ITextFont *iface, LONG *value)
2887 ITextFontImpl *This = impl_from_ITextFont(iface);
2888 TRACE("(%p)->(%p)\n", This, value);
2889 return get_textfont_propl(This, FONT_BOLD, value);
2892 static HRESULT WINAPI TextFont_SetBold(ITextFont *iface, LONG value)
2894 ITextFontImpl *This = impl_from_ITextFont(iface);
2895 TRACE("(%p)->(%d)\n", This, value);
2896 return set_textfont_propd(This, FONT_BOLD, value);
2899 static HRESULT WINAPI TextFont_GetEmboss(ITextFont *iface, LONG *value)
2901 ITextFontImpl *This = impl_from_ITextFont(iface);
2902 TRACE("(%p)->(%p)\n", This, value);
2903 return get_textfont_propl(This, FONT_EMBOSS, value);
2906 static HRESULT WINAPI TextFont_SetEmboss(ITextFont *iface, LONG value)
2908 ITextFontImpl *This = impl_from_ITextFont(iface);
2909 TRACE("(%p)->(%d)\n", This, value);
2910 return set_textfont_propd(This, FONT_EMBOSS, value);
2913 static HRESULT WINAPI TextFont_GetForeColor(ITextFont *iface, LONG *value)
2915 ITextFontImpl *This = impl_from_ITextFont(iface);
2916 TRACE("(%p)->(%p)\n", This, value);
2917 return get_textfont_propl(This, FONT_FORECOLOR, value);
2920 static HRESULT WINAPI TextFont_SetForeColor(ITextFont *iface, LONG value)
2922 ITextFontImpl *This = impl_from_ITextFont(iface);
2923 TRACE("(%p)->(%d)\n", This, value);
2924 return set_textfont_propl(This, FONT_FORECOLOR, value);
2927 static HRESULT WINAPI TextFont_GetHidden(ITextFont *iface, LONG *value)
2929 ITextFontImpl *This = impl_from_ITextFont(iface);
2930 TRACE("(%p)->(%p)\n", This, value);
2931 return get_textfont_propl(This, FONT_HIDDEN, value);
2934 static HRESULT WINAPI TextFont_SetHidden(ITextFont *iface, LONG value)
2936 ITextFontImpl *This = impl_from_ITextFont(iface);
2937 TRACE("(%p)->(%d)\n", This, value);
2938 return set_textfont_propd(This, FONT_HIDDEN, value);
2941 static HRESULT WINAPI TextFont_GetEngrave(ITextFont *iface, LONG *value)
2943 ITextFontImpl *This = impl_from_ITextFont(iface);
2944 TRACE("(%p)->(%p)\n", This, value);
2945 return get_textfont_propl(This, FONT_ENGRAVE, value);
2948 static HRESULT WINAPI TextFont_SetEngrave(ITextFont *iface, LONG value)
2950 ITextFontImpl *This = impl_from_ITextFont(iface);
2951 TRACE("(%p)->(%d)\n", This, value);
2952 return set_textfont_propd(This, FONT_ENGRAVE, value);
2955 static HRESULT WINAPI TextFont_GetItalic(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_ITALIC, value);
2962 static HRESULT WINAPI TextFont_SetItalic(ITextFont *iface, LONG value)
2964 ITextFontImpl *This = impl_from_ITextFont(iface);
2965 TRACE("(%p)->(%d)\n", This, value);
2966 return set_textfont_propd(This, FONT_ITALIC, value);
2969 static HRESULT WINAPI TextFont_GetKerning(ITextFont *iface, FLOAT *value)
2971 ITextFontImpl *This = impl_from_ITextFont(iface);
2972 TRACE("(%p)->(%p)\n", This, value);
2973 return get_textfont_propf(This, FONT_KERNING, value);
2976 static HRESULT WINAPI TextFont_SetKerning(ITextFont *iface, FLOAT value)
2978 ITextFontImpl *This = impl_from_ITextFont(iface);
2979 TRACE("(%p)->(%.2f)\n", This, value);
2980 return set_textfont_propf(This, FONT_KERNING, value);
2983 static HRESULT WINAPI TextFont_GetLanguageID(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_LANGID, value);
2990 static HRESULT WINAPI TextFont_SetLanguageID(ITextFont *iface, LONG value)
2992 ITextFontImpl *This = impl_from_ITextFont(iface);
2993 TRACE("(%p)->(%d)\n", This, value);
2994 return set_textfont_propl(This, FONT_LANGID, value);
2997 static HRESULT WINAPI TextFont_GetName(ITextFont *iface, BSTR *value)
2999 ITextFontImpl *This = impl_from_ITextFont(iface);
3001 TRACE("(%p)->(%p)\n", This, value);
3003 if (!value)
3004 return E_INVALIDARG;
3006 *value = NULL;
3008 if (!This->range) {
3009 if (This->props[FONT_NAME].str)
3010 *value = SysAllocString(This->props[FONT_NAME].str);
3011 else
3012 *value = SysAllocStringLen(NULL, 0);
3013 return *value ? S_OK : E_OUTOFMEMORY;
3016 return textfont_getname_from_range(This->range, value);
3019 static HRESULT WINAPI TextFont_SetName(ITextFont *iface, BSTR value)
3021 ITextFontImpl *This = impl_from_ITextFont(iface);
3022 textfont_prop_val v;
3024 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
3026 v.str = value;
3027 return set_textfont_prop(This, FONT_NAME, &v);
3030 static HRESULT WINAPI TextFont_GetOutline(ITextFont *iface, LONG *value)
3032 ITextFontImpl *This = impl_from_ITextFont(iface);
3033 TRACE("(%p)->(%p)\n", This, value);
3034 return get_textfont_propl(This, FONT_OUTLINE, value);
3037 static HRESULT WINAPI TextFont_SetOutline(ITextFont *iface, LONG value)
3039 ITextFontImpl *This = impl_from_ITextFont(iface);
3040 TRACE("(%p)->(%d)\n", This, value);
3041 return set_textfont_propd(This, FONT_OUTLINE, value);
3044 static HRESULT WINAPI TextFont_GetPosition(ITextFont *iface, FLOAT *value)
3046 ITextFontImpl *This = impl_from_ITextFont(iface);
3047 TRACE("(%p)->(%p)\n", This, value);
3048 return get_textfont_propf(This, FONT_POSITION, value);
3051 static HRESULT WINAPI TextFont_SetPosition(ITextFont *iface, FLOAT value)
3053 ITextFontImpl *This = impl_from_ITextFont(iface);
3054 TRACE("(%p)->(%.2f)\n", This, value);
3055 return set_textfont_propf(This, FONT_POSITION, value);
3058 static HRESULT WINAPI TextFont_GetProtected(ITextFont *iface, LONG *value)
3060 ITextFontImpl *This = impl_from_ITextFont(iface);
3061 TRACE("(%p)->(%p)\n", This, value);
3062 return get_textfont_propl(This, FONT_PROTECTED, value);
3065 static HRESULT WINAPI TextFont_SetProtected(ITextFont *iface, LONG value)
3067 ITextFontImpl *This = impl_from_ITextFont(iface);
3068 TRACE("(%p)->(%d)\n", This, value);
3069 return set_textfont_propd(This, FONT_PROTECTED, value);
3072 static HRESULT WINAPI TextFont_GetShadow(ITextFont *iface, LONG *value)
3074 ITextFontImpl *This = impl_from_ITextFont(iface);
3075 TRACE("(%p)->(%p)\n", This, value);
3076 return get_textfont_propl(This, FONT_SHADOW, value);
3079 static HRESULT WINAPI TextFont_SetShadow(ITextFont *iface, LONG value)
3081 ITextFontImpl *This = impl_from_ITextFont(iface);
3082 TRACE("(%p)->(%d)\n", This, value);
3083 return set_textfont_propd(This, FONT_SHADOW, value);
3086 static HRESULT WINAPI TextFont_GetSize(ITextFont *iface, FLOAT *value)
3088 ITextFontImpl *This = impl_from_ITextFont(iface);
3089 TRACE("(%p)->(%p)\n", This, value);
3090 return get_textfont_propf(This, FONT_SIZE, value);
3093 static HRESULT WINAPI TextFont_SetSize(ITextFont *iface, FLOAT value)
3095 ITextFontImpl *This = impl_from_ITextFont(iface);
3096 TRACE("(%p)->(%.2f)\n", This, value);
3097 return set_textfont_propf(This, FONT_SIZE, value);
3100 static HRESULT WINAPI TextFont_GetSmallCaps(ITextFont *iface, LONG *value)
3102 ITextFontImpl *This = impl_from_ITextFont(iface);
3103 TRACE("(%p)->(%p)\n", This, value);
3104 return get_textfont_propl(This, FONT_SMALLCAPS, value);
3107 static HRESULT WINAPI TextFont_SetSmallCaps(ITextFont *iface, LONG value)
3109 ITextFontImpl *This = impl_from_ITextFont(iface);
3110 TRACE("(%p)->(%d)\n", This, value);
3111 return set_textfont_propd(This, FONT_SMALLCAPS, value);
3114 static HRESULT WINAPI TextFont_GetSpacing(ITextFont *iface, FLOAT *value)
3116 ITextFontImpl *This = impl_from_ITextFont(iface);
3117 TRACE("(%p)->(%p)\n", This, value);
3118 return get_textfont_propf(This, FONT_SPACING, value);
3121 static HRESULT WINAPI TextFont_SetSpacing(ITextFont *iface, FLOAT value)
3123 ITextFontImpl *This = impl_from_ITextFont(iface);
3124 TRACE("(%p)->(%.2f)\n", This, value);
3125 return set_textfont_propf(This, FONT_SPACING, value);
3128 static HRESULT WINAPI TextFont_GetStrikeThrough(ITextFont *iface, LONG *value)
3130 ITextFontImpl *This = impl_from_ITextFont(iface);
3131 TRACE("(%p)->(%p)\n", This, value);
3132 return get_textfont_propl(This, FONT_STRIKETHROUGH, value);
3135 static HRESULT WINAPI TextFont_SetStrikeThrough(ITextFont *iface, LONG value)
3137 ITextFontImpl *This = impl_from_ITextFont(iface);
3138 TRACE("(%p)->(%d)\n", This, value);
3139 return set_textfont_propd(This, FONT_STRIKETHROUGH, value);
3142 static HRESULT WINAPI TextFont_GetSubscript(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_SUBSCRIPT, value);
3149 static HRESULT WINAPI TextFont_SetSubscript(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_SUBSCRIPT, value);
3156 static HRESULT WINAPI TextFont_GetSuperscript(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_SUPERSCRIPT, value);
3163 static HRESULT WINAPI TextFont_SetSuperscript(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_SUPERSCRIPT, value);
3170 static HRESULT WINAPI TextFont_GetUnderline(ITextFont *iface, LONG *value)
3172 ITextFontImpl *This = impl_from_ITextFont(iface);
3173 TRACE("(%p)->(%p)\n", This, value);
3174 return get_textfont_propl(This, FONT_UNDERLINE, value);
3177 static HRESULT WINAPI TextFont_SetUnderline(ITextFont *iface, LONG value)
3179 ITextFontImpl *This = impl_from_ITextFont(iface);
3180 TRACE("(%p)->(%d)\n", This, value);
3181 return set_textfont_propd(This, FONT_UNDERLINE, value);
3184 static HRESULT WINAPI TextFont_GetWeight(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_WEIGHT, value);
3191 static HRESULT WINAPI TextFont_SetWeight(ITextFont *iface, LONG value)
3193 ITextFontImpl *This = impl_from_ITextFont(iface);
3194 TRACE("(%p)->(%d)\n", This, value);
3195 return set_textfont_propl(This, FONT_WEIGHT, value);
3198 static ITextFontVtbl textfontvtbl = {
3199 TextFont_QueryInterface,
3200 TextFont_AddRef,
3201 TextFont_Release,
3202 TextFont_GetTypeInfoCount,
3203 TextFont_GetTypeInfo,
3204 TextFont_GetIDsOfNames,
3205 TextFont_Invoke,
3206 TextFont_GetDuplicate,
3207 TextFont_SetDuplicate,
3208 TextFont_CanChange,
3209 TextFont_IsEqual,
3210 TextFont_Reset,
3211 TextFont_GetStyle,
3212 TextFont_SetStyle,
3213 TextFont_GetAllCaps,
3214 TextFont_SetAllCaps,
3215 TextFont_GetAnimation,
3216 TextFont_SetAnimation,
3217 TextFont_GetBackColor,
3218 TextFont_SetBackColor,
3219 TextFont_GetBold,
3220 TextFont_SetBold,
3221 TextFont_GetEmboss,
3222 TextFont_SetEmboss,
3223 TextFont_GetForeColor,
3224 TextFont_SetForeColor,
3225 TextFont_GetHidden,
3226 TextFont_SetHidden,
3227 TextFont_GetEngrave,
3228 TextFont_SetEngrave,
3229 TextFont_GetItalic,
3230 TextFont_SetItalic,
3231 TextFont_GetKerning,
3232 TextFont_SetKerning,
3233 TextFont_GetLanguageID,
3234 TextFont_SetLanguageID,
3235 TextFont_GetName,
3236 TextFont_SetName,
3237 TextFont_GetOutline,
3238 TextFont_SetOutline,
3239 TextFont_GetPosition,
3240 TextFont_SetPosition,
3241 TextFont_GetProtected,
3242 TextFont_SetProtected,
3243 TextFont_GetShadow,
3244 TextFont_SetShadow,
3245 TextFont_GetSize,
3246 TextFont_SetSize,
3247 TextFont_GetSmallCaps,
3248 TextFont_SetSmallCaps,
3249 TextFont_GetSpacing,
3250 TextFont_SetSpacing,
3251 TextFont_GetStrikeThrough,
3252 TextFont_SetStrikeThrough,
3253 TextFont_GetSubscript,
3254 TextFont_SetSubscript,
3255 TextFont_GetSuperscript,
3256 TextFont_SetSuperscript,
3257 TextFont_GetUnderline,
3258 TextFont_SetUnderline,
3259 TextFont_GetWeight,
3260 TextFont_SetWeight
3263 static HRESULT create_textfont(ITextRange *range, const ITextFontImpl *src, ITextFont **ret)
3265 ITextFontImpl *font;
3267 *ret = NULL;
3268 font = heap_alloc(sizeof(*font));
3269 if (!font)
3270 return E_OUTOFMEMORY;
3272 font->ITextFont_iface.lpVtbl = &textfontvtbl;
3273 font->ref = 1;
3275 if (src) {
3276 font->range = NULL;
3277 font->get_cache_enabled = TRUE;
3278 font->set_cache_enabled = TRUE;
3279 memcpy(&font->props, &src->props, sizeof(font->props));
3280 if (font->props[FONT_NAME].str)
3281 font->props[FONT_NAME].str = SysAllocString(font->props[FONT_NAME].str);
3283 else {
3284 font->range = range;
3285 ITextRange_AddRef(range);
3287 /* cache current properties */
3288 font->get_cache_enabled = FALSE;
3289 font->set_cache_enabled = FALSE;
3290 textfont_cache_range_props(font);
3293 *ret = &font->ITextFont_iface;
3294 return S_OK;
3297 /* ITextPara */
3298 static HRESULT WINAPI TextPara_QueryInterface(ITextPara *iface, REFIID riid, void **ppv)
3300 ITextParaImpl *This = impl_from_ITextPara(iface);
3302 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
3304 if (IsEqualIID(riid, &IID_ITextPara) ||
3305 IsEqualIID(riid, &IID_IDispatch) ||
3306 IsEqualIID(riid, &IID_IUnknown))
3308 *ppv = iface;
3309 ITextPara_AddRef(iface);
3310 return S_OK;
3313 *ppv = NULL;
3314 return E_NOINTERFACE;
3317 static ULONG WINAPI TextPara_AddRef(ITextPara *iface)
3319 ITextParaImpl *This = impl_from_ITextPara(iface);
3320 ULONG ref = InterlockedIncrement(&This->ref);
3321 TRACE("(%p)->(%u)\n", This, ref);
3322 return ref;
3325 static ULONG WINAPI TextPara_Release(ITextPara *iface)
3327 ITextParaImpl *This = impl_from_ITextPara(iface);
3328 ULONG ref = InterlockedDecrement(&This->ref);
3330 TRACE("(%p)->(%u)\n", This, ref);
3332 if (!ref)
3334 ITextRange_Release(This->range);
3335 heap_free(This);
3338 return ref;
3341 static HRESULT WINAPI TextPara_GetTypeInfoCount(ITextPara *iface, UINT *pctinfo)
3343 ITextParaImpl *This = impl_from_ITextPara(iface);
3344 TRACE("(%p)->(%p)\n", This, pctinfo);
3345 *pctinfo = 1;
3346 return S_OK;
3349 static HRESULT WINAPI TextPara_GetTypeInfo(ITextPara *iface, UINT iTInfo, LCID lcid,
3350 ITypeInfo **ppTInfo)
3352 ITextParaImpl *This = impl_from_ITextPara(iface);
3353 HRESULT hr;
3355 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3357 hr = get_typeinfo(ITextPara_tid, ppTInfo);
3358 if (SUCCEEDED(hr))
3359 ITypeInfo_AddRef(*ppTInfo);
3360 return hr;
3363 static HRESULT WINAPI TextPara_GetIDsOfNames(ITextPara *iface, REFIID riid,
3364 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3366 ITextParaImpl *This = impl_from_ITextPara(iface);
3367 ITypeInfo *ti;
3368 HRESULT hr;
3370 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
3371 rgDispId);
3373 hr = get_typeinfo(ITextPara_tid, &ti);
3374 if (SUCCEEDED(hr))
3375 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3376 return hr;
3379 static HRESULT WINAPI TextPara_Invoke(
3380 ITextPara *iface,
3381 DISPID dispIdMember,
3382 REFIID riid,
3383 LCID lcid,
3384 WORD wFlags,
3385 DISPPARAMS *pDispParams,
3386 VARIANT *pVarResult,
3387 EXCEPINFO *pExcepInfo,
3388 UINT *puArgErr)
3390 ITextParaImpl *This = impl_from_ITextPara(iface);
3391 ITypeInfo *ti;
3392 HRESULT hr;
3394 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
3395 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3397 hr = get_typeinfo(ITextPara_tid, &ti);
3398 if (SUCCEEDED(hr))
3399 hr = ITypeInfo_Invoke(ti, iface, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3400 return hr;
3403 static HRESULT WINAPI TextPara_GetDuplicate(ITextPara *iface, ITextPara **ret)
3405 ITextParaImpl *This = impl_from_ITextPara(iface);
3406 FIXME("(%p)->(%p)\n", This, ret);
3407 return E_NOTIMPL;
3410 static HRESULT WINAPI TextPara_SetDuplicate(ITextPara *iface, ITextPara *para)
3412 ITextParaImpl *This = impl_from_ITextPara(iface);
3413 FIXME("(%p)->(%p)\n", This, para);
3414 return E_NOTIMPL;
3417 static HRESULT WINAPI TextPara_CanChange(ITextPara *iface, LONG *ret)
3419 ITextParaImpl *This = impl_from_ITextPara(iface);
3420 FIXME("(%p)->(%p)\n", This, ret);
3421 return E_NOTIMPL;
3424 static HRESULT WINAPI TextPara_IsEqual(ITextPara *iface, ITextPara *para, LONG *ret)
3426 ITextParaImpl *This = impl_from_ITextPara(iface);
3427 FIXME("(%p)->(%p %p)\n", This, para, ret);
3428 return E_NOTIMPL;
3431 static HRESULT WINAPI TextPara_Reset(ITextPara *iface, LONG value)
3433 ITextParaImpl *This = impl_from_ITextPara(iface);
3434 FIXME("(%p)->(%d)\n", This, value);
3435 return E_NOTIMPL;
3438 static HRESULT WINAPI TextPara_GetStyle(ITextPara *iface, LONG *value)
3440 ITextParaImpl *This = impl_from_ITextPara(iface);
3441 FIXME("(%p)->(%p)\n", This, value);
3442 return E_NOTIMPL;
3445 static HRESULT WINAPI TextPara_SetStyle(ITextPara *iface, LONG value)
3447 ITextParaImpl *This = impl_from_ITextPara(iface);
3448 FIXME("(%p)->(%d)\n", This, value);
3449 return E_NOTIMPL;
3452 static HRESULT WINAPI TextPara_GetAlignment(ITextPara *iface, LONG *value)
3454 ITextParaImpl *This = impl_from_ITextPara(iface);
3455 FIXME("(%p)->(%p)\n", This, value);
3456 return E_NOTIMPL;
3459 static HRESULT WINAPI TextPara_SetAlignment(ITextPara *iface, LONG value)
3461 ITextParaImpl *This = impl_from_ITextPara(iface);
3462 FIXME("(%p)->(%d)\n", This, value);
3463 return E_NOTIMPL;
3466 static HRESULT WINAPI TextPara_GetHyphenation(ITextPara *iface, LONG *value)
3468 ITextParaImpl *This = impl_from_ITextPara(iface);
3469 FIXME("(%p)->(%p)\n", This, value);
3470 return E_NOTIMPL;
3473 static HRESULT WINAPI TextPara_SetHyphenation(ITextPara *iface, LONG value)
3475 ITextParaImpl *This = impl_from_ITextPara(iface);
3476 FIXME("(%p)->(%d)\n", This, value);
3477 return E_NOTIMPL;
3480 static HRESULT WINAPI TextPara_GetFirstLineIndent(ITextPara *iface, FLOAT *value)
3482 ITextParaImpl *This = impl_from_ITextPara(iface);
3483 FIXME("(%p)->(%p)\n", This, value);
3484 return E_NOTIMPL;
3487 static HRESULT WINAPI TextPara_GetKeepTogether(ITextPara *iface, LONG *value)
3489 ITextParaImpl *This = impl_from_ITextPara(iface);
3490 FIXME("(%p)->(%p)\n", This, value);
3491 return E_NOTIMPL;
3494 static HRESULT WINAPI TextPara_SetKeepTogether(ITextPara *iface, LONG value)
3496 ITextParaImpl *This = impl_from_ITextPara(iface);
3497 FIXME("(%p)->(%d)\n", This, value);
3498 return E_NOTIMPL;
3501 static HRESULT WINAPI TextPara_GetKeepWithNext(ITextPara *iface, LONG *value)
3503 ITextParaImpl *This = impl_from_ITextPara(iface);
3504 FIXME("(%p)->(%p)\n", This, value);
3505 return E_NOTIMPL;
3508 static HRESULT WINAPI TextPara_SetKeepWithNext(ITextPara *iface, LONG value)
3510 ITextParaImpl *This = impl_from_ITextPara(iface);
3511 FIXME("(%p)->(%d)\n", This, value);
3512 return E_NOTIMPL;
3515 static HRESULT WINAPI TextPara_GetLeftIndent(ITextPara *iface, FLOAT *value)
3517 ITextParaImpl *This = impl_from_ITextPara(iface);
3518 FIXME("(%p)->(%p)\n", This, value);
3519 return E_NOTIMPL;
3522 static HRESULT WINAPI TextPara_GetLineSpacing(ITextPara *iface, FLOAT *value)
3524 ITextParaImpl *This = impl_from_ITextPara(iface);
3525 FIXME("(%p)->(%p)\n", This, value);
3526 return E_NOTIMPL;
3529 static HRESULT WINAPI TextPara_GetLineSpacingRule(ITextPara *iface, LONG *value)
3531 ITextParaImpl *This = impl_from_ITextPara(iface);
3532 FIXME("(%p)->(%p)\n", This, value);
3533 return E_NOTIMPL;
3536 static HRESULT WINAPI TextPara_GetListAlignment(ITextPara *iface, LONG *value)
3538 ITextParaImpl *This = impl_from_ITextPara(iface);
3539 FIXME("(%p)->(%p)\n", This, value);
3540 return E_NOTIMPL;
3543 static HRESULT WINAPI TextPara_SetListAlignment(ITextPara *iface, LONG value)
3545 ITextParaImpl *This = impl_from_ITextPara(iface);
3546 FIXME("(%p)->(%d)\n", This, value);
3547 return E_NOTIMPL;
3550 static HRESULT WINAPI TextPara_GetListLevelIndex(ITextPara *iface, LONG *value)
3552 ITextParaImpl *This = impl_from_ITextPara(iface);
3553 FIXME("(%p)->(%p)\n", This, value);
3554 return E_NOTIMPL;
3557 static HRESULT WINAPI TextPara_SetListLevelIndex(ITextPara *iface, LONG value)
3559 ITextParaImpl *This = impl_from_ITextPara(iface);
3560 FIXME("(%p)->(%d)\n", This, value);
3561 return E_NOTIMPL;
3564 static HRESULT WINAPI TextPara_GetListStart(ITextPara *iface, LONG *value)
3566 ITextParaImpl *This = impl_from_ITextPara(iface);
3567 FIXME("(%p)->(%p)\n", This, value);
3568 return E_NOTIMPL;
3571 static HRESULT WINAPI TextPara_SetListStart(ITextPara *iface, LONG value)
3573 ITextParaImpl *This = impl_from_ITextPara(iface);
3574 FIXME("(%p)->(%d)\n", This, value);
3575 return E_NOTIMPL;
3578 static HRESULT WINAPI TextPara_GetListTab(ITextPara *iface, FLOAT *value)
3580 ITextParaImpl *This = impl_from_ITextPara(iface);
3581 FIXME("(%p)->(%p)\n", This, value);
3582 return E_NOTIMPL;
3585 static HRESULT WINAPI TextPara_SetListTab(ITextPara *iface, FLOAT value)
3587 ITextParaImpl *This = impl_from_ITextPara(iface);
3588 FIXME("(%p)->(%.2f)\n", This, value);
3589 return E_NOTIMPL;
3592 static HRESULT WINAPI TextPara_GetListType(ITextPara *iface, LONG *value)
3594 ITextParaImpl *This = impl_from_ITextPara(iface);
3595 FIXME("(%p)->(%p)\n", This, value);
3596 return E_NOTIMPL;
3599 static HRESULT WINAPI TextPara_SetListType(ITextPara *iface, LONG value)
3601 ITextParaImpl *This = impl_from_ITextPara(iface);
3602 FIXME("(%p)->(%d)\n", This, value);
3603 return E_NOTIMPL;
3606 static HRESULT WINAPI TextPara_GetNoLineNumber(ITextPara *iface, LONG *value)
3608 ITextParaImpl *This = impl_from_ITextPara(iface);
3609 FIXME("(%p)->(%p)\n", This, value);
3610 return E_NOTIMPL;
3613 static HRESULT WINAPI TextPara_SetNoLineNumber(ITextPara *iface, LONG value)
3615 ITextParaImpl *This = impl_from_ITextPara(iface);
3616 FIXME("(%p)->(%d)\n", This, value);
3617 return E_NOTIMPL;
3620 static HRESULT WINAPI TextPara_GetPageBreakBefore(ITextPara *iface, LONG *value)
3622 ITextParaImpl *This = impl_from_ITextPara(iface);
3623 FIXME("(%p)->(%p)\n", This, value);
3624 return E_NOTIMPL;
3627 static HRESULT WINAPI TextPara_SetPageBreakBefore(ITextPara *iface, LONG value)
3629 ITextParaImpl *This = impl_from_ITextPara(iface);
3630 FIXME("(%p)->(%d)\n", This, value);
3631 return E_NOTIMPL;
3634 static HRESULT WINAPI TextPara_GetRightIndent(ITextPara *iface, FLOAT *value)
3636 ITextParaImpl *This = impl_from_ITextPara(iface);
3637 FIXME("(%p)->(%p)\n", This, value);
3638 return E_NOTIMPL;
3641 static HRESULT WINAPI TextPara_SetRightIndent(ITextPara *iface, FLOAT value)
3643 ITextParaImpl *This = impl_from_ITextPara(iface);
3644 FIXME("(%p)->(%.2f)\n", This, value);
3645 return E_NOTIMPL;
3648 static HRESULT WINAPI TextPara_SetIndents(ITextPara *iface, FLOAT StartIndent, FLOAT LeftIndent, FLOAT RightIndent)
3650 ITextParaImpl *This = impl_from_ITextPara(iface);
3651 FIXME("(%p)->(%.2f %.2f %.2f)\n", This, StartIndent, LeftIndent, RightIndent);
3652 return E_NOTIMPL;
3655 static HRESULT WINAPI TextPara_SetLineSpacing(ITextPara *iface, LONG LineSpacingRule, FLOAT LineSpacing)
3657 ITextParaImpl *This = impl_from_ITextPara(iface);
3658 FIXME("(%p)->(%d %.2f)\n", This, LineSpacingRule, LineSpacing);
3659 return E_NOTIMPL;
3662 static HRESULT WINAPI TextPara_GetSpaceAfter(ITextPara *iface, FLOAT *value)
3664 ITextParaImpl *This = impl_from_ITextPara(iface);
3665 FIXME("(%p)->(%p)\n", This, value);
3666 return E_NOTIMPL;
3669 static HRESULT WINAPI TextPara_SetSpaceAfter(ITextPara *iface, FLOAT value)
3671 ITextParaImpl *This = impl_from_ITextPara(iface);
3672 FIXME("(%p)->(%.2f)\n", This, value);
3673 return E_NOTIMPL;
3676 static HRESULT WINAPI TextPara_GetSpaceBefore(ITextPara *iface, FLOAT *value)
3678 ITextParaImpl *This = impl_from_ITextPara(iface);
3679 FIXME("(%p)->(%p)\n", This, value);
3680 return E_NOTIMPL;
3683 static HRESULT WINAPI TextPara_SetSpaceBefore(ITextPara *iface, FLOAT value)
3685 ITextParaImpl *This = impl_from_ITextPara(iface);
3686 FIXME("(%p)->(%.2f)\n", This, value);
3687 return E_NOTIMPL;
3690 static HRESULT WINAPI TextPara_GetWidowControl(ITextPara *iface, LONG *value)
3692 ITextParaImpl *This = impl_from_ITextPara(iface);
3693 FIXME("(%p)->(%p)\n", This, value);
3694 return E_NOTIMPL;
3697 static HRESULT WINAPI TextPara_SetWidowControl(ITextPara *iface, LONG value)
3699 ITextParaImpl *This = impl_from_ITextPara(iface);
3700 FIXME("(%p)->(%d)\n", This, value);
3701 return E_NOTIMPL;
3704 static HRESULT WINAPI TextPara_GetTabCount(ITextPara *iface, LONG *value)
3706 ITextParaImpl *This = impl_from_ITextPara(iface);
3707 FIXME("(%p)->(%p)\n", This, value);
3708 return E_NOTIMPL;
3711 static HRESULT WINAPI TextPara_AddTab(ITextPara *iface, FLOAT tbPos, LONG tbAlign, LONG tbLeader)
3713 ITextParaImpl *This = impl_from_ITextPara(iface);
3714 FIXME("(%p)->(%.2f %d %d)\n", This, tbPos, tbAlign, tbLeader);
3715 return E_NOTIMPL;
3718 static HRESULT WINAPI TextPara_ClearAllTabs(ITextPara *iface)
3720 ITextParaImpl *This = impl_from_ITextPara(iface);
3721 FIXME("(%p)\n", This);
3722 return E_NOTIMPL;
3725 static HRESULT WINAPI TextPara_DeleteTab(ITextPara *iface, FLOAT pos)
3727 ITextParaImpl *This = impl_from_ITextPara(iface);
3728 FIXME("(%p)->(%.2f)\n", This, pos);
3729 return E_NOTIMPL;
3732 static HRESULT WINAPI TextPara_GetTab(ITextPara *iface, LONG iTab, FLOAT *ptbPos, LONG *ptbAlign, LONG *ptbLeader)
3734 ITextParaImpl *This = impl_from_ITextPara(iface);
3735 FIXME("(%p)->(%d %p %p %p)\n", This, iTab, ptbPos, ptbAlign, ptbLeader);
3736 return E_NOTIMPL;
3739 static ITextParaVtbl textparavtbl = {
3740 TextPara_QueryInterface,
3741 TextPara_AddRef,
3742 TextPara_Release,
3743 TextPara_GetTypeInfoCount,
3744 TextPara_GetTypeInfo,
3745 TextPara_GetIDsOfNames,
3746 TextPara_Invoke,
3747 TextPara_GetDuplicate,
3748 TextPara_SetDuplicate,
3749 TextPara_CanChange,
3750 TextPara_IsEqual,
3751 TextPara_Reset,
3752 TextPara_GetStyle,
3753 TextPara_SetStyle,
3754 TextPara_GetAlignment,
3755 TextPara_SetAlignment,
3756 TextPara_GetHyphenation,
3757 TextPara_SetHyphenation,
3758 TextPara_GetFirstLineIndent,
3759 TextPara_GetKeepTogether,
3760 TextPara_SetKeepTogether,
3761 TextPara_GetKeepWithNext,
3762 TextPara_SetKeepWithNext,
3763 TextPara_GetLeftIndent,
3764 TextPara_GetLineSpacing,
3765 TextPara_GetLineSpacingRule,
3766 TextPara_GetListAlignment,
3767 TextPara_SetListAlignment,
3768 TextPara_GetListLevelIndex,
3769 TextPara_SetListLevelIndex,
3770 TextPara_GetListStart,
3771 TextPara_SetListStart,
3772 TextPara_GetListTab,
3773 TextPara_SetListTab,
3774 TextPara_GetListType,
3775 TextPara_SetListType,
3776 TextPara_GetNoLineNumber,
3777 TextPara_SetNoLineNumber,
3778 TextPara_GetPageBreakBefore,
3779 TextPara_SetPageBreakBefore,
3780 TextPara_GetRightIndent,
3781 TextPara_SetRightIndent,
3782 TextPara_SetIndents,
3783 TextPara_SetLineSpacing,
3784 TextPara_GetSpaceAfter,
3785 TextPara_SetSpaceAfter,
3786 TextPara_GetSpaceBefore,
3787 TextPara_SetSpaceBefore,
3788 TextPara_GetWidowControl,
3789 TextPara_SetWidowControl,
3790 TextPara_GetTabCount,
3791 TextPara_AddTab,
3792 TextPara_ClearAllTabs,
3793 TextPara_DeleteTab,
3794 TextPara_GetTab
3797 static HRESULT create_textpara(ITextRange *range, ITextPara **ret)
3799 ITextParaImpl *para;
3801 *ret = NULL;
3802 para = heap_alloc(sizeof(*para));
3803 if (!para)
3804 return E_OUTOFMEMORY;
3806 para->ITextPara_iface.lpVtbl = &textparavtbl;
3807 para->ref = 1;
3808 para->range = range;
3809 ITextRange_AddRef(range);
3811 *ret = &para->ITextPara_iface;
3812 return S_OK;
3815 /* ITextDocument */
3816 static HRESULT WINAPI
3817 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
3818 void** ppvObject)
3820 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3821 return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
3824 static ULONG WINAPI
3825 ITextDocument_fnAddRef(ITextDocument* me)
3827 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3828 return IRichEditOle_AddRef(&This->IRichEditOle_iface);
3831 static ULONG WINAPI
3832 ITextDocument_fnRelease(ITextDocument* me)
3834 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3835 return IRichEditOle_Release(&This->IRichEditOle_iface);
3838 static HRESULT WINAPI
3839 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
3840 UINT* pctinfo)
3842 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3843 TRACE("(%p)->(%p)\n", This, pctinfo);
3844 *pctinfo = 1;
3845 return S_OK;
3848 static HRESULT WINAPI
3849 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
3850 ITypeInfo** ppTInfo)
3852 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3853 HRESULT hr;
3855 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
3857 hr = get_typeinfo(ITextDocument_tid, ppTInfo);
3858 if (SUCCEEDED(hr))
3859 ITypeInfo_AddRef(*ppTInfo);
3860 return hr;
3863 static HRESULT WINAPI
3864 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
3865 LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
3867 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3868 ITypeInfo *ti;
3869 HRESULT hr;
3871 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
3872 rgDispId);
3874 hr = get_typeinfo(ITextDocument_tid, &ti);
3875 if (SUCCEEDED(hr))
3876 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
3877 return hr;
3880 static HRESULT WINAPI
3881 ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
3882 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
3883 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
3885 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3886 ITypeInfo *ti;
3887 HRESULT hr;
3889 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
3890 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3892 hr = get_typeinfo(ITextDocument_tid, &ti);
3893 if (SUCCEEDED(hr))
3894 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3895 return hr;
3898 static HRESULT WINAPI
3899 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
3901 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3902 FIXME("stub %p\n",This);
3903 return E_NOTIMPL;
3906 static HRESULT WINAPI
3907 ITextDocument_fnGetSelection(ITextDocument *me, ITextSelection **selection)
3909 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3911 TRACE("(%p)->(%p)\n", me, selection);
3913 if (!selection)
3914 return E_INVALIDARG;
3916 if (!This->txtSel) {
3917 This->txtSel = CreateTextSelection(This);
3918 if (!This->txtSel) {
3919 *selection = NULL;
3920 return E_OUTOFMEMORY;
3924 *selection = &This->txtSel->ITextSelection_iface;
3925 ITextSelection_AddRef(*selection);
3926 return S_OK;
3929 static HRESULT WINAPI
3930 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
3932 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3933 FIXME("stub %p\n",This);
3934 return E_NOTIMPL;
3937 static HRESULT WINAPI
3938 ITextDocument_fnGetStoryRanges(ITextDocument* me,
3939 ITextStoryRanges** ppStories)
3941 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3942 FIXME("stub %p\n",This);
3943 return E_NOTIMPL;
3946 static HRESULT WINAPI
3947 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
3949 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3950 FIXME("stub %p\n",This);
3951 return E_NOTIMPL;
3954 static HRESULT WINAPI
3955 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
3957 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3958 FIXME("stub %p\n",This);
3959 return E_NOTIMPL;
3962 static HRESULT WINAPI
3963 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
3965 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3966 FIXME("stub %p\n",This);
3967 return E_NOTIMPL;
3970 static HRESULT WINAPI
3971 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
3973 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3974 FIXME("stub %p\n",This);
3975 return E_NOTIMPL;
3978 static HRESULT WINAPI
3979 ITextDocument_fnNew(ITextDocument* me)
3981 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3982 FIXME("stub %p\n",This);
3983 return E_NOTIMPL;
3986 static HRESULT WINAPI
3987 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
3988 LONG CodePage)
3990 IRichEditOleImpl *This = impl_from_ITextDocument(me);
3991 FIXME("stub %p\n",This);
3992 return E_NOTIMPL;
3995 static HRESULT WINAPI
3996 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
3997 LONG CodePage)
3999 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4000 FIXME("stub %p\n",This);
4001 return E_NOTIMPL;
4004 static HRESULT WINAPI
4005 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
4007 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4008 FIXME("stub %p\n",This);
4009 return E_NOTIMPL;
4012 static HRESULT WINAPI
4013 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
4015 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4016 FIXME("stub %p\n",This);
4017 return E_NOTIMPL;
4020 static HRESULT WINAPI
4021 ITextDocument_fnBeginEditCollection(ITextDocument* me)
4023 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4024 FIXME("stub %p\n",This);
4025 return E_NOTIMPL;
4028 static HRESULT WINAPI
4029 ITextDocument_fnEndEditCollection(ITextDocument* me)
4031 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4032 FIXME("stub %p\n",This);
4033 return E_NOTIMPL;
4036 static HRESULT WINAPI
4037 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
4039 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4040 FIXME("stub %p\n",This);
4041 return E_NOTIMPL;
4044 static HRESULT WINAPI
4045 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
4047 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4048 FIXME("stub %p\n",This);
4049 return E_NOTIMPL;
4052 static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
4054 ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
4056 if (!txtRge)
4057 return E_OUTOFMEMORY;
4058 txtRge->ITextRange_iface.lpVtbl = &trvt;
4059 txtRge->ref = 1;
4060 txtRge->child.reole = reOle;
4061 txtRge->start = start;
4062 txtRge->end = end;
4063 list_add_head(&reOle->rangelist, &txtRge->child.entry);
4064 *ppRange = &txtRge->ITextRange_iface;
4065 return S_OK;
4068 static HRESULT WINAPI
4069 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
4070 ITextRange** ppRange)
4072 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4073 const int len = ME_GetTextLength(This->editor) + 1;
4075 TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
4076 if (!ppRange)
4077 return E_INVALIDARG;
4079 cp1 = max(cp1, 0);
4080 cp2 = max(cp2, 0);
4081 cp1 = min(cp1, len);
4082 cp2 = min(cp2, len);
4083 if (cp1 > cp2)
4085 LONG tmp;
4086 tmp = cp1;
4087 cp1 = cp2;
4088 cp2 = tmp;
4090 if (cp1 == len)
4091 cp1 = cp2 = len - 1;
4093 return CreateITextRange(This, cp1, cp2, ppRange);
4096 static HRESULT WINAPI
4097 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
4098 ITextRange** ppRange)
4100 IRichEditOleImpl *This = impl_from_ITextDocument(me);
4101 FIXME("stub %p\n",This);
4102 return E_NOTIMPL;
4105 static const ITextDocumentVtbl tdvt = {
4106 ITextDocument_fnQueryInterface,
4107 ITextDocument_fnAddRef,
4108 ITextDocument_fnRelease,
4109 ITextDocument_fnGetTypeInfoCount,
4110 ITextDocument_fnGetTypeInfo,
4111 ITextDocument_fnGetIDsOfNames,
4112 ITextDocument_fnInvoke,
4113 ITextDocument_fnGetName,
4114 ITextDocument_fnGetSelection,
4115 ITextDocument_fnGetStoryCount,
4116 ITextDocument_fnGetStoryRanges,
4117 ITextDocument_fnGetSaved,
4118 ITextDocument_fnSetSaved,
4119 ITextDocument_fnGetDefaultTabStop,
4120 ITextDocument_fnSetDefaultTabStop,
4121 ITextDocument_fnNew,
4122 ITextDocument_fnOpen,
4123 ITextDocument_fnSave,
4124 ITextDocument_fnFreeze,
4125 ITextDocument_fnUnfreeze,
4126 ITextDocument_fnBeginEditCollection,
4127 ITextDocument_fnEndEditCollection,
4128 ITextDocument_fnUndo,
4129 ITextDocument_fnRedo,
4130 ITextDocument_fnRange,
4131 ITextDocument_fnRangeFromPoint
4134 /* ITextSelection */
4135 static HRESULT WINAPI ITextSelection_fnQueryInterface(
4136 ITextSelection *me,
4137 REFIID riid,
4138 void **ppvObj)
4140 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4142 *ppvObj = NULL;
4143 if (IsEqualGUID(riid, &IID_IUnknown)
4144 || IsEqualGUID(riid, &IID_IDispatch)
4145 || IsEqualGUID(riid, &IID_ITextRange)
4146 || IsEqualGUID(riid, &IID_ITextSelection))
4148 *ppvObj = me;
4149 ITextSelection_AddRef(me);
4150 return S_OK;
4152 else if (IsEqualGUID(riid, &IID_Igetrichole))
4154 *ppvObj = This->reOle;
4155 return S_OK;
4158 return E_NOINTERFACE;
4161 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
4163 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4164 return InterlockedIncrement(&This->ref);
4167 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
4169 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4170 ULONG ref = InterlockedDecrement(&This->ref);
4171 if (ref == 0)
4172 heap_free(This);
4173 return ref;
4176 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
4178 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4179 TRACE("(%p)->(%p)\n", This, pctinfo);
4180 *pctinfo = 1;
4181 return S_OK;
4184 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
4185 ITypeInfo **ppTInfo)
4187 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4188 HRESULT hr;
4190 TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
4192 hr = get_typeinfo(ITextSelection_tid, ppTInfo);
4193 if (SUCCEEDED(hr))
4194 ITypeInfo_AddRef(*ppTInfo);
4195 return hr;
4198 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
4199 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4201 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4202 ITypeInfo *ti;
4203 HRESULT hr;
4205 TRACE("(%p)->(%p,%p,%u,%d,%p)\n", This, riid, rgszNames, cNames, lcid,
4206 rgDispId);
4208 hr = get_typeinfo(ITextSelection_tid, &ti);
4209 if (SUCCEEDED(hr))
4210 hr = ITypeInfo_GetIDsOfNames(ti, rgszNames, cNames, rgDispId);
4211 return hr;
4214 static HRESULT WINAPI ITextSelection_fnInvoke(
4215 ITextSelection *me,
4216 DISPID dispIdMember,
4217 REFIID riid,
4218 LCID lcid,
4219 WORD wFlags,
4220 DISPPARAMS *pDispParams,
4221 VARIANT *pVarResult,
4222 EXCEPINFO *pExcepInfo,
4223 UINT *puArgErr)
4225 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4226 ITypeInfo *ti;
4227 HRESULT hr;
4229 TRACE("(%p)->(%d,%p,%d,%u,%p,%p,%p,%p)\n", This, dispIdMember, riid, lcid,
4230 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
4232 hr = get_typeinfo(ITextSelection_tid, &ti);
4233 if (SUCCEEDED(hr))
4234 hr = ITypeInfo_Invoke(ti, me, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
4235 return hr;
4238 /*** ITextRange methods ***/
4239 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
4241 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4242 ME_Cursor *start = NULL, *end = NULL;
4243 int nChars, endOfs;
4244 BOOL bEOP;
4246 TRACE("(%p)->(%p)\n", This, pbstr);
4248 if (!This->reOle)
4249 return CO_E_RELEASED;
4251 if (!pbstr)
4252 return E_INVALIDARG;
4254 ME_GetSelection(This->reOle->editor, &start, &end);
4255 endOfs = ME_GetCursorOfs(end);
4256 nChars = endOfs - ME_GetCursorOfs(start);
4257 if (!nChars)
4259 *pbstr = NULL;
4260 return S_OK;
4263 *pbstr = SysAllocStringLen(NULL, nChars);
4264 if (!*pbstr)
4265 return E_OUTOFMEMORY;
4267 bEOP = (end->pRun->next->type == diTextEnd && endOfs > ME_GetTextLength(This->reOle->editor));
4268 ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
4269 TRACE("%s\n", wine_dbgstr_w(*pbstr));
4271 return S_OK;
4274 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR str)
4276 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4277 ME_TextEditor *editor;
4278 int len, to, from;
4280 TRACE("(%p)->(%s)\n", This, debugstr_w(str));
4282 if (!This->reOle)
4283 return CO_E_RELEASED;
4285 editor = This->reOle->editor;
4286 len = strlenW(str);
4287 ME_GetSelectionOfs(editor, &from, &to);
4288 ME_ReplaceSel(editor, FALSE, str, len);
4290 if (len < to - from)
4291 textranges_update_ranges(This->reOle, from, len, RANGE_UPDATE_DELETE);
4293 return S_OK;
4296 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
4298 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4299 ME_Cursor *start = NULL, *end = NULL;
4301 TRACE("(%p)->(%p)\n", This, pch);
4303 if (!This->reOle)
4304 return CO_E_RELEASED;
4306 if (!pch)
4307 return E_INVALIDARG;
4309 ME_GetSelection(This->reOle->editor, &start, &end);
4310 return range_GetChar(This->reOle->editor, start, pch);
4313 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
4315 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4317 FIXME("(%p)->(%x): stub\n", This, ch);
4319 if (!This->reOle)
4320 return CO_E_RELEASED;
4322 return E_NOTIMPL;
4325 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **range)
4327 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4328 LONG start, end;
4330 TRACE("(%p)->(%p)\n", This, range);
4332 if (!This->reOle)
4333 return CO_E_RELEASED;
4335 if (!range)
4336 return E_INVALIDARG;
4338 ITextSelection_GetStart(me, &start);
4339 ITextSelection_GetEnd(me, &end);
4340 return CreateITextRange(This->reOle, start, end, range);
4343 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **range)
4345 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4347 FIXME("(%p)->(%p): stub\n", This, range);
4349 if (!This->reOle)
4350 return CO_E_RELEASED;
4352 return E_NOTIMPL;
4355 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *range)
4357 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4359 FIXME("(%p)->(%p): stub\n", This, range);
4361 if (!This->reOle)
4362 return CO_E_RELEASED;
4364 FIXME("not implemented\n");
4365 return E_NOTIMPL;
4368 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
4370 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4371 LONG lim;
4373 TRACE("(%p)->(%p)\n", This, pcpFirst);
4375 if (!This->reOle)
4376 return CO_E_RELEASED;
4378 if (!pcpFirst)
4379 return E_INVALIDARG;
4380 ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim);
4381 return S_OK;
4384 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG value)
4386 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4387 LONG start, end;
4388 HRESULT hr;
4390 TRACE("(%p)->(%d)\n", This, value);
4392 if (!This->reOle)
4393 return CO_E_RELEASED;
4395 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
4396 hr = textrange_setstart(This->reOle, value, &start, &end);
4397 if (hr == S_OK)
4398 ME_SetSelection(This->reOle->editor, start, end);
4400 return hr;
4403 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
4405 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4406 LONG first;
4408 TRACE("(%p)->(%p)\n", This, pcpLim);
4410 if (!This->reOle)
4411 return CO_E_RELEASED;
4413 if (!pcpLim)
4414 return E_INVALIDARG;
4415 ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim);
4416 return S_OK;
4419 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG value)
4421 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4422 LONG start, end;
4423 HRESULT hr;
4425 TRACE("(%p)->(%d)\n", This, value);
4427 if (!This->reOle)
4428 return CO_E_RELEASED;
4430 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
4431 hr = textrange_setend(This->reOle, value, &start, &end);
4432 if (hr == S_OK)
4433 ME_SetSelection(This->reOle->editor, start, end);
4435 return hr;
4438 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **font)
4440 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4442 TRACE("(%p)->(%p)\n", This, font);
4444 if (!This->reOle)
4445 return CO_E_RELEASED;
4447 if (!font)
4448 return E_INVALIDARG;
4450 return create_textfont((ITextRange*)me, NULL, font);
4453 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *font)
4455 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4457 TRACE("(%p)->(%p)\n", This, font);
4459 if (!font)
4460 return E_INVALIDARG;
4462 if (!This->reOle)
4463 return CO_E_RELEASED;
4465 textrange_set_font((ITextRange*)me, font);
4466 return S_OK;
4469 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **para)
4471 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4473 TRACE("(%p)->(%p)\n", This, para);
4475 if (!This->reOle)
4476 return CO_E_RELEASED;
4478 if (!para)
4479 return E_INVALIDARG;
4481 return create_textpara((ITextRange*)me, para);
4484 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *para)
4486 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4488 FIXME("(%p)->(%p): stub\n", This, para);
4490 if (!This->reOle)
4491 return CO_E_RELEASED;
4493 FIXME("not implemented\n");
4494 return E_NOTIMPL;
4497 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *length)
4499 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4501 TRACE("(%p)->(%p)\n", This, length);
4503 if (!This->reOle)
4504 return CO_E_RELEASED;
4506 return textrange_get_storylength(This->reOle->editor, length);
4509 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *value)
4511 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4513 TRACE("(%p)->(%p)\n", This, value);
4515 if (!This->reOle)
4516 return CO_E_RELEASED;
4518 if (!value)
4519 return E_INVALIDARG;
4521 *value = tomUnknownStory;
4522 return S_OK;
4525 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
4527 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4528 LONG start, end;
4529 HRESULT hres;
4531 TRACE("(%p)->(%d)\n", This, bStart);
4533 if (!This->reOle)
4534 return CO_E_RELEASED;
4536 ME_GetSelectionOfs(This->reOle->editor, &start, &end);
4537 hres = range_Collapse(bStart, &start, &end);
4538 if (SUCCEEDED(hres))
4539 ME_SetSelection(This->reOle->editor, start, end);
4540 return hres;
4543 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG unit, LONG *delta)
4545 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4547 TRACE("(%p)->(%d %p)\n", This, unit, delta);
4549 if (!This->reOle)
4550 return CO_E_RELEASED;
4552 return textrange_expand((ITextRange*)me, unit, delta);
4555 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG unit, LONG *index)
4557 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4559 FIXME("(%p)->(%d %p): stub\n", This, unit, index);
4561 if (!This->reOle)
4562 return CO_E_RELEASED;
4564 return E_NOTIMPL;
4567 static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG unit, LONG index,
4568 LONG extend)
4570 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4572 FIXME("(%p)->(%d %d %d): stub\n", This, unit, index, extend);
4574 if (!This->reOle)
4575 return CO_E_RELEASED;
4577 return E_NOTIMPL;
4580 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG anchor, LONG active)
4582 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4584 FIXME("(%p)->(%d %d): stub\n", This, anchor, active);
4586 if (!This->reOle)
4587 return CO_E_RELEASED;
4589 return E_NOTIMPL;
4592 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *range, LONG *ret)
4594 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4595 ITextSelection *selection = NULL;
4596 LONG start, end;
4598 TRACE("(%p)->(%p %p)\n", This, range, ret);
4600 if (ret)
4601 *ret = tomFalse;
4603 if (!This->reOle)
4604 return CO_E_RELEASED;
4606 if (!range)
4607 return S_FALSE;
4609 ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&selection);
4610 if (!selection)
4611 return S_FALSE;
4612 ITextSelection_Release(selection);
4614 ITextSelection_GetStart(me, &start);
4615 ITextSelection_GetEnd(me, &end);
4616 return textrange_inrange(start, end, range, ret);
4619 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *range, LONG *ret)
4621 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4623 FIXME("(%p)->(%p %p): stub\n", This, range, ret);
4625 if (!This->reOle)
4626 return CO_E_RELEASED;
4628 return E_NOTIMPL;
4631 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *range, LONG *ret)
4633 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4634 ITextSelection *selection = NULL;
4635 LONG start, end;
4637 TRACE("(%p)->(%p %p)\n", This, range, ret);
4639 if (ret)
4640 *ret = tomFalse;
4642 if (!This->reOle)
4643 return CO_E_RELEASED;
4645 if (!range)
4646 return S_FALSE;
4648 ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&selection);
4649 if (!selection)
4650 return S_FALSE;
4651 ITextSelection_Release(selection);
4653 ITextSelection_GetStart(me, &start);
4654 ITextSelection_GetEnd(me, &end);
4655 return textrange_isequal(start, end, range, ret);
4658 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
4660 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4662 TRACE("(%p)\n", This);
4664 if (!This->reOle)
4665 return CO_E_RELEASED;
4667 /* nothing to do */
4668 return S_OK;
4671 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG unit, LONG extend,
4672 LONG *delta)
4674 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4676 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
4678 if (!This->reOle)
4679 return CO_E_RELEASED;
4681 return E_NOTIMPL;
4684 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG unit, LONG extend,
4685 LONG *delta)
4687 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4689 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
4691 if (!This->reOle)
4692 return CO_E_RELEASED;
4694 return E_NOTIMPL;
4697 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG unit, LONG count, LONG *delta)
4699 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4701 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
4703 if (!This->reOle)
4704 return CO_E_RELEASED;
4706 return E_NOTIMPL;
4709 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG unit, LONG count,
4710 LONG *delta)
4712 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4714 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
4716 if (!This->reOle)
4717 return CO_E_RELEASED;
4719 return E_NOTIMPL;
4722 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG unit, LONG count,
4723 LONG *delta)
4725 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4727 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
4729 if (!This->reOle)
4730 return CO_E_RELEASED;
4732 return E_NOTIMPL;
4735 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *charset, LONG count,
4736 LONG *delta)
4738 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4740 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
4742 if (!This->reOle)
4743 return CO_E_RELEASED;
4745 return E_NOTIMPL;
4748 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *charset, LONG count,
4749 LONG *delta)
4751 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4753 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
4755 if (!This->reOle)
4756 return CO_E_RELEASED;
4758 return E_NOTIMPL;
4761 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *charset, LONG count,
4762 LONG *delta)
4764 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4766 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
4768 if (!This->reOle)
4769 return CO_E_RELEASED;
4771 return E_NOTIMPL;
4774 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *charset, LONG count,
4775 LONG *delta)
4777 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4779 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
4781 if (!This->reOle)
4782 return CO_E_RELEASED;
4784 return E_NOTIMPL;
4787 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *charset, LONG count,
4788 LONG *delta)
4790 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4792 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
4794 if (!This->reOle)
4795 return CO_E_RELEASED;
4797 return E_NOTIMPL;
4800 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *charset, LONG count,
4801 LONG *delta)
4803 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4805 FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
4807 if (!This->reOle)
4808 return CO_E_RELEASED;
4810 return E_NOTIMPL;
4813 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR text, LONG count, LONG flags,
4814 LONG *length)
4816 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4818 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
4820 if (!This->reOle)
4821 return CO_E_RELEASED;
4823 FIXME("not implemented\n");
4824 return E_NOTIMPL;
4827 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR text, LONG count,
4828 LONG flags, LONG *length)
4830 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4832 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
4834 if (!This->reOle)
4835 return CO_E_RELEASED;
4837 return E_NOTIMPL;
4840 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR text, LONG count,
4841 LONG flags, LONG *length)
4843 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4845 FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
4847 if (!This->reOle)
4848 return CO_E_RELEASED;
4850 return E_NOTIMPL;
4853 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG unit, LONG count,
4854 LONG *delta)
4856 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4858 FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
4860 if (!This->reOle)
4861 return CO_E_RELEASED;
4863 return E_NOTIMPL;
4866 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *v)
4868 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4870 FIXME("(%p)->(%p): stub\n", This, v);
4872 if (!This->reOle)
4873 return CO_E_RELEASED;
4875 return E_NOTIMPL;
4878 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *v)
4880 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4882 FIXME("(%p)->(%p): stub\n", This, v);
4884 if (!This->reOle)
4885 return CO_E_RELEASED;
4887 return E_NOTIMPL;
4890 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *v, LONG format)
4892 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4894 FIXME("(%p)->(%s %x): stub\n", This, debugstr_variant(v), format);
4896 if (!This->reOle)
4897 return CO_E_RELEASED;
4899 return E_NOTIMPL;
4902 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *v, LONG format,
4903 LONG *ret)
4905 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4907 FIXME("(%p)->(%s %x %p): stub\n", This, debugstr_variant(v), format, ret);
4909 if (!This->reOle)
4910 return CO_E_RELEASED;
4912 return E_NOTIMPL;
4915 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *ret)
4917 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4919 FIXME("(%p)->(%p): stub\n", This, ret);
4921 if (!This->reOle)
4922 return CO_E_RELEASED;
4924 return E_NOTIMPL;
4927 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG type)
4929 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4931 FIXME("(%p)->(%d): stub\n", This, type);
4933 if (!This->reOle)
4934 return CO_E_RELEASED;
4936 return E_NOTIMPL;
4939 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG type, LONG *cx, LONG *cy)
4941 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4943 FIXME("(%p)->(%d %p %p): stub\n", This, type, cx, cy);
4945 if (!This->reOle)
4946 return CO_E_RELEASED;
4948 return E_NOTIMPL;
4951 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG type,
4952 LONG extend)
4954 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4956 FIXME("(%p)->(%d %d %d %d): stub\n", This, x, y, type, extend);
4958 if (!This->reOle)
4959 return CO_E_RELEASED;
4961 return E_NOTIMPL;
4964 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG value)
4966 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4968 FIXME("(%p)->(%d): stub\n", This, value);
4970 if (!This->reOle)
4971 return CO_E_RELEASED;
4973 return E_NOTIMPL;
4976 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
4978 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4980 FIXME("(%p)->(%p): stub\n", This, ppv);
4982 if (!This->reOle)
4983 return CO_E_RELEASED;
4985 return E_NOTIMPL;
4988 /*** ITextSelection methods ***/
4989 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *flags)
4991 ITextSelectionImpl *This = impl_from_ITextSelection(me);
4993 FIXME("(%p)->(%p): stub\n", This, flags);
4995 if (!This->reOle)
4996 return CO_E_RELEASED;
4998 return E_NOTIMPL;
5001 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG flags)
5003 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5005 FIXME("(%p)->(%x): stub\n", This, flags);
5007 if (!This->reOle)
5008 return CO_E_RELEASED;
5010 return E_NOTIMPL;
5013 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *type)
5015 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5017 FIXME("(%p)->(%p): stub\n", This, type);
5019 if (!This->reOle)
5020 return CO_E_RELEASED;
5022 return E_NOTIMPL;
5025 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG unit, LONG count,
5026 LONG extend, LONG *delta)
5028 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5030 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5032 if (!This->reOle)
5033 return CO_E_RELEASED;
5035 return E_NOTIMPL;
5038 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG unit, LONG count,
5039 LONG extend, LONG *delta)
5041 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5043 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5045 if (!This->reOle)
5046 return CO_E_RELEASED;
5048 return E_NOTIMPL;
5051 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG unit, LONG count,
5052 LONG extend, LONG *delta)
5054 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5056 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5058 if (!This->reOle)
5059 return CO_E_RELEASED;
5061 return E_NOTIMPL;
5064 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG unit, LONG count,
5065 LONG extend, LONG *delta)
5067 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5069 FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
5071 if (!This->reOle)
5072 return CO_E_RELEASED;
5074 return E_NOTIMPL;
5077 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG unit, LONG extend,
5078 LONG *delta)
5080 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5082 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
5084 if (!This->reOle)
5085 return CO_E_RELEASED;
5087 return E_NOTIMPL;
5090 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG unit, LONG extend,
5091 LONG *delta)
5093 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5095 FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
5097 if (!This->reOle)
5098 return CO_E_RELEASED;
5100 return E_NOTIMPL;
5103 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR text)
5105 ITextSelectionImpl *This = impl_from_ITextSelection(me);
5107 FIXME("(%p)->(%s): stub\n", This, debugstr_w(text));
5109 if (!This->reOle)
5110 return CO_E_RELEASED;
5112 return E_NOTIMPL;
5115 static const ITextSelectionVtbl tsvt = {
5116 ITextSelection_fnQueryInterface,
5117 ITextSelection_fnAddRef,
5118 ITextSelection_fnRelease,
5119 ITextSelection_fnGetTypeInfoCount,
5120 ITextSelection_fnGetTypeInfo,
5121 ITextSelection_fnGetIDsOfNames,
5122 ITextSelection_fnInvoke,
5123 ITextSelection_fnGetText,
5124 ITextSelection_fnSetText,
5125 ITextSelection_fnGetChar,
5126 ITextSelection_fnSetChar,
5127 ITextSelection_fnGetDuplicate,
5128 ITextSelection_fnGetFormattedText,
5129 ITextSelection_fnSetFormattedText,
5130 ITextSelection_fnGetStart,
5131 ITextSelection_fnSetStart,
5132 ITextSelection_fnGetEnd,
5133 ITextSelection_fnSetEnd,
5134 ITextSelection_fnGetFont,
5135 ITextSelection_fnSetFont,
5136 ITextSelection_fnGetPara,
5137 ITextSelection_fnSetPara,
5138 ITextSelection_fnGetStoryLength,
5139 ITextSelection_fnGetStoryType,
5140 ITextSelection_fnCollapse,
5141 ITextSelection_fnExpand,
5142 ITextSelection_fnGetIndex,
5143 ITextSelection_fnSetIndex,
5144 ITextSelection_fnSetRange,
5145 ITextSelection_fnInRange,
5146 ITextSelection_fnInStory,
5147 ITextSelection_fnIsEqual,
5148 ITextSelection_fnSelect,
5149 ITextSelection_fnStartOf,
5150 ITextSelection_fnEndOf,
5151 ITextSelection_fnMove,
5152 ITextSelection_fnMoveStart,
5153 ITextSelection_fnMoveEnd,
5154 ITextSelection_fnMoveWhile,
5155 ITextSelection_fnMoveStartWhile,
5156 ITextSelection_fnMoveEndWhile,
5157 ITextSelection_fnMoveUntil,
5158 ITextSelection_fnMoveStartUntil,
5159 ITextSelection_fnMoveEndUntil,
5160 ITextSelection_fnFindText,
5161 ITextSelection_fnFindTextStart,
5162 ITextSelection_fnFindTextEnd,
5163 ITextSelection_fnDelete,
5164 ITextSelection_fnCut,
5165 ITextSelection_fnCopy,
5166 ITextSelection_fnPaste,
5167 ITextSelection_fnCanPaste,
5168 ITextSelection_fnCanEdit,
5169 ITextSelection_fnChangeCase,
5170 ITextSelection_fnGetPoint,
5171 ITextSelection_fnSetPoint,
5172 ITextSelection_fnScrollIntoView,
5173 ITextSelection_fnGetEmbeddedObject,
5174 ITextSelection_fnGetFlags,
5175 ITextSelection_fnSetFlags,
5176 ITextSelection_fnGetType,
5177 ITextSelection_fnMoveLeft,
5178 ITextSelection_fnMoveRight,
5179 ITextSelection_fnMoveUp,
5180 ITextSelection_fnMoveDown,
5181 ITextSelection_fnHomeKey,
5182 ITextSelection_fnEndKey,
5183 ITextSelection_fnTypeText
5186 static ITextSelectionImpl *
5187 CreateTextSelection(IRichEditOleImpl *reOle)
5189 ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
5190 if (!txtSel)
5191 return NULL;
5193 txtSel->ITextSelection_iface.lpVtbl = &tsvt;
5194 txtSel->ref = 1;
5195 txtSel->reOle = reOle;
5196 return txtSel;
5199 LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *ppvObj)
5201 IRichEditOleImpl *reo;
5203 reo = heap_alloc(sizeof(IRichEditOleImpl));
5204 if (!reo)
5205 return 0;
5207 reo->IUnknown_inner.lpVtbl = &reo_unk_vtbl;
5208 reo->IRichEditOle_iface.lpVtbl = &revt;
5209 reo->ITextDocument_iface.lpVtbl = &tdvt;
5210 reo->ref = 1;
5211 reo->editor = editor;
5212 reo->txtSel = NULL;
5214 TRACE("Created %p\n",reo);
5215 list_init(&reo->rangelist);
5216 list_init(&reo->clientsites);
5217 if (outer_unk)
5218 reo->outer_unk = outer_unk;
5219 else
5220 reo->outer_unk = &reo->IUnknown_inner;
5221 *ppvObj = &reo->IRichEditOle_iface;
5223 return 1;
5226 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
5228 /* sizel is in .01 millimeters, sz in pixels */
5229 sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
5230 sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
5233 /******************************************************************************
5234 * ME_GetOLEObjectSize
5236 * Sets run extent for OLE objects.
5238 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
5240 IDataObject* ido;
5241 FORMATETC fmt;
5242 STGMEDIUM stgm;
5243 DIBSECTION dibsect;
5244 ENHMETAHEADER emh;
5246 assert(run->nFlags & MERF_GRAPHICS);
5247 assert(run->ole_obj);
5249 if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
5251 convert_sizel(c, &run->ole_obj->sizel, pSize);
5252 if (c->editor->nZoomNumerator != 0)
5254 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5255 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5257 return;
5260 if (!run->ole_obj->poleobj)
5262 pSize->cx = pSize->cy = 0;
5263 return;
5266 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
5268 FIXME("Query Interface IID_IDataObject failed!\n");
5269 pSize->cx = pSize->cy = 0;
5270 return;
5272 fmt.cfFormat = CF_BITMAP;
5273 fmt.ptd = NULL;
5274 fmt.dwAspect = DVASPECT_CONTENT;
5275 fmt.lindex = -1;
5276 fmt.tymed = TYMED_GDI;
5277 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5279 fmt.cfFormat = CF_ENHMETAFILE;
5280 fmt.tymed = TYMED_ENHMF;
5281 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5283 FIXME("unsupported format\n");
5284 pSize->cx = pSize->cy = 0;
5285 IDataObject_Release(ido);
5286 return;
5290 switch (stgm.tymed)
5292 case TYMED_GDI:
5293 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
5294 pSize->cx = dibsect.dsBm.bmWidth;
5295 pSize->cy = dibsect.dsBm.bmHeight;
5296 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
5297 break;
5298 case TYMED_ENHMF:
5299 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
5300 pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
5301 pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
5302 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
5303 break;
5304 default:
5305 FIXME("Unsupported tymed %d\n", stgm.tymed);
5306 break;
5308 IDataObject_Release(ido);
5309 if (c->editor->nZoomNumerator != 0)
5311 pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5312 pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5316 void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
5317 ME_Paragraph *para, BOOL selected)
5319 IDataObject* ido;
5320 FORMATETC fmt;
5321 STGMEDIUM stgm;
5322 DIBSECTION dibsect;
5323 ENHMETAHEADER emh;
5324 HDC hMemDC;
5325 SIZE sz;
5326 BOOL has_size;
5328 assert(run->nFlags & MERF_GRAPHICS);
5329 assert(run->ole_obj);
5330 if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
5332 FIXME("Couldn't get interface\n");
5333 return;
5335 has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
5336 fmt.cfFormat = CF_BITMAP;
5337 fmt.ptd = NULL;
5338 fmt.dwAspect = DVASPECT_CONTENT;
5339 fmt.lindex = -1;
5340 fmt.tymed = TYMED_GDI;
5341 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5343 fmt.cfFormat = CF_ENHMETAFILE;
5344 fmt.tymed = TYMED_ENHMF;
5345 if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
5347 FIXME("Couldn't get storage medium\n");
5348 IDataObject_Release(ido);
5349 return;
5352 switch (stgm.tymed)
5354 case TYMED_GDI:
5355 GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
5356 hMemDC = CreateCompatibleDC(c->hDC);
5357 SelectObject(hMemDC, stgm.u.hBitmap);
5358 if (has_size)
5360 convert_sizel(c, &run->ole_obj->sizel, &sz);
5361 } else {
5362 sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
5363 sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
5365 if (c->editor->nZoomNumerator != 0)
5367 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5368 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5370 if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
5372 BitBlt(c->hDC, x, y - sz.cy,
5373 dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
5374 hMemDC, 0, 0, SRCCOPY);
5375 } else {
5376 StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
5377 hMemDC, 0, 0, dibsect.dsBm.bmWidth,
5378 dibsect.dsBm.bmHeight, SRCCOPY);
5380 DeleteDC(hMemDC);
5381 if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
5382 break;
5383 case TYMED_ENHMF:
5384 GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
5385 if (has_size)
5387 convert_sizel(c, &run->ole_obj->sizel, &sz);
5388 } else {
5389 sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
5390 sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
5392 if (c->editor->nZoomNumerator != 0)
5394 sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5395 sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
5399 RECT rc;
5401 rc.left = x;
5402 rc.top = y - sz.cy;
5403 rc.right = x + sz.cx;
5404 rc.bottom = y;
5405 PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
5407 if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
5408 break;
5409 default:
5410 FIXME("Unsupported tymed %d\n", stgm.tymed);
5411 selected = FALSE;
5412 break;
5414 if (selected && !c->editor->bHideSelection)
5415 PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
5416 IDataObject_Release(ido);
5419 void ME_DeleteReObject(REOBJECT* reo)
5421 if (reo->poleobj) IOleObject_Release(reo->poleobj);
5422 if (reo->pstg) IStorage_Release(reo->pstg);
5423 if (reo->polesite) IOleClientSite_Release(reo->polesite);
5424 FREE_OBJ(reo);
5427 void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
5429 *dst = *src;
5431 if (dst->poleobj) IOleObject_AddRef(dst->poleobj);
5432 if (dst->pstg) IStorage_AddRef(dst->pstg);
5433 if (dst->polesite) IOleClientSite_AddRef(dst->polesite);
5436 void ME_GetITextDocumentInterface(IRichEditOle *iface, LPVOID *ppvObj)
5438 IRichEditOleImpl *This = impl_from_IRichEditOle(iface);
5439 *ppvObj = &This->ITextDocument_iface;