/src/libreoffice/vcl/source/accessibility/AccessibleBrowseBoxTableBase.cxx
Line | Count | Source (jump to first uncovered line) |
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 <vcl/accessibility/AccessibleBrowseBoxTableBase.hxx> |
21 | | #include <vcl/accessibletableprovider.hxx> |
22 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
23 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
24 | | |
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 | | |
33 | | |
34 | | // Ctor/Dtor/disposing -------------------------------------------------------- |
35 | | |
36 | | AccessibleBrowseBoxTableBase::AccessibleBrowseBoxTableBase( |
37 | | const Reference<XAccessible>& rxParent, vcl::IAccessibleTableProvider& rBrowseBox, |
38 | | AccessibleBrowseBoxObjType eObjType) |
39 | 0 | : ImplInheritanceHelper(rxParent, rBrowseBox, nullptr, eObjType) |
40 | 0 | { |
41 | 0 | } |
42 | | |
43 | | // XAccessibleContext --------------------------------------------------------- |
44 | | |
45 | | sal_Int64 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleChildCount() |
46 | 0 | { |
47 | 0 | SolarMethodGuard aGuard(getMutex()); |
48 | 0 | ensureIsAlive(); |
49 | 0 | return implGetChildCount(); |
50 | 0 | } |
51 | | |
52 | | sal_Int16 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRole() |
53 | 0 | { |
54 | 0 | osl::MutexGuard aGuard( getMutex() ); |
55 | 0 | ensureIsAlive(); |
56 | 0 | return AccessibleRole::TABLE; |
57 | 0 | } |
58 | | |
59 | | // XAccessibleTable ----------------------------------------------------------- |
60 | | |
61 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowCount() |
62 | 0 | { |
63 | 0 | SolarMethodGuard aGuard(getMutex()); |
64 | 0 | ensureIsAlive(); |
65 | 0 | return implGetRowCount(); |
66 | 0 | } |
67 | | |
68 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnCount() |
69 | 0 | { |
70 | 0 | SolarMethodGuard aGuard(getMutex()); |
71 | 0 | ensureIsAlive(); |
72 | 0 | return implGetColumnCount(); |
73 | 0 | } |
74 | | |
75 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowExtentAt( |
76 | | sal_Int32 nRow, sal_Int32 nColumn ) |
77 | 0 | { |
78 | 0 | SolarMethodGuard aGuard(getMutex()); |
79 | 0 | ensureIsAlive(); |
80 | 0 | ensureIsValidAddress( nRow, nColumn ); |
81 | 0 | return 1; // merged cells not supported |
82 | 0 | } |
83 | | |
84 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnExtentAt( |
85 | | sal_Int32 nRow, sal_Int32 nColumn ) |
86 | 0 | { |
87 | 0 | SolarMethodGuard aGuard(getMutex()); |
88 | 0 | ensureIsAlive(); |
89 | 0 | ensureIsValidAddress( nRow, nColumn ); |
90 | 0 | return 1; // merged cells not supported |
91 | 0 | } |
92 | | |
93 | | Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleCaption() |
94 | 0 | { |
95 | 0 | ensureIsAlive(); |
96 | 0 | return nullptr; // not supported |
97 | 0 | } |
98 | | |
99 | | Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleSummary() |
100 | 0 | { |
101 | 0 | ensureIsAlive(); |
102 | 0 | return nullptr; // not supported |
103 | 0 | } |
104 | | |
105 | | sal_Int64 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleIndex( |
106 | | sal_Int32 nRow, sal_Int32 nColumn ) |
107 | 0 | { |
108 | 0 | SolarMethodGuard aGuard(getMutex()); |
109 | 0 | ensureIsAlive(); |
110 | 0 | ensureIsValidAddress( nRow, nColumn ); |
111 | 0 | return static_cast<sal_Int64>(nRow) * static_cast<sal_Int64>(implGetColumnCount()) + nColumn; |
112 | 0 | } |
113 | | |
114 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRow( sal_Int64 nChildIndex ) |
115 | 0 | { |
116 | 0 | SolarMethodGuard aGuard(getMutex()); |
117 | 0 | ensureIsAlive(); |
118 | 0 | ensureIsValidIndex( nChildIndex ); |
119 | 0 | return implGetRow( nChildIndex ); |
120 | 0 | } |
121 | | |
122 | | sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumn( sal_Int64 nChildIndex ) |
123 | 0 | { |
124 | 0 | SolarMethodGuard aGuard(getMutex()); |
125 | 0 | ensureIsAlive(); |
126 | 0 | ensureIsValidIndex( nChildIndex ); |
127 | 0 | return implGetColumn( nChildIndex ); |
128 | 0 | } |
129 | | |
130 | | // internal virtual methods --------------------------------------------------- |
131 | | |
132 | | sal_Int32 AccessibleBrowseBoxTableBase::implGetRowCount() const |
133 | 0 | { |
134 | 0 | return mpBrowseBox->GetRowCount(); |
135 | 0 | } |
136 | | |
137 | | sal_Int32 AccessibleBrowseBoxTableBase::implGetColumnCount() const |
138 | 0 | { |
139 | 0 | sal_uInt16 nColumns = mpBrowseBox->GetColumnCount(); |
140 | | // do not count the "handle column" |
141 | 0 | if( nColumns && implHasHandleColumn() ) |
142 | 0 | --nColumns; |
143 | 0 | return nColumns; |
144 | 0 | } |
145 | | |
146 | | // internal helper methods ---------------------------------------------------- |
147 | | |
148 | | bool AccessibleBrowseBoxTableBase::implHasHandleColumn() const |
149 | 0 | { |
150 | 0 | return mpBrowseBox->HasRowHeader(); |
151 | 0 | } |
152 | | |
153 | | sal_uInt16 AccessibleBrowseBoxTableBase::implToVCLColumnPos( sal_Int32 nColumn ) const |
154 | 0 | { |
155 | 0 | sal_uInt16 nVCLPos = 0; |
156 | 0 | if( (0 <= nColumn) && (nColumn < implGetColumnCount()) ) |
157 | 0 | { |
158 | | // regard "handle column" |
159 | 0 | if( implHasHandleColumn() ) |
160 | 0 | ++nColumn; |
161 | 0 | nVCLPos = static_cast< sal_uInt16 >( nColumn ); |
162 | 0 | } |
163 | 0 | return nVCLPos; |
164 | 0 | } |
165 | | |
166 | | sal_Int64 AccessibleBrowseBoxTableBase::implGetChildCount() const |
167 | 0 | { |
168 | 0 | return static_cast<sal_Int64>(implGetRowCount()) * static_cast<sal_Int64>(implGetColumnCount()); |
169 | 0 | } |
170 | | |
171 | | sal_Int32 AccessibleBrowseBoxTableBase::implGetRow( sal_Int64 nChildIndex ) const |
172 | 0 | { |
173 | 0 | sal_Int32 nColumns = implGetColumnCount(); |
174 | 0 | return nColumns ? (nChildIndex / nColumns) : 0; |
175 | 0 | } |
176 | | |
177 | | sal_Int32 AccessibleBrowseBoxTableBase::implGetColumn( sal_Int64 nChildIndex ) const |
178 | 0 | { |
179 | 0 | sal_Int32 nColumns = implGetColumnCount(); |
180 | 0 | return nColumns ? (nChildIndex % nColumns) : 0; |
181 | 0 | } |
182 | | |
183 | | bool AccessibleBrowseBoxTableBase::implIsRowSelected( sal_Int32 nRow ) const |
184 | 0 | { |
185 | 0 | return mpBrowseBox->IsRowSelected( nRow ); |
186 | 0 | } |
187 | | |
188 | | bool AccessibleBrowseBoxTableBase::implIsColumnSelected( sal_Int32 nColumn ) const |
189 | 0 | { |
190 | 0 | if( implHasHandleColumn() ) |
191 | 0 | --nColumn; |
192 | 0 | return mpBrowseBox->IsColumnSelected( nColumn ); |
193 | 0 | } |
194 | | |
195 | | void AccessibleBrowseBoxTableBase::implSelectRow( sal_Int32 nRow, bool bSelect ) |
196 | 0 | { |
197 | 0 | mpBrowseBox->SelectRow( nRow, bSelect ); |
198 | 0 | } |
199 | | |
200 | | void AccessibleBrowseBoxTableBase::implSelectColumn( sal_Int32 nColumnPos, bool bSelect ) |
201 | 0 | { |
202 | 0 | mpBrowseBox->SelectColumn( static_cast<sal_uInt16>(nColumnPos), bSelect ); |
203 | 0 | } |
204 | | |
205 | | sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedRowCount() const |
206 | 0 | { |
207 | 0 | return mpBrowseBox->GetSelectedRowCount(); |
208 | 0 | } |
209 | | |
210 | | sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedColumnCount() const |
211 | 0 | { |
212 | 0 | return mpBrowseBox->GetSelectedColumnCount(); |
213 | 0 | } |
214 | | |
215 | | void AccessibleBrowseBoxTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq ) |
216 | 0 | { |
217 | 0 | mpBrowseBox->GetAllSelectedRows( rSeq ); |
218 | 0 | } |
219 | | |
220 | | void AccessibleBrowseBoxTableBase::implGetSelectedColumns( Sequence< sal_Int32 >& rSeq ) |
221 | 0 | { |
222 | 0 | mpBrowseBox->GetAllSelectedColumns( rSeq ); |
223 | 0 | } |
224 | | |
225 | | void AccessibleBrowseBoxTableBase::ensureIsValidRow( sal_Int32 nRow ) |
226 | 0 | { |
227 | 0 | if( nRow >= implGetRowCount() ) |
228 | 0 | throw lang::IndexOutOfBoundsException( u"row index is invalid"_ustr, *this ); |
229 | 0 | } |
230 | | |
231 | | void AccessibleBrowseBoxTableBase::ensureIsValidColumn( sal_Int32 nColumn ) |
232 | 0 | { |
233 | 0 | if( nColumn >= implGetColumnCount() ) |
234 | 0 | throw lang::IndexOutOfBoundsException( u"column index is invalid"_ustr, *this ); |
235 | 0 | } |
236 | | |
237 | | void AccessibleBrowseBoxTableBase::ensureIsValidAddress( |
238 | | sal_Int32 nRow, sal_Int32 nColumn ) |
239 | 0 | { |
240 | 0 | ensureIsValidRow( nRow ); |
241 | 0 | ensureIsValidColumn( nColumn ); |
242 | 0 | } |
243 | | |
244 | | void AccessibleBrowseBoxTableBase::ensureIsValidIndex( sal_Int64 nChildIndex ) |
245 | 0 | { |
246 | 0 | if( nChildIndex >= implGetChildCount() ) |
247 | 0 | throw lang::IndexOutOfBoundsException( u"child index is invalid"_ustr, *this ); |
248 | 0 | } |
249 | | |
250 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |