impress: don't exit textbox editing when new slide was added
[LibreOffice.git] / vcl / osx / a11ytablewrapper.mm
blobe7cd02fcee7e1c86ec05f46fdee17e0079fc71b2
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>
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();
42     
43             if( nRows * nCols < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
44             {
45                 // make all children visible to the hierarchy
46                 for ( sal_Int32 rowCount = 0; rowCount < nRows; rowCount++ )
47                 {
48                     for ( sal_Int32 columnCount = 0; columnCount < nCols; columnCount++ )
49                     {
50                         Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( rowCount, columnCount );
51                         if ( rAccessibleCell.is() )
52                         {
53                             id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
54                             [ cells addObject: cell_wrapper ];
55                             [ cell_wrapper release ];
56                         }
57                     }
58                 }
59             }
60             else
61             {
62                 XAccessibleComponent * accessibleComponent = [ wrapper accessibleComponent ];
63                 // find out which cells are actually visible by determining the top-left-cell and the bottom-right-cell
64                 Size tableSize = accessibleComponent -> getSize();
65                 Point point;
66                 point.X = 0;
67                 point.Y = 0;
68                 Reference < XAccessible > rAccessibleTopLeft = accessibleComponent -> getAccessibleAtPoint ( point );
69                 point.X = tableSize.Width - 1;
70                 point.Y = tableSize.Height - 1;
71                 Reference < XAccessible > rAccessibleBottomRight = accessibleComponent -> getAccessibleAtPoint ( point );
72                 if ( rAccessibleTopLeft.is() && rAccessibleBottomRight.is() )
73                 {
74                     sal_Int32 idxTopLeft = rAccessibleTopLeft -> getAccessibleContext() -> getAccessibleIndexInParent();
75                     sal_Int32 idxBottomRight = rAccessibleBottomRight -> getAccessibleContext() -> getAccessibleIndexInParent();
76                     sal_Int32 rowTopLeft = accessibleTable -> getAccessibleRow ( idxTopLeft );
77                     sal_Int32 columnTopLeft = accessibleTable -> getAccessibleColumn ( idxTopLeft );
78                     sal_Int32 rowBottomRight = accessibleTable -> getAccessibleRow ( idxBottomRight );
79                     sal_Int32 columnBottomRight = accessibleTable -> getAccessibleColumn ( idxBottomRight );
80                     // create an array containing the visible cells
81                     for ( sal_Int32 rowCount = rowTopLeft; rowCount <= rowBottomRight; rowCount++ )
82                     {
83                         for ( sal_Int32 columnCount = columnTopLeft; columnCount <= columnBottomRight; columnCount++ )
84                         {
85                             Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( rowCount, columnCount );
86                             if ( rAccessibleCell.is() )
87                             {
88                                 id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
89                                 [ cells addObject: cell_wrapper ];
90                                 [ cell_wrapper release ];
91                             }
92                         }
93                     }
94                 }
95             }
96             pResult = NSAccessibilityUnignoredChildren( cells );
97         }
98         catch (const Exception &) 
99         {
100         }
101         [cells autorelease];
102     }
103     
104     return pResult;
107 +(void)addAttributeNamesTo: (NSMutableArray *)attributeNames object: (AquaA11yWrapper*)pObject
109     XAccessibleTable * accessibleTable = [ pObject accessibleTable ];
110     if( accessibleTable )
111     {
112         sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
113         sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();    
114         
115         
116         if( nRows*nCols < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
117         {
118             [ attributeNames addObject: NSAccessibilityRowsAttribute ];
119             [ attributeNames addObject: NSAccessibilityColumnsAttribute ];
120         }
121     }
124 -(id)rowsAttribute
126     NSArray* pResult = nil;
128     XAccessibleTable * accessibleTable = [ self accessibleTable ];
129     if( accessibleTable )
130     {
131         sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
132         sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();    
133         if( nRows * nCols < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
134         {
135             NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
136             try
137             {
138                 for( sal_Int32 n = 0; n < nRows; n++ )
139                 {
140                     Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( n, 0 );
141                     if ( rAccessibleCell.is() )
142                     {
143                         id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
144                         [ cells addObject: cell_wrapper ];
145                         [ cell_wrapper release ];
146                     }
147                 }
148                 pResult = NSAccessibilityUnignoredChildren( cells );
149             }
150             catch (const Exception &) 
151             {
152                 pResult = nil;
153             }
154             [ cells autorelease ];
155         }
156     }
157     
158     return pResult;
161 -(id)columnsAttribute
163     NSArray* pResult = nil;
165     XAccessibleTable * accessibleTable = [ self accessibleTable ];
166     
167     if( accessibleTable )
168     {
169         sal_Int32 nRows = accessibleTable->getAccessibleRowCount();
170         sal_Int32 nCols = accessibleTable->getAccessibleColumnCount();    
171         if( nRows * nCols < MAXIMUM_ACCESSIBLE_TABLE_CELLS )
172         {
173             NSMutableArray * cells = [ [ NSMutableArray alloc ] init ];
174             try
175             {
176                 // find out number of columns
177                 for( sal_Int32 n = 0; n < nCols; n++ )
178                 {
179                     Reference < XAccessible > rAccessibleCell = accessibleTable -> getAccessibleCellAt ( 0, n );
180                     if ( rAccessibleCell.is() )
181                     {
182                         id cell_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rAccessibleCell -> getAccessibleContext() ];
183                         [ cells addObject: cell_wrapper ];
184                         [ cell_wrapper release ];
185                     }
186                 }
187                 pResult = NSAccessibilityUnignoredChildren( cells );
188             }
189             catch (const Exception &) 
190             {
191                 pResult = nil;
192             }
193             [ cells autorelease ];
194         }
195     }
196     
197     return pResult;
200 @end
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */