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 void wstrbuf_append_nodetxt(wstrbuf_t
*buf
, LPCWSTR str
, int len
)
207 const WCHAR
*s
= str
;
210 TRACE("%s\n", debugstr_wn(str
, len
));
212 if(buf
->len
+len
>= buf
->size
) {
213 buf
->size
= 2*buf
->len
+len
;
214 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
* sizeof(WCHAR
));
217 if(buf
->len
&& isspaceW(buf
->buf
[buf
->len
-1])) {
218 while(s
< str
+len
&& isspaceW(*s
))
222 d
= buf
->buf
+buf
->len
;
227 while(s
< str
+len
&& isspaceW(*s
))
234 buf
->len
= d
- buf
->buf
;
238 static void wstrbuf_append_node(wstrbuf_t
*buf
, nsIDOMNode
*node
)
241 switch(get_node_type(node
)) {
245 const PRUnichar
*data
;
247 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMText
, (void**)&nstext
);
249 nsAString_Init(&data_str
, NULL
);
250 nsIDOMText_GetData(nstext
, &data_str
);
251 nsAString_GetData(&data_str
, &data
);
252 wstrbuf_append_nodetxt(buf
, data
, strlenW(data
));
253 nsAString_Finish(&data_str
);
255 nsIDOMText_Release(nstext
);
260 if(is_elem_tag(node
, brW
)) {
261 static const WCHAR endlW
[] = {'\r','\n'};
262 wstrbuf_append_len(buf
, endlW
, 2);
263 }else if(is_elem_tag(node
, hrW
)) {
264 static const WCHAR endl2W
[] = {'\r','\n','\r','\n'};
265 wstrbuf_append_len(buf
, endl2W
, 4);
270 static BOOL
fill_nodestr(dompos_t
*pos
)
275 if(pos
->type
!= TEXT_NODE
)
278 nsres
= nsIDOMNode_QueryInterface(pos
->node
, &IID_nsIDOMText
, (void**)&text
);
282 nsAString_Init(&pos
->str
, NULL
);
283 nsIDOMText_GetData(text
, &pos
->str
);
284 nsIDOMText_Release(text
);
285 nsAString_GetData(&pos
->str
, &pos
->p
);
288 pos
->off
= *pos
->p
? strlenW(pos
->p
)-1 : 0;
293 static nsIDOMNode
*next_node(nsIDOMNode
*iter
)
295 nsIDOMNode
*ret
, *tmp
;
301 nsres
= nsIDOMNode_GetFirstChild(iter
, &ret
);
302 if(NS_SUCCEEDED(nsres
) && ret
)
305 nsIDOMNode_AddRef(iter
);
308 nsres
= nsIDOMNode_GetNextSibling(iter
, &ret
);
309 if(NS_SUCCEEDED(nsres
) && ret
) {
310 nsIDOMNode_Release(iter
);
314 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
315 nsIDOMNode_Release(iter
);
317 }while(NS_SUCCEEDED(nsres
) && iter
);
322 static nsIDOMNode
*prev_node(HTMLTxtRange
*This
, nsIDOMNode
*iter
)
324 nsIDOMNode
*ret
, *tmp
;
328 nsIDOMHTMLElement
*nselem
;
330 nsIDOMHTMLDocument_GetBody(This
->doc
->nsdoc
, &nselem
);
331 nsIDOMElement_GetLastChild(nselem
, &tmp
);
333 return (nsIDOMNode
*)nselem
;
337 nsIDOMNode_GetLastChild(ret
, &tmp
);
340 nsIDOMElement_Release(nselem
);
345 nsres
= nsIDOMNode_GetLastChild(iter
, &ret
);
346 if(NS_SUCCEEDED(nsres
) && ret
)
349 nsIDOMNode_AddRef(iter
);
352 nsres
= nsIDOMNode_GetPreviousSibling(iter
, &ret
);
353 if(NS_SUCCEEDED(nsres
) && ret
) {
354 nsIDOMNode_Release(iter
);
358 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
359 nsIDOMNode_Release(iter
);
361 }while(NS_SUCCEEDED(nsres
) && iter
);
366 static nsIDOMNode
*get_child_node(nsIDOMNode
*node
, PRUint32 off
)
368 nsIDOMNodeList
*node_list
;
369 nsIDOMNode
*ret
= NULL
;
371 nsIDOMNode_GetChildNodes(node
, &node_list
);
372 nsIDOMNodeList_Item(node_list
, off
, &ret
);
373 nsIDOMNodeList_Release(node_list
);
378 static void get_cur_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
387 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
392 nsIDOMRange_GetStartContainer(This
->nsrange
, &node
);
393 nsIDOMRange_GetStartOffset(This
->nsrange
, &off
);
395 nsIDOMRange_GetEndContainer(This
->nsrange
, &node
);
396 nsIDOMRange_GetEndOffset(This
->nsrange
, &off
);
399 pos
->type
= get_node_type(node
);
400 if(pos
->type
== ELEMENT_NODE
) {
402 pos
->node
= get_child_node(node
, off
);
405 pos
->node
= off
? get_child_node(node
, off
-1) : prev_node(This
, node
);
409 pos
->type
= get_node_type(pos
->node
);
410 nsIDOMNode_Release(node
);
418 pos
->node
= prev_node(This
, node
);
420 nsIDOMNode_Release(node
);
423 if(pos
->type
== TEXT_NODE
)
427 static void set_range_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
432 if(pos
->type
== TEXT_NODE
)
433 nsres
= nsIDOMRange_SetStart(This
->nsrange
, pos
->node
, pos
->off
);
435 nsres
= nsIDOMRange_SetStartBefore(This
->nsrange
, pos
->node
);
437 if(pos
->type
== TEXT_NODE
&& pos
->p
[pos
->off
+1])
438 nsres
= nsIDOMRange_SetEnd(This
->nsrange
, pos
->node
, pos
->off
+1);
440 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, pos
->node
);
444 ERR("failed: %p %08x\n", pos
->node
, nsres
);
447 static inline void dompos_release(dompos_t
*pos
)
450 nsIDOMNode_Release(pos
->node
);
453 nsAString_Finish(&pos
->str
);
456 static inline void dompos_addref(dompos_t
*pos
)
459 nsIDOMNode_AddRef(pos
->node
);
461 if(pos
->type
== TEXT_NODE
)
465 static inline BOOL
dompos_cmp(const dompos_t
*pos1
, const dompos_t
*pos2
)
467 return pos1
->node
== pos2
->node
&& pos1
->off
== pos2
->off
;
470 static void range_to_string(HTMLTxtRange
*This
, wstrbuf_t
*buf
)
472 nsIDOMNode
*iter
, *tmp
;
473 dompos_t start_pos
, end_pos
;
476 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
484 get_cur_pos(This
, FALSE
, &end_pos
);
485 get_cur_pos(This
, TRUE
, &start_pos
);
487 if(start_pos
.type
== TEXT_NODE
) {
488 if(start_pos
.node
== end_pos
.node
) {
489 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, end_pos
.off
-start_pos
.off
+1);
490 iter
= start_pos
.node
;
491 nsIDOMNode_AddRef(iter
);
493 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, strlenW(start_pos
.p
+start_pos
.off
));
494 iter
= next_node(start_pos
.node
);
497 iter
= start_pos
.node
;
498 nsIDOMNode_AddRef(iter
);
501 while(iter
!= end_pos
.node
) {
502 wstrbuf_append_node(buf
, iter
);
503 tmp
= next_node(iter
);
504 nsIDOMNode_Release(iter
);
508 nsIDOMNode_AddRef(end_pos
.node
);
510 if(start_pos
.node
!= end_pos
.node
) {
511 if(end_pos
.type
== TEXT_NODE
)
512 wstrbuf_append_nodetxt(buf
, end_pos
.p
, end_pos
.off
+1);
514 wstrbuf_append_node(buf
, end_pos
.node
);
517 nsIDOMNode_Release(iter
);
518 dompos_release(&start_pos
);
519 dompos_release(&end_pos
);
524 for(p
= buf
->buf
+buf
->len
-1; p
>= buf
->buf
&& isspaceW(*p
); p
--);
526 p
= strchrW(p
, '\r');
532 static WCHAR
get_pos_char(const dompos_t
*pos
)
536 return pos
->p
[pos
->off
];
538 if(is_space_elem(pos
->node
))
545 static void end_space(const dompos_t
*pos
, dompos_t
*new_pos
)
550 dompos_addref(new_pos
);
552 if(pos
->type
!= TEXT_NODE
)
555 p
= new_pos
->p
+new_pos
->off
;
557 if(!*p
|| !isspace(*p
))
560 while(p
[1] && isspace(p
[1]))
563 new_pos
->off
= p
- new_pos
->p
;
566 static WCHAR
next_char(const dompos_t
*pos
, dompos_t
*new_pos
)
568 nsIDOMNode
*iter
, *tmp
;
569 dompos_t last_space
, tmp_pos
;
573 if(pos
->type
== TEXT_NODE
&& pos
->off
!= -1 && pos
->p
[pos
->off
]) {
577 while(isspaceW(*++p
));
581 if(*p
&& isspaceW(*p
)) {
583 while(p
[1] && isspaceW(p
[1]))
589 new_pos
->off
= p
- pos
->p
;
590 dompos_addref(new_pos
);
592 return cspace
? cspace
: *p
;
595 last_space
.off
= p
- pos
->p
;
596 dompos_addref(&last_space
);
600 iter
= next_node(pos
->node
);
603 switch(get_node_type(iter
)) {
606 tmp_pos
.type
= TEXT_NODE
;
608 dompos_addref(&tmp_pos
);
613 dompos_release(&tmp_pos
);
615 }else if(isspaceW(*p
)) {
617 dompos_release(&last_space
);
621 while(p
[1] && isspaceW(p
[1]))
624 tmp_pos
.off
= p
-tmp_pos
.p
;
627 last_space
= tmp_pos
;
632 nsIDOMNode_Release(iter
);
635 *new_pos
= last_space
;
636 dompos_release(&tmp_pos
);
637 nsIDOMNode_Release(iter
);
645 nsIDOMNode_Release(iter
);
649 if(is_elem_tag(iter
, brW
)) {
651 dompos_release(&last_space
);
654 nsIDOMNode_AddRef(iter
);
655 last_space
.node
= iter
;
656 last_space
.type
= ELEMENT_NODE
;
659 }else if(is_elem_tag(iter
, hrW
)) {
661 *new_pos
= last_space
;
662 nsIDOMNode_Release(iter
);
666 new_pos
->node
= iter
;
667 new_pos
->type
= ELEMENT_NODE
;
675 iter
= next_node(iter
);
676 nsIDOMNode_Release(tmp
);
680 *new_pos
= last_space
;
683 dompos_addref(new_pos
);
689 static WCHAR
prev_char(HTMLTxtRange
*This
, const dompos_t
*pos
, dompos_t
*new_pos
)
691 nsIDOMNode
*iter
, *tmp
;
693 BOOL skip_space
= FALSE
;
695 if(pos
->type
== TEXT_NODE
&& isspaceW(pos
->p
[pos
->off
]))
698 if(pos
->type
== TEXT_NODE
&& pos
->off
) {
699 p
= pos
->p
+pos
->off
-1;
702 while(p
>= pos
->p
&& isspace(*p
))
708 new_pos
->off
= p
-pos
->p
;
709 dompos_addref(new_pos
);
710 return new_pos
->p
[new_pos
->off
];
714 iter
= prev_node(This
, pos
->node
);
717 switch(get_node_type(iter
)) {
722 tmp_pos
.type
= TEXT_NODE
;
724 dompos_addref(&tmp_pos
);
726 p
= tmp_pos
.p
+ strlenW(tmp_pos
.p
)-1;
729 while(p
>= tmp_pos
.p
&& isspaceW(*p
))
734 dompos_release(&tmp_pos
);
738 tmp_pos
.off
= p
-tmp_pos
.p
;
740 nsIDOMNode_Release(iter
);
745 if(is_elem_tag(iter
, brW
)) {
750 }else if(!is_elem_tag(iter
, hrW
)) {
754 new_pos
->node
= iter
;
755 new_pos
->type
= ELEMENT_NODE
;
762 iter
= prev_node(This
, iter
);
763 nsIDOMNode_Release(tmp
);
767 dompos_addref(new_pos
);
771 static long move_next_chars(long cnt
, const dompos_t
*pos
, BOOL col
, const dompos_t
*bound_pos
,
772 BOOL
*bounded
, dompos_t
*new_pos
)
785 end_space(pos
, new_pos
);
789 c
= next_char(pos
, &iter
);
794 c
= next_char(&tmp
, &iter
);
795 dompos_release(&tmp
);
800 if(bound_pos
&& dompos_cmp(&tmp
, bound_pos
)) {
810 static long move_prev_chars(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, BOOL end
,
811 const dompos_t
*bound_pos
, BOOL
*bounded
, dompos_t
*new_pos
)
815 BOOL prev_eq
= FALSE
;
821 c
= prev_char(This
, pos
, &iter
);
825 while(c
&& ret
< cnt
) {
827 c
= prev_char(This
, &tmp
, &iter
);
828 dompos_release(&tmp
);
842 prev_eq
= bound_pos
&& dompos_cmp(&iter
, bound_pos
);
849 static long find_prev_space(HTMLTxtRange
*This
, const dompos_t
*pos
, BOOL first_space
, dompos_t
*ret
)
854 c
= prev_char(This
, pos
, &iter
);
855 if(!c
|| (first_space
&& isspaceW(c
))) {
862 c
= prev_char(This
, &tmp
, &iter
);
863 if(!c
|| isspaceW(c
)) {
864 dompos_release(&iter
);
867 dompos_release(&tmp
);
874 static int find_word_end(const dompos_t
*pos
, dompos_t
*ret
)
879 c
= get_pos_char(pos
);
886 c
= next_char(pos
, &iter
);
897 while(c
&& !isspaceW(c
)) {
899 c
= next_char(&tmp
, &iter
);
901 dompos_release(&iter
);
905 dompos_release(&tmp
);
913 static long move_next_words(long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
919 c
= get_pos_char(pos
);
921 end_space(pos
, &iter
);
924 c
= next_char(pos
, &iter
);
929 while(c
&& ret
< cnt
) {
931 c
= next_char(&tmp
, &iter
);
932 dompos_release(&tmp
);
941 static long move_prev_words(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
947 dompos_addref(&iter
);
950 if(!find_prev_space(This
, &iter
, FALSE
, &tmp
))
953 dompos_release(&iter
);
962 #define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
964 static HRESULT WINAPI
HTMLTxtRange_QueryInterface(IHTMLTxtRange
*iface
, REFIID riid
, void **ppv
)
966 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
970 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
971 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
972 *ppv
= HTMLTXTRANGE(This
);
973 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
974 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
975 *ppv
= HTMLTXTRANGE(This
);
976 }else if(IsEqualGUID(&IID_IHTMLTxtRange
, riid
)) {
977 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This
, ppv
);
978 *ppv
= HTMLTXTRANGE(This
);
979 }else if(IsEqualGUID(&IID_IOleCommandTarget
, riid
)) {
980 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This
, ppv
);
981 *ppv
= CMDTARGET(This
);
985 IUnknown_AddRef((IUnknown
*)*ppv
);
989 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
990 return E_NOINTERFACE
;
993 static ULONG WINAPI
HTMLTxtRange_AddRef(IHTMLTxtRange
*iface
)
995 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
996 LONG ref
= InterlockedIncrement(&This
->ref
);
998 TRACE("(%p) ref=%d\n", This
, ref
);
1003 static ULONG WINAPI
HTMLTxtRange_Release(IHTMLTxtRange
*iface
)
1005 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1006 LONG ref
= InterlockedDecrement(&This
->ref
);
1008 TRACE("(%p) ref=%d\n", This
, ref
);
1012 nsISelection_Release(This
->nsrange
);
1014 list_remove(&This
->entry
);
1021 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange
*iface
, UINT
*pctinfo
)
1023 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1024 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1028 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfo(IHTMLTxtRange
*iface
, UINT iTInfo
,
1029 LCID lcid
, ITypeInfo
**ppTInfo
)
1031 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1032 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1036 static HRESULT WINAPI
HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange
*iface
, REFIID riid
,
1037 LPOLESTR
*rgszNames
, UINT cNames
,
1038 LCID lcid
, DISPID
*rgDispId
)
1040 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1041 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1046 static HRESULT WINAPI
HTMLTxtRange_Invoke(IHTMLTxtRange
*iface
, DISPID dispIdMember
,
1047 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1048 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1050 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1051 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1052 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1056 static HRESULT WINAPI
HTMLTxtRange_get_htmlText(IHTMLTxtRange
*iface
, BSTR
*p
)
1058 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1060 TRACE("(%p)->(%p)\n", This
, p
);
1065 nsIDOMDocumentFragment
*fragment
;
1068 nsres
= nsIDOMRange_CloneContents(This
->nsrange
, &fragment
);
1069 if(NS_SUCCEEDED(nsres
)) {
1070 const PRUnichar
*nstext
;
1073 nsAString_Init(&nsstr
, NULL
);
1074 nsnode_to_nsstring((nsIDOMNode
*)fragment
, &nsstr
);
1075 nsIDOMDocumentFragment_Release(fragment
);
1077 nsAString_GetData(&nsstr
, &nstext
);
1078 *p
= SysAllocString(nstext
);
1080 nsAString_Finish(&nsstr
);
1085 const WCHAR emptyW
[] = {0};
1086 *p
= SysAllocString(emptyW
);
1089 TRACE("return %s\n", debugstr_w(*p
));
1093 static HRESULT WINAPI
HTMLTxtRange_put_text(IHTMLTxtRange
*iface
, BSTR v
)
1095 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1096 nsIDOMText
*text_node
;
1100 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
1103 return MSHTML_E_NODOC
;
1105 nsAString_Init(&text_str
, v
);
1106 nsres
= nsIDOMHTMLDocument_CreateTextNode(This
->doc
->nsdoc
, &text_str
, &text_node
);
1107 nsAString_Finish(&text_str
);
1108 if(NS_FAILED(nsres
)) {
1109 ERR("CreateTextNode failed: %08x\n", nsres
);
1112 nsres
= nsIDOMRange_DeleteContents(This
->nsrange
);
1113 if(NS_FAILED(nsres
))
1114 ERR("DeleteContents failed: %08x\n", nsres
);
1116 nsres
= nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)text_node
);
1117 if(NS_FAILED(nsres
))
1118 ERR("InsertNode failed: %08x\n", nsres
);
1120 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, (nsIDOMNode
*)text_node
);
1121 if(NS_FAILED(nsres
))
1122 ERR("SetEndAfter failed: %08x\n", nsres
);
1124 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), VARIANT_FALSE
);
1127 static HRESULT WINAPI
HTMLTxtRange_get_text(IHTMLTxtRange
*iface
, BSTR
*p
)
1129 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1132 TRACE("(%p)->(%p)\n", This
, p
);
1139 range_to_string(This
, &buf
);
1141 *p
= SysAllocString(buf
.buf
);
1142 wstrbuf_finish(&buf
);
1144 TRACE("ret %s\n", debugstr_w(*p
));
1148 static HRESULT WINAPI
HTMLTxtRange_parentElement(IHTMLTxtRange
*iface
, IHTMLElement
**parent
)
1150 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1151 nsIDOMNode
*nsnode
, *tmp
;
1154 TRACE("(%p)->(%p)\n", This
, parent
);
1156 nsIDOMRange_GetCommonAncestorContainer(This
->nsrange
, &nsnode
);
1157 while(nsnode
&& get_node_type(nsnode
) != ELEMENT_NODE
) {
1158 nsIDOMNode_GetParentNode(nsnode
, &tmp
);
1159 nsIDOMNode_Release(nsnode
);
1168 node
= get_node(This
->doc
, nsnode
, TRUE
);
1169 nsIDOMNode_Release(nsnode
);
1171 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node
), &IID_IHTMLElement
, (void**)parent
);
1174 static HRESULT WINAPI
HTMLTxtRange_duplicate(IHTMLTxtRange
*iface
, IHTMLTxtRange
**Duplicate
)
1176 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1177 nsIDOMRange
*nsrange
= NULL
;
1179 TRACE("(%p)->(%p)\n", This
, Duplicate
);
1181 nsIDOMRange_CloneRange(This
->nsrange
, &nsrange
);
1182 *Duplicate
= HTMLTxtRange_Create(This
->doc
, nsrange
);
1183 nsIDOMRange_Release(nsrange
);
1188 static HRESULT WINAPI
HTMLTxtRange_inRange(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1189 VARIANT_BOOL
*InRange
)
1191 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1192 HTMLTxtRange
*src_range
;
1196 TRACE("(%p)->(%p %p)\n", This
, Range
, InRange
);
1198 *InRange
= VARIANT_FALSE
;
1200 src_range
= get_range_object(This
->doc
, Range
);
1204 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1205 src_range
->nsrange
, &nsret
);
1206 if(NS_SUCCEEDED(nsres
) && nsret
<= 0) {
1207 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1208 src_range
->nsrange
, &nsret
);
1209 if(NS_SUCCEEDED(nsres
) && nsret
>= 0)
1210 *InRange
= VARIANT_TRUE
;
1213 if(NS_FAILED(nsres
))
1214 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1219 static HRESULT WINAPI
HTMLTxtRange_isEqual(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1220 VARIANT_BOOL
*IsEqual
)
1222 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1223 HTMLTxtRange
*src_range
;
1227 TRACE("(%p)->(%p %p)\n", This
, Range
, IsEqual
);
1229 *IsEqual
= VARIANT_FALSE
;
1231 src_range
= get_range_object(This
->doc
, Range
);
1235 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1236 src_range
->nsrange
, &nsret
);
1237 if(NS_SUCCEEDED(nsres
) && !nsret
) {
1238 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1239 src_range
->nsrange
, &nsret
);
1240 if(NS_SUCCEEDED(nsres
) && !nsret
)
1241 *IsEqual
= VARIANT_TRUE
;
1244 if(NS_FAILED(nsres
))
1245 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1250 static HRESULT WINAPI
HTMLTxtRange_scrollIntoView(IHTMLTxtRange
*iface
, VARIANT_BOOL fStart
)
1252 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1253 FIXME("(%p)->(%x)\n", This
, fStart
);
1257 static HRESULT WINAPI
HTMLTxtRange_collapse(IHTMLTxtRange
*iface
, VARIANT_BOOL Start
)
1259 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1261 TRACE("(%p)->(%x)\n", This
, Start
);
1263 nsIDOMRange_Collapse(This
->nsrange
, Start
!= VARIANT_FALSE
);
1267 static HRESULT WINAPI
HTMLTxtRange_expand(IHTMLTxtRange
*iface
, BSTR Unit
, VARIANT_BOOL
*Success
)
1269 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1272 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(Unit
), Success
);
1274 unit
= string_to_unit(Unit
);
1275 if(unit
== RU_UNKNOWN
)
1276 return E_INVALIDARG
;
1278 *Success
= VARIANT_FALSE
;
1282 dompos_t end_pos
, start_pos
, new_start_pos
, new_end_pos
;
1285 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1287 get_cur_pos(This
, TRUE
, &start_pos
);
1288 get_cur_pos(This
, FALSE
, &end_pos
);
1290 if(find_word_end(&end_pos
, &new_end_pos
) || collapsed
) {
1291 set_range_pos(This
, FALSE
, &new_end_pos
);
1292 *Success
= VARIANT_TRUE
;
1295 if(start_pos
.type
&& (get_pos_char(&end_pos
) || !dompos_cmp(&new_end_pos
, &end_pos
))) {
1296 if(find_prev_space(This
, &start_pos
, TRUE
, &new_start_pos
)) {
1297 set_range_pos(This
, TRUE
, &new_start_pos
);
1298 *Success
= VARIANT_TRUE
;
1300 dompos_release(&new_start_pos
);
1303 dompos_release(&new_end_pos
);
1304 dompos_release(&end_pos
);
1305 dompos_release(&start_pos
);
1311 nsIDOMHTMLElement
*nsbody
= NULL
;
1314 nsres
= nsIDOMHTMLDocument_GetBody(This
->doc
->nsdoc
, &nsbody
);
1315 if(NS_FAILED(nsres
) || !nsbody
) {
1316 ERR("Could not get body: %08x\n", nsres
);
1320 nsres
= nsIDOMRange_SelectNodeContents(This
->nsrange
, (nsIDOMNode
*)nsbody
);
1321 nsIDOMHTMLElement_Release(nsbody
);
1322 if(NS_FAILED(nsres
)) {
1323 ERR("Collapse failed: %08x\n", nsres
);
1327 *Success
= VARIANT_TRUE
;
1332 FIXME("Unimplemented unit %s\n", debugstr_w(Unit
));
1338 static HRESULT WINAPI
HTMLTxtRange_move(IHTMLTxtRange
*iface
, BSTR Unit
,
1339 long Count
, long *ActualCount
)
1341 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1344 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1346 unit
= string_to_unit(Unit
);
1347 if(unit
== RU_UNKNOWN
)
1348 return E_INVALIDARG
;
1352 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1357 dompos_t cur_pos
, new_pos
;
1359 get_cur_pos(This
, TRUE
, &cur_pos
);
1362 *ActualCount
= move_next_chars(Count
, &cur_pos
, TRUE
, NULL
, NULL
, &new_pos
);
1363 set_range_pos(This
, FALSE
, &new_pos
);
1364 dompos_release(&new_pos
);
1366 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1368 *ActualCount
= -move_prev_chars(This
, -Count
, &cur_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1369 set_range_pos(This
, TRUE
, &new_pos
);
1370 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1371 dompos_release(&new_pos
);
1374 dompos_release(&cur_pos
);
1379 dompos_t cur_pos
, new_pos
;
1381 get_cur_pos(This
, TRUE
, &cur_pos
);
1384 *ActualCount
= move_next_words(Count
, &cur_pos
, &new_pos
);
1385 set_range_pos(This
, FALSE
, &new_pos
);
1386 dompos_release(&new_pos
);
1387 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1389 *ActualCount
= -move_prev_words(This
, -Count
, &cur_pos
, &new_pos
);
1390 set_range_pos(This
, TRUE
, &new_pos
);
1391 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1392 dompos_release(&new_pos
);
1395 dompos_release(&cur_pos
);
1400 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1403 TRACE("ret %ld\n", *ActualCount
);
1407 static HRESULT WINAPI
HTMLTxtRange_moveStart(IHTMLTxtRange
*iface
, BSTR Unit
,
1408 long Count
, long *ActualCount
)
1410 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1413 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1415 unit
= string_to_unit(Unit
);
1416 if(unit
== RU_UNKNOWN
)
1417 return E_INVALIDARG
;
1426 dompos_t start_pos
, end_pos
, new_pos
;
1429 get_cur_pos(This
, TRUE
, &start_pos
);
1430 get_cur_pos(This
, FALSE
, &end_pos
);
1431 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1436 *ActualCount
= move_next_chars(Count
, &start_pos
, collapsed
, &end_pos
, &bounded
, &new_pos
);
1437 set_range_pos(This
, !bounded
, &new_pos
);
1439 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1441 *ActualCount
= -move_prev_chars(This
, -Count
, &start_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1442 set_range_pos(This
, TRUE
, &new_pos
);
1445 dompos_release(&start_pos
);
1446 dompos_release(&end_pos
);
1447 dompos_release(&new_pos
);
1452 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1458 static HRESULT WINAPI
HTMLTxtRange_moveEnd(IHTMLTxtRange
*iface
, BSTR Unit
,
1459 long Count
, long *ActualCount
)
1461 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1464 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1466 unit
= string_to_unit(Unit
);
1467 if(unit
== RU_UNKNOWN
)
1468 return E_INVALIDARG
;
1477 dompos_t start_pos
, end_pos
, new_pos
;
1480 get_cur_pos(This
, TRUE
, &start_pos
);
1481 get_cur_pos(This
, FALSE
, &end_pos
);
1482 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1485 *ActualCount
= move_next_chars(Count
, &end_pos
, collapsed
, NULL
, NULL
, &new_pos
);
1486 set_range_pos(This
, FALSE
, &new_pos
);
1490 *ActualCount
= -move_prev_chars(This
, -Count
, &end_pos
, TRUE
, &start_pos
, &bounded
, &new_pos
);
1491 set_range_pos(This
, bounded
, &new_pos
);
1493 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1496 dompos_release(&start_pos
);
1497 dompos_release(&end_pos
);
1498 dompos_release(&new_pos
);
1503 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1509 static HRESULT WINAPI
HTMLTxtRange_select(IHTMLTxtRange
*iface
)
1511 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1513 TRACE("(%p)\n", This
);
1515 if(This
->doc
->nscontainer
) {
1516 nsIDOMWindow
*dom_window
= NULL
;
1517 nsISelection
*nsselection
;
1519 nsIWebBrowser_GetContentDOMWindow(This
->doc
->nscontainer
->webbrowser
, &dom_window
);
1520 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
1521 nsIDOMWindow_Release(dom_window
);
1523 nsISelection_RemoveAllRanges(nsselection
);
1524 nsISelection_AddRange(nsselection
, This
->nsrange
);
1526 nsISelection_Release(nsselection
);
1532 static HRESULT WINAPI
HTMLTxtRange_pasteHTML(IHTMLTxtRange
*iface
, BSTR html
)
1534 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1535 FIXME("(%p)->(%s)\n", This
, debugstr_w(html
));
1539 static HRESULT WINAPI
HTMLTxtRange_moveToElementText(IHTMLTxtRange
*iface
, IHTMLElement
*element
)
1541 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1542 FIXME("(%p)->(%p)\n", This
, element
);
1546 static HRESULT WINAPI
HTMLTxtRange_setEndPoint(IHTMLTxtRange
*iface
, BSTR how
,
1547 IHTMLTxtRange
*SourceRange
)
1549 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1550 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(how
), SourceRange
);
1554 static HRESULT WINAPI
HTMLTxtRange_compareEndPoints(IHTMLTxtRange
*iface
, BSTR how
,
1555 IHTMLTxtRange
*SourceRange
, long *ret
)
1557 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1558 HTMLTxtRange
*src_range
;
1563 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(how
), SourceRange
, ret
);
1565 nscmpt
= string_to_nscmptype(how
);
1567 return E_INVALIDARG
;
1569 src_range
= get_range_object(This
->doc
, SourceRange
);
1573 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, nscmpt
, src_range
->nsrange
, &nsret
);
1574 if(NS_FAILED(nsres
))
1575 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1581 static HRESULT WINAPI
HTMLTxtRange_findText(IHTMLTxtRange
*iface
, BSTR String
,
1582 long count
, long Flags
, VARIANT_BOOL
*Success
)
1584 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1585 FIXME("(%p)->(%s %ld %08lx %p)\n", This
, debugstr_w(String
), count
, Flags
, Success
);
1589 static HRESULT WINAPI
HTMLTxtRange_moveToPoint(IHTMLTxtRange
*iface
, long x
, long y
)
1591 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1592 FIXME("(%p)->(%ld %ld)\n", This
, x
, y
);
1596 static HRESULT WINAPI
HTMLTxtRange_getBookmark(IHTMLTxtRange
*iface
, BSTR
*Bookmark
)
1598 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1599 FIXME("(%p)->(%p)\n", This
, Bookmark
);
1603 static HRESULT WINAPI
HTMLTxtRange_moveToBookmark(IHTMLTxtRange
*iface
, BSTR Bookmark
,
1604 VARIANT_BOOL
*Success
)
1606 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1607 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(Bookmark
), Success
);
1611 static HRESULT WINAPI
HTMLTxtRange_queryCommandSupported(IHTMLTxtRange
*iface
, BSTR cmdID
,
1612 VARIANT_BOOL
*pfRet
)
1614 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1615 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1619 static HRESULT WINAPI
HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange
*iface
, BSTR cmdID
,
1620 VARIANT_BOOL
*pfRet
)
1622 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1623 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1627 static HRESULT WINAPI
HTMLTxtRange_queryCommandState(IHTMLTxtRange
*iface
, BSTR cmdID
,
1628 VARIANT_BOOL
*pfRet
)
1630 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1631 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1635 static HRESULT WINAPI
HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange
*iface
, BSTR cmdID
,
1636 VARIANT_BOOL
*pfRet
)
1638 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1639 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1643 static HRESULT WINAPI
HTMLTxtRange_queryCommandText(IHTMLTxtRange
*iface
, BSTR cmdID
,
1646 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1647 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdText
);
1651 static HRESULT WINAPI
HTMLTxtRange_queryCommandValue(IHTMLTxtRange
*iface
, BSTR cmdID
,
1654 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1655 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdValue
);
1659 static HRESULT WINAPI
HTMLTxtRange_execCommand(IHTMLTxtRange
*iface
, BSTR cmdID
,
1660 VARIANT_BOOL showUI
, VARIANT value
, VARIANT_BOOL
*pfRet
)
1662 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1663 FIXME("(%p)->(%s %x v %p)\n", This
, debugstr_w(cmdID
), showUI
, pfRet
);
1667 static HRESULT WINAPI
HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange
*iface
, BSTR cmdID
,
1668 VARIANT_BOOL
*pfRet
)
1670 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1671 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1675 #undef HTMLTXTRANGE_THIS
1677 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl
= {
1678 HTMLTxtRange_QueryInterface
,
1679 HTMLTxtRange_AddRef
,
1680 HTMLTxtRange_Release
,
1681 HTMLTxtRange_GetTypeInfoCount
,
1682 HTMLTxtRange_GetTypeInfo
,
1683 HTMLTxtRange_GetIDsOfNames
,
1684 HTMLTxtRange_Invoke
,
1685 HTMLTxtRange_get_htmlText
,
1686 HTMLTxtRange_put_text
,
1687 HTMLTxtRange_get_text
,
1688 HTMLTxtRange_parentElement
,
1689 HTMLTxtRange_duplicate
,
1690 HTMLTxtRange_inRange
,
1691 HTMLTxtRange_isEqual
,
1692 HTMLTxtRange_scrollIntoView
,
1693 HTMLTxtRange_collapse
,
1694 HTMLTxtRange_expand
,
1696 HTMLTxtRange_moveStart
,
1697 HTMLTxtRange_moveEnd
,
1698 HTMLTxtRange_select
,
1699 HTMLTxtRange_pasteHTML
,
1700 HTMLTxtRange_moveToElementText
,
1701 HTMLTxtRange_setEndPoint
,
1702 HTMLTxtRange_compareEndPoints
,
1703 HTMLTxtRange_findText
,
1704 HTMLTxtRange_moveToPoint
,
1705 HTMLTxtRange_getBookmark
,
1706 HTMLTxtRange_moveToBookmark
,
1707 HTMLTxtRange_queryCommandSupported
,
1708 HTMLTxtRange_queryCommandEnabled
,
1709 HTMLTxtRange_queryCommandState
,
1710 HTMLTxtRange_queryCommandIndeterm
,
1711 HTMLTxtRange_queryCommandText
,
1712 HTMLTxtRange_queryCommandValue
,
1713 HTMLTxtRange_execCommand
,
1714 HTMLTxtRange_execCommandShowHelp
1717 #define OLECMDTRG_THIS(iface) DEFINE_THIS(HTMLTxtRange, OleCommandTarget, iface)
1719 static HRESULT WINAPI
RangeCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
1721 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1722 return IHTMLTxtRange_QueryInterface(HTMLTXTRANGE(This
), riid
, ppv
);
1725 static ULONG WINAPI
RangeCommandTarget_AddRef(IOleCommandTarget
*iface
)
1727 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1728 return IHTMLTxtRange_AddRef(HTMLTXTRANGE(This
));
1731 static ULONG WINAPI
RangeCommandTarget_Release(IOleCommandTarget
*iface
)
1733 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1734 return IHTMLTxtRange_Release(HTMLTXTRANGE(This
));
1737 static HRESULT WINAPI
RangeCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1738 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
1740 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1741 FIXME("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
1745 static HRESULT
exec_indent(HTMLTxtRange
*This
, VARIANT
*in
, VARIANT
*out
)
1747 nsIDOMDocumentFragment
*fragment
;
1748 nsIDOMElement
*blockquote_elem
, *p_elem
;
1752 static const PRUnichar blockquoteW
[] = {'B','L','O','C','K','Q','U','O','T','E',0};
1753 static const PRUnichar pW
[] = {'P',0};
1755 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
1757 if(!This
->doc
->nsdoc
) {
1758 WARN("NULL nsdoc\n");
1762 nsAString_Init(&tag_str
, blockquoteW
);
1763 nsIDOMHTMLDocument_CreateElement(This
->doc
->nsdoc
, &tag_str
, &blockquote_elem
);
1764 nsAString_Finish(&tag_str
);
1766 nsAString_Init(&tag_str
, pW
);
1767 nsIDOMDocument_CreateElement(This
->doc
->nsdoc
, &tag_str
, &p_elem
);
1768 nsAString_Finish(&tag_str
);
1770 nsIDOMRange_ExtractContents(This
->nsrange
, &fragment
);
1771 nsIDOMElement_AppendChild(p_elem
, (nsIDOMNode
*)fragment
, &tmp
);
1772 nsIDOMDocumentFragment_Release(fragment
);
1773 nsIDOMNode_Release(tmp
);
1775 nsIDOMElement_AppendChild(blockquote_elem
, (nsIDOMNode
*)p_elem
, &tmp
);
1776 nsIDOMElement_Release(p_elem
);
1777 nsIDOMNode_Release(tmp
);
1779 nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)blockquote_elem
);
1780 nsIDOMElement_Release(blockquote_elem
);
1785 static HRESULT WINAPI
RangeCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1786 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
1788 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1790 TRACE("(%p)->(%s %d %x %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
,
1791 nCmdexecopt
, pvaIn
, pvaOut
);
1793 if(pguidCmdGroup
&& IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
1796 return exec_indent(This
, pvaIn
, pvaOut
);
1798 FIXME("Unsupported cmdid %d of CGID_MSHTML\n", nCmdID
);
1801 FIXME("Unsupported cmd %d of group %s\n", nCmdID
, debugstr_guid(pguidCmdGroup
));
1807 #undef OLECMDTRG_THIS
1809 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
1810 RangeCommandTarget_QueryInterface
,
1811 RangeCommandTarget_AddRef
,
1812 RangeCommandTarget_Release
,
1813 RangeCommandTarget_QueryStatus
,
1814 RangeCommandTarget_Exec
1817 IHTMLTxtRange
*HTMLTxtRange_Create(HTMLDocument
*doc
, nsIDOMRange
*nsrange
)
1819 HTMLTxtRange
*ret
= heap_alloc(sizeof(HTMLTxtRange
));
1821 ret
->lpHTMLTxtRangeVtbl
= &HTMLTxtRangeVtbl
;
1822 ret
->lpOleCommandTargetVtbl
= &OleCommandTargetVtbl
;
1826 nsIDOMRange_AddRef(nsrange
);
1827 ret
->nsrange
= nsrange
;
1830 list_add_head(&doc
->range_list
, &ret
->entry
);
1832 return HTMLTXTRANGE(ret
);
1835 void detach_ranges(HTMLDocument
*This
)
1839 LIST_FOR_EACH_ENTRY(iter
, &This
->range_list
, HTMLTxtRange
, entry
) {