fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / Accessibility / AccessibleCellBase.cxx
blobc50a46ed889d9952116c88e6df550015a719866b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 "formulacell.hxx"
28 #include "scresid.hxx"
29 #include "sc.hrc"
30 #include "unonames.hxx"
31 #include "detfunc.hxx"
32 #include "chgtrack.hxx"
34 #include <com/sun/star/accessibility/AccessibleRole.hpp>
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
37 #include <com/sun/star/sheet/XSpreadsheet.hpp>
38 #include <com/sun/star/sheet/XSheetAnnotation.hpp>
39 #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
40 #include <com/sun/star/text/XSimpleText.hpp>
41 #include <editeng/brushitem.hxx>
42 #include <comphelper/sequence.hxx>
43 #include <comphelper/servicehelper.hxx>
44 #include <sfx2/objsh.hxx>
45 #include <vcl/svapp.hxx>
47 #include <float.h>
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::accessibility;
52 //===== internal ============================================================
54 ScAccessibleCellBase::ScAccessibleCellBase(
55 const uno::Reference<XAccessible>& rxParent,
56 ScDocument* pDoc,
57 const ScAddress& rCellAddress,
58 sal_Int32 nIndex)
60 ScAccessibleContextBase(rxParent, AccessibleRole::TABLE_CELL),
61 maCellAddress(rCellAddress),
62 mpDoc(pDoc),
63 mnIndex(nIndex)
67 ScAccessibleCellBase::~ScAccessibleCellBase()
71 //===== XAccessibleComponent ============================================
73 bool SAL_CALL ScAccessibleCellBase::isVisible()
74 throw (uno::RuntimeException, std::exception)
76 SolarMutexGuard aGuard;
77 IsObjectValid();
78 // test whether the cell is hidden (column/row - hidden/filtered)
79 bool bVisible(true);
80 if (mpDoc)
82 bool bColHidden = mpDoc->ColHidden(maCellAddress.Col(), maCellAddress.Tab());
83 bool bRowHidden = mpDoc->RowHidden(maCellAddress.Row(), maCellAddress.Tab());
84 bool bColFiltered = mpDoc->ColFiltered(maCellAddress.Col(), maCellAddress.Tab());
85 bool bRowFiltered = mpDoc->RowFiltered(maCellAddress.Row(), maCellAddress.Tab());
87 if (bColHidden || bColFiltered || bRowHidden || bRowFiltered)
88 bVisible = false;
90 return bVisible;
93 sal_Int32 SAL_CALL ScAccessibleCellBase::getForeground()
94 throw (uno::RuntimeException, std::exception)
96 SolarMutexGuard aGuard;
97 IsObjectValid();
98 sal_Int32 nColor(0);
99 if (mpDoc)
101 SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
102 if ( pObjSh )
104 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
105 if ( xSpreadDoc.is() )
107 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
108 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
109 if ( xIndex.is() )
111 uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
112 uno::Reference<sheet::XSpreadsheet> xTable;
113 if (aTable>>=xTable)
115 uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
116 if (xCell.is())
118 uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
119 if (xCellProps.is())
121 uno::Any aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_CCOLOR));
122 aAny >>= nColor;
130 return nColor;
133 sal_Int32 SAL_CALL ScAccessibleCellBase::getBackground()
134 throw (uno::RuntimeException, std::exception)
136 SolarMutexGuard aGuard;
137 IsObjectValid();
138 sal_Int32 nColor(0);
140 if (mpDoc)
142 SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
143 if ( pObjSh )
145 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
146 if ( xSpreadDoc.is() )
148 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
149 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
150 if ( xIndex.is() )
152 uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
153 uno::Reference<sheet::XSpreadsheet> xTable;
154 if (aTable>>=xTable)
156 uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
157 if (xCell.is())
159 uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
160 if (xCellProps.is())
162 uno::Any aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_CELLBACK));
163 aAny >>= nColor;
172 return nColor;
175 //===== XInterface =====================================================
177 uno::Any SAL_CALL ScAccessibleCellBase::queryInterface( uno::Type const & rType )
178 throw (uno::RuntimeException, std::exception)
180 uno::Any aAny (ScAccessibleCellBaseImpl::queryInterface(rType));
181 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
184 void SAL_CALL ScAccessibleCellBase::acquire()
185 throw ()
187 ScAccessibleContextBase::acquire();
190 void SAL_CALL ScAccessibleCellBase::release()
191 throw ()
193 ScAccessibleContextBase::release();
196 //===== XAccessibleContext ==============================================
198 sal_Int32
199 ScAccessibleCellBase::getAccessibleIndexInParent()
200 throw (uno::RuntimeException, std::exception)
202 SolarMutexGuard aGuard;
203 IsObjectValid();
204 return mnIndex;
207 OUString SAL_CALL
208 ScAccessibleCellBase::createAccessibleDescription()
209 throw (uno::RuntimeException)
211 OUString sDescription = OUString(ScResId(STR_ACC_CELL_DESCR));
213 return sDescription;
216 OUString SAL_CALL
217 ScAccessibleCellBase::createAccessibleName()
218 throw (uno::RuntimeException, std::exception)
220 // Document not needed, because only the cell address, but not the tablename is needed
221 // always us OOO notation
222 return maCellAddress.Format(SCA_VALID, NULL);
225 //===== XAccessibleValue ================================================
227 uno::Any SAL_CALL
228 ScAccessibleCellBase::getCurrentValue()
229 throw (uno::RuntimeException, std::exception)
231 SolarMutexGuard aGuard;
232 IsObjectValid();
233 uno::Any aAny;
234 if (mpDoc)
236 aAny <<= mpDoc->GetValue(maCellAddress);
238 return aAny;
241 sal_Bool SAL_CALL
242 ScAccessibleCellBase::setCurrentValue( const uno::Any& aNumber )
243 throw (uno::RuntimeException, std::exception)
245 SolarMutexGuard aGuard;
246 IsObjectValid();
247 double fValue = 0;
248 bool bResult = false;
249 if((aNumber >>= fValue) && mpDoc && mpDoc->GetDocumentShell())
251 uno::Reference<XAccessibleStateSet> xParentStates;
252 if (getAccessibleParent().is())
254 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
255 xParentStates = xParentContext->getAccessibleStateSet();
257 if (IsEditable(xParentStates))
259 ScDocShell* pDocShell = static_cast<ScDocShell*>(mpDoc->GetDocumentShell());
260 bResult = pDocShell->GetDocFunc().SetValueCell(maCellAddress, fValue, false);
263 return bResult;
266 uno::Any SAL_CALL
267 ScAccessibleCellBase::getMaximumValue( )
268 throw (uno::RuntimeException, std::exception)
270 uno::Any aAny;
271 aAny <<= DBL_MAX;
273 return aAny;
276 uno::Any SAL_CALL
277 ScAccessibleCellBase::getMinimumValue( )
278 throw (uno::RuntimeException, std::exception)
280 uno::Any aAny;
281 aAny <<= -DBL_MAX;
283 return aAny;
286 //===== XServiceInfo ====================================================
288 OUString SAL_CALL ScAccessibleCellBase::getImplementationName()
289 throw (uno::RuntimeException, std::exception)
291 return OUString("ScAccessibleCellBase");
294 //===== XTypeProvider ===================================================
296 uno::Sequence< uno::Type > SAL_CALL ScAccessibleCellBase::getTypes()
297 throw (uno::RuntimeException, std::exception)
299 return comphelper::concatSequences(ScAccessibleCellBaseImpl::getTypes(), ScAccessibleContextBase::getTypes());
302 uno::Sequence<sal_Int8> SAL_CALL
303 ScAccessibleCellBase::getImplementationId()
304 throw (uno::RuntimeException, std::exception)
306 return css::uno::Sequence<sal_Int8>();
309 bool ScAccessibleCellBase::IsEditable(
310 const uno::Reference<XAccessibleStateSet>& rxParentStates)
312 bool bEditable(false);
313 if (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::EDITABLE))
314 bEditable = true;
315 return bEditable;
318 OUString SAL_CALL ScAccessibleCellBase::GetNote()
319 throw (::com::sun::star::uno::RuntimeException)
321 SolarMutexGuard aGuard;
322 IsObjectValid();
323 OUString msNote;
324 if (mpDoc)
326 SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
327 if ( pObjSh )
329 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
330 if ( xSpreadDoc.is() )
332 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
333 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
334 if ( xIndex.is() )
336 uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
337 uno::Reference<sheet::XSpreadsheet> xTable;
338 if (aTable>>=xTable)
340 uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
341 if (xCell.is())
343 uno::Reference <sheet::XSheetAnnotationAnchor> xAnnotationAnchor ( xCell, uno::UNO_QUERY);
344 if(xAnnotationAnchor.is())
346 uno::Reference <sheet::XSheetAnnotation> xSheetAnnotation = xAnnotationAnchor->getAnnotation();
347 if (xSheetAnnotation.is())
349 uno::Reference <text::XSimpleText> xText (xSheetAnnotation, uno::UNO_QUERY);
350 if (xText.is())
352 msNote = xText->getString();
362 return msNote;
365 #include <com/sun/star/table/ShadowFormat.hpp>
367 OUString SAL_CALL ScAccessibleCellBase::getShadowAttrs()
368 throw (::com::sun::star::uno::RuntimeException)
370 SolarMutexGuard aGuard;
371 IsObjectValid();
372 table::ShadowFormat aShadowFmt;
373 if (mpDoc)
375 SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
376 if ( pObjSh )
378 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
379 if ( xSpreadDoc.is() )
381 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
382 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
383 if ( xIndex.is() )
385 uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
386 uno::Reference<sheet::XSpreadsheet> xTable;
387 if (aTable>>=xTable)
389 uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
390 if (xCell.is())
392 uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
393 if (xCellProps.is())
395 uno::Any aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_SHADOW));
396 aAny >>= aShadowFmt;
404 //construct shadow attributes string
405 OUString sShadowAttrs("Shadow:");
406 OUString sInnerSplit(",");
407 OUString sOuterSplit(";");
408 sal_Int32 nLocationVal = 0;
409 switch( aShadowFmt.Location )
411 case table::ShadowLocation_TOP_LEFT:
412 nLocationVal = 1;
413 break;
414 case table::ShadowLocation_TOP_RIGHT:
415 nLocationVal = 2;
416 break;
417 case table::ShadowLocation_BOTTOM_LEFT:
418 nLocationVal = 3;
419 break;
420 case table::ShadowLocation_BOTTOM_RIGHT:
421 nLocationVal = 4;
422 break;
423 default:
424 break;
426 //if there is no shadow property for the cell
427 if ( nLocationVal == 0 )
429 sShadowAttrs += sOuterSplit;
430 return sShadowAttrs;
432 //else return all the shadow properties
433 sShadowAttrs += "Location=";
434 sShadowAttrs += OUString::number( (sal_Int32)nLocationVal );
435 sShadowAttrs += sInnerSplit;
436 sShadowAttrs += "ShadowWidth=";
437 sShadowAttrs += OUString::number( (sal_Int32)aShadowFmt.ShadowWidth ) ;
438 sShadowAttrs += sInnerSplit;
439 sShadowAttrs += "IsTransparent=";
440 sShadowAttrs += OUString::number( (int)aShadowFmt.IsTransparent ) ;
441 sShadowAttrs += sInnerSplit;
442 sShadowAttrs += "Color=";
443 sShadowAttrs += OUString::number( (sal_Int32)aShadowFmt.Color );
444 sShadowAttrs += sOuterSplit;
445 return sShadowAttrs;
448 #include <com/sun/star/table/BorderLine.hpp>
450 OUString SAL_CALL ScAccessibleCellBase::getBorderAttrs()
451 throw (::com::sun::star::uno::RuntimeException)
453 SolarMutexGuard aGuard;
454 IsObjectValid();
455 table::BorderLine aTopBorder;
456 table::BorderLine aBottomBorder;
457 table::BorderLine aLeftBorder;
458 table::BorderLine aRightBorder;
459 if (mpDoc)
461 SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
462 if ( pObjSh )
464 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
465 if ( xSpreadDoc.is() )
467 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
468 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
469 if ( xIndex.is() )
471 uno::Any aTable = xIndex->getByIndex(maCellAddress.Tab());
472 uno::Reference<sheet::XSpreadsheet> xTable;
473 if (aTable>>=xTable)
475 uno::Reference<table::XCell> xCell = xTable->getCellByPosition(maCellAddress.Col(), maCellAddress.Row());
476 if (xCell.is())
478 uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
479 if (xCellProps.is())
481 uno::Any aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_TOPBORDER));
482 aAny >>= aTopBorder;
483 aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_BOTTBORDER));
484 aAny >>= aBottomBorder;
485 aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_LEFTBORDER));
486 aAny >>= aLeftBorder;
487 aAny = xCellProps->getPropertyValue(OUString(SC_UNONAME_RIGHTBORDER));
488 aAny >>= aRightBorder;
497 Color aColor;
498 bool bIn = mpDoc && mpDoc->IsCellInChangeTrack(maCellAddress,&aColor);
499 if (bIn)
501 aTopBorder.Color = aColor.GetColor();
502 aBottomBorder.Color = aColor.GetColor();
503 aLeftBorder.Color = aColor.GetColor();
504 aRightBorder.Color = aColor.GetColor();
505 aTopBorder.OuterLineWidth =2;
506 aBottomBorder.OuterLineWidth =2;
507 aLeftBorder.OuterLineWidth =2;
508 aRightBorder.OuterLineWidth =2;
511 //construct border attributes string
512 OUString sBorderAttrs;
513 OUString sInnerSplit(",");
514 OUString sOuterSplit(";");
515 //top border
516 //if top of the cell has no border
517 if ( aTopBorder.InnerLineWidth == 0 && aTopBorder.OuterLineWidth == 0 )
519 sBorderAttrs += "TopBorder:;";
521 else//add all the border properties to the return string.
523 sBorderAttrs += "TopBorder:Color=";
524 sBorderAttrs += OUString::number( (sal_Int32)aTopBorder.Color );
525 sBorderAttrs += sInnerSplit;
526 sBorderAttrs += "InnerLineWidth=";
527 sBorderAttrs += OUString::number( (sal_Int32)aTopBorder.InnerLineWidth );
528 sBorderAttrs += sInnerSplit;
529 sBorderAttrs += "OuterLineWidth=";
530 sBorderAttrs += OUString::number( (sal_Int32)aTopBorder.OuterLineWidth );
531 sBorderAttrs += sInnerSplit;
532 sBorderAttrs += "LineDistance=";
533 sBorderAttrs += OUString::number( (sal_Int32)aTopBorder.LineDistance );
534 sBorderAttrs += sOuterSplit;
536 //bottom border
537 if ( aBottomBorder.InnerLineWidth == 0 && aBottomBorder.OuterLineWidth == 0 )
539 sBorderAttrs += "BottomBorde:;";
541 else
543 sBorderAttrs += "BottomBorder:Color=";
544 sBorderAttrs += OUString::number( (sal_Int32)aBottomBorder.Color );
545 sBorderAttrs += sInnerSplit;
546 sBorderAttrs += "InnerLineWidth=";
547 sBorderAttrs += OUString::number( (sal_Int32)aBottomBorder.InnerLineWidth );
548 sBorderAttrs += sInnerSplit;
549 sBorderAttrs += "OuterLineWidth=";
550 sBorderAttrs += OUString::number( (sal_Int32)aBottomBorder.OuterLineWidth );
551 sBorderAttrs += sInnerSplit;
552 sBorderAttrs += "LineDistance=";
553 sBorderAttrs += OUString::number( (sal_Int32)aBottomBorder.LineDistance );
554 sBorderAttrs += sOuterSplit;
556 //left border
557 if ( aLeftBorder.InnerLineWidth == 0 && aLeftBorder.OuterLineWidth == 0 )
559 sBorderAttrs += "LeftBorder:;";
561 else
563 sBorderAttrs += "LeftBorder:Color=";
564 sBorderAttrs += OUString::number( (sal_Int32)aLeftBorder.Color );
565 sBorderAttrs += sInnerSplit;
566 sBorderAttrs += "InnerLineWidth=";
567 sBorderAttrs += OUString::number( (sal_Int32)aLeftBorder.InnerLineWidth );
568 sBorderAttrs += sInnerSplit;
569 sBorderAttrs += "OuterLineWidth=";
570 sBorderAttrs += OUString::number( (sal_Int32)aLeftBorder.OuterLineWidth );
571 sBorderAttrs += sInnerSplit;
572 sBorderAttrs += "LineDistance=";
573 sBorderAttrs += OUString::number( (sal_Int32)aLeftBorder.LineDistance );
574 sBorderAttrs += sOuterSplit;
576 //right border
577 if ( aRightBorder.InnerLineWidth == 0 && aRightBorder.OuterLineWidth == 0 )
579 sBorderAttrs += "RightBorder:;";
581 else
583 sBorderAttrs += "RightBorder:Color=";
584 sBorderAttrs += OUString::number( (sal_Int32)aRightBorder.Color );
585 sBorderAttrs += sInnerSplit;
586 sBorderAttrs += "InnerLineWidth=";
587 sBorderAttrs += OUString::number( (sal_Int32)aRightBorder.InnerLineWidth );
588 sBorderAttrs += sInnerSplit;
589 sBorderAttrs += "OuterLineWidth=";
590 sBorderAttrs += OUString::number( (sal_Int32)aRightBorder.OuterLineWidth );
591 sBorderAttrs += sInnerSplit;
592 sBorderAttrs += "LineDistance=";
593 sBorderAttrs += OUString::number( (sal_Int32)aRightBorder.LineDistance );
594 sBorderAttrs += sOuterSplit;
596 return sBorderAttrs;
598 //end of cell attributes
600 OUString SAL_CALL ScAccessibleCellBase::GetAllDisplayNote()
601 throw (::com::sun::star::uno::RuntimeException)
603 OUString strNote;
604 OUString strTrackText;
605 if (mpDoc)
607 bool bLeftedge = false;
608 mpDoc->GetCellChangeTrackNote(maCellAddress,strTrackText,bLeftedge);
610 if (!strTrackText.isEmpty())
612 ScDetectiveFunc::AppendChangTrackNoteSeparator(strTrackText);
613 strNote = strTrackText;
615 strNote += GetNote();
616 return strNote;
619 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */