ReactOS 0.4.15-dev-7788-g1ad9096
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
21typedef struct {
23 IHTMLSelectionObject IHTMLSelectionObject_iface;
24 IHTMLSelectionObject2 IHTMLSelectionObject2_iface;
25
27
30
31 struct list entry;
33
34static inline HTMLSelectionObject *impl_from_IHTMLSelectionObject(IHTMLSelectionObject *iface)
35{
36 return CONTAINING_RECORD(iface, HTMLSelectionObject, IHTMLSelectionObject_iface);
37}
38
39static 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
66static ULONG WINAPI HTMLSelectionObject_AddRef(IHTMLSelectionObject *iface)
67{
70
71 TRACE("(%p) ref=%d\n", This, ref);
72
73 return ref;
74}
75
76static 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);
90 }
91
92 return ref;
93}
94
95static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
96{
98
99 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
100}
101
102static 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
110static 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
120static 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
131static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
132{
134 IHTMLTxtRange *range_obj = NULL;
135 nsIDOMRange *nsrange = NULL;
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
181static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
182{
184 FIXME("(%p)\n", This);
185 return E_NOTIMPL;
186}
187
188static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
189{
191 FIXME("(%p)\n", This);
192 return E_NOTIMPL;
193}
194
195static 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
213static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl = {
225};
226
227static inline HTMLSelectionObject *impl_from_IHTMLSelectionObject2(IHTMLSelectionObject2 *iface)
228{
229 return CONTAINING_RECORD(iface, HTMLSelectionObject, IHTMLSelectionObject2_iface);
230}
231
232static HRESULT WINAPI HTMLSelectionObject2_QueryInterface(IHTMLSelectionObject2 *iface, REFIID riid, void **ppv)
233{
235
236 return IHTMLSelectionObject_QueryInterface(&This->IHTMLSelectionObject_iface, riid, ppv);
237}
238
239static ULONG WINAPI HTMLSelectionObject2_AddRef(IHTMLSelectionObject2 *iface)
240{
242
243 return IHTMLSelectionObject_AddRef(&This->IHTMLSelectionObject_iface);
244}
245
246static ULONG WINAPI HTMLSelectionObject2_Release(IHTMLSelectionObject2 *iface)
247{
249
250 return IHTMLSelectionObject_Release(&This->IHTMLSelectionObject_iface);
251}
252
253static HRESULT WINAPI HTMLSelectionObject2_GetTypeInfoCount(IHTMLSelectionObject2 *iface, UINT *pctinfo)
254{
256
257 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
258}
259
260static 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
268static 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
277static 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
287static HRESULT WINAPI HTMLSelectionObject2_createRangeCollection(IHTMLSelectionObject2 *iface, IDispatch **rangeCollection)
288{
290 FIXME("(%p)->(%p)\n", This, rangeCollection);
291 return E_NOTIMPL;
292}
293
294static HRESULT WINAPI HTMLSelectionObject2_get_typeDetail(IHTMLSelectionObject2 *iface, BSTR *p)
295{
297 FIXME("(%p)->(%p)\n", This, p);
298 return E_NOTIMPL;
299}
300
301static 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
325HRESULT 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{
350
351 LIST_FOR_EACH_ENTRY(iter, &This->selection_list, HTMLSelectionObject, entry) {
352 iter->doc = NULL;
353 }
354}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
const GUID IID_IUnknown
#define FIXME(fmt,...)
Definition: debug.h:111
#define WARN(fmt,...)
Definition: debug.h:112
#define ERR(fmt,...)
Definition: debug.h:110
Definition: list.h:37
int selection
Definition: ctm.c:92
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
unsigned char cpp_bool
Definition: atl.c:38
OLECHAR * BSTR
Definition: compat.h:2293
const char * debugstr_mshtml_guid(const GUID *iid)
Definition: main.c:542
unsigned short WORD
Definition: ntddk_ex.h:93
GLenum GLint * range
Definition: glext.h:7539
GLfloat GLfloat p
Definition: glext.h:8902
tid_t
Definition: ieframe.h:311
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
uint32_t entry
Definition: isohybrid.c:63
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:919
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
HRESULT hres
Definition: protocol.c:465
static LPOLESTR
Definition: stg_prop.c:27
static VARIANTARG static DISPID
Definition: ordinal.c:52
void release_dispex(DispatchEx *This)
Definition: dispex.c:1706
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
static HRESULT WINAPI HTMLSelectionObject2_GetIDsOfNames(IHTMLSelectionObject2 *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: selection.c:268
static HRESULT WINAPI HTMLSelectionObject2_GetTypeInfo(IHTMLSelectionObject2 *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: selection.c:260
static dispex_static_data_t HTMLSelectionObject_dispex
Definition: selection.c:318
static HRESULT WINAPI HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: selection.c:102
static ULONG WINAPI HTMLSelectionObject2_Release(IHTMLSelectionObject2 *iface)
Definition: selection.c:246
static ULONG WINAPI HTMLSelectionObject_AddRef(IHTMLSelectionObject *iface)
Definition: selection.c:66
static ULONG WINAPI HTMLSelectionObject_Release(IHTMLSelectionObject *iface)
Definition: selection.c:76
static HRESULT WINAPI HTMLSelectionObject2_GetTypeInfoCount(IHTMLSelectionObject2 *iface, UINT *pctinfo)
Definition: selection.c:253
static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl
Definition: selection.c:213
static HTMLSelectionObject * impl_from_IHTMLSelectionObject2(IHTMLSelectionObject2 *iface)
Definition: selection.c:227
static ULONG WINAPI HTMLSelectionObject2_AddRef(IHTMLSelectionObject2 *iface)
Definition: selection.c:239
static HTMLSelectionObject * impl_from_IHTMLSelectionObject(IHTMLSelectionObject *iface)
Definition: selection.c:34
void detach_selection(HTMLDocumentNode *This)
Definition: selection.c:347
static HRESULT WINAPI HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: selection.c:110
static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
Definition: selection.c:181
static const IHTMLSelectionObject2Vtbl HTMLSelectionObject2Vtbl
Definition: selection.c:301
static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
Definition: selection.c:95
static HRESULT WINAPI HTMLSelectionObject2_get_typeDetail(IHTMLSelectionObject2 *iface, BSTR *p)
Definition: selection.c:294
static HRESULT WINAPI HTMLSelectionObject2_createRangeCollection(IHTMLSelectionObject2 *iface, IDispatch **rangeCollection)
Definition: selection.c:287
static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
Definition: selection.c:195
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_QueryInterface(IHTMLSelectionObject *iface, REFIID riid, void **ppv)
Definition: selection.c:39
static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
Definition: selection.c:188
static const tid_t HTMLSelectionObject_iface_tids[]
Definition: selection.c:313
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
static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
Definition: selection.c:131
static HRESULT WINAPI HTMLSelectionObject2_QueryInterface(IHTMLSelectionObject2 *iface, REFIID riid, void **ppv)
Definition: selection.c:232
HRESULT HTMLTxtRange_Create(HTMLDocumentNode *, nsIDOMRange *, IHTMLTxtRange **) DECLSPEC_HIDDEN
Definition: txtrange.c:1722
#define NS_FAILED(res)
unsigned int UINT
Definition: ndis.h:50
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
const GUID IID_IDispatch
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
DWORD LCID
Definition: nls.h:13
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define TRACE(s)
Definition: solgame.cpp:4
struct list selection_list
DispatchEx dispex
Definition: selection.c:22
IHTMLSelectionObject2 IHTMLSelectionObject2_iface
Definition: selection.c:24
IHTMLSelectionObject IHTMLSelectionObject_iface
Definition: selection.c:23
nsISelection * nsselection
Definition: selection.c:28
HTMLDocumentNode * doc
Definition: selection.c:29
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
int ret
_In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon.h:531
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
#define E_UNEXPECTED
Definition: winerror.h:2456
__wchar_t WCHAR
Definition: xmlstorage.h:180