1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 * AccTable.cpp : Implementation of CAccTable.
27 #pragma clang diagnostic push
28 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
32 #pragma clang diagnostic pop
35 #include <vcl/svapp.hxx>
36 #include <o3tl/char16_t2wchar_t.hxx>
38 #include <com/sun/star/accessibility/XAccessible.hpp>
39 #include "MAccessible.h"
41 #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
43 using namespace com::sun::star::accessibility
;
44 using namespace com::sun::star::uno
;
46 * Gets accessible table cell.
48 * @param row the row of the specified cell.
49 * @param column the column of the specified cell.
50 * @param accessible the accessible object of the cell.
53 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_accessibleAt(long row
, long column
, IUnknown
* * accessible
)
60 if(accessible
== nullptr)
66 Reference
<XAccessible
> pRAcc
= GetXInterface()->getAccessibleCellAt(row
,column
);
70 *accessible
= nullptr;
74 IAccessible
* pRet
= nullptr;
76 bool isTRUE
= CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
79 *accessible
= static_cast<IAccessible2
*>(pRet
);
85 Reference
<XAccessible
> pxTable(GetXInterface(),UNO_QUERY
);
87 CMAccessible::g_pAgent
->InsertAccObj(pRAcc
.get(),pxTable
.get());
88 isTRUE
= CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
92 *accessible
= static_cast<IAccessible2
*>(pRet
);
103 * Gets accessible table caption.
105 * @param accessible the accessible object of table caption.
107 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_caption(IUnknown
* *)
113 * Gets accessible column description (as string).
115 * @param column the column index.
116 * @param description the description of the specified column.
118 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_columnDescription(long column
, BSTR
* description
)
122 ENTER_PROTECTED_BLOCK
125 if(description
== nullptr)
128 // #CHECK XInterface#
132 const OUString
& ouStr
= GetXInterface()->getAccessibleColumnDescription(column
);
135 SAFE_SYSFREESTRING(*description
);
136 *description
= SysAllocString(o3tl::toW(ouStr
.getStr()));
137 if (*description
==nullptr)
141 LEAVE_PROTECTED_BLOCK
145 * Gets number of columns spanned by table cell.
147 * @param row the row of the specified cell.
148 * @param column the column of the specified cell.
149 * @param spanColumns the column span of the specified cell.
151 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_columnExtentAt(long row
, long column
, long * nColumnsSpanned
)
155 ENTER_PROTECTED_BLOCK
157 XAccessibleTable
*pXAccTable
= GetXInterface();
160 if(nColumnsSpanned
== nullptr)
166 long lExt
= pXAccTable
->getAccessibleColumnExtentAt(row
,column
);
168 // Fill Extent struct.
169 *nColumnsSpanned
= lExt
;
175 LEAVE_PROTECTED_BLOCK
179 * Gets accessible column header.
181 * @param column the column index.
182 * @param accessible the accessible object of the specified column.
184 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_columnHeader(IAccessibleTable __RPC_FAR
*__RPC_FAR
*accessibleTable
, long *startingRowIndex
)
188 ENTER_PROTECTED_BLOCK
191 if(accessibleTable
== nullptr || startingRowIndex
== nullptr)
194 // #CHECK XInterface#
198 Reference
<XAccessibleTable
> pRColumnHeaderTable
= GetXInterface()->getAccessibleColumnHeaders();
199 if(!pRColumnHeaderTable
.is())
201 *accessibleTable
= nullptr;
205 Reference
<XAccessible
> pRXColumnHeader(pRColumnHeaderTable
,UNO_QUERY
);
207 if(!pRXColumnHeader
.is())
209 *accessibleTable
= nullptr;
212 *startingRowIndex
= 0 ;
214 IMAccessible
* pIMacc
= nullptr;
215 HRESULT hr
= createInstance
<CMAccessible
>(IID_IMAccessible
, &pIMacc
);
220 pIMacc
->SetXAccessible(
221 reinterpret_cast<hyper
>(pRXColumnHeader
.get()));
222 pIMacc
->QueryInterface(IID_IAccessibleTable
,reinterpret_cast<void **>(accessibleTable
));
226 LEAVE_PROTECTED_BLOCK
230 * Gets total number of columns in table.
232 * @param columnCount the number of columns in table.
234 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_nColumns(long * columnCount
)
238 ENTER_PROTECTED_BLOCK
241 if(columnCount
== nullptr)
244 // #CHECK XInterface#
248 *columnCount
= GetXInterface()->getAccessibleColumnCount();
251 LEAVE_PROTECTED_BLOCK
255 * Gets total number of rows in table.
257 * @param rowCount the number of rows in table.
259 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_nRows(long * rowCount
)
263 ENTER_PROTECTED_BLOCK
266 if(rowCount
== nullptr)
269 // #CHECK XInterface#
273 *rowCount
= GetXInterface()->getAccessibleRowCount();
276 LEAVE_PROTECTED_BLOCK
280 * Gets total number of selected columns.
282 * @param columnCount the number of selected columns.
284 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_nSelectedColumns(long * columnCount
)
288 ENTER_PROTECTED_BLOCK
291 if(columnCount
== nullptr)
294 // #CHECK XInterface#
298 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleColumns();
299 *columnCount
= pSelected
.getLength();
302 LEAVE_PROTECTED_BLOCK
306 * Gets total number of selected rows.
308 * @param rowCount the number of selected rows.
310 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_nSelectedRows(long * rowCount
)
314 ENTER_PROTECTED_BLOCK
317 if(rowCount
== nullptr)
320 // #CHECK XInterface#
324 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleRows();
325 *rowCount
= pSelected
.getLength();
328 LEAVE_PROTECTED_BLOCK
332 * Gets accessible row description (as string).
334 * @param row the row index.
335 * @param description the description of the specified row.
337 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_rowDescription(long row
, BSTR
* description
)
341 ENTER_PROTECTED_BLOCK
344 if(description
== nullptr)
347 // #CHECK XInterface#
351 const OUString
& ouStr
= GetXInterface()->getAccessibleRowDescription(row
);
354 SAFE_SYSFREESTRING(*description
);
355 *description
= SysAllocString(o3tl::toW(ouStr
.getStr()));
356 if (*description
==nullptr)
360 LEAVE_PROTECTED_BLOCK
364 * Gets number of rows spanned by a table cell.
366 * @param row the row of the specified cell.
367 * @param column the column of the specified cell.
368 * @param spanRows the row span of the specified cell.
370 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_rowExtentAt(long row
, long column
, long * nRowsSpanned
)
374 ENTER_PROTECTED_BLOCK
376 XAccessibleTable
*pXAccTable
= GetXInterface();
379 if(nRowsSpanned
== nullptr)
385 long lExt
= GetXInterface()->getAccessibleRowExtentAt(row
,column
);
387 // Fill Extent struct.
395 LEAVE_PROTECTED_BLOCK
399 * Gets accessible row header.
401 * @param row the row index.
402 * @param accessible the accessible object of the row header.
404 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_rowHeader(IAccessibleTable __RPC_FAR
*__RPC_FAR
*accessibleTable
, long *startingColumnIndex
)
408 ENTER_PROTECTED_BLOCK
411 if(accessibleTable
== nullptr || startingColumnIndex
== nullptr)
414 // #CHECK XInterface#
418 Reference
<XAccessibleTable
> pRRowHeaderTable
= GetXInterface()->getAccessibleRowHeaders();
419 if(!pRRowHeaderTable
.is())
421 *accessibleTable
= nullptr;
425 Reference
<XAccessible
> pRXRowHeader(pRRowHeaderTable
,UNO_QUERY
);
427 if(!pRXRowHeader
.is())
429 *accessibleTable
= nullptr;
432 *startingColumnIndex
= 0 ;
434 IMAccessible
* pIMacc
= nullptr;
435 HRESULT hr
= createInstance
<CMAccessible
>(IID_IMAccessible
, &pIMacc
);
440 pIMacc
->SetXAccessible(
441 reinterpret_cast<hyper
>(pRXRowHeader
.get()));
442 pIMacc
->QueryInterface(IID_IAccessibleTable
,reinterpret_cast<void **>(accessibleTable
));
446 LEAVE_PROTECTED_BLOCK
450 * Gets list of row indexes currently selected (0-based).
452 * @param maxRows the max number of the rows.
453 * @param accessible the accessible object array of the selected rows.
454 * @param nRows the actual size of the accessible object array.
456 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_selectedRows(long, long ** rows
, long * nRows
)
460 ENTER_PROTECTED_BLOCK
463 if(rows
== nullptr || nRows
== nullptr)
466 // #CHECK XInterface#
470 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleRows();
471 long count
= pSelected
.getLength() ;
474 *rows
= static_cast<long*>(CoTaskMemAlloc(count
* sizeof(long)));
475 // #CHECK Memory Allocation#
480 for(int i
=0; i
<count
; i
++)
481 (*rows
)[i
] = pSelected
[i
];
485 LEAVE_PROTECTED_BLOCK
489 * Gets list of column indexes currently selected (0-based).
491 * @param maxColumns the max number of the columns.
492 * @param accessible the accessible object array of the selected columns.
493 * @param numColumns the actual size of accessible object array.
495 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_selectedColumns(long, long ** columns
, long * numColumns
)
499 ENTER_PROTECTED_BLOCK
502 if(columns
== nullptr || numColumns
== nullptr)
505 // #CHECK XInterface#
509 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleColumns();
510 long count
= pSelected
.getLength() ;
513 *columns
= static_cast<long*>(CoTaskMemAlloc(count
* sizeof(long)));
514 // #CHECK Memory Allocation#
515 if(*columns
== nullptr)
519 for(int i
=0; i
<count
; i
++)
520 (*columns
)[i
] = pSelected
[i
];
524 LEAVE_PROTECTED_BLOCK
528 * Gets accessible table summary.
530 * @param accessible the accessible object of the summary.
532 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_summary(IUnknown
* * accessible
)
536 ENTER_PROTECTED_BLOCK
539 if(accessible
== nullptr)
542 // #CHECK XInterface#
547 Reference
<XAccessible
> pRAcc
= GetXInterface()->getAccessibleSummary();
549 IAccessible
* pRet
= nullptr;
550 CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
554 *accessible
= static_cast<IAccessible2
*>(pRet
);
561 LEAVE_PROTECTED_BLOCK
565 * Determines if table column is selected.
567 * @param column the column index.
568 * @param isSelected the result.
570 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_isColumnSelected(long column
, boolean
* isSelected
)
574 ENTER_PROTECTED_BLOCK
577 if(isSelected
== nullptr)
580 // #CHECK XInterface#
584 *isSelected
= GetXInterface()->isAccessibleColumnSelected(column
);
587 LEAVE_PROTECTED_BLOCK
591 * Determines if table row is selected.
593 * @param row the row index.
594 * @param isSelected the result.
596 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_isRowSelected(long row
, boolean
* isSelected
)
600 ENTER_PROTECTED_BLOCK
603 if(isSelected
== nullptr)
606 // #CHECK XInterface#
611 *isSelected
= GetXInterface()->isAccessibleRowSelected(row
);
614 LEAVE_PROTECTED_BLOCK
618 * Determines if table cell is selected.
620 * @param row the row index.
621 * @param column the column index.
622 * @param isSelected the result.
624 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_isSelected(long row
, long column
, boolean
* isSelected
)
628 ENTER_PROTECTED_BLOCK
631 if(isSelected
== nullptr)
634 // #CHECK XInterface#
638 *isSelected
= GetXInterface()->isAccessibleSelected(row
,column
);
641 LEAVE_PROTECTED_BLOCK
645 * Selects a row and unselect all previously selected rows.
647 * @param row the row index.
648 * @param success the result.
650 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::selectRow(long row
)
654 ENTER_PROTECTED_BLOCK
656 // Check XAccessibleTable reference.
660 Reference
<XAccessibleTableSelection
> pRTableExtent(pRXTable
, UNO_QUERY
);
661 if(pRTableExtent
.is())
663 pRTableExtent
->selectRow(row
);
668 // Get XAccessibleSelection.
669 Reference
<XAccessibleSelection
> pRSelection(GetXInterface(), UNO_QUERY
);
670 if(!pRSelection
.is())
674 long lCol
, lColumnCount
;
675 lColumnCount
= GetXInterface()->getAccessibleColumnCount();
676 for(lCol
= 0; lCol
< lColumnCount
; lCol
++)
678 long lChildIndex
= GetXInterface()->getAccessibleIndex(row
, lCol
);
679 pRSelection
->selectAccessibleChild(lChildIndex
);
685 LEAVE_PROTECTED_BLOCK
689 * Selects a column and unselect all previously selected columns.
691 * @param column the column index.
692 * @param success the result.
694 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::selectColumn(long column
)
698 ENTER_PROTECTED_BLOCK
700 // Check XAccessibleTable reference.
704 Reference
<XAccessibleTableSelection
> pRTableExtent(GetXInterface(), UNO_QUERY
);
705 if(pRTableExtent
.is())
707 pRTableExtent
->selectColumn(column
);
712 // Get XAccessibleSelection.
713 Reference
<XAccessibleSelection
> pRSelection(pRXTable
, UNO_QUERY
);
714 if(!pRSelection
.is())
718 long lRow
, lRowCount
;
719 lRowCount
= GetXInterface()->getAccessibleRowCount();
720 for(lRow
= 0; lRow
< lRowCount
; lRow
++)
722 long lChildIndex
= GetXInterface()->getAccessibleIndex(lRow
, column
);
723 pRSelection
->selectAccessibleChild(lChildIndex
);
730 LEAVE_PROTECTED_BLOCK
734 * Unselects one row, leaving other selected rows selected (if any).
736 * @param row the row index.
737 * @param success the result.
739 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::unselectRow(long row
)
743 ENTER_PROTECTED_BLOCK
745 // Check XAccessibleTable reference.
749 Reference
<XAccessibleTableSelection
> pRTableExtent(GetXInterface(), UNO_QUERY
);
750 if(pRTableExtent
.is())
752 if(pRTableExtent
->unselectRow(row
))
759 // Get XAccessibleSelection.
760 Reference
<XAccessibleSelection
> pRSelection(pRXTable
, UNO_QUERY
);
761 if(!pRSelection
.is())
765 long lColumn
, lColumnCount
;
766 lColumnCount
= GetXInterface()->getAccessibleColumnCount();
767 for(lColumn
= 0; lColumn
< lColumnCount
; lColumn
++)
769 long lChildIndex
= GetXInterface()->getAccessibleIndex(row
,lColumn
);
770 pRSelection
->deselectAccessibleChild(lChildIndex
);
777 LEAVE_PROTECTED_BLOCK
781 * Unselects one column, leaving other selected columns selected (if any).
783 * @param column the column index.
784 * @param success the result.
786 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::unselectColumn(long column
)
790 ENTER_PROTECTED_BLOCK
792 // Check XAccessibleTable reference.
796 Reference
<XAccessibleTableSelection
> pRTableExtent(GetXInterface(), UNO_QUERY
);
797 if(pRTableExtent
.is())
799 if(pRTableExtent
->unselectColumn(column
))
806 // Get XAccessibleSelection.
807 Reference
<XAccessibleSelection
> pRSelection(pRXTable
, UNO_QUERY
);
808 if(!pRSelection
.is())
812 long lRow
, lRowCount
;
813 lRowCount
= GetXInterface()->getAccessibleRowCount();
815 for(lRow
= 0; lRow
< lRowCount
; lRow
++)
817 long lChildIndex
= GetXInterface()->getAccessibleIndex(lRow
, column
);
818 pRSelection
->deselectAccessibleChild(lChildIndex
);
823 LEAVE_PROTECTED_BLOCK
827 * Override of IUNOXWrapper.
829 * @param pXInterface the pointer of UNO interface.
831 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::put_XInterface(hyper pXInterface
)
833 // internal IUNOXWrapper - no mutex meeded
835 ENTER_PROTECTED_BLOCK
837 CUNOXWrapper::put_XInterface(pXInterface
);
839 if(pUNOInterface
== nullptr)
842 Reference
<XAccessibleContext
> pRContext
= pUNOInterface
->getAccessibleContext();
843 if( !pRContext
.is() )
846 Reference
<XAccessibleTable
> pRXI(pRContext
,UNO_QUERY
);
850 pRXTable
= pRXI
.get();
853 LEAVE_PROTECTED_BLOCK
857 * Gets columnIndex of childIndex.
859 * @param childIndex childIndex
861 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_columnIndex(long childIndex
, long * columnIndex
)
865 ENTER_PROTECTED_BLOCK
868 if(columnIndex
== nullptr)
871 // #CHECK XInterface#
875 *columnIndex
= GetXInterface()->getAccessibleColumn(childIndex
);
878 LEAVE_PROTECTED_BLOCK
881 * Gets rowIndex of childIndex.
883 * @param childIndex childIndex
885 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_rowIndex(long childIndex
, long * rowIndex
)
889 ENTER_PROTECTED_BLOCK
892 if(rowIndex
== nullptr)
895 // #CHECK XInterface#
899 *rowIndex
= GetXInterface()->getAccessibleRow(childIndex
);
902 LEAVE_PROTECTED_BLOCK
905 * Gets childIndex of childIndex.
907 * @param childIndex childIndex
909 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_childIndex(long RowIndex
, long columnIndex
, long * childIndex
)
913 ENTER_PROTECTED_BLOCK
916 if(childIndex
== nullptr)
919 // #CHECK XInterface#
923 *childIndex
= GetXInterface()->getAccessibleIndex(RowIndex
, columnIndex
);
926 LEAVE_PROTECTED_BLOCK
929 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_rowColumnExtentsAtIndex(long,
939 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_modelChange(IA2TableModelChange
*)
944 // @brief Returns the total number of selected children
945 // @param [out] childCount
946 // Number of children currently selected
947 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_nSelectedChildren(long *childCount
)
951 ENTER_PROTECTED_BLOCK
954 if(childCount
== nullptr)
957 // #CHECK XInterface#
961 Reference
<XAccessibleSelection
> pRSelection(GetXInterface(), UNO_QUERY
);
962 if(!pRSelection
.is())
965 *childCount
= pRSelection
->getSelectedAccessibleChildCount();
968 LEAVE_PROTECTED_BLOCK
971 // @brief Returns a list of child indexes currently selected (0-based).
972 // @param [in] maxChildren
973 // Max children requested (possibly from IAccessibleTable::nSelectedChildren)
974 // @param [out] children
975 // array of indexes of selected children (each index is 0-based)
976 // @param [out] nChildren
977 // Length of array (not more than maxChildren)
978 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTable::get_selectedChildren(long, long **children
, long *nChildren
)
982 ENTER_PROTECTED_BLOCK
985 if(children
== nullptr || nChildren
== nullptr)
988 // #CHECK XInterface#
992 Reference
<XAccessibleSelection
> pRSelection(GetXInterface(), UNO_QUERY
);
993 if(!pRSelection
.is())
996 long childCount
= pRSelection
->getSelectedAccessibleChildCount() ;
998 *nChildren
= childCount
;
1000 *children
= static_cast<long*>(CoTaskMemAlloc(childCount
* sizeof(long)));
1002 for( long i
= 0; i
< childCount
; i
++)
1004 Reference
<XAccessible
> pRAcc
= pRSelection
->getSelectedAccessibleChild(i
);
1007 Reference
<XAccessibleContext
> pRContext(pRAcc
, UNO_QUERY
);
1008 if( !pRContext
.is() )
1011 long childIndex
= pRContext
->getAccessibleIndexInParent();
1012 (*children
)[i
] = childIndex
;
1018 LEAVE_PROTECTED_BLOCK
1022 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */