3908314f5845d16893fb8829f1f7659878c897c5
[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 nsAString nsstr;
107 nsresult nsres;
108
109 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
110
111 nsAString_InitDepend(&nsstr, v);
112 nsres = nsIDOMText_SetData(This->nstext, &nsstr);
113 nsAString_Finish(&nsstr);
114 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
115 }
116
117 static HRESULT WINAPI HTMLDOMTextNode_get_data(IHTMLDOMTextNode *iface, BSTR *p)
118 {
119 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
120 nsAString nsstr;
121 nsresult nsres;
122
123 TRACE("(%p)->(%p)\n", This, p);
124
125 nsAString_Init(&nsstr, NULL);
126 nsres = nsIDOMText_GetData(This->nstext, &nsstr);
127 return return_nsstr(nsres, &nsstr, p);
128 }
129
130 static HRESULT WINAPI HTMLDOMTextNode_toString(IHTMLDOMTextNode *iface, BSTR *String)
131 {
132 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
133 FIXME("(%p)->(%p)\n", This, String);
134 return E_NOTIMPL;
135 }
136
137 static HRESULT WINAPI HTMLDOMTextNode_get_length(IHTMLDOMTextNode *iface, LONG *p)
138 {
139 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
140 UINT32 length = 0;
141 nsresult nsres;
142
143 TRACE("(%p)->(%p)\n", This, p);
144
145 nsres = nsIDOMText_GetLength(This->nstext, &length);
146 if(NS_FAILED(nsres))
147 ERR("GetLength failed: %08x\n", nsres);
148
149 *p = length;
150 return S_OK;
151 }
152
153 static HRESULT WINAPI HTMLDOMTextNode_splitText(IHTMLDOMTextNode *iface, LONG offset, IHTMLDOMNode **pRetNode)
154 {
155 HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
156 FIXME("(%p)->(%d %p)\n", This, offset, pRetNode);
157 return E_NOTIMPL;
158 }
159
160 static const IHTMLDOMTextNodeVtbl HTMLDOMTextNodeVtbl = {
161 HTMLDOMTextNode_QueryInterface,
162 HTMLDOMTextNode_AddRef,
163 HTMLDOMTextNode_Release,
164 HTMLDOMTextNode_GetTypeInfoCount,
165 HTMLDOMTextNode_GetTypeInfo,
166 HTMLDOMTextNode_GetIDsOfNames,
167 HTMLDOMTextNode_Invoke,
168 HTMLDOMTextNode_put_data,
169 HTMLDOMTextNode_get_data,
170 HTMLDOMTextNode_toString,
171 HTMLDOMTextNode_get_length,
172 HTMLDOMTextNode_splitText
173 };
174
175 static inline HTMLDOMTextNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
176 {
177 return CONTAINING_RECORD(iface, HTMLDOMTextNode, node);
178 }
179
180 static HRESULT HTMLDOMTextNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
181 {
182 HTMLDOMTextNode *This = impl_from_HTMLDOMNode(iface);
183
184 *ppv = NULL;
185
186 if(IsEqualGUID(&IID_IHTMLDOMTextNode, riid)) {
187 TRACE("(%p)->(IID_IHTMLDOMTextNode %p)\n", This, ppv);
188 *ppv = &This->IHTMLDOMTextNode_iface;
189 }else {
190 return HTMLDOMNode_QI(&This->node, riid, ppv);
191 }
192
193 IUnknown_AddRef((IUnknown*)*ppv);
194 return S_OK;
195 }
196
197 static HRESULT HTMLDOMTextNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
198 {
199 HTMLDOMTextNode *This = impl_from_HTMLDOMNode(iface);
200
201 return HTMLDOMTextNode_Create(This->node.doc, nsnode, ret);
202 }
203
204 static const cpc_entry_t HTMLDOMTextNode_cpc[] = {{NULL}};
205
206 static const NodeImplVtbl HTMLDOMTextNodeImplVtbl = {
207 HTMLDOMTextNode_QI,
208 HTMLDOMNode_destructor,
209 HTMLDOMTextNode_cpc,
210 HTMLDOMTextNode_clone
211 };
212
213 static const tid_t HTMLDOMTextNode_iface_tids[] = {
214 IHTMLDOMNode_tid,
215 IHTMLDOMNode2_tid,
216 IHTMLDOMTextNode_tid,
217 0
218 };
219 static dispex_static_data_t HTMLDOMTextNode_dispex = {
220 NULL,
221 DispHTMLDOMTextNode_tid,
222 0,
223 HTMLDOMTextNode_iface_tids
224 };
225
226 HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **node)
227 {
228 HTMLDOMTextNode *ret;
229 nsresult nsres;
230
231 ret = heap_alloc_zero(sizeof(*ret));
232 if(!ret)
233 return E_OUTOFMEMORY;
234
235 ret->node.vtbl = &HTMLDOMTextNodeImplVtbl;
236 ret->IHTMLDOMTextNode_iface.lpVtbl = &HTMLDOMTextNodeVtbl;
237
238 init_dispex(&ret->node.dispex, (IUnknown*)&ret->IHTMLDOMTextNode_iface,
239 &HTMLDOMTextNode_dispex);
240
241 HTMLDOMNode_Init(doc, &ret->node, nsnode);
242
243 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&ret->nstext);
244 assert(nsres == NS_OK && (nsIDOMNode*)ret->nstext == ret->node.nsnode);
245
246 /* Share reference with nsnode */
247 nsIDOMNode_Release(ret->node.nsnode);
248
249 *node = &ret->node;
250 return S_OK;
251 }