Avoid potential negative array index access to cached text.
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccTable.cxx
bloba158cf70667fe580017125b490eb07bafa341081
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 /**
21 * AccTable.cpp : Implementation of CAccTable.
23 #include "stdafx.h"
24 #include <UAccCOM.h>
25 #include "AccTable.h"
27 #include <sal/log.hxx>
28 #include <vcl/svapp.hxx>
29 #include <o3tl/char16_t2wchar_t.hxx>
31 #include <com/sun/star/accessibility/XAccessible.hpp>
32 #include "MAccessible.h"
34 #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
36 using namespace com::sun::star::accessibility;
37 using namespace com::sun::star::uno;
38 /**
39 * Gets accessible table cell.
41 * @param row the row of the specified cell.
42 * @param column the column of the specified cell.
43 * @param accessible the accessible object of the cell.
46 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_accessibleAt(long row, long column, IUnknown * * accessible)
48 SolarMutexGuard g;
50 try {
52 if(accessible == nullptr)
53 return E_INVALIDARG;
55 if(!pRXTable.is())
56 return E_FAIL;
58 Reference<XAccessible> pRAcc = pRXTable->getAccessibleCellAt(row, column);
60 if(!pRAcc.is())
62 *accessible = nullptr;
63 return E_FAIL;
66 IAccessible* pRet = CMAccessible::get_IAccessibleFromXAccessible(pRAcc.get());
67 if (pRet)
69 *accessible = pRet;
70 pRet->AddRef();
71 return S_OK;
73 else if(pRAcc.is())
75 Reference<XAccessible> pxTable(pRXTable, UNO_QUERY);
77 CMAccessible::g_pAccObjectManager->InsertAccObj(pRAcc.get(),pxTable.get());
78 pRet = CMAccessible::get_IAccessibleFromXAccessible(pRAcc.get());
80 if (pRet)
82 *accessible = pRet;
83 pRet->AddRef();
84 return S_OK;
87 return E_FAIL;
89 } catch(...) { return E_FAIL; }
92 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_cellAt(long row, long column, IUnknown * * cell)
94 return get_accessibleAt(row, column, cell);
97 /**
98 * Gets accessible table caption.
100 * @param accessible the accessible object of table caption.
102 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_caption(IUnknown * *)
104 return E_NOTIMPL;
108 * Gets accessible column description (as string).
110 * @param column the column index.
111 * @param description the description of the specified column.
113 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnDescription(long column, BSTR * description)
115 SolarMutexGuard g;
117 try {
119 if(description == nullptr)
120 return E_INVALIDARG;
122 if(!pRXTable.is())
123 return E_FAIL;
125 const OUString& ouStr = pRXTable->getAccessibleColumnDescription(column);
127 SysFreeString(*description);
128 *description = SysAllocString(o3tl::toW(ouStr.getStr()));
129 if (*description==nullptr)
130 return E_FAIL;
131 return S_OK;
133 } catch(...) { return E_FAIL; }
137 * Gets number of columns spanned by table cell.
139 * @param row the row of the specified cell.
140 * @param column the column of the specified cell.
141 * @param spanColumns the column span of the specified cell.
143 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnExtentAt(long row, long column, long * nColumnsSpanned)
145 SolarMutexGuard g;
147 try {
149 // Check pointer.
150 if(nColumnsSpanned == nullptr)
151 return E_INVALIDARG;
153 if(!pRXTable.is())
154 return E_FAIL;
156 *nColumnsSpanned = pRXTable->getAccessibleColumnExtentAt(row, column);
157 return S_OK;
159 } catch(...) { return E_FAIL; }
163 * Gets accessible column header.
165 * @param column the column index.
166 * @param accessible the accessible object of the specified column.
168 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *accessibleTable, long *startingRowIndex)
170 SolarMutexGuard g;
172 try {
174 if(accessibleTable == nullptr || startingRowIndex == nullptr)
175 return E_INVALIDARG;
177 if(!pRXTable.is())
178 return E_FAIL;
180 Reference<XAccessibleTable> pRColumnHeaderTable = pRXTable->getAccessibleColumnHeaders();
181 if(!pRColumnHeaderTable.is())
183 *accessibleTable = nullptr;
184 return E_FAIL;
187 Reference<XAccessible> pRXColumnHeader(pRColumnHeaderTable,UNO_QUERY);
189 if(!pRXColumnHeader.is())
191 *accessibleTable = nullptr;
192 return E_FAIL;
194 *startingRowIndex = 0 ;
196 IMAccessible* pIMacc = nullptr;
197 HRESULT hr = createInstance<CMAccessible>(IID_IMAccessible, &pIMacc);
198 if (!SUCCEEDED(hr))
200 return E_FAIL;
202 pIMacc->SetXAccessible(
203 reinterpret_cast<hyper>(pRXColumnHeader.get()));
204 pIMacc->QueryInterface(IID_IAccessibleTable,reinterpret_cast<void **>(accessibleTable));
206 return S_OK;
208 } catch(...) { return E_FAIL; }
212 * Gets total number of columns in table.
214 * @param columnCount the number of columns in table.
216 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nColumns(long * columnCount)
218 SolarMutexGuard g;
220 try {
222 if(columnCount == nullptr)
223 return E_INVALIDARG;
225 if(!pRXTable.is())
226 return E_FAIL;
228 *columnCount = pRXTable->getAccessibleColumnCount();
229 return S_OK;
231 } catch(...) { return E_FAIL; }
235 * Gets total number of rows in table.
237 * @param rowCount the number of rows in table.
239 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nRows(long * rowCount)
241 SolarMutexGuard g;
243 try {
245 if(rowCount == nullptr)
246 return E_INVALIDARG;
248 if(!pRXTable.is())
249 return E_FAIL;
251 *rowCount = pRXTable->getAccessibleRowCount();
252 return S_OK;
254 } catch(...) { return E_FAIL; }
258 * Gets total number of selected columns.
260 * @param columnCount the number of selected columns.
262 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedColumns(long * columnCount)
264 SolarMutexGuard g;
266 try {
268 if(columnCount == nullptr)
269 return E_INVALIDARG;
271 if(!pRXTable.is())
272 return E_FAIL;
274 Sequence<long> pSelected = pRXTable->getSelectedAccessibleColumns();
275 *columnCount = pSelected.getLength();
276 return S_OK;
278 } catch(...) { return E_FAIL; }
282 * Gets total number of selected rows.
284 * @param rowCount the number of selected rows.
286 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedRows(long * rowCount)
288 SolarMutexGuard g;
290 try {
292 if(rowCount == nullptr)
293 return E_INVALIDARG;
295 if(!pRXTable.is())
296 return E_FAIL;
298 Sequence<long> pSelected = pRXTable->getSelectedAccessibleRows();
299 *rowCount = pSelected.getLength();
300 return S_OK;
302 } catch(...) { return E_FAIL; }
306 * Gets accessible row description (as string).
308 * @param row the row index.
309 * @param description the description of the specified row.
311 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowDescription(long row, BSTR * description)
313 SolarMutexGuard g;
315 try {
317 if(description == nullptr)
318 return E_INVALIDARG;
320 if(!pRXTable.is())
321 return E_FAIL;
323 const OUString& ouStr = pRXTable->getAccessibleRowDescription(row);
325 SysFreeString(*description);
326 *description = SysAllocString(o3tl::toW(ouStr.getStr()));
327 if (*description==nullptr)
328 return E_FAIL;
329 return S_OK;
331 } catch(...) { return E_FAIL; }
335 * Gets number of rows spanned by a table cell.
337 * @param row the row of the specified cell.
338 * @param column the column of the specified cell.
339 * @param spanRows the row span of the specified cell.
341 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowExtentAt(long row, long column, long * nRowsSpanned)
343 SolarMutexGuard g;
345 try {
347 // Check pointer.
348 if(nRowsSpanned == nullptr)
349 return E_INVALIDARG;
351 if(!pRXTable.is())
352 return E_FAIL;
354 *nRowsSpanned= pRXTable->getAccessibleRowExtentAt(row, column);
356 return S_OK;
358 } catch(...) { return E_FAIL; }
362 * Gets accessible row header.
364 * @param row the row index.
365 * @param accessible the accessible object of the row header.
367 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *accessibleTable, long *startingColumnIndex)
369 SolarMutexGuard g;
371 try {
373 if(accessibleTable == nullptr || startingColumnIndex == nullptr)
374 return E_INVALIDARG;
376 if(!pRXTable.is())
377 return E_FAIL;
379 Reference<XAccessibleTable> pRRowHeaderTable = pRXTable->getAccessibleRowHeaders();
380 if(!pRRowHeaderTable.is())
382 *accessibleTable = nullptr;
383 return E_FAIL;
386 Reference<XAccessible> pRXRowHeader(pRRowHeaderTable,UNO_QUERY);
388 if(!pRXRowHeader.is())
390 *accessibleTable = nullptr;
391 return E_FAIL;
393 *startingColumnIndex = 0 ;
395 IMAccessible* pIMacc = nullptr;
396 HRESULT hr = createInstance<CMAccessible>(IID_IMAccessible, &pIMacc);
397 if (!SUCCEEDED(hr))
399 return E_FAIL;
401 pIMacc->SetXAccessible(
402 reinterpret_cast<hyper>(pRXRowHeader.get()));
403 pIMacc->QueryInterface(IID_IAccessibleTable,reinterpret_cast<void **>(accessibleTable));
405 return S_OK;
407 } catch(...) { return E_FAIL; }
411 * Gets list of row indexes currently selected (0-based).
413 * @param accessible the accessible object array of the selected rows.
414 * @param nRows the actual size of the accessible object array.
416 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedRows(long** rows, long* nRows)
418 SolarMutexGuard g;
420 try {
422 if(rows == nullptr || nRows == nullptr)
423 return E_INVALIDARG;
425 if(!pRXTable.is())
426 return E_FAIL;
428 Sequence<long> pSelected = pRXTable->getSelectedAccessibleRows();
429 long count = pSelected.getLength() ;
430 *nRows = count;
432 *rows = static_cast<long*>(CoTaskMemAlloc(count * sizeof(long)));
433 // #CHECK Memory Allocation#
434 if(*rows == nullptr)
436 return E_FAIL;
438 for(int i=0; i<count; i++)
439 (*rows)[i] = pSelected[i];
441 return S_OK;
443 } catch(...) { return E_FAIL; }
447 * Gets list of row indexes currently selected (0-based).
449 * @param maxRows This parameter is ignored.
450 * @param accessible the accessible object array of the selected rows.
451 * @param nRows the actual size of the accessible object array.
453 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedRows(long, long ** rows, long * nRows)
455 return get_selectedRows(rows, nRows);
459 * Gets list of column indexes currently selected (0-based).
461 * @param accessible the accessible object array of the selected columns.
462 * @param numColumns the actual size of accessible object array.
464 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedColumns(long ** columns, long * numColumns)
466 SolarMutexGuard g;
468 try {
470 if(columns == nullptr || numColumns == nullptr)
471 return E_INVALIDARG;
473 if(!pRXTable.is())
474 return E_FAIL;
476 Sequence<long> pSelected = pRXTable->getSelectedAccessibleColumns();
477 long count = pSelected.getLength() ;
478 *numColumns = count;
480 *columns = static_cast<long*>(CoTaskMemAlloc(count * sizeof(long)));
481 // #CHECK Memory Allocation#
482 if(*columns == nullptr)
484 return E_FAIL;
486 for(int i=0; i<count; i++)
487 (*columns)[i] = pSelected[i];
489 return S_OK;
491 } catch(...) { return E_FAIL; }
495 * Gets list of column indexes currently selected (0-based).
497 * @param maxColumns This parameter is ignored
498 * @param accessible the accessible object array of the selected columns.
499 * @param numColumns the actual size of accessible object array.
501 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedColumns(long, long ** columns, long * numColumns)
503 return get_selectedColumns(columns, numColumns);
507 * Gets accessible table summary.
509 * @param accessible the accessible object of the summary.
511 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_summary(IUnknown * * accessible)
513 SolarMutexGuard g;
515 try {
517 if(accessible == nullptr)
518 return E_INVALIDARG;
520 if(!pRXTable.is())
521 return E_FAIL;
523 Reference<XAccessible> pRAcc = pRXTable->getAccessibleSummary();
525 IAccessible* pRet = CMAccessible::get_IAccessibleFromXAccessible(pRAcc.get());
527 if(pRet)
529 *accessible = pRet;
530 pRet->AddRef();
531 return S_OK;
534 return E_FAIL;
536 } catch(...) { return E_FAIL; }
540 * Determines if table column is selected.
542 * @param column the column index.
543 * @param isSelected the result.
545 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_isColumnSelected(long column, boolean * isSelected)
547 SolarMutexGuard g;
549 try {
551 if(isSelected == nullptr)
552 return E_INVALIDARG;
554 if(!pRXTable.is())
555 return E_FAIL;
557 *isSelected = pRXTable->isAccessibleColumnSelected(column);
558 return S_OK;
560 } catch(...) { return E_FAIL; }
564 * Determines if table row is selected.
566 * @param row the row index.
567 * @param isSelected the result.
569 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_isRowSelected(long row, boolean * isSelected)
571 SolarMutexGuard g;
573 try {
575 if(isSelected == nullptr)
576 return E_INVALIDARG;
578 if(!pRXTable.is())
579 return E_FAIL;
581 *isSelected = pRXTable->isAccessibleRowSelected(row);
582 return S_OK;
584 } catch(...) { return E_FAIL; }
588 * Determines if table cell is selected.
590 * @param row the row index.
591 * @param column the column index.
592 * @param isSelected the result.
594 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_isSelected(long row, long column, boolean * isSelected)
596 SolarMutexGuard g;
598 try {
600 if(isSelected == nullptr)
601 return E_INVALIDARG;
603 if(!pRXTable.is())
604 return E_FAIL;
606 *isSelected = pRXTable->isAccessibleSelected(row, column);
607 return S_OK;
609 } catch(...) { return E_FAIL; }
613 * Selects a row and unselect all previously selected rows.
615 * @param row the row index.
616 * @param success the result.
618 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::selectRow(long row)
620 SolarMutexGuard g;
622 try {
624 // Check XAccessibleTable reference.
625 if(!pRXTable.is())
626 return E_FAIL;
628 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
629 if(pRTableExtent.is())
631 pRTableExtent->selectRow(row);
632 return S_OK;
634 else
636 // Get XAccessibleSelection.
637 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
638 if(!pRSelection.is())
639 return E_FAIL;
641 // Select row.
642 long lCol, lColumnCount;
643 lColumnCount = pRXTable->getAccessibleColumnCount();
644 for(lCol = 0; lCol < lColumnCount; lCol ++)
646 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(row, lCol);
647 pRSelection->selectAccessibleChild(nChildIndex);
650 return S_OK;
653 } catch(...) { return E_FAIL; }
657 * Selects a column and unselect all previously selected columns.
659 * @param column the column index.
660 * @param success the result.
662 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::selectColumn(long column)
664 SolarMutexGuard g;
666 try {
668 // Check XAccessibleTable reference.
669 if(!pRXTable.is())
670 return E_FAIL;
672 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
673 if(pRTableExtent.is())
675 pRTableExtent->selectColumn(column);
676 return S_OK;
678 else
680 // Get XAccessibleSelection.
681 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
682 if(!pRSelection.is())
683 return E_FAIL;
685 // Select column.
686 long lRow, lRowCount;
687 lRowCount = pRXTable->getAccessibleRowCount();
688 for(lRow = 0; lRow < lRowCount; lRow ++)
690 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(lRow, column);
691 pRSelection->selectAccessibleChild(nChildIndex);
694 return S_OK;
696 // End of added.
698 } catch(...) { return E_FAIL; }
702 * Unselects one row, leaving other selected rows selected (if any).
704 * @param row the row index.
705 * @param success the result.
707 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::unselectRow(long row)
709 SolarMutexGuard g;
711 try {
713 // Check XAccessibleTable reference.
714 if(!pRXTable.is())
715 return E_FAIL;
717 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
718 if(pRTableExtent.is())
720 if(pRTableExtent->unselectRow(row))
721 return S_OK;
722 else
723 return E_FAIL;
725 else
727 // Get XAccessibleSelection.
728 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
729 if(!pRSelection.is())
730 return E_FAIL;
732 // Select column.
733 long lColumn, lColumnCount;
734 lColumnCount = pRXTable->getAccessibleColumnCount();
735 for(lColumn = 0; lColumn < lColumnCount; lColumn ++)
737 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(row, lColumn);
738 pRSelection->deselectAccessibleChild(nChildIndex);
741 return S_OK;
743 // End of added.
745 } catch(...) { return E_FAIL; }
749 * Unselects one column, leaving other selected columns selected (if any).
751 * @param column the column index.
752 * @param success the result.
754 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::unselectColumn(long column)
756 SolarMutexGuard g;
758 try {
760 // Check XAccessibleTable reference.
761 if(!pRXTable.is())
762 return E_FAIL;
764 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
765 if(pRTableExtent.is())
767 if(pRTableExtent->unselectColumn(column))
768 return S_OK;
769 else
770 return E_FAIL;
772 else
774 // Get XAccessibleSelection.
775 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
776 if(!pRSelection.is())
777 return E_FAIL;
779 // Unselect columns.
780 long lRow, lRowCount;
781 lRowCount = pRXTable->getAccessibleRowCount();
783 for(lRow = 0; lRow < lRowCount; lRow ++)
785 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(lRow, column);
786 pRSelection->deselectAccessibleChild(nChildIndex);
788 return S_OK;
791 } catch(...) { return E_FAIL; }
795 * Override of IUNOXWrapper.
797 * @param pXInterface the pointer of UNO interface.
799 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::put_XInterface(hyper pXInterface)
801 // internal IUNOXWrapper - no mutex meeded
803 try {
805 CUNOXWrapper::put_XInterface(pXInterface);
806 //special query.
807 if(pUNOInterface == nullptr)
808 return E_INVALIDARG;
810 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
811 if( !pRContext.is() )
812 return E_FAIL;
814 Reference<XAccessibleTable> pRXI(pRContext,UNO_QUERY);
815 if( !pRXI.is() )
816 pRXTable = nullptr;
817 else
818 pRXTable = pRXI.get();
819 return S_OK;
821 } catch(...) { return E_FAIL; }
826 * Gets columnIndex of childIndex.
828 * @param childIndex childIndex
830 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnIndex(long childIndex, long * columnIndex)
832 SolarMutexGuard g;
834 try {
836 if(columnIndex == nullptr)
837 return E_INVALIDARG;
839 if(!pRXTable.is())
840 return E_FAIL;
842 *columnIndex = pRXTable->getAccessibleColumn(childIndex);
843 return S_OK;
845 } catch(...) { return E_FAIL; }
848 * Gets rowIndex of childIndex.
850 * @param childIndex childIndex
852 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowIndex(long childIndex, long * rowIndex)
854 SolarMutexGuard g;
856 try {
858 if(rowIndex == nullptr)
859 return E_INVALIDARG;
861 if(!pRXTable.is())
862 return E_FAIL;
864 *rowIndex = pRXTable->getAccessibleRow(childIndex);
865 return S_OK;
867 } catch(...) { return E_FAIL; }
871 * Gets childIndex of childIndex.
873 * @param childIndex childIndex
875 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_childIndex(long RowIndex , long columnIndex, long * childIndex )
877 SolarMutexGuard g;
879 try {
881 if(childIndex == nullptr)
882 return E_INVALIDARG;
884 if(!pRXTable.is())
885 return E_FAIL;
887 sal_Int64 nIndex = pRXTable->getAccessibleIndex(RowIndex, columnIndex);
888 if (nIndex > std::numeric_limits<long>::max())
890 // use -2 when the child index is too large to fit into 32 bit to neither use the
891 // valid index of another child nor -1, which is more commonly used to indicate that
892 // a child is no more inside of a parent or invalid otherwise
893 SAL_WARN("vcl.qt", "CAccTable::get_childIndex: Child index exceeds maximum long value, "
894 "returning -2.");
895 nIndex = -2;
897 *childIndex = nIndex;
898 return S_OK;
900 } catch(...) { return E_FAIL; }
903 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowColumnExtentsAtIndex(long,
904 long *,
905 long *,
906 long *,
907 long *,
908 boolean *)
910 return E_NOTIMPL;
913 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_modelChange(IA2TableModelChange *)
915 return E_NOTIMPL;
918 // @brief Returns the total number of selected children
919 // @param [out] childCount
920 // Number of children currently selected
921 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedChildren(long *childCount)
923 SolarMutexGuard g;
925 try {
927 if(childCount == nullptr)
928 return E_INVALIDARG;
930 if(!pRXTable.is())
931 return E_FAIL;
933 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
934 if(!pRSelection.is())
935 return E_FAIL;
937 sal_Int64 nSelected = pRSelection->getSelectedAccessibleChildCount();
938 if (nSelected > std::numeric_limits<long>::max())
940 SAL_WARN("iacc2", "CAccTable::get_nSelectedChildren: Selected item count exceeds maximum long value, "
941 "using max long.");
942 nSelected = std::numeric_limits<long>::max();
944 *childCount = nSelected;
945 return S_OK;
947 } catch(...) { return E_FAIL; }
952 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedCells(long *cellCount)
954 return get_nSelectedChildren(cellCount);
957 // @brief Returns a list of child indexes currently selected (0-based).
958 // @param [in] maxChildren
959 // Max children requested (possibly from IAccessibleTable::nSelectedChildren)
960 // @param [out] children
961 // array of indexes of selected children (each index is 0-based)
962 // @param [out] nChildren
963 // Length of array (not more than maxChildren)
964 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedChildren(long, long **children, long *nChildren)
966 SolarMutexGuard g;
968 try {
970 if(children == nullptr || nChildren == nullptr)
971 return E_INVALIDARG;
973 if(!pRXTable.is())
974 return E_FAIL;
976 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
977 if(!pRSelection.is())
978 return E_FAIL;
980 sal_Int64 nChildCount = pRSelection->getSelectedAccessibleChildCount();
981 if (nChildCount > std::numeric_limits<long>::max())
983 SAL_WARN("iacc2", "CAccTable::get_selectedChildren: Selected child count exceeds maximum long value, "
984 "using max long.");
985 nChildCount = std::numeric_limits<long>::max();
988 *nChildren = nChildCount;
989 *children = static_cast<long*>(CoTaskMemAlloc(nChildCount * sizeof(long)));
991 for( sal_Int64 i = 0; i< nChildCount; i++)
993 Reference<XAccessible> pRAcc = pRSelection->getSelectedAccessibleChild(i);
994 if(pRAcc.is())
996 Reference<XAccessibleContext> pRContext(pRAcc, UNO_QUERY);
997 if( !pRContext.is() )
998 return E_FAIL;
1001 sal_Int64 nChildIndex = pRContext->getAccessibleIndexInParent();
1002 if (nChildIndex > std::numeric_limits<long>::max())
1004 SAL_WARN("iacc2", "CAccTable::get_selectedChildren: Child index exceeds maximum long value, "
1005 "using max long.");
1006 nChildIndex = std::numeric_limits<long>::max();
1008 (*children)[i] = nChildIndex;
1012 return S_OK;
1014 } catch(...) { return E_FAIL; }
1019 * @brief Returns a list of accessibles currently selected.
1020 * @param cells Pointer to an array of references to selected accessibles.
1021 * The array is allocated by the server with CoTaskMemAlloc and
1022 * freed by the client with CoTaskMemFree.
1023 * @param nSelectedCells The number of accessibles returned; the size of the returned array.
1024 * @return S_FALSE if there are none, [out] values are NULL and 0 respectively, otherwise S_OK
1026 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedCells(IUnknown * * * cells, long *nSelectedCells)
1028 SolarMutexGuard g;
1030 try {
1032 if (cells == nullptr || nSelectedCells == nullptr)
1033 return E_INVALIDARG;
1035 if (!pRXTable.is())
1036 return E_FAIL;
1038 Reference<XAccessibleSelection> xSelection(pRXTable, UNO_QUERY);
1039 if (!xSelection.is())
1040 return E_FAIL;
1042 sal_Int64 nSelected = xSelection->getSelectedAccessibleChildCount();
1043 if (nSelected > std::numeric_limits<long>::max())
1045 SAL_WARN("iacc2", "CAccTable::get_selectedCells: Selected cell count exceeds maximum long value, "
1046 "using max long.");
1047 nSelected = std::numeric_limits<long>::max();
1049 *nSelectedCells = nSelected;
1051 *cells = static_cast<IUnknown**>(CoTaskMemAlloc(nSelected * sizeof(IUnknown*)));
1053 for (sal_Int64 i = 0; i < nSelected; i++)
1055 Reference<XAccessible> xAcc = xSelection->getSelectedAccessibleChild(i);
1056 assert(xAcc.is());
1058 IAccessible* pIAccessible = CMAccessible::get_IAccessibleFromXAccessible(xAcc.get());
1060 if (!pIAccessible)
1062 Reference<XAccessible> xTable(pRXTable, UNO_QUERY);
1063 CMAccessible::g_pAccObjectManager->InsertAccObj(xAcc.get(), xTable.get());
1064 pIAccessible = CMAccessible::get_IAccessibleFromXAccessible(xAcc.get());
1067 assert(pIAccessible && "Couldn't retrieve IAccessible object");
1069 pIAccessible->AddRef();
1070 (*cells)[i] = pIAccessible;
1073 return S_OK;
1075 } catch(...) { return E_FAIL; }
1078 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */