bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / osx / a11ytablewrapper.mm
blob1c155313c97f08287274610db5892b3647c5a3ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
21 #include <osx/a11yfactory.h>
22 #include <sal/log.hxx>
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;
35     if( accessibleTable )
36     {
37         NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
38         try
39         {
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 )
46             {
47                 // make all children visible to the hierarchy
48                 for ( sal_Int32 rowCount = 0; rowCount < nRows; rowCount++ )
49                 {
50                     for ( sal_Int32 columnCount = 0; columnCount < nCols; columnCount++ )
51                     {
52                         Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( rowCount, columnCount );
53                         if ( rAccessibleCell.is() )
54                         {
55                             id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
56                             [ cells addObject: cell_wrapper ];
57                             [ cell_wrapper release ];
58                         }
59                     }
60                 }
61             }
62             else
63             {
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();
67                 Point point;
68                 point.X = 0;
69                 point.Y = 0;
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() )
75                 {
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                     SAL_WARN("vcl", "creating " << ((rowBottomRight - rowTopLeft) * (columnBottomRight - columnTopLeft)) << " cells");
83                     // create an array containing the visible cells
84                     for ( sal_Int32 rowCount = rowTopLeft; rowCount <= rowBottomRight; rowCount++ )
85                     {
86                         for ( sal_Int32 columnCount = columnTopLeft; columnCount <= columnBottomRight; columnCount++ )
87                         {
88                             Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( rowCount, columnCount );
89                             if ( rAccessibleCell.is() )
90                             {
91                                 id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
92                                 [ cells addObject: cell_wrapper ];
93                                 [ cell_wrapper release ];
94                             }
95                         }
96                     }
97                 }
98             }
99             pResult = NSAccessibilityUnignoredChildren( cells );
100         }
101         catch (const Exception &) 
102         {
103         }
104         [cells autorelease];
105     }
106     
107     return pResult;
110 +(void)addAttributeNamesTo: (NSMutableArray *)attributeNames object: (AquaA11yWrapper*)pObject
112     XAccessibleTable * accessibleTable = [ pObject accessibleTable ];
113     if( accessibleTable )
114     {
115         sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
116         sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();    
118         // tdf#152648 Handle overflow when multiplying rows and columns
119         sal_Int64 nCells = static_cast<sal_Int64>(nRows) * static_cast<sal_Int64>(nCols);
120         if( nCells >= 0 && nCells < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
121         {
122             [ attributeNames addObject: NSAccessibilityRowsAttribute ];
123             [ attributeNames addObject: NSAccessibilityColumnsAttribute ];
124         }
125     }
128 -(id)rowsAttribute
130     NSArray* pResult = nil;
132     XAccessibleTable * accessibleTable = [ self accessibleTable ];
133     if( accessibleTable )
134     {
135         sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
136         sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();    
138         // tdf#152648 Handle overflow when multiplying rows and columns
139         sal_Int64 nCells = static_cast<sal_Int64>(nRows) * static_cast<sal_Int64>(nCols);
140         if( nCells >= 0 && nCells < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
141         {
142             NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
143             try
144             {
145                 for( sal_Int32 n = 0; n < nRows; n++ )
146                 {
147                     Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( n, 0 );
148                     if ( rAccessibleCell.is() )
149                     {
150                         id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
151                         [ cells addObject: cell_wrapper ];
152                         [ cell_wrapper release ];
153                     }
154                 }
155                 pResult = NSAccessibilityUnignoredChildren( cells );
156             }
157             catch (const Exception &) 
158             {
159                 pResult = nil;
160             }
161             [ cells autorelease ];
162         }
163     }
164     
165     return pResult;
168 -(id)columnsAttribute
170     NSArray* pResult = nil;
172     XAccessibleTable * accessibleTable = [ self accessibleTable ];
173     
174     if( accessibleTable )
175     {
176         sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
177         sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();    
179         // tdf#152648 Handle overflow when multiplying rows and columns
180         sal_Int64 nCells = static_cast<sal_Int64>(nRows) * static_cast<sal_Int64>(nCols);
181         if( nCells >= 0 && nCells < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
182         {
183             NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
184             try
185             {
186                 // find out number of columns
187                 for( sal_Int32 n = 0; n < nCols; n++ )
188                 {
189                     Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( 0, n );
190                     if ( rAccessibleCell.is() )
191                     {
192                         id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
193                         [ cells addObject: cell_wrapper ];
194                         [ cell_wrapper release ];
195                     }
196                 }
197                 pResult = NSAccessibilityUnignoredChildren( cells );
198             }
199             catch (const Exception &) 
200             {
201                 pResult = nil;
202             }
203             [ cells autorelease ];
204         }
205     }
206     
207     return pResult;
210 @end
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */