2 * Copyright 2006-2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 static const WCHAR brW[] = {'b','r',0};
36 static const WCHAR hrW[] = {'h','r',0};
39 IHTMLTxtRange IHTMLTxtRange_iface;
40 IOleCommandTarget IOleCommandTarget_iface;
45 HTMLDocumentNode *doc;
72 static HTMLTxtRange *get_range_object(HTMLDocumentNode *doc, IHTMLTxtRange *iface)
76 LIST_FOR_EACH_ENTRY(iter, &doc->range_list, HTMLTxtRange, entry) {
77 if(&iter->IHTMLTxtRange_iface == iface)
81 ERR("Could not find range in document\n");
85 static range_unit_t string_to_unit(LPCWSTR str)
87 static const WCHAR characterW[] =
88 {'c','h','a','r','a','c','t','e','r',0};
89 static const WCHAR wordW[] =
91 static const WCHAR sentenceW[] =
92 {'s','e','n','t','e','n','c','e',0};
93 static const WCHAR texteditW[] =
94 {'t','e','x','t','e','d','i','t',0};
96 if(!strcmpiW(str, characterW)) return RU_CHAR;
97 if(!strcmpiW(str, wordW)) return RU_WORD;
98 if(!strcmpiW(str, sentenceW)) return RU_SENTENCE;
99 if(!strcmpiW(str, texteditW)) return RU_TEXTEDIT;
104 static int string_to_nscmptype(LPCWSTR str)
106 static const WCHAR seW[] = {'S','t','a','r','t','T','o','E','n','d',0};
107 static const WCHAR ssW[] = {'S','t','a','r','t','T','o','S','t','a','r','t',0};
108 static const WCHAR esW[] = {'E','n','d','T','o','S','t','a','r','t',0};
109 static const WCHAR eeW[] = {'E','n','d','T','o','E','n','d',0};
111 if(!strcmpiW(str, seW)) return NS_START_TO_END;
112 if(!strcmpiW(str, ssW)) return NS_START_TO_START;
113 if(!strcmpiW(str, esW)) return NS_END_TO_START;
114 if(!strcmpiW(str, eeW)) return NS_END_TO_END;
119 static PRUint16 get_node_type(nsIDOMNode *node)
124 nsIDOMNode_GetNodeType(node, &type);
129 static BOOL is_elem_tag(nsIDOMNode *node, LPCWSTR istag)
133 const PRUnichar *tag;
137 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMElement, (void**)&elem);
141 nsAString_Init(&tag_str, NULL);
142 nsIDOMElement_GetTagName(elem, &tag_str);
143 nsIDOMElement_Release(elem);
144 nsAString_GetData(&tag_str, &tag);
146 ret = !strcmpiW(tag, istag);
148 nsAString_Finish(&tag_str);
153 static BOOL is_space_elem(nsIDOMNode *node)
157 const PRUnichar *tag;
161 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMElement, (void**)&elem);
165 nsAString_Init(&tag_str, NULL);
166 nsIDOMElement_GetTagName(elem, &tag_str);
167 nsIDOMElement_Release(elem);
168 nsAString_GetData(&tag_str, &tag);
170 ret = !strcmpiW(tag, brW) || !strcmpiW(tag, hrW);
172 nsAString_Finish(&tag_str);
177 static inline BOOL wstrbuf_init(wstrbuf_t *buf)
181 buf->buf = heap_alloc(buf->size * sizeof(WCHAR));
182 if (!buf->buf) return FALSE;
187 static inline void wstrbuf_finish(wstrbuf_t *buf)
192 static void wstrbuf_append_len(wstrbuf_t *buf, LPCWSTR str, int len)
194 if(buf->len+len >= buf->size) {
195 buf->size = 2*buf->size+len;
196 buf->buf = heap_realloc(buf->buf, buf->size * sizeof(WCHAR));
199 memcpy(buf->buf+buf->len, str, len*sizeof(WCHAR));
201 buf->buf[buf->len] = 0;
204 static void wstrbuf_append_nodetxt(wstrbuf_t *buf, LPCWSTR str, int len)
206 const WCHAR *s = str;
209 TRACE("%s\n", debugstr_wn(str, len));
211 if(buf->len+len >= buf->size) {
212 buf->size = 2*buf->size+len;
213 buf->buf = heap_realloc(buf->buf, buf->size * sizeof(WCHAR));
216 if(buf->len && isspaceW(buf->buf[buf->len-1])) {
217 while(s < str+len && isspaceW(*s))
221 d = buf->buf+buf->len;
226 while(s < str+len && isspaceW(*s))
233 buf->len = d - buf->buf;
237 static void wstrbuf_append_node(wstrbuf_t *buf, nsIDOMNode *node)
240 switch(get_node_type(node)) {
244 const PRUnichar *data;
246 nsIDOMNode_QueryInterface(node, &IID_nsIDOMText, (void**)&nstext);
248 nsAString_Init(&data_str, NULL);
249 nsIDOMText_GetData(nstext, &data_str);
250 nsAString_GetData(&data_str, &data);
251 wstrbuf_append_nodetxt(buf, data, strlenW(data));
252 nsAString_Finish(&data_str);
254 nsIDOMText_Release(nstext);
259 if(is_elem_tag(node, brW)) {
260 static const WCHAR endlW[] = {'\r','\n'};
261 wstrbuf_append_len(buf, endlW, 2);
262 }else if(is_elem_tag(node, hrW)) {
263 static const WCHAR endl2W[] = {'\r','\n','\r','\n'};
264 wstrbuf_append_len(buf, endl2W, 4);
269 static void wstrbuf_append_node_rec(wstrbuf_t *buf, nsIDOMNode *node)
271 nsIDOMNode *iter, *tmp;
273 wstrbuf_append_node(buf, node);
275 nsIDOMNode_GetFirstChild(node, &iter);
277 wstrbuf_append_node_rec(buf, iter);
278 nsIDOMNode_GetNextSibling(iter, &tmp);
279 nsIDOMNode_Release(iter);
284 static BOOL fill_nodestr(dompos_t *pos)
289 if(pos->type != TEXT_NODE)
292 nsres = nsIDOMNode_QueryInterface(pos->node, &IID_nsIDOMText, (void**)&text);
296 nsAString_Init(&pos->str, NULL);
297 nsIDOMText_GetData(text, &pos->str);
298 nsIDOMText_Release(text);
299 nsAString_GetData(&pos->str, &pos->p);
302 pos->off = *pos->p ? strlenW(pos->p)-1 : 0;
307 static nsIDOMNode *next_node(nsIDOMNode *iter)
309 nsIDOMNode *ret, *tmp;
315 nsres = nsIDOMNode_GetFirstChild(iter, &ret);
316 if(NS_SUCCEEDED(nsres) && ret)
319 nsIDOMNode_AddRef(iter);
322 nsres = nsIDOMNode_GetNextSibling(iter, &ret);
323 if(NS_SUCCEEDED(nsres) && ret) {
324 nsIDOMNode_Release(iter);
328 nsres = nsIDOMNode_GetParentNode(iter, &tmp);
329 nsIDOMNode_Release(iter);
331 }while(NS_SUCCEEDED(nsres) && iter);
336 static nsIDOMNode *prev_node(HTMLTxtRange *This, nsIDOMNode *iter)
338 nsIDOMNode *ret, *tmp;
342 nsIDOMHTMLElement *nselem;
344 nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nselem);
345 nsIDOMElement_GetLastChild(nselem, &tmp);
347 return (nsIDOMNode*)nselem;
351 nsIDOMNode_GetLastChild(ret, &tmp);
354 nsIDOMElement_Release(nselem);
359 nsres = nsIDOMNode_GetLastChild(iter, &ret);
360 if(NS_SUCCEEDED(nsres) && ret)
363 nsIDOMNode_AddRef(iter);
366 nsres = nsIDOMNode_GetPreviousSibling(iter, &ret);
367 if(NS_SUCCEEDED(nsres) && ret) {
368 nsIDOMNode_Release(iter);
372 nsres = nsIDOMNode_GetParentNode(iter, &tmp);
373 nsIDOMNode_Release(iter);
375 }while(NS_SUCCEEDED(nsres) && iter);
380 static nsIDOMNode *get_child_node(nsIDOMNode *node, PRUint32 off)
382 nsIDOMNodeList *node_list;
383 nsIDOMNode *ret = NULL;
385 nsIDOMNode_GetChildNodes(node, &node_list);
386 nsIDOMNodeList_Item(node_list, off, &ret);
387 nsIDOMNodeList_Release(node_list);
392 static void get_cur_pos(HTMLTxtRange *This, BOOL start, dompos_t *pos)
401 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
406 nsIDOMRange_GetStartContainer(This->nsrange, &node);
407 nsIDOMRange_GetStartOffset(This->nsrange, &off);
409 nsIDOMRange_GetEndContainer(This->nsrange, &node);
410 nsIDOMRange_GetEndOffset(This->nsrange, &off);
413 pos->type = get_node_type(node);
414 if(pos->type == ELEMENT_NODE) {
416 pos->node = get_child_node(node, off);
419 pos->node = off ? get_child_node(node, off-1) : prev_node(This, node);
423 pos->type = get_node_type(pos->node);
424 nsIDOMNode_Release(node);
432 pos->node = prev_node(This, node);
434 nsIDOMNode_Release(node);
437 if(pos->type == TEXT_NODE)
441 static void set_range_pos(HTMLTxtRange *This, BOOL start, dompos_t *pos)
446 if(pos->type == TEXT_NODE)
447 nsres = nsIDOMRange_SetStart(This->nsrange, pos->node, pos->off);
449 nsres = nsIDOMRange_SetStartBefore(This->nsrange, pos->node);
451 if(pos->type == TEXT_NODE && pos->p[pos->off+1])
452 nsres = nsIDOMRange_SetEnd(This->nsrange, pos->node, pos->off+1);
454 nsres = nsIDOMRange_SetEndAfter(This->nsrange, pos->node);
458 ERR("failed: %p %08x\n", pos->node, nsres);
461 static inline void dompos_release(dompos_t *pos)
464 nsIDOMNode_Release(pos->node);
467 nsAString_Finish(&pos->str);
470 static inline void dompos_addref(dompos_t *pos)
473 nsIDOMNode_AddRef(pos->node);
475 if(pos->type == TEXT_NODE)
479 static inline BOOL dompos_cmp(const dompos_t *pos1, const dompos_t *pos2)
481 return pos1->node == pos2->node && pos1->off == pos2->off;
484 static void range_to_string(HTMLTxtRange *This, wstrbuf_t *buf)
486 nsIDOMNode *iter, *tmp;
487 dompos_t start_pos, end_pos;
490 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
498 get_cur_pos(This, FALSE, &end_pos);
499 get_cur_pos(This, TRUE, &start_pos);
501 if(start_pos.type == TEXT_NODE) {
502 if(start_pos.node == end_pos.node) {
503 wstrbuf_append_nodetxt(buf, start_pos.p+start_pos.off, end_pos.off-start_pos.off+1);
504 iter = start_pos.node;
505 nsIDOMNode_AddRef(iter);
507 wstrbuf_append_nodetxt(buf, start_pos.p+start_pos.off, strlenW(start_pos.p+start_pos.off));
508 iter = next_node(start_pos.node);
511 iter = start_pos.node;
512 nsIDOMNode_AddRef(iter);
515 while(iter != end_pos.node) {
516 wstrbuf_append_node(buf, iter);
517 tmp = next_node(iter);
518 nsIDOMNode_Release(iter);
522 nsIDOMNode_AddRef(end_pos.node);
524 if(start_pos.node != end_pos.node) {
525 if(end_pos.type == TEXT_NODE)
526 wstrbuf_append_nodetxt(buf, end_pos.p, end_pos.off+1);
528 wstrbuf_append_node(buf, end_pos.node);
531 nsIDOMNode_Release(iter);
532 dompos_release(&start_pos);
533 dompos_release(&end_pos);
538 for(p = buf->buf+buf->len-1; p >= buf->buf && isspaceW(*p); p--);
540 p = strchrW(p, '\r');
546 HRESULT get_node_text(HTMLDOMNode *node, BSTR *ret)
551 if (!wstrbuf_init(&buf))
552 return E_OUTOFMEMORY;
553 wstrbuf_append_node_rec(&buf, node->nsnode);
555 *ret = SysAllocString(buf.buf);
557 hres = E_OUTOFMEMORY;
561 wstrbuf_finish(&buf);
564 TRACE("ret %s\n", debugstr_w(*ret));
568 static WCHAR get_pos_char(const dompos_t *pos)
572 return pos->p[pos->off];
574 if(is_space_elem(pos->node))
581 static void end_space(const dompos_t *pos, dompos_t *new_pos)
586 dompos_addref(new_pos);
588 if(pos->type != TEXT_NODE)
591 p = new_pos->p+new_pos->off;
593 if(!*p || !isspace(*p))
596 while(p[1] && isspace(p[1]))
599 new_pos->off = p - new_pos->p;
602 static WCHAR next_char(const dompos_t *pos, dompos_t *new_pos)
604 nsIDOMNode *iter, *tmp;
605 dompos_t last_space, tmp_pos;
609 if(pos->type == TEXT_NODE && pos->off != -1 && pos->p[pos->off]) {
613 while(isspaceW(*++p));
617 if(*p && isspaceW(*p)) {
619 while(p[1] && isspaceW(p[1]))
625 new_pos->off = p - pos->p;
626 dompos_addref(new_pos);
628 return cspace ? cspace : *p;
631 last_space.off = p - pos->p;
632 dompos_addref(&last_space);
636 iter = next_node(pos->node);
639 switch(get_node_type(iter)) {
642 tmp_pos.type = TEXT_NODE;
644 dompos_addref(&tmp_pos);
649 dompos_release(&tmp_pos);
651 }else if(isspaceW(*p)) {
653 dompos_release(&last_space);
657 while(p[1] && isspaceW(p[1]))
660 tmp_pos.off = p-tmp_pos.p;
663 last_space = tmp_pos;
668 nsIDOMNode_Release(iter);
671 *new_pos = last_space;
672 dompos_release(&tmp_pos);
673 nsIDOMNode_Release(iter);
681 nsIDOMNode_Release(iter);
685 if(is_elem_tag(iter, brW)) {
687 dompos_release(&last_space);
690 nsIDOMNode_AddRef(iter);
691 last_space.node = iter;
692 last_space.type = ELEMENT_NODE;
695 }else if(is_elem_tag(iter, hrW)) {
697 *new_pos = last_space;
698 nsIDOMNode_Release(iter);
702 new_pos->node = iter;
703 new_pos->type = ELEMENT_NODE;
711 iter = next_node(iter);
712 nsIDOMNode_Release(tmp);
716 *new_pos = last_space;
719 dompos_addref(new_pos);
725 static WCHAR prev_char(HTMLTxtRange *This, const dompos_t *pos, dompos_t *new_pos)
727 nsIDOMNode *iter, *tmp;
729 BOOL skip_space = FALSE;
731 if(pos->type == TEXT_NODE && isspaceW(pos->p[pos->off]))
734 if(pos->type == TEXT_NODE && pos->off) {
735 p = pos->p+pos->off-1;
738 while(p >= pos->p && isspace(*p))
744 new_pos->off = p-pos->p;
745 dompos_addref(new_pos);
746 return new_pos->p[new_pos->off];
750 iter = prev_node(This, pos->node);
753 switch(get_node_type(iter)) {
758 tmp_pos.type = TEXT_NODE;
760 dompos_addref(&tmp_pos);
762 p = tmp_pos.p + strlenW(tmp_pos.p)-1;
765 while(p >= tmp_pos.p && isspaceW(*p))
770 dompos_release(&tmp_pos);
774 tmp_pos.off = p-tmp_pos.p;
776 nsIDOMNode_Release(iter);
781 if(is_elem_tag(iter, brW)) {
786 }else if(!is_elem_tag(iter, hrW)) {
790 new_pos->node = iter;
791 new_pos->type = ELEMENT_NODE;
798 iter = prev_node(This, iter);
799 nsIDOMNode_Release(tmp);
803 dompos_addref(new_pos);
807 static LONG move_next_chars(LONG cnt, const dompos_t *pos, BOOL col, const dompos_t *bound_pos,
808 BOOL *bounded, dompos_t *new_pos)
821 end_space(pos, new_pos);
825 c = next_char(pos, &iter);
830 c = next_char(&tmp, &iter);
831 dompos_release(&tmp);
836 if(bound_pos && dompos_cmp(&tmp, bound_pos)) {
846 static LONG move_prev_chars(HTMLTxtRange *This, LONG cnt, const dompos_t *pos, BOOL end,
847 const dompos_t *bound_pos, BOOL *bounded, dompos_t *new_pos)
851 BOOL prev_eq = FALSE;
857 c = prev_char(This, pos, &iter);
861 while(c && ret < cnt) {
863 c = prev_char(This, &tmp, &iter);
864 dompos_release(&tmp);
878 prev_eq = bound_pos && dompos_cmp(&iter, bound_pos);
885 static LONG find_prev_space(HTMLTxtRange *This, const dompos_t *pos, BOOL first_space, dompos_t *ret)
890 c = prev_char(This, pos, &iter);
891 if(!c || (first_space && isspaceW(c))) {
898 c = prev_char(This, &tmp, &iter);
899 if(!c || isspaceW(c)) {
900 dompos_release(&iter);
903 dompos_release(&tmp);
910 static int find_word_end(const dompos_t *pos, dompos_t *ret)
915 c = get_pos_char(pos);
922 c = next_char(pos, &iter);
933 while(c && !isspaceW(c)) {
935 c = next_char(&tmp, &iter);
937 dompos_release(&iter);
941 dompos_release(&tmp);
949 static LONG move_next_words(LONG cnt, const dompos_t *pos, dompos_t *new_pos)
955 c = get_pos_char(pos);
957 end_space(pos, &iter);
960 c = next_char(pos, &iter);
965 while(c && ret < cnt) {
967 c = next_char(&tmp, &iter);
968 dompos_release(&tmp);
977 static LONG move_prev_words(HTMLTxtRange *This, LONG cnt, const dompos_t *pos, dompos_t *new_pos)
983 dompos_addref(&iter);
986 if(!find_prev_space(This, &iter, FALSE, &tmp))
989 dompos_release(&iter);
998 static inline HTMLTxtRange *impl_from_IHTMLTxtRange(IHTMLTxtRange *iface)
1000 return CONTAINING_RECORD(iface, HTMLTxtRange, IHTMLTxtRange_iface);
1003 static HRESULT WINAPI HTMLTxtRange_QueryInterface(IHTMLTxtRange *iface, REFIID riid, void **ppv)
1005 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1009 if(IsEqualGUID(&IID_IUnknown, riid)) {
1010 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1011 *ppv = &This->IHTMLTxtRange_iface;
1012 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1013 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1014 *ppv = &This->IHTMLTxtRange_iface;
1015 }else if(IsEqualGUID(&IID_IHTMLTxtRange, riid)) {
1016 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This, ppv);
1017 *ppv = &This->IHTMLTxtRange_iface;
1018 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1019 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This, ppv);
1020 *ppv = &This->IOleCommandTarget_iface;
1024 IUnknown_AddRef((IUnknown*)*ppv);
1028 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1029 return E_NOINTERFACE;
1032 static ULONG WINAPI HTMLTxtRange_AddRef(IHTMLTxtRange *iface)
1034 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1035 LONG ref = InterlockedIncrement(&This->ref);
1037 TRACE("(%p) ref=%d\n", This, ref);
1042 static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface)
1044 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1045 LONG ref = InterlockedDecrement(&This->ref);
1047 TRACE("(%p) ref=%d\n", This, ref);
1051 nsISelection_Release(This->nsrange);
1053 list_remove(&This->entry);
1060 static HRESULT WINAPI HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange *iface, UINT *pctinfo)
1062 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1063 FIXME("(%p)->(%p)\n", This, pctinfo);
1067 static HRESULT WINAPI HTMLTxtRange_GetTypeInfo(IHTMLTxtRange *iface, UINT iTInfo,
1068 LCID lcid, ITypeInfo **ppTInfo)
1070 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1071 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1075 static HRESULT WINAPI HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange *iface, REFIID riid,
1076 LPOLESTR *rgszNames, UINT cNames,
1077 LCID lcid, DISPID *rgDispId)
1079 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1080 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1085 static HRESULT WINAPI HTMLTxtRange_Invoke(IHTMLTxtRange *iface, DISPID dispIdMember,
1086 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1087 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1089 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1090 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1091 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1095 static HRESULT WINAPI HTMLTxtRange_get_htmlText(IHTMLTxtRange *iface, BSTR *p)
1097 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1099 TRACE("(%p)->(%p)\n", This, p);
1104 nsIDOMDocumentFragment *fragment;
1107 nsres = nsIDOMRange_CloneContents(This->nsrange, &fragment);
1108 if(NS_SUCCEEDED(nsres)) {
1109 const PRUnichar *nstext;
1112 nsAString_Init(&nsstr, NULL);
1113 nsnode_to_nsstring((nsIDOMNode*)fragment, &nsstr);
1114 nsIDOMDocumentFragment_Release(fragment);
1116 nsAString_GetData(&nsstr, &nstext);
1117 *p = SysAllocString(nstext);
1119 nsAString_Finish(&nsstr);
1124 const WCHAR emptyW[] = {0};
1125 *p = SysAllocString(emptyW);
1128 TRACE("return %s\n", debugstr_w(*p));
1132 static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v)
1134 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1135 nsIDOMText *text_node;
1139 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1142 return MSHTML_E_NODOC;
1144 nsAString_InitDepend(&text_str, v);
1145 nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc->nsdoc, &text_str, &text_node);
1146 nsAString_Finish(&text_str);
1147 if(NS_FAILED(nsres)) {
1148 ERR("CreateTextNode failed: %08x\n", nsres);
1151 nsres = nsIDOMRange_DeleteContents(This->nsrange);
1152 if(NS_FAILED(nsres))
1153 ERR("DeleteContents failed: %08x\n", nsres);
1155 nsres = nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)text_node);
1156 if(NS_FAILED(nsres))
1157 ERR("InsertNode failed: %08x\n", nsres);
1159 nsres = nsIDOMRange_SetEndAfter(This->nsrange, (nsIDOMNode*)text_node);
1160 if(NS_FAILED(nsres))
1161 ERR("SetEndAfter failed: %08x\n", nsres);
1163 return IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, VARIANT_FALSE);
1166 static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p)
1168 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1171 TRACE("(%p)->(%p)\n", This, p);
1177 if (!wstrbuf_init(&buf))
1178 return E_OUTOFMEMORY;
1179 range_to_string(This, &buf);
1181 *p = SysAllocString(buf.buf);
1182 wstrbuf_finish(&buf);
1184 TRACE("ret %s\n", debugstr_w(*p));
1188 static HRESULT WINAPI HTMLTxtRange_parentElement(IHTMLTxtRange *iface, IHTMLElement **parent)
1190 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1191 nsIDOMNode *nsnode, *tmp;
1195 TRACE("(%p)->(%p)\n", This, parent);
1197 nsIDOMRange_GetCommonAncestorContainer(This->nsrange, &nsnode);
1198 while(nsnode && get_node_type(nsnode) != ELEMENT_NODE) {
1199 nsIDOMNode_GetParentNode(nsnode, &tmp);
1200 nsIDOMNode_Release(nsnode);
1209 hres = get_node(This->doc, nsnode, TRUE, &node);
1210 nsIDOMNode_Release(nsnode);
1214 return IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)parent);
1217 static HRESULT WINAPI HTMLTxtRange_duplicate(IHTMLTxtRange *iface, IHTMLTxtRange **Duplicate)
1219 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1220 nsIDOMRange *nsrange = NULL;
1223 TRACE("(%p)->(%p)\n", This, Duplicate);
1225 nsIDOMRange_CloneRange(This->nsrange, &nsrange);
1226 hres = HTMLTxtRange_Create(This->doc, nsrange, Duplicate);
1227 nsIDOMRange_Release(nsrange);
1232 static HRESULT WINAPI HTMLTxtRange_inRange(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
1233 VARIANT_BOOL *InRange)
1235 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1236 HTMLTxtRange *src_range;
1240 TRACE("(%p)->(%p %p)\n", This, Range, InRange);
1242 *InRange = VARIANT_FALSE;
1244 src_range = get_range_object(This->doc, Range);
1248 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
1249 src_range->nsrange, &nsret);
1250 if(NS_SUCCEEDED(nsres) && nsret <= 0) {
1251 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
1252 src_range->nsrange, &nsret);
1253 if(NS_SUCCEEDED(nsres) && nsret >= 0)
1254 *InRange = VARIANT_TRUE;
1257 if(NS_FAILED(nsres))
1258 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
1263 static HRESULT WINAPI HTMLTxtRange_isEqual(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
1264 VARIANT_BOOL *IsEqual)
1266 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1267 HTMLTxtRange *src_range;
1271 TRACE("(%p)->(%p %p)\n", This, Range, IsEqual);
1273 *IsEqual = VARIANT_FALSE;
1275 src_range = get_range_object(This->doc, Range);
1279 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
1280 src_range->nsrange, &nsret);
1281 if(NS_SUCCEEDED(nsres) && !nsret) {
1282 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
1283 src_range->nsrange, &nsret);
1284 if(NS_SUCCEEDED(nsres) && !nsret)
1285 *IsEqual = VARIANT_TRUE;
1288 if(NS_FAILED(nsres))
1289 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
1294 static HRESULT WINAPI HTMLTxtRange_scrollIntoView(IHTMLTxtRange *iface, VARIANT_BOOL fStart)
1296 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1297 FIXME("(%p)->(%x)\n", This, fStart);
1301 static HRESULT WINAPI HTMLTxtRange_collapse(IHTMLTxtRange *iface, VARIANT_BOOL Start)
1303 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1305 TRACE("(%p)->(%x)\n", This, Start);
1307 nsIDOMRange_Collapse(This->nsrange, Start != VARIANT_FALSE);
1311 static HRESULT WINAPI HTMLTxtRange_expand(IHTMLTxtRange *iface, BSTR Unit, VARIANT_BOOL *Success)
1313 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1316 TRACE("(%p)->(%s %p)\n", This, debugstr_w(Unit), Success);
1318 unit = string_to_unit(Unit);
1319 if(unit == RU_UNKNOWN)
1320 return E_INVALIDARG;
1322 *Success = VARIANT_FALSE;
1326 dompos_t end_pos, start_pos, new_start_pos, new_end_pos;
1329 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
1331 get_cur_pos(This, TRUE, &start_pos);
1332 get_cur_pos(This, FALSE, &end_pos);
1334 if(find_word_end(&end_pos, &new_end_pos) || collapsed) {
1335 set_range_pos(This, FALSE, &new_end_pos);
1336 *Success = VARIANT_TRUE;
1339 if(start_pos.type && (get_pos_char(&end_pos) || !dompos_cmp(&new_end_pos, &end_pos))) {
1340 if(find_prev_space(This, &start_pos, TRUE, &new_start_pos)) {
1341 set_range_pos(This, TRUE, &new_start_pos);
1342 *Success = VARIANT_TRUE;
1344 dompos_release(&new_start_pos);
1347 dompos_release(&new_end_pos);
1348 dompos_release(&end_pos);
1349 dompos_release(&start_pos);
1355 nsIDOMHTMLElement *nsbody = NULL;
1358 nsres = nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nsbody);
1359 if(NS_FAILED(nsres) || !nsbody) {
1360 ERR("Could not get body: %08x\n", nsres);
1364 nsres = nsIDOMRange_SelectNodeContents(This->nsrange, (nsIDOMNode*)nsbody);
1365 nsIDOMHTMLElement_Release(nsbody);
1366 if(NS_FAILED(nsres)) {
1367 ERR("Collapse failed: %08x\n", nsres);
1371 *Success = VARIANT_TRUE;
1376 FIXME("Unimplemented unit %s\n", debugstr_w(Unit));
1382 static HRESULT WINAPI HTMLTxtRange_move(IHTMLTxtRange *iface, BSTR Unit,
1383 LONG Count, LONG *ActualCount)
1385 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1388 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(Unit), Count, ActualCount);
1390 unit = string_to_unit(Unit);
1391 if(unit == RU_UNKNOWN)
1392 return E_INVALIDARG;
1396 return IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, TRUE);
1401 dompos_t cur_pos, new_pos;
1403 get_cur_pos(This, TRUE, &cur_pos);
1406 *ActualCount = move_next_chars(Count, &cur_pos, TRUE, NULL, NULL, &new_pos);
1407 set_range_pos(This, FALSE, &new_pos);
1408 dompos_release(&new_pos);
1410 IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, FALSE);
1412 *ActualCount = -move_prev_chars(This, -Count, &cur_pos, FALSE, NULL, NULL, &new_pos);
1413 set_range_pos(This, TRUE, &new_pos);
1414 IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, TRUE);
1415 dompos_release(&new_pos);
1418 dompos_release(&cur_pos);
1423 dompos_t cur_pos, new_pos;
1425 get_cur_pos(This, TRUE, &cur_pos);
1428 *ActualCount = move_next_words(Count, &cur_pos, &new_pos);
1429 set_range_pos(This, FALSE, &new_pos);
1430 dompos_release(&new_pos);
1431 IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, FALSE);
1433 *ActualCount = -move_prev_words(This, -Count, &cur_pos, &new_pos);
1434 set_range_pos(This, TRUE, &new_pos);
1435 IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, TRUE);
1436 dompos_release(&new_pos);
1439 dompos_release(&cur_pos);
1444 FIXME("unimplemented unit %s\n", debugstr_w(Unit));
1447 TRACE("ret %d\n", *ActualCount);
1451 static HRESULT WINAPI HTMLTxtRange_moveStart(IHTMLTxtRange *iface, BSTR Unit,
1452 LONG Count, LONG *ActualCount)
1454 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1457 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(Unit), Count, ActualCount);
1459 unit = string_to_unit(Unit);
1460 if(unit == RU_UNKNOWN)
1461 return E_INVALIDARG;
1470 dompos_t start_pos, end_pos, new_pos;
1473 get_cur_pos(This, TRUE, &start_pos);
1474 get_cur_pos(This, FALSE, &end_pos);
1475 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
1480 *ActualCount = move_next_chars(Count, &start_pos, collapsed, &end_pos, &bounded, &new_pos);
1481 set_range_pos(This, !bounded, &new_pos);
1483 IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, FALSE);
1485 *ActualCount = -move_prev_chars(This, -Count, &start_pos, FALSE, NULL, NULL, &new_pos);
1486 set_range_pos(This, TRUE, &new_pos);
1489 dompos_release(&start_pos);
1490 dompos_release(&end_pos);
1491 dompos_release(&new_pos);
1496 FIXME("unimplemented unit %s\n", debugstr_w(Unit));
1502 static HRESULT WINAPI HTMLTxtRange_moveEnd(IHTMLTxtRange *iface, BSTR Unit,
1503 LONG Count, LONG *ActualCount)
1505 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1508 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(Unit), Count, ActualCount);
1510 unit = string_to_unit(Unit);
1511 if(unit == RU_UNKNOWN)
1512 return E_INVALIDARG;
1521 dompos_t start_pos, end_pos, new_pos;
1524 get_cur_pos(This, TRUE, &start_pos);
1525 get_cur_pos(This, FALSE, &end_pos);
1526 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
1529 *ActualCount = move_next_chars(Count, &end_pos, collapsed, NULL, NULL, &new_pos);
1530 set_range_pos(This, FALSE, &new_pos);
1534 *ActualCount = -move_prev_chars(This, -Count, &end_pos, TRUE, &start_pos, &bounded, &new_pos);
1535 set_range_pos(This, bounded, &new_pos);
1537 IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, TRUE);
1540 dompos_release(&start_pos);
1541 dompos_release(&end_pos);
1542 dompos_release(&new_pos);
1547 FIXME("unimplemented unit %s\n", debugstr_w(Unit));
1553 static HRESULT WINAPI HTMLTxtRange_select(IHTMLTxtRange *iface)
1555 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1556 nsISelection *nsselection;
1559 TRACE("(%p)\n", This);
1561 nsres = nsIDOMWindow_GetSelection(This->doc->basedoc.window->nswindow, &nsselection);
1562 if(NS_FAILED(nsres)) {
1563 ERR("GetSelection failed: %08x\n", nsres);
1567 nsISelection_RemoveAllRanges(nsselection);
1568 nsISelection_AddRange(nsselection, This->nsrange);
1569 nsISelection_Release(nsselection);
1573 static HRESULT WINAPI HTMLTxtRange_pasteHTML(IHTMLTxtRange *iface, BSTR html)
1575 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1576 FIXME("(%p)->(%s)\n", This, debugstr_w(html));
1580 static HRESULT WINAPI HTMLTxtRange_moveToElementText(IHTMLTxtRange *iface, IHTMLElement *element)
1582 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1583 FIXME("(%p)->(%p)\n", This, element);
1587 static HRESULT WINAPI HTMLTxtRange_setEndPoint(IHTMLTxtRange *iface, BSTR how,
1588 IHTMLTxtRange *SourceRange)
1590 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1591 FIXME("(%p)->(%s %p)\n", This, debugstr_w(how), SourceRange);
1595 static HRESULT WINAPI HTMLTxtRange_compareEndPoints(IHTMLTxtRange *iface, BSTR how,
1596 IHTMLTxtRange *SourceRange, LONG *ret)
1598 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1599 HTMLTxtRange *src_range;
1604 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(how), SourceRange, ret);
1606 nscmpt = string_to_nscmptype(how);
1608 return E_INVALIDARG;
1610 src_range = get_range_object(This->doc, SourceRange);
1614 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, nscmpt, src_range->nsrange, &nsret);
1615 if(NS_FAILED(nsres))
1616 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
1622 static HRESULT WINAPI HTMLTxtRange_findText(IHTMLTxtRange *iface, BSTR String,
1623 LONG count, LONG Flags, VARIANT_BOOL *Success)
1625 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1626 FIXME("(%p)->(%s %d %08x %p)\n", This, debugstr_w(String), count, Flags, Success);
1630 static HRESULT WINAPI HTMLTxtRange_moveToPoint(IHTMLTxtRange *iface, LONG x, LONG y)
1632 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1633 FIXME("(%p)->(%d %d)\n", This, x, y);
1637 static HRESULT WINAPI HTMLTxtRange_getBookmark(IHTMLTxtRange *iface, BSTR *Bookmark)
1639 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1640 FIXME("(%p)->(%p)\n", This, Bookmark);
1644 static HRESULT WINAPI HTMLTxtRange_moveToBookmark(IHTMLTxtRange *iface, BSTR Bookmark,
1645 VARIANT_BOOL *Success)
1647 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1648 FIXME("(%p)->(%s %p)\n", This, debugstr_w(Bookmark), Success);
1652 static HRESULT WINAPI HTMLTxtRange_queryCommandSupported(IHTMLTxtRange *iface, BSTR cmdID,
1653 VARIANT_BOOL *pfRet)
1655 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1656 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1660 static HRESULT WINAPI HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange *iface, BSTR cmdID,
1661 VARIANT_BOOL *pfRet)
1663 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1664 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1668 static HRESULT WINAPI HTMLTxtRange_queryCommandState(IHTMLTxtRange *iface, BSTR cmdID,
1669 VARIANT_BOOL *pfRet)
1671 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1672 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1676 static HRESULT WINAPI HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange *iface, BSTR cmdID,
1677 VARIANT_BOOL *pfRet)
1679 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1680 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1684 static HRESULT WINAPI HTMLTxtRange_queryCommandText(IHTMLTxtRange *iface, BSTR cmdID,
1687 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1688 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdText);
1692 static HRESULT WINAPI HTMLTxtRange_queryCommandValue(IHTMLTxtRange *iface, BSTR cmdID,
1695 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1696 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdValue);
1700 static HRESULT WINAPI HTMLTxtRange_execCommand(IHTMLTxtRange *iface, BSTR cmdID,
1701 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1703 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1704 FIXME("(%p)->(%s %x v %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
1708 static HRESULT WINAPI HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange *iface, BSTR cmdID,
1709 VARIANT_BOOL *pfRet)
1711 HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
1712 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1716 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = {
1717 HTMLTxtRange_QueryInterface,
1718 HTMLTxtRange_AddRef,
1719 HTMLTxtRange_Release,
1720 HTMLTxtRange_GetTypeInfoCount,
1721 HTMLTxtRange_GetTypeInfo,
1722 HTMLTxtRange_GetIDsOfNames,
1723 HTMLTxtRange_Invoke,
1724 HTMLTxtRange_get_htmlText,
1725 HTMLTxtRange_put_text,
1726 HTMLTxtRange_get_text,
1727 HTMLTxtRange_parentElement,
1728 HTMLTxtRange_duplicate,
1729 HTMLTxtRange_inRange,
1730 HTMLTxtRange_isEqual,
1731 HTMLTxtRange_scrollIntoView,
1732 HTMLTxtRange_collapse,
1733 HTMLTxtRange_expand,
1735 HTMLTxtRange_moveStart,
1736 HTMLTxtRange_moveEnd,
1737 HTMLTxtRange_select,
1738 HTMLTxtRange_pasteHTML,
1739 HTMLTxtRange_moveToElementText,
1740 HTMLTxtRange_setEndPoint,
1741 HTMLTxtRange_compareEndPoints,
1742 HTMLTxtRange_findText,
1743 HTMLTxtRange_moveToPoint,
1744 HTMLTxtRange_getBookmark,
1745 HTMLTxtRange_moveToBookmark,
1746 HTMLTxtRange_queryCommandSupported,
1747 HTMLTxtRange_queryCommandEnabled,
1748 HTMLTxtRange_queryCommandState,
1749 HTMLTxtRange_queryCommandIndeterm,
1750 HTMLTxtRange_queryCommandText,
1751 HTMLTxtRange_queryCommandValue,
1752 HTMLTxtRange_execCommand,
1753 HTMLTxtRange_execCommandShowHelp
1756 static inline HTMLTxtRange *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
1758 return CONTAINING_RECORD(iface, HTMLTxtRange, IOleCommandTarget_iface);
1761 static HRESULT WINAPI RangeCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
1763 HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
1764 return IHTMLTxtRange_QueryInterface(&This->IHTMLTxtRange_iface, riid, ppv);
1767 static ULONG WINAPI RangeCommandTarget_AddRef(IOleCommandTarget *iface)
1769 HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
1770 return IHTMLTxtRange_AddRef(&This->IHTMLTxtRange_iface);
1773 static ULONG WINAPI RangeCommandTarget_Release(IOleCommandTarget *iface)
1775 HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
1776 return IHTMLTxtRange_Release(&This->IHTMLTxtRange_iface);
1779 static HRESULT WINAPI RangeCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
1780 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
1782 HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
1783 FIXME("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
1787 static HRESULT exec_indent(HTMLTxtRange *This, VARIANT *in, VARIANT *out)
1789 nsIDOMHTMLElement *blockquote_elem, *p_elem;
1790 nsIDOMDocumentFragment *fragment;
1793 static const PRUnichar blockquoteW[] = {'B','L','O','C','K','Q','U','O','T','E',0};
1794 static const PRUnichar pW[] = {'P',0};
1796 TRACE("(%p)->(%p %p)\n", This, in, out);
1798 if(!This->doc->nsdoc) {
1799 WARN("NULL nsdoc\n");
1803 create_nselem(This->doc, blockquoteW, &blockquote_elem);
1804 create_nselem(This->doc, pW, &p_elem);
1806 nsIDOMRange_ExtractContents(This->nsrange, &fragment);
1807 nsIDOMElement_AppendChild(p_elem, (nsIDOMNode*)fragment, &tmp);
1808 nsIDOMDocumentFragment_Release(fragment);
1809 nsIDOMNode_Release(tmp);
1811 nsIDOMElement_AppendChild(blockquote_elem, (nsIDOMNode*)p_elem, &tmp);
1812 nsIDOMElement_Release(p_elem);
1813 nsIDOMNode_Release(tmp);
1815 nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)blockquote_elem);
1816 nsIDOMElement_Release(blockquote_elem);
1821 static HRESULT WINAPI RangeCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
1822 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
1824 HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
1826 TRACE("(%p)->(%s %d %x %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
1827 nCmdexecopt, pvaIn, pvaOut);
1829 if(pguidCmdGroup && IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
1832 return exec_indent(This, pvaIn, pvaOut);
1834 FIXME("Unsupported cmdid %d of CGID_MSHTML\n", nCmdID);
1837 FIXME("Unsupported cmd %d of group %s\n", nCmdID, debugstr_guid(pguidCmdGroup));
1843 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1844 RangeCommandTarget_QueryInterface,
1845 RangeCommandTarget_AddRef,
1846 RangeCommandTarget_Release,
1847 RangeCommandTarget_QueryStatus,
1848 RangeCommandTarget_Exec
1851 HRESULT HTMLTxtRange_Create(HTMLDocumentNode *doc, nsIDOMRange *nsrange, IHTMLTxtRange **p)
1855 ret = heap_alloc(sizeof(HTMLTxtRange));
1857 return E_OUTOFMEMORY;
1859 ret->IHTMLTxtRange_iface.lpVtbl = &HTMLTxtRangeVtbl;
1860 ret->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1864 nsIDOMRange_AddRef(nsrange);
1865 ret->nsrange = nsrange;
1868 list_add_head(&doc->range_list, &ret->entry);
1870 *p = &ret->IHTMLTxtRange_iface;
1874 void detach_ranges(HTMLDocumentNode *This)
1878 LIST_FOR_EACH_ENTRY(iter, &This->range_list, HTMLTxtRange, entry) {