mshtml: Pass HTMLDOMNode pointer to its destructor.
[wine.git] / dlls / mshtml / selection.c
blob4139d3b04c3221657d8e06e7de3cb299ab2ee7ce
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 typedef struct {
40 const IHTMLSelectionObjectVtbl *lpHTMLSelectionObjectVtbl;
42 LONG ref;
44 nsISelection *nsselection;
45 HTMLDocument *doc;
47 struct list entry;
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);
59 *ppv = NULL;
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);
72 if(*ppv) {
73 IUnknown_AddRef((IUnknown*)*ppv);
74 return S_OK;
77 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
78 return E_NOINTERFACE;
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);
88 return 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);
98 if(!ref) {
99 if(This->nsselection)
100 nsISelection_Release(This->nsselection);
101 if(This->doc)
102 list_remove(&This->entry);
103 mshtml_free(This);
106 return ref;
109 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
111 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
112 FIXME("(%p)->(%p)\n", This, pctinfo);
113 return E_NOTIMPL;
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);
121 return E_NOTIMPL;
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,
130 lcid, rgDispId);
131 return E_NOTIMPL;
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);
141 return E_NOTIMPL;
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;
153 nsresult nsres;
155 nsISelection_GetRangeCount(This->nsselection, &nsrange_cnt);
156 if(nsrange_cnt != 1)
157 FIXME("range_cnt = %d\n", nsrange_cnt);
159 nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange);
160 if(NS_FAILED(nsres))
161 ERR("GetRangeAt failed: %08x\n", nsres);
164 *range = (IDispatch*)HTMLTxtRange_Create(This->doc, nsrange);
165 return S_OK;
168 static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
170 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
171 FIXME("(%p)\n", This);
172 return E_NOTIMPL;
175 static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
177 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
178 FIXME("(%p)\n", This);
179 return E_NOTIMPL;
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));
197 return S_OK;
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;
221 ret->ref = 1;
222 ret->nsselection = nsselection; /* We shouldn't call AddRef here */
224 ret->doc = doc;
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) {
235 iter->doc = NULL;