mshtml: Use GetIsCollapsed in IHTMLSelectionObject::get_type.
[wine.git] / dlls / mshtml / selection.c
blobfe191f46a8db5b228c856f1d03991ed3f902bd48
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 } HTMLSelectionObject;
47 #define HTMLSELOBJ(x) ((IHTMLSelectionObject*) &(x)->lpHTMLSelectionObjectVtbl)
49 #define HTMLSELOBJ_THIS(iface) DEFINE_THIS(HTMLSelectionObject, HTMLSelectionObject, iface)
51 static HRESULT WINAPI HTMLSelectionObject_QueryInterface(IHTMLSelectionObject *iface,
52 REFIID riid, void **ppv)
54 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
56 *ppv = NULL;
58 if(IsEqualGUID(&IID_IUnknown, riid)) {
59 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
60 *ppv = HTMLSELOBJ(This);
61 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
62 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
63 *ppv = HTMLSELOBJ(This);
64 }else if(IsEqualGUID(&IID_IHTMLSelectionObject, riid)) {
65 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
66 *ppv = HTMLSELOBJ(This);
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 = HTMLSELOBJ_THIS(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 = HTMLSELOBJ_THIS(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 mshtml_free(This);
101 return ref;
104 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
106 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
107 FIXME("(%p)->(%p)\n", This, pctinfo);
108 return E_NOTIMPL;
111 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject *iface, UINT iTInfo,
112 LCID lcid, ITypeInfo **ppTInfo)
114 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
115 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
116 return E_NOTIMPL;
119 static HRESULT WINAPI HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject *iface, REFIID riid,
120 LPOLESTR *rgszNames, UINT cNames,
121 LCID lcid, DISPID *rgDispId)
123 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
124 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
125 lcid, rgDispId);
126 return E_NOTIMPL;
129 static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DISPID dispIdMember,
130 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
131 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
133 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
134 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
135 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
136 return E_NOTIMPL;
139 static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
141 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
142 nsIDOMRange *nsrange = NULL;
144 TRACE("(%p)->(%p)\n", This, range);
146 if(This->nsselection) {
147 PRInt32 nsrange_cnt = 0;
148 nsresult nsres;
150 nsISelection_GetRangeCount(This->nsselection, &nsrange_cnt);
151 if(nsrange_cnt != 1)
152 FIXME("range_cnt = %d\n", nsrange_cnt);
154 nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange);
155 if(NS_FAILED(nsres))
156 ERR("GetRangeAt failed: %08x\n", nsres);
159 *range = (IDispatch*)HTMLTxtRange_Create(nsrange);
160 return S_OK;
163 static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
165 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
166 FIXME("(%p)\n", This);
167 return E_NOTIMPL;
170 static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
172 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
173 FIXME("(%p)\n", This);
174 return E_NOTIMPL;
177 static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
179 HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
180 PRBool collapsed = TRUE;
182 static const WCHAR wszNone[] = {'N','o','n','e',0};
183 static const WCHAR wszText[] = {'T','e','x','t',0};
185 TRACE("(%p)->(%p)\n", This, p);
187 if(This->nsselection)
188 nsISelection_GetIsCollapsed(This->nsselection, &collapsed);
190 *p = SysAllocString(collapsed ? wszNone : wszText); /* FIXME: control */
191 TRACE("ret %s\n", debugstr_w(*p));
192 return S_OK;
195 #undef HTMLSELOBJ_THIS
197 static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl = {
198 HTMLSelectionObject_QueryInterface,
199 HTMLSelectionObject_AddRef,
200 HTMLSelectionObject_Release,
201 HTMLSelectionObject_GetTypeInfoCount,
202 HTMLSelectionObject_GetTypeInfo,
203 HTMLSelectionObject_GetIDsOfNames,
204 HTMLSelectionObject_Invoke,
205 HTMLSelectionObject_createRange,
206 HTMLSelectionObject_empty,
207 HTMLSelectionObject_clear,
208 HTMLSelectionObject_get_type
211 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection *nsselection)
213 HTMLSelectionObject *ret = mshtml_alloc(sizeof(HTMLSelectionObject));
215 ret->lpHTMLSelectionObjectVtbl = &HTMLSelectionObjectVtbl;
216 ret->ref = 1;
217 ret->nsselection = nsselection; /* We shouldn't call AddRef here */
219 return HTMLSELOBJ(ret);