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"
30 #include "wine/unicode.h"
32 #include "mshtml_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
36 static const WCHAR brW
[] = {'b','r',0};
37 static const WCHAR hrW
[] = {'h','r',0};
40 const IHTMLTxtRangeVtbl
*lpHTMLTxtRangeVtbl
;
41 const IOleCommandTargetVtbl
*lpOleCommandTargetVtbl
;
51 #define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl)
75 static HTMLTxtRange
*get_range_object(HTMLDocument
*doc
, IHTMLTxtRange
*iface
)
79 LIST_FOR_EACH_ENTRY(iter
, &doc
->range_list
, HTMLTxtRange
, entry
) {
80 if(HTMLTXTRANGE(iter
) == iface
)
84 ERR("Could not find range in document\n");
88 static range_unit_t
string_to_unit(LPCWSTR str
)
90 static const WCHAR characterW
[] =
91 {'c','h','a','r','a','c','t','e','r',0};
92 static const WCHAR wordW
[] =
94 static const WCHAR sentenceW
[] =
95 {'s','e','n','t','e','n','c','e',0};
96 static const WCHAR texteditW
[] =
97 {'t','e','x','t','e','d','i','t',0};
99 if(!strcmpiW(str
, characterW
)) return RU_CHAR
;
100 if(!strcmpiW(str
, wordW
)) return RU_WORD
;
101 if(!strcmpiW(str
, sentenceW
)) return RU_SENTENCE
;
102 if(!strcmpiW(str
, texteditW
)) return RU_TEXTEDIT
;
107 static int string_to_nscmptype(LPCWSTR str
)
109 static const WCHAR seW
[] = {'S','t','a','r','t','T','o','E','n','d',0};
110 static const WCHAR ssW
[] = {'S','t','a','r','t','T','o','S','t','a','r','t',0};
111 static const WCHAR esW
[] = {'E','n','d','T','o','S','t','a','r','t',0};
112 static const WCHAR eeW
[] = {'E','n','d','T','o','E','n','d',0};
114 if(!strcmpiW(str
, seW
)) return NS_START_TO_END
;
115 if(!strcmpiW(str
, ssW
)) return NS_START_TO_START
;
116 if(!strcmpiW(str
, esW
)) return NS_END_TO_START
;
117 if(!strcmpiW(str
, eeW
)) return NS_END_TO_END
;
122 static PRUint16
get_node_type(nsIDOMNode
*node
)
127 nsIDOMNode_GetNodeType(node
, &type
);
132 static BOOL
is_elem_tag(nsIDOMNode
*node
, LPCWSTR istag
)
136 const PRUnichar
*tag
;
140 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
144 nsAString_Init(&tag_str
, NULL
);
145 nsIDOMElement_GetTagName(elem
, &tag_str
);
146 nsIDOMElement_Release(elem
);
147 nsAString_GetData(&tag_str
, &tag
);
149 ret
= !strcmpiW(tag
, istag
);
151 nsAString_Finish(&tag_str
);
156 static BOOL
is_space_elem(nsIDOMNode
*node
)
160 const PRUnichar
*tag
;
164 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
168 nsAString_Init(&tag_str
, NULL
);
169 nsIDOMElement_GetTagName(elem
, &tag_str
);
170 nsIDOMElement_Release(elem
);
171 nsAString_GetData(&tag_str
, &tag
);
173 ret
= !strcmpiW(tag
, brW
) || !strcmpiW(tag
, hrW
);
175 nsAString_Finish(&tag_str
);
180 static inline void wstrbuf_init(wstrbuf_t
*buf
)
184 buf
->buf
= heap_alloc(buf
->size
* sizeof(WCHAR
));
188 static inline void wstrbuf_finish(wstrbuf_t
*buf
)
193 static void wstrbuf_append_len(wstrbuf_t
*buf
, LPCWSTR str
, int len
)
195 if(buf
->len
+len
>= buf
->size
) {
196 buf
->size
= 2*buf
->len
+len
;
197 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
* sizeof(WCHAR
));
200 memcpy(buf
->buf
+buf
->len
, str
, len
*sizeof(WCHAR
));
202 buf
->buf
[buf
->len
] = 0;
205 static inline void wstrbuf_append(wstrbuf_t
*buf
, LPCWSTR str
)
207 wstrbuf_append_len(buf
, str
, strlenW(str
));
210 static void wstrbuf_append_nodetxt(wstrbuf_t
*buf
, LPCWSTR str
, int len
)
212 const WCHAR
*s
= str
;
215 TRACE("%s\n", debugstr_wn(str
, len
));
217 if(buf
->len
+len
>= buf
->size
) {
218 buf
->size
= 2*buf
->len
+len
;
219 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
* sizeof(WCHAR
));
222 if(buf
->len
&& isspaceW(buf
->buf
[buf
->len
-1])) {
223 while(s
< str
+len
&& isspaceW(*s
))
227 d
= buf
->buf
+buf
->len
;
232 while(s
< str
+len
&& isspaceW(*s
))
239 buf
->len
= d
- buf
->buf
;
243 static void wstrbuf_append_node(wstrbuf_t
*buf
, nsIDOMNode
*node
)
246 switch(get_node_type(node
)) {
250 const PRUnichar
*data
;
252 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMText
, (void**)&nstext
);
254 nsAString_Init(&data_str
, NULL
);
255 nsIDOMText_GetData(nstext
, &data_str
);
256 nsAString_GetData(&data_str
, &data
);
257 wstrbuf_append_nodetxt(buf
, data
, strlenW(data
));
258 nsAString_Finish(&data_str
);
260 nsIDOMText_Release(nstext
);
265 if(is_elem_tag(node
, brW
)) {
266 static const WCHAR endlW
[] = {'\r','\n'};
267 wstrbuf_append_len(buf
, endlW
, 2);
268 }else if(is_elem_tag(node
, hrW
)) {
269 static const WCHAR endl2W
[] = {'\r','\n','\r','\n'};
270 wstrbuf_append_len(buf
, endl2W
, 4);
275 static BOOL
fill_nodestr(dompos_t
*pos
)
280 if(pos
->type
!= TEXT_NODE
)
283 nsres
= nsIDOMNode_QueryInterface(pos
->node
, &IID_nsIDOMText
, (void**)&text
);
287 nsAString_Init(&pos
->str
, NULL
);
288 nsIDOMText_GetData(text
, &pos
->str
);
289 nsIDOMText_Release(text
);
290 nsAString_GetData(&pos
->str
, &pos
->p
);
293 pos
->off
= *pos
->p
? strlenW(pos
->p
)-1 : 0;
298 static nsIDOMNode
*next_node(nsIDOMNode
*iter
)
300 nsIDOMNode
*ret
, *tmp
;
306 nsres
= nsIDOMNode_GetFirstChild(iter
, &ret
);
307 if(NS_SUCCEEDED(nsres
) && ret
)
310 nsIDOMNode_AddRef(iter
);
313 nsres
= nsIDOMNode_GetNextSibling(iter
, &ret
);
314 if(NS_SUCCEEDED(nsres
) && ret
) {
315 nsIDOMNode_Release(iter
);
319 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
320 nsIDOMNode_Release(iter
);
322 }while(NS_SUCCEEDED(nsres
) && iter
);
327 static nsIDOMNode
*prev_node(HTMLTxtRange
*This
, nsIDOMNode
*iter
)
329 nsIDOMNode
*ret
, *tmp
;
333 nsIDOMHTMLDocument
*nshtmldoc
;
334 nsIDOMHTMLElement
*nselem
;
335 nsIDOMDocument
*nsdoc
;
337 nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
338 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nshtmldoc
);
339 nsIDOMDocument_Release(nsdoc
);
340 nsIDOMHTMLDocument_GetBody(nshtmldoc
, &nselem
);
341 nsIDOMHTMLDocument_Release(nshtmldoc
);
343 nsIDOMElement_GetLastChild(nselem
, &tmp
);
345 return (nsIDOMNode
*)nselem
;
349 nsIDOMNode_GetLastChild(ret
, &tmp
);
352 nsIDOMElement_Release(nselem
);
357 nsres
= nsIDOMNode_GetLastChild(iter
, &ret
);
358 if(NS_SUCCEEDED(nsres
) && ret
)
361 nsIDOMNode_AddRef(iter
);
364 nsres
= nsIDOMNode_GetPreviousSibling(iter
, &ret
);
365 if(NS_SUCCEEDED(nsres
) && ret
) {
366 nsIDOMNode_Release(iter
);
370 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
371 nsIDOMNode_Release(iter
);
373 }while(NS_SUCCEEDED(nsres
) && iter
);
378 static nsIDOMNode
*get_child_node(nsIDOMNode
*node
, PRUint32 off
)
380 nsIDOMNodeList
*node_list
;
381 nsIDOMNode
*ret
= NULL
;
383 nsIDOMNode_GetChildNodes(node
, &node_list
);
384 nsIDOMNodeList_Item(node_list
, off
, &ret
);
385 nsIDOMNodeList_Release(node_list
);
390 static void get_cur_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
399 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
404 nsIDOMRange_GetStartContainer(This
->nsrange
, &node
);
405 nsIDOMRange_GetStartOffset(This
->nsrange
, &off
);
407 nsIDOMRange_GetEndContainer(This
->nsrange
, &node
);
408 nsIDOMRange_GetEndOffset(This
->nsrange
, &off
);
411 pos
->type
= get_node_type(node
);
412 if(pos
->type
== ELEMENT_NODE
) {
414 pos
->node
= get_child_node(node
, off
);
417 pos
->node
= off
? get_child_node(node
, off
-1) : prev_node(This
, node
);
421 pos
->type
= get_node_type(pos
->node
);
422 nsIDOMNode_Release(node
);
430 pos
->node
= prev_node(This
, node
);
432 nsIDOMNode_Release(node
);
435 if(pos
->type
== TEXT_NODE
)
439 static void set_range_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
444 if(pos
->type
== TEXT_NODE
)
445 nsres
= nsIDOMRange_SetStart(This
->nsrange
, pos
->node
, pos
->off
);
447 nsres
= nsIDOMRange_SetStartBefore(This
->nsrange
, pos
->node
);
449 if(pos
->type
== TEXT_NODE
&& pos
->p
[pos
->off
+1])
450 nsres
= nsIDOMRange_SetEnd(This
->nsrange
, pos
->node
, pos
->off
+1);
452 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, pos
->node
);
456 ERR("failed: %p %08x\n", pos
->node
, nsres
);
459 static inline void dompos_release(dompos_t
*pos
)
462 nsIDOMNode_Release(pos
->node
);
465 nsAString_Finish(&pos
->str
);
468 static inline void dompos_addref(dompos_t
*pos
)
471 nsIDOMNode_AddRef(pos
->node
);
473 if(pos
->type
== TEXT_NODE
)
477 static inline BOOL
dompos_cmp(const dompos_t
*pos1
, const dompos_t
*pos2
)
479 return pos1
->node
== pos2
->node
&& pos1
->off
== pos2
->off
;
482 static void range_to_string(HTMLTxtRange
*This
, wstrbuf_t
*buf
)
484 nsIDOMNode
*iter
, *tmp
;
485 dompos_t start_pos
, end_pos
;
488 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
496 get_cur_pos(This
, FALSE
, &end_pos
);
497 get_cur_pos(This
, TRUE
, &start_pos
);
499 if(start_pos
.type
== TEXT_NODE
) {
500 if(start_pos
.node
== end_pos
.node
) {
501 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, end_pos
.off
-start_pos
.off
+1);
502 iter
= start_pos
.node
;
503 nsIDOMNode_AddRef(iter
);
505 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, strlenW(start_pos
.p
+start_pos
.off
));
506 iter
= next_node(start_pos
.node
);
509 iter
= start_pos
.node
;
510 nsIDOMNode_AddRef(iter
);
513 while(iter
!= end_pos
.node
) {
514 wstrbuf_append_node(buf
, iter
);
515 tmp
= next_node(iter
);
516 nsIDOMNode_Release(iter
);
520 nsIDOMNode_AddRef(end_pos
.node
);
522 if(start_pos
.node
!= end_pos
.node
) {
523 if(end_pos
.type
== TEXT_NODE
)
524 wstrbuf_append_nodetxt(buf
, end_pos
.p
, end_pos
.off
+1);
526 wstrbuf_append_node(buf
, end_pos
.node
);
529 nsIDOMNode_Release(iter
);
530 dompos_release(&start_pos
);
531 dompos_release(&end_pos
);
536 for(p
= buf
->buf
+buf
->len
-1; p
>= buf
->buf
&& isspaceW(*p
); p
--);
538 p
= strchrW(p
, '\r');
544 static WCHAR
get_pos_char(const dompos_t
*pos
)
548 return pos
->p
[pos
->off
];
550 if(is_space_elem(pos
->node
))
557 static void end_space(const dompos_t
*pos
, dompos_t
*new_pos
)
562 dompos_addref(new_pos
);
564 if(pos
->type
!= TEXT_NODE
)
567 p
= new_pos
->p
+new_pos
->off
;
569 if(!*p
|| !isspace(*p
))
572 while(p
[1] && isspace(p
[1]))
575 new_pos
->off
= p
- new_pos
->p
;
578 static WCHAR
next_char(const dompos_t
*pos
, dompos_t
*new_pos
)
580 nsIDOMNode
*iter
, *tmp
;
581 dompos_t last_space
, tmp_pos
;
585 if(pos
->type
== TEXT_NODE
&& pos
->off
!= -1 && pos
->p
[pos
->off
]) {
589 while(isspaceW(*++p
));
593 if(*p
&& isspaceW(*p
)) {
595 while(p
[1] && isspaceW(p
[1]))
601 new_pos
->off
= p
- pos
->p
;
602 dompos_addref(new_pos
);
604 return cspace
? cspace
: *p
;
607 last_space
.off
= p
- pos
->p
;
608 dompos_addref(&last_space
);
612 iter
= next_node(pos
->node
);
615 switch(get_node_type(iter
)) {
618 tmp_pos
.type
= TEXT_NODE
;
619 dompos_addref(&tmp_pos
);
624 dompos_release(&tmp_pos
);
626 }else if(isspaceW(*p
)) {
628 dompos_release(&last_space
);
632 while(p
[1] && isspaceW(p
[1]))
635 tmp_pos
.off
= p
-tmp_pos
.p
;
638 last_space
= tmp_pos
;
643 nsIDOMNode_Release(iter
);
646 *new_pos
= last_space
;
647 dompos_release(&tmp_pos
);
648 nsIDOMNode_Release(iter
);
656 nsIDOMNode_Release(iter
);
660 if(is_elem_tag(iter
, brW
)) {
662 dompos_release(&last_space
);
665 nsIDOMNode_AddRef(iter
);
666 last_space
.node
= iter
;
667 last_space
.type
= ELEMENT_NODE
;
670 }else if(is_elem_tag(iter
, hrW
)) {
672 *new_pos
= last_space
;
673 nsIDOMNode_Release(iter
);
677 new_pos
->node
= iter
;
678 new_pos
->type
= ELEMENT_NODE
;
686 iter
= next_node(iter
);
687 nsIDOMNode_Release(tmp
);
691 *new_pos
= last_space
;
694 dompos_addref(new_pos
);
700 static WCHAR
prev_char(HTMLTxtRange
*This
, const dompos_t
*pos
, dompos_t
*new_pos
)
702 nsIDOMNode
*iter
, *tmp
;
704 BOOL skip_space
= FALSE
;
706 if(pos
->type
== TEXT_NODE
&& isspaceW(pos
->p
[pos
->off
]))
709 if(pos
->type
== TEXT_NODE
&& pos
->off
) {
710 p
= pos
->p
+pos
->off
-1;
713 while(p
>= pos
->p
&& isspace(*p
))
719 new_pos
->off
= p
-pos
->p
;
720 dompos_addref(new_pos
);
721 return new_pos
->p
[new_pos
->off
];
725 iter
= prev_node(This
, pos
->node
);
728 switch(get_node_type(iter
)) {
733 tmp_pos
.type
= TEXT_NODE
;
734 dompos_addref(&tmp_pos
);
736 p
= tmp_pos
.p
+ strlenW(tmp_pos
.p
)-1;
739 while(p
>= tmp_pos
.p
&& isspaceW(*p
))
744 dompos_release(&tmp_pos
);
748 tmp_pos
.off
= p
-tmp_pos
.p
;
750 nsIDOMNode_Release(iter
);
755 if(is_elem_tag(iter
, brW
)) {
760 }else if(!is_elem_tag(iter
, hrW
)) {
764 new_pos
->node
= iter
;
765 new_pos
->type
= ELEMENT_NODE
;
772 iter
= prev_node(This
, iter
);
773 nsIDOMNode_Release(tmp
);
777 dompos_addref(new_pos
);
781 static long move_next_chars(long cnt
, const dompos_t
*pos
, BOOL col
, const dompos_t
*bound_pos
,
782 BOOL
*bounded
, dompos_t
*new_pos
)
795 end_space(pos
, new_pos
);
799 c
= next_char(pos
, &iter
);
804 c
= next_char(&tmp
, &iter
);
805 dompos_release(&tmp
);
810 if(bound_pos
&& dompos_cmp(&tmp
, bound_pos
)) {
820 static long move_prev_chars(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, BOOL end
,
821 const dompos_t
*bound_pos
, BOOL
*bounded
, dompos_t
*new_pos
)
825 BOOL prev_eq
= FALSE
;
831 c
= prev_char(This
, pos
, &iter
);
835 while(c
&& ret
< cnt
) {
837 c
= prev_char(This
, &tmp
, &iter
);
838 dompos_release(&tmp
);
852 prev_eq
= bound_pos
&& dompos_cmp(&iter
, bound_pos
);
859 static long find_prev_space(HTMLTxtRange
*This
, const dompos_t
*pos
, BOOL first_space
, dompos_t
*ret
)
864 c
= prev_char(This
, pos
, &iter
);
865 if(!c
|| (first_space
&& isspaceW(c
))) {
872 c
= prev_char(This
, &tmp
, &iter
);
873 if(!c
|| isspaceW(c
)) {
874 dompos_release(&iter
);
877 dompos_release(&tmp
);
884 static int find_word_end(const dompos_t
*pos
, dompos_t
*ret
)
889 c
= get_pos_char(pos
);
896 c
= next_char(pos
, &iter
);
907 while(c
&& !isspaceW(c
)) {
909 c
= next_char(&tmp
, &iter
);
911 dompos_release(&iter
);
915 dompos_release(&tmp
);
923 static long move_next_words(long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
929 c
= get_pos_char(pos
);
931 end_space(pos
, &iter
);
934 c
= next_char(pos
, &iter
);
939 while(c
&& ret
< cnt
) {
941 c
= next_char(&tmp
, &iter
);
942 dompos_release(&tmp
);
951 static long move_prev_words(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
957 dompos_addref(&iter
);
960 if(!find_prev_space(This
, &iter
, FALSE
, &tmp
))
963 dompos_release(&iter
);
972 #define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
974 static HRESULT WINAPI
HTMLTxtRange_QueryInterface(IHTMLTxtRange
*iface
, REFIID riid
, void **ppv
)
976 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
980 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
981 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
982 *ppv
= HTMLTXTRANGE(This
);
983 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
984 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
985 *ppv
= HTMLTXTRANGE(This
);
986 }else if(IsEqualGUID(&IID_IHTMLTxtRange
, riid
)) {
987 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This
, ppv
);
988 *ppv
= HTMLTXTRANGE(This
);
989 }else if(IsEqualGUID(&IID_IOleCommandTarget
, riid
)) {
990 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This
, ppv
);
991 *ppv
= CMDTARGET(This
);
995 IUnknown_AddRef((IUnknown
*)*ppv
);
999 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1000 return E_NOINTERFACE
;
1003 static ULONG WINAPI
HTMLTxtRange_AddRef(IHTMLTxtRange
*iface
)
1005 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1006 LONG ref
= InterlockedIncrement(&This
->ref
);
1008 TRACE("(%p) ref=%d\n", This
, ref
);
1013 static ULONG WINAPI
HTMLTxtRange_Release(IHTMLTxtRange
*iface
)
1015 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1016 LONG ref
= InterlockedDecrement(&This
->ref
);
1018 TRACE("(%p) ref=%d\n", This
, ref
);
1022 nsISelection_Release(This
->nsrange
);
1024 list_remove(&This
->entry
);
1031 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange
*iface
, UINT
*pctinfo
)
1033 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1034 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1038 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfo(IHTMLTxtRange
*iface
, UINT iTInfo
,
1039 LCID lcid
, ITypeInfo
**ppTInfo
)
1041 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1042 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1046 static HRESULT WINAPI
HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange
*iface
, REFIID riid
,
1047 LPOLESTR
*rgszNames
, UINT cNames
,
1048 LCID lcid
, DISPID
*rgDispId
)
1050 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1051 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1056 static HRESULT WINAPI
HTMLTxtRange_Invoke(IHTMLTxtRange
*iface
, DISPID dispIdMember
,
1057 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1058 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1060 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1061 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1062 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1066 static HRESULT WINAPI
HTMLTxtRange_get_htmlText(IHTMLTxtRange
*iface
, BSTR
*p
)
1068 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1070 TRACE("(%p)->(%p)\n", This
, p
);
1075 nsIDOMDocumentFragment
*fragment
;
1078 nsres
= nsIDOMRange_CloneContents(This
->nsrange
, &fragment
);
1079 if(NS_SUCCEEDED(nsres
)) {
1080 const PRUnichar
*nstext
;
1083 nsAString_Init(&nsstr
, NULL
);
1084 nsnode_to_nsstring((nsIDOMNode
*)fragment
, &nsstr
);
1085 nsIDOMDocumentFragment_Release(fragment
);
1087 nsAString_GetData(&nsstr
, &nstext
);
1088 *p
= SysAllocString(nstext
);
1090 nsAString_Finish(&nsstr
);
1095 const WCHAR emptyW
[] = {0};
1096 *p
= SysAllocString(emptyW
);
1099 TRACE("return %s\n", debugstr_w(*p
));
1103 static HRESULT WINAPI
HTMLTxtRange_put_text(IHTMLTxtRange
*iface
, BSTR v
)
1105 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1106 nsIDOMDocument
*nsdoc
;
1107 nsIDOMText
*text_node
;
1111 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
1114 return MSHTML_E_NODOC
;
1116 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1117 if(NS_FAILED(nsres
)) {
1118 ERR("GetDocument failed: %08x\n", nsres
);
1122 nsAString_Init(&text_str
, v
);
1123 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &text_str
, &text_node
);
1124 nsIDOMDocument_Release(nsdoc
);
1125 nsAString_Finish(&text_str
);
1126 if(NS_FAILED(nsres
)) {
1127 ERR("CreateTextNode failed: %08x\n", nsres
);
1130 nsres
= nsIDOMRange_DeleteContents(This
->nsrange
);
1131 if(NS_FAILED(nsres
))
1132 ERR("DeleteContents failed: %08x\n", nsres
);
1134 nsres
= nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)text_node
);
1135 if(NS_FAILED(nsres
))
1136 ERR("InsertNode failed: %08x\n", nsres
);
1138 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, (nsIDOMNode
*)text_node
);
1139 if(NS_FAILED(nsres
))
1140 ERR("SetEndAfter failed: %08x\n", nsres
);
1142 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), VARIANT_FALSE
);
1145 static HRESULT WINAPI
HTMLTxtRange_get_text(IHTMLTxtRange
*iface
, BSTR
*p
)
1147 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1150 TRACE("(%p)->(%p)\n", This
, p
);
1157 range_to_string(This
, &buf
);
1159 *p
= SysAllocString(buf
.buf
);
1160 wstrbuf_finish(&buf
);
1162 TRACE("ret %s\n", debugstr_w(*p
));
1166 static HRESULT WINAPI
HTMLTxtRange_parentElement(IHTMLTxtRange
*iface
, IHTMLElement
**parent
)
1168 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1169 nsIDOMNode
*nsnode
, *tmp
;
1172 TRACE("(%p)->(%p)\n", This
, parent
);
1174 nsIDOMRange_GetCommonAncestorContainer(This
->nsrange
, &nsnode
);
1175 while(nsnode
&& get_node_type(nsnode
) != ELEMENT_NODE
) {
1176 nsIDOMNode_GetParentNode(nsnode
, &tmp
);
1177 nsIDOMNode_Release(nsnode
);
1186 node
= get_node(This
->doc
, nsnode
, TRUE
);
1187 nsIDOMNode_Release(nsnode
);
1189 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node
), &IID_IHTMLElement
, (void**)parent
);
1192 static HRESULT WINAPI
HTMLTxtRange_duplicate(IHTMLTxtRange
*iface
, IHTMLTxtRange
**Duplicate
)
1194 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1195 nsIDOMRange
*nsrange
= NULL
;
1197 TRACE("(%p)->(%p)\n", This
, Duplicate
);
1199 nsIDOMRange_CloneRange(This
->nsrange
, &nsrange
);
1200 *Duplicate
= HTMLTxtRange_Create(This
->doc
, nsrange
);
1201 nsIDOMRange_Release(nsrange
);
1206 static HRESULT WINAPI
HTMLTxtRange_inRange(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1207 VARIANT_BOOL
*InRange
)
1209 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1210 HTMLTxtRange
*src_range
;
1214 TRACE("(%p)->(%p %p)\n", This
, Range
, InRange
);
1216 *InRange
= VARIANT_FALSE
;
1218 src_range
= get_range_object(This
->doc
, Range
);
1222 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1223 src_range
->nsrange
, &nsret
);
1224 if(NS_SUCCEEDED(nsres
) && nsret
<= 0) {
1225 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1226 src_range
->nsrange
, &nsret
);
1227 if(NS_SUCCEEDED(nsres
) && nsret
>= 0)
1228 *InRange
= VARIANT_TRUE
;
1231 if(NS_FAILED(nsres
))
1232 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1237 static HRESULT WINAPI
HTMLTxtRange_isEqual(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1238 VARIANT_BOOL
*IsEqual
)
1240 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1241 HTMLTxtRange
*src_range
;
1245 TRACE("(%p)->(%p %p)\n", This
, Range
, IsEqual
);
1247 *IsEqual
= VARIANT_FALSE
;
1249 src_range
= get_range_object(This
->doc
, Range
);
1253 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1254 src_range
->nsrange
, &nsret
);
1255 if(NS_SUCCEEDED(nsres
) && !nsret
) {
1256 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1257 src_range
->nsrange
, &nsret
);
1258 if(NS_SUCCEEDED(nsres
) && !nsret
)
1259 *IsEqual
= VARIANT_TRUE
;
1262 if(NS_FAILED(nsres
))
1263 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1268 static HRESULT WINAPI
HTMLTxtRange_scrollIntoView(IHTMLTxtRange
*iface
, VARIANT_BOOL fStart
)
1270 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1271 FIXME("(%p)->(%x)\n", This
, fStart
);
1275 static HRESULT WINAPI
HTMLTxtRange_collapse(IHTMLTxtRange
*iface
, VARIANT_BOOL Start
)
1277 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1279 TRACE("(%p)->(%x)\n", This
, Start
);
1281 nsIDOMRange_Collapse(This
->nsrange
, Start
!= VARIANT_FALSE
);
1285 static HRESULT WINAPI
HTMLTxtRange_expand(IHTMLTxtRange
*iface
, BSTR Unit
, VARIANT_BOOL
*Success
)
1287 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1290 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(Unit
), Success
);
1292 unit
= string_to_unit(Unit
);
1293 if(unit
== RU_UNKNOWN
)
1294 return E_INVALIDARG
;
1296 *Success
= VARIANT_FALSE
;
1300 dompos_t end_pos
, start_pos
, new_start_pos
, new_end_pos
;
1303 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1305 get_cur_pos(This
, TRUE
, &start_pos
);
1306 get_cur_pos(This
, FALSE
, &end_pos
);
1308 if(find_word_end(&end_pos
, &new_end_pos
) || collapsed
) {
1309 set_range_pos(This
, FALSE
, &new_end_pos
);
1310 *Success
= VARIANT_TRUE
;
1313 if(start_pos
.type
&& (get_pos_char(&end_pos
) || !dompos_cmp(&new_end_pos
, &end_pos
))) {
1314 if(find_prev_space(This
, &start_pos
, TRUE
, &new_start_pos
)) {
1315 set_range_pos(This
, TRUE
, &new_start_pos
);
1316 *Success
= VARIANT_TRUE
;
1318 dompos_release(&new_start_pos
);
1321 dompos_release(&new_end_pos
);
1322 dompos_release(&end_pos
);
1323 dompos_release(&start_pos
);
1329 nsIDOMDocument
*nsdoc
;
1330 nsIDOMHTMLDocument
*nshtmldoc
;
1331 nsIDOMHTMLElement
*nsbody
= NULL
;
1334 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1335 if(NS_FAILED(nsres
) || !nsdoc
) {
1336 ERR("GetDocument failed: %08x\n", nsres
);
1340 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nshtmldoc
);
1341 nsIDOMDocument_Release(nsdoc
);
1343 nsres
= nsIDOMHTMLDocument_GetBody(nshtmldoc
, &nsbody
);
1344 nsIDOMHTMLDocument_Release(nshtmldoc
);
1345 if(NS_FAILED(nsres
) || !nsbody
) {
1346 ERR("Could not get body: %08x\n", nsres
);
1350 nsres
= nsIDOMRange_SelectNodeContents(This
->nsrange
, (nsIDOMNode
*)nsbody
);
1351 nsIDOMHTMLElement_Release(nsbody
);
1352 if(NS_FAILED(nsres
)) {
1353 ERR("Collapse failed: %08x\n", nsres
);
1357 *Success
= VARIANT_TRUE
;
1362 FIXME("Unimplemented unit %s\n", debugstr_w(Unit
));
1368 static HRESULT WINAPI
HTMLTxtRange_move(IHTMLTxtRange
*iface
, BSTR Unit
,
1369 long Count
, long *ActualCount
)
1371 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1374 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1376 unit
= string_to_unit(Unit
);
1377 if(unit
== RU_UNKNOWN
)
1378 return E_INVALIDARG
;
1382 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1387 dompos_t cur_pos
, new_pos
;
1389 get_cur_pos(This
, TRUE
, &cur_pos
);
1392 *ActualCount
= move_next_chars(Count
, &cur_pos
, TRUE
, NULL
, NULL
, &new_pos
);
1393 set_range_pos(This
, FALSE
, &new_pos
);
1394 dompos_release(&new_pos
);
1396 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1398 *ActualCount
= -move_prev_chars(This
, -Count
, &cur_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1399 set_range_pos(This
, TRUE
, &new_pos
);
1400 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1401 dompos_release(&new_pos
);
1404 dompos_release(&cur_pos
);
1409 dompos_t cur_pos
, new_pos
;
1411 get_cur_pos(This
, TRUE
, &cur_pos
);
1414 *ActualCount
= move_next_words(Count
, &cur_pos
, &new_pos
);
1415 set_range_pos(This
, FALSE
, &new_pos
);
1416 dompos_release(&new_pos
);
1417 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1419 *ActualCount
= -move_prev_words(This
, -Count
, &cur_pos
, &new_pos
);
1420 set_range_pos(This
, TRUE
, &new_pos
);
1421 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1422 dompos_release(&new_pos
);
1425 dompos_release(&cur_pos
);
1430 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1433 TRACE("ret %ld\n", *ActualCount
);
1437 static HRESULT WINAPI
HTMLTxtRange_moveStart(IHTMLTxtRange
*iface
, BSTR Unit
,
1438 long Count
, long *ActualCount
)
1440 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1443 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1445 unit
= string_to_unit(Unit
);
1446 if(unit
== RU_UNKNOWN
)
1447 return E_INVALIDARG
;
1456 dompos_t start_pos
, end_pos
, new_pos
;
1459 get_cur_pos(This
, TRUE
, &start_pos
);
1460 get_cur_pos(This
, FALSE
, &end_pos
);
1461 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1466 *ActualCount
= move_next_chars(Count
, &start_pos
, collapsed
, &end_pos
, &bounded
, &new_pos
);
1467 set_range_pos(This
, !bounded
, &new_pos
);
1469 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1471 *ActualCount
= -move_prev_chars(This
, -Count
, &start_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1472 set_range_pos(This
, TRUE
, &new_pos
);
1475 dompos_release(&start_pos
);
1476 dompos_release(&end_pos
);
1477 dompos_release(&new_pos
);
1482 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1488 static HRESULT WINAPI
HTMLTxtRange_moveEnd(IHTMLTxtRange
*iface
, BSTR Unit
,
1489 long Count
, long *ActualCount
)
1491 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1494 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1496 unit
= string_to_unit(Unit
);
1497 if(unit
== RU_UNKNOWN
)
1498 return E_INVALIDARG
;
1507 dompos_t start_pos
, end_pos
, new_pos
;
1510 get_cur_pos(This
, TRUE
, &start_pos
);
1511 get_cur_pos(This
, FALSE
, &end_pos
);
1512 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1515 *ActualCount
= move_next_chars(Count
, &end_pos
, collapsed
, NULL
, NULL
, &new_pos
);
1516 set_range_pos(This
, FALSE
, &new_pos
);
1520 *ActualCount
= -move_prev_chars(This
, -Count
, &end_pos
, TRUE
, &start_pos
, &bounded
, &new_pos
);
1521 set_range_pos(This
, bounded
, &new_pos
);
1523 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1526 dompos_release(&start_pos
);
1527 dompos_release(&end_pos
);
1528 dompos_release(&new_pos
);
1533 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1539 static HRESULT WINAPI
HTMLTxtRange_select(IHTMLTxtRange
*iface
)
1541 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1543 TRACE("(%p)\n", This
);
1545 if(This
->doc
->nscontainer
) {
1546 nsIDOMWindow
*dom_window
= NULL
;
1547 nsISelection
*nsselection
;
1549 nsIWebBrowser_GetContentDOMWindow(This
->doc
->nscontainer
->webbrowser
, &dom_window
);
1550 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
1551 nsIDOMWindow_Release(dom_window
);
1553 nsISelection_RemoveAllRanges(nsselection
);
1554 nsISelection_AddRange(nsselection
, This
->nsrange
);
1556 nsISelection_Release(nsselection
);
1562 static HRESULT WINAPI
HTMLTxtRange_pasteHTML(IHTMLTxtRange
*iface
, BSTR html
)
1564 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1565 FIXME("(%p)->(%s)\n", This
, debugstr_w(html
));
1569 static HRESULT WINAPI
HTMLTxtRange_moveToElementText(IHTMLTxtRange
*iface
, IHTMLElement
*element
)
1571 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1572 FIXME("(%p)->(%p)\n", This
, element
);
1576 static HRESULT WINAPI
HTMLTxtRange_setEndPoint(IHTMLTxtRange
*iface
, BSTR how
,
1577 IHTMLTxtRange
*SourceRange
)
1579 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1580 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(how
), SourceRange
);
1584 static HRESULT WINAPI
HTMLTxtRange_compareEndPoints(IHTMLTxtRange
*iface
, BSTR how
,
1585 IHTMLTxtRange
*SourceRange
, long *ret
)
1587 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1588 HTMLTxtRange
*src_range
;
1593 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(how
), SourceRange
, ret
);
1595 nscmpt
= string_to_nscmptype(how
);
1597 return E_INVALIDARG
;
1599 src_range
= get_range_object(This
->doc
, SourceRange
);
1603 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, nscmpt
, src_range
->nsrange
, &nsret
);
1604 if(NS_FAILED(nsres
))
1605 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1611 static HRESULT WINAPI
HTMLTxtRange_findText(IHTMLTxtRange
*iface
, BSTR String
,
1612 long count
, long Flags
, VARIANT_BOOL
*Success
)
1614 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1615 FIXME("(%p)->(%s %ld %08lx %p)\n", This
, debugstr_w(String
), count
, Flags
, Success
);
1619 static HRESULT WINAPI
HTMLTxtRange_moveToPoint(IHTMLTxtRange
*iface
, long x
, long y
)
1621 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1622 FIXME("(%p)->(%ld %ld)\n", This
, x
, y
);
1626 static HRESULT WINAPI
HTMLTxtRange_getBookmark(IHTMLTxtRange
*iface
, BSTR
*Bookmark
)
1628 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1629 FIXME("(%p)->(%p)\n", This
, Bookmark
);
1633 static HRESULT WINAPI
HTMLTxtRange_moveToBookmark(IHTMLTxtRange
*iface
, BSTR Bookmark
,
1634 VARIANT_BOOL
*Success
)
1636 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1637 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(Bookmark
), Success
);
1641 static HRESULT WINAPI
HTMLTxtRange_queryCommandSupported(IHTMLTxtRange
*iface
, BSTR cmdID
,
1642 VARIANT_BOOL
*pfRet
)
1644 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1645 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1649 static HRESULT WINAPI
HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange
*iface
, BSTR cmdID
,
1650 VARIANT_BOOL
*pfRet
)
1652 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1653 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1657 static HRESULT WINAPI
HTMLTxtRange_queryCommandState(IHTMLTxtRange
*iface
, BSTR cmdID
,
1658 VARIANT_BOOL
*pfRet
)
1660 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1661 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1665 static HRESULT WINAPI
HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange
*iface
, BSTR cmdID
,
1666 VARIANT_BOOL
*pfRet
)
1668 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1669 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1673 static HRESULT WINAPI
HTMLTxtRange_queryCommandText(IHTMLTxtRange
*iface
, BSTR cmdID
,
1676 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1677 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdText
);
1681 static HRESULT WINAPI
HTMLTxtRange_queryCommandValue(IHTMLTxtRange
*iface
, BSTR cmdID
,
1684 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1685 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdValue
);
1689 static HRESULT WINAPI
HTMLTxtRange_execCommand(IHTMLTxtRange
*iface
, BSTR cmdID
,
1690 VARIANT_BOOL showUI
, VARIANT value
, VARIANT_BOOL
*pfRet
)
1692 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1693 FIXME("(%p)->(%s %x v %p)\n", This
, debugstr_w(cmdID
), showUI
, pfRet
);
1697 static HRESULT WINAPI
HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange
*iface
, BSTR cmdID
,
1698 VARIANT_BOOL
*pfRet
)
1700 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1701 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1705 #undef HTMLTXTRANGE_THIS
1707 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl
= {
1708 HTMLTxtRange_QueryInterface
,
1709 HTMLTxtRange_AddRef
,
1710 HTMLTxtRange_Release
,
1711 HTMLTxtRange_GetTypeInfoCount
,
1712 HTMLTxtRange_GetTypeInfo
,
1713 HTMLTxtRange_GetIDsOfNames
,
1714 HTMLTxtRange_Invoke
,
1715 HTMLTxtRange_get_htmlText
,
1716 HTMLTxtRange_put_text
,
1717 HTMLTxtRange_get_text
,
1718 HTMLTxtRange_parentElement
,
1719 HTMLTxtRange_duplicate
,
1720 HTMLTxtRange_inRange
,
1721 HTMLTxtRange_isEqual
,
1722 HTMLTxtRange_scrollIntoView
,
1723 HTMLTxtRange_collapse
,
1724 HTMLTxtRange_expand
,
1726 HTMLTxtRange_moveStart
,
1727 HTMLTxtRange_moveEnd
,
1728 HTMLTxtRange_select
,
1729 HTMLTxtRange_pasteHTML
,
1730 HTMLTxtRange_moveToElementText
,
1731 HTMLTxtRange_setEndPoint
,
1732 HTMLTxtRange_compareEndPoints
,
1733 HTMLTxtRange_findText
,
1734 HTMLTxtRange_moveToPoint
,
1735 HTMLTxtRange_getBookmark
,
1736 HTMLTxtRange_moveToBookmark
,
1737 HTMLTxtRange_queryCommandSupported
,
1738 HTMLTxtRange_queryCommandEnabled
,
1739 HTMLTxtRange_queryCommandState
,
1740 HTMLTxtRange_queryCommandIndeterm
,
1741 HTMLTxtRange_queryCommandText
,
1742 HTMLTxtRange_queryCommandValue
,
1743 HTMLTxtRange_execCommand
,
1744 HTMLTxtRange_execCommandShowHelp
1747 #define OLECMDTRG_THIS(iface) DEFINE_THIS(HTMLTxtRange, OleCommandTarget, iface)
1749 static HRESULT WINAPI
RangeCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
1751 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1752 return IHTMLTxtRange_QueryInterface(HTMLTXTRANGE(This
), riid
, ppv
);
1755 static ULONG WINAPI
RangeCommandTarget_AddRef(IOleCommandTarget
*iface
)
1757 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1758 return IHTMLTxtRange_AddRef(HTMLTXTRANGE(This
));
1761 static ULONG WINAPI
RangeCommandTarget_Release(IOleCommandTarget
*iface
)
1763 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1764 return IHTMLTxtRange_Release(HTMLTXTRANGE(This
));
1767 static HRESULT WINAPI
RangeCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1768 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
1770 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1771 FIXME("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
1775 static HRESULT
exec_indent(HTMLTxtRange
*This
, VARIANT
*in
, VARIANT
*out
)
1777 nsIDOMDocumentFragment
*fragment
;
1778 nsIDOMElement
*blockquote_elem
, *p_elem
;
1779 nsIDOMDocument
*nsdoc
;
1783 static const PRUnichar blockquoteW
[] = {'B','L','O','C','K','Q','U','O','T','E',0};
1784 static const PRUnichar pW
[] = {'P',0};
1786 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
1788 nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1790 nsAString_Init(&tag_str
, blockquoteW
);
1791 nsIDOMDocument_CreateElement(nsdoc
, &tag_str
, &blockquote_elem
);
1792 nsAString_Finish(&tag_str
);
1794 nsAString_Init(&tag_str
, pW
);
1795 nsIDOMDocument_CreateElement(nsdoc
, &tag_str
, &p_elem
);
1796 nsAString_Finish(&tag_str
);
1798 nsIDOMDocument_Release(nsdoc
);
1800 nsIDOMRange_ExtractContents(This
->nsrange
, &fragment
);
1801 nsIDOMElement_AppendChild(p_elem
, (nsIDOMNode
*)fragment
, &tmp
);
1802 nsIDOMDocumentFragment_Release(fragment
);
1803 nsIDOMNode_Release(tmp
);
1805 nsIDOMElement_AppendChild(blockquote_elem
, (nsIDOMNode
*)p_elem
, &tmp
);
1806 nsIDOMElement_Release(p_elem
);
1807 nsIDOMNode_Release(tmp
);
1809 nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)blockquote_elem
);
1810 nsIDOMElement_Release(blockquote_elem
);
1815 static HRESULT WINAPI
RangeCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1816 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
1818 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1820 TRACE("(%p)->(%s %d %x %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
,
1821 nCmdexecopt
, pvaIn
, pvaOut
);
1823 if(pguidCmdGroup
&& IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
1826 return exec_indent(This
, pvaIn
, pvaOut
);
1828 FIXME("Unsupported cmdid %d of CGID_MSHTML\n", nCmdID
);
1831 FIXME("Unsupported cmd %d of group %s\n", nCmdID
, debugstr_guid(pguidCmdGroup
));
1837 #undef OLECMDTRG_THIS
1839 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
1840 RangeCommandTarget_QueryInterface
,
1841 RangeCommandTarget_AddRef
,
1842 RangeCommandTarget_Release
,
1843 RangeCommandTarget_QueryStatus
,
1844 RangeCommandTarget_Exec
1847 IHTMLTxtRange
*HTMLTxtRange_Create(HTMLDocument
*doc
, nsIDOMRange
*nsrange
)
1849 HTMLTxtRange
*ret
= heap_alloc(sizeof(HTMLTxtRange
));
1851 ret
->lpHTMLTxtRangeVtbl
= &HTMLTxtRangeVtbl
;
1852 ret
->lpOleCommandTargetVtbl
= &OleCommandTargetVtbl
;
1856 nsIDOMRange_AddRef(nsrange
);
1857 ret
->nsrange
= nsrange
;
1860 list_add_head(&doc
->range_list
, &ret
->entry
);
1862 return HTMLTXTRANGE(ret
);
1865 void detach_ranges(HTMLDocument
*This
)
1869 LIST_FOR_EACH_ENTRY(iter
, &This
->range_list
, HTMLTxtRange
, entry
) {