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 #include <osx/a11yfactory.h>
23 #include "a11ytablewrapper.h"
25 using namespace ::com::sun::star::accessibility;
26 using namespace ::com::sun::star::awt;
27 using namespace ::com::sun::star::uno;
29 @implementation AquaA11yTableWrapper : AquaA11yWrapper
31 +(id)childrenAttributeForElement:(AquaA11yTableWrapper *)wrapper
33 XAccessibleTable * accessibleTable = [ wrapper accessibleTable ];
34 NSArray* pResult = nil;
37 NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
40 sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
41 sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();
43 // tdf#152648 Handle overflow when multiplying rows and columns
44 sal_Int64 nCells = static_cast<sal_Int64>(nRows) * static_cast<sal_Int64>(nCols);
45 if( nCells >= 0 && nCells < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
47 // make all children visible to the hierarchy
48 for ( sal_Int32 rowCount = 0; rowCount < nRows; rowCount++ )
50 for ( sal_Int32 columnCount = 0; columnCount < nCols; columnCount++ )
52 Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( rowCount, columnCount );
53 if ( rAccessibleCell.is() )
55 id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
56 [ cells addObject: cell_wrapper ];
57 [ cell_wrapper release ];
64 XAccessibleComponent * accessibleComponent = [ wrapper accessibleComponent ];
65 // find out which cells are actually visible by determining the top-left-cell and the bottom-right-cell
66 Size tableSize = accessibleComponent -> getSize();
70 Reference < XAccessible > rAccessibleTopLeft = accessibleComponent -> getAccessibleAtPoint ( point );
71 point.X = tableSize.Width - 1;
72 point.Y = tableSize.Height - 1;
73 Reference < XAccessible > rAccessibleBottomRight = accessibleComponent -> getAccessibleAtPoint ( point );
74 if ( rAccessibleTopLeft.is() && rAccessibleBottomRight.is() )
76 sal_Int64 idxTopLeft = rAccessibleTopLeft -> getAccessibleContext() -> getAccessibleIndexInParent();
77 sal_Int64 idxBottomRight = rAccessibleBottomRight -> getAccessibleContext() -> getAccessibleIndexInParent();
78 sal_Int32 rowTopLeft = accessibleTable -> getAccessibleRow ( idxTopLeft );
79 sal_Int32 columnTopLeft = accessibleTable -> getAccessibleColumn ( idxTopLeft );
80 sal_Int32 rowBottomRight = accessibleTable -> getAccessibleRow ( idxBottomRight );
81 sal_Int32 columnBottomRight = accessibleTable -> getAccessibleColumn ( idxBottomRight );
82 // create an array containing the visible cells
83 for ( sal_Int32 rowCount = rowTopLeft; rowCount <= rowBottomRight; rowCount++ )
85 for ( sal_Int32 columnCount = columnTopLeft; columnCount <= columnBottomRight; columnCount++ )
87 Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( rowCount, columnCount );
88 if ( rAccessibleCell.is() )
90 id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
91 [ cells addObject: cell_wrapper ];
92 [ cell_wrapper release ];
98 pResult = NSAccessibilityUnignoredChildren( cells );
100 catch (const Exception &)
109 +(void)addAttributeNamesTo: (NSMutableArray *)attributeNames object: (AquaA11yWrapper*)pObject
111 XAccessibleTable * accessibleTable = [ pObject accessibleTable ];
112 if( accessibleTable )
114 sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
115 sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();
117 // tdf#152648 Handle overflow when multiplying rows and columns
118 sal_Int64 nCells = static_cast<sal_Int64>(nRows) * static_cast<sal_Int64>(nCols);
119 if( nCells >= 0 && nCells < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
121 [ attributeNames addObject: NSAccessibilityRowsAttribute ];
122 [ attributeNames addObject: NSAccessibilityColumnsAttribute ];
129 NSArray* pResult = nil;
131 XAccessibleTable * accessibleTable = [ self accessibleTable ];
132 if( accessibleTable )
134 sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
135 sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();
137 // tdf#152648 Handle overflow when multiplying rows and columns
138 sal_Int64 nCells = static_cast<sal_Int64>(nRows) * static_cast<sal_Int64>(nCols);
139 if( nCells >= 0 && nCells < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
141 NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
144 for( sal_Int32 n = 0; n < nRows; n++ )
146 Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( n, 0 );
147 if ( rAccessibleCell.is() )
149 id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
150 [ cells addObject: cell_wrapper ];
151 [ cell_wrapper release ];
154 pResult = NSAccessibilityUnignoredChildren( cells );
156 catch (const Exception &)
160 [ cells autorelease ];
167 -(id)columnsAttribute
169 NSArray* pResult = nil;
171 XAccessibleTable * accessibleTable = [ self accessibleTable ];
173 if( accessibleTable )
175 sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
176 sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();
178 // tdf#152648 Handle overflow when multiplying rows and columns
179 sal_Int64 nCells = static_cast<sal_Int64>(nRows) * static_cast<sal_Int64>(nCols);
180 if( nCells >= 0 && nCells < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
182 NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
185 // find out number of columns
186 for( sal_Int32 n = 0; n < nCols; n++ )
188 Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( 0, n );
189 if ( rAccessibleCell.is() )
191 id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
192 [ cells addObject: cell_wrapper ];
193 [ cell_wrapper release ];
196 pResult = NSAccessibilityUnignoredChildren( cells );
198 catch (const Exception &)
202 [ cells autorelease ];
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */