1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
,
42 const ScRange
& rRange
)
44 ScAccessibleContextBase (rxParent
, AccessibleRole::TABLE
),
50 ScAccessibleTableBase::~ScAccessibleTableBase()
54 void SAL_CALL
ScAccessibleTableBase::disposing()
56 SolarMutexGuard aGuard
;
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));
72 uno::Any
aAny (ScAccessibleTableBaseImpl::queryInterface(rType
));
73 return aAny
.hasValue() ? aAny
: ScAccessibleContextBase::queryInterface(rType
);
77 void SAL_CALL
ScAccessibleTableBase::acquire()
80 ScAccessibleContextBase::acquire();
83 void SAL_CALL
ScAccessibleTableBase::release()
86 ScAccessibleContextBase::release();
89 //===== XAccessibleTable ================================================
91 sal_Int32 SAL_CALL
ScAccessibleTableBase::getAccessibleRowCount( )
93 SolarMutexGuard aGuard
;
95 return maRange
.aEnd
.Row() - maRange
.aStart
.Row() + 1;
98 sal_Int32 SAL_CALL
ScAccessibleTableBase::getAccessibleColumnCount( )
100 SolarMutexGuard aGuard
;
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
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
127 sal_Int32 SAL_CALL
ScAccessibleTableBase::getAccessibleRowExtentAt( sal_Int32 nRow
, sal_Int32 nColumn
)
129 SolarMutexGuard aGuard
;
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();
142 ScTable
* pTab
= mpDoc
->FetchTable(maRange
.aStart
.Tab());
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;
160 sal_Int32 SAL_CALL
ScAccessibleTableBase::getAccessibleColumnExtentAt( sal_Int32 nRow
, sal_Int32 nColumn
)
162 SolarMutexGuard aGuard
;
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();
175 ScTable
* pTab
= mpDoc
->FetchTable(maRange
.aStart
.Tab());
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;
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");
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");
208 return xAccessibleTable
;
211 uno::Sequence
< sal_Int32
> SAL_CALL
ScAccessibleTableBase::getSelectedAccessibleRows( )
213 OSL_FAIL("not implemented yet");
214 uno::Sequence
< sal_Int32
> aSequence
;
218 uno::Sequence
< sal_Int32
> SAL_CALL
ScAccessibleTableBase::getSelectedAccessibleColumns( )
220 OSL_FAIL("not implemented yet");
221 uno::Sequence
< sal_Int32
> aSequence
;
225 sal_Bool SAL_CALL
ScAccessibleTableBase::isAccessibleRowSelected( sal_Int32
/* nRow */ )
227 OSL_FAIL("not implemented yet");
231 sal_Bool SAL_CALL
ScAccessibleTableBase::isAccessibleColumnSelected( sal_Int32
/* nColumn */ )
233 OSL_FAIL("not implemented yet");
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
;
244 uno::Reference
< XAccessible
> SAL_CALL
ScAccessibleTableBase::getAccessibleCaption( )
246 OSL_FAIL("not implemented yet");
247 uno::Reference
< XAccessible
> xAccessible
;
251 uno::Reference
< XAccessible
> SAL_CALL
ScAccessibleTableBase::getAccessibleSummary( )
253 OSL_FAIL("not implemented yet");
254 uno::Reference
< XAccessible
> xAccessible
;
258 sal_Bool SAL_CALL
ScAccessibleTableBase::isAccessibleSelected( sal_Int32
/* nRow */, sal_Int32
/* nColumn */ )
260 OSL_FAIL("not implemented yet");
264 // ===== XAccessibleExtendedTable ========================================
266 sal_Int64 SAL_CALL
ScAccessibleTableBase::getAccessibleIndex( sal_Int32 nRow
, sal_Int32 nColumn
)
268 SolarMutexGuard aGuard
;
271 if (nRow
> (maRange
.aEnd
.Row() - maRange
.aStart
.Row()) ||
273 nColumn
> (maRange
.aEnd
.Col() - maRange
.aStart
.Col()) ||
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
;
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
;
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
;
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);
320 uno::Reference
< XAccessible
> SAL_CALL
321 ScAccessibleTableBase::getAccessibleChild(sal_Int64 nIndex
)
323 SolarMutexGuard aGuard
;
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.
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
);
341 ScAccessibleTableBase::createAccessibleDescription()
343 return STR_ACC_TABLE_DESCR
;
346 OUString
ScAccessibleTableBase::createAccessibleName()
348 OUString
sName(ScResId(STR_ACC_TABLE_NAME
));
350 if (mpDoc
&& mpDoc
->GetName( maRange
.aStart
.Tab(), sCoreName
))
351 sName
= sName
.replaceFirst("%1", sCoreName
);
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");
368 ///===== XAccessibleSelection ===========================================
370 void SAL_CALL
ScAccessibleTableBase::selectAccessibleChild( sal_Int64
/* nChildIndex */ )
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
));
384 ScAccessibleTableBase::clearAccessibleSelection( )
388 void SAL_CALL
ScAccessibleTableBase::selectAllAccessibleChildren()
393 ScAccessibleTableBase::getSelectedAccessibleChildCount( )
398 uno::Reference
<XAccessible
> SAL_CALL
399 ScAccessibleTableBase::getSelectedAccessibleChild( sal_Int64
/* nSelectedChildIndex */ )
401 uno::Reference
< XAccessible
> 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
)
451 sal_Bool SAL_CALL
ScAccessibleTableBase::selectColumn( sal_Int32
)
456 sal_Bool SAL_CALL
ScAccessibleTableBase::unselectRow( sal_Int32
)
461 sal_Bool SAL_CALL
ScAccessibleTableBase::unselectColumn( sal_Int32
)
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */