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