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
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
40 static const WCHAR brW
[] = {'b','r',0};
43 const IHTMLTxtRangeVtbl
*lpHTMLTxtRangeVtbl
;
44 const IOleCommandTargetVtbl
*lpOleCommandTargetVtbl
;
54 #define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl)
78 static HTMLTxtRange
*get_range_object(HTMLDocument
*doc
, IHTMLTxtRange
*iface
)
82 LIST_FOR_EACH_ENTRY(iter
, &doc
->range_list
, HTMLTxtRange
, entry
) {
83 if(HTMLTXTRANGE(iter
) == iface
)
87 ERR("Could not find range in document\n");
91 static range_unit_t
string_to_unit(LPCWSTR str
)
93 static const WCHAR characterW
[] =
94 {'c','h','a','r','a','c','t','e','r',0};
95 static const WCHAR wordW
[] =
97 static const WCHAR sentenceW
[] =
98 {'s','e','n','t','e','n','c','e',0};
99 static const WCHAR texteditW
[] =
100 {'t','e','x','t','e','d','i','t',0};
102 if(!strcmpiW(str
, characterW
)) return RU_CHAR
;
103 if(!strcmpiW(str
, wordW
)) return RU_WORD
;
104 if(!strcmpiW(str
, sentenceW
)) return RU_SENTENCE
;
105 if(!strcmpiW(str
, texteditW
)) return RU_TEXTEDIT
;
110 static int string_to_nscmptype(LPCWSTR str
)
112 static const WCHAR seW
[] = {'S','t','a','r','t','T','o','E','n','d',0};
113 static const WCHAR ssW
[] = {'S','t','a','r','t','T','o','S','t','a','r','t',0};
114 static const WCHAR esW
[] = {'E','n','d','T','o','S','t','a','r','t',0};
115 static const WCHAR eeW
[] = {'E','n','d','T','o','E','n','d',0};
117 if(!strcmpiW(str
, seW
)) return NS_START_TO_END
;
118 if(!strcmpiW(str
, ssW
)) return NS_START_TO_START
;
119 if(!strcmpiW(str
, esW
)) return NS_END_TO_START
;
120 if(!strcmpiW(str
, eeW
)) return NS_END_TO_END
;
125 static PRUint16
get_node_type(nsIDOMNode
*node
)
130 nsIDOMNode_GetNodeType(node
, &type
);
135 static BOOL
is_br_node(nsIDOMNode
*node
)
139 const PRUnichar
*tag
;
143 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
147 nsAString_Init(&tag_str
, NULL
);
148 nsIDOMElement_GetTagName(elem
, &tag_str
);
149 nsIDOMElement_Release(elem
);
150 nsAString_GetData(&tag_str
, &tag
);
152 if(!strcmpiW(tag
, brW
))
155 nsAString_Finish(&tag_str
);
160 static inline void wstrbuf_init(wstrbuf_t
*buf
)
164 buf
->buf
= heap_alloc(buf
->size
* sizeof(WCHAR
));
168 static inline void wstrbuf_finish(wstrbuf_t
*buf
)
173 static void wstrbuf_append_len(wstrbuf_t
*buf
, LPCWSTR str
, int len
)
175 if(buf
->len
+len
>= buf
->size
) {
176 buf
->size
= 2*buf
->len
+len
;
177 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
* sizeof(WCHAR
));
180 memcpy(buf
->buf
+buf
->len
, str
, len
*sizeof(WCHAR
));
182 buf
->buf
[buf
->len
] = 0;
185 static inline void wstrbuf_append(wstrbuf_t
*buf
, LPCWSTR str
)
187 wstrbuf_append_len(buf
, str
, strlenW(str
));
190 static void wstrbuf_append_nodetxt(wstrbuf_t
*buf
, LPCWSTR str
, int len
)
192 const WCHAR
*s
= str
;
195 TRACE("%s\n", debugstr_wn(str
, len
));
197 if(buf
->len
+len
>= buf
->size
) {
198 buf
->size
= 2*buf
->len
+len
;
199 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
* sizeof(WCHAR
));
202 if(buf
->len
&& isspaceW(buf
->buf
[buf
->len
-1])) {
203 while(s
< str
+len
&& isspaceW(*s
))
207 d
= buf
->buf
+buf
->len
;
212 while(s
< str
+len
&& isspaceW(*s
))
219 buf
->len
= d
- buf
->buf
;
223 static void wstrbuf_append_node(wstrbuf_t
*buf
, nsIDOMNode
*node
)
226 switch(get_node_type(node
)) {
230 const PRUnichar
*data
;
232 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMText
, (void**)&nstext
);
234 nsAString_Init(&data_str
, NULL
);
235 nsIDOMText_GetData(nstext
, &data_str
);
236 nsAString_GetData(&data_str
, &data
);
237 wstrbuf_append_nodetxt(buf
, data
, strlenW(data
));
238 nsAString_Finish(&data_str
);
240 nsIDOMText_Release(nstext
);
245 if(is_br_node(node
)) {
246 static const WCHAR endlW
[] = {'\r','\n'};
247 wstrbuf_append_len(buf
, endlW
, 2);
252 static BOOL
fill_nodestr(dompos_t
*pos
)
257 if(pos
->type
!= TEXT_NODE
)
260 nsres
= nsIDOMNode_QueryInterface(pos
->node
, &IID_nsIDOMText
, (void**)&text
);
264 nsAString_Init(&pos
->str
, NULL
);
265 nsIDOMText_GetData(text
, &pos
->str
);
266 nsIDOMText_Release(text
);
267 nsAString_GetData(&pos
->str
, &pos
->p
);
270 pos
->off
= *pos
->p
? strlenW(pos
->p
)-1 : 0;
275 static nsIDOMNode
*next_node(nsIDOMNode
*iter
)
277 nsIDOMNode
*ret
, *tmp
;
283 nsres
= nsIDOMNode_GetFirstChild(iter
, &ret
);
284 if(NS_SUCCEEDED(nsres
) && ret
)
287 nsIDOMNode_AddRef(iter
);
290 nsres
= nsIDOMNode_GetNextSibling(iter
, &ret
);
291 if(NS_SUCCEEDED(nsres
) && ret
) {
292 nsIDOMNode_Release(iter
);
296 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
297 nsIDOMNode_Release(iter
);
299 }while(NS_SUCCEEDED(nsres
) && iter
);
304 static nsIDOMNode
*prev_node(HTMLTxtRange
*This
, nsIDOMNode
*iter
)
306 nsIDOMNode
*ret
, *tmp
;
310 nsIDOMHTMLDocument
*nshtmldoc
;
311 nsIDOMHTMLElement
*nselem
;
312 nsIDOMDocument
*nsdoc
;
314 nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
315 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nshtmldoc
);
316 nsIDOMDocument_Release(nsdoc
);
317 nsIDOMHTMLDocument_GetBody(nshtmldoc
, &nselem
);
318 nsIDOMHTMLDocument_Release(nshtmldoc
);
320 nsIDOMElement_GetLastChild(nselem
, &tmp
);
322 return (nsIDOMNode
*)nselem
;
326 nsIDOMNode_GetLastChild(ret
, &tmp
);
329 nsIDOMElement_Release(nselem
);
334 nsres
= nsIDOMNode_GetLastChild(iter
, &ret
);
335 if(NS_SUCCEEDED(nsres
) && ret
)
338 nsIDOMNode_AddRef(iter
);
341 nsres
= nsIDOMNode_GetPreviousSibling(iter
, &ret
);
342 if(NS_SUCCEEDED(nsres
) && ret
) {
343 nsIDOMNode_Release(iter
);
347 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
348 nsIDOMNode_Release(iter
);
350 }while(NS_SUCCEEDED(nsres
) && iter
);
355 static nsIDOMNode
*get_child_node(nsIDOMNode
*node
, PRUint32 off
)
357 nsIDOMNodeList
*node_list
;
358 nsIDOMNode
*ret
= NULL
;
360 nsIDOMNode_GetChildNodes(node
, &node_list
);
361 nsIDOMNodeList_Item(node_list
, off
, &ret
);
362 nsIDOMNodeList_Release(node_list
);
367 static void get_cur_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
376 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
381 nsIDOMRange_GetStartContainer(This
->nsrange
, &node
);
382 nsIDOMRange_GetStartOffset(This
->nsrange
, &off
);
384 nsIDOMRange_GetEndContainer(This
->nsrange
, &node
);
385 nsIDOMRange_GetEndOffset(This
->nsrange
, &off
);
388 pos
->type
= get_node_type(node
);
389 if(pos
->type
== ELEMENT_NODE
) {
391 pos
->node
= get_child_node(node
, off
);
394 pos
->node
= off
? get_child_node(node
, off
-1) : prev_node(This
, node
);
398 pos
->type
= get_node_type(pos
->node
);
399 nsIDOMNode_Release(node
);
407 pos
->node
= prev_node(This
, node
);
409 nsIDOMNode_Release(node
);
412 if(pos
->type
== TEXT_NODE
)
416 static void set_range_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
421 if(pos
->type
== TEXT_NODE
)
422 nsres
= nsIDOMRange_SetStart(This
->nsrange
, pos
->node
, pos
->off
);
424 nsres
= nsIDOMRange_SetStartBefore(This
->nsrange
, pos
->node
);
426 if(pos
->type
== TEXT_NODE
&& pos
->p
[pos
->off
+1])
427 nsres
= nsIDOMRange_SetEnd(This
->nsrange
, pos
->node
, pos
->off
+1);
429 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, pos
->node
);
433 ERR("failed: %p %08x\n", pos
->node
, nsres
);
436 static inline void dompos_release(dompos_t
*pos
)
439 nsIDOMNode_Release(pos
->node
);
442 nsAString_Finish(&pos
->str
);
445 static inline void dompos_addref(dompos_t
*pos
)
448 nsIDOMNode_AddRef(pos
->node
);
450 if(pos
->type
== TEXT_NODE
)
454 static inline BOOL
dompos_cmp(const dompos_t
*pos1
, const dompos_t
*pos2
)
456 return pos1
->node
== pos2
->node
&& pos1
->off
== pos2
->off
;
459 static void range_to_string(HTMLTxtRange
*This
, wstrbuf_t
*buf
)
461 nsIDOMNode
*iter
, *tmp
;
462 dompos_t start_pos
, end_pos
;
465 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
473 get_cur_pos(This
, FALSE
, &end_pos
);
474 get_cur_pos(This
, TRUE
, &start_pos
);
476 if(start_pos
.type
== TEXT_NODE
) {
477 if(start_pos
.node
== end_pos
.node
) {
478 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, end_pos
.off
-start_pos
.off
+1);
479 iter
= start_pos
.node
;
480 nsIDOMNode_AddRef(iter
);
482 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, strlenW(start_pos
.p
+start_pos
.off
));
483 iter
= next_node(start_pos
.node
);
486 iter
= start_pos
.node
;
487 nsIDOMNode_AddRef(iter
);
490 while(iter
!= end_pos
.node
) {
491 wstrbuf_append_node(buf
, iter
);
492 tmp
= next_node(iter
);
493 nsIDOMNode_Release(iter
);
497 nsIDOMNode_AddRef(end_pos
.node
);
499 if(start_pos
.node
!= end_pos
.node
&& !is_br_node(end_pos
.node
))
500 wstrbuf_append_nodetxt(buf
, end_pos
.p
, end_pos
.off
+1);
502 nsIDOMNode_Release(iter
);
503 dompos_release(&start_pos
);
504 dompos_release(&end_pos
);
509 for(p
= buf
->buf
+buf
->len
-1; p
>= buf
->buf
&& isspaceW(*p
); p
--);
511 p
= strchrW(p
, '\r');
517 static WCHAR
get_pos_char(const dompos_t
*pos
)
521 return pos
->p
[pos
->off
];
523 if(is_br_node(pos
->node
))
530 static void end_space(const dompos_t
*pos
, dompos_t
*new_pos
)
535 dompos_addref(new_pos
);
537 if(pos
->type
!= TEXT_NODE
)
540 p
= new_pos
->p
+new_pos
->off
;
542 if(!*p
|| !isspace(*p
))
545 while(p
[1] && isspace(p
[1]))
548 new_pos
->off
= p
- new_pos
->p
;
551 static WCHAR
next_char(const dompos_t
*pos
, dompos_t
*new_pos
)
553 nsIDOMNode
*iter
, *tmp
;
554 dompos_t last_space
, tmp_pos
;
558 if(pos
->type
== TEXT_NODE
&& pos
->off
!= -1 && pos
->p
[pos
->off
]) {
562 while(isspaceW(*++p
));
566 if(*p
&& isspaceW(*p
)) {
568 while(p
[1] && isspaceW(p
[1]))
574 new_pos
->off
= p
- pos
->p
;
575 dompos_addref(new_pos
);
577 return cspace
? cspace
: *p
;
580 last_space
.off
= p
- pos
->p
;
581 dompos_addref(&last_space
);
585 iter
= next_node(pos
->node
);
588 switch(get_node_type(iter
)) {
591 tmp_pos
.type
= TEXT_NODE
;
592 dompos_addref(&tmp_pos
);
597 dompos_release(&tmp_pos
);
599 }else if(isspaceW(*p
)) {
601 dompos_release(&last_space
);
605 while(p
[1] && isspaceW(p
[1]))
608 tmp_pos
.off
= p
-tmp_pos
.p
;
611 last_space
= tmp_pos
;
616 nsIDOMNode_Release(iter
);
619 *new_pos
= last_space
;
620 dompos_release(&tmp_pos
);
621 nsIDOMNode_Release(iter
);
629 nsIDOMNode_Release(iter
);
633 if(!is_br_node(iter
))
637 dompos_release(&last_space
);
640 nsIDOMNode_AddRef(iter
);
641 last_space
.node
= iter
;
642 last_space
.type
= ELEMENT_NODE
;
648 iter
= next_node(iter
);
649 nsIDOMNode_Release(tmp
);
653 *new_pos
= last_space
;
656 dompos_addref(new_pos
);
662 static WCHAR
prev_char(HTMLTxtRange
*This
, const dompos_t
*pos
, dompos_t
*new_pos
)
664 nsIDOMNode
*iter
, *tmp
;
666 BOOL skip_space
= FALSE
;
668 if(pos
->type
== TEXT_NODE
&& isspaceW(pos
->p
[pos
->off
]))
671 if(pos
->type
== TEXT_NODE
&& pos
->off
) {
672 p
= pos
->p
+pos
->off
-1;
675 while(p
>= pos
->p
&& isspace(*p
))
681 new_pos
->off
= p
-pos
->p
;
682 dompos_addref(new_pos
);
683 return new_pos
->p
[new_pos
->off
];
687 iter
= prev_node(This
, pos
->node
);
690 switch(get_node_type(iter
)) {
695 tmp_pos
.type
= TEXT_NODE
;
696 dompos_addref(&tmp_pos
);
698 p
= tmp_pos
.p
+ strlenW(tmp_pos
.p
)-1;
701 while(p
>= tmp_pos
.p
&& isspaceW(*p
))
706 dompos_release(&tmp_pos
);
710 tmp_pos
.off
= p
-tmp_pos
.p
;
712 nsIDOMNode_Release(iter
);
717 if(!is_br_node(iter
))
725 new_pos
->node
= iter
;
726 new_pos
->type
= ELEMENT_NODE
;
733 iter
= prev_node(This
, iter
);
734 nsIDOMNode_Release(tmp
);
738 dompos_addref(new_pos
);
742 static long move_next_chars(long cnt
, const dompos_t
*pos
, BOOL col
, const dompos_t
*bound_pos
,
743 BOOL
*bounded
, dompos_t
*new_pos
)
756 end_space(pos
, new_pos
);
760 c
= next_char(pos
, &iter
);
765 c
= next_char(&tmp
, &iter
);
766 dompos_release(&tmp
);
771 if(bound_pos
&& dompos_cmp(&tmp
, bound_pos
)) {
781 static long move_prev_chars(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, BOOL end
,
782 const dompos_t
*bound_pos
, BOOL
*bounded
, dompos_t
*new_pos
)
791 c
= prev_char(This
, pos
, &iter
);
795 while(c
&& ret
< cnt
) {
797 c
= prev_char(This
, &tmp
, &iter
);
798 dompos_release(&tmp
);
807 if(bound_pos
&& dompos_cmp(&iter
, bound_pos
)) {
814 return bounded
&& *bounded
? ret
+1 : ret
;
817 static long find_prev_space(HTMLTxtRange
*This
, const dompos_t
*pos
, BOOL first_space
, dompos_t
*ret
)
822 c
= prev_char(This
, pos
, &iter
);
823 if(!c
|| (first_space
&& isspaceW(c
))) {
830 c
= prev_char(This
, &tmp
, &iter
);
831 if(!c
|| isspaceW(c
)) {
832 dompos_release(&iter
);
835 dompos_release(&tmp
);
842 static int find_word_end(const dompos_t
*pos
, dompos_t
*ret
)
847 c
= get_pos_char(pos
);
854 c
= next_char(pos
, &iter
);
865 while(c
&& !isspaceW(c
)) {
867 c
= next_char(&tmp
, &iter
);
869 dompos_release(&iter
);
873 dompos_release(&tmp
);
881 static long move_next_words(long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
887 c
= get_pos_char(pos
);
889 end_space(pos
, &iter
);
892 c
= next_char(pos
, &iter
);
897 while(c
&& ret
< cnt
) {
899 c
= next_char(&tmp
, &iter
);
900 dompos_release(&tmp
);
909 static long move_prev_words(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
915 dompos_addref(&iter
);
918 if(!find_prev_space(This
, &iter
, FALSE
, &tmp
))
921 dompos_release(&iter
);
930 #define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
932 static HRESULT WINAPI
HTMLTxtRange_QueryInterface(IHTMLTxtRange
*iface
, REFIID riid
, void **ppv
)
934 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
938 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
939 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
940 *ppv
= HTMLTXTRANGE(This
);
941 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
942 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
943 *ppv
= HTMLTXTRANGE(This
);
944 }else if(IsEqualGUID(&IID_IHTMLTxtRange
, riid
)) {
945 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This
, ppv
);
946 *ppv
= HTMLTXTRANGE(This
);
947 }else if(IsEqualGUID(&IID_IOleCommandTarget
, riid
)) {
948 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This
, ppv
);
949 *ppv
= CMDTARGET(This
);
953 IUnknown_AddRef((IUnknown
*)*ppv
);
957 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
958 return E_NOINTERFACE
;
961 static ULONG WINAPI
HTMLTxtRange_AddRef(IHTMLTxtRange
*iface
)
963 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
964 LONG ref
= InterlockedIncrement(&This
->ref
);
966 TRACE("(%p) ref=%d\n", This
, ref
);
971 static ULONG WINAPI
HTMLTxtRange_Release(IHTMLTxtRange
*iface
)
973 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
974 LONG ref
= InterlockedDecrement(&This
->ref
);
976 TRACE("(%p) ref=%d\n", This
, ref
);
980 nsISelection_Release(This
->nsrange
);
982 list_remove(&This
->entry
);
989 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange
*iface
, UINT
*pctinfo
)
991 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
992 FIXME("(%p)->(%p)\n", This
, pctinfo
);
996 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfo(IHTMLTxtRange
*iface
, UINT iTInfo
,
997 LCID lcid
, ITypeInfo
**ppTInfo
)
999 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1000 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1004 static HRESULT WINAPI
HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange
*iface
, REFIID riid
,
1005 LPOLESTR
*rgszNames
, UINT cNames
,
1006 LCID lcid
, DISPID
*rgDispId
)
1008 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1009 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1014 static HRESULT WINAPI
HTMLTxtRange_Invoke(IHTMLTxtRange
*iface
, DISPID dispIdMember
,
1015 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1016 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1018 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1019 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1020 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1024 static HRESULT WINAPI
HTMLTxtRange_get_htmlText(IHTMLTxtRange
*iface
, BSTR
*p
)
1026 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1028 TRACE("(%p)->(%p)\n", This
, p
);
1033 nsIDOMDocumentFragment
*fragment
;
1036 nsres
= nsIDOMRange_CloneContents(This
->nsrange
, &fragment
);
1037 if(NS_SUCCEEDED(nsres
)) {
1038 const PRUnichar
*nstext
;
1041 nsAString_Init(&nsstr
, NULL
);
1042 nsnode_to_nsstring((nsIDOMNode
*)fragment
, &nsstr
);
1043 nsIDOMDocumentFragment_Release(fragment
);
1045 nsAString_GetData(&nsstr
, &nstext
);
1046 *p
= SysAllocString(nstext
);
1048 nsAString_Finish(&nsstr
);
1053 const WCHAR emptyW
[] = {0};
1054 *p
= SysAllocString(emptyW
);
1057 TRACE("return %s\n", debugstr_w(*p
));
1061 static HRESULT WINAPI
HTMLTxtRange_put_text(IHTMLTxtRange
*iface
, BSTR v
)
1063 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1064 nsIDOMDocument
*nsdoc
;
1065 nsIDOMText
*text_node
;
1069 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
1072 return MSHTML_E_NODOC
;
1074 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1075 if(NS_FAILED(nsres
)) {
1076 ERR("GetDocument failed: %08x\n", nsres
);
1080 nsAString_Init(&text_str
, v
);
1081 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &text_str
, &text_node
);
1082 nsIDOMDocument_Release(nsdoc
);
1083 nsAString_Finish(&text_str
);
1084 if(NS_FAILED(nsres
)) {
1085 ERR("CreateTextNode failed: %08x\n", nsres
);
1088 nsres
= nsIDOMRange_DeleteContents(This
->nsrange
);
1089 if(NS_FAILED(nsres
))
1090 ERR("DeleteContents failed: %08x\n", nsres
);
1092 nsres
= nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)text_node
);
1093 if(NS_FAILED(nsres
))
1094 ERR("InsertNode failed: %08x\n", nsres
);
1096 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, (nsIDOMNode
*)text_node
);
1097 if(NS_FAILED(nsres
))
1098 ERR("SetEndAfter failed: %08x\n", nsres
);
1100 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), VARIANT_FALSE
);
1103 static HRESULT WINAPI
HTMLTxtRange_get_text(IHTMLTxtRange
*iface
, BSTR
*p
)
1105 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1108 TRACE("(%p)->(%p)\n", This
, p
);
1115 range_to_string(This
, &buf
);
1117 *p
= SysAllocString(buf
.buf
);
1118 wstrbuf_finish(&buf
);
1120 TRACE("ret %s\n", debugstr_w(*p
));
1124 static HRESULT WINAPI
HTMLTxtRange_parentElement(IHTMLTxtRange
*iface
, IHTMLElement
**parent
)
1126 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1127 nsIDOMNode
*nsnode
, *tmp
;
1130 TRACE("(%p)->(%p)\n", This
, parent
);
1132 nsIDOMRange_GetCommonAncestorContainer(This
->nsrange
, &nsnode
);
1133 while(nsnode
&& get_node_type(nsnode
) != ELEMENT_NODE
) {
1134 nsIDOMNode_GetParentNode(nsnode
, &tmp
);
1135 nsIDOMNode_Release(nsnode
);
1144 node
= get_node(This
->doc
, nsnode
);
1145 nsIDOMNode_Release(nsnode
);
1147 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node
), &IID_IHTMLElement
, (void**)parent
);
1150 static HRESULT WINAPI
HTMLTxtRange_duplicate(IHTMLTxtRange
*iface
, IHTMLTxtRange
**Duplicate
)
1152 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1153 nsIDOMRange
*nsrange
= NULL
;
1155 TRACE("(%p)->(%p)\n", This
, Duplicate
);
1157 nsIDOMRange_CloneRange(This
->nsrange
, &nsrange
);
1158 *Duplicate
= HTMLTxtRange_Create(This
->doc
, nsrange
);
1159 nsIDOMRange_Release(nsrange
);
1164 static HRESULT WINAPI
HTMLTxtRange_inRange(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1165 VARIANT_BOOL
*InRange
)
1167 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1168 HTMLTxtRange
*src_range
;
1172 TRACE("(%p)->(%p %p)\n", This
, Range
, InRange
);
1174 *InRange
= VARIANT_FALSE
;
1176 src_range
= get_range_object(This
->doc
, Range
);
1180 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1181 src_range
->nsrange
, &nsret
);
1182 if(NS_SUCCEEDED(nsres
) && nsret
<= 0) {
1183 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1184 src_range
->nsrange
, &nsret
);
1185 if(NS_SUCCEEDED(nsres
) && nsret
>= 0)
1186 *InRange
= VARIANT_TRUE
;
1189 if(NS_FAILED(nsres
))
1190 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1195 static HRESULT WINAPI
HTMLTxtRange_isEqual(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1196 VARIANT_BOOL
*IsEqual
)
1198 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1199 HTMLTxtRange
*src_range
;
1203 TRACE("(%p)->(%p %p)\n", This
, Range
, IsEqual
);
1205 *IsEqual
= VARIANT_FALSE
;
1207 src_range
= get_range_object(This
->doc
, Range
);
1211 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1212 src_range
->nsrange
, &nsret
);
1213 if(NS_SUCCEEDED(nsres
) && !nsret
) {
1214 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1215 src_range
->nsrange
, &nsret
);
1216 if(NS_SUCCEEDED(nsres
) && !nsret
)
1217 *IsEqual
= VARIANT_TRUE
;
1220 if(NS_FAILED(nsres
))
1221 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1226 static HRESULT WINAPI
HTMLTxtRange_scrollIntoView(IHTMLTxtRange
*iface
, VARIANT_BOOL fStart
)
1228 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1229 FIXME("(%p)->(%x)\n", This
, fStart
);
1233 static HRESULT WINAPI
HTMLTxtRange_collapse(IHTMLTxtRange
*iface
, VARIANT_BOOL Start
)
1235 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1237 TRACE("(%p)->(%x)\n", This
, Start
);
1239 nsIDOMRange_Collapse(This
->nsrange
, Start
!= VARIANT_FALSE
);
1243 static HRESULT WINAPI
HTMLTxtRange_expand(IHTMLTxtRange
*iface
, BSTR Unit
, VARIANT_BOOL
*Success
)
1245 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1248 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(Unit
), Success
);
1250 unit
= string_to_unit(Unit
);
1251 if(unit
== RU_UNKNOWN
)
1252 return E_INVALIDARG
;
1254 *Success
= VARIANT_FALSE
;
1258 dompos_t end_pos
, start_pos
, new_start_pos
, new_end_pos
;
1261 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1263 get_cur_pos(This
, TRUE
, &start_pos
);
1264 get_cur_pos(This
, FALSE
, &end_pos
);
1266 if(find_word_end(&end_pos
, &new_end_pos
) || collapsed
) {
1267 set_range_pos(This
, FALSE
, &new_end_pos
);
1268 *Success
= VARIANT_TRUE
;
1271 if(start_pos
.type
&& (get_pos_char(&end_pos
) || !dompos_cmp(&new_end_pos
, &end_pos
))) {
1272 if(find_prev_space(This
, &start_pos
, TRUE
, &new_start_pos
)) {
1273 set_range_pos(This
, TRUE
, &new_start_pos
);
1274 *Success
= VARIANT_TRUE
;
1276 dompos_release(&new_start_pos
);
1279 dompos_release(&new_end_pos
);
1280 dompos_release(&end_pos
);
1281 dompos_release(&start_pos
);
1287 nsIDOMDocument
*nsdoc
;
1288 nsIDOMHTMLDocument
*nshtmldoc
;
1289 nsIDOMHTMLElement
*nsbody
= NULL
;
1292 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1293 if(NS_FAILED(nsres
) || !nsdoc
) {
1294 ERR("GetDocument failed: %08x\n", nsres
);
1298 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nshtmldoc
);
1299 nsIDOMDocument_Release(nsdoc
);
1301 nsres
= nsIDOMHTMLDocument_GetBody(nshtmldoc
, &nsbody
);
1302 nsIDOMHTMLDocument_Release(nshtmldoc
);
1303 if(NS_FAILED(nsres
) || !nsbody
) {
1304 ERR("Could not get body: %08x\n", nsres
);
1308 nsres
= nsIDOMRange_SelectNodeContents(This
->nsrange
, (nsIDOMNode
*)nsbody
);
1309 nsIDOMHTMLElement_Release(nsbody
);
1310 if(NS_FAILED(nsres
)) {
1311 ERR("Collapse failed: %08x\n", nsres
);
1315 *Success
= VARIANT_TRUE
;
1320 FIXME("Unimplemented unit %s\n", debugstr_w(Unit
));
1326 static HRESULT WINAPI
HTMLTxtRange_move(IHTMLTxtRange
*iface
, BSTR Unit
,
1327 long Count
, long *ActualCount
)
1329 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1332 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1334 unit
= string_to_unit(Unit
);
1335 if(unit
== RU_UNKNOWN
)
1336 return E_INVALIDARG
;
1340 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1345 dompos_t cur_pos
, new_pos
;
1347 get_cur_pos(This
, TRUE
, &cur_pos
);
1350 *ActualCount
= move_next_chars(Count
, &cur_pos
, TRUE
, NULL
, NULL
, &new_pos
);
1351 set_range_pos(This
, FALSE
, &new_pos
);
1352 dompos_release(&new_pos
);
1354 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1356 *ActualCount
= -move_prev_chars(This
, -Count
, &cur_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1357 set_range_pos(This
, TRUE
, &new_pos
);
1358 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1359 dompos_release(&new_pos
);
1362 dompos_release(&cur_pos
);
1367 dompos_t cur_pos
, new_pos
;
1369 get_cur_pos(This
, TRUE
, &cur_pos
);
1372 *ActualCount
= move_next_words(Count
, &cur_pos
, &new_pos
);
1373 set_range_pos(This
, FALSE
, &new_pos
);
1374 dompos_release(&new_pos
);
1375 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1377 *ActualCount
= -move_prev_words(This
, -Count
, &cur_pos
, &new_pos
);
1378 set_range_pos(This
, TRUE
, &new_pos
);
1379 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1380 dompos_release(&new_pos
);
1383 dompos_release(&cur_pos
);
1388 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1391 TRACE("ret %ld\n", *ActualCount
);
1395 static HRESULT WINAPI
HTMLTxtRange_moveStart(IHTMLTxtRange
*iface
, BSTR Unit
,
1396 long Count
, long *ActualCount
)
1398 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1401 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1403 unit
= string_to_unit(Unit
);
1404 if(unit
== RU_UNKNOWN
)
1405 return E_INVALIDARG
;
1414 dompos_t start_pos
, end_pos
, new_pos
;
1417 get_cur_pos(This
, TRUE
, &start_pos
);
1418 get_cur_pos(This
, FALSE
, &end_pos
);
1419 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1424 *ActualCount
= move_next_chars(Count
, &start_pos
, collapsed
, &end_pos
, &bounded
, &new_pos
);
1425 set_range_pos(This
, !bounded
, &new_pos
);
1427 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1429 *ActualCount
= -move_prev_chars(This
, -Count
, &start_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1430 set_range_pos(This
, TRUE
, &new_pos
);
1433 dompos_release(&start_pos
);
1434 dompos_release(&end_pos
);
1435 dompos_release(&new_pos
);
1440 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1446 static HRESULT WINAPI
HTMLTxtRange_moveEnd(IHTMLTxtRange
*iface
, BSTR Unit
,
1447 long Count
, long *ActualCount
)
1449 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1452 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1454 unit
= string_to_unit(Unit
);
1455 if(unit
== RU_UNKNOWN
)
1456 return E_INVALIDARG
;
1465 dompos_t start_pos
, end_pos
, new_pos
;
1468 get_cur_pos(This
, TRUE
, &start_pos
);
1469 get_cur_pos(This
, FALSE
, &end_pos
);
1470 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1473 *ActualCount
= move_next_chars(Count
, &end_pos
, collapsed
, NULL
, NULL
, &new_pos
);
1474 set_range_pos(This
, FALSE
, &new_pos
);
1478 *ActualCount
= -move_prev_chars(This
, -Count
, &end_pos
, TRUE
, &start_pos
, &bounded
, &new_pos
);
1479 set_range_pos(This
, bounded
, &new_pos
);
1481 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1484 dompos_release(&start_pos
);
1485 dompos_release(&end_pos
);
1486 dompos_release(&new_pos
);
1491 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1497 static HRESULT WINAPI
HTMLTxtRange_select(IHTMLTxtRange
*iface
)
1499 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1501 TRACE("(%p)\n", This
);
1503 if(This
->doc
->nscontainer
) {
1504 nsIDOMWindow
*dom_window
= NULL
;
1505 nsISelection
*nsselection
;
1507 nsIWebBrowser_GetContentDOMWindow(This
->doc
->nscontainer
->webbrowser
, &dom_window
);
1508 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
1509 nsIDOMWindow_Release(dom_window
);
1511 nsISelection_RemoveAllRanges(nsselection
);
1512 nsISelection_AddRange(nsselection
, This
->nsrange
);
1514 nsISelection_Release(nsselection
);
1520 static HRESULT WINAPI
HTMLTxtRange_pasteHTML(IHTMLTxtRange
*iface
, BSTR html
)
1522 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1523 FIXME("(%p)->(%s)\n", This
, debugstr_w(html
));
1527 static HRESULT WINAPI
HTMLTxtRange_moveToElementText(IHTMLTxtRange
*iface
, IHTMLElement
*element
)
1529 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1530 FIXME("(%p)->(%p)\n", This
, element
);
1534 static HRESULT WINAPI
HTMLTxtRange_setEndPoint(IHTMLTxtRange
*iface
, BSTR how
,
1535 IHTMLTxtRange
*SourceRange
)
1537 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1538 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(how
), SourceRange
);
1542 static HRESULT WINAPI
HTMLTxtRange_compareEndPoints(IHTMLTxtRange
*iface
, BSTR how
,
1543 IHTMLTxtRange
*SourceRange
, long *ret
)
1545 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1546 HTMLTxtRange
*src_range
;
1551 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(how
), SourceRange
, ret
);
1553 nscmpt
= string_to_nscmptype(how
);
1555 return E_INVALIDARG
;
1557 src_range
= get_range_object(This
->doc
, SourceRange
);
1561 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, nscmpt
, src_range
->nsrange
, &nsret
);
1562 if(NS_FAILED(nsres
))
1563 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1569 static HRESULT WINAPI
HTMLTxtRange_findText(IHTMLTxtRange
*iface
, BSTR String
,
1570 long count
, long Flags
, VARIANT_BOOL
*Success
)
1572 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1573 FIXME("(%p)->(%s %ld %08lx %p)\n", This
, debugstr_w(String
), count
, Flags
, Success
);
1577 static HRESULT WINAPI
HTMLTxtRange_moveToPoint(IHTMLTxtRange
*iface
, long x
, long y
)
1579 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1580 FIXME("(%p)->(%ld %ld)\n", This
, x
, y
);
1584 static HRESULT WINAPI
HTMLTxtRange_getBookmark(IHTMLTxtRange
*iface
, BSTR
*Bookmark
)
1586 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1587 FIXME("(%p)->(%p)\n", This
, Bookmark
);
1591 static HRESULT WINAPI
HTMLTxtRange_moveToBookmark(IHTMLTxtRange
*iface
, BSTR Bookmark
,
1592 VARIANT_BOOL
*Success
)
1594 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1595 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(Bookmark
), Success
);
1599 static HRESULT WINAPI
HTMLTxtRange_queryCommandSupported(IHTMLTxtRange
*iface
, BSTR cmdID
,
1600 VARIANT_BOOL
*pfRet
)
1602 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1603 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1607 static HRESULT WINAPI
HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange
*iface
, BSTR cmdID
,
1608 VARIANT_BOOL
*pfRet
)
1610 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1611 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1615 static HRESULT WINAPI
HTMLTxtRange_queryCommandState(IHTMLTxtRange
*iface
, BSTR cmdID
,
1616 VARIANT_BOOL
*pfRet
)
1618 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1619 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1623 static HRESULT WINAPI
HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange
*iface
, BSTR cmdID
,
1624 VARIANT_BOOL
*pfRet
)
1626 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1627 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1631 static HRESULT WINAPI
HTMLTxtRange_queryCommandText(IHTMLTxtRange
*iface
, BSTR cmdID
,
1634 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1635 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdText
);
1639 static HRESULT WINAPI
HTMLTxtRange_queryCommandValue(IHTMLTxtRange
*iface
, BSTR cmdID
,
1642 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1643 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdValue
);
1647 static HRESULT WINAPI
HTMLTxtRange_execCommand(IHTMLTxtRange
*iface
, BSTR cmdID
,
1648 VARIANT_BOOL showUI
, VARIANT value
, VARIANT_BOOL
*pfRet
)
1650 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1651 FIXME("(%p)->(%s %x v %p)\n", This
, debugstr_w(cmdID
), showUI
, pfRet
);
1655 static HRESULT WINAPI
HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange
*iface
, BSTR cmdID
,
1656 VARIANT_BOOL
*pfRet
)
1658 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1659 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1663 #undef HTMLTXTRANGE_THIS
1665 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl
= {
1666 HTMLTxtRange_QueryInterface
,
1667 HTMLTxtRange_AddRef
,
1668 HTMLTxtRange_Release
,
1669 HTMLTxtRange_GetTypeInfoCount
,
1670 HTMLTxtRange_GetTypeInfo
,
1671 HTMLTxtRange_GetIDsOfNames
,
1672 HTMLTxtRange_Invoke
,
1673 HTMLTxtRange_get_htmlText
,
1674 HTMLTxtRange_put_text
,
1675 HTMLTxtRange_get_text
,
1676 HTMLTxtRange_parentElement
,
1677 HTMLTxtRange_duplicate
,
1678 HTMLTxtRange_inRange
,
1679 HTMLTxtRange_isEqual
,
1680 HTMLTxtRange_scrollIntoView
,
1681 HTMLTxtRange_collapse
,
1682 HTMLTxtRange_expand
,
1684 HTMLTxtRange_moveStart
,
1685 HTMLTxtRange_moveEnd
,
1686 HTMLTxtRange_select
,
1687 HTMLTxtRange_pasteHTML
,
1688 HTMLTxtRange_moveToElementText
,
1689 HTMLTxtRange_setEndPoint
,
1690 HTMLTxtRange_compareEndPoints
,
1691 HTMLTxtRange_findText
,
1692 HTMLTxtRange_moveToPoint
,
1693 HTMLTxtRange_getBookmark
,
1694 HTMLTxtRange_moveToBookmark
,
1695 HTMLTxtRange_queryCommandSupported
,
1696 HTMLTxtRange_queryCommandEnabled
,
1697 HTMLTxtRange_queryCommandState
,
1698 HTMLTxtRange_queryCommandIndeterm
,
1699 HTMLTxtRange_queryCommandText
,
1700 HTMLTxtRange_queryCommandValue
,
1701 HTMLTxtRange_execCommand
,
1702 HTMLTxtRange_execCommandShowHelp
1705 #define OLECMDTRG_THIS(iface) DEFINE_THIS(HTMLTxtRange, OleCommandTarget, iface)
1707 static HRESULT WINAPI
RangeCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
1709 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1710 return IHTMLTxtRange_QueryInterface(HTMLTXTRANGE(This
), riid
, ppv
);
1713 static ULONG WINAPI
RangeCommandTarget_AddRef(IOleCommandTarget
*iface
)
1715 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1716 return IHTMLTxtRange_AddRef(HTMLTXTRANGE(This
));
1719 static ULONG WINAPI
RangeCommandTarget_Release(IOleCommandTarget
*iface
)
1721 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1722 return IHTMLTxtRange_Release(HTMLTXTRANGE(This
));
1725 static HRESULT WINAPI
RangeCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1726 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
1728 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1729 FIXME("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
1733 static HRESULT
exec_indent(HTMLTxtRange
*This
, VARIANT
*in
, VARIANT
*out
)
1735 nsIDOMDocumentFragment
*fragment
;
1736 nsIDOMElement
*blockquote_elem
, *p_elem
;
1737 nsIDOMDocument
*nsdoc
;
1741 static const PRUnichar blockquoteW
[] = {'B','L','O','C','K','Q','U','O','T','E',0};
1742 static const PRUnichar pW
[] = {'P',0};
1744 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
1746 nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1748 nsAString_Init(&tag_str
, blockquoteW
);
1749 nsIDOMDocument_CreateElement(nsdoc
, &tag_str
, &blockquote_elem
);
1750 nsAString_Finish(&tag_str
);
1752 nsAString_Init(&tag_str
, pW
);
1753 nsIDOMDocument_CreateElement(nsdoc
, &tag_str
, &p_elem
);
1754 nsAString_Finish(&tag_str
);
1756 nsIDOMDocument_Release(nsdoc
);
1758 nsIDOMRange_ExtractContents(This
->nsrange
, &fragment
);
1759 nsIDOMElement_AppendChild(p_elem
, (nsIDOMNode
*)fragment
, &tmp
);
1760 nsIDOMDocumentFragment_Release(fragment
);
1761 nsIDOMNode_Release(tmp
);
1763 nsIDOMElement_AppendChild(blockquote_elem
, (nsIDOMNode
*)p_elem
, &tmp
);
1764 nsIDOMElement_Release(p_elem
);
1765 nsIDOMNode_Release(tmp
);
1767 nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)blockquote_elem
);
1768 nsIDOMElement_Release(blockquote_elem
);
1773 static HRESULT WINAPI
RangeCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1774 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
1776 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1778 TRACE("(%p)->(%s %d %x %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
,
1779 nCmdexecopt
, pvaIn
, pvaOut
);
1781 if(pguidCmdGroup
&& IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
1784 return exec_indent(This
, pvaIn
, pvaOut
);
1786 FIXME("Unsupported cmdid %d of CGID_MSHTML\n", nCmdID
);
1789 FIXME("Unsupported cmd %d of group %s\n", nCmdID
, debugstr_guid(pguidCmdGroup
));
1795 #undef OLECMDTRG_THIS
1797 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
1798 RangeCommandTarget_QueryInterface
,
1799 RangeCommandTarget_AddRef
,
1800 RangeCommandTarget_Release
,
1801 RangeCommandTarget_QueryStatus
,
1802 RangeCommandTarget_Exec
1805 IHTMLTxtRange
*HTMLTxtRange_Create(HTMLDocument
*doc
, nsIDOMRange
*nsrange
)
1807 HTMLTxtRange
*ret
= heap_alloc(sizeof(HTMLTxtRange
));
1809 ret
->lpHTMLTxtRangeVtbl
= &HTMLTxtRangeVtbl
;
1810 ret
->lpOleCommandTargetVtbl
= &OleCommandTargetVtbl
;
1814 nsIDOMRange_AddRef(nsrange
);
1815 ret
->nsrange
= nsrange
;
1818 list_add_head(&doc
->range_list
, &ret
->entry
);
1820 return HTMLTXTRANGE(ret
);
1823 void detach_ranges(HTMLDocument
*This
)
1827 LIST_FOR_EACH_ENTRY(iter
, &This
->range_list
, HTMLTxtRange
, entry
) {