1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
22 #include "scitems.hxx"
23 #include "miscuno.hxx"
24 #include "document.hxx"
25 #include "docfunc.hxx"
27 #include "formulacell.hxx"
28 #include "scresid.hxx"
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>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::accessibility
;
52 //===== internal ============================================================
54 ScAccessibleCellBase::ScAccessibleCellBase(
55 const uno::Reference
<XAccessible
>& rxParent
,
57 const ScAddress
& rCellAddress
,
60 ScAccessibleContextBase(rxParent
, AccessibleRole::TABLE_CELL
),
61 maCellAddress(rCellAddress
),
67 ScAccessibleCellBase::~ScAccessibleCellBase()
71 //===== XAccessibleComponent ============================================
73 bool SAL_CALL
ScAccessibleCellBase::isVisible()
74 throw (uno::RuntimeException
, std::exception
)
76 SolarMutexGuard aGuard
;
78 // test whether the cell is hidden (column/row - hidden/filtered)
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
)
93 sal_Int32 SAL_CALL
ScAccessibleCellBase::getForeground()
94 throw (uno::RuntimeException
, std::exception
)
96 SolarMutexGuard aGuard
;
101 SfxObjectShell
* pObjSh
= mpDoc
->GetDocumentShell();
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
);
111 uno::Any aTable
= xIndex
->getByIndex(maCellAddress
.Tab());
112 uno::Reference
<sheet::XSpreadsheet
> xTable
;
115 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByPosition(maCellAddress
.Col(), maCellAddress
.Row());
118 uno::Reference
<beans::XPropertySet
> xCellProps(xCell
, uno::UNO_QUERY
);
121 uno::Any aAny
= xCellProps
->getPropertyValue(OUString(SC_UNONAME_CCOLOR
));
133 sal_Int32 SAL_CALL
ScAccessibleCellBase::getBackground()
134 throw (uno::RuntimeException
, std::exception
)
136 SolarMutexGuard aGuard
;
142 SfxObjectShell
* pObjSh
= mpDoc
->GetDocumentShell();
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
);
152 uno::Any aTable
= xIndex
->getByIndex(maCellAddress
.Tab());
153 uno::Reference
<sheet::XSpreadsheet
> xTable
;
156 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByPosition(maCellAddress
.Col(), maCellAddress
.Row());
159 uno::Reference
<beans::XPropertySet
> xCellProps(xCell
, uno::UNO_QUERY
);
162 uno::Any aAny
= xCellProps
->getPropertyValue(OUString(SC_UNONAME_CELLBACK
));
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()
187 ScAccessibleContextBase::acquire();
190 void SAL_CALL
ScAccessibleCellBase::release()
193 ScAccessibleContextBase::release();
196 //===== XAccessibleContext ==============================================
199 ScAccessibleCellBase::getAccessibleIndexInParent()
200 throw (uno::RuntimeException
, std::exception
)
202 SolarMutexGuard aGuard
;
208 ScAccessibleCellBase::createAccessibleDescription()
209 throw (uno::RuntimeException
)
211 OUString sDescription
= OUString(ScResId(STR_ACC_CELL_DESCR
));
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 ================================================
228 ScAccessibleCellBase::getCurrentValue()
229 throw (uno::RuntimeException
, std::exception
)
231 SolarMutexGuard aGuard
;
236 aAny
<<= mpDoc
->GetValue(maCellAddress
);
242 ScAccessibleCellBase::setCurrentValue( const uno::Any
& aNumber
)
243 throw (uno::RuntimeException
, std::exception
)
245 SolarMutexGuard aGuard
;
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);
267 ScAccessibleCellBase::getMaximumValue( )
268 throw (uno::RuntimeException
, std::exception
)
277 ScAccessibleCellBase::getMinimumValue( )
278 throw (uno::RuntimeException
, std::exception
)
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
))
318 OUString SAL_CALL
ScAccessibleCellBase::GetNote()
319 throw (::com::sun::star::uno::RuntimeException
)
321 SolarMutexGuard aGuard
;
326 SfxObjectShell
* pObjSh
= mpDoc
->GetDocumentShell();
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
);
336 uno::Any aTable
= xIndex
->getByIndex(maCellAddress
.Tab());
337 uno::Reference
<sheet::XSpreadsheet
> xTable
;
340 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByPosition(maCellAddress
.Col(), maCellAddress
.Row());
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
);
352 msNote
= xText
->getString();
365 #include <com/sun/star/table/ShadowFormat.hpp>
367 OUString SAL_CALL
ScAccessibleCellBase::getShadowAttrs()
368 throw (::com::sun::star::uno::RuntimeException
)
370 SolarMutexGuard aGuard
;
372 table::ShadowFormat aShadowFmt
;
375 SfxObjectShell
* pObjSh
= mpDoc
->GetDocumentShell();
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
);
385 uno::Any aTable
= xIndex
->getByIndex(maCellAddress
.Tab());
386 uno::Reference
<sheet::XSpreadsheet
> xTable
;
389 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByPosition(maCellAddress
.Col(), maCellAddress
.Row());
392 uno::Reference
<beans::XPropertySet
> xCellProps(xCell
, uno::UNO_QUERY
);
395 uno::Any aAny
= xCellProps
->getPropertyValue(OUString(SC_UNONAME_SHADOW
));
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
:
414 case table::ShadowLocation_TOP_RIGHT
:
417 case table::ShadowLocation_BOTTOM_LEFT
:
420 case table::ShadowLocation_BOTTOM_RIGHT
:
426 //if there is no shadow property for the cell
427 if ( nLocationVal
== 0 )
429 sShadowAttrs
+= sOuterSplit
;
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
;
448 #include <com/sun/star/table/BorderLine.hpp>
450 OUString SAL_CALL
ScAccessibleCellBase::getBorderAttrs()
451 throw (::com::sun::star::uno::RuntimeException
)
453 SolarMutexGuard aGuard
;
455 table::BorderLine aTopBorder
;
456 table::BorderLine aBottomBorder
;
457 table::BorderLine aLeftBorder
;
458 table::BorderLine aRightBorder
;
461 SfxObjectShell
* pObjSh
= mpDoc
->GetDocumentShell();
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
);
471 uno::Any aTable
= xIndex
->getByIndex(maCellAddress
.Tab());
472 uno::Reference
<sheet::XSpreadsheet
> xTable
;
475 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByPosition(maCellAddress
.Col(), maCellAddress
.Row());
478 uno::Reference
<beans::XPropertySet
> xCellProps(xCell
, uno::UNO_QUERY
);
481 uno::Any aAny
= xCellProps
->getPropertyValue(OUString(SC_UNONAME_TOPBORDER
));
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
;
498 bool bIn
= mpDoc
&& mpDoc
->IsCellInChangeTrack(maCellAddress
,&aColor
);
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(";");
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
;
537 if ( aBottomBorder
.InnerLineWidth
== 0 && aBottomBorder
.OuterLineWidth
== 0 )
539 sBorderAttrs
+= "BottomBorde:;";
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
;
557 if ( aLeftBorder
.InnerLineWidth
== 0 && aLeftBorder
.OuterLineWidth
== 0 )
559 sBorderAttrs
+= "LeftBorder:;";
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
;
577 if ( aRightBorder
.InnerLineWidth
== 0 && aRightBorder
.OuterLineWidth
== 0 )
579 sBorderAttrs
+= "RightBorder:;";
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
;
598 //end of cell attributes
600 OUString SAL_CALL
ScAccessibleCellBase::GetAllDisplayNote()
601 throw (::com::sun::star::uno::RuntimeException
)
604 OUString strTrackText
;
607 bool bLeftedge
= false;
608 mpDoc
->GetCellChangeTrackNote(maCellAddress
,strTrackText
,bLeftedge
);
610 if (!strTrackText
.isEmpty())
612 ScDetectiveFunc::AppendChangTrackNoteSeparator(strTrackText
);
613 strNote
= strTrackText
;
615 strNote
+= GetNote();
619 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */