dinput/tests: Tests for EnumObjects with different types of device objects.
[wine/multimedia.git] / dlls / mshtml / selection.c
blob1ffc567faed95fe1bc3e20f3a95dea16ed3ce5cf
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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 typedef struct {
36 IHTMLSelectionObject IHTMLSelectionObject_iface;
38 LONG ref;
40 nsISelection *nsselection;
41 HTMLDocumentNode *doc;
43 struct list entry;
44 } HTMLSelectionObject;
46 static inline HTMLSelectionObject *impl_from_IHTMLSelectionObject(IHTMLSelectionObject *iface)
48 return CONTAINING_RECORD(iface, HTMLSelectionObject, IHTMLSelectionObject_iface);
51 static HRESULT WINAPI HTMLSelectionObject_QueryInterface(IHTMLSelectionObject *iface,
52 REFIID riid, void **ppv)
54 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
56 *ppv = NULL;
58 if(IsEqualGUID(&IID_IUnknown, riid)) {
59 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
60 *ppv = &This->IHTMLSelectionObject_iface;
61 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
62 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
63 *ppv = &This->IHTMLSelectionObject_iface;
64 }else if(IsEqualGUID(&IID_IHTMLSelectionObject, riid)) {
65 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
66 *ppv = &This->IHTMLSelectionObject_iface;
69 if(*ppv) {
70 IUnknown_AddRef((IUnknown*)*ppv);
71 return S_OK;
74 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
75 return E_NOINTERFACE;
78 static ULONG WINAPI HTMLSelectionObject_AddRef(IHTMLSelectionObject *iface)
80 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
81 LONG ref = InterlockedIncrement(&This->ref);
83 TRACE("(%p) ref=%d\n", This, ref);
85 return ref;
88 static ULONG WINAPI HTMLSelectionObject_Release(IHTMLSelectionObject *iface)
90 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
91 LONG ref = InterlockedDecrement(&This->ref);
93 TRACE("(%p) ref=%d\n", This, ref);
95 if(!ref) {
96 if(This->nsselection)
97 nsISelection_Release(This->nsselection);
98 if(This->doc)
99 list_remove(&This->entry);
100 heap_free(This);
103 return ref;
106 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
108 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
109 FIXME("(%p)->(%p)\n", This, pctinfo);
110 return E_NOTIMPL;
113 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject *iface, UINT iTInfo,
114 LCID lcid, ITypeInfo **ppTInfo)
116 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
117 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
118 return E_NOTIMPL;
121 static HRESULT WINAPI HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject *iface, REFIID riid,
122 LPOLESTR *rgszNames, UINT cNames,
123 LCID lcid, DISPID *rgDispId)
125 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
126 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
127 lcid, rgDispId);
128 return E_NOTIMPL;
131 static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DISPID dispIdMember,
132 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
133 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
135 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
136 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
137 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
138 return E_NOTIMPL;
141 static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
143 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
144 IHTMLTxtRange *range_obj = NULL;
145 nsIDOMRange *nsrange = NULL;
146 HRESULT hres;
148 TRACE("(%p)->(%p)\n", This, range);
150 if(This->nsselection) {
151 PRInt32 nsrange_cnt = 0;
152 nsresult nsres;
154 nsISelection_GetRangeCount(This->nsselection, &nsrange_cnt);
155 if(!nsrange_cnt) {
156 nsIDOMHTMLElement *nsbody = NULL;
158 TRACE("nsrange_cnt = 0\n");
160 if(!This->doc->nsdoc) {
161 WARN("nsdoc is NULL\n");
162 return E_UNEXPECTED;
165 nsres = nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nsbody);
166 if(NS_FAILED(nsres) || !nsbody) {
167 ERR("Could not get body: %08x\n", nsres);
168 return E_FAIL;
171 nsres = nsISelection_Collapse(This->nsselection, (nsIDOMNode*)nsbody, 0);
172 nsIDOMHTMLElement_Release(nsbody);
173 if(NS_FAILED(nsres))
174 ERR("Collapse failed: %08x\n", nsres);
175 }else if(nsrange_cnt > 1) {
176 FIXME("range_cnt = %d\n", nsrange_cnt);
179 nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange);
180 if(NS_FAILED(nsres))
181 ERR("GetRangeAt failed: %08x\n", nsres);
184 hres = HTMLTxtRange_Create(This->doc, nsrange, &range_obj);
186 if (nsrange) nsIDOMRange_Release(nsrange);
187 *range = (IDispatch*)range_obj;
188 return hres;
191 static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
193 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
194 FIXME("(%p)\n", This);
195 return E_NOTIMPL;
198 static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
200 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
201 FIXME("(%p)\n", This);
202 return E_NOTIMPL;
205 static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
207 HTMLSelectionObject *This = impl_from_IHTMLSelectionObject(iface);
208 PRBool collapsed = TRUE;
210 static const WCHAR wszNone[] = {'N','o','n','e',0};
211 static const WCHAR wszText[] = {'T','e','x','t',0};
213 TRACE("(%p)->(%p)\n", This, p);
215 if(This->nsselection)
216 nsISelection_GetIsCollapsed(This->nsselection, &collapsed);
218 *p = SysAllocString(collapsed ? wszNone : wszText); /* FIXME: control */
219 TRACE("ret %s\n", debugstr_w(*p));
220 return S_OK;
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 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode *doc, nsISelection *nsselection, IHTMLSelectionObject **ret)
239 HTMLSelectionObject *selection;
241 selection = heap_alloc(sizeof(HTMLSelectionObject));
242 if(!selection)
243 return E_OUTOFMEMORY;
245 selection->IHTMLSelectionObject_iface.lpVtbl = &HTMLSelectionObjectVtbl;
246 selection->ref = 1;
247 selection->nsselection = nsselection; /* We shouldn't call AddRef here */
249 selection->doc = doc;
250 list_add_head(&doc->selection_list, &selection->entry);
252 *ret = &selection->IHTMLSelectionObject_iface;
253 return S_OK;
256 void detach_selection(HTMLDocumentNode *This)
258 HTMLSelectionObject *iter;
260 LIST_FOR_EACH_ENTRY(iter, &This->selection_list, HTMLSelectionObject, entry) {
261 iter->doc = NULL;