Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccTable.cxx
blob2022eb7e24ebe3fcaf9c20ad08dafb01e6757a9f
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 // #CHECK#
53 if(accessible == nullptr)
54 return E_INVALIDARG;
55 // #CHECK XInterface#
56 if(!pRXTable.is())
57 return E_FAIL;
59 Reference<XAccessible> pRAcc = pRXTable->getAccessibleCellAt(row, column);
61 if(!pRAcc.is())
63 *accessible = nullptr;
64 return E_FAIL;
67 IAccessible* pRet = nullptr;
69 bool isTRUE = CMAccessible::get_IAccessibleFromXAccessible(pRAcc.get(), &pRet);
70 if(isTRUE)
72 *accessible = pRet;
73 pRet->AddRef();
74 return S_OK;
76 else if(pRAcc.is())
78 Reference<XAccessible> pxTable(pRXTable, UNO_QUERY);
80 CMAccessible::g_pAgent->InsertAccObj(pRAcc.get(),pxTable.get());
81 isTRUE = CMAccessible::get_IAccessibleFromXAccessible(pRAcc.get(), &pRet);
83 if(isTRUE)
85 *accessible = pRet;
86 pRet->AddRef();
87 return S_OK;
90 return E_FAIL;
92 } catch(...) { return E_FAIL; }
95 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_cellAt(long row, long column, IUnknown * * cell)
97 return get_accessibleAt(row, column, cell);
101 * Gets accessible table caption.
103 * @param accessible the accessible object of table caption.
105 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_caption(IUnknown * *)
107 return E_NOTIMPL;
111 * Gets accessible column description (as string).
113 * @param column the column index.
114 * @param description the description of the specified column.
116 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnDescription(long column, BSTR * description)
118 SolarMutexGuard g;
120 try {
122 // #CHECK#
123 if(description == nullptr)
124 return E_INVALIDARG;
126 // #CHECK XInterface#
127 if(!pRXTable.is())
128 return E_FAIL;
130 const OUString& ouStr = pRXTable->getAccessibleColumnDescription(column);
131 // #CHECK#
133 SysFreeString(*description);
134 *description = SysAllocString(o3tl::toW(ouStr.getStr()));
135 if (*description==nullptr)
136 return E_FAIL;
137 return S_OK;
139 } catch(...) { return E_FAIL; }
143 * Gets number of columns spanned by table cell.
145 * @param row the row of the specified cell.
146 * @param column the column of the specified cell.
147 * @param spanColumns the column span of the specified cell.
149 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnExtentAt(long row, long column, long * nColumnsSpanned)
151 SolarMutexGuard g;
153 try {
155 // Check pointer.
156 if(nColumnsSpanned == nullptr)
157 return E_INVALIDARG;
159 if(!pRXTable.is())
160 return E_FAIL;
162 *nColumnsSpanned = pRXTable->getAccessibleColumnExtentAt(row, column);
163 return S_OK;
165 } catch(...) { return E_FAIL; }
169 * Gets accessible column header.
171 * @param column the column index.
172 * @param accessible the accessible object of the specified column.
174 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *accessibleTable, long *startingRowIndex)
176 SolarMutexGuard g;
178 try {
180 // #CHECK#
181 if(accessibleTable == nullptr || startingRowIndex == nullptr)
182 return E_INVALIDARG;
184 // #CHECK XInterface#
185 if(!pRXTable.is())
186 return E_FAIL;
188 Reference<XAccessibleTable> pRColumnHeaderTable = pRXTable->getAccessibleColumnHeaders();
189 if(!pRColumnHeaderTable.is())
191 *accessibleTable = nullptr;
192 return E_FAIL;
195 Reference<XAccessible> pRXColumnHeader(pRColumnHeaderTable,UNO_QUERY);
197 if(!pRXColumnHeader.is())
199 *accessibleTable = nullptr;
200 return E_FAIL;
202 *startingRowIndex = 0 ;
204 IMAccessible* pIMacc = nullptr;
205 HRESULT hr = createInstance<CMAccessible>(IID_IMAccessible, &pIMacc);
206 if (!SUCCEEDED(hr))
208 return E_FAIL;
210 pIMacc->SetXAccessible(
211 reinterpret_cast<hyper>(pRXColumnHeader.get()));
212 pIMacc->QueryInterface(IID_IAccessibleTable,reinterpret_cast<void **>(accessibleTable));
214 return S_OK;
216 } catch(...) { return E_FAIL; }
220 * Gets total number of columns in table.
222 * @param columnCount the number of columns in table.
224 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nColumns(long * columnCount)
226 SolarMutexGuard g;
228 try {
230 // #CHECK#
231 if(columnCount == nullptr)
232 return E_INVALIDARG;
234 // #CHECK XInterface#
235 if(!pRXTable.is())
236 return E_FAIL;
238 *columnCount = pRXTable->getAccessibleColumnCount();
239 return S_OK;
241 } catch(...) { return E_FAIL; }
245 * Gets total number of rows in table.
247 * @param rowCount the number of rows in table.
249 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nRows(long * rowCount)
251 SolarMutexGuard g;
253 try {
255 // #CHECK#
256 if(rowCount == nullptr)
257 return E_INVALIDARG;
259 // #CHECK XInterface#
260 if(!pRXTable.is())
261 return E_FAIL;
263 *rowCount = pRXTable->getAccessibleRowCount();
264 return S_OK;
266 } catch(...) { return E_FAIL; }
270 * Gets total number of selected columns.
272 * @param columnCount the number of selected columns.
274 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedColumns(long * columnCount)
276 SolarMutexGuard g;
278 try {
280 // #CHECK#
281 if(columnCount == nullptr)
282 return E_INVALIDARG;
284 // #CHECK XInterface#
285 if(!pRXTable.is())
286 return E_FAIL;
288 Sequence<long> pSelected = pRXTable->getSelectedAccessibleColumns();
289 *columnCount = pSelected.getLength();
290 return S_OK;
292 } catch(...) { return E_FAIL; }
296 * Gets total number of selected rows.
298 * @param rowCount the number of selected rows.
300 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedRows(long * rowCount)
302 SolarMutexGuard g;
304 try {
306 // #CHECK#
307 if(rowCount == nullptr)
308 return E_INVALIDARG;
310 // #CHECK XInterface#
311 if(!pRXTable.is())
312 return E_FAIL;
314 Sequence<long> pSelected = pRXTable->getSelectedAccessibleRows();
315 *rowCount = pSelected.getLength();
316 return S_OK;
318 } catch(...) { return E_FAIL; }
322 * Gets accessible row description (as string).
324 * @param row the row index.
325 * @param description the description of the specified row.
327 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowDescription(long row, BSTR * description)
329 SolarMutexGuard g;
331 try {
333 // #CHECK#
334 if(description == nullptr)
335 return E_INVALIDARG;
337 // #CHECK XInterface#
338 if(!pRXTable.is())
339 return E_FAIL;
341 const OUString& ouStr = pRXTable->getAccessibleRowDescription(row);
342 // #CHECK#
344 SysFreeString(*description);
345 *description = SysAllocString(o3tl::toW(ouStr.getStr()));
346 if (*description==nullptr)
347 return E_FAIL;
348 return S_OK;
350 } catch(...) { return E_FAIL; }
354 * Gets number of rows spanned by a table cell.
356 * @param row the row of the specified cell.
357 * @param column the column of the specified cell.
358 * @param spanRows the row span of the specified cell.
360 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowExtentAt(long row, long column, long * nRowsSpanned)
362 SolarMutexGuard g;
364 try {
366 // Check pointer.
367 if(nRowsSpanned == nullptr)
368 return E_INVALIDARG;
370 if(!pRXTable.is())
371 return E_FAIL;
373 *nRowsSpanned= pRXTable->getAccessibleRowExtentAt(row, column);
375 return S_OK;
377 } catch(...) { return E_FAIL; }
381 * Gets accessible row header.
383 * @param row the row index.
384 * @param accessible the accessible object of the row header.
386 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *accessibleTable, long *startingColumnIndex)
388 SolarMutexGuard g;
390 try {
392 // #CHECK#
393 if(accessibleTable == nullptr || startingColumnIndex == nullptr)
394 return E_INVALIDARG;
396 // #CHECK XInterface#
397 if(!pRXTable.is())
398 return E_FAIL;
400 Reference<XAccessibleTable> pRRowHeaderTable = pRXTable->getAccessibleRowHeaders();
401 if(!pRRowHeaderTable.is())
403 *accessibleTable = nullptr;
404 return E_FAIL;
407 Reference<XAccessible> pRXRowHeader(pRRowHeaderTable,UNO_QUERY);
409 if(!pRXRowHeader.is())
411 *accessibleTable = nullptr;
412 return E_FAIL;
414 *startingColumnIndex = 0 ;
416 IMAccessible* pIMacc = nullptr;
417 HRESULT hr = createInstance<CMAccessible>(IID_IMAccessible, &pIMacc);
418 if (!SUCCEEDED(hr))
420 return E_FAIL;
422 pIMacc->SetXAccessible(
423 reinterpret_cast<hyper>(pRXRowHeader.get()));
424 pIMacc->QueryInterface(IID_IAccessibleTable,reinterpret_cast<void **>(accessibleTable));
426 return S_OK;
428 } catch(...) { return E_FAIL; }
432 * Gets list of row indexes currently selected (0-based).
434 * @param accessible the accessible object array of the selected rows.
435 * @param nRows the actual size of the accessible object array.
437 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedRows(long** rows, long* nRows)
439 SolarMutexGuard g;
441 try {
443 // #CHECK#
444 if(rows == nullptr || nRows == nullptr)
445 return E_INVALIDARG;
447 // #CHECK XInterface#
448 if(!pRXTable.is())
449 return E_FAIL;
451 Sequence<long> pSelected = pRXTable->getSelectedAccessibleRows();
452 long count = pSelected.getLength() ;
453 *nRows = count;
455 *rows = static_cast<long*>(CoTaskMemAlloc(count * sizeof(long)));
456 // #CHECK Memory Allocation#
457 if(*rows == nullptr)
459 return E_FAIL;
461 for(int i=0; i<count; i++)
462 (*rows)[i] = pSelected[i];
464 return S_OK;
466 } catch(...) { return E_FAIL; }
470 * Gets list of row indexes currently selected (0-based).
472 * @param maxRows This parameter is ignored.
473 * @param accessible the accessible object array of the selected rows.
474 * @param nRows the actual size of the accessible object array.
476 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedRows(long, long ** rows, long * nRows)
478 return get_selectedRows(rows, nRows);
482 * Gets list of column indexes currently selected (0-based).
484 * @param accessible the accessible object array of the selected columns.
485 * @param numColumns the actual size of accessible object array.
487 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedColumns(long ** columns, long * numColumns)
489 SolarMutexGuard g;
491 try {
493 // #CHECK#
494 if(columns == nullptr || numColumns == nullptr)
495 return E_INVALIDARG;
497 // #CHECK XInterface#
498 if(!pRXTable.is())
499 return E_FAIL;
501 Sequence<long> pSelected = pRXTable->getSelectedAccessibleColumns();
502 long count = pSelected.getLength() ;
503 *numColumns = count;
505 *columns = static_cast<long*>(CoTaskMemAlloc(count * sizeof(long)));
506 // #CHECK Memory Allocation#
507 if(*columns == nullptr)
509 return E_FAIL;
511 for(int i=0; i<count; i++)
512 (*columns)[i] = pSelected[i];
514 return S_OK;
516 } catch(...) { return E_FAIL; }
520 * Gets list of column indexes currently selected (0-based).
522 * @param maxColumns This parameter is ignored
523 * @param accessible the accessible object array of the selected columns.
524 * @param numColumns the actual size of accessible object array.
526 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedColumns(long, long ** columns, long * numColumns)
528 return get_selectedColumns(columns, numColumns);
532 * Gets accessible table summary.
534 * @param accessible the accessible object of the summary.
536 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_summary(IUnknown * * accessible)
538 SolarMutexGuard g;
540 try {
542 // #CHECK#
543 if(accessible == nullptr)
544 return E_INVALIDARG;
546 // #CHECK XInterface#
547 if(!pRXTable.is())
548 return E_FAIL;
550 Reference<XAccessible> pRAcc = pRXTable->getAccessibleSummary();
552 IAccessible* pRet = nullptr;
553 CMAccessible::get_IAccessibleFromXAccessible(pRAcc.get(), &pRet);
555 if(pRet)
557 *accessible = pRet;
558 pRet->AddRef();
559 return S_OK;
562 return E_FAIL;
564 } catch(...) { return E_FAIL; }
568 * Determines if table column is selected.
570 * @param column the column index.
571 * @param isSelected the result.
573 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_isColumnSelected(long column, boolean * isSelected)
575 SolarMutexGuard g;
577 try {
579 // #CHECK#
580 if(isSelected == nullptr)
581 return E_INVALIDARG;
583 // #CHECK XInterface#
584 if(!pRXTable.is())
585 return E_FAIL;
587 *isSelected = pRXTable->isAccessibleColumnSelected(column);
588 return S_OK;
590 } catch(...) { return E_FAIL; }
594 * Determines if table row is selected.
596 * @param row the row index.
597 * @param isSelected the result.
599 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_isRowSelected(long row, boolean * isSelected)
601 SolarMutexGuard g;
603 try {
605 // #CHECK#
606 if(isSelected == nullptr)
607 return E_INVALIDARG;
609 // #CHECK XInterface#
610 if(!pRXTable.is())
611 return E_FAIL;
613 *isSelected = pRXTable->isAccessibleRowSelected(row);
614 return S_OK;
616 } catch(...) { return E_FAIL; }
620 * Determines if table cell is selected.
622 * @param row the row index.
623 * @param column the column index.
624 * @param isSelected the result.
626 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_isSelected(long row, long column, boolean * isSelected)
628 SolarMutexGuard g;
630 try {
632 // #CHECK#
633 if(isSelected == nullptr)
634 return E_INVALIDARG;
636 // #CHECK XInterface#
637 if(!pRXTable.is())
638 return E_FAIL;
640 *isSelected = pRXTable->isAccessibleSelected(row, column);
641 return S_OK;
643 } catch(...) { return E_FAIL; }
647 * Selects a row and unselect all previously selected rows.
649 * @param row the row index.
650 * @param success the result.
652 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::selectRow(long row)
654 SolarMutexGuard g;
656 try {
658 // Check XAccessibleTable reference.
659 if(!pRXTable.is())
660 return E_FAIL;
662 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
663 if(pRTableExtent.is())
665 pRTableExtent->selectRow(row);
666 return S_OK;
668 else
670 // Get XAccessibleSelection.
671 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
672 if(!pRSelection.is())
673 return E_FAIL;
675 // Select row.
676 long lCol, lColumnCount;
677 lColumnCount = pRXTable->getAccessibleColumnCount();
678 for(lCol = 0; lCol < lColumnCount; lCol ++)
680 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(row, lCol);
681 pRSelection->selectAccessibleChild(nChildIndex);
684 return S_OK;
687 } catch(...) { return E_FAIL; }
691 * Selects a column and unselect all previously selected columns.
693 * @param column the column index.
694 * @param success the result.
696 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::selectColumn(long column)
698 SolarMutexGuard g;
700 try {
702 // Check XAccessibleTable reference.
703 if(!pRXTable.is())
704 return E_FAIL;
706 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
707 if(pRTableExtent.is())
709 pRTableExtent->selectColumn(column);
710 return S_OK;
712 else
714 // Get XAccessibleSelection.
715 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
716 if(!pRSelection.is())
717 return E_FAIL;
719 // Select column.
720 long lRow, lRowCount;
721 lRowCount = pRXTable->getAccessibleRowCount();
722 for(lRow = 0; lRow < lRowCount; lRow ++)
724 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(lRow, column);
725 pRSelection->selectAccessibleChild(nChildIndex);
728 return S_OK;
730 // End of added.
732 } catch(...) { return E_FAIL; }
736 * Unselects one row, leaving other selected rows selected (if any).
738 * @param row the row index.
739 * @param success the result.
741 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::unselectRow(long row)
743 SolarMutexGuard g;
745 try {
747 // Check XAccessibleTable reference.
748 if(!pRXTable.is())
749 return E_FAIL;
751 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
752 if(pRTableExtent.is())
754 if(pRTableExtent->unselectRow(row))
755 return S_OK;
756 else
757 return E_FAIL;
759 else
761 // Get XAccessibleSelection.
762 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
763 if(!pRSelection.is())
764 return E_FAIL;
766 // Select column.
767 long lColumn, lColumnCount;
768 lColumnCount = pRXTable->getAccessibleColumnCount();
769 for(lColumn = 0; lColumn < lColumnCount; lColumn ++)
771 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(row, lColumn);
772 pRSelection->deselectAccessibleChild(nChildIndex);
775 return S_OK;
777 // End of added.
779 } catch(...) { return E_FAIL; }
783 * Unselects one column, leaving other selected columns selected (if any).
785 * @param column the column index.
786 * @param success the result.
788 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::unselectColumn(long column)
790 SolarMutexGuard g;
792 try {
794 // Check XAccessibleTable reference.
795 if(!pRXTable.is())
796 return E_FAIL;
798 Reference<XAccessibleTableSelection> pRTableExtent(pRXTable, UNO_QUERY);
799 if(pRTableExtent.is())
801 if(pRTableExtent->unselectColumn(column))
802 return S_OK;
803 else
804 return E_FAIL;
806 else
808 // Get XAccessibleSelection.
809 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
810 if(!pRSelection.is())
811 return E_FAIL;
813 // Unselect columns.
814 long lRow, lRowCount;
815 lRowCount = pRXTable->getAccessibleRowCount();
817 for(lRow = 0; lRow < lRowCount; lRow ++)
819 sal_Int64 nChildIndex = pRXTable->getAccessibleIndex(lRow, column);
820 pRSelection->deselectAccessibleChild(nChildIndex);
822 return S_OK;
825 } catch(...) { return E_FAIL; }
829 * Override of IUNOXWrapper.
831 * @param pXInterface the pointer of UNO interface.
833 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::put_XInterface(hyper pXInterface)
835 // internal IUNOXWrapper - no mutex meeded
837 try {
839 CUNOXWrapper::put_XInterface(pXInterface);
840 //special query.
841 if(pUNOInterface == nullptr)
842 return E_INVALIDARG;
844 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
845 if( !pRContext.is() )
846 return E_FAIL;
848 Reference<XAccessibleTable> pRXI(pRContext,UNO_QUERY);
849 if( !pRXI.is() )
850 pRXTable = nullptr;
851 else
852 pRXTable = pRXI.get();
853 return S_OK;
855 } catch(...) { return E_FAIL; }
860 * Gets columnIndex of childIndex.
862 * @param childIndex childIndex
864 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnIndex(long childIndex, long * columnIndex)
866 SolarMutexGuard g;
868 try {
870 // #CHECK#
871 if(columnIndex == nullptr)
872 return E_INVALIDARG;
874 // #CHECK XInterface#
875 if(!pRXTable.is())
876 return E_FAIL;
878 *columnIndex = pRXTable->getAccessibleColumn(childIndex);
879 return S_OK;
881 } catch(...) { return E_FAIL; }
884 * Gets rowIndex of childIndex.
886 * @param childIndex childIndex
888 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowIndex(long childIndex, long * rowIndex)
890 SolarMutexGuard g;
892 try {
894 // #CHECK#
895 if(rowIndex == nullptr)
896 return E_INVALIDARG;
898 // #CHECK XInterface#
899 if(!pRXTable.is())
900 return E_FAIL;
902 *rowIndex = pRXTable->getAccessibleRow(childIndex);
903 return S_OK;
905 } catch(...) { return E_FAIL; }
909 * Gets childIndex of childIndex.
911 * @param childIndex childIndex
913 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_childIndex(long RowIndex , long columnIndex, long * childIndex )
915 SolarMutexGuard g;
917 try {
919 // #CHECK#
920 if(childIndex == nullptr)
921 return E_INVALIDARG;
923 // #CHECK XInterface#
924 if(!pRXTable.is())
925 return E_FAIL;
927 sal_Int64 nIndex = pRXTable->getAccessibleIndex(RowIndex, columnIndex);
928 if (nIndex > std::numeric_limits<long>::max())
930 // use -2 when the child index is too large to fit into 32 bit to neither use the
931 // valid index of another child nor -1, which is more commonly used to indicate that
932 // a child is no more inside of a parent or invalid otherwise
933 SAL_WARN("vcl.qt", "CAccTable::get_childIndex: Child index exceeds maximum long value, "
934 "returning -2.");
935 nIndex = -2;
937 *childIndex = nIndex;
938 return S_OK;
940 } catch(...) { return E_FAIL; }
943 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowColumnExtentsAtIndex(long,
944 long *,
945 long *,
946 long *,
947 long *,
948 boolean *)
950 return E_NOTIMPL;
953 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_modelChange(IA2TableModelChange *)
955 return E_NOTIMPL;
958 // @brief Returns the total number of selected children
959 // @param [out] childCount
960 // Number of children currently selected
961 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedChildren(long *childCount)
963 SolarMutexGuard g;
965 try {
967 // #CHECK#
968 if(childCount == nullptr)
969 return E_INVALIDARG;
971 // #CHECK XInterface#
972 if(!pRXTable.is())
973 return E_FAIL;
975 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
976 if(!pRSelection.is())
977 return E_FAIL;
979 sal_Int64 nSelected = pRSelection->getSelectedAccessibleChildCount();
980 if (nSelected > std::numeric_limits<long>::max())
982 SAL_WARN("iacc2", "CAccTable::get_nSelectedChildren: Selected item count exceeds maximum long value, "
983 "using max long.");
984 nSelected = std::numeric_limits<long>::max();
986 *childCount = nSelected;
987 return S_OK;
989 } catch(...) { return E_FAIL; }
994 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_nSelectedCells(long *cellCount)
996 return get_nSelectedChildren(cellCount);
999 // @brief Returns a list of child indexes currently selected (0-based).
1000 // @param [in] maxChildren
1001 // Max children requested (possibly from IAccessibleTable::nSelectedChildren)
1002 // @param [out] children
1003 // array of indexes of selected children (each index is 0-based)
1004 // @param [out] nChildren
1005 // Length of array (not more than maxChildren)
1006 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedChildren(long, long **children, long *nChildren)
1008 SolarMutexGuard g;
1010 try {
1012 // #CHECK#
1013 if(children == nullptr || nChildren == nullptr)
1014 return E_INVALIDARG;
1016 // #CHECK XInterface#
1017 if(!pRXTable.is())
1018 return E_FAIL;
1020 Reference<XAccessibleSelection> pRSelection(pRXTable, UNO_QUERY);
1021 if(!pRSelection.is())
1022 return E_FAIL;
1024 sal_Int64 nChildCount = pRSelection->getSelectedAccessibleChildCount();
1025 if (nChildCount > std::numeric_limits<long>::max())
1027 SAL_WARN("iacc2", "CAccTable::get_selectedChildren: Selected child count exceeds maximum long value, "
1028 "using max long.");
1029 nChildCount = std::numeric_limits<long>::max();
1032 *nChildren = nChildCount;
1033 *children = static_cast<long*>(CoTaskMemAlloc(nChildCount * sizeof(long)));
1035 for( sal_Int64 i = 0; i< nChildCount; i++)
1037 Reference<XAccessible> pRAcc = pRSelection->getSelectedAccessibleChild(i);
1038 if(pRAcc.is())
1040 Reference<XAccessibleContext> pRContext(pRAcc, UNO_QUERY);
1041 if( !pRContext.is() )
1042 return E_FAIL;
1045 sal_Int64 nChildIndex = pRContext->getAccessibleIndexInParent();
1046 if (nChildIndex > std::numeric_limits<long>::max())
1048 SAL_WARN("iacc2", "CAccTable::get_selectedChildren: Child index exceeds maximum long value, "
1049 "using max long.");
1050 nChildIndex = std::numeric_limits<long>::max();
1052 (*children)[i] = nChildIndex;
1056 return S_OK;
1058 } catch(...) { return E_FAIL; }
1063 * @brief Returns a list of accessibles currently selected.
1064 * @param cells Pointer to an array of references to selected accessibles.
1065 * The array is allocated by the server with CoTaskMemAlloc and
1066 * freed by the client with CoTaskMemFree.
1067 * @param nSelectedCells The number of accessibles returned; the size of the returned array.
1068 * @return S_FALSE if there are none, [out] values are NULL and 0 respectively, otherwise S_OK
1070 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_selectedCells(IUnknown * * * cells, long *nSelectedCells)
1072 SolarMutexGuard g;
1074 try {
1076 if (cells == nullptr || nSelectedCells == nullptr)
1077 return E_INVALIDARG;
1079 if (!pRXTable.is())
1080 return E_FAIL;
1082 Reference<XAccessibleSelection> xSelection(pRXTable, UNO_QUERY);
1083 if (!xSelection.is())
1084 return E_FAIL;
1086 sal_Int64 nSelected = xSelection->getSelectedAccessibleChildCount();
1087 if (nSelected > std::numeric_limits<long>::max())
1089 SAL_WARN("iacc2", "CAccTable::get_selectedCells: Selected cell count exceeds maximum long value, "
1090 "using max long.");
1091 nSelected = std::numeric_limits<long>::max();
1093 *nSelectedCells = nSelected;
1095 *cells = static_cast<IUnknown**>(CoTaskMemAlloc(nSelected * sizeof(IUnknown*)));
1097 for (sal_Int64 i = 0; i < nSelected; i++)
1099 Reference<XAccessible> xAcc = xSelection->getSelectedAccessibleChild(i);
1100 assert(xAcc.is());
1102 IAccessible* pIAccessible;
1103 bool bOK = CMAccessible::get_IAccessibleFromXAccessible(xAcc.get(), &pIAccessible);
1105 if (!bOK)
1107 Reference<XAccessible> xTable(pRXTable, UNO_QUERY);
1108 CMAccessible::g_pAgent->InsertAccObj(xAcc.get(), xTable.get());
1109 bOK = CMAccessible::get_IAccessibleFromXAccessible(xAcc.get(), &pIAccessible);
1112 assert(bOK && "Couldn't retrieve IAccessible object");
1114 pIAccessible->AddRef();
1115 (*cells)[i] = pIAccessible;
1118 return S_OK;
1120 } catch(...) { return E_FAIL; }
1123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */