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 
20 #include <AccessibleTableBase.hxx>
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>
31 #include <comphelper/sequence.hxx>
32 #include <vcl/svapp.hxx>
33 
34 using namespace ::com::sun::star;
35 using 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  throw ()
79 {
81 }
82 
84  throw ()
85 {
87 }
88 
89  //===== XAccessibleTable ================================================
90 
92 {
93  SolarMutexGuard aGuard;
94  IsObjectValid();
95  return maRange.aEnd.Row() - maRange.aStart.Row() + 1;
96 }
97 
99 {
100  SolarMutexGuard aGuard;
101  IsObjectValid();
102  return maRange.aEnd.Col() - maRange.aStart.Col() + 1;
103 }
104 
105 OUString 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 
116 OUString 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 
127 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
128 {
129  SolarMutexGuard aGuard;
130  IsObjectValid();
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 
160 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
161 {
162  SolarMutexGuard aGuard;
163  IsObjectValid();
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 
193 uno::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 
202 uno::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 
211 uno::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 
218 uno::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 
237 uno::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 
244 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCaption( )
245 {
246  OSL_FAIL("not implemented yet");
247  uno::Reference< XAccessible > xAccessible;
248  return xAccessible;
249 }
250 
251 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleSummary( )
252 {
253  OSL_FAIL("not implemented yet");
254  uno::Reference< XAccessible > xAccessible;
255  return xAccessible;
256 }
257 
258 sal_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 
266 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
267 {
268  SolarMutexGuard aGuard;
269  IsObjectValid();
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 (nRow * (maRange.aEnd.Col() + 1)) + nColumn;
280 }
281 
282 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRow( sal_Int32 nChildIndex )
283 {
284  SolarMutexGuard aGuard;
285  IsObjectValid();
286 
287  if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
288  throw lang::IndexOutOfBoundsException();
289 
290  return nChildIndex / (maRange.aEnd.Col() - maRange.aStart.Col() + 1);
291 }
292 
293 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
294 {
295  SolarMutexGuard aGuard;
296  IsObjectValid();
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;
309  IsObjectValid();
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 > SAL_MAX_INT32)
316  nMax = SAL_MAX_INT32;
317  if (nMax < 0)
318  return 0;
319  return static_cast<sal_Int32>(nMax);
320 }
321 
322 uno::Reference< XAccessible > SAL_CALL
324 {
325  SolarMutexGuard aGuard;
326  IsObjectValid();
327 
328  if (nIndex >= getAccessibleChildCount() || nIndex < 0)
329  throw lang::IndexOutOfBoundsException();
330 
331  // FIXME: representing rows & columns this way is a plain and simple madness.
332  // this needs a radical re-think.
333 
334  sal_Int32 nRow(0);
335  sal_Int32 nColumn(0);
336  sal_Int32 nTemp(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
337  nRow = nIndex / nTemp;
338  nColumn = nIndex % nTemp;
339  return getAccessibleCellAt(nRow, nColumn);
340 }
341 
342 OUString
344 {
345  return STR_ACC_TABLE_DESCR;
346 }
347 
349 {
350  OUString sName(ScResId(STR_ACC_TABLE_NAME));
351  OUString sCoreName;
352  if (mpDoc && mpDoc->GetName( maRange.aStart.Tab(), sCoreName ))
353  sName = sName.replaceFirst("%1", sCoreName);
354  return sName;
355 }
356 
357 uno::Reference<XAccessibleRelationSet> SAL_CALL
359 {
360  OSL_FAIL("should be implemented in the abrevated class");
361  return uno::Reference<XAccessibleRelationSet>();
362 }
363 
364 uno::Reference<XAccessibleStateSet> SAL_CALL
366 {
367  OSL_FAIL("should be implemented in the abrevated class");
368  uno::Reference< XAccessibleStateSet > xAccessibleStateSet;
369  return xAccessibleStateSet;
370 }
371 
373 
374 void SAL_CALL ScAccessibleTableBase::selectAccessibleChild( sal_Int32 /* nChildIndex */ )
375 {
376 }
377 
378 sal_Bool SAL_CALL
380 {
381  // I don't need to guard, because the called functions have a guard
382  if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
383  throw lang::IndexOutOfBoundsException();
384  return isAccessibleSelected(getAccessibleRow(nChildIndex), getAccessibleColumn(nChildIndex));
385 }
386 
387 void SAL_CALL
389 {
390 }
391 
393 {
394 }
395 
396 sal_Int32 SAL_CALL
398 {
399  return 0;
400 }
401 
402 uno::Reference<XAccessible > SAL_CALL
403  ScAccessibleTableBase::getSelectedAccessibleChild( sal_Int32 /* nSelectedChildIndex */ )
404 {
405  uno::Reference < XAccessible > xAccessible;
406  return xAccessible;
407 }
408 
409 void SAL_CALL ScAccessibleTableBase::deselectAccessibleChild( sal_Int32 /* nSelectedChildIndex */ )
410 {
411 }
412 
413  //===== XServiceInfo ====================================================
414 
416 {
417  return "ScAccessibleTableBase";
418 }
419 
420  //===== XTypeProvider ===================================================
421 
422 uno::Sequence< uno::Type > SAL_CALL ScAccessibleTableBase::getTypes()
423 {
425 }
426 
427 uno::Sequence<sal_Int8> SAL_CALL
429 {
430  return css::uno::Sequence<sal_Int8>();
431 }
432 
433 void ScAccessibleTableBase::CommitTableModelChange(sal_Int32 nStartRow, sal_Int32 nStartCol, sal_Int32 nEndRow, sal_Int32 nEndCol, sal_uInt16 nId)
434 {
435  AccessibleTableModelChange aModelChange;
436  aModelChange.FirstRow = nStartRow;
437  aModelChange.FirstColumn = nStartCol;
438  aModelChange.LastRow = nEndRow;
439  aModelChange.LastColumn = nEndCol;
440  aModelChange.Type = nId;
441 
442  AccessibleEventObject aEvent;
443  aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
444  aEvent.Source = uno::Reference< XAccessibleContext >(this);
445  aEvent.NewValue <<= aModelChange;
446 
447  CommitChange(aEvent);
448 }
449 
451 {
452  return true;
453 }
454 
456 {
457  return true;
458 }
459 
461 {
462  return true;
463 }
464 
466 {
467  return true;
468 }
469 
470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL release() override
virtual OUString createAccessibleDescription() override
Return this object's description.
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 sal_Int32 SAL_CALL getAccessibleChildCount() override
Return the number of currently visible children.
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual void SAL_CALL selectAllAccessibleChildren() override
bool hasValue()
ScAddress aStart
Definition: address.hxx:500
virtual void SAL_CALL acquire() override
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
SCROW Row() const
Definition: address.hxx:262
virtual OUString SAL_CALL getAccessibleRowDescription(sal_Int32 nRow) override
Returns the description of the specified row in the table.
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ===================================================
ScTable * FetchTable(SCTAB nTab)
Definition: document.cxx:2508
virtual OUString SAL_CALL getAccessibleColumnDescription(sal_Int32 nColumn) override
Returns the description text of the specified column in the table.
virtual sal_Bool SAL_CALL unselectColumn(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getAccessibleRowCount() override
===== XAccessibleTable ================================================
virtual sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int32 nChildIndex) override
ScAddress aEnd
Definition: address.hxx:501
virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount() override
virtual void SAL_CALL clearAccessibleSelection() override
virtual sal_Int32 SAL_CALL getAccessibleColumnCount() override
Returns the number of columns in the table.
virtual void SAL_CALL release() override
virtual void SAL_CALL selectAccessibleChild(sal_Int32 nChildIndex) override
===== XAccessibleSelection ===========================================
#define STR_ACC_TABLE_DESCR
Definition: strings.hxx:15
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleCaption() override
Returns the caption for the table.
virtual sal_Int32 SAL_CALL getAccessibleColumn(sal_Int32 nChildIndex) override
Returns the column number of an index in the table.
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Returns an implementation id.
virtual sal_Bool SAL_CALL selectRow(sal_Int32 row) override
int nCount
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
===== XTypeProvider ===================================================
SCTAB Tab() const
Definition: address.hxx:271
const char * sName
virtual ~ScAccessibleTableBase() override
void CommitTableModelChange(sal_Int32 nStartRow, sal_Int32 nStartCol, sal_Int32 nEndRow, sal_Int32 nEndCol, sal_uInt16 nId)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
#define SAL_MAX_INT32
virtual sal_Bool SAL_CALL isAccessibleRowSelected(sal_Int32 nRow) override
Returns a boolean value indicating whether the specified row is selected.
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
===== XTypeProvider ===================================================
virtual css::uno::Reference< css::accessibility::XAccessibleTable > SAL_CALL getAccessibleRowHeaders() override
Returns the row headers as an AccessibleTable.
sal_Int16 SCCOL
Definition: types.hxx:22
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 nIndex) override
Return the specified child or NULL if index is invalid.
virtual void SAL_CALL disposing() override
unsigned char sal_Bool
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
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::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Return NULL to indicate that an empty relation set.
virtual sal_Bool SAL_CALL selectColumn(sal_Int32 column) override
virtual void SAL_CALL deselectAccessibleChild(sal_Int32 nSelectedChildIndex) override
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 void SAL_CALL acquire() override
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
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...
SCCOL Col() const
Definition: address.hxx:267
virtual sal_Int32 SAL_CALL getAccessibleRow(sal_Int32 nChildIndex) override
Returns the row number of an index in the table.
sal_Int32 SCROW
Definition: types.hxx:18
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleSummary() override
Returns the summary description of 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 OUString createAccessibleName() override
Return the object's current name.
virtual sal_Int32 SAL_CALL getAccessibleIndex(sal_Int32 nRow, sal_Int32 nColumn) override
===== XAccessibleExtendedTable ========================================
void CommitChange(const css::accessibility::AccessibleEventObject &rEvent) const
Calls all Listener to tell they the change.
bool ExtendMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, bool bRefresh)
Definition: table2.cxx:2098
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
Return the set of current states.
virtual sal_Bool SAL_CALL unselectRow(sal_Int32 row) override
virtual css::uno::Reference< css::accessibility::XAccessibleTable > SAL_CALL getAccessibleColumnHeaders() override
Returns the column headers as an AccessibleTable.
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:213
virtual css::uno::Sequence< sal_Int32 > SAL_CALL getSelectedAccessibleColumns() override
Returns the selected columns in a table.
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...
AnyEventRef aEvent
B2DRange maRange
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 getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex) override