update dev300-m58
[ooovba.git] / sc / source / ui / Accessibility / AccessibleCellBase.cxx
blob046b4cefa874109a689e76e5de269d8d58290a28
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: AccessibleCellBase.cxx,v $
10 * $Revision: 1.22 $
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 "AccessibleCellBase.hxx"
36 #include "attrib.hxx"
37 #include "scitems.hxx"
38 #include "miscuno.hxx"
39 #include "document.hxx"
40 #include "docfunc.hxx"
41 #include "cell.hxx"
42 #include "unoguard.hxx"
43 #include "scresid.hxx"
44 #ifndef SC_SC_HRC
45 #include "sc.hrc"
46 #endif
47 #include "unonames.hxx"
49 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
50 #include <com/sun/star/accessibility/AccessibleRole.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
53 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
54 #endif
55 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
56 #include <com/sun/star/sheet/XSpreadsheet.hpp>
57 #include <tools/debug.hxx>
58 #include <svx/brshitem.hxx>
59 #include <rtl/uuid.h>
60 #include <comphelper/sequence.hxx>
61 #include <sfx2/objsh.hxx>
63 #include <float.h>
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::accessibility;
68 //===== internal ============================================================
70 ScAccessibleCellBase::ScAccessibleCellBase(
71 const uno::Reference<XAccessible>& rxParent,
72 ScDocument* pDoc,
73 const ScAddress& rCellAddress,
74 sal_Int32 nIndex)
76 ScAccessibleContextBase(rxParent, AccessibleRole::TABLE_CELL),
77 maCellAddress(rCellAddress),
78 mpDoc(pDoc),
79 mnIndex(nIndex)
83 ScAccessibleCellBase::~ScAccessibleCellBase()
87 //===== XAccessibleComponent ============================================
89 sal_Bool SAL_CALL ScAccessibleCellBase::isVisible( )
90 throw (uno::RuntimeException)
92 ScUnoGuard aGuard;
93 IsObjectValid();
94 // test whether the cell is hidden (column/row - hidden/filtered)
95 sal_Bool bVisible(sal_True);
96 if (mpDoc)
98 bool bColHidden = mpDoc->ColHidden(maCellAddress.Col(), maCellAddress.Tab());
99 bool bRowHidden = mpDoc->RowHidden(maCellAddress.Row(), maCellAddress.Tab());
100 bool bColFiltered = mpDoc->ColFiltered(maCellAddress.Col(), maCellAddress.Tab());
101 bool bRowFiltered = mpDoc->RowFiltered(maCellAddress.Row(), maCellAddress.Tab());
103 if (bColHidden || bColFiltered || bRowHidden || bRowFiltered)
104 bVisible = sal_False;
106 return bVisible;
109 sal_Int32 SAL_CALL ScAccessibleCellBase::getForeground()
110 throw (uno::RuntimeException)
112 ScUnoGuard aGuard;
113 IsObjectValid();
114 sal_Int32 nColor(0);
115 if (mpDoc)
117 SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
118 if ( pObjSh )
120 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
121 if ( xSpreadDoc.is() )
123 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
124 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
125 if ( xIndex.is() )
127 uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
128 uno::Reference<sheet::XSpreadsheet> xTable;
129 if (aTable>>=xTable)
131 uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
132 if (xCell.is())
134 uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
135 if (xCellProps.is())
137 uno::Any aAny = xCellProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CCOLOR)));
138 aAny >>= nColor;
146 return nColor;
149 sal_Int32 SAL_CALL ScAccessibleCellBase::getBackground()
150 throw (uno::RuntimeException)
152 ScUnoGuard aGuard;
153 IsObjectValid();
154 sal_Int32 nColor(0);
156 if (mpDoc)
158 SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
159 if ( pObjSh )
161 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
162 if ( xSpreadDoc.is() )
164 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
165 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
166 if ( xIndex.is() )
168 uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
169 uno::Reference<sheet::XSpreadsheet> xTable;
170 if (aTable>>=xTable)
172 uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
173 if (xCell.is())
175 uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
176 if (xCellProps.is())
178 uno::Any aAny = xCellProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLBACK)));
179 aAny >>= nColor;
188 return nColor;
191 //===== XInterface =====================================================
193 uno::Any SAL_CALL ScAccessibleCellBase::queryInterface( uno::Type const & rType )
194 throw (uno::RuntimeException)
196 uno::Any aAny (ScAccessibleCellBaseImpl::queryInterface(rType));
197 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
200 void SAL_CALL ScAccessibleCellBase::acquire()
201 throw ()
203 ScAccessibleContextBase::acquire();
206 void SAL_CALL ScAccessibleCellBase::release()
207 throw ()
209 ScAccessibleContextBase::release();
212 //===== XAccessibleContext ==============================================
214 sal_Int32
215 ScAccessibleCellBase::getAccessibleIndexInParent(void)
216 throw (uno::RuntimeException)
218 ScUnoGuard aGuard;
219 IsObjectValid();
220 return mnIndex;
223 ::rtl::OUString SAL_CALL
224 ScAccessibleCellBase::createAccessibleDescription(void)
225 throw (uno::RuntimeException)
227 rtl::OUString sDescription = String(ScResId(STR_ACC_CELL_DESCR));
229 return sDescription;
232 ::rtl::OUString SAL_CALL
233 ScAccessibleCellBase::createAccessibleName(void)
234 throw (uno::RuntimeException)
236 String sName( ScResId(STR_ACC_CELL_NAME) );
237 String sAddress;
238 // Document not needed, because only the cell address, but not the tablename is needed
239 // always us OOO notation
240 maCellAddress.Format( sAddress, SCA_VALID, NULL );
241 sName.SearchAndReplaceAscii("%1", sAddress);
242 /* #i65103# ZoomText merges cell address and contents, e.g. if value 2 is
243 contained in cell A1, ZT reads "cell A twelve" instead of "cell A1 - 2".
244 Simple solution: Append a space character to the cell address. */
245 sName.Append( ' ' );
246 return rtl::OUString(sName);
249 //===== XAccessibleValue ================================================
251 uno::Any SAL_CALL
252 ScAccessibleCellBase::getCurrentValue( )
253 throw (uno::RuntimeException)
255 ScUnoGuard aGuard;
256 IsObjectValid();
257 uno::Any aAny;
258 if (mpDoc)
259 aAny <<= mpDoc->GetValue(maCellAddress);
261 return aAny;
264 sal_Bool SAL_CALL
265 ScAccessibleCellBase::setCurrentValue( const uno::Any& aNumber )
266 throw (uno::RuntimeException)
268 ScUnoGuard aGuard;
269 IsObjectValid();
270 double fValue = 0;
271 sal_Bool bResult(sal_False);
272 if((aNumber >>= fValue) && mpDoc && mpDoc->GetDocumentShell())
274 uno::Reference<XAccessibleStateSet> xParentStates;
275 if (getAccessibleParent().is())
277 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
278 xParentStates = xParentContext->getAccessibleStateSet();
280 if (IsEditable(xParentStates))
282 ScDocShell* pDocShell = (ScDocShell*) mpDoc->GetDocumentShell();
283 ScDocFunc aFunc(*pDocShell);
284 bResult = aFunc.PutCell( maCellAddress, new ScValueCell(fValue), TRUE );
287 return bResult;
290 uno::Any SAL_CALL
291 ScAccessibleCellBase::getMaximumValue( )
292 throw (uno::RuntimeException)
294 uno::Any aAny;
295 aAny <<= DBL_MAX;
297 return aAny;
300 uno::Any SAL_CALL
301 ScAccessibleCellBase::getMinimumValue( )
302 throw (uno::RuntimeException)
304 uno::Any aAny;
305 aAny <<= -DBL_MAX;
307 return aAny;
310 //===== XServiceInfo ====================================================
312 ::rtl::OUString SAL_CALL ScAccessibleCellBase::getImplementationName(void)
313 throw (uno::RuntimeException)
315 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleCellBase"));
318 //===== XTypeProvider ===================================================
320 uno::Sequence< uno::Type > SAL_CALL ScAccessibleCellBase::getTypes()
321 throw (uno::RuntimeException)
323 return comphelper::concatSequences(ScAccessibleCellBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
326 uno::Sequence<sal_Int8> SAL_CALL
327 ScAccessibleCellBase::getImplementationId(void)
328 throw (uno::RuntimeException)
330 ScUnoGuard aGuard;
331 IsObjectValid();
332 static uno::Sequence<sal_Int8> aId;
333 if (aId.getLength() == 0)
335 aId.realloc (16);
336 rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
338 return aId;
341 sal_Bool ScAccessibleCellBase::IsEditable(
342 const uno::Reference<XAccessibleStateSet>& rxParentStates)
344 sal_Bool bEditable(sal_False);
345 if (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::EDITABLE))
346 bEditable = sal_True;
347 return bEditable;