xref: /reactos/dll/win32/mshtml/htmltablerow.c (revision c2c66aff)
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 #include "mshtml_private.h"
20 
21 typedef struct {
22     HTMLElement element;
23 
24     IHTMLTableRow IHTMLTableRow_iface;
25 
26     nsIDOMHTMLTableRowElement *nsrow;
27 } HTMLTableRow;
28 
impl_from_IHTMLTableRow(IHTMLTableRow * iface)29 static inline HTMLTableRow *impl_from_IHTMLTableRow(IHTMLTableRow *iface)
30 {
31     return CONTAINING_RECORD(iface, HTMLTableRow, IHTMLTableRow_iface);
32 }
33 
HTMLTableRow_QueryInterface(IHTMLTableRow * iface,REFIID riid,void ** ppv)34 static HRESULT WINAPI HTMLTableRow_QueryInterface(IHTMLTableRow *iface,
35         REFIID riid, void **ppv)
36 {
37     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
38 
39     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
40 }
41 
HTMLTableRow_AddRef(IHTMLTableRow * iface)42 static ULONG WINAPI HTMLTableRow_AddRef(IHTMLTableRow *iface)
43 {
44     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
45 
46     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
47 }
48 
HTMLTableRow_Release(IHTMLTableRow * iface)49 static ULONG WINAPI HTMLTableRow_Release(IHTMLTableRow *iface)
50 {
51     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
52 
53     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
54 }
55 
HTMLTableRow_GetTypeInfoCount(IHTMLTableRow * iface,UINT * pctinfo)56 static HRESULT WINAPI HTMLTableRow_GetTypeInfoCount(IHTMLTableRow *iface, UINT *pctinfo)
57 {
58     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
59     return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
60 }
61 
HTMLTableRow_GetTypeInfo(IHTMLTableRow * iface,UINT iTInfo,LCID lcid,ITypeInfo ** ppTInfo)62 static HRESULT WINAPI HTMLTableRow_GetTypeInfo(IHTMLTableRow *iface, UINT iTInfo,
63                                               LCID lcid, ITypeInfo **ppTInfo)
64 {
65     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
66     return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
67             ppTInfo);
68 }
69 
HTMLTableRow_GetIDsOfNames(IHTMLTableRow * iface,REFIID riid,LPOLESTR * rgszNames,UINT cNames,LCID lcid,DISPID * rgDispId)70 static HRESULT WINAPI HTMLTableRow_GetIDsOfNames(IHTMLTableRow *iface, REFIID riid,
71                                                 LPOLESTR *rgszNames, UINT cNames,
72                                                 LCID lcid, DISPID *rgDispId)
73 {
74     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
75     return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
76             cNames, lcid, rgDispId);
77 }
78 
HTMLTableRow_Invoke(IHTMLTableRow * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)79 static HRESULT WINAPI HTMLTableRow_Invoke(IHTMLTableRow *iface, DISPID dispIdMember,
80                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
81                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
82 {
83     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
84     return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
85             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
86 }
87 
HTMLTableRow_put_align(IHTMLTableRow * iface,BSTR v)88 static HRESULT WINAPI HTMLTableRow_put_align(IHTMLTableRow *iface, BSTR v)
89 {
90     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
91     nsAString val;
92     nsresult nsres;
93 
94     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
95 
96     nsAString_InitDepend(&val, v);
97 
98     nsres = nsIDOMHTMLTableRowElement_SetAlign(This->nsrow, &val);
99     nsAString_Finish(&val);
100     if (NS_FAILED(nsres)){
101         ERR("Set Align(%s) failed!\n", debugstr_w(v));
102         return E_FAIL;
103     }
104     return S_OK;
105 }
106 
HTMLTableRow_get_align(IHTMLTableRow * iface,BSTR * p)107 static HRESULT WINAPI HTMLTableRow_get_align(IHTMLTableRow *iface, BSTR *p)
108 {
109     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
110     nsAString val;
111     nsresult nsres;
112 
113     TRACE("(%p)->(%p)\n", This, p);
114 
115     nsAString_Init(&val, NULL);
116     nsres = nsIDOMHTMLTableRowElement_GetAlign(This->nsrow, &val);
117 
118     return return_nsstr(nsres, &val, p);
119 }
120 
HTMLTableRow_put_vAlign(IHTMLTableRow * iface,BSTR v)121 static HRESULT WINAPI HTMLTableRow_put_vAlign(IHTMLTableRow *iface, BSTR v)
122 {
123     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
124     nsAString val;
125     nsresult nsres;
126 
127     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
128 
129     nsAString_InitDepend(&val, v);
130 
131     nsres = nsIDOMHTMLTableRowElement_SetVAlign(This->nsrow, &val);
132     nsAString_Finish(&val);
133 
134     if (NS_FAILED(nsres)){
135         ERR("Set VAlign(%s) failed!\n", debugstr_w(v));
136         return E_FAIL;
137     }
138 
139     return S_OK;
140 }
141 
HTMLTableRow_get_vAlign(IHTMLTableRow * iface,BSTR * p)142 static HRESULT WINAPI HTMLTableRow_get_vAlign(IHTMLTableRow *iface, BSTR *p)
143 {
144     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
145     nsAString val;
146     nsresult nsres;
147 
148     TRACE("(%p)->(%p)\n", This, p);
149 
150     nsAString_Init(&val, NULL);
151     nsres = nsIDOMHTMLTableRowElement_GetVAlign(This->nsrow, &val);
152 
153     return return_nsstr(nsres, &val, p);
154 }
155 
HTMLTableRow_put_bgColor(IHTMLTableRow * iface,VARIANT v)156 static HRESULT WINAPI HTMLTableRow_put_bgColor(IHTMLTableRow *iface, VARIANT v)
157 {
158     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
159     nsAString val;
160     nsresult nsres;
161 
162     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
163 
164     if (!variant_to_nscolor(&v, &val))
165         return S_OK;
166 
167     nsres = nsIDOMHTMLTableRowElement_SetBgColor(This->nsrow, &val);
168     nsAString_Finish(&val);
169 
170     if (NS_FAILED(nsres)){
171         ERR("Set BgColor(%s) failed!\n", debugstr_variant(&v));
172         return E_FAIL;
173     }
174 
175     return S_OK;
176 }
177 
HTMLTableRow_get_bgColor(IHTMLTableRow * iface,VARIANT * p)178 static HRESULT WINAPI HTMLTableRow_get_bgColor(IHTMLTableRow *iface, VARIANT *p)
179 {
180     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
181     nsAString strColor;
182     nsresult nsres;
183     HRESULT hres;
184     const PRUnichar *color;
185 
186     TRACE("(%p)->(%p)\n", This, p);
187 
188     nsAString_Init(&strColor, NULL);
189     nsres = nsIDOMHTMLTableRowElement_GetBgColor(This->nsrow, &strColor);
190 
191     if(NS_SUCCEEDED(nsres)) {
192        nsAString_GetData(&strColor, &color);
193        V_VT(p) = VT_BSTR;
194        hres = nscolor_to_str(color, &V_BSTR(p));
195     }else {
196        ERR("SetBgColor failed: %08x\n", nsres);
197        hres = E_FAIL;
198     }
199 
200     nsAString_Finish(&strColor);
201     return hres;
202 }
203 
HTMLTableRow_put_borderColor(IHTMLTableRow * iface,VARIANT v)204 static HRESULT WINAPI HTMLTableRow_put_borderColor(IHTMLTableRow *iface, VARIANT v)
205 {
206     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
207     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
208     return E_NOTIMPL;
209 }
210 
HTMLTableRow_get_borderColor(IHTMLTableRow * iface,VARIANT * p)211 static HRESULT WINAPI HTMLTableRow_get_borderColor(IHTMLTableRow *iface, VARIANT *p)
212 {
213     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
214     FIXME("(%p)->(%p)\n", This, p);
215     return E_NOTIMPL;
216 }
217 
HTMLTableRow_put_borderColorLight(IHTMLTableRow * iface,VARIANT v)218 static HRESULT WINAPI HTMLTableRow_put_borderColorLight(IHTMLTableRow *iface, VARIANT v)
219 {
220     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
221     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
222     return E_NOTIMPL;
223 }
224 
HTMLTableRow_get_borderColorLight(IHTMLTableRow * iface,VARIANT * p)225 static HRESULT WINAPI HTMLTableRow_get_borderColorLight(IHTMLTableRow *iface, VARIANT *p)
226 {
227     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
228     FIXME("(%p)->(%p)\n", This, p);
229     return E_NOTIMPL;
230 }
231 
HTMLTableRow_put_borderColorDark(IHTMLTableRow * iface,VARIANT v)232 static HRESULT WINAPI HTMLTableRow_put_borderColorDark(IHTMLTableRow *iface, VARIANT v)
233 {
234     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
235     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
236     return E_NOTIMPL;
237 }
238 
HTMLTableRow_get_borderColorDark(IHTMLTableRow * iface,VARIANT * p)239 static HRESULT WINAPI HTMLTableRow_get_borderColorDark(IHTMLTableRow *iface, VARIANT *p)
240 {
241     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
242     FIXME("(%p)->(%p)\n", This, p);
243     return E_NOTIMPL;
244 }
245 
HTMLTableRow_get_rowIndex(IHTMLTableRow * iface,LONG * p)246 static HRESULT WINAPI HTMLTableRow_get_rowIndex(IHTMLTableRow *iface, LONG *p)
247 {
248     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
249     nsresult nsres;
250 
251     TRACE("(%p)->(%p)\n", This, p);
252     nsres = nsIDOMHTMLTableRowElement_GetRowIndex(This->nsrow, p);
253     if(NS_FAILED(nsres)) {
254         ERR("Get rowIndex failed: %08x\n", nsres);
255         return E_FAIL;
256     }
257     return S_OK;
258 }
259 
HTMLTableRow_get_sectionRowIndex(IHTMLTableRow * iface,LONG * p)260 static HRESULT WINAPI HTMLTableRow_get_sectionRowIndex(IHTMLTableRow *iface, LONG *p)
261 {
262     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
263     nsresult nsres;
264 
265     TRACE("(%p)->(%p)\n", This, p);
266     nsres = nsIDOMHTMLTableRowElement_GetSectionRowIndex(This->nsrow, p);
267     if(NS_FAILED(nsres)) {
268         ERR("Get selectionRowIndex failed: %08x\n", nsres);
269         return E_FAIL;
270     }
271     return S_OK;
272 }
273 
HTMLTableRow_get_cells(IHTMLTableRow * iface,IHTMLElementCollection ** p)274 static HRESULT WINAPI HTMLTableRow_get_cells(IHTMLTableRow *iface, IHTMLElementCollection **p)
275 {
276     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
277     nsIDOMHTMLCollection *nscol;
278     nsresult nsres;
279 
280     TRACE("(%p)->(%p)\n", This, p);
281 
282     nsres = nsIDOMHTMLTableRowElement_GetCells(This->nsrow, &nscol);
283     if(NS_FAILED(nsres)) {
284         ERR("GetCells failed: %08x\n", nsres);
285         return E_FAIL;
286     }
287 
288     *p = create_collection_from_htmlcol(This->element.node.doc, nscol);
289 
290     nsIDOMHTMLCollection_Release(nscol);
291     return S_OK;
292 }
293 
HTMLTableRow_insertCell(IHTMLTableRow * iface,LONG index,IDispatch ** row)294 static HRESULT WINAPI HTMLTableRow_insertCell(IHTMLTableRow *iface, LONG index, IDispatch **row)
295 {
296     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
297     nsIDOMHTMLElement *nselem;
298     HTMLElement *elem;
299     nsresult nsres;
300     HRESULT hres;
301 
302     TRACE("(%p)->(%d %p)\n", This, index, row);
303     nsres = nsIDOMHTMLTableRowElement_InsertCell(This->nsrow, index, &nselem);
304     if(NS_FAILED(nsres)) {
305         ERR("Insert Cell at %d failed: %08x\n", index, nsres);
306         return E_FAIL;
307     }
308 
309     hres = HTMLTableCell_Create(This->element.node.doc, nselem, &elem);
310     nsIDOMHTMLElement_Release(nselem);
311     if (FAILED(hres)) {
312         ERR("Create TableCell failed: %08x\n", hres);
313         return hres;
314     }
315 
316     *row = (IDispatch *)&elem->IHTMLElement_iface;
317     return S_OK;
318 }
319 
HTMLTableRow_deleteCell(IHTMLTableRow * iface,LONG index)320 static HRESULT WINAPI HTMLTableRow_deleteCell(IHTMLTableRow *iface, LONG index)
321 {
322     HTMLTableRow *This = impl_from_IHTMLTableRow(iface);
323     nsresult nsres;
324 
325     TRACE("(%p)->(%d)\n", This, index);
326     nsres = nsIDOMHTMLTableRowElement_DeleteCell(This->nsrow, index);
327     if(NS_FAILED(nsres)) {
328         ERR("Delete Cell failed: %08x\n", nsres);
329         return E_FAIL;
330     }
331     return S_OK;
332 }
333 
334 static const IHTMLTableRowVtbl HTMLTableRowVtbl = {
335     HTMLTableRow_QueryInterface,
336     HTMLTableRow_AddRef,
337     HTMLTableRow_Release,
338     HTMLTableRow_GetTypeInfoCount,
339     HTMLTableRow_GetTypeInfo,
340     HTMLTableRow_GetIDsOfNames,
341     HTMLTableRow_Invoke,
342     HTMLTableRow_put_align,
343     HTMLTableRow_get_align,
344     HTMLTableRow_put_vAlign,
345     HTMLTableRow_get_vAlign,
346     HTMLTableRow_put_bgColor,
347     HTMLTableRow_get_bgColor,
348     HTMLTableRow_put_borderColor,
349     HTMLTableRow_get_borderColor,
350     HTMLTableRow_put_borderColorLight,
351     HTMLTableRow_get_borderColorLight,
352     HTMLTableRow_put_borderColorDark,
353     HTMLTableRow_get_borderColorDark,
354     HTMLTableRow_get_rowIndex,
355     HTMLTableRow_get_sectionRowIndex,
356     HTMLTableRow_get_cells,
357     HTMLTableRow_insertCell,
358     HTMLTableRow_deleteCell
359 };
360 
impl_from_HTMLDOMNode(HTMLDOMNode * iface)361 static inline HTMLTableRow *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
362 {
363     return CONTAINING_RECORD(iface, HTMLTableRow, element.node);
364 }
365 
HTMLTableRow_QI(HTMLDOMNode * iface,REFIID riid,void ** ppv)366 static HRESULT HTMLTableRow_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
367 {
368     HTMLTableRow *This = impl_from_HTMLDOMNode(iface);
369 
370     *ppv = NULL;
371 
372     if(IsEqualGUID(&IID_IUnknown, riid)) {
373         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
374         *ppv = &This->IHTMLTableRow_iface;
375     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
376         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
377         *ppv = &This->IHTMLTableRow_iface;
378     }else if(IsEqualGUID(&IID_IHTMLTableRow, riid)) {
379         TRACE("(%p)->(IID_IHTMLTableRow %p)\n", This, ppv);
380         *ppv = &This->IHTMLTableRow_iface;
381     }
382 
383     if(*ppv) {
384         IUnknown_AddRef((IUnknown*)*ppv);
385         return S_OK;
386     }
387 
388     return HTMLElement_QI(&This->element.node, riid, ppv);
389 }
390 
HTMLTableRow_traverse(HTMLDOMNode * iface,nsCycleCollectionTraversalCallback * cb)391 static void HTMLTableRow_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
392 {
393     HTMLTableRow *This = impl_from_HTMLDOMNode(iface);
394 
395     if(This->nsrow)
396         note_cc_edge((nsISupports*)This->nsrow, "This->nstablerow", cb);
397 }
398 
HTMLTableRow_unlink(HTMLDOMNode * iface)399 static void HTMLTableRow_unlink(HTMLDOMNode *iface)
400 {
401     HTMLTableRow *This = impl_from_HTMLDOMNode(iface);
402 
403     if(This->nsrow) {
404         nsIDOMHTMLTableRowElement *nsrow = This->nsrow;
405 
406         This->nsrow = NULL;
407         nsIDOMHTMLTableRowElement_Release(nsrow);
408     }
409 }
410 
411 static const NodeImplVtbl HTMLTableRowImplVtbl = {
412     HTMLTableRow_QI,
413     HTMLElement_destructor,
414     HTMLElement_cpc,
415     HTMLElement_clone,
416     HTMLElement_handle_event,
417     HTMLElement_get_attr_col,
418     NULL,
419     NULL,
420     NULL,
421     NULL,
422     NULL,
423     NULL,
424     NULL,
425     NULL,
426     NULL,
427     HTMLTableRow_traverse,
428     HTMLTableRow_unlink
429 };
430 
431 static const tid_t HTMLTableRow_iface_tids[] = {
432     HTMLELEMENT_TIDS,
433     IHTMLTableRow_tid,
434     0
435 };
436 
437 static dispex_static_data_t HTMLTableRow_dispex = {
438     NULL,
439     DispHTMLTableRow_tid,
440     NULL,
441     HTMLTableRow_iface_tids
442 };
443 
HTMLTableRow_Create(HTMLDocumentNode * doc,nsIDOMHTMLElement * nselem,HTMLElement ** elem)444 HRESULT HTMLTableRow_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
445 {
446     HTMLTableRow *ret;
447     nsresult nsres;
448 
449     ret = heap_alloc_zero(sizeof(HTMLTableRow));
450     if(!ret)
451         return E_OUTOFMEMORY;
452 
453     ret->IHTMLTableRow_iface.lpVtbl = &HTMLTableRowVtbl;
454     ret->element.node.vtbl = &HTMLTableRowImplVtbl;
455 
456     HTMLElement_Init(&ret->element, doc, nselem, &HTMLTableRow_dispex);
457 
458     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLTableRowElement, (void**)&ret->nsrow);
459     assert(nsres == NS_OK);
460 
461     *elem = &ret->element;
462     return S_OK;
463 }
464