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 #include <vcl/svapp.hxx>
29 #include <com/sun/star/accessibility/XAccessible.hpp>
30 #include "MAccessible.h"
32 #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
34 using namespace com::sun::star::accessibility
;
35 using namespace com::sun::star::uno
;
37 * Gets accessible table cell.
39 * @param row the row of the specified cell.
40 * @param column the column of the specified cell.
41 * @param accessible the accessible object of the cell.
44 STDMETHODIMP
CAccTable::get_accessibleAt(long row
, long column
, IUnknown
* * accessible
)
51 if(accessible
== NULL
)
57 Reference
<XAccessible
> pRAcc
= GetXInterface()->getAccessibleCellAt(row
,column
);
65 IAccessible
* pRet
= NULL
;
67 BOOL isTRUE
= CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
70 *accessible
= (IAccessible2
*)pRet
;
76 Reference
<XAccessible
> pxTable(GetXInterface(),UNO_QUERY
);
78 CMAccessible::g_pAgent
->InsertAccObj(pRAcc
.get(),pxTable
.get());
79 isTRUE
= CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
83 *accessible
= (IAccessible2
*)pRet
;
94 * Gets accessible table caption.
96 * @param accessible the accessible object of table cpation.
98 STDMETHODIMP
CAccTable::get_caption(IUnknown
* *)
104 * Gets accessible column description (as string).
106 * @param column the column index.
107 * @param description the description of the specified column.
109 STDMETHODIMP
CAccTable::get_columnDescription(long column
, BSTR
* description
)
113 ENTER_PROTECTED_BLOCK
116 if(description
== NULL
)
119 // #CHECK XInterface#
123 const ::rtl::OUString
& ouStr
= GetXInterface()->getAccessibleColumnDescription(column
);
126 SAFE_SYSFREESTRING(*description
);//??
127 *description
= SysAllocString((OLECHAR
*)ouStr
.getStr());
128 if(description
==NULL
)
132 LEAVE_PROTECTED_BLOCK
136 * Gets number of columns spanned by table cell.
138 * @param row the row of the specified cell.
139 * @param column the column of the specified cell.
140 * @param spanColumns the column span of the specified cell.
142 STDMETHODIMP
CAccTable::get_columnExtentAt(long row
, long column
, long * nColumnsSpanned
)
146 ENTER_PROTECTED_BLOCK
148 XAccessibleTable
*pXAccTable
= GetXInterface();
151 if(nColumnsSpanned
== NULL
)
157 long lExt
= pXAccTable
->getAccessibleColumnExtentAt(row
,column
);
159 // Fill Extent struct.
160 *nColumnsSpanned
= lExt
;
166 LEAVE_PROTECTED_BLOCK
170 * Gets accessible column header.
172 * @param column the column index.
173 * @param accessible the accessible object of the specified column.
175 STDMETHODIMP
CAccTable::get_columnHeader(IAccessibleTable __RPC_FAR
*__RPC_FAR
*accessibleTable
, long *startingRowIndex
)
179 ENTER_PROTECTED_BLOCK
182 if(accessibleTable
== NULL
|| startingRowIndex
== NULL
)
185 // #CHECK XInterface#
189 Reference
<XAccessibleTable
> pRColumnHeaderTable
= GetXInterface()->getAccessibleColumnHeaders();
190 if(!pRColumnHeaderTable
.is())
192 *accessibleTable
= NULL
;
196 Reference
<XAccessible
> pRXColumnHeader(pRColumnHeaderTable
,UNO_QUERY
);
198 if(!pRXColumnHeader
.is())
200 *accessibleTable
= NULL
;
203 *startingRowIndex
= 0 ;
205 IMAccessible
* pIMacc
= NULL
;
206 HRESULT hr
= createInstance
<CMAccessible
>(IID_IMAccessible
, &pIMacc
);
211 pIMacc
->SetXAccessible(
212 reinterpret_cast<hyper
>(pRXColumnHeader
.get()));
213 pIMacc
->QueryInterface(IID_IAccessibleTable
,(void **)accessibleTable
);
217 LEAVE_PROTECTED_BLOCK
221 * Gets total number of columns in table.
223 * @param columnCount the number of columns in table.
225 STDMETHODIMP
CAccTable::get_nColumns(long * columnCount
)
229 ENTER_PROTECTED_BLOCK
232 if(columnCount
== NULL
)
235 // #CHECK XInterface#
239 *columnCount
= GetXInterface()->getAccessibleColumnCount();
242 LEAVE_PROTECTED_BLOCK
246 * Gets total number of rows in table.
248 * @param rowCount the number of rows in table.
250 STDMETHODIMP
CAccTable::get_nRows(long * rowCount
)
254 ENTER_PROTECTED_BLOCK
260 // #CHECK XInterface#
264 *rowCount
= GetXInterface()->getAccessibleRowCount();
267 LEAVE_PROTECTED_BLOCK
271 * Gets total number of selected columns.
273 * @param columnCount the number of selected columns.
275 STDMETHODIMP
CAccTable::get_nSelectedColumns(long * columnCount
)
279 ENTER_PROTECTED_BLOCK
282 if(columnCount
== NULL
)
285 // #CHECK XInterface#
289 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleColumns();
290 *columnCount
= pSelected
.getLength();
293 LEAVE_PROTECTED_BLOCK
297 * Gets total number of selected rows.
299 * @param rowCount the number of selected rows.
301 STDMETHODIMP
CAccTable::get_nSelectedRows(long * rowCount
)
305 ENTER_PROTECTED_BLOCK
311 // #CHECK XInterface#
315 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleRows();
316 *rowCount
= pSelected
.getLength();
319 LEAVE_PROTECTED_BLOCK
323 * Gets accessible row description (as string).
325 * @param row the row index.
326 * @param description the description of the specified row.
328 STDMETHODIMP
CAccTable::get_rowDescription(long row
, BSTR
* description
)
332 ENTER_PROTECTED_BLOCK
335 if(description
== NULL
)
338 // #CHECK XInterface#
342 const ::rtl::OUString
& ouStr
= GetXInterface()->getAccessibleRowDescription(row
);
345 SAFE_SYSFREESTRING(*description
);
346 *description
= SysAllocString((OLECHAR
*)ouStr
.getStr());
347 if(description
==NULL
)
352 LEAVE_PROTECTED_BLOCK
356 * Gets number of rows spanned by a table cell.
358 * @param row the row of the specified cell.
359 * @param column the column of the specified cell.
360 * @param spanRows the row span of the specified cell.
362 STDMETHODIMP
CAccTable::get_rowExtentAt(long row
, long column
, long * nRowsSpanned
)
366 ENTER_PROTECTED_BLOCK
368 XAccessibleTable
*pXAccTable
= GetXInterface();
371 if(nRowsSpanned
== NULL
)
377 long lExt
= GetXInterface()->getAccessibleRowExtentAt(row
,column
);
379 // Fill Extent struct.
387 LEAVE_PROTECTED_BLOCK
391 * Gets accessible row header.
393 * @param row the row index.
394 * @param accessible the accessible object of the row header.
396 STDMETHODIMP
CAccTable::get_rowHeader(IAccessibleTable __RPC_FAR
*__RPC_FAR
*accessibleTable
, long *startingColumnIndex
)
400 ENTER_PROTECTED_BLOCK
403 if(accessibleTable
== NULL
|| startingColumnIndex
== NULL
)
406 // #CHECK XInterface#
410 Reference
<XAccessibleTable
> pRRowHeaderTable
= GetXInterface()->getAccessibleRowHeaders();
411 if(!pRRowHeaderTable
.is())
413 *accessibleTable
= NULL
;
417 Reference
<XAccessible
> pRXRowHeader(pRRowHeaderTable
,UNO_QUERY
);
419 if(!pRXRowHeader
.is())
421 *accessibleTable
= NULL
;
424 *startingColumnIndex
= 0 ;
426 IMAccessible
* pIMacc
= NULL
;
427 HRESULT hr
= createInstance
<CMAccessible
>(IID_IMAccessible
, &pIMacc
);
432 pIMacc
->SetXAccessible(
433 reinterpret_cast<hyper
>(pRXRowHeader
.get()));
434 pIMacc
->QueryInterface(IID_IAccessibleTable
,(void **)accessibleTable
);
438 LEAVE_PROTECTED_BLOCK
442 * Gets list of row indexes currently selected (0-based).
444 * @param maxRows the max number of the rows.
445 * @param accessible the accessible object array of the selected rows.
446 * @param nRows the actual size of the accessible object array.
448 STDMETHODIMP
CAccTable::get_selectedRows(long, long ** rows
, long * nRows
)
452 ENTER_PROTECTED_BLOCK
455 if(rows
== NULL
|| nRows
== NULL
)
458 // #CHECK XInterface#
462 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleRows();
463 long count
= pSelected
.getLength() ;
466 *rows
= reinterpret_cast<long*>(CoTaskMemAlloc((count
) * sizeof(long)));
467 // #CHECK Memory Allocation#
472 for(int i
=0; i
<count
; i
++)
473 (*rows
)[i
] = pSelected
[i
];
477 LEAVE_PROTECTED_BLOCK
481 * Gets list of column indexes currently selected (0-based).
483 * @param maxColumns the max number of the columns.
484 * @param accessible the accessible object array of the selected columns.
485 * @param numColumns the actual size of accessible object array.
487 STDMETHODIMP
CAccTable::get_selectedColumns(long, long ** columns
, long * numColumns
)
491 ENTER_PROTECTED_BLOCK
494 if(columns
== NULL
|| numColumns
== NULL
)
497 // #CHECK XInterface#
501 Sequence
<long> pSelected
= GetXInterface()->getSelectedAccessibleColumns();
502 long count
= pSelected
.getLength() ;
505 *columns
= reinterpret_cast<long*>(CoTaskMemAlloc((count
) * sizeof(long)));
506 // #CHECK Memory Allocation#
511 for(int i
=0; i
<count
; i
++)
512 (*columns
)[i
] = pSelected
[i
];
516 LEAVE_PROTECTED_BLOCK
520 * Gets accessible table summary.
522 * @param accessible the accessible object of the summary.
524 STDMETHODIMP
CAccTable::get_summary(IUnknown
* * accessible
)
528 ENTER_PROTECTED_BLOCK
531 if(accessible
== NULL
)
534 // #CHECK XInterface#
539 Reference
<XAccessible
> pRAcc
= GetXInterface()->getAccessibleSummary();
541 IAccessible
* pRet
= NULL
;
542 CMAccessible::get_IAccessibleFromXAccessible(pRAcc
.get(), &pRet
);
546 *accessible
= (IAccessible2
*)pRet
;
553 LEAVE_PROTECTED_BLOCK
557 * Determines if table column is selected.
559 * @param column the column index.
560 * @param isSelected the result.
562 STDMETHODIMP
CAccTable::get_isColumnSelected(long column
, unsigned char * isSelected
)
566 ENTER_PROTECTED_BLOCK
569 if(isSelected
== NULL
)
572 // #CHECK XInterface#
576 *isSelected
= GetXInterface()->isAccessibleColumnSelected(column
);
579 LEAVE_PROTECTED_BLOCK
583 * Determines if table row is selected.
585 * @param row the row index.
586 * @param isSelected the result.
588 STDMETHODIMP
CAccTable::get_isRowSelected(long row
, unsigned char * isSelected
)
592 ENTER_PROTECTED_BLOCK
595 if(isSelected
== NULL
)
598 // #CHECK XInterface#
603 *isSelected
= GetXInterface()->isAccessibleRowSelected(row
);
606 LEAVE_PROTECTED_BLOCK
610 * Determines if table cell is selected.
612 * @param row the row index.
613 * @param column the column index.
614 * @param isSelected the result.
616 STDMETHODIMP
CAccTable::get_isSelected(long row
, long column
, unsigned char * isSelected
)
620 ENTER_PROTECTED_BLOCK
623 if(isSelected
== NULL
)
626 // #CHECK XInterface#
630 *isSelected
= GetXInterface()->isAccessibleSelected(row
,column
);
633 LEAVE_PROTECTED_BLOCK
637 * Selects a row and unselect all previously selected rows.
639 * @param row the row index.
640 * @param success the result.
642 STDMETHODIMP
CAccTable::selectRow(long row
)
646 ENTER_PROTECTED_BLOCK
648 // Check XAccessibleTable reference.
652 Reference
<XAccessibleTableSelection
> pRTableExtent(pRXTable
, UNO_QUERY
);
653 if(pRTableExtent
.is())
655 pRTableExtent
.get()->selectRow(row
);
660 // Get XAccessibleSelection.
661 Reference
<XAccessibleSelection
> pRSelection(GetXInterface(), UNO_QUERY
);
662 if(!pRSelection
.is())
666 long lCol
, lColumnCount
;
667 lColumnCount
= GetXInterface()->getAccessibleColumnCount();
668 for(lCol
= 0; lCol
< lColumnCount
; lCol
++)
670 long lChildIndex
= GetXInterface()->getAccessibleIndex(row
, lCol
);
671 pRSelection
.get()->selectAccessibleChild(lChildIndex
);
677 LEAVE_PROTECTED_BLOCK
681 * Selects a column and unselect all previously selected columns.
683 * @param column the column index.
684 * @param success the result.
686 STDMETHODIMP
CAccTable::selectColumn(long column
)
690 ENTER_PROTECTED_BLOCK
692 // Check XAccessibleTable reference.
696 Reference
<XAccessibleTableSelection
> pRTableExtent(GetXInterface(), UNO_QUERY
);
697 if(pRTableExtent
.is())
699 pRTableExtent
.get()->selectColumn(column
);
704 // Get XAccessibleSelection.
705 Reference
<XAccessibleSelection
> pRSelection(pRXTable
, UNO_QUERY
);
706 if(!pRSelection
.is())
710 long lRow
, lRowCount
;
711 lRowCount
= GetXInterface()->getAccessibleRowCount();
712 for(lRow
= 0; lRow
< lRowCount
; lRow
++)
714 long lChildIndex
= GetXInterface()->getAccessibleIndex(lRow
, column
);
715 pRSelection
.get()->selectAccessibleChild(lChildIndex
);
722 LEAVE_PROTECTED_BLOCK
726 * Unselects one row, leaving other selected rows selected (if any).
728 * @param row the row index.
729 * @param success the result.
731 STDMETHODIMP
CAccTable::unselectRow(long row
)
735 ENTER_PROTECTED_BLOCK
737 // Check XAccessibleTable reference.
741 Reference
<XAccessibleTableSelection
> pRTableExtent(GetXInterface(), UNO_QUERY
);
742 if(pRTableExtent
.is())
744 if(pRTableExtent
.get()->unselectRow(row
))
751 // Get XAccessibleSelection.
752 Reference
<XAccessibleSelection
> pRSelection(pRXTable
, UNO_QUERY
);
753 if(!pRSelection
.is())
757 long lColumn
, lColumnCount
;
758 lColumnCount
= GetXInterface()->getAccessibleColumnCount();
759 for(lColumn
= 0; lColumn
< lColumnCount
; lColumn
++)
761 long lChildIndex
= GetXInterface()->getAccessibleIndex(row
,lColumn
);
762 pRSelection
.get()->deselectAccessibleChild(lChildIndex
);
769 LEAVE_PROTECTED_BLOCK
773 * Unselects one column, leaving other selected columns selected (if any).
775 * @param column the column index.
776 * @param success the result.
778 STDMETHODIMP
CAccTable::unselectColumn(long column
)
782 ENTER_PROTECTED_BLOCK
784 // Check XAccessibleTable reference.
788 Reference
<XAccessibleTableSelection
> pRTableExtent(GetXInterface(), UNO_QUERY
);
789 if(pRTableExtent
.is())
791 if(pRTableExtent
.get()->unselectColumn(column
))
798 // Get XAccessibleSelection.
799 Reference
<XAccessibleSelection
> pRSelection(pRXTable
, UNO_QUERY
);
800 if(!pRSelection
.is())
804 long lRow
, lRowCount
;
805 lRowCount
= GetXInterface()->getAccessibleRowCount();
807 for(lRow
= 0; lRow
< lRowCount
; lRow
++)
809 long lChildIndex
= GetXInterface()->getAccessibleIndex(lRow
, column
);
810 pRSelection
.get()->deselectAccessibleChild(lChildIndex
);
815 LEAVE_PROTECTED_BLOCK
819 * Override of IUNOXWrapper.
821 * @param pXInterface the pointer of UNO interface.
823 STDMETHODIMP
CAccTable::put_XInterface(hyper pXInterface
)
825 // internal IUNOXWrapper - no mutex meeded
827 ENTER_PROTECTED_BLOCK
829 CUNOXWrapper::put_XInterface(pXInterface
);
831 if(pUNOInterface
== NULL
)
834 Reference
<XAccessibleContext
> pRContext
= pUNOInterface
->getAccessibleContext();
835 if( !pRContext
.is() )
838 Reference
<XAccessibleTable
> pRXI(pRContext
,UNO_QUERY
);
842 pRXTable
= pRXI
.get();
845 LEAVE_PROTECTED_BLOCK
849 * Gets columnIndex of childIndex.
851 * @param childIndex childIndex
853 STDMETHODIMP
CAccTable::get_columnIndex(long childIndex
, long * columnIndex
)
857 ENTER_PROTECTED_BLOCK
860 if(columnIndex
== NULL
)
863 // #CHECK XInterface#
867 *columnIndex
= GetXInterface()->getAccessibleColumn(childIndex
);
870 LEAVE_PROTECTED_BLOCK
873 * Gets rowIndex of childIndex.
875 * @param childIndex childIndex
877 STDMETHODIMP
CAccTable::get_rowIndex(long childIndex
, long * rowIndex
)
881 ENTER_PROTECTED_BLOCK
887 // #CHECK XInterface#
891 *rowIndex
= GetXInterface()->getAccessibleRow(childIndex
);
894 LEAVE_PROTECTED_BLOCK
897 * Gets childIndex of childIndex.
899 * @param childIndex childIndex
901 STDMETHODIMP
CAccTable::get_childIndex(long RowIndex
, long columnIndex
, long * childIndex
)
905 ENTER_PROTECTED_BLOCK
908 if(childIndex
== NULL
)
911 // #CHECK XInterface#
915 *childIndex
= GetXInterface()->getAccessibleIndex(RowIndex
, columnIndex
);
918 LEAVE_PROTECTED_BLOCK
921 STDMETHODIMP
CAccTable::get_rowColumnExtentsAtIndex(long,
931 STDMETHODIMP
CAccTable::get_modelChange(IA2TableModelChange
*)
936 // @brief Returns the total number of selected children
937 // @param [out] childCount
938 // Number of children currently selected
939 STDMETHODIMP
CAccTable::get_nSelectedChildren(long *childCount
)
943 ENTER_PROTECTED_BLOCK
946 if(childCount
== NULL
)
949 // #CHECK XInterface#
953 Reference
<XAccessibleSelection
> pRSelection(GetXInterface(), UNO_QUERY
);
954 if(!pRSelection
.is())
957 *childCount
= pRSelection
->getSelectedAccessibleChildCount();
960 LEAVE_PROTECTED_BLOCK
963 // @brief Returns a list of child indexes currently selected (0-based).
964 // @param [in] maxChildren
965 // Max children requested (possibly from IAccessibleTable::nSelectedChildren)
966 // @param [out] children
967 // array of indexes of selected children (each index is 0-based)
968 // @param [out] nChildren
969 // Length of array (not more than maxChildren)
970 STDMETHODIMP
CAccTable::get_selectedChildren(long, long **children
, long *nChildren
)
974 ENTER_PROTECTED_BLOCK
977 if(children
== NULL
|| nChildren
== NULL
)
980 // #CHECK XInterface#
984 Reference
<XAccessibleSelection
> pRSelection(GetXInterface(), UNO_QUERY
);
985 if(!pRSelection
.is())
988 long childCount
= pRSelection
->getSelectedAccessibleChildCount() ;
990 *nChildren
= childCount
;
992 *children
= reinterpret_cast<long*>(CoTaskMemAlloc((childCount
) * sizeof(long)));
994 for( long i
= 0; i
< childCount
; i
++)
996 Reference
<XAccessible
> pRAcc
= pRSelection
->getSelectedAccessibleChild(i
);
999 Reference
<XAccessibleContext
> pRContext(pRAcc
, UNO_QUERY
);
1000 if( !pRContext
.is() )
1003 long childIndex
= pRContext
->getAccessibleIndexInParent();
1004 (*children
)[i
] = childIndex
;
1010 LEAVE_PROTECTED_BLOCK
1014 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */