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