Bug 453883, ensure true/false marcos are available, r=joshmoz, sr=jst
[wine-gecko.git] / accessible / src / msaa / CAccessibleTable.cpp
blob91f3aa350d7c7a31d7b2f97afeb4563442439b06
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
20 * Mozilla Foundation.
21 * Portions created by the Initial Developer are Copyright (C) 2007
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * Alexander Surkov <surkov.alexander@gmail.com> (original author)
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "CAccessibleTable.h"
43 #include "Accessible2.h"
44 #include "AccessibleTable_i.c"
46 #include "nsIAccessible.h"
47 #include "nsIAccessibleTable.h"
48 #include "nsIWinAccessNode.h"
49 #include "nsAccessNodeWrap.h"
51 #include "nsCOMPtr.h"
52 #include "nsString.h"
54 #define CANT_QUERY_ASSERTION_MSG \
55 "Subclass of CAccessibleTable doesn't implement nsIAccessibleTable"\
57 // IUnknown
59 STDMETHODIMP
60 CAccessibleTable::QueryInterface(REFIID iid, void** ppv)
62 *ppv = NULL;
64 if (IID_IAccessibleTable == iid) {
65 *ppv = static_cast<IAccessibleTable*>(this);
66 (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
67 return S_OK;
70 return E_NOINTERFACE;
73 // IAccessibleTable
75 STDMETHODIMP
76 CAccessibleTable::get_accessibleAt(long aRow, long aColumn,
77 IUnknown **aAccessible)
79 __try {
80 *aAccessible = NULL;
82 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
83 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
84 if (!tableAcc)
85 return E_FAIL;
87 nsCOMPtr<nsIAccessible> cell;
88 nsresult rv = tableAcc->CellRefAt(aRow, aColumn, getter_AddRefs(cell));
89 if (NS_FAILED(rv))
90 return GetHRESULT(rv);
92 nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(cell));
93 if (!winAccessNode)
94 return E_FAIL;
96 void *instancePtr = NULL;
97 rv = winAccessNode->QueryNativeInterface(IID_IAccessible2, &instancePtr);
98 if (NS_FAILED(rv))
99 return E_FAIL;
101 *aAccessible = static_cast<IUnknown*>(instancePtr);
102 return S_OK;
104 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
105 return E_FAIL;
108 STDMETHODIMP
109 CAccessibleTable::get_caption(IUnknown **aAccessible)
111 __try {
112 *aAccessible = NULL;
114 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
115 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
116 if (!tableAcc)
117 return E_FAIL;
119 nsCOMPtr<nsIAccessible> caption;
120 nsresult rv = tableAcc->GetCaption(getter_AddRefs(caption));
121 if (NS_FAILED(rv))
122 return GetHRESULT(rv);
124 if (!caption)
125 return S_FALSE;
127 nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(caption));
128 if (!winAccessNode)
129 return E_FAIL;
131 void *instancePtr = NULL;
132 rv = winAccessNode->QueryNativeInterface(IID_IAccessible2, &instancePtr);
133 if (NS_FAILED(rv))
134 return E_FAIL;
136 *aAccessible = static_cast<IUnknown*>(instancePtr);
137 return S_OK;
139 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
140 return E_FAIL;
143 STDMETHODIMP
144 CAccessibleTable::get_childIndex(long aRowIndex, long aColumnIndex,
145 long *aChildIndex)
147 __try {
148 *aChildIndex = 0;
150 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
151 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
152 if (!tableAcc)
153 return E_FAIL;
155 PRInt32 childIndex = 0;
156 nsresult rv = tableAcc->GetIndexAt(aRowIndex, aColumnIndex, &childIndex);
157 if (NS_FAILED(rv))
158 return GetHRESULT(rv);
160 *aChildIndex = childIndex;
161 return S_OK;
163 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
164 return E_FAIL;
167 STDMETHODIMP
168 CAccessibleTable::get_columnDescription(long aColumn, BSTR *aDescription)
170 __try {
171 *aDescription = NULL;
173 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
174 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
175 if (!tableAcc)
176 return E_FAIL;
178 nsAutoString descr;
179 nsresult rv = tableAcc->GetColumnDescription (aColumn, descr);
180 if (NS_FAILED(rv))
181 return GetHRESULT(rv);
183 if (descr.IsEmpty())
184 return S_FALSE;
186 *aDescription = ::SysAllocStringLen(descr.get(), descr.Length());
187 return *aDescription ? S_OK : E_OUTOFMEMORY;
189 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
190 return E_FAIL;
193 STDMETHODIMP
194 CAccessibleTable::get_columnExtentAt(long aRow, long aColumn,
195 long *nColumnsSpanned)
197 __try {
198 *nColumnsSpanned = 0;
200 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
201 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
202 if (!tableAcc)
203 return E_FAIL;
205 PRInt32 columnsSpanned = 0;
206 nsresult rv = tableAcc->GetColumnExtentAt(aRow, aColumn, &columnsSpanned);
207 if (NS_FAILED(rv))
208 return GetHRESULT(rv);
210 *nColumnsSpanned = columnsSpanned;
211 return S_OK;
213 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
214 return E_FAIL;
217 STDMETHODIMP
218 CAccessibleTable::get_columnHeader(IAccessibleTable **aAccessibleTable,
219 long *aStartingRowIndex)
221 __try {
222 *aAccessibleTable = NULL;
224 // XXX: starting row index is always 0.
225 *aStartingRowIndex = 0;
227 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
228 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
229 if (!tableAcc)
230 return E_FAIL;
232 nsCOMPtr<nsIAccessibleTable> header;
233 nsresult rv = tableAcc->GetColumnHeader(getter_AddRefs(header));
234 if (NS_FAILED(rv))
235 return GetHRESULT(rv);
237 if (!header)
238 return S_FALSE;
240 nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(header));
241 if (!winAccessNode)
242 return E_FAIL;
244 void *instancePtr = NULL;
245 rv = winAccessNode->QueryNativeInterface(IID_IAccessibleTable, &instancePtr);
246 if (NS_FAILED(rv))
247 return GetHRESULT(rv);
249 *aAccessibleTable = static_cast<IAccessibleTable*>(instancePtr);
250 return S_OK;
252 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
253 return E_FAIL;
256 STDMETHODIMP
257 CAccessibleTable::get_columnIndex(long aChildIndex, long *aColumnIndex)
259 __try {
260 *aColumnIndex = 0;
262 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
263 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
264 if (!tableAcc)
265 return E_FAIL;
267 PRInt32 columnIndex = 0;
268 nsresult rv = tableAcc->GetColumnAtIndex(aChildIndex, &columnIndex);
269 if (NS_FAILED(rv))
270 return GetHRESULT(rv);
272 *aColumnIndex = columnIndex;
273 return S_OK;
275 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
276 return E_FAIL;
279 STDMETHODIMP
280 CAccessibleTable::get_nColumns(long *aColumnCount)
282 __try {
283 *aColumnCount = 0;
285 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
286 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
287 if (!tableAcc)
288 return E_FAIL;
290 PRInt32 columnCount = 0;
291 nsresult rv = tableAcc->GetColumns(&columnCount);
292 if (NS_FAILED(rv))
293 return GetHRESULT(rv);
295 *aColumnCount = columnCount;
296 return S_OK;
298 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
299 return E_FAIL;
302 STDMETHODIMP
303 CAccessibleTable::get_nRows(long *aRowCount)
305 __try {
306 *aRowCount = 0;
308 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
309 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
310 if (!tableAcc)
311 return E_FAIL;
313 PRInt32 rowCount = 0;
314 nsresult rv = tableAcc->GetRows(&rowCount);
315 if (NS_FAILED(rv))
316 return GetHRESULT(rv);
318 *aRowCount = rowCount;
319 return S_OK;
321 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
322 return E_FAIL;
325 STDMETHODIMP
326 CAccessibleTable::get_nSelectedChildren(long *aChildCount)
328 __try {
329 *aChildCount = 0;
331 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
332 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
333 if (!tableAcc)
334 return E_FAIL;
336 PRUint32 count = 0;
337 nsresult rv = tableAcc->GetSelectedCellsCount(&count);
338 if (NS_FAILED(rv))
339 return GetHRESULT(rv);
341 *aChildCount = count;
342 return S_OK;
344 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
345 return E_FAIL;
348 STDMETHODIMP
349 CAccessibleTable::get_nSelectedColumns(long *aColumnCount)
351 __try {
352 *aColumnCount = 0;
354 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
355 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
356 if (!tableAcc)
357 return E_FAIL;
359 PRUint32 count = 0;
360 nsresult rv = tableAcc->GetSelectedColumnsCount(&count);
361 if (NS_FAILED(rv))
362 return GetHRESULT(rv);
364 *aColumnCount = count;
365 return S_OK;
367 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
368 return E_FAIL;
371 STDMETHODIMP
372 CAccessibleTable::get_nSelectedRows(long *aRowCount)
374 __try {
375 *aRowCount = 0;
377 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
378 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
379 if (!tableAcc)
380 return E_FAIL;
382 PRUint32 count = 0;
383 nsresult rv = tableAcc->GetSelectedRowsCount(&count);
384 if (NS_FAILED(rv))
385 return GetHRESULT(rv);
387 *aRowCount = count;
388 return S_OK;
390 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
391 return E_FAIL;
394 STDMETHODIMP
395 CAccessibleTable::get_rowDescription(long aRow, BSTR *aDescription)
397 __try {
398 *aDescription = NULL;
400 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
401 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
402 if (!tableAcc)
403 return E_FAIL;
405 nsAutoString descr;
406 nsresult rv = tableAcc->GetRowDescription (aRow, descr);
407 if (NS_FAILED(rv))
408 return GetHRESULT(rv);
410 if (descr.IsEmpty())
411 return S_FALSE;
413 *aDescription = ::SysAllocStringLen(descr.get(), descr.Length());
414 return *aDescription ? S_OK : E_OUTOFMEMORY;
416 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
417 return E_FAIL;
420 STDMETHODIMP
421 CAccessibleTable::get_rowExtentAt(long aRow, long aColumn, long *aNRowsSpanned)
423 __try {
424 *aNRowsSpanned = 0;
426 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
427 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
428 if (!tableAcc)
429 return E_FAIL;
431 PRInt32 rowsSpanned = 0;
432 nsresult rv = tableAcc->GetRowExtentAt(aRow, aColumn, &rowsSpanned);
433 if (NS_FAILED(rv))
434 return GetHRESULT(rv);
436 *aNRowsSpanned = rowsSpanned;
437 return S_OK;
439 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
440 return E_FAIL;
443 STDMETHODIMP
444 CAccessibleTable::get_rowHeader(IAccessibleTable **aAccessibleTable,
445 long *aStartingColumnIndex)
447 __try {
448 *aAccessibleTable = NULL;
450 // XXX: starting column index is always 0.
451 *aStartingColumnIndex = 0;
453 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
454 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
455 if (!tableAcc)
456 return E_FAIL;
458 nsCOMPtr<nsIAccessibleTable> header;
459 nsresult rv = tableAcc->GetRowHeader(getter_AddRefs(header));
460 if (NS_FAILED(rv))
461 return GetHRESULT(rv);
463 if (!header)
464 return S_FALSE;
466 nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(header));
467 if (!winAccessNode)
468 return E_FAIL;
470 void *instancePtr = NULL;
471 rv = winAccessNode->QueryNativeInterface(IID_IAccessibleTable,
472 &instancePtr);
473 if (NS_FAILED(rv))
474 return GetHRESULT(rv);
476 *aAccessibleTable = static_cast<IAccessibleTable*>(instancePtr);
477 return S_OK;
479 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
480 return E_FAIL;
483 STDMETHODIMP
484 CAccessibleTable::get_rowIndex(long aChildIndex, long *aRowIndex)
486 __try {
487 *aRowIndex = 0;
489 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
490 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
491 if (!tableAcc)
492 return E_FAIL;
494 PRInt32 rowIndex = 0;
495 nsresult rv = tableAcc->GetRowAtIndex(aChildIndex, &rowIndex);
496 if (NS_FAILED(rv))
497 return GetHRESULT(rv);
499 *aRowIndex = rowIndex;
500 return S_OK;
502 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
503 return E_FAIL;
506 STDMETHODIMP
507 CAccessibleTable::get_selectedChildren(long aMaxChildren, long **aChildren,
508 long *aNChildren)
510 __try {
511 return GetSelectedItems(aMaxChildren, aChildren, aNChildren, ITEMSTYPE_CELLS);
512 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
513 return E_FAIL;
516 STDMETHODIMP
517 CAccessibleTable::get_selectedColumns(long aMaxColumns, long **aColumns,
518 long *aNColumns)
520 __try {
521 return GetSelectedItems(aMaxColumns, aColumns, aNColumns, ITEMSTYPE_COLUMNS);
522 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
523 return E_FAIL;
526 STDMETHODIMP
527 CAccessibleTable::get_selectedRows(long aMaxRows, long **aRows, long *aNRows)
529 __try {
530 return GetSelectedItems(aMaxRows, aRows, aNRows, ITEMSTYPE_ROWS);
531 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
532 return E_FAIL;
535 STDMETHODIMP
536 CAccessibleTable::get_summary(IUnknown **aAccessible)
538 __try {
539 *aAccessible = NULL;
541 // Neither html:table nor xul:tree nor ARIA grid/tree have an ability to
542 // link an accessible object to specify a summary. There is closes method
543 // in nsIAccessibleTable::summary to get a summary as a string which is not
544 // mapped directly to IAccessible2.
546 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
547 return S_FALSE;
550 STDMETHODIMP
551 CAccessibleTable::get_isColumnSelected(long aColumn, boolean *aIsSelected)
553 __try {
554 *aIsSelected = false;
556 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
557 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
558 if (!tableAcc)
559 return E_FAIL;
561 PRBool isSelected = PR_FALSE;
562 nsresult rv = tableAcc->IsColumnSelected(aColumn, &isSelected);
563 if (NS_FAILED(rv))
564 return GetHRESULT(rv);
566 *aIsSelected = isSelected;
567 return S_OK;
569 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
570 return E_FAIL;
573 STDMETHODIMP
574 CAccessibleTable::get_isRowSelected(long aRow, boolean *aIsSelected)
576 __try {
577 *aIsSelected = false;
579 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
580 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
581 if (!tableAcc)
582 return E_FAIL;
584 PRBool isSelected = PR_FALSE;
585 nsresult rv = tableAcc->IsRowSelected(aRow, &isSelected);
586 if (NS_FAILED(rv))
587 return GetHRESULT(rv);
589 *aIsSelected = isSelected;
590 return S_OK;
592 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
593 return E_FAIL;
596 STDMETHODIMP
597 CAccessibleTable::get_isSelected(long aRow, long aColumn, boolean *aIsSelected)
599 __try {
600 *aIsSelected = false;
602 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
603 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
604 if (!tableAcc)
605 return E_FAIL;
607 PRBool isSelected = PR_FALSE;
608 nsresult rv = tableAcc->IsCellSelected(aRow, aColumn, &isSelected);
609 if (NS_FAILED(rv))
610 return GetHRESULT(rv);
612 *aIsSelected = isSelected;
613 return S_OK;
615 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
616 return E_FAIL;
619 STDMETHODIMP
620 CAccessibleTable::selectRow(long aRow)
622 __try {
623 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
624 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
625 if (!tableAcc)
626 return E_FAIL;
628 nsresult rv = tableAcc->SelectRow(aRow);
629 return GetHRESULT(rv);
631 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
632 return E_FAIL;
635 STDMETHODIMP
636 CAccessibleTable::selectColumn(long aColumn)
638 __try {
639 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
640 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
641 if (!tableAcc)
642 return E_FAIL;
644 nsresult rv = tableAcc->SelectColumn(aColumn);
645 return GetHRESULT(rv);
647 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
648 return E_FAIL;
651 STDMETHODIMP
652 CAccessibleTable::unselectRow(long aRow)
654 __try {
655 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
656 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
657 if (!tableAcc)
658 return E_FAIL;
660 nsresult rv = tableAcc->UnselectRow(aRow);
661 return GetHRESULT(rv);
663 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
664 return E_FAIL;
667 STDMETHODIMP
668 CAccessibleTable::unselectColumn(long aColumn)
670 __try {
671 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
672 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
673 if (!tableAcc)
674 return E_FAIL;
676 nsresult rv = tableAcc->UnselectColumn(aColumn);
677 return GetHRESULT(rv);
679 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
680 return E_FAIL;
683 STDMETHODIMP
684 CAccessibleTable::get_rowColumnExtentsAtIndex(long aIndex, long *aRow,
685 long *aColumn,
686 long *aRowExtents,
687 long *aColumnExtents,
688 boolean *aIsSelected)
690 __try {
691 *aRow = 0;
692 *aColumn = 0;
693 *aRowExtents = 0;
694 *aColumnExtents = 0;
695 *aIsSelected = false;
697 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
698 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
699 if (!tableAcc)
700 return E_FAIL;
702 PRInt32 row = -1;
703 nsresult rv = tableAcc->GetRowAtIndex(aIndex, &row);
704 if (NS_FAILED(rv))
705 return GetHRESULT(rv);
707 PRInt32 column = -1;
708 rv = tableAcc->GetColumnAtIndex(aIndex, &column);
709 if (NS_FAILED(rv))
710 return GetHRESULT(rv);
712 PRInt32 rowExtents = 0;
713 rv = tableAcc->GetRowExtentAt(row, column, &rowExtents);
714 if (NS_FAILED(rv))
715 return GetHRESULT(rv);
717 PRInt32 columnExtents = 0;
718 rv = tableAcc->GetColumnExtentAt(row, column, &columnExtents);
719 if (NS_FAILED(rv))
720 return GetHRESULT(rv);
722 PRBool isSelected = PR_FALSE;
723 rv = tableAcc->IsCellSelected(row, column, &isSelected);
724 if (NS_FAILED(rv))
725 return GetHRESULT(rv);
727 *aRow = row;
728 *aColumn = column;
729 *aRowExtents = rowExtents;
730 *aColumnExtents = columnExtents;
731 *aIsSelected = isSelected;
732 return S_OK;
734 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
735 return E_FAIL;
738 STDMETHODIMP
739 CAccessibleTable::get_modelChange(IA2TableModelChange *aModelChange)
741 __try {
743 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
744 return E_NOTIMPL;
747 // CAccessibleTable
749 HRESULT
750 CAccessibleTable::GetSelectedItems(long aMaxItems, long **aItems,
751 long *aItemsCount, eItemsType aType)
753 *aItemsCount = 0;
755 nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
756 NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
757 if (!tableAcc)
758 return E_FAIL;
760 PRUint32 size = 0;
761 PRInt32 *items = nsnull;
763 nsresult rv = NS_OK;
764 switch (aType) {
765 case ITEMSTYPE_CELLS:
766 rv = tableAcc->GetSelectedCells(&size, &items);
767 break;
768 case ITEMSTYPE_COLUMNS:
769 rv = tableAcc->GetSelectedColumns(&size, &items);
770 break;
771 case ITEMSTYPE_ROWS:
772 rv = tableAcc->GetSelectedRows(&size, &items);
773 break;
774 default:
775 return E_FAIL;
778 if (NS_FAILED(rv))
779 return GetHRESULT(rv);
781 if (size == 0 || !items)
782 return S_FALSE;
784 PRUint32 maxSize = size < static_cast<PRUint32>(aMaxItems) ? size : aMaxItems;
785 *aItemsCount = maxSize;
787 *aItems = static_cast<long*>(nsMemory::Alloc((maxSize) * sizeof(long)));
788 if (!*aItems)
789 return E_OUTOFMEMORY;
791 for (PRUint32 index = 0; index < maxSize; ++index)
792 (*aItems)[index] = items[index];
794 nsMemory::Free(items);
795 return S_OK;