xref: /AOO41X/main/sc/source/ui/Accessibility/AccessibleCellBase.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "AccessibleCellBase.hxx"
33*cdf0e10cSrcweir #include "attrib.hxx"
34*cdf0e10cSrcweir #include "scitems.hxx"
35*cdf0e10cSrcweir #include "miscuno.hxx"
36*cdf0e10cSrcweir #include "document.hxx"
37*cdf0e10cSrcweir #include "docfunc.hxx"
38*cdf0e10cSrcweir #include "cell.hxx"
39*cdf0e10cSrcweir #include "unoguard.hxx"
40*cdf0e10cSrcweir #include "scresid.hxx"
41*cdf0e10cSrcweir #ifndef SC_SC_HRC
42*cdf0e10cSrcweir #include "sc.hrc"
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir #include "unonames.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
47*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
50*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheet.hpp>
54*cdf0e10cSrcweir #include <tools/debug.hxx>
55*cdf0e10cSrcweir #include <editeng/brshitem.hxx>
56*cdf0e10cSrcweir #include <rtl/uuid.h>
57*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
58*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #include <float.h>
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir using namespace	::com::sun::star;
63*cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir //=====  internal  ============================================================
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir ScAccessibleCellBase::ScAccessibleCellBase(
68*cdf0e10cSrcweir         const uno::Reference<XAccessible>& rxParent,
69*cdf0e10cSrcweir 		ScDocument* pDoc,
70*cdf0e10cSrcweir 		const ScAddress& rCellAddress,
71*cdf0e10cSrcweir 		sal_Int32 nIndex)
72*cdf0e10cSrcweir 	:
73*cdf0e10cSrcweir 	ScAccessibleContextBase(rxParent, AccessibleRole::TABLE_CELL),
74*cdf0e10cSrcweir 	maCellAddress(rCellAddress),
75*cdf0e10cSrcweir 	mpDoc(pDoc),
76*cdf0e10cSrcweir 	mnIndex(nIndex)
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir ScAccessibleCellBase::~ScAccessibleCellBase()
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	//=====  XAccessibleComponent  ============================================
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir sal_Bool SAL_CALL ScAccessibleCellBase::isVisible(  )
87*cdf0e10cSrcweir 		throw (uno::RuntimeException)
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir  	ScUnoGuard aGuard;
90*cdf0e10cSrcweir     IsObjectValid();
91*cdf0e10cSrcweir 	// test whether the cell is hidden (column/row - hidden/filtered)
92*cdf0e10cSrcweir 	sal_Bool bVisible(sal_True);
93*cdf0e10cSrcweir 	if (mpDoc)
94*cdf0e10cSrcweir 	{
95*cdf0e10cSrcweir         bool bColHidden = mpDoc->ColHidden(maCellAddress.Col(), maCellAddress.Tab());
96*cdf0e10cSrcweir         bool bRowHidden = mpDoc->RowHidden(maCellAddress.Row(), maCellAddress.Tab());
97*cdf0e10cSrcweir         bool bColFiltered = mpDoc->ColFiltered(maCellAddress.Col(), maCellAddress.Tab());
98*cdf0e10cSrcweir         bool bRowFiltered = mpDoc->RowFiltered(maCellAddress.Row(), maCellAddress.Tab());
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         if (bColHidden || bColFiltered || bRowHidden || bRowFiltered)
101*cdf0e10cSrcweir 			bVisible = sal_False;
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir 	return bVisible;
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessibleCellBase::getForeground()
107*cdf0e10cSrcweir     throw (uno::RuntimeException)
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     ScUnoGuard aGuard;
110*cdf0e10cSrcweir     IsObjectValid();
111*cdf0e10cSrcweir     sal_Int32 nColor(0);
112*cdf0e10cSrcweir     if (mpDoc)
113*cdf0e10cSrcweir     {
114*cdf0e10cSrcweir         SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
115*cdf0e10cSrcweir         if ( pObjSh )
116*cdf0e10cSrcweir         {
117*cdf0e10cSrcweir             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
118*cdf0e10cSrcweir             if ( xSpreadDoc.is() )
119*cdf0e10cSrcweir             {
120*cdf0e10cSrcweir                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
121*cdf0e10cSrcweir                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
122*cdf0e10cSrcweir                 if ( xIndex.is() )
123*cdf0e10cSrcweir                 {
124*cdf0e10cSrcweir                     uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
125*cdf0e10cSrcweir                     uno::Reference<sheet::XSpreadsheet> xTable;
126*cdf0e10cSrcweir                     if (aTable>>=xTable)
127*cdf0e10cSrcweir                     {
128*cdf0e10cSrcweir                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
129*cdf0e10cSrcweir                         if (xCell.is())
130*cdf0e10cSrcweir                         {
131*cdf0e10cSrcweir                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
132*cdf0e10cSrcweir                             if (xCellProps.is())
133*cdf0e10cSrcweir                             {
134*cdf0e10cSrcweir                                 uno::Any aAny = xCellProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CCOLOR)));
135*cdf0e10cSrcweir                                 aAny >>= nColor;
136*cdf0e10cSrcweir                             }
137*cdf0e10cSrcweir                         }
138*cdf0e10cSrcweir                     }
139*cdf0e10cSrcweir                 }
140*cdf0e10cSrcweir             }
141*cdf0e10cSrcweir         }
142*cdf0e10cSrcweir     }
143*cdf0e10cSrcweir     return nColor;
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessibleCellBase::getBackground()
147*cdf0e10cSrcweir     throw (uno::RuntimeException)
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     ScUnoGuard aGuard;
150*cdf0e10cSrcweir     IsObjectValid();
151*cdf0e10cSrcweir     sal_Int32 nColor(0);
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     if (mpDoc)
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
156*cdf0e10cSrcweir         if ( pObjSh )
157*cdf0e10cSrcweir         {
158*cdf0e10cSrcweir             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
159*cdf0e10cSrcweir             if ( xSpreadDoc.is() )
160*cdf0e10cSrcweir             {
161*cdf0e10cSrcweir                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
162*cdf0e10cSrcweir                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
163*cdf0e10cSrcweir                 if ( xIndex.is() )
164*cdf0e10cSrcweir                 {
165*cdf0e10cSrcweir                     uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
166*cdf0e10cSrcweir                     uno::Reference<sheet::XSpreadsheet> xTable;
167*cdf0e10cSrcweir                     if (aTable>>=xTable)
168*cdf0e10cSrcweir                     {
169*cdf0e10cSrcweir                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
170*cdf0e10cSrcweir                         if (xCell.is())
171*cdf0e10cSrcweir                         {
172*cdf0e10cSrcweir                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
173*cdf0e10cSrcweir                             if (xCellProps.is())
174*cdf0e10cSrcweir                             {
175*cdf0e10cSrcweir                                 uno::Any aAny = xCellProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLBACK)));
176*cdf0e10cSrcweir                                 aAny >>= nColor;
177*cdf0e10cSrcweir                             }
178*cdf0e10cSrcweir                         }
179*cdf0e10cSrcweir                     }
180*cdf0e10cSrcweir                 }
181*cdf0e10cSrcweir             }
182*cdf0e10cSrcweir         }
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     return nColor;
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	//=====  XInterface  =====================================================
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir uno::Any SAL_CALL ScAccessibleCellBase::queryInterface( uno::Type const & rType )
191*cdf0e10cSrcweir 	throw (uno::RuntimeException)
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir 	uno::Any aAny (ScAccessibleCellBaseImpl::queryInterface(rType));
194*cdf0e10cSrcweir 	return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir void SAL_CALL ScAccessibleCellBase::acquire()
198*cdf0e10cSrcweir 	throw ()
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir 	ScAccessibleContextBase::acquire();
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir void SAL_CALL ScAccessibleCellBase::release()
204*cdf0e10cSrcweir 	throw ()
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir 	ScAccessibleContextBase::release();
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	//=====  XAccessibleContext  ==============================================
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir sal_Int32
212*cdf0e10cSrcweir 	ScAccessibleCellBase::getAccessibleIndexInParent(void)
213*cdf0e10cSrcweir         throw (uno::RuntimeException)
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir 	ScUnoGuard aGuard;
216*cdf0e10cSrcweir     IsObjectValid();
217*cdf0e10cSrcweir 	return mnIndex;
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
221*cdf0e10cSrcweir     ScAccessibleCellBase::createAccessibleDescription(void)
222*cdf0e10cSrcweir     throw (uno::RuntimeException)
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	rtl::OUString sDescription = String(ScResId(STR_ACC_CELL_DESCR));
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	return sDescription;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
230*cdf0e10cSrcweir     ScAccessibleCellBase::createAccessibleName(void)
231*cdf0e10cSrcweir     throw (uno::RuntimeException)
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir 	String sName( ScResId(STR_ACC_CELL_NAME) );
234*cdf0e10cSrcweir 	String sAddress;
235*cdf0e10cSrcweir 	// Document not needed, because only the cell address, but not the tablename is needed
236*cdf0e10cSrcweir 	// always us OOO notation
237*cdf0e10cSrcweir 	maCellAddress.Format( sAddress, SCA_VALID, NULL );
238*cdf0e10cSrcweir 	sName.SearchAndReplaceAscii("%1", sAddress);
239*cdf0e10cSrcweir     /*  #i65103# ZoomText merges cell address and contents, e.g. if value 2 is
240*cdf0e10cSrcweir         contained in cell A1, ZT reads "cell A twelve" instead of "cell A1 - 2".
241*cdf0e10cSrcweir         Simple solution: Append a space character to the cell address. */
242*cdf0e10cSrcweir     sName.Append( ' ' );
243*cdf0e10cSrcweir     return rtl::OUString(sName);
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	//=====  XAccessibleValue  ================================================
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir uno::Any SAL_CALL
249*cdf0e10cSrcweir 	ScAccessibleCellBase::getCurrentValue(  )
250*cdf0e10cSrcweir 	throw (uno::RuntimeException)
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir  	ScUnoGuard aGuard;
253*cdf0e10cSrcweir     IsObjectValid();
254*cdf0e10cSrcweir 	uno::Any aAny;
255*cdf0e10cSrcweir 	if (mpDoc)
256*cdf0e10cSrcweir 		aAny <<= mpDoc->GetValue(maCellAddress);
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	return aAny;
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir sal_Bool SAL_CALL
262*cdf0e10cSrcweir 	ScAccessibleCellBase::setCurrentValue( const uno::Any& aNumber )
263*cdf0e10cSrcweir 	throw (uno::RuntimeException)
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir  	ScUnoGuard aGuard;
266*cdf0e10cSrcweir     IsObjectValid();
267*cdf0e10cSrcweir 	double fValue = 0;
268*cdf0e10cSrcweir 	sal_Bool bResult(sal_False);
269*cdf0e10cSrcweir 	if((aNumber >>= fValue) && mpDoc && mpDoc->GetDocumentShell())
270*cdf0e10cSrcweir 	{
271*cdf0e10cSrcweir 		uno::Reference<XAccessibleStateSet> xParentStates;
272*cdf0e10cSrcweir 		if (getAccessibleParent().is())
273*cdf0e10cSrcweir 		{
274*cdf0e10cSrcweir 			uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
275*cdf0e10cSrcweir 			xParentStates = xParentContext->getAccessibleStateSet();
276*cdf0e10cSrcweir 		}
277*cdf0e10cSrcweir 		if (IsEditable(xParentStates))
278*cdf0e10cSrcweir 		{
279*cdf0e10cSrcweir 			ScDocShell* pDocShell = (ScDocShell*) mpDoc->GetDocumentShell();
280*cdf0e10cSrcweir 			ScDocFunc aFunc(*pDocShell);
281*cdf0e10cSrcweir 			bResult = aFunc.PutCell( maCellAddress, new ScValueCell(fValue), sal_True );
282*cdf0e10cSrcweir 		}
283*cdf0e10cSrcweir 	}
284*cdf0e10cSrcweir 	return bResult;
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir uno::Any SAL_CALL
288*cdf0e10cSrcweir 	ScAccessibleCellBase::getMaximumValue(  )
289*cdf0e10cSrcweir 	throw (uno::RuntimeException)
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir 	uno::Any aAny;
292*cdf0e10cSrcweir 	aAny <<= DBL_MAX;
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 	return aAny;
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir uno::Any SAL_CALL
298*cdf0e10cSrcweir 	ScAccessibleCellBase::getMinimumValue(  )
299*cdf0e10cSrcweir 	throw (uno::RuntimeException)
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir 	uno::Any aAny;
302*cdf0e10cSrcweir 	aAny <<= -DBL_MAX;
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 	return aAny;
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	//=====  XServiceInfo  ====================================================
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleCellBase::getImplementationName(void)
310*cdf0e10cSrcweir         throw (uno::RuntimeException)
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleCellBase"));
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	//=====  XTypeProvider  ===================================================
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL ScAccessibleCellBase::getTypes()
318*cdf0e10cSrcweir 		throw (uno::RuntimeException)
319*cdf0e10cSrcweir {
320*cdf0e10cSrcweir 	return comphelper::concatSequences(ScAccessibleCellBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
321*cdf0e10cSrcweir }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL
324*cdf0e10cSrcweir 	ScAccessibleCellBase::getImplementationId(void)
325*cdf0e10cSrcweir     throw (uno::RuntimeException)
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir     ScUnoGuard aGuard;
328*cdf0e10cSrcweir     IsObjectValid();
329*cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> aId;
330*cdf0e10cSrcweir 	if (aId.getLength() == 0)
331*cdf0e10cSrcweir 	{
332*cdf0e10cSrcweir 		aId.realloc (16);
333*cdf0e10cSrcweir 		rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
334*cdf0e10cSrcweir 	}
335*cdf0e10cSrcweir 	return aId;
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir sal_Bool ScAccessibleCellBase::IsEditable(
339*cdf0e10cSrcweir 	const uno::Reference<XAccessibleStateSet>& rxParentStates)
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir 	sal_Bool bEditable(sal_False);
342*cdf0e10cSrcweir 	if (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::EDITABLE))
343*cdf0e10cSrcweir 		bEditable = sal_True;
344*cdf0e10cSrcweir 	return bEditable;
345*cdf0e10cSrcweir }
346