1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleCellBase.cxx,v $
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"
37 #include "scitems.hxx"
38 #include "miscuno.hxx"
39 #include "document.hxx"
40 #include "docfunc.hxx"
42 #include "unoguard.hxx"
43 #include "scresid.hxx"
47 #include "unonames.hxx"
49 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
50 #include <com/sun/star/accessibility/AccessibleRole.hpp>
52 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
53 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
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>
60 #include <comphelper/sequence.hxx>
61 #include <sfx2/objsh.hxx>
65 using namespace ::com::sun::star
;
66 using namespace ::com::sun::star::accessibility
;
68 //===== internal ============================================================
70 ScAccessibleCellBase::ScAccessibleCellBase(
71 const uno::Reference
<XAccessible
>& rxParent
,
73 const ScAddress
& rCellAddress
,
76 ScAccessibleContextBase(rxParent
, AccessibleRole::TABLE_CELL
),
77 maCellAddress(rCellAddress
),
83 ScAccessibleCellBase::~ScAccessibleCellBase()
87 //===== XAccessibleComponent ============================================
89 sal_Bool SAL_CALL
ScAccessibleCellBase::isVisible( )
90 throw (uno::RuntimeException
)
94 // test whether the cell is hidden (column/row - hidden/filtered)
95 sal_Bool
bVisible(sal_True
);
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
;
109 sal_Int32 SAL_CALL
ScAccessibleCellBase::getForeground()
110 throw (uno::RuntimeException
)
117 SfxObjectShell
* pObjSh
= mpDoc
->GetDocumentShell();
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
);
127 uno::Any aTable
= xIndex
->getByIndex(maCellAddress
.Tab());
128 uno::Reference
<sheet::XSpreadsheet
> xTable
;
131 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByPosition(maCellAddress
.Col(), maCellAddress
.Row());
134 uno::Reference
<beans::XPropertySet
> xCellProps(xCell
, uno::UNO_QUERY
);
137 uno::Any aAny
= xCellProps
->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CCOLOR
)));
149 sal_Int32 SAL_CALL
ScAccessibleCellBase::getBackground()
150 throw (uno::RuntimeException
)
158 SfxObjectShell
* pObjSh
= mpDoc
->GetDocumentShell();
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
);
168 uno::Any aTable
= xIndex
->getByIndex(maCellAddress
.Tab());
169 uno::Reference
<sheet::XSpreadsheet
> xTable
;
172 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByPosition(maCellAddress
.Col(), maCellAddress
.Row());
175 uno::Reference
<beans::XPropertySet
> xCellProps(xCell
, uno::UNO_QUERY
);
178 uno::Any aAny
= xCellProps
->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLBACK
)));
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()
203 ScAccessibleContextBase::acquire();
206 void SAL_CALL
ScAccessibleCellBase::release()
209 ScAccessibleContextBase::release();
212 //===== XAccessibleContext ==============================================
215 ScAccessibleCellBase::getAccessibleIndexInParent(void)
216 throw (uno::RuntimeException
)
223 ::rtl::OUString SAL_CALL
224 ScAccessibleCellBase::createAccessibleDescription(void)
225 throw (uno::RuntimeException
)
227 rtl::OUString sDescription
= String(ScResId(STR_ACC_CELL_DESCR
));
232 ::rtl::OUString SAL_CALL
233 ScAccessibleCellBase::createAccessibleName(void)
234 throw (uno::RuntimeException
)
236 String
sName( ScResId(STR_ACC_CELL_NAME
) );
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. */
246 return rtl::OUString(sName
);
249 //===== XAccessibleValue ================================================
252 ScAccessibleCellBase::getCurrentValue( )
253 throw (uno::RuntimeException
)
259 aAny
<<= mpDoc
->GetValue(maCellAddress
);
265 ScAccessibleCellBase::setCurrentValue( const uno::Any
& aNumber
)
266 throw (uno::RuntimeException
)
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
);
291 ScAccessibleCellBase::getMaximumValue( )
292 throw (uno::RuntimeException
)
301 ScAccessibleCellBase::getMinimumValue( )
302 throw (uno::RuntimeException
)
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
)
332 static uno::Sequence
<sal_Int8
> aId
;
333 if (aId
.getLength() == 0)
336 rtl_createUuid (reinterpret_cast<sal_uInt8
*>(aId
.getArray()), 0, sal_True
);
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
;