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 IHTMLSelectionObjectVtbl
*lpHTMLSelectionObjectVtbl
;
44 nsISelection
*nsselection
;
48 } HTMLSelectionObject
;
50 #define HTMLSELOBJ(x) ((IHTMLSelectionObject*) &(x)->lpHTMLSelectionObjectVtbl)
52 #define HTMLSELOBJ_THIS(iface) DEFINE_THIS(HTMLSelectionObject, HTMLSelectionObject, iface)
54 static HRESULT WINAPI
HTMLSelectionObject_QueryInterface(IHTMLSelectionObject
*iface
,
55 REFIID riid
, void **ppv
)
57 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
61 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
62 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
63 *ppv
= HTMLSELOBJ(This
);
64 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
65 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
66 *ppv
= HTMLSELOBJ(This
);
67 }else if(IsEqualGUID(&IID_IHTMLSelectionObject
, riid
)) {
68 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
69 *ppv
= HTMLSELOBJ(This
);
73 IUnknown_AddRef((IUnknown
*)*ppv
);
77 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
81 static ULONG WINAPI
HTMLSelectionObject_AddRef(IHTMLSelectionObject
*iface
)
83 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
84 LONG ref
= InterlockedIncrement(&This
->ref
);
86 TRACE("(%p) ref=%d\n", This
, ref
);
91 static ULONG WINAPI
HTMLSelectionObject_Release(IHTMLSelectionObject
*iface
)
93 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
94 LONG ref
= InterlockedDecrement(&This
->ref
);
96 TRACE("(%p) ref=%d\n", This
, ref
);
100 nsISelection_Release(This
->nsselection
);
102 list_remove(&This
->entry
);
109 static HRESULT WINAPI
HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject
*iface
, UINT
*pctinfo
)
111 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
112 FIXME("(%p)->(%p)\n", This
, pctinfo
);
116 static HRESULT WINAPI
HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject
*iface
, UINT iTInfo
,
117 LCID lcid
, ITypeInfo
**ppTInfo
)
119 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
120 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
124 static HRESULT WINAPI
HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject
*iface
, REFIID riid
,
125 LPOLESTR
*rgszNames
, UINT cNames
,
126 LCID lcid
, DISPID
*rgDispId
)
128 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
129 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
134 static HRESULT WINAPI
HTMLSelectionObject_Invoke(IHTMLSelectionObject
*iface
, DISPID dispIdMember
,
135 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
136 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
138 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
139 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
140 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
144 static HRESULT WINAPI
HTMLSelectionObject_createRange(IHTMLSelectionObject
*iface
, IDispatch
**range
)
146 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
147 nsIDOMRange
*nsrange
= NULL
;
149 TRACE("(%p)->(%p)\n", This
, range
);
151 if(This
->nsselection
) {
152 PRInt32 nsrange_cnt
= 0;
155 nsISelection_GetRangeCount(This
->nsselection
, &nsrange_cnt
);
157 FIXME("range_cnt = %d\n", nsrange_cnt
);
159 nsres
= nsISelection_GetRangeAt(This
->nsselection
, 0, &nsrange
);
161 ERR("GetRangeAt failed: %08x\n", nsres
);
164 *range
= (IDispatch
*)HTMLTxtRange_Create(This
->doc
, nsrange
);
168 static HRESULT WINAPI
HTMLSelectionObject_empty(IHTMLSelectionObject
*iface
)
170 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
171 FIXME("(%p)\n", This
);
175 static HRESULT WINAPI
HTMLSelectionObject_clear(IHTMLSelectionObject
*iface
)
177 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
178 FIXME("(%p)\n", This
);
182 static HRESULT WINAPI
HTMLSelectionObject_get_type(IHTMLSelectionObject
*iface
, BSTR
*p
)
184 HTMLSelectionObject
*This
= HTMLSELOBJ_THIS(iface
);
185 PRBool collapsed
= TRUE
;
187 static const WCHAR wszNone
[] = {'N','o','n','e',0};
188 static const WCHAR wszText
[] = {'T','e','x','t',0};
190 TRACE("(%p)->(%p)\n", This
, p
);
192 if(This
->nsselection
)
193 nsISelection_GetIsCollapsed(This
->nsselection
, &collapsed
);
195 *p
= SysAllocString(collapsed
? wszNone
: wszText
); /* FIXME: control */
196 TRACE("ret %s\n", debugstr_w(*p
));
200 #undef HTMLSELOBJ_THIS
202 static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl
= {
203 HTMLSelectionObject_QueryInterface
,
204 HTMLSelectionObject_AddRef
,
205 HTMLSelectionObject_Release
,
206 HTMLSelectionObject_GetTypeInfoCount
,
207 HTMLSelectionObject_GetTypeInfo
,
208 HTMLSelectionObject_GetIDsOfNames
,
209 HTMLSelectionObject_Invoke
,
210 HTMLSelectionObject_createRange
,
211 HTMLSelectionObject_empty
,
212 HTMLSelectionObject_clear
,
213 HTMLSelectionObject_get_type
216 IHTMLSelectionObject
*HTMLSelectionObject_Create(HTMLDocument
*doc
, nsISelection
*nsselection
)
218 HTMLSelectionObject
*ret
= mshtml_alloc(sizeof(HTMLSelectionObject
));
220 ret
->lpHTMLSelectionObjectVtbl
= &HTMLSelectionObjectVtbl
;
222 ret
->nsselection
= nsselection
; /* We shouldn't call AddRef here */
225 list_add_head(&doc
->selection_list
, &ret
->entry
);
227 return HTMLSELOBJ(ret
);
230 void detach_selection(HTMLDocument
*This
)
232 HTMLSelectionObject
*iter
;
234 LIST_FOR_EACH_ENTRY(iter
, &This
->selection_list
, HTMLSelectionObject
, entry
) {