Update ooo320-m1
[ooovba.git] / sc / source / ui / Accessibility / AccessibleTableBase.cxx
blob188257e1edb48f644d7ffa2782a898f947e5693e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleTableBase.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include "AccessibleTableBase.hxx"
36 #include "miscuno.hxx"
37 #include "document.hxx"
38 #include "unoguard.hxx"
39 #include "scresid.hxx"
40 #ifndef SC_SC_HRC
41 #include "sc.hrc"
42 #endif
44 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
45 #include <com/sun/star/accessibility/AccessibleRole.hpp>
46 #endif
47 #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
48 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
49 #include <rtl/uuid.h>
50 #include <tools/debug.hxx>
51 #include <comphelper/sequence.hxx>
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::accessibility;
57 //===== internal ============================================================
59 ScAccessibleTableBase::ScAccessibleTableBase(
60 const uno::Reference<XAccessible>& rxParent,
61 ScDocument* pDoc,
62 const ScRange& rRange)
64 ScAccessibleContextBase (rxParent, AccessibleRole::TABLE),
65 maRange(rRange),
66 mpDoc(pDoc)
70 ScAccessibleTableBase::~ScAccessibleTableBase()
74 void SAL_CALL ScAccessibleTableBase::disposing()
76 ScUnoGuard aGuard;
77 mpDoc = NULL;
79 ScAccessibleContextBase::disposing();
82 //===== XInterface =====================================================
84 uno::Any SAL_CALL ScAccessibleTableBase::queryInterface( uno::Type const & rType )
85 throw (uno::RuntimeException)
87 uno::Any aAny (ScAccessibleTableBaseImpl::queryInterface(rType));
88 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
91 void SAL_CALL ScAccessibleTableBase::acquire()
92 throw ()
94 ScAccessibleContextBase::acquire();
97 void SAL_CALL ScAccessibleTableBase::release()
98 throw ()
100 ScAccessibleContextBase::release();
103 //===== XAccessibleTable ================================================
105 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowCount( )
106 throw (uno::RuntimeException)
108 ScUnoGuard aGuard;
109 IsObjectValid();
110 return maRange.aEnd.Row() - maRange.aStart.Row() + 1;
113 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnCount( )
114 throw (uno::RuntimeException)
116 ScUnoGuard aGuard;
117 IsObjectValid();
118 return maRange.aEnd.Col() - maRange.aStart.Col() + 1;
121 ::rtl::OUString SAL_CALL ScAccessibleTableBase::getAccessibleRowDescription( sal_Int32 nRow )
122 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
124 DBG_ERROR("Here should be a implementation to fill the description");
126 if ((nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
127 throw lang::IndexOutOfBoundsException();
129 //setAccessibleRowDescription(nRow, xAccessible); // to remember the created Description
130 return rtl::OUString();
133 ::rtl::OUString SAL_CALL ScAccessibleTableBase::getAccessibleColumnDescription( sal_Int32 nColumn )
134 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
136 DBG_ERROR("Here should be a implementation to fill the description");
138 if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0))
139 throw lang::IndexOutOfBoundsException();
141 //setAccessibleColumnDescription(nColumn, xAccessible); // to remember the created Description
142 return rtl::OUString();
145 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
146 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
148 ScUnoGuard aGuard;
149 IsObjectValid();
151 if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0) ||
152 (nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
153 throw lang::IndexOutOfBoundsException();
155 sal_Int32 nCount(1); // the same cell
156 nRow += maRange.aStart.Row();
157 nColumn += maRange.aStart.Col();
159 if (mpDoc)
161 SCROW nEndRow(0);
162 SCCOL nEndCol(0);
163 if (mpDoc->ExtendMerge(static_cast<SCCOL>(nColumn), static_cast<SCROW>(nRow),
164 nEndCol, nEndRow, maRange.aStart.Tab()))
166 if (nEndRow > nRow)
167 nCount = nEndRow - nRow + 1;
171 return nCount;
174 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
175 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
177 ScUnoGuard aGuard;
178 IsObjectValid();
180 if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0) ||
181 (nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
182 throw lang::IndexOutOfBoundsException();
184 sal_Int32 nCount(1); // the same cell
185 nRow += maRange.aStart.Row();
186 nColumn += maRange.aStart.Col();
188 if (mpDoc)
190 SCROW nEndRow(0);
191 SCCOL nEndCol(0);
192 if (mpDoc->ExtendMerge(static_cast<SCCOL>(nColumn), static_cast<SCROW>(nRow),
193 nEndCol, nEndRow, maRange.aStart.Tab()))
195 if (nEndCol > nColumn)
196 nCount = nEndCol - nColumn + 1;
200 return nCount;
203 uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleRowHeaders( )
204 throw (uno::RuntimeException)
206 uno::Reference< XAccessibleTable > xAccessibleTable;
207 DBG_ERROR("Here should be a implementation to fill the row headers");
209 //CommitChange
210 return xAccessibleTable;
213 uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleTableBase::getAccessibleColumnHeaders( )
214 throw (uno::RuntimeException)
216 uno::Reference< XAccessibleTable > xAccessibleTable;
217 DBG_ERROR("Here should be a implementation to fill the column headers");
219 //CommitChange
220 return xAccessibleTable;
223 uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleRows( )
224 throw (uno::RuntimeException)
226 DBG_ERROR("not implemented yet");
227 uno::Sequence< sal_Int32 > aSequence;
228 return aSequence;
231 uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleTableBase::getSelectedAccessibleColumns( )
232 throw (uno::RuntimeException)
234 DBG_ERROR("not implemented yet");
235 uno::Sequence< sal_Int32 > aSequence;
236 return aSequence;
239 sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleRowSelected( sal_Int32 /* nRow */ )
240 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
242 DBG_ERROR("not implemented yet");
243 return sal_False;
246 sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleColumnSelected( sal_Int32 /* nColumn */ )
247 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
249 DBG_ERROR("not implemented yet");
250 return sal_False;
253 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCellAt( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
254 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
256 DBG_ERROR("not implemented yet");
257 uno::Reference< XAccessible > xAccessible;
258 return xAccessible;
261 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleCaption( )
262 throw (uno::RuntimeException)
264 DBG_ERROR("not implemented yet");
265 uno::Reference< XAccessible > xAccessible;
266 return xAccessible;
269 uno::Reference< XAccessible > SAL_CALL ScAccessibleTableBase::getAccessibleSummary( )
270 throw (uno::RuntimeException)
272 DBG_ERROR("not implemented yet");
273 uno::Reference< XAccessible > xAccessible;
274 return xAccessible;
277 sal_Bool SAL_CALL ScAccessibleTableBase::isAccessibleSelected( sal_Int32 /* nRow */, sal_Int32 /* nColumn */ )
278 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
280 DBG_ERROR("not implemented yet");
281 return sal_False;
284 //===== XAccessibleExtendedTable ========================================
286 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
287 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
289 ScUnoGuard aGuard;
290 IsObjectValid();
292 if (nRow > (maRange.aEnd.Row() - maRange.aStart.Row()) ||
293 nRow < 0 ||
294 nColumn > (maRange.aEnd.Col() - maRange.aStart.Col()) ||
295 nColumn < 0)
296 throw lang::IndexOutOfBoundsException();
298 nRow -= maRange.aStart.Row();
299 nColumn -= maRange.aStart.Col();
300 return (nRow * (maRange.aEnd.Col() + 1)) + nColumn;
303 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleRow( sal_Int32 nChildIndex )
304 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
306 ScUnoGuard aGuard;
307 IsObjectValid();
309 if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
310 throw lang::IndexOutOfBoundsException();
312 return nChildIndex / (maRange.aEnd.Col() - maRange.aStart.Col() + 1);
315 sal_Int32 SAL_CALL ScAccessibleTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
316 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
318 ScUnoGuard aGuard;
319 IsObjectValid();
321 if (nChildIndex >= getAccessibleChildCount() || nChildIndex < 0)
322 throw lang::IndexOutOfBoundsException();
324 return nChildIndex % static_cast<sal_Int32>(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
327 //===== XAccessibleContext ==============================================
329 sal_Int32 SAL_CALL
330 ScAccessibleTableBase::getAccessibleChildCount(void)
331 throw (uno::RuntimeException)
333 ScUnoGuard aGuard;
334 IsObjectValid();
335 return static_cast<sal_Int32>(maRange.aEnd.Row() - maRange.aStart.Row() + 1) *
336 (maRange.aEnd.Col() - maRange.aStart.Col() + 1);
337 // return 1;
340 uno::Reference< XAccessible > SAL_CALL
341 ScAccessibleTableBase::getAccessibleChild(sal_Int32 nIndex)
342 throw (uno::RuntimeException,
343 lang::IndexOutOfBoundsException)
345 ScUnoGuard aGuard;
346 IsObjectValid();
348 if (nIndex >= getAccessibleChildCount() || nIndex < 0)
349 throw lang::IndexOutOfBoundsException();
351 sal_Int32 nRow(0);
352 sal_Int32 nColumn(0);
353 sal_Int32 nTemp(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
354 nRow = nIndex / nTemp;
355 nColumn = nIndex % nTemp;
356 return getAccessibleCellAt(nRow, nColumn);
359 ::rtl::OUString SAL_CALL
360 ScAccessibleTableBase::createAccessibleDescription(void)
361 throw (uno::RuntimeException)
363 String sDesc(ScResId(STR_ACC_TABLE_DESCR));
364 /* String sCoreName;
365 if (mpDoc && mpDoc->GetName( maRange.aStart.Tab(), sCoreName ))
366 sDesc.SearchAndReplaceAscii("%1", sCoreName);
367 sDesc.SearchAndReplaceAscii("%2", String(ScResId(SCSTR_UNKNOWN)));*/
368 return rtl::OUString(sDesc);
371 ::rtl::OUString SAL_CALL
372 ScAccessibleTableBase::createAccessibleName(void)
373 throw (uno::RuntimeException)
375 String sName(ScResId(STR_ACC_TABLE_NAME));
376 String sCoreName;
377 if (mpDoc && mpDoc->GetName( maRange.aStart.Tab(), sCoreName ))
378 sName.SearchAndReplaceAscii("%1", sCoreName);
379 return rtl::OUString(sName);
382 uno::Reference<XAccessibleRelationSet> SAL_CALL
383 ScAccessibleTableBase::getAccessibleRelationSet(void)
384 throw (uno::RuntimeException)
386 DBG_ERROR("should be implemented in the abrevated class");
387 return uno::Reference<XAccessibleRelationSet>();
390 uno::Reference<XAccessibleStateSet> SAL_CALL
391 ScAccessibleTableBase::getAccessibleStateSet(void)
392 throw (uno::RuntimeException)
394 DBG_ERROR("should be implemented in the abrevated class");
395 uno::Reference< XAccessibleStateSet > xAccessibleStateSet;
396 return xAccessibleStateSet;
399 ///===== XAccessibleSelection ===========================================
401 void SAL_CALL
402 ScAccessibleTableBase::selectAccessibleChild( sal_Int32 /* nChildIndex */ )
403 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
407 sal_Bool SAL_CALL
408 ScAccessibleTableBase::isAccessibleChildSelected( sal_Int32 nChildIndex )
409 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
411 // I don't need to guard, because the called funtions have a guard
412 // ScUnoGuard aGuard;
413 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
414 throw lang::IndexOutOfBoundsException();
415 return isAccessibleSelected(getAccessibleRow(nChildIndex), getAccessibleColumn(nChildIndex));
418 void SAL_CALL
419 ScAccessibleTableBase::clearAccessibleSelection( )
420 throw (uno::RuntimeException)
424 void SAL_CALL
425 ScAccessibleTableBase::selectAllAccessibleChildren( )
426 throw (uno::RuntimeException)
430 sal_Int32 SAL_CALL
431 ScAccessibleTableBase::getSelectedAccessibleChildCount( )
432 throw (uno::RuntimeException)
434 sal_Int32 nResult(0);
435 return nResult;
438 uno::Reference<XAccessible > SAL_CALL
439 ScAccessibleTableBase::getSelectedAccessibleChild( sal_Int32 /* nSelectedChildIndex */ )
440 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
442 uno::Reference < XAccessible > xAccessible;
443 return xAccessible;
446 void SAL_CALL
447 ScAccessibleTableBase::deselectAccessibleChild( sal_Int32 /* nSelectedChildIndex */ )
448 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
452 //===== XServiceInfo ====================================================
454 ::rtl::OUString SAL_CALL ScAccessibleTableBase::getImplementationName(void)
455 throw (uno::RuntimeException)
457 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleTableBase"));
460 //===== XTypeProvider ===================================================
462 uno::Sequence< uno::Type > SAL_CALL ScAccessibleTableBase::getTypes()
463 throw (uno::RuntimeException)
465 return comphelper::concatSequences(ScAccessibleTableBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
468 uno::Sequence<sal_Int8> SAL_CALL
469 ScAccessibleTableBase::getImplementationId(void)
470 throw (uno::RuntimeException)
472 ScUnoGuard aGuard;
473 IsObjectValid();
474 static uno::Sequence<sal_Int8> aId;
475 if (aId.getLength() == 0)
477 aId.realloc (16);
478 rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
480 return aId;
483 void ScAccessibleTableBase::CommitTableModelChange(sal_Int32 nStartRow, sal_Int32 nStartCol, sal_Int32 nEndRow, sal_Int32 nEndCol, sal_uInt16 nId)
485 AccessibleTableModelChange aModelChange;
486 aModelChange.FirstRow = nStartRow;
487 aModelChange.FirstColumn = nStartCol;
488 aModelChange.LastRow = nEndRow;
489 aModelChange.LastColumn = nEndCol;
490 aModelChange.Type = nId;
492 AccessibleEventObject aEvent;
493 aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
494 aEvent.Source = uno::Reference< XAccessibleContext >(this);
495 aEvent.NewValue <<= aModelChange;
497 CommitChange(aEvent);