3297450bf5f765e5fd97841f6eb6df59462e5853
[reactos.git] / reactos / dll / win32 / mshtml / htmltextnode.c
1 /*
2 * Copyright 2008 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 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21
22 #include <stdarg.h>
23 #include <assert.h>
24
25 #define COBJMACROS
26
27 #include <windef.h>
28 #include <winbase.h>
29 //#include "winuser.h"
30 #include <ole2.h>
31
32 #include "mshtml_private.h"
33
34 #include <wine/debug.h>
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 struct HTMLDOMTextNode {
39 HTMLDOMNode node;
40 IHTMLDOMTextNode IHTMLDOMTextNode_iface;
41
42 nsIDOMText *nstext;
43 };
44
45 static inline HTMLDOMTextNode *impl_from_IHTMLDOMTextNode(IHTMLDOMTextNode *iface)
46 {
47 return CONTAINING_RECORD(iface, HTMLDOMTextNode, IHTMLDOMTextNode_iface);
48 }
49
50 static HRESULT WINAPI HTMLDOMTextNode_QueryInterface(IHTMLDOMTextNode *iface,
51 REFIID riid, void **ppv)
52 {
53 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
54
55 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
56 }
57
58 static ULONG WINAPI HTMLDOMTextNode_AddRef(IHTMLDOMTextNode *iface)
59 {
60 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
61
62 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
63 }
64
65 static ULONG WINAPI HTMLDOMTextNode_Release(IHTMLDOMTextNode *iface)
66 {
67 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
68
69 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
70 }
71
72 static HRESULT WINAPI HTMLDOMTextNode_GetTypeInfoCount(IHTMLDOMTextNode *iface, UINT *pctinfo)
73 {
74 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
75 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
76 }
77
78 static HRESULT WINAPI HTMLDOMTextNode_GetTypeInfo(IHTMLDOMTextNode *iface, UINT iTInfo,
79 LCID lcid, ITypeInfo **ppTInfo)
80 {
81 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
82 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
83 }
84
85 static HRESULT WINAPI HTMLDOMTextNode_GetIDsOfNames(IHTMLDOMTextNode *iface, REFIID riid,
86 LPOLESTR *rgszNames, UINT cNames,
87 LCID lcid, DISPID *rgDispId)
88 {
89 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
90 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
91 lcid, rgDispId);
92 }
93
94 static HRESULT WINAPI HTMLDOMTextNode_Invoke(IHTMLDOMTextNode *iface, DISPID dispIdMember,
95 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
96 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
97 {
98 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
99 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
100 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
101 }
102
103 static HRESULT WINAPI HTMLDOMTextNode_put_data(IHTMLDOMTextNode *iface, BSTR v)
104 {
105 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
106 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
107 return E_NOTIMPL;
108 }
109
110 static HRESULT WINAPI HTMLDOMTextNode_get_data(IHTMLDOMTextNode *iface, BSTR *p)
111 {
112 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
113 FIXME("(%p)->(%p)\n", This, p);
114 return E_NOTIMPL;
115 }
116
117 static HRESULT WINAPI HTMLDOMTextNode_toString(IHTMLDOMTextNode *iface, BSTR *String)
118 {
119 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
120 FIXME("(%p)->(%p)\n", This, String);
121 return E_NOTIMPL;
122 }
123
124 static HRESULT WINAPI HTMLDOMTextNode_get_length(IHTMLDOMTextNode *iface, LONG *p)
125 {
126 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
127 UINT32 length = 0;
128 nsresult nsres;
129
130 TRACE("(%p)->(%p)\n", This, p);
131
132 nsres = nsIDOMText_GetLength(This->nstext, &length);
133 if(NS_FAILED(nsres))
134 ERR("GetLength failed: %08x\n", nsres);
135
136 *p = length;
137 return S_OK;
138 }
139
140 static HRESULT WINAPI HTMLDOMTextNode_splitText(IHTMLDOMTextNode *iface, LONG offset, IHTMLDOMNode **pRetNode)
141 {
142 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
143 FIXME("(%p)->(%d %p)\n", This, offset, pRetNode);
144 return E_NOTIMPL;
145 }
146
147 static const IHTMLDOMTextNodeVtbl HTMLDOMTextNodeVtbl = {
148 HTMLDOMTextNode_QueryInterface,
149 HTMLDOMTextNode_AddRef,
150 HTMLDOMTextNode_Release,
151 HTMLDOMTextNode_GetTypeInfoCount,
152 HTMLDOMTextNode_GetTypeInfo,
153 HTMLDOMTextNode_GetIDsOfNames,
154 HTMLDOMTextNode_Invoke,
155 HTMLDOMTextNode_put_data,
156 HTMLDOMTextNode_get_data,
157 HTMLDOMTextNode_toString,
158 HTMLDOMTextNode_get_length,
159 HTMLDOMTextNode_splitText
160 };
161
162 static inline HTMLDOMTextNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
163 {
164 return CONTAINING_RECORD(iface, HTMLDOMTextNode, node);
165 }
166
167 static HRESULT HTMLDOMTextNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
168 {
169 HTMLDOMTextNode *This = impl_from_HTMLDOMNode(iface);
170
171 *ppv = NULL;
172
173 if(IsEqualGUID(&IID_IHTMLDOMTextNode, riid)) {
174 TRACE("(%p)->(IID_IHTMLDOMTextNode %p)\n", This, ppv);
175 *ppv = &This->IHTMLDOMTextNode_iface;
176 }else {
177 return HTMLDOMNode_QI(&This->node, riid, ppv);
178 }
179
180 IUnknown_AddRef((IUnknown*)*ppv);
181 return S_OK;
182 }
183
184 static HRESULT HTMLDOMTextNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
185 {
186 HTMLDOMTextNode *This = impl_from_HTMLDOMNode(iface);
187
188 return HTMLDOMTextNode_Create(This->node.doc, nsnode, ret);
189 }
190
191 static const cpc_entry_t HTMLDOMTextNode_cpc[] = {{NULL}};
192
193 static const NodeImplVtbl HTMLDOMTextNodeImplVtbl = {
194 HTMLDOMTextNode_QI,
195 HTMLDOMNode_destructor,
196 HTMLDOMTextNode_cpc,
197 HTMLDOMTextNode_clone
198 };
199
200 static const tid_t HTMLDOMTextNode_iface_tids[] = {
201 IHTMLDOMNode_tid,
202 IHTMLDOMNode2_tid,
203 IHTMLDOMTextNode_tid,
204 0
205 };
206 static dispex_static_data_t HTMLDOMTextNode_dispex = {
207 NULL,
208 DispHTMLDOMTextNode_tid,
209 0,
210 HTMLDOMTextNode_iface_tids
211 };
212
213 HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **node)
214 {
215 HTMLDOMTextNode *ret;
216 nsresult nsres;
217
218 ret = heap_alloc_zero(sizeof(*ret));
219 if(!ret)
220 return E_OUTOFMEMORY;
221
222 ret->node.vtbl = &HTMLDOMTextNodeImplVtbl;
223 ret->IHTMLDOMTextNode_iface.lpVtbl = &HTMLDOMTextNodeVtbl;
224
225 init_dispex(&ret->node.dispex, (IUnknown*)&ret->IHTMLDOMTextNode_iface,
226 &HTMLDOMTextNode_dispex);
227
228 HTMLDOMNode_Init(doc, &ret->node, nsnode);
229
230 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&ret->nstext);
231 assert(nsres == NS_OK && (nsIDOMNode*)ret->nstext == ret->node.nsnode);
232
233 /* Share reference with nsnode */
234 nsIDOMNode_Release(ret->node.nsnode);
235
236 *node = &ret->node;
237 return S_OK;
238 }