tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / Accessibility / AccessibleTableBase.cxx
blob993370ccc5a8c480535906383839d36644aae245
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <AccessibleTableBase.hxx>
21 #include <document.hxx>
22 #include <scresid.hxx>
23 #include <strings.hrc>
24 #include <strings.hxx>
25 #include <table.hxx>
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>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::accessibility;
37 //===== internal ============================================================
39 ScAccessibleTableBase::ScAccessibleTableBase(
40 const uno::Reference<XAccessible>& rxParent,
41 ScDocument* pDoc,
42 const ScRange& rRange)
44 ScAccessibleContextBase (rxParent, AccessibleRole::TABLE),
45 maRange(rRange),
46 mpDoc(pDoc)
50 ScAccessibleTableBase::~ScAccessibleTableBase()
54 void SAL_CALL ScAccessibleTableBase::disposing()
56 SolarMutexGuard aGuard;
57 mpDoc = nullptr;
59 ScAccessibleContextBase::disposing();
62 //===== XInterface =====================================================
64 uno::Any SAL_CALL ScAccessibleTableBase::queryInterface( uno::Type const & rType )
66 if ( rType == cppu::UnoType<XAccessibleTableSelection>::get())
68 return uno::Any(uno::Reference<XAccessibleTableSelection>(this));
70 else
72 uno::Any aAny (ScAccessibleTableBaseImpl::queryInterface(rType));
73 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
77 void SAL_CALL ScAccessibleTableBase::acquire()
78 noexcept
80 ScAccessibleContextBase::acquire();
83 void SAL_CALL ScAccessibleTableBase::release()
84 noexcept
86 ScAccessibleContextBase::release();
89 //===== XAccessibleTable ================================================
91 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowCount( )
93 SolarMutexGuard aGuard;
94 IsObjectValid();
95 return maRange.aEnd.Row() - maRange.aStart.Row() + 1;
98 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnCount( )
100 SolarMutexGuard aGuard;
101 IsObjectValid();
102 return maRange.aEnd.Col() - maRange.aStart.Col() + 1;
105 OUString SAL_CALL ScAccessibleTableBase::getAccessibleRowDescription( sal_Int32 nRow )
107 OSL_FAIL("Here should be an implementation to fill the description");
109 if ((nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
110 throw lang::IndexOutOfBoundsException();
112 //setAccessibleRowDescription(nRow, xAccessible); // to remember the created Description
113 return OUString();
116 OUString SAL_CALL ScAccessibleTableBase::getAccessibleColumnDescription( sal_Int32 nColumn )
118 OSL_FAIL("Here should be an implementation to fill the description");
120 if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0))
121 throw lang::IndexOutOfBoundsException();
123 //setAccessibleColumnDescription(nColumn, xAccessible); // to remember the created Description
124 return OUString();
127 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
129 SolarMutexGuard aGuard;
130 IsObjectValid();
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();
136 sal_Int32 nCount(1); // the same cell
137 nRow += maRange.aStart.Row();
138 nColumn += maRange.aStart.Col();
140 if (mpDoc)
142 ScTable* pTab = mpDoc->FetchTable(maRange.aStart.Tab());
143 if (pTab)
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))
151 if (nEndRow > nStartRow)
152 nCount = nEndRow - nStartRow + 1;
157 return nCount;
160 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
162 SolarMutexGuard aGuard;
163 IsObjectValid();
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();
169 sal_Int32 nCount(1); // the same cell
170 nRow += maRange.aStart.Row();
171 nColumn += maRange.aStart.Col();
173 if (mpDoc)
175 ScTable* pTab = mpDoc->FetchTable(maRange.aStart.Tab());
176 if (pTab)
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))
184 if (nEndCol > nStartCol)
185 nCount = nEndCol - nStartCol + 1;
190 return nCount;
193 uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleRowHeaders( )
195 uno::Reference< XAccessibleTable > xAccessibleTable;
196 OSL_FAIL("Here should be an implementation to fill the row headers");
198 //CommitChange
199 return xAccessibleTable;
202 uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleColumnHeaders( )
204 uno::Reference< XAccessibleTable > xAccessibleTable;
205 OSL_FAIL("Here should be an implementation to fill the column headers");
207 //CommitChange
208 return xAccessibleTable;
211 uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleRows( )
213 OSL_FAIL("not implemented yet");
214 uno::Sequence< sal_Int32 > aSequence;
215 return aSequence;
218 uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleColumns( )
220 OSL_FAIL("not implemented yet");
221 uno::Sequence< sal_Int32 > aSequence;
222 return aSequence;
225 sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleRowSelected( sal_Int32 /* nRow */ )
227 OSL_FAIL("not implemented yet");
228 return false;
231 sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleColumnSelected( sal_Int32 /* nColumn */ )
233 OSL_FAIL("not implemented yet");
234 return false;
237 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCellAt( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
239 OSL_FAIL("not implemented yet");
240 uno::Reference< XAccessible > xAccessible;
241 return xAccessible;
244 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCaption( )
246 OSL_FAIL("not implemented yet");
247 uno::Reference< XAccessible > xAccessible;
248 return xAccessible;
251 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleSummary( )
253 OSL_FAIL("not implemented yet");
254 uno::Reference< XAccessible > xAccessible;
255 return xAccessible;
258 sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleSelected( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
260 OSL_FAIL("not implemented yet");
261 return false;
264 // ===== XAccessibleExtendedTable ========================================
266 sal_Int64 SAL_CALL ScAccessibleTableBase::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
268 SolarMutexGuard aGuard;
269 IsObjectValid();
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();
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;
282 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRow( sal_Int64 nChildIndex )
284 SolarMutexGuard aGuard;
285 IsObjectValid();
287 if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
288 throw lang::IndexOutOfBoundsException();
290 return nChildIndex / (maRange.aEnd.Col() - maRange.aStart.Col() + 1);
293 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumn( sal_Int64 nChildIndex )
295 SolarMutexGuard aGuard;
296 IsObjectValid();
298 if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
299 throw lang::IndexOutOfBoundsException();
301 return nChildIndex % static_cast<sal_Int32>(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
304 // ===== XAccessibleContext ==============================================
306 sal_Int64 SAL_CALL ScAccessibleTableBase::getAccessibleChildCount()
308 SolarMutexGuard aGuard;
309 IsObjectValid();
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;
320 uno::Reference< XAccessible > SAL_CALL
321 ScAccessibleTableBase::getAccessibleChild(sal_Int64 nIndex)
323 SolarMutexGuard aGuard;
324 IsObjectValid();
326 if (nIndex >= getAccessibleChildCount() || nIndex < 0)
327 throw lang::IndexOutOfBoundsException();
329 // FIXME: representing rows & columns this way is a plain and simple madness.
330 // this needs a radical re-think.
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);
340 OUString
341 ScAccessibleTableBase::createAccessibleDescription()
343 return STR_ACC_TABLE_DESCR;
346 OUString ScAccessibleTableBase::createAccessibleName()
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;
355 uno::Reference<XAccessibleRelationSet> SAL_CALL
356 ScAccessibleTableBase::getAccessibleRelationSet()
358 OSL_FAIL("should be implemented in the abrevated class");
359 return uno::Reference<XAccessibleRelationSet>();
362 sal_Int64 SAL_CALL ScAccessibleTableBase::getAccessibleStateSet()
364 OSL_FAIL("should be implemented in the abrevated class");
365 return 0;
368 ///===== XAccessibleSelection ===========================================
370 void SAL_CALL ScAccessibleTableBase::selectAccessibleChild( sal_Int64 /* nChildIndex */ )
374 sal_Bool SAL_CALL
375 ScAccessibleTableBase::isAccessibleChildSelected( sal_Int64 nChildIndex )
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));
383 void SAL_CALL
384 ScAccessibleTableBase::clearAccessibleSelection( )
388 void SAL_CALL ScAccessibleTableBase::selectAllAccessibleChildren()
392 sal_Int64 SAL_CALL
393 ScAccessibleTableBase::getSelectedAccessibleChildCount( )
395 return 0;
398 uno::Reference<XAccessible > SAL_CALL
399 ScAccessibleTableBase::getSelectedAccessibleChild( sal_Int64 /* nSelectedChildIndex */ )
401 uno::Reference < XAccessible > xAccessible;
402 return xAccessible;
405 void SAL_CALL ScAccessibleTableBase::deselectAccessibleChild( sal_Int64 /* nSelectedChildIndex */ )
409 //===== XServiceInfo ====================================================
411 OUString SAL_CALL ScAccessibleTableBase::getImplementationName()
413 return u"ScAccessibleTableBase"_ustr;
416 //===== XTypeProvider ===================================================
418 uno::Sequence< uno::Type > SAL_CALL ScAccessibleTableBase::getTypes()
420 return comphelper::concatSequences(ScAccessibleTableBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
423 uno::Sequence<sal_Int8> SAL_CALL
424 ScAccessibleTableBase::getImplementationId()
426 return css::uno::Sequence<sal_Int8>();
429 void ScAccessibleTableBase::CommitTableModelChange(sal_Int32 nStartRow, sal_Int32 nStartCol, sal_Int32 nEndRow, sal_Int32 nEndCol, sal_uInt16 nId)
431 AccessibleTableModelChange aModelChange;
432 aModelChange.FirstRow = nStartRow;
433 aModelChange.FirstColumn = nStartCol;
434 aModelChange.LastRow = nEndRow;
435 aModelChange.LastColumn = nEndCol;
436 aModelChange.Type = nId;
438 AccessibleEventObject aEvent;
439 aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
440 aEvent.Source = uno::Reference< XAccessibleContext >(this);
441 aEvent.NewValue <<= aModelChange;
443 CommitChange(aEvent);
446 sal_Bool SAL_CALL ScAccessibleTableBase::selectRow( sal_Int32 )
448 return true;
451 sal_Bool SAL_CALL ScAccessibleTableBase::selectColumn( sal_Int32 )
453 return true;
456 sal_Bool SAL_CALL ScAccessibleTableBase::unselectRow( sal_Int32 )
458 return true;
461 sal_Bool SAL_CALL ScAccessibleTableBase::unselectColumn( sal_Int32 )
463 return true;
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */