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