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