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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
36 IHTMLSelectionObject IHTMLSelectionObject_iface
;
37 IHTMLSelectionObject2 IHTMLSelectionObject2_iface
;
41 nsISelection
*nsselection
;
42 HTMLDocumentNode
*doc
;
45 } HTMLSelectionObject
;
47 static inline HTMLSelectionObject
*impl_from_IHTMLSelectionObject(IHTMLSelectionObject
*iface
)
49 return CONTAINING_RECORD(iface
, HTMLSelectionObject
, IHTMLSelectionObject_iface
);
52 static HRESULT WINAPI
HTMLSelectionObject_QueryInterface(IHTMLSelectionObject
*iface
,
53 REFIID riid
, void **ppv
)
55 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
57 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
59 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
60 *ppv
= &This
->IHTMLSelectionObject_iface
;
61 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
62 *ppv
= &This
->IHTMLSelectionObject_iface
;
63 }else if(IsEqualGUID(&IID_IHTMLSelectionObject
, riid
)) {
64 *ppv
= &This
->IHTMLSelectionObject_iface
;
65 }else if(IsEqualGUID(&IID_IHTMLSelectionObject2
, riid
)) {
66 *ppv
= &This
->IHTMLSelectionObject2_iface
;
67 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
68 return *ppv
? S_OK
: E_NOINTERFACE
;
71 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
75 IUnknown_AddRef((IUnknown
*)*ppv
);
79 static ULONG WINAPI
HTMLSelectionObject_AddRef(IHTMLSelectionObject
*iface
)
81 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
82 LONG ref
= InterlockedIncrement(&This
->ref
);
84 TRACE("(%p) ref=%d\n", This
, ref
);
89 static ULONG WINAPI
HTMLSelectionObject_Release(IHTMLSelectionObject
*iface
)
91 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
92 LONG ref
= InterlockedDecrement(&This
->ref
);
94 TRACE("(%p) ref=%d\n", This
, ref
);
98 nsISelection_Release(This
->nsselection
);
100 list_remove(&This
->entry
);
101 release_dispex(&This
->dispex
);
108 static HRESULT WINAPI
HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject
*iface
, UINT
*pctinfo
)
110 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
112 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
115 static HRESULT WINAPI
HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject
*iface
, UINT iTInfo
,
116 LCID lcid
, ITypeInfo
**ppTInfo
)
118 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
120 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
123 static HRESULT WINAPI
HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject
*iface
, REFIID riid
,
124 LPOLESTR
*rgszNames
, UINT cNames
,
125 LCID lcid
, DISPID
*rgDispId
)
127 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
129 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
,
130 cNames
, lcid
, rgDispId
);
133 static HRESULT WINAPI
HTMLSelectionObject_Invoke(IHTMLSelectionObject
*iface
, DISPID dispIdMember
,
134 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
135 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
137 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
140 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
141 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
144 static HRESULT WINAPI
HTMLSelectionObject_createRange(IHTMLSelectionObject
*iface
, IDispatch
**range
)
146 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
147 IHTMLTxtRange
*range_obj
= NULL
;
148 nsIDOMRange
*nsrange
= NULL
;
151 TRACE("(%p)->(%p)\n", This
, range
);
153 if(This
->nsselection
) {
154 LONG nsrange_cnt
= 0;
157 nsISelection_GetRangeCount(This
->nsselection
, &nsrange_cnt
);
159 nsIDOMHTMLElement
*nsbody
= NULL
;
161 TRACE("nsrange_cnt = 0\n");
163 if(!This
->doc
->nsdoc
) {
164 WARN("nsdoc is NULL\n");
168 nsres
= nsIDOMHTMLDocument_GetBody(This
->doc
->nsdoc
, &nsbody
);
169 if(NS_FAILED(nsres
) || !nsbody
) {
170 ERR("Could not get body: %08x\n", nsres
);
174 nsres
= nsISelection_Collapse(This
->nsselection
, (nsIDOMNode
*)nsbody
, 0);
175 nsIDOMHTMLElement_Release(nsbody
);
177 ERR("Collapse failed: %08x\n", nsres
);
178 }else if(nsrange_cnt
> 1) {
179 FIXME("range_cnt = %d\n", nsrange_cnt
);
182 nsres
= nsISelection_GetRangeAt(This
->nsselection
, 0, &nsrange
);
184 ERR("GetRangeAt failed: %08x\n", nsres
);
187 hres
= HTMLTxtRange_Create(This
->doc
, nsrange
, &range_obj
);
189 if (nsrange
) nsIDOMRange_Release(nsrange
);
190 *range
= (IDispatch
*)range_obj
;
194 static HRESULT WINAPI
HTMLSelectionObject_empty(IHTMLSelectionObject
*iface
)
196 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
197 FIXME("(%p)\n", This
);
201 static HRESULT WINAPI
HTMLSelectionObject_clear(IHTMLSelectionObject
*iface
)
203 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
204 FIXME("(%p)\n", This
);
208 static HRESULT WINAPI
HTMLSelectionObject_get_type(IHTMLSelectionObject
*iface
, BSTR
*p
)
210 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject(iface
);
211 cpp_bool collapsed
= TRUE
;
213 TRACE("(%p)->(%p)\n", This
, p
);
215 if(This
->nsselection
)
216 nsISelection_GetIsCollapsed(This
->nsselection
, &collapsed
);
218 *p
= SysAllocString(collapsed
? L
"None" : L
"Text"); /* FIXME: control */
219 TRACE("ret %s\n", debugstr_w(*p
));
223 static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl
= {
224 HTMLSelectionObject_QueryInterface
,
225 HTMLSelectionObject_AddRef
,
226 HTMLSelectionObject_Release
,
227 HTMLSelectionObject_GetTypeInfoCount
,
228 HTMLSelectionObject_GetTypeInfo
,
229 HTMLSelectionObject_GetIDsOfNames
,
230 HTMLSelectionObject_Invoke
,
231 HTMLSelectionObject_createRange
,
232 HTMLSelectionObject_empty
,
233 HTMLSelectionObject_clear
,
234 HTMLSelectionObject_get_type
237 static inline HTMLSelectionObject
*impl_from_IHTMLSelectionObject2(IHTMLSelectionObject2
*iface
)
239 return CONTAINING_RECORD(iface
, HTMLSelectionObject
, IHTMLSelectionObject2_iface
);
242 static HRESULT WINAPI
HTMLSelectionObject2_QueryInterface(IHTMLSelectionObject2
*iface
, REFIID riid
, void **ppv
)
244 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
246 return IHTMLSelectionObject_QueryInterface(&This
->IHTMLSelectionObject_iface
, riid
, ppv
);
249 static ULONG WINAPI
HTMLSelectionObject2_AddRef(IHTMLSelectionObject2
*iface
)
251 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
253 return IHTMLSelectionObject_AddRef(&This
->IHTMLSelectionObject_iface
);
256 static ULONG WINAPI
HTMLSelectionObject2_Release(IHTMLSelectionObject2
*iface
)
258 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
260 return IHTMLSelectionObject_Release(&This
->IHTMLSelectionObject_iface
);
263 static HRESULT WINAPI
HTMLSelectionObject2_GetTypeInfoCount(IHTMLSelectionObject2
*iface
, UINT
*pctinfo
)
265 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
267 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
270 static HRESULT WINAPI
HTMLSelectionObject2_GetTypeInfo(IHTMLSelectionObject2
*iface
, UINT iTInfo
,
271 LCID lcid
, ITypeInfo
**ppTInfo
)
273 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
275 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
278 static HRESULT WINAPI
HTMLSelectionObject2_GetIDsOfNames(IHTMLSelectionObject2
*iface
, REFIID riid
,
279 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
281 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
283 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
,
284 cNames
, lcid
, rgDispId
);
287 static HRESULT WINAPI
HTMLSelectionObject2_Invoke(IHTMLSelectionObject2
*iface
, DISPID dispIdMember
,
288 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
289 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
291 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
293 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
294 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
297 static HRESULT WINAPI
HTMLSelectionObject2_createRangeCollection(IHTMLSelectionObject2
*iface
, IDispatch
**rangeCollection
)
299 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
300 FIXME("(%p)->(%p)\n", This
, rangeCollection
);
304 static HRESULT WINAPI
HTMLSelectionObject2_get_typeDetail(IHTMLSelectionObject2
*iface
, BSTR
*p
)
306 HTMLSelectionObject
*This
= impl_from_IHTMLSelectionObject2(iface
);
308 FIXME("(%p)->(%p) semi-stub\n", This
, p
);
310 /* FIXME: We should try to use ISelectionServicesListener::GetTypeDetail here. */
311 *p
= SysAllocString(L
"undefined");
312 return *p
? S_OK
: E_OUTOFMEMORY
;
315 static const IHTMLSelectionObject2Vtbl HTMLSelectionObject2Vtbl
= {
316 HTMLSelectionObject2_QueryInterface
,
317 HTMLSelectionObject2_AddRef
,
318 HTMLSelectionObject2_Release
,
319 HTMLSelectionObject2_GetTypeInfoCount
,
320 HTMLSelectionObject2_GetTypeInfo
,
321 HTMLSelectionObject2_GetIDsOfNames
,
322 HTMLSelectionObject2_Invoke
,
323 HTMLSelectionObject2_createRangeCollection
,
324 HTMLSelectionObject2_get_typeDetail
327 static const tid_t HTMLSelectionObject_iface_tids
[] = {
328 IHTMLSelectionObject_tid
,
329 IHTMLSelectionObject2_tid
,
332 static dispex_static_data_t HTMLSelectionObject_dispex
= {
334 IHTMLSelectionObject_tid
, /* FIXME: We have a test for that, but it doesn't expose IHTMLSelectionObject2 iface. */
335 HTMLSelectionObject_iface_tids
338 HRESULT
HTMLSelectionObject_Create(HTMLDocumentNode
*doc
, nsISelection
*nsselection
, IHTMLSelectionObject
**ret
)
340 HTMLSelectionObject
*selection
;
342 selection
= heap_alloc(sizeof(HTMLSelectionObject
));
344 return E_OUTOFMEMORY
;
346 init_dispatch(&selection
->dispex
, (IUnknown
*)&selection
->IHTMLSelectionObject_iface
,
347 &HTMLSelectionObject_dispex
, dispex_compat_mode(&doc
->node
.event_target
.dispex
));
349 selection
->IHTMLSelectionObject_iface
.lpVtbl
= &HTMLSelectionObjectVtbl
;
350 selection
->IHTMLSelectionObject2_iface
.lpVtbl
= &HTMLSelectionObject2Vtbl
;
352 selection
->nsselection
= nsselection
; /* We shouldn't call AddRef here */
354 selection
->doc
= doc
;
355 list_add_head(&doc
->selection_list
, &selection
->entry
);
357 *ret
= &selection
->IHTMLSelectionObject_iface
;
361 void detach_selection(HTMLDocumentNode
*This
)
363 HTMLSelectionObject
*iter
, *next
;
365 LIST_FOR_EACH_ENTRY_SAFE(iter
, next
, &This
->selection_list
, HTMLSelectionObject
, entry
) {
367 list_remove(&iter
->entry
);