2 * Copyright 2006 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
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
40 const IHTMLTxtRangeVtbl
*lpHTMLTxtRangeVtbl
;
50 #define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl)
52 static HTMLTxtRange
*get_range_object(HTMLDocument
*doc
, IHTMLTxtRange
*iface
)
56 LIST_FOR_EACH_ENTRY(iter
, &doc
->range_list
, HTMLTxtRange
, entry
) {
57 if(HTMLTXTRANGE(iter
) == iface
)
61 ERR("Could not find range in document\n");
65 static int string_to_nscmptype(LPCWSTR str
)
67 static const WCHAR seW
[] = {'S','t','a','r','t','T','o','E','n','d',0};
68 static const WCHAR ssW
[] = {'S','t','a','r','t','T','o','S','t','a','r','t',0};
69 static const WCHAR esW
[] = {'E','n','d','T','o','S','t','a','r','t',0};
70 static const WCHAR eeW
[] = {'E','n','d','T','o','E','n','d',0};
72 if(!strcmpiW(str
, seW
)) return NS_START_TO_END
;
73 if(!strcmpiW(str
, ssW
)) return NS_START_TO_START
;
74 if(!strcmpiW(str
, esW
)) return NS_END_TO_START
;
75 if(!strcmpiW(str
, eeW
)) return NS_END_TO_END
;
80 #define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
82 static HRESULT WINAPI
HTMLTxtRange_QueryInterface(IHTMLTxtRange
*iface
, REFIID riid
, void **ppv
)
84 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
88 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
89 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
90 *ppv
= HTMLTXTRANGE(This
);
91 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
92 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
93 *ppv
= HTMLTXTRANGE(This
);
94 }else if(IsEqualGUID(&IID_IHTMLTxtRange
, riid
)) {
95 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This
, ppv
);
96 *ppv
= HTMLTXTRANGE(This
);
100 IUnknown_AddRef((IUnknown
*)*ppv
);
104 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
105 return E_NOINTERFACE
;
108 static ULONG WINAPI
HTMLTxtRange_AddRef(IHTMLTxtRange
*iface
)
110 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
111 LONG ref
= InterlockedIncrement(&This
->ref
);
113 TRACE("(%p) ref=%d\n", This
, ref
);
118 static ULONG WINAPI
HTMLTxtRange_Release(IHTMLTxtRange
*iface
)
120 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
121 LONG ref
= InterlockedDecrement(&This
->ref
);
123 TRACE("(%p) ref=%d\n", This
, ref
);
127 nsISelection_Release(This
->nsrange
);
129 list_remove(&This
->entry
);
136 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange
*iface
, UINT
*pctinfo
)
138 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
139 FIXME("(%p)->(%p)\n", This
, pctinfo
);
143 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfo(IHTMLTxtRange
*iface
, UINT iTInfo
,
144 LCID lcid
, ITypeInfo
**ppTInfo
)
146 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
147 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
151 static HRESULT WINAPI
HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange
*iface
, REFIID riid
,
152 LPOLESTR
*rgszNames
, UINT cNames
,
153 LCID lcid
, DISPID
*rgDispId
)
155 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
156 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
161 static HRESULT WINAPI
HTMLTxtRange_Invoke(IHTMLTxtRange
*iface
, DISPID dispIdMember
,
162 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
163 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
165 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
166 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
167 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
171 static HRESULT WINAPI
HTMLTxtRange_get_htmlText(IHTMLTxtRange
*iface
, BSTR
*p
)
173 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
175 TRACE("(%p)->(%p)\n", This
, p
);
180 nsIDOMDocumentFragment
*fragment
;
183 nsres
= nsIDOMRange_CloneContents(This
->nsrange
, &fragment
);
184 if(NS_SUCCEEDED(nsres
)) {
185 const PRUnichar
*nstext
;
188 nsAString_Init(&nsstr
, NULL
);
189 nsnode_to_nsstring((nsIDOMNode
*)fragment
, &nsstr
);
190 nsIDOMDocumentFragment_Release(fragment
);
192 nsAString_GetData(&nsstr
, &nstext
, NULL
);
193 *p
= SysAllocString(nstext
);
195 nsAString_Finish(&nsstr
);
200 const WCHAR emptyW
[] = {0};
201 *p
= SysAllocString(emptyW
);
204 TRACE("return %s\n", debugstr_w(*p
));
208 static HRESULT WINAPI
HTMLTxtRange_put_text(IHTMLTxtRange
*iface
, BSTR v
)
210 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
211 nsIDOMDocument
*nsdoc
;
212 nsIDOMText
*text_node
;
216 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
219 return MSHTML_E_NODOC
;
221 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
222 if(NS_FAILED(nsres
)) {
223 ERR("GetDocument failed: %08x\n", nsres
);
227 nsAString_Init(&text_str
, v
);
228 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &text_str
, &text_node
);
229 nsAString_Finish(&text_str
);
230 if(NS_FAILED(nsres
)) {
231 ERR("CreateTextNode failed: %08x\n", nsres
);
234 nsres
= nsIDOMRange_DeleteContents(This
->nsrange
);
236 ERR("DeleteContents failed: %08x\n", nsres
);
238 nsres
= nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)text_node
);
240 ERR("InsertNode failed: %08x\n", nsres
);
245 static HRESULT WINAPI
HTMLTxtRange_get_text(IHTMLTxtRange
*iface
, BSTR
*p
)
247 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
249 TRACE("(%p)->(%p)\n", This
, p
);
257 nsAString_Init(&text_str
, NULL
);
259 nsres
= nsIDOMRange_ToString(This
->nsrange
, &text_str
);
260 if(NS_SUCCEEDED(nsres
)) {
261 const PRUnichar
*nstext
;
263 nsAString_GetData(&text_str
, &nstext
, NULL
);
264 *p
= SysAllocString(nstext
);
266 ERR("ToString failed: %08x\n", nsres
);
269 nsAString_Finish(&text_str
);
273 static const WCHAR empty
[] = {0};
274 *p
= SysAllocString(empty
);
280 static HRESULT WINAPI
HTMLTxtRange_parentElement(IHTMLTxtRange
*iface
, IHTMLElement
**parent
)
282 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
283 FIXME("(%p)->(%p)\n", This
, parent
);
287 static HRESULT WINAPI
HTMLTxtRange_duplicate(IHTMLTxtRange
*iface
, IHTMLTxtRange
**Duplicate
)
289 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
290 nsIDOMRange
*nsrange
= NULL
;
292 TRACE("(%p)->(%p)\n", This
, Duplicate
);
294 nsIDOMRange_CloneRange(This
->nsrange
, &nsrange
);
295 *Duplicate
= HTMLTxtRange_Create(This
->doc
, nsrange
);
296 nsIDOMRange_Release(nsrange
);
301 static HRESULT WINAPI
HTMLTxtRange_inRange(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
302 VARIANT_BOOL
*InRange
)
304 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
305 FIXME("(%p)->(%p %p)\n", This
, Range
, InRange
);
309 static HRESULT WINAPI
HTMLTxtRange_isEqual(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
310 VARIANT_BOOL
*IsEqual
)
312 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
313 FIXME("(%p)->(%p %p)\n", This
, Range
, IsEqual
);
317 static HRESULT WINAPI
HTMLTxtRange_scrollIntoView(IHTMLTxtRange
*iface
, VARIANT_BOOL fStart
)
319 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
320 FIXME("(%p)->(%x)\n", This
, fStart
);
324 static HRESULT WINAPI
HTMLTxtRange_collapse(IHTMLTxtRange
*iface
, VARIANT_BOOL Start
)
326 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
328 TRACE("(%p)->(%x)\n", This
, Start
);
330 nsIDOMRange_Collapse(This
->nsrange
, Start
!= VARIANT_FALSE
);
334 static HRESULT WINAPI
HTMLTxtRange_expand(IHTMLTxtRange
*iface
, BSTR Unit
, VARIANT_BOOL
*Success
)
336 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
337 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(Unit
), Success
);
341 static HRESULT WINAPI
HTMLTxtRange_move(IHTMLTxtRange
*iface
, BSTR Unit
,
342 long Count
, long *ActualCount
)
344 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
345 FIXME("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
349 static HRESULT WINAPI
HTMLTxtRange_moveStart(IHTMLTxtRange
*iface
, BSTR Unit
,
350 long Count
, long *ActualCount
)
352 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
353 FIXME("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
357 static HRESULT WINAPI
HTMLTxtRange_moveEnd(IHTMLTxtRange
*iface
, BSTR Unit
,
358 long Count
, long *ActualCount
)
360 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
361 FIXME("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
365 static HRESULT WINAPI
HTMLTxtRange_select(IHTMLTxtRange
*iface
)
367 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
369 TRACE("(%p)\n", This
);
371 if(This
->doc
->nscontainer
) {
372 nsIDOMWindow
*dom_window
= NULL
;
373 nsISelection
*nsselection
;
375 nsIWebBrowser_GetContentDOMWindow(This
->doc
->nscontainer
->webbrowser
, &dom_window
);
376 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
377 nsIDOMWindow_Release(dom_window
);
379 nsISelection_RemoveAllRanges(nsselection
);
380 nsISelection_AddRange(nsselection
, This
->nsrange
);
382 nsISelection_Release(nsselection
);
388 static HRESULT WINAPI
HTMLTxtRange_pasteHTML(IHTMLTxtRange
*iface
, BSTR html
)
390 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
391 FIXME("(%p)->(%s)\n", This
, debugstr_w(html
));
395 static HRESULT WINAPI
HTMLTxtRange_moveToElementText(IHTMLTxtRange
*iface
, IHTMLElement
*element
)
397 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
398 FIXME("(%p)->(%p)\n", This
, element
);
402 static HRESULT WINAPI
HTMLTxtRange_setEndPoint(IHTMLTxtRange
*iface
, BSTR how
,
403 IHTMLTxtRange
*SourceRange
)
405 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
406 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(how
), SourceRange
);
410 static HRESULT WINAPI
HTMLTxtRange_compareEndPoints(IHTMLTxtRange
*iface
, BSTR how
,
411 IHTMLTxtRange
*SourceRange
, long *ret
)
413 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
414 HTMLTxtRange
*src_range
;
419 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(how
), SourceRange
, ret
);
421 nscmpt
= string_to_nscmptype(how
);
425 src_range
= get_range_object(This
->doc
, SourceRange
);
429 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, nscmpt
, src_range
->nsrange
, &nsret
);
431 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
437 static HRESULT WINAPI
HTMLTxtRange_findText(IHTMLTxtRange
*iface
, BSTR String
,
438 long count
, long Flags
, VARIANT_BOOL
*Success
)
440 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
441 FIXME("(%p)->(%s %ld %08lx %p)\n", This
, debugstr_w(String
), count
, Flags
, Success
);
445 static HRESULT WINAPI
HTMLTxtRange_moveToPoint(IHTMLTxtRange
*iface
, long x
, long y
)
447 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
448 FIXME("(%p)->(%ld %ld)\n", This
, x
, y
);
452 static HRESULT WINAPI
HTMLTxtRange_getBookmark(IHTMLTxtRange
*iface
, BSTR
*Bookmark
)
454 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
455 FIXME("(%p)->(%p)\n", This
, Bookmark
);
459 static HRESULT WINAPI
HTMLTxtRange_moveToBookmark(IHTMLTxtRange
*iface
, BSTR Bookmark
,
460 VARIANT_BOOL
*Success
)
462 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
463 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(Bookmark
), Success
);
467 static HRESULT WINAPI
HTMLTxtRange_queryCommandSupported(IHTMLTxtRange
*iface
, BSTR cmdID
,
470 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
471 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
475 static HRESULT WINAPI
HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange
*iface
, BSTR cmdID
,
478 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
479 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
483 static HRESULT WINAPI
HTMLTxtRange_queryCommandState(IHTMLTxtRange
*iface
, BSTR cmdID
,
486 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
487 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
491 static HRESULT WINAPI
HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange
*iface
, BSTR cmdID
,
494 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
495 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
499 static HRESULT WINAPI
HTMLTxtRange_queryCommandText(IHTMLTxtRange
*iface
, BSTR cmdID
,
502 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
503 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdText
);
507 static HRESULT WINAPI
HTMLTxtRange_queryCommandValue(IHTMLTxtRange
*iface
, BSTR cmdID
,
510 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
511 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdValue
);
515 static HRESULT WINAPI
HTMLTxtRange_execCommand(IHTMLTxtRange
*iface
, BSTR cmdID
,
516 VARIANT_BOOL showUI
, VARIANT value
, VARIANT_BOOL
*pfRet
)
518 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
519 FIXME("(%p)->(%s %x v %p)\n", This
, debugstr_w(cmdID
), showUI
, pfRet
);
523 static HRESULT WINAPI
HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange
*iface
, BSTR cmdID
,
526 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
527 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
531 #undef HTMLTXTRANGE_THIS
533 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl
= {
534 HTMLTxtRange_QueryInterface
,
536 HTMLTxtRange_Release
,
537 HTMLTxtRange_GetTypeInfoCount
,
538 HTMLTxtRange_GetTypeInfo
,
539 HTMLTxtRange_GetIDsOfNames
,
541 HTMLTxtRange_get_htmlText
,
542 HTMLTxtRange_put_text
,
543 HTMLTxtRange_get_text
,
544 HTMLTxtRange_parentElement
,
545 HTMLTxtRange_duplicate
,
546 HTMLTxtRange_inRange
,
547 HTMLTxtRange_isEqual
,
548 HTMLTxtRange_scrollIntoView
,
549 HTMLTxtRange_collapse
,
552 HTMLTxtRange_moveStart
,
553 HTMLTxtRange_moveEnd
,
555 HTMLTxtRange_pasteHTML
,
556 HTMLTxtRange_moveToElementText
,
557 HTMLTxtRange_setEndPoint
,
558 HTMLTxtRange_compareEndPoints
,
559 HTMLTxtRange_findText
,
560 HTMLTxtRange_moveToPoint
,
561 HTMLTxtRange_getBookmark
,
562 HTMLTxtRange_moveToBookmark
,
563 HTMLTxtRange_queryCommandSupported
,
564 HTMLTxtRange_queryCommandEnabled
,
565 HTMLTxtRange_queryCommandState
,
566 HTMLTxtRange_queryCommandIndeterm
,
567 HTMLTxtRange_queryCommandText
,
568 HTMLTxtRange_queryCommandValue
,
569 HTMLTxtRange_execCommand
,
570 HTMLTxtRange_execCommandShowHelp
573 IHTMLTxtRange
*HTMLTxtRange_Create(HTMLDocument
*doc
, nsIDOMRange
*nsrange
)
575 HTMLTxtRange
*ret
= mshtml_alloc(sizeof(HTMLTxtRange
));
577 ret
->lpHTMLTxtRangeVtbl
= &HTMLTxtRangeVtbl
;
581 nsIDOMRange_AddRef(nsrange
);
582 ret
->nsrange
= nsrange
;
585 list_add_head(&doc
->range_list
, &ret
->entry
);
587 return HTMLTXTRANGE(ret
);
590 void detach_ranges(HTMLDocument
*This
)
594 LIST_FOR_EACH_ENTRY(iter
, &This
->range_list
, HTMLTxtRange
, entry
) {