ReactOS  0.4.13-dev-563-g0561610
selection.c
Go to the documentation of this file.
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include "mshtml_private.h"
20 
21 typedef struct {
23  IHTMLSelectionObject IHTMLSelectionObject_iface;
24  IHTMLSelectionObject2 IHTMLSelectionObject2_iface;
25 
27 
30 
31  struct list entry;
33 
34 static inline HTMLSelectionObject *impl_from_IHTMLSelectionObject(IHTMLSelectionObject *iface)
35 {
36  return CONTAINING_RECORD(iface, HTMLSelectionObject, IHTMLSelectionObject_iface);
37 }
38 
39 static HRESULT WINAPI HTMLSelectionObject_QueryInterface(IHTMLSelectionObject *iface,
40  REFIID riid, void **ppv)
41 {
43 
44  TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
45 
47  *ppv = &This->IHTMLSelectionObject_iface;
48  }else if(IsEqualGUID(&IID_IDispatch, riid)) {
49  *ppv = &This->IHTMLSelectionObject_iface;
50  }else if(IsEqualGUID(&IID_IHTMLSelectionObject, riid)) {
51  *ppv = &This->IHTMLSelectionObject_iface;
52  }else if(IsEqualGUID(&IID_IHTMLSelectionObject2, riid)) {
53  *ppv = &This->IHTMLSelectionObject2_iface;
54  }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
55  return *ppv ? S_OK : E_NOINTERFACE;
56  }else {
57  *ppv = NULL;
58  WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
59  return E_NOINTERFACE;
60  }
61 
62  IUnknown_AddRef((IUnknown*)*ppv);
63  return S_OK;
64 }
65 
66 static ULONG WINAPI HTMLSelectionObject_AddRef(IHTMLSelectionObject *iface)
67 {
70 
71  TRACE("(%p) ref=%d\n", This, ref);
72 
73  return ref;
74 }
75 
76 static ULONG WINAPI HTMLSelectionObject_Release(IHTMLSelectionObject *iface)
77 {
80 
81  TRACE("(%p) ref=%d\n", This, ref);
82 
83  if(!ref) {
84  if(This->nsselection)
85  nsISelection_Release(This->nsselection);
86  if(This->doc)
87  list_remove(&This->entry);
88  release_dispex(&This->dispex);
89  heap_free(This);
90  }
91 
92  return ref;
93 }
94 
95 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
96 {
98 
99  return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
100 }
101 
102 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject *iface, UINT iTInfo,
103  LCID lcid, ITypeInfo **ppTInfo)
104 {
106 
107  return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
108 }
109 
110 static HRESULT WINAPI HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject *iface, REFIID riid,
111  LPOLESTR *rgszNames, UINT cNames,
112  LCID lcid, DISPID *rgDispId)
113 {
115 
116  return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames,
117  cNames, lcid, rgDispId);
118 }
119 
120 static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DISPID dispIdMember,
121  REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
122  VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
123 {
125 
126 
127  return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid,
128  lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
129 }
130 
131 static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
132 {
134  IHTMLTxtRange *range_obj = NULL;
135  nsIDOMRange *nsrange = NULL;
136  HRESULT hres;
137 
138  TRACE("(%p)->(%p)\n", This, range);
139 
140  if(This->nsselection) {
141  LONG nsrange_cnt = 0;
142  nsresult nsres;
143 
144  nsISelection_GetRangeCount(This->nsselection, &nsrange_cnt);
145  if(!nsrange_cnt) {
146  nsIDOMHTMLElement *nsbody = NULL;
147 
148  TRACE("nsrange_cnt = 0\n");
149 
150  if(!This->doc->nsdoc) {
151  WARN("nsdoc is NULL\n");
152  return E_UNEXPECTED;
153  }
154 
155  nsres = nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nsbody);
156  if(NS_FAILED(nsres) || !nsbody) {
157  ERR("Could not get body: %08x\n", nsres);
158  return E_FAIL;
159  }
160 
161  nsres = nsISelection_Collapse(This->nsselection, (nsIDOMNode*)nsbody, 0);
162  nsIDOMHTMLElement_Release(nsbody);
163  if(NS_FAILED(nsres))
164  ERR("Collapse failed: %08x\n", nsres);
165  }else if(nsrange_cnt > 1) {
166  FIXME("range_cnt = %d\n", nsrange_cnt);
167  }
168 
169  nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange);
170  if(NS_FAILED(nsres))
171  ERR("GetRangeAt failed: %08x\n", nsres);
172  }
173 
174  hres = HTMLTxtRange_Create(This->doc, nsrange, &range_obj);
175 
176  if (nsrange) nsIDOMRange_Release(nsrange);
177  *range = (IDispatch*)range_obj;
178  return hres;
179 }
180 
181 static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
182 {
184  FIXME("(%p)\n", This);
185  return E_NOTIMPL;
186 }
187 
188 static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
189 {
191  FIXME("(%p)\n", This);
192  return E_NOTIMPL;
193 }
194 
195 static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
196 {
198  cpp_bool collapsed = TRUE;
199 
200  static const WCHAR wszNone[] = {'N','o','n','e',0};
201  static const WCHAR wszText[] = {'T','e','x','t',0};
202 
203  TRACE("(%p)->(%p)\n", This, p);
204 
205  if(This->nsselection)
206  nsISelection_GetIsCollapsed(This->nsselection, &collapsed);
207 
208  *p = SysAllocString(collapsed ? wszNone : wszText); /* FIXME: control */
209  TRACE("ret %s\n", debugstr_w(*p));
210  return S_OK;
211 }
212 
213 static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl = {
225 };
226 
227 static inline HTMLSelectionObject *impl_from_IHTMLSelectionObject2(IHTMLSelectionObject2 *iface)
228 {
229  return CONTAINING_RECORD(iface, HTMLSelectionObject, IHTMLSelectionObject2_iface);
230 }
231 
232 static HRESULT WINAPI HTMLSelectionObject2_QueryInterface(IHTMLSelectionObject2 *iface, REFIID riid, void **ppv)
233 {
235 
236  return IHTMLSelectionObject_QueryInterface(&This->IHTMLSelectionObject_iface, riid, ppv);
237 }
238 
239 static ULONG WINAPI HTMLSelectionObject2_AddRef(IHTMLSelectionObject2 *iface)
240 {
242 
243  return IHTMLSelectionObject_AddRef(&This->IHTMLSelectionObject_iface);
244 }
245 
246 static ULONG WINAPI HTMLSelectionObject2_Release(IHTMLSelectionObject2 *iface)
247 {
249 
250  return IHTMLSelectionObject_Release(&This->IHTMLSelectionObject_iface);
251 }
252 
253 static HRESULT WINAPI HTMLSelectionObject2_GetTypeInfoCount(IHTMLSelectionObject2 *iface, UINT *pctinfo)
254 {
256 
257  return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
258 }
259 
260 static HRESULT WINAPI HTMLSelectionObject2_GetTypeInfo(IHTMLSelectionObject2 *iface, UINT iTInfo,
261  LCID lcid, ITypeInfo **ppTInfo)
262 {
264 
265  return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
266 }
267 
268 static HRESULT WINAPI HTMLSelectionObject2_GetIDsOfNames(IHTMLSelectionObject2 *iface, REFIID riid,
269  LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
270 {
272 
273  return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames,
274  cNames, lcid, rgDispId);
275 }
276 
277 static HRESULT WINAPI HTMLSelectionObject2_Invoke(IHTMLSelectionObject2 *iface, DISPID dispIdMember,
278  REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
279  EXCEPINFO *pExcepInfo, UINT *puArgErr)
280 {
282 
283  return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid,
284  lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
285 }
286 
287 static HRESULT WINAPI HTMLSelectionObject2_createRangeCollection(IHTMLSelectionObject2 *iface, IDispatch **rangeCollection)
288 {
290  FIXME("(%p)->(%p)\n", This, rangeCollection);
291  return E_NOTIMPL;
292 }
293 
294 static HRESULT WINAPI HTMLSelectionObject2_get_typeDetail(IHTMLSelectionObject2 *iface, BSTR *p)
295 {
297  FIXME("(%p)->(%p)\n", This, p);
298  return E_NOTIMPL;
299 }
300 
301 static const IHTMLSelectionObject2Vtbl HTMLSelectionObject2Vtbl = {
311 };
312 
314  IHTMLSelectionObject_tid,
315  IHTMLSelectionObject2_tid,
316  0
317 };
319  NULL,
320  IHTMLSelectionObject_tid, /* FIXME: We have a test for that, but it doesn't expose IHTMLSelectionObject2 iface. */
321  NULL,
323 };
324 
325 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode *doc, nsISelection *nsselection, IHTMLSelectionObject **ret)
326 {
328 
330  if(!selection)
331  return E_OUTOFMEMORY;
332 
333  init_dispex(&selection->dispex, (IUnknown*)&selection->IHTMLSelectionObject_iface, &HTMLSelectionObject_dispex);
334 
335  selection->IHTMLSelectionObject_iface.lpVtbl = &HTMLSelectionObjectVtbl;
336  selection->IHTMLSelectionObject2_iface.lpVtbl = &HTMLSelectionObject2Vtbl;
337  selection->ref = 1;
338  selection->nsselection = nsselection; /* We shouldn't call AddRef here */
339 
340  selection->doc = doc;
341  list_add_head(&doc->selection_list, &selection->entry);
342 
343  *ret = &selection->IHTMLSelectionObject_iface;
344  return S_OK;
345 }
346 
348 {
349  HTMLSelectionObject *iter;
350 
351  LIST_FOR_EACH_ENTRY(iter, &This->selection_list, HTMLSelectionObject, entry) {
352  iter->doc = NULL;
353  }
354 }
static ULONG WINAPI HTMLSelectionObject_AddRef(IHTMLSelectionObject *iface)
Definition: selection.c:66
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
static HRESULT WINAPI HTMLSelectionObject2_QueryInterface(IHTMLSelectionObject2 *iface, REFIID riid, void **ppv)
Definition: selection.c:232
REFIID riid
Definition: precomp.h:44
tid_t
Definition: ieframe.h:311
#define WARN(fmt,...)
Definition: debug.h:111
static HTMLSelectionObject * impl_from_IHTMLSelectionObject(IHTMLSelectionObject *iface)
Definition: selection.c:34
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
REFIID LPVOID * ppv
Definition: atlbase.h:39
static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
Definition: selection.c:95
static ULONG WINAPI HTMLSelectionObject_Release(IHTMLSelectionObject *iface)
Definition: selection.c:76
HRESULT HTMLTxtRange_Create(HTMLDocumentNode *, nsIDOMRange *, IHTMLTxtRange **) DECLSPEC_HIDDEN
Definition: txtrange.c:1722
static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl
Definition: selection.c:213
DWORD LCID
Definition: nls.h:13
OLECHAR * BSTR
Definition: compat.h:1934
static LPOLESTR
Definition: stg_prop.c:27
#define E_FAIL
Definition: ddrawi.h:102
Definition: send.c:47
int selection
Definition: ctm.c:92
IHTMLSelectionObject2 IHTMLSelectionObject2_iface
Definition: selection.c:24
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
Definition: selection.c:131
const char * debugstr_mshtml_guid(const GUID *iid)
Definition: main.c:535
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static HRESULT WINAPI HTMLSelectionObject2_GetTypeInfo(IHTMLSelectionObject2 *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: selection.c:260
static HTMLSelectionObject * impl_from_IHTMLSelectionObject2(IHTMLSelectionObject2 *iface)
Definition: selection.c:227
static const IHTMLSelectionObject2Vtbl HTMLSelectionObject2Vtbl
Definition: selection.c:301
static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
Definition: selection.c:195
long LONG
Definition: pedump.c:60
HTMLDocumentNode * doc
Definition: selection.c:29
#define debugstr_w
Definition: kernel32.h:32
GLenum GLint ref
Definition: glext.h:6028
#define FIXME(fmt,...)
Definition: debug.h:110
nsISelection * nsselection
Definition: selection.c:28
smooth NULL
Definition: ftsmooth.c:416
struct list selection_list
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:241
static const tid_t HTMLSelectionObject_iface_tids[]
Definition: selection.c:313
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define NS_FAILED(res)
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
unsigned char cpp_bool
Definition: atl.c:39
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
static ULONG WINAPI HTMLSelectionObject2_Release(IHTMLSelectionObject2 *iface)
Definition: selection.c:246
LONG HRESULT
Definition: typedefs.h:77
static HRESULT WINAPI HTMLSelectionObject2_GetIDsOfNames(IHTMLSelectionObject2 *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: selection.c:268
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
unsigned short WORD
Definition: ntddk_ex.h:93
static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: selection.c:120
static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
Definition: selection.c:188
IHTMLSelectionObject IHTMLSelectionObject_iface
Definition: selection.c:23
const GUID IID_IDispatch
int ret
static HRESULT WINAPI HTMLSelectionObject_QueryInterface(IHTMLSelectionObject *iface, REFIID riid, void **ppv)
Definition: selection.c:39
#define InterlockedDecrement
Definition: armddk.h:52
uint32_t entry
Definition: isohybrid.c:63
Definition: _list.h:228
static HRESULT WINAPI HTMLSelectionObject2_GetTypeInfoCount(IHTMLSelectionObject2 *iface, UINT *pctinfo)
Definition: selection.c:253
GLenum GLint * range
Definition: glext.h:7539
static HRESULT WINAPI HTMLSelectionObject2_get_typeDetail(IHTMLSelectionObject2 *iface, BSTR *p)
Definition: selection.c:294
_In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon.h:519
#define ERR(fmt,...)
Definition: debug.h:109
static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
Definition: selection.c:181
static HRESULT WINAPI HTMLSelectionObject2_Invoke(IHTMLSelectionObject2 *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: selection.c:277
struct stdole::EXCEPINFO EXCEPINFO
static VARIANTARG static DISPID
Definition: ordinal.c:49
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
BOOL dispex_query_interface(DispatchEx *This, REFIID riid, void **ppv)
Definition: dispex.c:1656
HRESULT HTMLSelectionObject_Create(HTMLDocumentNode *doc, nsISelection *nsselection, IHTMLSelectionObject **ret)
Definition: selection.c:325
#define E_NOTIMPL
Definition: ddrawi.h:99
static HRESULT WINAPI HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: selection.c:102
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:940
#define E_UNEXPECTED
Definition: winerror.h:2456
static ULONG WINAPI HTMLSelectionObject2_AddRef(IHTMLSelectionObject2 *iface)
Definition: selection.c:239
static dispex_static_data_t HTMLSelectionObject_dispex
Definition: selection.c:318
struct stdole::DISPPARAMS DISPPARAMS
DispatchEx dispex
Definition: selection.c:22
static HRESULT WINAPI HTMLSelectionObject2_createRangeCollection(IHTMLSelectionObject2 *iface, IDispatch **rangeCollection)
Definition: selection.c:287
HRESULT nsresult
Definition: nsiface.idl:39
unsigned int ULONG
Definition: retypes.h:1
static HRESULT WINAPI HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: selection.c:110
GLfloat GLfloat p
Definition: glext.h:8902
void release_dispex(DispatchEx *This)
Definition: dispex.c:1706
void detach_selection(HTMLDocumentNode *This)
Definition: selection.c:347
static BOOL heap_free(void *mem)
Definition: appwiz.h:75