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>
37 #include <com/sun/star/accessibility/XAccessible.hpp>
38 #include "MAccessible.h"
40 #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
42 using namespace com::sun::star::accessibility
;
43 using namespace com::sun::star::uno
;
45 * Gets accessible table cell.
47 * @param row the row of the specified cell.
48 * @param column the column of the specified cell.
49 * @param accessible the accessible object of the cell.
52 STDMETHODIMP
CAccTable::get_accessibleAt(long row
, long column
, IUnknown
* * accessible
)
59 if(accessible
== NULL
)
65 Reference
<XAccessible
> pRAcc
= GetXInterface()->getAccessibleCellAt(row
,column
);
73 IAccessible
* pRet
= NULL
;
75 BOOL isTRUE
= CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
78 *accessible
= (IAccessible2
*)pRet
;
84 Reference
<XAccessible
> pxTable(GetXInterface(),UNO_QUERY
);
86 CMAccessible::g_pAgent
->InsertAccObj(pRAcc
.get(),pxTable
.get());
87 isTRUE
= CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
91 *accessible
= (IAccessible2
*)pRet
;
102 * Gets accessible table caption.
104 * @param accessible the accessible object of table caption.
106 STDMETHODIMP
CAccTable::get_caption(IUnknown
* *)
112 * Gets accessible column description (as string).
114 * @param column the column index.
115 * @param description the description of the specified column.
117 STDMETHODIMP
CAccTable::get_columnDescription(long column
, BSTR
* description
)
121 ENTER_PROTECTED_BLOCK
124 if(description
== NULL
)
127 // #CHECK XInterface#
131 const ::rtl::OUString
& ouStr
= GetXInterface()->getAccessibleColumnDescription(column
);
134 SAFE_SYSFREESTRING(*description
);//??
135 *description
= SysAllocString((OLECHAR
*)ouStr
.getStr());
136 if(description
==NULL
)
140 LEAVE_PROTECTED_BLOCK
144 * Gets number of columns spanned by table cell.
146 * @param row the row of the specified cell.
147 * @param column the column of the specified cell.
148 * @param spanColumns the column span of the specified cell.
150 STDMETHODIMP
CAccTable::get_columnExtentAt(long row
, long column
, long * nColumnsSpanned
)
154 ENTER_PROTECTED_BLOCK
156 XAccessibleTable
*pXAccTable
= GetXInterface();
159 if(nColumnsSpanned
== NULL
)
165 long lExt
= pXAccTable
->getAccessibleColumnExtentAt(row
,column
);
167 // Fill Extent struct.
168 *nColumnsSpanned
= lExt
;
174 LEAVE_PROTECTED_BLOCK
178 * Gets accessible column header.
180 * @param column the column index.
181 * @param accessible the accessible object of the specified column.
183 STDMETHODIMP
CAccTable::get_columnHeader(IAccessibleTable __RPC_FAR
*__RPC_FAR
*accessibleTable
, long *startingRowIndex
)
187 ENTER_PROTECTED_BLOCK
190 if(accessibleTable
== NULL
|| startingRowIndex
== NULL
)
193 // #CHECK XInterface#
197 Reference
<XAccessibleTable
> pRColumnHeaderTable
= GetXInterface()->getAccessibleColumnHeaders();
198 if(!pRColumnHeaderTable
.is())
200 *accessibleTable
= NULL
;
204 Reference
<XAccessible
> pRXColumnHeader(pRColumnHeaderTable
,UNO_QUERY
);
206 if(!pRXColumnHeader
.is())
208 *accessibleTable
= NULL
;
211 *startingRowIndex
= 0 ;
213 IMAccessible
* pIMacc
= NULL
;
214 HRESULT hr
= createInstance
<CMAccessible
>(IID_IMAccessible
, &pIMacc
);
219 pIMacc
->SetXAccessible(
220 reinterpret_cast<hyper
>(pRXColumnHeader
.get()));
221 pIMacc
->QueryInterface(IID_IAccessibleTable
,(void **)accessibleTable
);
225 LEAVE_PROTECTED_BLOCK
229 * Gets total number of columns in table.
231 * @param columnCount the number of columns in table.
233 STDMETHODIMP
CAccTable::get_nColumns(long * columnCount
)
237 ENTER_PROTECTED_BLOCK
240 if(columnCount
== NULL
)
243 // #CHECK XInterface#
247 *columnCount
= GetXInterface()->getAccessibleColumnCount();
250 LEAVE_PROTECTED_BLOCK
254 * Gets total number of rows in table.
256 * @param rowCount the number of rows in table.
258 STDMETHODIMP
CAccTable::get_nRows(long * rowCount
)
262 ENTER_PROTECTED_BLOCK
268 // #CHECK XInterface#
272 *rowCount
= GetXInterface()->getAccessibleRowCount();
275 LEAVE_PROTECTED_BLOCK
279 * Gets total number of selected columns.
281 * @param columnCount the number of selected columns.
283 STDMETHODIMP
CAccTable::get_nSelectedColumns(long * columnCount
)
287 ENTER_PROTECTED_BLOCK
290 if(columnCount
== NULL
)
293 // #CHECK XInterface#
297 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleColumns();
298 *columnCount
= pSelected
.getLength();
301 LEAVE_PROTECTED_BLOCK
305 * Gets total number of selected rows.
307 * @param rowCount the number of selected rows.
309 STDMETHODIMP
CAccTable::get_nSelectedRows(long * rowCount
)
313 ENTER_PROTECTED_BLOCK
319 // #CHECK XInterface#
323 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleRows();
324 *rowCount
= pSelected
.getLength();
327 LEAVE_PROTECTED_BLOCK
331 * Gets accessible row description (as string).
333 * @param row the row index.
334 * @param description the description of the specified row.
336 STDMETHODIMP
CAccTable::get_rowDescription(long row
, BSTR
* description
)
340 ENTER_PROTECTED_BLOCK
343 if(description
== NULL
)
346 // #CHECK XInterface#
350 const ::rtl::OUString
& ouStr
= GetXInterface()->getAccessibleRowDescription(row
);
353 SAFE_SYSFREESTRING(*description
);
354 *description
= SysAllocString((OLECHAR
*)ouStr
.getStr());
355 if(description
==NULL
)
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 STDMETHODIMP
CAccTable::get_rowExtentAt(long row
, long column
, long * nRowsSpanned
)
374 ENTER_PROTECTED_BLOCK
376 XAccessibleTable
*pXAccTable
= GetXInterface();
379 if(nRowsSpanned
== NULL
)
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 STDMETHODIMP
CAccTable::get_rowHeader(IAccessibleTable __RPC_FAR
*__RPC_FAR
*accessibleTable
, long *startingColumnIndex
)
408 ENTER_PROTECTED_BLOCK
411 if(accessibleTable
== NULL
|| startingColumnIndex
== NULL
)
414 // #CHECK XInterface#
418 Reference
<XAccessibleTable
> pRRowHeaderTable
= GetXInterface()->getAccessibleRowHeaders();
419 if(!pRRowHeaderTable
.is())
421 *accessibleTable
= NULL
;
425 Reference
<XAccessible
> pRXRowHeader(pRRowHeaderTable
,UNO_QUERY
);
427 if(!pRXRowHeader
.is())
429 *accessibleTable
= NULL
;
432 *startingColumnIndex
= 0 ;
434 IMAccessible
* pIMacc
= NULL
;
435 HRESULT hr
= createInstance
<CMAccessible
>(IID_IMAccessible
, &pIMacc
);
440 pIMacc
->SetXAccessible(
441 reinterpret_cast<hyper
>(pRXRowHeader
.get()));
442 pIMacc
->QueryInterface(IID_IAccessibleTable
,(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 STDMETHODIMP
CAccTable::get_selectedRows(long, long ** rows
, long * nRows
)
460 ENTER_PROTECTED_BLOCK
463 if(rows
== NULL
|| nRows
== NULL
)
466 // #CHECK XInterface#
470 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleRows();
471 long count
= pSelected
.getLength() ;
474 *rows
= reinterpret_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 STDMETHODIMP
CAccTable::get_selectedColumns(long, long ** columns
, long * numColumns
)
499 ENTER_PROTECTED_BLOCK
502 if(columns
== NULL
|| numColumns
== NULL
)
505 // #CHECK XInterface#
509 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleColumns();
510 long count
= pSelected
.getLength() ;
513 *columns
= reinterpret_cast<long*>(CoTaskMemAlloc((count
) * sizeof(long)));
514 // #CHECK Memory Allocation#
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 STDMETHODIMP
CAccTable::get_summary(IUnknown
* * accessible
)
536 ENTER_PROTECTED_BLOCK
539 if(accessible
== NULL
)
542 // #CHECK XInterface#
547 Reference
<XAccessible
> pRAcc
= GetXInterface()->getAccessibleSummary();
549 IAccessible
* pRet
= NULL
;
550 CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
554 *accessible
= (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 STDMETHODIMP
CAccTable::get_isColumnSelected(long column
, unsigned char * isSelected
)
574 ENTER_PROTECTED_BLOCK
577 if(isSelected
== NULL
)
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 STDMETHODIMP
CAccTable::get_isRowSelected(long row
, unsigned char * isSelected
)
600 ENTER_PROTECTED_BLOCK
603 if(isSelected
== NULL
)
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 STDMETHODIMP
CAccTable::get_isSelected(long row
, long column
, unsigned char * isSelected
)
628 ENTER_PROTECTED_BLOCK
631 if(isSelected
== NULL
)
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 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
.get()->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
.get()->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 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
.get()->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
.get()->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 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
.get()->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
.get()->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 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
.get()->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
.get()->deselectAccessibleChild(lChildIndex
);
823 LEAVE_PROTECTED_BLOCK
827 * Override of IUNOXWrapper.
829 * @param pXInterface the pointer of UNO interface.
831 STDMETHODIMP
CAccTable::put_XInterface(hyper pXInterface
)
833 // internal IUNOXWrapper - no mutex meeded
835 ENTER_PROTECTED_BLOCK
837 CUNOXWrapper::put_XInterface(pXInterface
);
839 if(pUNOInterface
== NULL
)
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 STDMETHODIMP
CAccTable::get_columnIndex(long childIndex
, long * columnIndex
)
865 ENTER_PROTECTED_BLOCK
868 if(columnIndex
== NULL
)
871 // #CHECK XInterface#
875 *columnIndex
= GetXInterface()->getAccessibleColumn(childIndex
);
878 LEAVE_PROTECTED_BLOCK
881 * Gets rowIndex of childIndex.
883 * @param childIndex childIndex
885 STDMETHODIMP
CAccTable::get_rowIndex(long childIndex
, long * rowIndex
)
889 ENTER_PROTECTED_BLOCK
895 // #CHECK XInterface#
899 *rowIndex
= GetXInterface()->getAccessibleRow(childIndex
);
902 LEAVE_PROTECTED_BLOCK
905 * Gets childIndex of childIndex.
907 * @param childIndex childIndex
909 STDMETHODIMP
CAccTable::get_childIndex(long RowIndex
, long columnIndex
, long * childIndex
)
913 ENTER_PROTECTED_BLOCK
916 if(childIndex
== NULL
)
919 // #CHECK XInterface#
923 *childIndex
= GetXInterface()->getAccessibleIndex(RowIndex
, columnIndex
);
926 LEAVE_PROTECTED_BLOCK
929 STDMETHODIMP
CAccTable::get_rowColumnExtentsAtIndex(long,
939 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 STDMETHODIMP
CAccTable::get_nSelectedChildren(long *childCount
)
951 ENTER_PROTECTED_BLOCK
954 if(childCount
== NULL
)
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 STDMETHODIMP
CAccTable::get_selectedChildren(long, long **children
, long *nChildren
)
982 ENTER_PROTECTED_BLOCK
985 if(children
== NULL
|| nChildren
== NULL
)
988 // #CHECK XInterface#
992 Reference
<XAccessibleSelection
> pRSelection(GetXInterface(), UNO_QUERY
);
993 if(!pRSelection
.is())
996 long childCount
= pRSelection
->getSelectedAccessibleChildCount() ;
998 *nChildren
= childCount
;
1000 *children
= reinterpret_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: */