1 /* 2 * Copyright 2012 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 IHTMLTableCell IHTMLTableCell_iface; 25 26 nsIDOMHTMLTableCellElement *nscell; 27 } HTMLTableCell; 28 29 static inline HTMLTableCell *impl_from_IHTMLTableCell(IHTMLTableCell *iface) 30 { 31 return CONTAINING_RECORD(iface, HTMLTableCell, IHTMLTableCell_iface); 32 } 33 34 static HRESULT WINAPI HTMLTableCell_QueryInterface(IHTMLTableCell *iface, REFIID riid, void **ppv) 35 { 36 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 37 38 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv); 39 } 40 41 static ULONG WINAPI HTMLTableCell_AddRef(IHTMLTableCell *iface) 42 { 43 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 44 45 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface); 46 } 47 48 static ULONG WINAPI HTMLTableCell_Release(IHTMLTableCell *iface) 49 { 50 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 51 52 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface); 53 } 54 55 static HRESULT WINAPI HTMLTableCell_GetTypeInfoCount(IHTMLTableCell *iface, UINT *pctinfo) 56 { 57 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 58 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo); 59 } 60 61 static HRESULT WINAPI HTMLTableCell_GetTypeInfo(IHTMLTableCell *iface, UINT iTInfo, 62 LCID lcid, ITypeInfo **ppTInfo) 63 { 64 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 65 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid, 66 ppTInfo); 67 } 68 69 static HRESULT WINAPI HTMLTableCell_GetIDsOfNames(IHTMLTableCell *iface, REFIID riid, 70 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) 71 { 72 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 73 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames, 74 cNames, lcid, rgDispId); 75 } 76 77 static HRESULT WINAPI HTMLTableCell_Invoke(IHTMLTableCell *iface, DISPID dispIdMember, REFIID riid, 78 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, 79 UINT *puArgErr) 80 { 81 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 82 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid, 83 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 84 } 85 86 static HRESULT WINAPI HTMLTableCell_put_rowSpan(IHTMLTableCell *iface, LONG v) 87 { 88 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 89 FIXME("(%p)->(%d)\n", This, v); 90 return E_NOTIMPL; 91 } 92 93 static HRESULT WINAPI HTMLTableCell_get_rowSpan(IHTMLTableCell *iface, LONG *p) 94 { 95 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 96 FIXME("(%p)->(%p)\n", This, p); 97 return E_NOTIMPL; 98 } 99 100 static HRESULT WINAPI HTMLTableCell_put_colSpan(IHTMLTableCell *iface, LONG v) 101 { 102 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 103 FIXME("(%p)->(%d)\n", This, v); 104 return E_NOTIMPL; 105 } 106 107 static HRESULT WINAPI HTMLTableCell_get_colSpan(IHTMLTableCell *iface, LONG *p) 108 { 109 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 110 FIXME("(%p)->(%p)\n", This, p); 111 return E_NOTIMPL; 112 } 113 114 static HRESULT WINAPI HTMLTableCell_put_align(IHTMLTableCell *iface, BSTR v) 115 { 116 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 117 nsAString str; 118 nsresult nsres; 119 120 TRACE("(%p)->(%s)\n", This, debugstr_w(v)); 121 122 nsAString_InitDepend(&str, v); 123 nsres = nsIDOMHTMLTableCellElement_SetAlign(This->nscell, &str); 124 nsAString_Finish(&str); 125 if (NS_FAILED(nsres)) { 126 ERR("Set Align failed: %08x\n", nsres); 127 return E_FAIL; 128 } 129 return S_OK; 130 } 131 132 static HRESULT WINAPI HTMLTableCell_get_align(IHTMLTableCell *iface, BSTR *p) 133 { 134 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 135 nsAString str; 136 nsresult nsres; 137 138 TRACE("(%p)->(%p)\n", This, p); 139 140 nsAString_Init(&str, NULL); 141 nsres = nsIDOMHTMLTableCellElement_GetAlign(This->nscell, &str); 142 143 return return_nsstr(nsres, &str, p); 144 } 145 146 static HRESULT WINAPI HTMLTableCell_put_vAlign(IHTMLTableCell *iface, BSTR v) 147 { 148 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 149 FIXME("(%p)->(%s)\n", This, debugstr_w(v)); 150 return E_NOTIMPL; 151 } 152 153 static HRESULT WINAPI HTMLTableCell_get_vAlign(IHTMLTableCell *iface, BSTR *p) 154 { 155 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 156 FIXME("(%p)->(%p)\n", This, p); 157 return E_NOTIMPL; 158 } 159 160 static HRESULT WINAPI HTMLTableCell_put_bgColor(IHTMLTableCell *iface, VARIANT v) 161 { 162 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 163 nsAString strColor; 164 nsresult nsres; 165 166 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v)); 167 168 if(!variant_to_nscolor(&v, &strColor)) 169 return S_OK; 170 171 nsres = nsIDOMHTMLTableCellElement_SetBgColor(This->nscell, &strColor); 172 nsAString_Finish(&strColor); 173 if(NS_FAILED(nsres)) { 174 ERR("SetBgColor(%s) failed: %08x\n", debugstr_variant(&v), nsres); 175 return E_FAIL; 176 } 177 178 return S_OK; 179 } 180 181 static HRESULT WINAPI HTMLTableCell_get_bgColor(IHTMLTableCell *iface, VARIANT *p) 182 { 183 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 184 nsAString strColor; 185 nsresult nsres; 186 HRESULT hres; 187 188 TRACE("(%p)->(%p)\n", This, p); 189 190 nsAString_Init(&strColor, NULL); 191 nsres = nsIDOMHTMLTableCellElement_GetBgColor(This->nscell, &strColor); 192 193 if(NS_SUCCEEDED(nsres)) { 194 const PRUnichar *color; 195 nsAString_GetData(&strColor, &color); 196 V_VT(p) = VT_BSTR; 197 hres = nscolor_to_str(color, &V_BSTR(p)); 198 }else { 199 ERR("GetBgColor failed: %08x\n", nsres); 200 hres = E_FAIL; 201 } 202 nsAString_Finish(&strColor); 203 return hres; 204 } 205 206 static HRESULT WINAPI HTMLTableCell_put_noWrap(IHTMLTableCell *iface, VARIANT_BOOL v) 207 { 208 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 209 FIXME("(%p)->(%x)\n", This, v); 210 return E_NOTIMPL; 211 } 212 213 static HRESULT WINAPI HTMLTableCell_get_noWrap(IHTMLTableCell *iface, VARIANT_BOOL *p) 214 { 215 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 216 FIXME("(%p)->(%p)\n", This, p); 217 return E_NOTIMPL; 218 } 219 220 static HRESULT WINAPI HTMLTableCell_put_background(IHTMLTableCell *iface, BSTR v) 221 { 222 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 223 FIXME("(%p)->(%s)\n", This, debugstr_w(v)); 224 return E_NOTIMPL; 225 } 226 227 static HRESULT WINAPI HTMLTableCell_get_background(IHTMLTableCell *iface, BSTR *p) 228 { 229 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 230 FIXME("(%p)->(%p)\n", This, p); 231 return E_NOTIMPL; 232 } 233 234 static HRESULT WINAPI HTMLTableCell_put_borderColor(IHTMLTableCell *iface, VARIANT v) 235 { 236 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 237 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); 238 return E_NOTIMPL; 239 } 240 241 static HRESULT WINAPI HTMLTableCell_get_borderColor(IHTMLTableCell *iface, VARIANT *p) 242 { 243 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 244 FIXME("(%p)->(%p)\n", This, p); 245 return E_NOTIMPL; 246 } 247 248 static HRESULT WINAPI HTMLTableCell_put_borderColorLight(IHTMLTableCell *iface, VARIANT v) 249 { 250 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 251 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); 252 return E_NOTIMPL; 253 } 254 255 static HRESULT WINAPI HTMLTableCell_get_borderColorLight(IHTMLTableCell *iface, VARIANT *p) 256 { 257 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 258 FIXME("(%p)->(%p)\n", This, p); 259 return E_NOTIMPL; 260 } 261 262 static HRESULT WINAPI HTMLTableCell_put_borderColorDark(IHTMLTableCell *iface, VARIANT v) 263 { 264 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 265 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); 266 return E_NOTIMPL; 267 } 268 269 static HRESULT WINAPI HTMLTableCell_get_borderColorDark(IHTMLTableCell *iface, VARIANT *p) 270 { 271 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 272 FIXME("(%p)->(%p)\n", This, p); 273 return E_NOTIMPL; 274 } 275 276 static HRESULT WINAPI HTMLTableCell_put_width(IHTMLTableCell *iface, VARIANT v) 277 { 278 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 279 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); 280 return E_NOTIMPL; 281 } 282 283 static HRESULT WINAPI HTMLTableCell_get_width(IHTMLTableCell *iface, VARIANT *p) 284 { 285 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 286 FIXME("(%p)->(%p)\n", This, p); 287 return E_NOTIMPL; 288 } 289 290 static HRESULT WINAPI HTMLTableCell_put_height(IHTMLTableCell *iface, VARIANT v) 291 { 292 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 293 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); 294 return E_NOTIMPL; 295 } 296 297 static HRESULT WINAPI HTMLTableCell_get_height(IHTMLTableCell *iface, VARIANT *p) 298 { 299 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 300 FIXME("(%p)->(%p)\n", This, p); 301 return E_NOTIMPL; 302 } 303 304 static HRESULT WINAPI HTMLTableCell_get_cellIndex(IHTMLTableCell *iface, LONG *p) 305 { 306 HTMLTableCell *This = impl_from_IHTMLTableCell(iface); 307 nsresult nsres; 308 309 TRACE("(%p)->(%p)\n", This, p); 310 nsres = nsIDOMHTMLTableCellElement_GetCellIndex(This->nscell, p); 311 if (NS_FAILED(nsres)) { 312 ERR("Get CellIndex failed: %08x\n", nsres); 313 return E_FAIL; 314 } 315 316 return S_OK; 317 } 318 319 static const IHTMLTableCellVtbl HTMLTableCellVtbl = { 320 HTMLTableCell_QueryInterface, 321 HTMLTableCell_AddRef, 322 HTMLTableCell_Release, 323 HTMLTableCell_GetTypeInfoCount, 324 HTMLTableCell_GetTypeInfo, 325 HTMLTableCell_GetIDsOfNames, 326 HTMLTableCell_Invoke, 327 HTMLTableCell_put_rowSpan, 328 HTMLTableCell_get_rowSpan, 329 HTMLTableCell_put_colSpan, 330 HTMLTableCell_get_colSpan, 331 HTMLTableCell_put_align, 332 HTMLTableCell_get_align, 333 HTMLTableCell_put_vAlign, 334 HTMLTableCell_get_vAlign, 335 HTMLTableCell_put_bgColor, 336 HTMLTableCell_get_bgColor, 337 HTMLTableCell_put_noWrap, 338 HTMLTableCell_get_noWrap, 339 HTMLTableCell_put_background, 340 HTMLTableCell_get_background, 341 HTMLTableCell_put_borderColor, 342 HTMLTableCell_get_borderColor, 343 HTMLTableCell_put_borderColorLight, 344 HTMLTableCell_get_borderColorLight, 345 HTMLTableCell_put_borderColorDark, 346 HTMLTableCell_get_borderColorDark, 347 HTMLTableCell_put_width, 348 HTMLTableCell_get_width, 349 HTMLTableCell_put_height, 350 HTMLTableCell_get_height, 351 HTMLTableCell_get_cellIndex 352 }; 353 354 static inline HTMLTableCell *impl_from_HTMLDOMNode(HTMLDOMNode *iface) 355 { 356 return CONTAINING_RECORD(iface, HTMLTableCell, element.node); 357 } 358 359 static HRESULT HTMLTableCell_QI(HTMLDOMNode *iface, REFIID riid, void **ppv) 360 { 361 HTMLTableCell *This = impl_from_HTMLDOMNode(iface); 362 363 if(IsEqualGUID(&IID_IUnknown, riid)) { 364 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv); 365 *ppv = &This->IHTMLTableCell_iface; 366 }else if(IsEqualGUID(&IID_IDispatch, riid)) { 367 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv); 368 *ppv = &This->IHTMLTableCell_iface; 369 }else if(IsEqualGUID(&IID_IHTMLTableCell, riid)) { 370 TRACE("(%p)->(IID_IHTMLTableCell %p)\n", This, ppv); 371 *ppv = &This->IHTMLTableCell_iface; 372 }else { 373 return HTMLElement_QI(&This->element.node, riid, ppv); 374 } 375 376 IUnknown_AddRef((IUnknown*)*ppv); 377 return S_OK; 378 } 379 380 static void HTMLTableCell_destructor(HTMLDOMNode *iface) 381 { 382 HTMLTableCell *This = impl_from_HTMLDOMNode(iface); 383 384 HTMLElement_destructor(&This->element.node); 385 } 386 387 static void HTMLTableCell_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb) 388 { 389 HTMLTableCell *This = impl_from_HTMLDOMNode(iface); 390 391 if(This->nscell) 392 note_cc_edge((nsISupports*)This->nscell, "This->nstablecell", cb); 393 } 394 395 static void HTMLTableCell_unlink(HTMLDOMNode *iface) 396 { 397 HTMLTableCell *This = impl_from_HTMLDOMNode(iface); 398 399 if(This->nscell) { 400 nsIDOMHTMLTableCellElement *nscell = This->nscell; 401 402 This->nscell = NULL; 403 nsIDOMHTMLTableCellElement_Release(nscell); 404 } 405 } 406 407 static const NodeImplVtbl HTMLTableCellImplVtbl = { 408 HTMLTableCell_QI, 409 HTMLTableCell_destructor, 410 HTMLElement_cpc, 411 HTMLElement_clone, 412 HTMLElement_handle_event, 413 HTMLElement_get_attr_col, 414 NULL, 415 NULL, 416 NULL, 417 NULL, 418 NULL, 419 NULL, 420 NULL, 421 NULL, 422 NULL, 423 HTMLTableCell_traverse, 424 HTMLTableCell_unlink 425 }; 426 427 static const tid_t HTMLTableCell_iface_tids[] = { 428 HTMLELEMENT_TIDS, 429 IHTMLTableCell_tid, 430 0 431 }; 432 433 static dispex_static_data_t HTMLTableCell_dispex = { 434 NULL, 435 DispHTMLTableCell_tid, 436 NULL, 437 HTMLTableCell_iface_tids 438 }; 439 440 HRESULT HTMLTableCell_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem) 441 { 442 HTMLTableCell *ret; 443 nsresult nsres; 444 445 ret = heap_alloc_zero(sizeof(*ret)); 446 if(!ret) 447 return E_OUTOFMEMORY; 448 449 ret->IHTMLTableCell_iface.lpVtbl = &HTMLTableCellVtbl; 450 ret->element.node.vtbl = &HTMLTableCellImplVtbl; 451 452 HTMLElement_Init(&ret->element, doc, nselem, &HTMLTableCell_dispex); 453 454 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLTableCellElement, (void**)&ret->nscell); 455 assert(nsres == NS_OK); 456 457 *elem = &ret->element; 458 return S_OK; 459 } 460