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 nsIDOMDocument *nsdoc;
158 nsIDOMHTMLDocument *nshtmldoc;
159 nsIDOMHTMLElement *nsbody = NULL;
161 TRACE("nsrange_cnt = 0\n");
163 nsres = nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
164 if(NS_FAILED(nsres) || !nsdoc) {
165 ERR("GetDocument failed: %08x\n", nsres);
169 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
170 nsIDOMDocument_Release(nsdoc);
172 nsres = nsIDOMHTMLDocument_GetBody(nshtmldoc, &nsbody);
173 nsIDOMHTMLDocument_Release(nshtmldoc);
174 if(NS_FAILED(nsres) || !nsbody) {
175 ERR("Could not get body: %08x\n", nsres);
179 nsres = nsISelection_Collapse(This->nsselection, (nsIDOMNode*)nsbody, 0);
180 nsIDOMHTMLElement_Release(nsbody);
182 ERR("Collapse failed: %08x\n", nsres);
183 }else if(nsrange_cnt > 1) {
184 FIXME("range_cnt = %d\n", nsrange_cnt);
187 nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange);
189 ERR("GetRangeAt failed: %08x\n", nsres);
192 *range = (IDispatch*)HTMLTxtRange_Create(This->doc, nsrange);
196 static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
198 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
199 FIXME("(%p)\n", This);
203 static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
205 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
206 FIXME("(%p)\n", This);
210 static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
212 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
213 PRBool collapsed = TRUE;
215 static const WCHAR wszNone[] = {'N','o','n','e',0};
216 static const WCHAR wszText[] = {'T','e','x','t',0};
218 TRACE("(%p)->(%p)\n", This, p);
220 if(This->nsselection)
221 nsISelection_GetIsCollapsed(This->nsselection, &collapsed);
223 *p = SysAllocString(collapsed ? wszNone : wszText); /* FIXME: control */
224 TRACE("ret %s\n", debugstr_w(*p));
228 #undef HTMLSELOBJ_THIS
230 static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl = {
231 HTMLSelectionObject_QueryInterface,
232 HTMLSelectionObject_AddRef,
233 HTMLSelectionObject_Release,
234 HTMLSelectionObject_GetTypeInfoCount,
235 HTMLSelectionObject_GetTypeInfo,
236 HTMLSelectionObject_GetIDsOfNames,
237 HTMLSelectionObject_Invoke,
238 HTMLSelectionObject_createRange,
239 HTMLSelectionObject_empty,
240 HTMLSelectionObject_clear,
241 HTMLSelectionObject_get_type
244 IHTMLSelectionObject *HTMLSelectionObject_Create(HTMLDocument *doc, nsISelection *nsselection)
246 HTMLSelectionObject *ret = heap_alloc(sizeof(HTMLSelectionObject));
248 ret->lpHTMLSelectionObjectVtbl = &HTMLSelectionObjectVtbl;
250 ret->nsselection = nsselection; /* We shouldn't call AddRef here */
253 list_add_head(&doc->selection_list, &ret->entry);
255 return HTMLSELOBJ(ret);
258 void detach_selection(HTMLDocument *This)
260 HTMLSelectionObject *iter;
262 LIST_FOR_EACH_ENTRY(iter, &This->selection_list, HTMLSelectionObject, entry) {