LibreOffice Module sc (master) 1
AccessibleTableBase.cxx
Go to the documentation of this file.
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
21#include <document.hxx>
22#include <scresid.hxx>
23#include <strings.hrc>
24#include <strings.hxx>
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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
32#include <vcl/svapp.hxx>
33
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::accessibility;
36
37//===== internal ============================================================
38
40 const uno::Reference<XAccessible>& rxParent,
41 ScDocument* pDoc,
42 const ScRange& rRange)
43 :
44 ScAccessibleContextBase (rxParent, AccessibleRole::TABLE),
45 maRange(rRange),
46 mpDoc(pDoc)
47{
48}
49
51{
52}
53
55{
56 SolarMutexGuard aGuard;
57 mpDoc = nullptr;
58
60}
61
62 //===== XInterface =====================================================
63
65{
67 {
68 return uno::Any(uno::Reference<XAccessibleTableSelection>(this));
69 }
70 else
71 {
73 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
74 }
75}
76
78 noexcept
79{
80 ScAccessibleContextBase::acquire();
81}
82
84 noexcept
85{
86 ScAccessibleContextBase::release();
87}
88
89 //===== XAccessibleTable ================================================
90
92{
93 SolarMutexGuard aGuard;
95 return maRange.aEnd.Row() - maRange.aStart.Row() + 1;
96}
97
99{
100 SolarMutexGuard aGuard;
102 return maRange.aEnd.Col() - maRange.aStart.Col() + 1;
103}
104
105OUString SAL_CALL ScAccessibleTableBase::getAccessibleRowDescription( sal_Int32 nRow )
106{
107 OSL_FAIL("Here should be an implementation to fill the description");
108
109 if ((nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
110 throw lang::IndexOutOfBoundsException();
111
112 //setAccessibleRowDescription(nRow, xAccessible); // to remember the created Description
113 return OUString();
114}
115
116OUString SAL_CALL ScAccessibleTableBase::getAccessibleColumnDescription( sal_Int32 nColumn )
117{
118 OSL_FAIL("Here should be an implementation to fill the description");
119
120 if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0))
121 throw lang::IndexOutOfBoundsException();
122
123 //setAccessibleColumnDescription(nColumn, xAccessible); // to remember the created Description
124 return OUString();
125}
126
127sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
128{
129 SolarMutexGuard aGuard;
131
132 if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0) ||
133 (nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
134 throw lang::IndexOutOfBoundsException();
135
136 sal_Int32 nCount(1); // the same cell
137 nRow += maRange.aStart.Row();
138 nColumn += maRange.aStart.Col();
139
140 if (mpDoc)
141 {
143 if (pTab)
144 {
145 SCROW nStartRow = static_cast<SCROW>(nRow);
146 SCROW nEndRow = nStartRow;
147 SCCOL nStartCol = static_cast<SCCOL>(nColumn);
148 SCCOL nEndCol = nStartCol;
149 if (pTab->ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, false))
150 {
151 if (nEndRow > nStartRow)
152 nCount = nEndRow - nStartRow + 1;
153 }
154 }
155 }
156
157 return nCount;
158}
159
160sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
161{
162 SolarMutexGuard aGuard;
164
165 if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0) ||
166 (nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
167 throw lang::IndexOutOfBoundsException();
168
169 sal_Int32 nCount(1); // the same cell
170 nRow += maRange.aStart.Row();
171 nColumn += maRange.aStart.Col();
172
173 if (mpDoc)
174 {
176 if (pTab)
177 {
178 SCROW nStartRow = static_cast<SCROW>(nRow);
179 SCROW nEndRow = nStartRow;
180 SCCOL nStartCol = static_cast<SCCOL>(nColumn);
181 SCCOL nEndCol = nStartCol;
182 if (pTab->ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, false))
183 {
184 if (nEndCol > nStartCol)
185 nCount = nEndCol - nStartCol + 1;
186 }
187 }
188 }
189
190 return nCount;
191}
192
193uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleRowHeaders( )
194{
195 uno::Reference< XAccessibleTable > xAccessibleTable;
196 OSL_FAIL("Here should be an implementation to fill the row headers");
197
198 //CommitChange
199 return xAccessibleTable;
200}
201
202uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleColumnHeaders( )
203{
204 uno::Reference< XAccessibleTable > xAccessibleTable;
205 OSL_FAIL("Here should be an implementation to fill the column headers");
206
207 //CommitChange
208 return xAccessibleTable;
209}
210
211uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleRows( )
212{
213 OSL_FAIL("not implemented yet");
214 uno::Sequence< sal_Int32 > aSequence;
215 return aSequence;
216}
217
218uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleColumns( )
219{
220 OSL_FAIL("not implemented yet");
221 uno::Sequence< sal_Int32 > aSequence;
222 return aSequence;
223}
224
226{
227 OSL_FAIL("not implemented yet");
228 return false;
229}
230
232{
233 OSL_FAIL("not implemented yet");
234 return false;
235}
236
237uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCellAt( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
238{
239 OSL_FAIL("not implemented yet");
240 uno::Reference< XAccessible > xAccessible;
241 return xAccessible;
242}
243
244uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCaption( )
245{
246 OSL_FAIL("not implemented yet");
247 uno::Reference< XAccessible > xAccessible;
248 return xAccessible;
249}
250
251uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleSummary( )
252{
253 OSL_FAIL("not implemented yet");
254 uno::Reference< XAccessible > xAccessible;
255 return xAccessible;
256}
257
258sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleSelected( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
259{
260 OSL_FAIL("not implemented yet");
261 return false;
262}
263
264// ===== XAccessibleExtendedTable ========================================
265
266sal_Int64 SAL_CALL ScAccessibleTableBase::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
267{
268 SolarMutexGuard aGuard;
270
271 if (nRow > (maRange.aEnd.Row() - maRange.aStart.Row()) ||
272 nRow < 0 ||
273 nColumn > (maRange.aEnd.Col() - maRange.aStart.Col()) ||
274 nColumn < 0)
275 throw lang::IndexOutOfBoundsException();
276
277 nRow -= maRange.aStart.Row();
278 nColumn -= maRange.aStart.Col();
279 return (static_cast<sal_Int64>(nRow) * static_cast<sal_Int64>(maRange.aEnd.Col() + 1)) + nColumn;
280}
281
282sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRow( sal_Int64 nChildIndex )
283{
284 SolarMutexGuard aGuard;
286
287 if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
288 throw lang::IndexOutOfBoundsException();
289
290 return nChildIndex / (maRange.aEnd.Col() - maRange.aStart.Col() + 1);
291}
292
293sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumn( sal_Int64 nChildIndex )
294{
295 SolarMutexGuard aGuard;
297
298 if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
299 throw lang::IndexOutOfBoundsException();
300
301 return nChildIndex % static_cast<sal_Int32>(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
302}
303
304// ===== XAccessibleContext ==============================================
305
307{
308 SolarMutexGuard aGuard;
310
311 // FIXME: representing rows & columns this way is a plain and simple madness.
312 // this needs a radical re-think.
313 sal_Int64 nMax = static_cast<sal_Int64>(maRange.aEnd.Row() - maRange.aStart.Row() + 1) *
314 static_cast<sal_Int64>(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
315 if (nMax < 0)
316 return 0;
317 return nMax;
318}
319
320uno::Reference< XAccessible > SAL_CALL
322{
323 SolarMutexGuard aGuard;
325
326 if (nIndex >= getAccessibleChildCount() || nIndex < 0)
327 throw lang::IndexOutOfBoundsException();
328
329 // FIXME: representing rows & columns this way is a plain and simple madness.
330 // this needs a radical re-think.
331
332 sal_Int32 nRow(0);
333 sal_Int32 nColumn(0);
334 sal_Int32 nTemp(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
335 nRow = nIndex / nTemp;
336 nColumn = nIndex % nTemp;
337 return getAccessibleCellAt(nRow, nColumn);
338}
339
340OUString
342{
343 return STR_ACC_TABLE_DESCR;
344}
345
347{
348 OUString sName(ScResId(STR_ACC_TABLE_NAME));
349 OUString sCoreName;
350 if (mpDoc && mpDoc->GetName( maRange.aStart.Tab(), sCoreName ))
351 sName = sName.replaceFirst("%1", sCoreName);
352 return sName;
353}
354
355uno::Reference<XAccessibleRelationSet> SAL_CALL
357{
358 OSL_FAIL("should be implemented in the abrevated class");
359 return uno::Reference<XAccessibleRelationSet>();
360}
361
363{
364 OSL_FAIL("should be implemented in the abrevated class");
365 return 0;
366}
367
369
370void SAL_CALL ScAccessibleTableBase::selectAccessibleChild( sal_Int64 /* nChildIndex */ )
371{
372}
373
374sal_Bool SAL_CALL
376{
377 // I don't need to guard, because the called functions have a guard
378 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
379 throw lang::IndexOutOfBoundsException();
380 return isAccessibleSelected(getAccessibleRow(nChildIndex), getAccessibleColumn(nChildIndex));
381}
382
383void SAL_CALL
385{
386}
387
389{
390}
391
392sal_Int64 SAL_CALL
394{
395 return 0;
396}
397
398uno::Reference<XAccessible > SAL_CALL
399 ScAccessibleTableBase::getSelectedAccessibleChild( sal_Int64 /* nSelectedChildIndex */ )
400{
401 uno::Reference < XAccessible > xAccessible;
402 return xAccessible;
403}
404
405void SAL_CALL ScAccessibleTableBase::deselectAccessibleChild( sal_Int64 /* nSelectedChildIndex */ )
406{
407}
408
409 //===== XServiceInfo ====================================================
410
412{
413 return "ScAccessibleTableBase";
414}
415
416 //===== XTypeProvider ===================================================
417
418uno::Sequence< uno::Type > SAL_CALL ScAccessibleTableBase::getTypes()
419{
420 return comphelper::concatSequences(ScAccessibleTableBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
421}
422
423uno::Sequence<sal_Int8> SAL_CALL
425{
426 return css::uno::Sequence<sal_Int8>();
427}
428
429void ScAccessibleTableBase::CommitTableModelChange(sal_Int32 nStartRow, sal_Int32 nStartCol, sal_Int32 nEndRow, sal_Int32 nEndCol, sal_uInt16 nId)
430{
431 AccessibleTableModelChange aModelChange;
432 aModelChange.FirstRow = nStartRow;
433 aModelChange.FirstColumn = nStartCol;
434 aModelChange.LastRow = nEndRow;
435 aModelChange.LastColumn = nEndCol;
436 aModelChange.Type = nId;
437
438 AccessibleEventObject aEvent;
439 aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
440 aEvent.Source = uno::Reference< XAccessibleContext >(this);
441 aEvent.NewValue <<= aModelChange;
442
444}
445
447{
448 return true;
449}
450
452{
453 return true;
454}
455
457{
458 return true;
459}
460
462{
463 return true;
464}
465
466/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
B2DRange maRange
virtual void SAL_CALL disposing() override
void CommitChange(const css::accessibility::AccessibleEventObject &rEvent) const
Calls all Listener to tell they the change.
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
virtual css::uno::Reference< css::accessibility::XAccessibleTable > SAL_CALL getAccessibleRowHeaders() override
Returns the row headers as an AccessibleTable.
virtual sal_Int32 SAL_CALL getAccessibleRowExtentAt(sal_Int32 nRow, sal_Int32 nColumn) override
Returns the number of rows occupied by the Accessible at a specified row and column in the table.
virtual sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int64 nChildIndex) override
virtual OUString createAccessibleName() override
Return the object's current name.
virtual sal_Int32 SAL_CALL getAccessibleColumnCount() override
Returns the number of columns in the table.
virtual void SAL_CALL acquire() noexcept override
virtual sal_Bool SAL_CALL isAccessibleRowSelected(sal_Int32 nRow) override
Returns a boolean value indicating whether the specified row is selected.
virtual void SAL_CALL release() noexcept override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(sal_Int64 nSelectedChildIndex) override
virtual OUString SAL_CALL getAccessibleRowDescription(sal_Int32 nRow) override
Returns the description of the specified row in the table.
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Returns an implementation id.
virtual void SAL_CALL clearAccessibleSelection() override
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ===================================================
virtual sal_Int32 SAL_CALL getAccessibleRowCount() override
===== XAccessibleTable ================================================
virtual sal_Int64 SAL_CALL getAccessibleIndex(sal_Int32 nRow, sal_Int32 nColumn) override
===== XAccessibleExtendedTable ========================================
virtual sal_Int32 SAL_CALL getAccessibleRow(sal_Int64 nChildIndex) override
Returns the row number of an index in the table.
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 nIndex) override
Return the specified child or NULL if index is invalid.
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleCaption() override
Returns the caption for the table.
virtual sal_Bool SAL_CALL isAccessibleSelected(sal_Int32 nRow, sal_Int32 nColumn) override
Returns a boolean value indicating whether the accessible at a specified row and column is selected.
virtual OUString SAL_CALL getAccessibleColumnDescription(sal_Int32 nColumn) override
Returns the description text of the specified column in the table.
ScRange maRange
contains the range of the table, because it could be a subrange of the complete table
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleCellAt(sal_Int32 nRow, sal_Int32 nColumn) override
Returns the Accessible at a specified row and column in the table.
virtual css::uno::Sequence< sal_Int32 > SAL_CALL getSelectedAccessibleRows() override
Returns the selected rows in a table.
ScAccessibleTableBase(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScDocument *pDoc, const ScRange &rRange)
virtual void SAL_CALL deselectAccessibleChild(sal_Int64 nSelectedChildIndex) override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleSummary() override
Returns the summary description of the table.
virtual void SAL_CALL selectAllAccessibleChildren() override
virtual sal_Bool SAL_CALL isAccessibleColumnSelected(sal_Int32 nColumn) override
Returns a boolean value indicating whether the specified column is selected.
virtual css::uno::Reference< css::accessibility::XAccessibleTable > SAL_CALL getAccessibleColumnHeaders() override
Returns the column headers as an AccessibleTable.
virtual ~ScAccessibleTableBase() override
virtual sal_Bool SAL_CALL selectColumn(sal_Int32 column) override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
Return the number of currently visible children.
void CommitTableModelChange(sal_Int32 nStartRow, sal_Int32 nStartCol, sal_Int32 nEndRow, sal_Int32 nEndCol, sal_uInt16 nId)
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
Return the set of current states.
virtual OUString createAccessibleDescription() override
Return this object's description.
virtual sal_Bool SAL_CALL selectRow(sal_Int32 row) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
===== XTypeProvider ===================================================
virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount() override
virtual sal_Bool SAL_CALL unselectColumn(sal_Int32 column) override
virtual void SAL_CALL selectAccessibleChild(sal_Int64 nChildIndex) override
===== XAccessibleSelection ===========================================
virtual sal_Bool SAL_CALL unselectRow(sal_Int32 row) override
virtual sal_Int32 SAL_CALL getAccessibleColumn(sal_Int64 nChildIndex) override
Returns the column number of an index in the table.
virtual css::uno::Sequence< sal_Int32 > SAL_CALL getSelectedAccessibleColumns() override
Returns the selected columns in a table.
virtual sal_Int32 SAL_CALL getAccessibleColumnExtentAt(sal_Int32 nRow, sal_Int32 nColumn) override
Returns the number of columns occupied by the Accessible at a specified row and column in the table.
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Return NULL to indicate that an empty relation set.
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
SC_DLLPUBLIC ScTable * FetchTable(SCTAB nTab)
Definition: document.cxx:2509
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:204
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
bool ExtendMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, bool bRefresh)
Definition: table2.cxx:2326
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
int nCount
OUString sName
sal_Int32 nIndex
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
sal_Int16 nId
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr OUStringLiteral STR_ACC_TABLE_DESCR
Definition: strings.hxx:17
bool hasValue()
unsigned char sal_Bool
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
@ TABLE
Definition: xmldpimp.hxx:43