Line data Source code
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 "AccessibleTableBase.hxx"
21 : #include "miscuno.hxx"
22 : #include "document.hxx"
23 : #include "scresid.hxx"
24 : #include "sc.hrc"
25 :
26 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 : #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
28 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 : #include <comphelper/sequence.hxx>
30 : #include <comphelper/servicehelper.hxx>
31 : #include <vcl/svapp.hxx>
32 :
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::accessibility;
36 :
37 : //===== internal ============================================================
38 :
39 0 : ScAccessibleTableBase::ScAccessibleTableBase(
40 : const uno::Reference<XAccessible>& rxParent,
41 : ScDocument* pDoc,
42 : const ScRange& rRange)
43 : :
44 : ScAccessibleContextBase (rxParent, AccessibleRole::TABLE),
45 : maRange(rRange),
46 0 : mpDoc(pDoc)
47 : {
48 0 : }
49 :
50 0 : ScAccessibleTableBase::~ScAccessibleTableBase()
51 : {
52 0 : }
53 :
54 0 : void SAL_CALL ScAccessibleTableBase::disposing()
55 : {
56 0 : SolarMutexGuard aGuard;
57 0 : mpDoc = NULL;
58 :
59 0 : ScAccessibleContextBase::disposing();
60 0 : }
61 :
62 : //===== XInterface =====================================================
63 :
64 0 : uno::Any SAL_CALL ScAccessibleTableBase::queryInterface( uno::Type const & rType )
65 : throw (uno::RuntimeException)
66 : {
67 0 : uno::Any aAny (ScAccessibleTableBaseImpl::queryInterface(rType));
68 0 : return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
69 : }
70 :
71 0 : void SAL_CALL ScAccessibleTableBase::acquire()
72 : throw ()
73 : {
74 0 : ScAccessibleContextBase::acquire();
75 0 : }
76 :
77 0 : void SAL_CALL ScAccessibleTableBase::release()
78 : throw ()
79 : {
80 0 : ScAccessibleContextBase::release();
81 0 : }
82 :
83 : //===== XAccessibleTable ================================================
84 :
85 0 : sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowCount( )
86 : throw (uno::RuntimeException)
87 : {
88 0 : SolarMutexGuard aGuard;
89 0 : IsObjectValid();
90 0 : return maRange.aEnd.Row() - maRange.aStart.Row() + 1;
91 : }
92 :
93 0 : sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnCount( )
94 : throw (uno::RuntimeException)
95 : {
96 0 : SolarMutexGuard aGuard;
97 0 : IsObjectValid();
98 0 : return maRange.aEnd.Col() - maRange.aStart.Col() + 1;
99 : }
100 :
101 0 : ::rtl::OUString SAL_CALL ScAccessibleTableBase::getAccessibleRowDescription( sal_Int32 nRow )
102 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
103 : {
104 : OSL_FAIL("Here should be a implementation to fill the description");
105 :
106 0 : if ((nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
107 0 : throw lang::IndexOutOfBoundsException();
108 :
109 : //setAccessibleRowDescription(nRow, xAccessible); // to remember the created Description
110 0 : return rtl::OUString();
111 : }
112 :
113 0 : ::rtl::OUString SAL_CALL ScAccessibleTableBase::getAccessibleColumnDescription( sal_Int32 nColumn )
114 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
115 : {
116 : OSL_FAIL("Here should be a implementation to fill the description");
117 :
118 0 : if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0))
119 0 : throw lang::IndexOutOfBoundsException();
120 :
121 : //setAccessibleColumnDescription(nColumn, xAccessible); // to remember the created Description
122 0 : return rtl::OUString();
123 : }
124 :
125 0 : sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
126 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
127 : {
128 0 : SolarMutexGuard aGuard;
129 0 : IsObjectValid();
130 :
131 0 : if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0) ||
132 0 : (nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
133 0 : throw lang::IndexOutOfBoundsException();
134 :
135 0 : sal_Int32 nCount(1); // the same cell
136 0 : nRow += maRange.aStart.Row();
137 0 : nColumn += maRange.aStart.Col();
138 :
139 0 : if (mpDoc)
140 : {
141 0 : SCROW nEndRow(0);
142 0 : SCCOL nEndCol(0);
143 0 : if (mpDoc->ExtendMerge(static_cast<SCCOL>(nColumn), static_cast<SCROW>(nRow),
144 0 : nEndCol, nEndRow, maRange.aStart.Tab()))
145 : {
146 0 : if (nEndRow > nRow)
147 0 : nCount = nEndRow - nRow + 1;
148 : }
149 : }
150 :
151 0 : return nCount;
152 : }
153 :
154 0 : sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
155 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
156 : {
157 0 : SolarMutexGuard aGuard;
158 0 : IsObjectValid();
159 :
160 0 : if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0) ||
161 0 : (nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
162 0 : throw lang::IndexOutOfBoundsException();
163 :
164 0 : sal_Int32 nCount(1); // the same cell
165 0 : nRow += maRange.aStart.Row();
166 0 : nColumn += maRange.aStart.Col();
167 :
168 0 : if (mpDoc)
169 : {
170 0 : SCROW nEndRow(0);
171 0 : SCCOL nEndCol(0);
172 0 : if (mpDoc->ExtendMerge(static_cast<SCCOL>(nColumn), static_cast<SCROW>(nRow),
173 0 : nEndCol, nEndRow, maRange.aStart.Tab()))
174 : {
175 0 : if (nEndCol > nColumn)
176 0 : nCount = nEndCol - nColumn + 1;
177 : }
178 : }
179 :
180 0 : return nCount;
181 : }
182 :
183 0 : uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleRowHeaders( )
184 : throw (uno::RuntimeException)
185 : {
186 0 : uno::Reference< XAccessibleTable > xAccessibleTable;
187 : OSL_FAIL("Here should be a implementation to fill the row headers");
188 :
189 : //CommitChange
190 0 : return xAccessibleTable;
191 : }
192 :
193 0 : uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleColumnHeaders( )
194 : throw (uno::RuntimeException)
195 : {
196 0 : uno::Reference< XAccessibleTable > xAccessibleTable;
197 : OSL_FAIL("Here should be a implementation to fill the column headers");
198 :
199 : //CommitChange
200 0 : return xAccessibleTable;
201 : }
202 :
203 0 : uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleRows( )
204 : throw (uno::RuntimeException)
205 : {
206 : OSL_FAIL("not implemented yet");
207 0 : uno::Sequence< sal_Int32 > aSequence;
208 0 : return aSequence;
209 : }
210 :
211 0 : uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleColumns( )
212 : throw (uno::RuntimeException)
213 : {
214 : OSL_FAIL("not implemented yet");
215 0 : uno::Sequence< sal_Int32 > aSequence;
216 0 : return aSequence;
217 : }
218 :
219 0 : sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleRowSelected( sal_Int32 /* nRow */ )
220 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
221 : {
222 : OSL_FAIL("not implemented yet");
223 0 : return false;
224 : }
225 :
226 0 : sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleColumnSelected( sal_Int32 /* nColumn */ )
227 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
228 : {
229 : OSL_FAIL("not implemented yet");
230 0 : return false;
231 : }
232 :
233 0 : uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCellAt( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
234 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
235 : {
236 : OSL_FAIL("not implemented yet");
237 0 : uno::Reference< XAccessible > xAccessible;
238 0 : return xAccessible;
239 : }
240 :
241 0 : uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCaption( )
242 : throw (uno::RuntimeException)
243 : {
244 : OSL_FAIL("not implemented yet");
245 0 : uno::Reference< XAccessible > xAccessible;
246 0 : return xAccessible;
247 : }
248 :
249 0 : uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleSummary( )
250 : throw (uno::RuntimeException)
251 : {
252 : OSL_FAIL("not implemented yet");
253 0 : uno::Reference< XAccessible > xAccessible;
254 0 : return xAccessible;
255 : }
256 :
257 0 : sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleSelected( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
258 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
259 : {
260 : OSL_FAIL("not implemented yet");
261 0 : return false;
262 : }
263 :
264 : //===== XAccessibleExtendedTable ========================================
265 :
266 0 : sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
267 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
268 : {
269 0 : SolarMutexGuard aGuard;
270 0 : IsObjectValid();
271 :
272 0 : if (nRow > (maRange.aEnd.Row() - maRange.aStart.Row()) ||
273 : nRow < 0 ||
274 0 : nColumn > (maRange.aEnd.Col() - maRange.aStart.Col()) ||
275 : nColumn < 0)
276 0 : throw lang::IndexOutOfBoundsException();
277 :
278 0 : nRow -= maRange.aStart.Row();
279 0 : nColumn -= maRange.aStart.Col();
280 0 : return (nRow * (maRange.aEnd.Col() + 1)) + nColumn;
281 : }
282 :
283 0 : sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRow( sal_Int32 nChildIndex )
284 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
285 : {
286 0 : SolarMutexGuard aGuard;
287 0 : IsObjectValid();
288 :
289 0 : if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
290 0 : throw lang::IndexOutOfBoundsException();
291 :
292 0 : return nChildIndex / (maRange.aEnd.Col() - maRange.aStart.Col() + 1);
293 : }
294 :
295 0 : sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
296 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
297 : {
298 0 : SolarMutexGuard aGuard;
299 0 : IsObjectValid();
300 :
301 0 : if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
302 0 : throw lang::IndexOutOfBoundsException();
303 :
304 0 : return nChildIndex % static_cast<sal_Int32>(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
305 : }
306 :
307 : //===== XAccessibleContext ==============================================
308 :
309 : sal_Int32 SAL_CALL
310 0 : ScAccessibleTableBase::getAccessibleChildCount(void)
311 : throw (uno::RuntimeException)
312 : {
313 0 : SolarMutexGuard aGuard;
314 0 : IsObjectValid();
315 0 : return static_cast<sal_Int32>(maRange.aEnd.Row() - maRange.aStart.Row() + 1) *
316 0 : (maRange.aEnd.Col() - maRange.aStart.Col() + 1);
317 : // return 1;
318 : }
319 :
320 : uno::Reference< XAccessible > SAL_CALL
321 0 : ScAccessibleTableBase::getAccessibleChild(sal_Int32 nIndex)
322 : throw (uno::RuntimeException,
323 : lang::IndexOutOfBoundsException)
324 : {
325 0 : SolarMutexGuard aGuard;
326 0 : IsObjectValid();
327 :
328 0 : if (nIndex >= getAccessibleChildCount() || nIndex < 0)
329 0 : throw lang::IndexOutOfBoundsException();
330 :
331 0 : sal_Int32 nRow(0);
332 0 : sal_Int32 nColumn(0);
333 0 : sal_Int32 nTemp(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
334 0 : nRow = nIndex / nTemp;
335 0 : nColumn = nIndex % nTemp;
336 0 : return getAccessibleCellAt(nRow, nColumn);
337 : }
338 :
339 : ::rtl::OUString SAL_CALL
340 0 : ScAccessibleTableBase::createAccessibleDescription(void)
341 : throw (uno::RuntimeException)
342 : {
343 0 : String sDesc(ScResId(STR_ACC_TABLE_DESCR));
344 0 : return rtl::OUString(sDesc);
345 : }
346 :
347 : ::rtl::OUString SAL_CALL
348 0 : ScAccessibleTableBase::createAccessibleName(void)
349 : throw (uno::RuntimeException)
350 : {
351 0 : String sName(ScResId(STR_ACC_TABLE_NAME));
352 0 : rtl::OUString sCoreName;
353 0 : if (mpDoc && mpDoc->GetName( maRange.aStart.Tab(), sCoreName ))
354 0 : sName.SearchAndReplaceAscii("%1", sCoreName);
355 0 : return rtl::OUString(sName);
356 : }
357 :
358 : uno::Reference<XAccessibleRelationSet> SAL_CALL
359 0 : ScAccessibleTableBase::getAccessibleRelationSet(void)
360 : throw (uno::RuntimeException)
361 : {
362 : OSL_FAIL("should be implemented in the abrevated class");
363 0 : return uno::Reference<XAccessibleRelationSet>();
364 : }
365 :
366 : uno::Reference<XAccessibleStateSet> SAL_CALL
367 0 : ScAccessibleTableBase::getAccessibleStateSet(void)
368 : throw (uno::RuntimeException)
369 : {
370 : OSL_FAIL("should be implemented in the abrevated class");
371 0 : uno::Reference< XAccessibleStateSet > xAccessibleStateSet;
372 0 : return xAccessibleStateSet;
373 : }
374 :
375 : ///===== XAccessibleSelection ===========================================
376 :
377 : void SAL_CALL
378 0 : ScAccessibleTableBase::selectAccessibleChild( sal_Int32 /* nChildIndex */ )
379 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
380 : {
381 0 : }
382 :
383 : sal_Bool SAL_CALL
384 0 : ScAccessibleTableBase::isAccessibleChildSelected( sal_Int32 nChildIndex )
385 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
386 : {
387 : // I don't need to guard, because the called functions have a guard
388 0 : if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
389 0 : throw lang::IndexOutOfBoundsException();
390 0 : return isAccessibleSelected(getAccessibleRow(nChildIndex), getAccessibleColumn(nChildIndex));
391 : }
392 :
393 : void SAL_CALL
394 0 : ScAccessibleTableBase::clearAccessibleSelection( )
395 : throw (uno::RuntimeException)
396 : {
397 0 : }
398 :
399 : void SAL_CALL
400 0 : ScAccessibleTableBase::selectAllAccessibleChildren( )
401 : throw (uno::RuntimeException)
402 : {
403 0 : }
404 :
405 : sal_Int32 SAL_CALL
406 0 : ScAccessibleTableBase::getSelectedAccessibleChildCount( )
407 : throw (uno::RuntimeException)
408 : {
409 0 : sal_Int32 nResult(0);
410 0 : return nResult;
411 : }
412 :
413 : uno::Reference<XAccessible > SAL_CALL
414 0 : ScAccessibleTableBase::getSelectedAccessibleChild( sal_Int32 /* nSelectedChildIndex */ )
415 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
416 : {
417 0 : uno::Reference < XAccessible > xAccessible;
418 0 : return xAccessible;
419 : }
420 :
421 : void SAL_CALL
422 0 : ScAccessibleTableBase::deselectAccessibleChild( sal_Int32 /* nSelectedChildIndex */ )
423 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
424 : {
425 0 : }
426 :
427 : //===== XServiceInfo ====================================================
428 :
429 0 : ::rtl::OUString SAL_CALL ScAccessibleTableBase::getImplementationName(void)
430 : throw (uno::RuntimeException)
431 : {
432 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleTableBase"));
433 : }
434 :
435 : //===== XTypeProvider ===================================================
436 :
437 0 : uno::Sequence< uno::Type > SAL_CALL ScAccessibleTableBase::getTypes()
438 : throw (uno::RuntimeException)
439 : {
440 0 : return comphelper::concatSequences(ScAccessibleTableBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
441 : }
442 :
443 : namespace
444 : {
445 : class theScAccessibleTableBaseImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessibleTableBaseImplementationId > {};
446 : }
447 :
448 : uno::Sequence<sal_Int8> SAL_CALL
449 0 : ScAccessibleTableBase::getImplementationId(void)
450 : throw (uno::RuntimeException)
451 : {
452 0 : return theScAccessibleTableBaseImplementationId::get().getSeq();
453 : }
454 :
455 0 : void ScAccessibleTableBase::CommitTableModelChange(sal_Int32 nStartRow, sal_Int32 nStartCol, sal_Int32 nEndRow, sal_Int32 nEndCol, sal_uInt16 nId)
456 : {
457 0 : AccessibleTableModelChange aModelChange;
458 0 : aModelChange.FirstRow = nStartRow;
459 0 : aModelChange.FirstColumn = nStartCol;
460 0 : aModelChange.LastRow = nEndRow;
461 0 : aModelChange.LastColumn = nEndCol;
462 0 : aModelChange.Type = nId;
463 :
464 0 : AccessibleEventObject aEvent;
465 0 : aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
466 0 : aEvent.Source = uno::Reference< XAccessibleContext >(this);
467 0 : aEvent.NewValue <<= aModelChange;
468 :
469 0 : CommitChange(aEvent);
470 0 : }
471 :
472 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|