/src/libreoffice/toolkit/source/controls/table/AccessibleGridControlTableBase.cxx
Line | Count | Source |
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 | | */ |
19 | | |
20 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
21 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
22 | | #include <controls/table/AccessibleGridControlTableBase.hxx> |
23 | | #include <vcl/svapp.hxx> |
24 | | #include <comphelper/sequence.hxx> |
25 | | |
26 | | using css::uno::Reference; |
27 | | using css::uno::Sequence; |
28 | | using css::uno::Any; |
29 | | |
30 | | using namespace ::com::sun::star; |
31 | | using namespace ::com::sun::star::accessibility; |
32 | | using namespace ::vcl; |
33 | | |
34 | | |
35 | | namespace accessibility { |
36 | | |
37 | | |
38 | | AccessibleGridControlTableBase::AccessibleGridControlTableBase( |
39 | | const Reference< XAccessible >& rxParent, |
40 | | svt::table::TableControl& rTable, |
41 | | AccessibleTableControlObjType eObjType ) : |
42 | 0 | AccessibleGridControlTableImplHelper( rxParent, rTable, eObjType ) |
43 | 0 | { |
44 | 0 | } |
45 | | |
46 | | // XAccessibleContext --------------------------------------------------------- |
47 | | |
48 | | sal_Int64 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount() |
49 | 0 | { |
50 | 0 | SolarMutexGuard aSolarGuard; |
51 | |
|
52 | 0 | ensureAlive(); |
53 | 0 | sal_Int64 nChildren = 0; |
54 | 0 | if (m_eObjType == AccessibleTableControlObjType::ROWHEADERBAR) |
55 | 0 | nChildren = m_aTable.GetRowCount(); |
56 | 0 | else if (m_eObjType == AccessibleTableControlObjType::TABLE) |
57 | 0 | nChildren = static_cast<sal_Int64>(m_aTable.GetRowCount()) * static_cast<sal_Int64>(m_aTable.GetColumnCount()); |
58 | 0 | else if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR) |
59 | 0 | nChildren = m_aTable.GetColumnCount(); |
60 | 0 | return nChildren; |
61 | 0 | } |
62 | | |
63 | | sal_Int16 SAL_CALL AccessibleGridControlTableBase::getAccessibleRole() |
64 | 0 | { |
65 | 0 | SolarMutexGuard g; |
66 | |
|
67 | 0 | ensureAlive(); |
68 | 0 | return AccessibleRole::TABLE; |
69 | 0 | } |
70 | | |
71 | | // XAccessibleTable ----------------------------------------------------------- |
72 | | |
73 | | sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowCount() |
74 | 0 | { |
75 | 0 | SolarMutexGuard aSolarGuard; |
76 | |
|
77 | 0 | ensureAlive(); |
78 | |
|
79 | 0 | if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR) |
80 | 0 | return 1; |
81 | 0 | return m_aTable.GetRowCount(); |
82 | 0 | } |
83 | | |
84 | | sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount() |
85 | 0 | { |
86 | 0 | SolarMutexGuard aSolarGuard; |
87 | |
|
88 | 0 | ensureAlive(); |
89 | |
|
90 | 0 | if (m_eObjType == AccessibleTableControlObjType::ROWHEADERBAR) |
91 | 0 | return 1; |
92 | 0 | return m_aTable.GetColumnCount(); |
93 | 0 | } |
94 | | |
95 | | sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt( |
96 | | sal_Int32 nRow, sal_Int32 nColumn ) |
97 | 0 | { |
98 | 0 | SolarMutexGuard aSolarGuard; |
99 | |
|
100 | 0 | ensureAlive(); |
101 | 0 | ensureIsValidAddress( nRow, nColumn ); |
102 | 0 | return 1; // merged cells not supported |
103 | 0 | } |
104 | | |
105 | | sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt( |
106 | | sal_Int32 nRow, sal_Int32 nColumn ) |
107 | 0 | { |
108 | 0 | SolarMutexGuard aSolarGuard; |
109 | |
|
110 | 0 | ensureAlive(); |
111 | 0 | ensureIsValidAddress( nRow, nColumn ); |
112 | 0 | return 1; // merged cells not supported |
113 | 0 | } |
114 | | |
115 | | Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption() |
116 | 0 | { |
117 | 0 | SolarMutexGuard g; |
118 | |
|
119 | 0 | ensureAlive(); |
120 | 0 | return nullptr; // not supported |
121 | 0 | } |
122 | | |
123 | | Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary() |
124 | 0 | { |
125 | 0 | SolarMutexGuard g; |
126 | |
|
127 | 0 | ensureAlive(); |
128 | 0 | return nullptr; // not supported |
129 | 0 | } |
130 | | |
131 | | sal_Int64 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex( |
132 | | sal_Int32 nRow, sal_Int32 nColumn ) |
133 | 0 | { |
134 | 0 | SolarMutexGuard aSolarGuard; |
135 | |
|
136 | 0 | ensureAlive(); |
137 | 0 | ensureIsValidAddress( nRow, nColumn ); |
138 | 0 | return static_cast<sal_Int64>(nRow) * static_cast<sal_Int64>(m_aTable.GetColumnCount()) + nColumn; |
139 | 0 | } |
140 | | |
141 | | sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int64 nChildIndex ) |
142 | 0 | { |
143 | 0 | SolarMutexGuard aSolarGuard; |
144 | |
|
145 | 0 | ensureAlive(); |
146 | 0 | ensureIsValidIndex( nChildIndex ); |
147 | 0 | return implGetRow( nChildIndex ); |
148 | 0 | } |
149 | | |
150 | | sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int64 nChildIndex ) |
151 | 0 | { |
152 | 0 | SolarMutexGuard aSolarGuard; |
153 | |
|
154 | 0 | ensureAlive(); |
155 | 0 | ensureIsValidIndex( nChildIndex ); |
156 | 0 | return implGetColumn( nChildIndex ); |
157 | 0 | } |
158 | | |
159 | | // internal helper methods ---------------------------------------------------- |
160 | | |
161 | | sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int64 nChildIndex ) |
162 | 0 | { |
163 | 0 | sal_Int32 nColumns = getAccessibleColumnCount(); |
164 | 0 | return nColumns ? (nChildIndex / nColumns) : 0; |
165 | 0 | } |
166 | | |
167 | | sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int64 nChildIndex ) |
168 | 0 | { |
169 | 0 | sal_Int32 nColumns = getAccessibleColumnCount(); |
170 | 0 | return nColumns ? (nChildIndex % nColumns) : 0; |
171 | 0 | } |
172 | | |
173 | | void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq ) |
174 | 0 | { |
175 | 0 | sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() ); |
176 | 0 | rSeq.realloc( selectionCount ); |
177 | 0 | auto pSeq = rSeq.getArray(); |
178 | 0 | for ( sal_Int32 i=0; i<selectionCount; ++i ) |
179 | 0 | pSeq[i] = m_aTable.GetSelectedRowIndex(i); |
180 | 0 | } |
181 | | |
182 | | void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow ) |
183 | 0 | { |
184 | 0 | if (nRow < 0 || nRow >= getAccessibleRowCount()) |
185 | 0 | throw lang::IndexOutOfBoundsException( u"row index is invalid"_ustr, *this ); |
186 | 0 | } |
187 | | |
188 | | void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn ) |
189 | 0 | { |
190 | 0 | if (nColumn < 0 || nColumn >= getAccessibleColumnCount()) |
191 | 0 | throw lang::IndexOutOfBoundsException( u"column index is invalid"_ustr, *this ); |
192 | 0 | } |
193 | | |
194 | | void AccessibleGridControlTableBase::ensureIsValidAddress( |
195 | | sal_Int32 nRow, sal_Int32 nColumn ) |
196 | 0 | { |
197 | 0 | ensureIsValidRow( nRow ); |
198 | 0 | ensureIsValidColumn( nColumn ); |
199 | 0 | } |
200 | | |
201 | | void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int64 nChildIndex ) |
202 | 0 | { |
203 | 0 | if (nChildIndex < 0 || nChildIndex >= static_cast<sal_Int64>(m_aTable.GetRowCount()) * static_cast<sal_Int64>(m_aTable.GetColumnCount())) |
204 | 0 | throw lang::IndexOutOfBoundsException( u"child index is invalid"_ustr, *this ); |
205 | 0 | } |
206 | | |
207 | | |
208 | | } // namespace accessibility |
209 | | |
210 | | |
211 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |