shell32: Add printers CLSID to test, clean up a bit.
[wine/testsucceed.git] / dlls / mshtml / selection.c
blob4c670a6063d90db39c207ebeab8dd3b5ddbae3f3
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 const IHTMLSelectionObjectVtbl *lpHTMLSelectionObjectVtbl;
38 LONG ref;
40 nsISelection *nsselection;
41 HTMLDocumentNode *doc;
43 struct list entry;
44 } HTMLSelectionObject;
46 #define HTMLSELOBJ(x) ((IHTMLSelectionObject*) &(x)->lpHTMLSelectionObjectVtbl)
48 #define HTMLSELOBJ_THIS(iface) DEFINE_THIS(HTMLSelectionObject, HTMLSelectionObject, iface)
50 static HRESULT WINAPI HTMLSelectionObject_QueryInterface(IHTMLSelectionObject *iface,
51 REFIID riid, void **ppv)
53 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
55 *ppv = NULL;
57 if(IsEqualGUID(&IID_IUnknown, riid)) {
58 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
59 *ppv = HTMLSELOBJ(This);
60 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
61 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
62 *ppv = HTMLSELOBJ(This);
63 }else if(IsEqualGUID(&IID_IHTMLSelectionObject, riid)) {
64 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
65 *ppv = HTMLSELOBJ(This);
68 if(*ppv) {
69 IUnknown_AddRef((IUnknown*)*ppv);
70 return S_OK;
73 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
74 return E_NOINTERFACE;
77 static ULONG WINAPI HTMLSelectionObject_AddRef(IHTMLSelectionObject *iface)
79 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
80 LONG ref = InterlockedIncrement(&This->ref);
82 TRACE("(%p) ref=%d\n", This, ref);
84 return ref;
87 static ULONG WINAPI HTMLSelectionObject_Release(IHTMLSelectionObject *iface)
89 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
90 LONG ref = InterlockedDecrement(&This->ref);
92 TRACE("(%p) ref=%d\n", This, ref);
94 if(!ref) {
95 if(This->nsselection)
96 nsISelection_Release(This->nsselection);
97 if(This->doc)
98 list_remove(&This->entry);
99 heap_free(This);
102 return ref;
105 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
107 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
108 FIXME("(%p)->(%p)\n", This, pctinfo);
109 return E_NOTIMPL;
112 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject *iface, UINT iTInfo,
113 LCID lcid, ITypeInfo **ppTInfo)
115 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
116 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
117 return E_NOTIMPL;
120 static HRESULT WINAPI HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject *iface, REFIID riid,
121 LPOLESTR *rgszNames, UINT cNames,
122 LCID lcid, DISPID *rgDispId)
124 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
125 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
126 lcid, rgDispId);
127 return E_NOTIMPL;
130 static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DISPID dispIdMember,
131 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
132 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
134 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
135 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
136 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
137 return E_NOTIMPL;
140 static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
142 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
143 IHTMLTxtRange *range_obj = NULL;
144 nsIDOMRange *nsrange = NULL;
145 HRESULT hres;
147 TRACE("(%p)->(%p)\n", This, range);
149 if(This->nsselection) {
150 PRInt32 nsrange_cnt = 0;
151 nsresult nsres;
153 nsISelection_GetRangeCount(This->nsselection, &nsrange_cnt);
154 if(!nsrange_cnt) {
155 nsIDOMHTMLElement *nsbody = NULL;
157 TRACE("nsrange_cnt = 0\n");
159 if(!This->doc->nsdoc) {
160 WARN("nsdoc is NULL\n");
161 return E_UNEXPECTED;
164 nsres = nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nsbody);
165 if(NS_FAILED(nsres) || !nsbody) {
166 ERR("Could not get body: %08x\n", nsres);
167 return E_FAIL;
170 nsres = nsISelection_Collapse(This->nsselection, (nsIDOMNode*)nsbody, 0);
171 nsIDOMHTMLElement_Release(nsbody);
172 if(NS_FAILED(nsres))
173 ERR("Collapse failed: %08x\n", nsres);
174 }else if(nsrange_cnt > 1) {
175 FIXME("range_cnt = %d\n", nsrange_cnt);
178 nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange);
179 if(NS_FAILED(nsres))
180 ERR("GetRangeAt failed: %08x\n", nsres);
183 hres = HTMLTxtRange_Create(This->doc, nsrange, &range_obj);
185 if (nsrange) nsIDOMRange_Release(nsrange);
186 *range = (IDispatch*)range_obj;
187 return hres;
190 static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
192 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
193 FIXME("(%p)\n", This);
194 return E_NOTIMPL;
197 static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
199 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
200 FIXME("(%p)\n", This);
201 return E_NOTIMPL;
204 static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
206 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
207 PRBool collapsed = TRUE;
209 static const WCHAR wszNone[] = {'N','o','n','e',0};
210 static const WCHAR wszText[] = {'T','e','x','t',0};
212 TRACE("(%p)->(%p)\n", This, p);
214 if(This->nsselection)
215 nsISelection_GetIsCollapsed(This->nsselection, &collapsed);
217 *p = SysAllocString(collapsed ? wszNone : wszText); /* FIXME: control */
218 TRACE("ret %s\n", debugstr_w(*p));
219 return S_OK;
222 #undef HTMLSELOBJ_THIS
224 static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl = {
225 HTMLSelectionObject_QueryInterface,
226 HTMLSelectionObject_AddRef,
227 HTMLSelectionObject_Release,
228 HTMLSelectionObject_GetTypeInfoCount,
229 HTMLSelectionObject_GetTypeInfo,
230 HTMLSelectionObject_GetIDsOfNames,
231 HTMLSelectionObject_Invoke,
232 HTMLSelectionObject_createRange,
233 HTMLSelectionObject_empty,
234 HTMLSelectionObject_clear,
235 HTMLSelectionObject_get_type
238 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode *doc, nsISelection *nsselection, IHTMLSelectionObject **ret)
240 HTMLSelectionObject *selection;
242 selection = heap_alloc(sizeof(HTMLSelectionObject));
243 if(!selection)
244 return E_OUTOFMEMORY;
246 selection->lpHTMLSelectionObjectVtbl = &HTMLSelectionObjectVtbl;
247 selection->ref = 1;
248 selection->nsselection = nsselection; /* We shouldn't call AddRef here */
250 selection->doc = doc;
251 list_add_head(&doc->selection_list, &selection->entry);
253 *ret = HTMLSELOBJ(selection);
254 return S_OK;
257 void detach_selection(HTMLDocumentNode *This)
259 HTMLSelectionObject *iter;
261 LIST_FOR_EACH_ENTRY(iter, &This->selection_list, HTMLSelectionObject, entry) {
262 iter->doc = NULL;