30#include <editeng/editeng.hxx>
51#include <com/sun/star/awt/XBitmap.hpp>
52#include <com/sun/star/util/CellProtection.hpp>
53#include <com/sun/star/table/CellHoriJustify.hpp>
54#include <com/sun/star/table/CellOrientation.hpp>
55#include <com/sun/star/table/ShadowFormat.hpp>
56#include <com/sun/star/table/TableBorder.hpp>
57#include <com/sun/star/table/TableBorder2.hpp>
58#include <com/sun/star/sheet/CellFlags.hpp>
59#include <com/sun/star/sheet/FormulaResult.hpp>
60#include <com/sun/star/beans/PropertyAttribute.hpp>
61#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
62#include <com/sun/star/lang/Locale.hpp>
63#include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
64#include <com/sun/star/beans/SetPropertyTolerantFailed.hpp>
65#include <com/sun/star/text/WritingMode2.hpp>
66#include <com/sun/star/text/textfield/Type.hpp>
67#include <com/sun/star/sheet/XConditionalFormats.hpp>
68#include <com/sun/star/util/XComplexColor.hpp>
102#include <stlsheet.hxx>
117#include <globstr.hrc>
119#include <unonames.hxx>
131#include <tokenarray.hxx>
248 return &aCellsPropertySet;
351 return &aRangePropertySet;
460 return &aCellPropertySet;
567 return &aColumnPropertySet;
672 return &aRowPropertySet;
789 return &aSheetPropertySet;
803 return aEditPropertyMap_Impl;
808 return &aEditPropertySet;
844 uno::Reference<beans::XPropertySetInfo> xInfo(rSource.getPropertySetInfo());
847 const uno::Sequence<beans::Property>
aSeq(xInfo->getProperties());
848 for (
const beans::Property& rProp :
aSeq)
850 OUString
aName(rProp.Name);
851 rDest.setPropertyValue(
aName, rSource.getPropertyValue(
aName ) );
859 throw std::out_of_range(
"empty range");
860 const ScRange & rFirst = rRanges[0];
866 if ( rRanges.
size() == 1 )
868 const ScRange & rRange = rRanges[0];
877template<
typename BorderLineType>
878const ::editeng::SvxBorderLine* lcl_getBorderLine(
895 return lcl_getBorderLine( rLine, rStruct);
901 return lcl_getBorderLine( rLine, rStruct);
905template<
typename TableBorderType>
916 rInner.
SetValid( SvxBoxInfoItemValidFlags::TOP, rBorder.IsTopLineValid );
917 rInner.
SetValid( SvxBoxInfoItemValidFlags::BOTTOM, rBorder.IsBottomLineValid );
918 rInner.
SetValid( SvxBoxInfoItemValidFlags::LEFT, rBorder.IsLeftLineValid );
919 rInner.
SetValid( SvxBoxInfoItemValidFlags::RIGHT, rBorder.IsRightLineValid );
920 rInner.
SetValid( SvxBoxInfoItemValidFlags::HORI, rBorder.IsHorizontalLineValid );
921 rInner.
SetValid( SvxBoxInfoItemValidFlags::VERT, rBorder.IsVerticalLineValid );
922 rInner.
SetValid( SvxBoxInfoItemValidFlags::DISTANCE, rBorder.IsDistanceValid );
929 lcl_fillBoxItems( rOuter, rInner, rBorder);
934 lcl_fillBoxItems( rOuter, rInner, rBorder);
949template<
typename TableBorderItem>
951 bool bInvalidateHorVerDist )
961 rBorder.IsTopLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::TOP);
962 rBorder.IsBottomLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::BOTTOM);
963 rBorder.IsLeftLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::LEFT);
964 rBorder.IsRightLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::RIGHT);
965 rBorder.IsHorizontalLineValid = !bInvalidateHorVerDist && rInner.
IsValid(SvxBoxInfoItemValidFlags::HORI);
966 rBorder.IsVerticalLineValid = !bInvalidateHorVerDist && rInner.
IsValid(SvxBoxInfoItemValidFlags::VERT);
967 rBorder.IsDistanceValid = !bInvalidateHorVerDist && rInner.
IsValid(SvxBoxInfoItemValidFlags::DISTANCE);
974 table::TableBorder aBorder;
975 lcl_fillTableBorder( aBorder, rOuter, rInner, bInvalidateHorVerDist);
982 table::TableBorder2 aBorder;
983 lcl_fillTableBorder( aBorder, rOuter, rInner, bInvalidateHorVerDist);
1000 ScRange const & rRange = rRanges[
i ];
1006 pUndoDoc->InitUndo( rDoc, nTab, nTab );
1008 pUndoDoc->AddUndoTab( nTab, nTab );
1023 std::make_unique<ScUndoBorder>( pDocShell, rRanges, std::move(pUndoDoc), rOuter, rInner ) );
1036 const uno::Sequence< uno::Sequence<uno::Any> >& aData )
1047 if ( !rDoc.
IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) )
1053 sal_Int32 nCols = 0;
1054 sal_Int32 nRows =
aData.getLength();
1056 nCols =
aData[0].getLength();
1058 if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 )
1068 pUndoDoc->InitUndo( rDoc, nTab, nTab );
1074 bool bError =
false;
1075 SCROW nDocRow = nStartRow;
1076 for (
const uno::Sequence<uno::Any>& rColSeq :
aData)
1078 if ( rColSeq.getLength() == nCols )
1080 SCCOL nDocCol = nStartCol;
1081 for (
const uno::Any& rElement : rColSeq)
1085 switch( rElement.getValueTypeClass() )
1087 case uno::TypeClass_VOID:
1090 rDoc.
SetError( nDocCol, nDocRow, nTab, FormulaError::NotAvailable );
1096 case uno::TypeClass_BYTE:
1097 case uno::TypeClass_SHORT:
1098 case uno::TypeClass_UNSIGNED_SHORT:
1099 case uno::TypeClass_LONG:
1100 case uno::TypeClass_UNSIGNED_LONG:
1101 case uno::TypeClass_FLOAT:
1102 case uno::TypeClass_DOUBLE:
1110 case uno::TypeClass_STRING:
1114 if ( !aUStr.isEmpty() )
1134 case uno::TypeClass_SEQUENCE:
1136 uno::Sequence< sheet::FormulaToken > aTokens;
1137 if ( rElement >>= aTokens )
1167 std::make_unique<ScUndoPaste>(
1168 &rDocShell,
ScRange(nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab),
1181 const uno::Sequence< uno::Sequence<OUString> >& aData,
1192 if ( !rDoc.
IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) )
1198 sal_Int32 nCols = 0;
1199 sal_Int32 nRows =
aData.getLength();
1201 nCols =
aData[0].getLength();
1203 if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 )
1213 pUndoDoc->InitUndo( rDoc, nTab, nTab );
1219 bool bError =
false;
1220 SCROW nDocRow = nStartRow;
1221 for (
const uno::Sequence<OUString>& rColSeq :
aData)
1223 if ( rColSeq.getLength() == nCols )
1225 SCCOL nDocCol = nStartCol;
1226 for (
const OUString& aText : rColSeq)
1228 ScAddress aPos( nDocCol, nDocRow, nTab );
1264 std::make_unique<ScUndoPaste>( &rDocShell,
1265 ScRange(nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab), aDestMark,
1319 OUString aTempString = aVal;
1320 bool bIsNumberFormat(pFormatter->
IsNumberFormat(aTempString, nNumFmt, fDummy));
1321 if ( bIsNumberFormat )
1322 aTempString =
"'" + aTempString;
1323 else if ( aTempString.startsWith(
"'") )
1327 if ( bEnglish || ( pFormatter->
GetType(nNumFmt) != SvNumFormatType::TEXT ) )
1328 aTempString =
"'" + aTempString;
1337 pDocShell( pDocSh ),
1339 bChartColAsHdr( false ),
1340 bChartRowAsHdr( false ),
1341 bCursorOnly( false ),
1342 bGotDataChangedHint( false ),
1343 aValueListeners( 0 )
1346 aCellRange.PutInOrder();
1347 aRanges.push_back( aCellRange );
1359 pDocShell( pDocSh ),
1360 aRanges(
std::move( aR )),
1362 bChartColAsHdr( false ),
1363 bChartRowAsHdr( false ),
1364 bCursorOnly( false ),
1365 bGotDataChangedHint( false ),
1366 aValueListeners( 0 )
1376ScCellRangesBase::~ScCellRangesBase()
1384 pDocShell->GetDocument().RemoveUnoObject(*
this);
1386 ForgetCurrentAttrs();
1389 pValueListener.reset();
1395void ScCellRangesBase::ForgetCurrentAttrs()
1397 pCurrentFlat.reset();
1398 pCurrentDeep.reset();
1399 moCurrentDataSet.reset();
1400 moNoDfltCurrentDataSet.reset();
1405void ScCellRangesBase::ForgetMarkData()
1414 if ( !pCurrentFlat && pDocShell )
1419 return pCurrentFlat.get();
1426 if ( !pCurrentDeep && pDocShell )
1431 return pCurrentDeep.get();
1434SfxItemSet* ScCellRangesBase::GetCurrentDataSet(
bool bNoDflt)
1436 if(!moCurrentDataSet)
1442 moCurrentDataSet.emplace( pPattern->
GetItemSet() );
1443 moNoDfltCurrentDataSet.emplace( pPattern->
GetItemSet() );
1444 moCurrentDataSet->ClearInvalidItems();
1449 if (moNoDfltCurrentDataSet)
1450 return &*moNoDfltCurrentDataSet;
1454 if (moCurrentDataSet)
1455 return &*moCurrentDataSet;
1460const ScMarkData* ScCellRangesBase::GetMarkData()
1464 pMarkData.reset(
new ScMarkData(GetDocument()->GetSheetLimits(), aRanges) );
1466 return pMarkData.get();
1472 if ( nId == SfxHintId::Dying )
1475 ForgetCurrentAttrs();
1476 pDocShell =
nullptr;
1479 if ( m_refCount > 0 && !aValueListeners.empty() )
1483 lang::EventObject
aEvent;
1484 aEvent.Source = getXWeak();
1485 for (uno::Reference<util::XModifyListener> & xValueListener : aValueListeners)
1486 xValueListener->disposing( aEvent );
1488 aValueListeners.clear();
1494 else if ( nId == SfxHintId::DataChanged )
1497 ForgetCurrentAttrs();
1499 if ( bGotDataChangedHint && pDocShell )
1509 lang::EventObject
aEvent;
1510 aEvent.Source = getXWeak();
1515 for (
const uno::Reference<util::XModifyListener> & xValueListener : aValueListeners)
1518 bGotDataChangedHint =
false;
1521 else if ( nId == SfxHintId::ScCalcAll )
1526 if ( !aValueListeners.empty() )
1527 bGotDataChangedHint =
true;
1529 else if (
auto pRefHint =
dynamic_cast<const ScUpdateRefHint*
>(&rHint) )
1532 std::unique_ptr<ScRangeList> pUndoRanges;
1536 if ( aRanges.UpdateReference( pRefHint->GetMode(), &rDoc, pRefHint->GetRange(),
1537 pRefHint->GetDx(), pRefHint->GetDy(), pRefHint->GetDz() ) )
1540 && aRanges.size() == 1
1545 ScRange & rR = aRanges.front();
1554 if ( !aValueListeners.empty() )
1555 bGotDataChangedHint =
true;
1563 if ( pUndoHint->GetObjectId() == nObjectId )
1567 aRanges = pUndoHint->GetRanges();
1570 if ( !aValueListeners.empty() )
1571 bGotDataChangedHint =
true;
1576void ScCellRangesBase::RefChanged()
1580 if ( pValueListener && !aValueListeners.empty() )
1582 pValueListener->EndListeningAll();
1585 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
1589 ForgetCurrentAttrs();
1593ScDocument* ScCellRangesBase::GetDocument()
const
1596 return &pDocShell->GetDocument();
1603 if ( pDocShell || !pDocSh )
1609 aCellRange.PutInOrder();
1610 aRanges.RemoveAll();
1611 aRanges.push_back( aCellRange );
1613 pDocShell->GetDocument().AddUnoObject(*
this);
1618void ScCellRangesBase::AddRange(
const ScRange& rRange,
const bool bMergeRanges)
1621 aRanges.Join(rRange);
1623 aRanges.push_back(rRange);
1627void ScCellRangesBase::SetNewRange(
const ScRange& rNew)
1630 aCellRange.PutInOrder();
1632 aRanges.RemoveAll();
1633 aRanges.push_back( aCellRange );
1637void ScCellRangesBase::SetNewRanges(
const ScRangeList& rNew)
1643void ScCellRangesBase::SetCursorOnly(
bool bSet )
1651void ScCellRangesBase::PaintGridRanges_Impl( )
1653 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i)
1659double SAL_CALL ScCellRangesBase::computeFunction( sheet::GeneralFunction nFunction )
1663 aMark.MarkToSimple();
1664 if (!aMark.IsMarked())
1665 aMark.SetMarkNegative(
true);
1673 throw uno::RuntimeException();
1679void SAL_CALL ScCellRangesBase::clearContents( sal_Int32 nContentFlags )
1682 if ( !aRanges.empty() )
1689 pDocShell->GetDocFunc().DeleteContents( *GetMarkData(), nDelFlags,
true, true );
1698 return pPropSet->getPropertyMap();
1702 sal_uInt16& rItemWhich )
1710 rItemWhich = pEntry->
nWID;
1712 switch ( pEntry->
nWID )
1732beans::PropertyState ScCellRangesBase::GetOnePropertyState( sal_uInt16 nItemWhich,
const SfxItemPropertyMapEntry* pEntry )
1734 beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE;
1749 if ( eState == SfxItemState::SET )
1750 eRet = beans::PropertyState_DIRECT_VALUE;
1751 else if ( eState == SfxItemState::DEFAULT )
1752 eRet = beans::PropertyState_DEFAULT_VALUE;
1753 else if ( eState == SfxItemState::DONTCARE )
1754 eRet = beans::PropertyState_AMBIGUOUS_VALUE;
1757 OSL_FAIL(
"unknown ItemState");
1764 eRet = beans::PropertyState_DIRECT_VALUE;
1768 const ScStyleSheet* pStyle = pDocShell->GetDocument().GetSelectionStyle(*GetMarkData());
1770 eRet = beans::PropertyState_DIRECT_VALUE;
1772 eRet = beans::PropertyState_AMBIGUOUS_VALUE;
1775 eRet = beans::PropertyState_DEFAULT_VALUE;
1780beans::PropertyState SAL_CALL ScCellRangesBase::getPropertyState(
const OUString& aPropertyName )
1783 if ( aRanges.empty() )
1784 throw uno::RuntimeException();
1787 sal_uInt16 nItemWhich = 0;
1790 return GetOnePropertyState( nItemWhich, pEntry );
1793uno::Sequence<beans::PropertyState> SAL_CALL ScCellRangesBase::getPropertyStates(
1794 const uno::Sequence<OUString>& aPropertyNames )
1800 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
1801 std::transform(aPropertyNames.begin(), aPropertyNames.end(), aRet.getArray(),
1802 [
this, &rPropertyMap](
const auto& rName) -> beans::PropertyState {
1803 sal_uInt16 nItemWhich = 0;
1804 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( rName );
1805 lcl_GetPropertyWhich( pEntry, nItemWhich );
1806 return GetOnePropertyState(nItemWhich, pEntry);
1811void SAL_CALL ScCellRangesBase::setPropertyToDefault(
const OUString& aPropertyName )
1818 sal_uInt16 nItemWhich = 0;
1823 if ( !aRanges.empty() )
1829 sal_uInt16 aWIDs[3];
1830 aWIDs[0] = nItemWhich;
1838 pDocShell->GetDocFunc().ClearItems( *GetMarkData(), aWIDs,
true );
1844 bChartColAsHdr =
false;
1846 bChartRowAsHdr =
false;
1849 OUString aStyleName(
ScResId( STR_STYLENAME_STANDARD ) );
1850 pDocShell->GetDocFunc().ApplyStyle( *GetMarkData(), aStyleName,
true );
1855uno::Any SAL_CALL ScCellRangesBase::getPropertyDefault(
const OUString& aPropertyName )
1876 switch ( pEntry->
nWID )
1887 pPropSet->getPropertyValue(aPropertyName, rSet, aAny);
1892 switch ( pEntry->
nWID )
1900 ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Para );
1929 aAny <<= uno::Reference<sheet::XSheetConditionalEntries>(
1943 aAny <<= uno::Reference<beans::XPropertySet>(
1961uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellRangesBase::getPropertySetInfo()
1964 static uno::Reference<beans::XPropertySetInfo> aRef(
1971 sal_uInt16& rFirstItemId, sal_uInt16& rSecondItemId )
1973 rFirstItemId = rEntry.
nWID;
1977 switch ( rEntry.
nWID )
1987 sal_Int32 nIntVal = 0;
1988 if ( !(rValue >>= nIntVal) )
1989 throw lang::IllegalArgumentException();
2017 sal_Int16 nIntVal = 0;
2018 if ( !(rValue >>= nIntVal) )
2019 throw lang::IllegalArgumentException();
2027 sal_Int32 nRotVal = 0;
2028 if ( !(rValue >>= nRotVal) )
2029 throw lang::IllegalArgumentException();
2042 table::CellOrientation eOrient;
2043 if( rValue >>= eOrient )
2047 case table::CellOrientation_STANDARD:
2050 case table::CellOrientation_TOPBOTTOM:
2055 case table::CellOrientation_BOTTOMTOP:
2060 case table::CellOrientation_STACKED:
2078void SAL_CALL ScCellRangesBase::setPropertyValue(
2079 const OUString& aPropertyName,
const uno::Any& aValue )
2083 if ( !pDocShell || aRanges.empty() )
2084 throw uno::RuntimeException();
2089 throw beans::UnknownPropertyException(aPropertyName);
2091 SetOnePropertyValue( pEntry, aValue );
2101 if ( !aRanges.empty() )
2116 sal_uInt16 nFirstItem, nSecondItem;
2120 if ( nWhich != nFirstItem && nWhich != nSecondItem )
2123 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), aPattern,
true );
2127 switch ( pEntry->
nWID )
2135 for (
size_t i = 0, n = aRanges.size(); i < n; ++i)
2137 ScRange const & rRange = aRanges[
i];
2144 OUString
aStr = aCell.getString(&rDoc);
2146 aEngine.SetEditTextObjectPool(rDoc.
GetEditPool());
2154 SfxItemSet aAttr = aEngine.GetEmptyItemSet();
2155 aEngine.SetText(aStr);
2160 aEngine.QuickSetAttribs(aAttr,
ESelection(0, 0, 0,
aStr.getLength()));
2163 rDoc.
SetEditText(aRanges[0].aStart, aEngine.CreateTextObject());
2180 aStrVal, SfxStyleFamily::Para ));
2181 pDocShell->GetDocFunc().ApplyStyle( *GetMarkData(), aString,
true );
2186 table::TableBorder aBorder;
2187 if ( !aRanges.empty() && ( aValue >>= aBorder ) )
2199 table::TableBorder2 aBorder2;
2200 if ( !aRanges.empty() && ( aValue >>= aBorder2 ) )
2214 uno::Reference<sheet::XSheetConditionalEntries> xInterface(aValue, uno::UNO_QUERY);
2215 if ( !aRanges.empty() && xInterface.is() )
2228 SCTAB nTab = aRanges.front().aStart.Tab();
2233 for (
size_t i = 0;
i < aRanges.size(); ++
i)
2236 aRanges[i].aStart.Col(), aRanges[
i].aStart.Row(),
2237 aRanges[
i].aEnd.Col(), aRanges[
i].aEnd.Row() );
2243 auto pNew = std::make_unique<ScConditionalFormat>( 0, &rDoc );
2244 pFormat->
FillFormat( *pNew, rDoc, eGrammar );
2245 pNew->SetRange( aRanges );
2246 pDocShell->GetDocFunc().ReplaceConditionalFormat( 0, std::move(pNew), nTab, aRanges );
2250 for (
size_t i = 0;
i < aRanges.size(); ++
i)
2252 pDocShell->SetDocumentModified();
2261 uno::Reference<beans::XPropertySet> xInterface(aValue, uno::UNO_QUERY);
2262 if ( !aRanges.empty() && xInterface.is() )
2275 std::unique_ptr<ScValidationData> pNewData(
2282 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), aPattern,
true );
2291uno::Any SAL_CALL ScCellRangesBase::getPropertyValue(
const OUString& aPropertyName )
2295 if ( !pDocShell || aRanges.empty() )
2296 throw uno::RuntimeException();
2301 throw beans::UnknownPropertyException(aPropertyName);
2304 GetOnePropertyValue( pEntry, aAny );
2318 switch ( pEntry->
nWID )
2329 GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang );
2330 rAny <<= static_cast<sal_Int32>(nOldFormat);
2345 pPropSet->getPropertyValue(*pEntry, *pDataSet, rAny);
2350 switch ( pEntry->
nWID )
2353 rAny <<= bChartColAsHdr;
2356 rAny <<= bChartRowAsHdr;
2360 OUString aStyleName;
2361 const ScStyleSheet* pStyle = pDocShell->GetDocument().GetSelectionStyle(*GetMarkData());
2363 aStyleName = pStyle->
GetName();
2365 aStyleName, SfxStyleFamily::Para );
2372 if ( !aRanges.empty() )
2374 const ScRange & rFirst = aRanges[ 0 ];
2380 aMark.SetMarkArea( rFirst );
2381 aMark.SelectTable( rFirst.
aStart.
Tab(),
true );
2409 rAny <<= uno::Reference<sheet::XSheetConditionalEntries>(
2429 rAny <<= uno::Reference<beans::XPropertySet>(
2450 rAny <<= pPattern->
GetKey();
2456void SAL_CALL ScCellRangesBase::addPropertyChangeListener(
const OUString& ,
2457 const uno::Reference<beans::XPropertyChangeListener>& )
2460 if ( aRanges.empty() )
2461 throw uno::RuntimeException();
2463 OSL_FAIL(
"not implemented");
2466void SAL_CALL ScCellRangesBase::removePropertyChangeListener(
const OUString& ,
2467 const uno::Reference<beans::XPropertyChangeListener>& )
2470 if ( aRanges.empty() )
2471 throw uno::RuntimeException();
2473 OSL_FAIL(
"not implemented");
2476void SAL_CALL ScCellRangesBase::addVetoableChangeListener(
const OUString&,
2477 const uno::Reference<beans::XVetoableChangeListener>&)
2479 OSL_FAIL(
"not implemented");
2482void SAL_CALL ScCellRangesBase::removeVetoableChangeListener(
const OUString&,
2483 const uno::Reference<beans::XVetoableChangeListener>&)
2485 OSL_FAIL(
"not implemented");
2490void SAL_CALL ScCellRangesBase::setPropertyValues(
const uno::Sequence< OUString >& aPropertyNames,
2491 const uno::Sequence< uno::Any >& aValues )
2495 sal_Int32
nCount(aPropertyNames.getLength());
2496 sal_Int32 nValues(aValues.getLength());
2497 if (nCount != nValues)
2498 throw lang::IllegalArgumentException();
2500 if ( !(pDocShell && nCount) )
2504 const OUString* pNames = aPropertyNames.getConstArray();
2516 pEntryArray[
i] = pEntry;
2523 SetOnePropertyValue( pEntry, pValues[i] );
2525 catch ( lang::IllegalArgumentException& )
2534 std::unique_ptr<ScPatternAttr> pOldPattern;
2535 std::unique_ptr<ScPatternAttr> pNewPattern;
2548 pOldPattern.reset(
new ScPatternAttr( *GetCurrentAttrsDeep() ));
2549 pOldPattern->GetItemSet().ClearInvalidItems();
2555 sal_uInt16 nFirstItem, nSecondItem;
2560 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nFirstItem ) );
2562 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nSecondItem ) );
2567 SetOnePropertyValue( pEntry, pValues[i] );
2572 if ( pNewPattern && !aRanges.empty() )
2573 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), *pNewPattern,
true );
2576uno::Sequence<uno::Any> SAL_CALL ScCellRangesBase::getPropertyValues(
2577 const uno::Sequence< OUString >& aPropertyNames )
2583 uno::Sequence<uno::Any> aRet(aPropertyNames.getLength());
2584 uno::Any* pProperties = aRet.getArray();
2585 for(sal_Int32 i = 0;
i < aPropertyNames.getLength();
i++)
2588 GetOnePropertyValue( pEntry, pProperties[i] );
2593void SAL_CALL ScCellRangesBase::addPropertiesChangeListener(
const uno::Sequence< OUString >& ,
2594 const uno::Reference< beans::XPropertiesChangeListener >& )
2596 OSL_FAIL(
"not implemented");
2599void SAL_CALL ScCellRangesBase::removePropertiesChangeListener(
const uno::Reference< beans::XPropertiesChangeListener >& )
2601 OSL_FAIL(
"not implemented");
2604void SAL_CALL ScCellRangesBase::firePropertiesChangeEvent(
const uno::Sequence< OUString >& ,
2605 const uno::Reference< beans::XPropertiesChangeListener >& )
2607 OSL_FAIL(
"not implemented");
2612 if ( pDocShell && (rHint.
GetId() == SfxHintId::ScDataChanged))
2618 bGotDataChangedHint =
true;
2623uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::setPropertyValuesTolerant(
const uno::Sequence< OUString >& aPropertyNames,
2624 const uno::Sequence< uno::Any >& aValues )
2628 sal_Int32
nCount(aPropertyNames.getLength());
2629 sal_Int32 nValues(aValues.getLength());
2630 if (nCount != nValues)
2631 throw lang::IllegalArgumentException();
2633 if ( pDocShell && nCount )
2635 uno::Sequence < beans::SetPropertyTolerantFailed > aReturns(nCount);
2636 beans::SetPropertyTolerantFailed* pReturns = aReturns.getArray();
2639 const OUString* pNames = aPropertyNames.getConstArray();
2651 pMapArray[
i] = pEntry;
2658 SetOnePropertyValue( pEntry, pValues[i] );
2660 catch ( lang::IllegalArgumentException& )
2669 std::unique_ptr<ScPatternAttr> pOldPattern;
2670 std::unique_ptr<ScPatternAttr> pNewPattern;
2672 sal_Int32 nFailed(0);
2678 if ( pEntry && ((pEntry->
nFlags & beans::PropertyAttribute::READONLY) == 0))
2684 pOldPattern.reset(
new ScPatternAttr( *GetCurrentAttrsDeep() ));
2685 pOldPattern->GetItemSet().ClearInvalidItems();
2692 sal_uInt16 nFirstItem, nSecondItem;
2697 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nFirstItem ) );
2699 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nSecondItem ) );
2701 catch ( lang::IllegalArgumentException& )
2703 pReturns[nFailed].Name = pNames[
i];
2704 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
2712 SetOnePropertyValue( pEntry, pValues[i] );
2714 catch ( lang::IllegalArgumentException& )
2716 pReturns[nFailed].Name = pNames[
i];
2717 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
2723 pReturns[nFailed].Name = pNames[
i];
2725 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
2727 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2731 if ( pNewPattern && !aRanges.empty() )
2732 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), *pNewPattern,
true );
2734 aReturns.realloc(nFailed);
2738 return uno::Sequence < beans::SetPropertyTolerantFailed >();
2741uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL ScCellRangesBase::getPropertyValuesTolerant(
const uno::Sequence< OUString >& aPropertyNames )
2745 sal_Int32
nCount(aPropertyNames.getLength());
2746 uno::Sequence < beans::GetPropertyTolerantResult > aReturns(nCount);
2747 beans::GetPropertyTolerantResult* pReturns = aReturns.getArray();
2751 for(sal_Int32 i = 0;
i <
nCount;
i++)
2756 pReturns[
i].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2760 sal_uInt16 nItemWhich = 0;
2762 pReturns[
i].State = GetOnePropertyState( nItemWhich, pEntry );
2763 GetOnePropertyValue( pEntry, pReturns[i].Value );
2764 pReturns[
i].Result = beans::TolerantPropertySetResultType::SUCCESS;
2770uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL ScCellRangesBase::getDirectPropertyValuesTolerant(
const uno::Sequence< OUString >& aPropertyNames )
2774 sal_Int32
nCount(aPropertyNames.getLength());
2775 uno::Sequence < beans::GetDirectPropertyTolerantResult > aReturns(nCount);
2776 beans::GetDirectPropertyTolerantResult* pReturns = aReturns.getArray();
2781 for(sal_Int32 i = 0;
i <
nCount;
i++)
2786 pReturns[
i].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2790 sal_uInt16 nItemWhich = 0;
2792 pReturns[j].State = GetOnePropertyState( nItemWhich, pEntry );
2793 if (pReturns[j].
State == beans::PropertyState_DIRECT_VALUE)
2795 GetOnePropertyValue( pEntry, pReturns[j].Value );
2796 pReturns[j].Result = beans::TolerantPropertySetResultType::SUCCESS;
2797 pReturns[j].Name = aPropertyNames[
i];
2803 aReturns.realloc(j);
2809void SAL_CALL ScCellRangesBase::decrementIndent()
2812 if ( pDocShell && !aRanges.empty() )
2816 aMarkData.MarkToMulti();
2817 pDocShell->GetDocFunc().ChangeIndent( aMarkData,
false,
true );
2821void SAL_CALL ScCellRangesBase::incrementIndent()
2824 if ( pDocShell && !aRanges.empty() )
2828 aMarkData.MarkToMulti();
2829 pDocShell->GetDocFunc().ChangeIndent( aMarkData,
true,
true );
2835std::unique_ptr<ScMemChart> ScCellRangesBase::CreateMemChart_Impl()
const
2837 if ( pDocShell && !aRanges.empty() )
2840 if ( aRanges.size() == 1 )
2846 const ScDocument & rDoc = pDocShell->GetDocument();
2847 const ScRange & rRange = aRanges[0];
2855 if (!pDocShell->GetDocument().GetDataStart( nTab, nStartX, nStartY ))
2863 if (!pDocShell->GetDocument().GetTableArea( nTab, nEndX, nEndY ))
2869 xChartRanges =
new ScRangeList(
ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
2872 if (!xChartRanges.
is())
2877 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
2879 return aArr.CreateMemChart();
2884uno::Sequence< uno::Sequence<double> > SAL_CALL ScCellRangesBase::getData()
2887 std::unique_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
2890 sal_Int32 nColCount = pMemChart->GetColCount();
2891 sal_Int32 nRowCount =
static_cast<sal_Int32
>(pMemChart->GetRowCount());
2893 uno::Sequence< uno::Sequence<double> > aRowSeq( nRowCount );
2894 uno::Sequence<double>* pRowAry = aRowSeq.getArray();
2895 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
2897 uno::Sequence<double> aColSeq( nColCount );
2898 double* pColAry = aColSeq.getArray();
2899 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
2900 pColAry[nCol] = pMemChart->GetData( nCol, nRow );
2902 pRowAry[nRow] = aColSeq;
2911ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( sal_Int32 nDataColumns, sal_Int32 nDataRows )
const
2913 if ( aRanges.size() == 1 )
2915 const ScDocument & rDoc = pDocShell->GetDocument();
2916 const ScRange & rRange = aRanges[0];
2924 sal_Int32 nEndColumn = nDataColumns - 1 + ( bChartColAsHdr ? 1 : 0 );
2925 if ( nEndColumn < 0 )
2927 if ( nEndColumn > rDoc.
MaxCol() )
2928 nEndColumn = rDoc.
MaxCol();
2930 sal_Int32 nEndRow = nDataRows - 1 + ( bChartRowAsHdr ? 1 : 0 );
2933 if ( nEndRow > rDoc.
MaxRow() )
2937 return xChartRanges;
2944void SAL_CALL ScCellRangesBase::setData(
const uno::Sequence< uno::Sequence<double> >& aData )
2948 sal_Int32 nRowCount =
aData.getLength();
2949 sal_Int32 nColCount = nRowCount ?
aData[0].getLength() : 0;
2950 ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, nRowCount );
2951 if ( pDocShell && xChartRanges.
is() )
2955 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
2962 for (sal_Int32 nRow=0; nRow<nRowCount; nRow++)
2964 const uno::Sequence<double>& rRowSeq =
aData[nRow];
2965 const double* pArray = rRowSeq.getConstArray();
2966 nColCount = rRowSeq.getLength();
2967 for (sal_Int32 nCol=0; nCol<nColCount; nCol++)
2970 sal::static_int_cast<SCCOL>(nCol),
2971 sal::static_int_cast<SCROW>(nRow) );
2974 double fVal = pArray[nCol];
2975 if ( fVal == DBL_MIN )
2978 rDoc.
SetValue(*pPos, pArray[nCol]);
2984 PaintGridRanges_Impl();
2985 pDocShell->SetDocumentModified();
2986 ForceChartListener_Impl();
2993 throw uno::RuntimeException();
2996uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getRowDescriptions()
2999 std::unique_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
3002 sal_Int32 nRowCount =
static_cast<sal_Int32
>(pMemChart->GetRowCount());
3003 uno::Sequence<OUString>
aSeq( nRowCount );
3004 OUString* pAry =
aSeq.getArray();
3005 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
3006 pAry[nRow] = pMemChart->GetRowText(nRow);
3013void SAL_CALL ScCellRangesBase::setRowDescriptions(
3014 const uno::Sequence<OUString>& aRowDescriptions )
3018 if ( bChartColAsHdr )
3020 sal_Int32 nRowCount = aRowDescriptions.getLength();
3021 ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( 1, nRowCount );
3022 if ( pDocShell && xChartRanges.
is() )
3026 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
3032 const OUString* pArray = aRowDescriptions.getConstArray();
3033 for (sal_Int32 nRow=0; nRow<nRowCount; nRow++)
3036 static_cast<SCSIZE>(nRow) );
3039 const OUString&
aStr = pArray[nRow];
3052 PaintGridRanges_Impl();
3053 pDocShell->SetDocumentModified();
3054 ForceChartListener_Impl();
3062 throw uno::RuntimeException();
3065uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getColumnDescriptions()
3068 std::unique_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
3071 sal_Int32 nColCount = pMemChart->GetColCount();
3072 uno::Sequence<OUString>
aSeq( nColCount );
3073 OUString* pAry =
aSeq.getArray();
3074 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
3075 pAry[nCol] = pMemChart->GetColText(nCol);
3082void SAL_CALL ScCellRangesBase::setColumnDescriptions(
3083 const uno::Sequence<OUString>& aColumnDescriptions )
3087 if ( bChartRowAsHdr )
3089 sal_Int32 nColCount = aColumnDescriptions.getLength();
3090 ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, 1 );
3091 if ( pDocShell && xChartRanges.
is() )
3095 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
3101 const OUString* pArray = aColumnDescriptions.getConstArray();
3102 for (sal_Int32 nCol=0; nCol<nColCount; nCol++)
3105 sal::static_int_cast<SCCOL>(nCol) );
3108 const OUString&
aStr = pArray[nCol];
3121 PaintGridRanges_Impl();
3122 pDocShell->SetDocumentModified();
3123 ForceChartListener_Impl();
3131 throw uno::RuntimeException();
3134void ScCellRangesBase::ForceChartListener_Impl()
3147 for (
auto const& it : rListeners)
3151 if (
p->GetUnoSource() ==
static_cast<chart::XChartData*
>(
this) &&
p->IsDirty())
3156void SAL_CALL ScCellRangesBase::addChartDataChangeEventListener(
const uno::Reference<
3157 chart::XChartDataChangeEventListener >& aListener )
3160 if ( !pDocShell || aRanges.empty() )
3169 if (
aName.isEmpty())
3174 pListener->
SetUno( aListener,
this );
3175 pColl->
insert( pListener );
3179void SAL_CALL ScCellRangesBase::removeChartDataChangeEventListener(
const uno::Reference<
3180 chart::XChartDataChangeEventListener >& aListener )
3183 if ( pDocShell && !aRanges.empty() )
3187 pColl->
FreeUno( aListener,
this );
3191double SAL_CALL ScCellRangesBase::getNotANumber()
3197sal_Bool SAL_CALL ScCellRangesBase::isNotANumber(
double nNumber )
3200 return (nNumber == DBL_MIN);
3205void SAL_CALL ScCellRangesBase::addModifyListener(
const uno::Reference<util::XModifyListener>& aListener)
3208 if ( aRanges.empty() )
3209 throw uno::RuntimeException();
3211 aValueListeners.emplace_back( aListener );
3213 if ( aValueListeners.size() == 1 )
3215 if (!pValueListener)
3216 pValueListener.reset(
new ScLinkListener(
LINK(
this, ScCellRangesBase, ValueListenerHdl ) ) );
3219 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; i++)
3226void SAL_CALL ScCellRangesBase::removeModifyListener(
const uno::Reference<util::XModifyListener>& aListener )
3230 if ( aRanges.empty() )
3231 throw uno::RuntimeException();
3235 sal_uInt16
nCount = aValueListeners.size();
3236 for ( sal_uInt16 n=nCount;
n--; )
3238 uno::Reference<util::XModifyListener>& rObj = aValueListeners[
n];
3239 if ( rObj == aListener )
3241 aValueListeners.erase( aValueListeners.begin() + n );
3243 if ( aValueListeners.empty() )
3246 pValueListener->EndListeningAll();
3258uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryVisibleCells()
3269 SCCOL nCol = 0, nLastCol;
3270 while (nCol <= rDoc.
MaxCol())
3272 if (rDoc.
ColHidden(nCol, nTab,
nullptr, &nLastCol))
3274 aMarkData.SetMultiMarkArea(
ScRange(nCol, 0, nTab, nLastCol, rDoc.
MaxRow(), nTab),
false);
3276 nCol = nLastCol + 1;
3279 SCROW nRow = 0, nLastRow;
3280 while (nRow <= rDoc.
MaxRow())
3282 if (rDoc.
RowHidden(nRow, nTab,
nullptr, &nLastRow))
3284 aMarkData.SetMultiMarkArea(
ScRange(0, nRow, nTab, rDoc.
MaxCol(), nLastRow, nTab),
false);
3286 nRow = nLastRow + 1;
3290 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3291 return new ScCellRangesObj( pDocShell, aNewRanges );
3297uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryEmptyCells()
3307 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i)
3309 ScRange const & rRange = aRanges[
i ];
3312 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3315 if (!aIter.isEmpty())
3316 aMarkData.SetMultiMarkArea(aIter.GetPos(),
false);
3323 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3325 return new ScCellRangesObj( pDocShell, aNewRanges );
3331uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryContentCells(
3332 sal_Int16 nContentFlags )
3342 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
3344 ScRange const & rRange = aRanges[
i ];
3347 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3350 switch (aIter.getType())
3353 if ( nContentFlags & sheet::CellFlags::STRING )
3357 if ( (nContentFlags & sheet::CellFlags::STRING) || (nContentFlags & sheet::CellFlags::FORMATTED) )
3365 if ( (nContentFlags & (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME))
3366 == (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME) )
3375 if ((nTyp == SvNumFormatType::DATE) || (nTyp == SvNumFormatType::TIME) ||
3376 (nTyp == SvNumFormatType::DATETIME))
3378 if ( nContentFlags & sheet::CellFlags::DATETIME )
3383 if ( nContentFlags & sheet::CellFlags::VALUE )
3395 aMarkData.SetMultiMarkArea(aIter.GetPos());
3399 if (nContentFlags & sheet::CellFlags::ANNOTATION)
3401 std::vector<sc::NoteEntry> aNotes;
3404 for (
const auto& i : aNotes)
3406 aMarkData.SetMultiMarkArea(
i.maPos);
3411 if (aMarkData.IsMultiMarked())
3412 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3414 return new ScCellRangesObj( pDocShell, aNewRanges );
3420uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryFormulaCells(
3421 sal_Int32 nResultFlags )
3431 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
3433 ScRange const & rRange = aRanges[
i ];
3436 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3442 if (pFCell->
GetErrCode() != FormulaError::NONE)
3444 if ( nResultFlags & sheet::FormulaResult::ERROR )
3449 if ( nResultFlags & sheet::FormulaResult::VALUE )
3454 if ( nResultFlags & sheet::FormulaResult::STRING )
3459 aMarkData.SetMultiMarkArea(aIter.GetPos());
3465 if (aMarkData.IsMultiMarked())
3466 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3468 return new ScCellRangesObj( pDocShell, aNewRanges );
3474uno::Reference<sheet::XSheetCellRanges> ScCellRangesBase::QueryDifferences_Impl(
3475 const table::CellAddress& aCompare,
bool bColumnDiff)
3479 size_t nRangeCount = aRanges.size();
3490 ScRange aCmpRange, aCellRange;
3492 aCmpRange =
ScRange( 0,nCmpPos,nTab, rDoc.
MaxCol(),nCmpPos,nTab );
3496 for (
bool bHasCell = aCmpIter.first(); bHasCell; bHasCell = aCmpIter.next())
3498 SCCOLROW nCellPos = bColumnDiff ?
static_cast<SCCOLROW>(aCmpIter.GetPos().Col()) :
static_cast<SCCOLROW>(aCmpIter.GetPos().Row());
3500 aCellRange =
ScRange(
static_cast<SCCOL>(nCellPos),0,nTab,
3501 static_cast<SCCOL>(nCellPos),rDoc.
MaxRow(),nTab );
3503 aCellRange =
ScRange( 0,nCellPos,nTab, rDoc.
MaxCol(),nCellPos,nTab );
3505 for (i=0;
i<nRangeCount;
i++)
3507 ScRange aRange( aRanges[ i ] );
3508 if ( aRange.Intersects( aCellRange ) )
3512 aRange.aStart.SetCol(
static_cast<SCCOL>(nCellPos));
3513 aRange.aEnd.SetCol(
static_cast<SCCOL>(nCellPos));
3517 aRange.aStart.SetRow(nCellPos);
3518 aRange.aEnd.SetRow(nCellPos);
3520 aMarkData.SetMultiMarkArea( aRange );
3529 for (i=0;
i<nRangeCount;
i++)
3531 ScRange const & rRange = aRanges[
i ];
3534 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3537 aCmpAddr =
ScAddress( aIter.GetPos().Col(), nCmpPos, aIter.GetPos().Tab() );
3539 aCmpAddr =
ScAddress(
static_cast<SCCOL>(nCmpPos), aIter.GetPos().Row(), aIter.GetPos().Tab() );
3541 ScRange aOneRange(aIter.GetPos());
3542 if (!aIter.equalsWithoutFormat(aCmpAddr))
3543 aMarkData.SetMultiMarkArea( aOneRange );
3545 aMarkData.SetMultiMarkArea( aOneRange,
false );
3550 if (aMarkData.IsMultiMarked())
3551 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3553 return new ScCellRangesObj( pDocShell, aNewRanges );
3558uno::Reference<sheet::XSheetCellRanges > SAL_CALL ScCellRangesBase::queryColumnDifferences(
3559 const table::CellAddress& aCompare )
3562 return QueryDifferences_Impl( aCompare,
true );
3565uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryRowDifferences(
3566 const table::CellAddress& aCompare )
3569 return QueryDifferences_Impl( aCompare,
false );
3572uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryIntersection(
3573 const table::CellRangeAddress& aRange )
3576 ScRange aMask(
static_cast<SCCOL>(aRange.StartColumn),
static_cast<SCROW>(aRange.StartRow), aRange.Sheet,
3577 static_cast<SCCOL>(aRange.EndColumn),
static_cast<SCROW>(aRange.EndRow), aRange.Sheet );
3580 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
3582 ScRange aTemp( aRanges[ i ] );
3583 if ( aTemp.Intersects( aMask ) )
3584 aNew.
Join(
ScRange( std::max( aTemp.aStart.Col(), aMask.aStart.Col() ),
3585 std::max( aTemp.aStart.Row(), aMask.aStart.Row() ),
3586 std::max( aTemp.aStart.Tab(), aMask.aStart.Tab() ),
3587 std::min( aTemp.aEnd.Col(), aMask.aEnd.Col() ),
3588 std::min( aTemp.aEnd.Row(), aMask.aEnd.Row() ),
3589 std::min( aTemp.aEnd.Tab(), aMask.aEnd.Tab() ) ) );
3592 return new ScCellRangesObj( pDocShell, aNew );
3597uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryPrecedents(
3613 aMarkData.MarkFromRangeList( aNewRanges,
false );
3615 for (
size_t nR = 0, nCount = aNewRanges.
size(); nR<nCount; ++nR)
3617 ScRange const & rRange = aNewRanges[ nR];
3619 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3626 while ( aRefIter.GetNextRef( aRefRange) )
3628 if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aRefRange ) )
3630 aMarkData.SetMultiMarkArea(aRefRange);
3635 aMarkData.FillRangeListWithMarks( &aNewRanges,
true );
3637 while ( bRecursive && bFound );
3639 return new ScCellRangesObj( pDocShell, aNewRanges );
3645uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryDependents(
3661 aMarkData.MarkFromRangeList( aNewRanges,
false );
3666 for (
bool bHasCell = aCellIter.first(); bHasCell; bHasCell = aCellIter.next())
3674 while ( aIter.GetNextRef( aRefRange) && !bMark )
3676 size_t nRangesCount = aNewRanges.
size();
3677 for (
size_t nR = 0; nR < nRangesCount; ++nR)
3679 ScRange const & rRange = aNewRanges[ nR ];
3689 ScRange aCellRange(aCellIter.GetPos());
3690 if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aCellRange ) )
3692 aMarkData.SetMultiMarkArea(aCellRange);
3696 aMarkData.FillRangeListWithMarks( &aNewRanges,
true );
3698 while ( bRecursive && bFound );
3700 return new ScCellRangesObj( pDocShell, aNewRanges );
3708uno::Reference<util::XSearchDescriptor> SAL_CALL ScCellRangesBase::createSearchDescriptor()
3713uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangesBase::findAll(
3714 const uno::Reference<util::XSearchDescriptor>& xDesc )
3718 uno::Reference<container::XIndexAccess> xRet;
3719 if ( pDocShell && xDesc.is() )
3728 pSearchItem->
SetCommand( SvxSearchCmd::FIND_ALL );
3734 OUString aDummyUndo;
3739 bool bMatchedRangesWereClamped =
false;
3741 *pSearchItem, nCol, nRow, nTab, aMark, aMatchedRanges, aDummyUndo,
nullptr, bMatchedRangesWereClamped);
3745 xRet.set(
new ScCellRangesObj( pDocShell, aMatchedRanges ));
3753uno::Reference<uno::XInterface> ScCellRangesBase::Find_Impl(
3754 const uno::Reference<util::XSearchDescriptor>& xDesc,
3757 uno::Reference<uno::XInterface> xRet;
3758 if ( pDocShell && xDesc.is() )
3767 pSearchItem->
SetCommand( SvxSearchCmd::FIND );
3777 pLastPos->
GetVars( nCol, nRow, nTab );
3784 OUString aDummyUndo;
3786 bool bMatchedRangesWereClamped;
3788 *pSearchItem, nCol, nRow, nTab, aMark, aMatchedRanges, aDummyUndo,
nullptr, bMatchedRangesWereClamped);
3791 ScAddress aFoundPos( nCol, nRow, nTab );
3792 xRet.set(cppu::getXWeak(
new ScCellObj( pDocShell, aFoundPos )));
3800uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findFirst(
3801 const uno::Reference<util::XSearchDescriptor>& xDesc )
3804 return Find_Impl( xDesc,
nullptr );
3807uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findNext(
3808 const uno::Reference<uno::XInterface>& xStartAt,
3809 const uno::Reference<util::XSearchDescriptor >& xDesc )
3812 if ( xStartAt.is() )
3814 ScCellRangesBase* pRangesImp =
dynamic_cast<ScCellRangesBase*
>( xStartAt.get() );
3815 if ( pRangesImp && pRangesImp->GetDocShell() == pDocShell )
3817 const ScRangeList& rStartRanges = pRangesImp->GetRangeList();
3818 if ( rStartRanges.
size() == 1 )
3820 ScAddress aStartPos = rStartRanges[ 0 ].aStart;
3821 return Find_Impl( xDesc, &aStartPos );
3830uno::Reference<util::XReplaceDescriptor> SAL_CALL ScCellRangesBase::createReplaceDescriptor()
3835sal_Int32 SAL_CALL ScCellRangesBase::replaceAll(
const uno::Reference<util::XSearchDescriptor>& xDesc )
3838 sal_uInt64 nReplaced = 0;
3839 if ( pDocShell && xDesc.is() )
3849 pSearchItem->
SetCommand( SvxSearchCmd::REPLACE_ALL );
3856 bool bProtected = !pDocShell->IsEditable();
3857 for (
const auto& rTab : aMark)
3859 if (rTab >= nTabCount)
3870 SCTAB nTab = aMark.GetFirstSelected();
3879 pUndoDoc->InitUndo( rDoc, nTab, nTab );
3881 for (
const auto& rTab : aMark)
3883 if (rTab >= nTabCount)
3885 if (rTab != nTab && bUndo)
3886 pUndoDoc->AddUndoTab( rTab, rTab );
3888 std::unique_ptr<ScMarkData> pUndoMark;
3892 bool bFound =
false;
3896 bool bMatchedRangesWereClamped;
3898 *pSearchItem, nCol, nRow, nTab, aMark, aMatchedRanges, aUndoStr, pUndoDoc.get(), bMatchedRangesWereClamped );
3902 nReplaced = pUndoDoc->GetCellCount();
3904 pDocShell->GetUndoManager()->AddUndoAction(
3905 std::make_unique<ScUndoReplace>( pDocShell, *pUndoMark, nCol, nRow, nTab,
3906 aUndoStr, std::move(pUndoDoc), pSearchItem ) );
3908 pDocShell->PostPaintGridAll();
3909 pDocShell->SetDocumentModified();
3919 : ScCellRangesBase(pDocSh, rR)
3923ScCellRangesObj::~ScCellRangesObj()
3927void ScCellRangesObj::RefChanged()
3929 ScCellRangesBase::RefChanged();
3943 return ScCellRangesBase::queryInterface( rType );
3946void SAL_CALL ScCellRangesObj::acquire() noexcept
3948 ScCellRangesBase::acquire();
3951void SAL_CALL ScCellRangesObj::release() noexcept
3953 ScCellRangesBase::release();
3956uno::Sequence<uno::Type> SAL_CALL ScCellRangesObj::getTypes()
3959 ScCellRangesBase::getTypes(),
3960 uno::Sequence<uno::Type>
3969uno::Sequence<sal_Int8> SAL_CALL ScCellRangesObj::getImplementationId()
3971 return css::uno::Sequence<sal_Int8>();
3980 if ( pDocSh && nIndex >= 0 && nIndex < sal::static_int_cast<sal_Int32>(rRanges.
size()) )
3992uno::Sequence<table::CellRangeAddress> SAL_CALL ScCellRangesObj::getRangeAddresses()
3998 if ( pDocSh && nCount )
4000 table::CellRangeAddress aRangeAddress;
4001 uno::Sequence<table::CellRangeAddress>
aSeq(nCount);
4002 table::CellRangeAddress* pAry =
aSeq.getArray();
4006 pAry[
i] = aRangeAddress;
4014uno::Reference<container::XEnumerationAccess> SAL_CALL ScCellRangesObj::getCells()
4030OUString SAL_CALL ScCellRangesObj::getRangeAddressesAsString()
4043void SAL_CALL ScCellRangesObj::addRangeAddress(
const table::CellRangeAddress& rRange,
4048 static_cast<SCROW>(rRange.StartRow),
4049 static_cast<SCTAB>(rRange.Sheet),
4050 static_cast<SCCOL>(rRange.EndColumn),
4051 static_cast<SCROW>(rRange.EndRow),
4052 static_cast<SCTAB>(rRange.Sheet));
4053 AddRange(aRange, bMergeRanges);
4058 sal_uInt16
nCount = rNamedEntries.size();
4060 if ( rNamedEntries[
n].GetRange() == rRange )
4061 rNamedEntries.erase( rNamedEntries.begin() +
n );
4064void SAL_CALL ScCellRangesObj::removeRangeAddress(
const table::CellRangeAddress& rRange )
4071 for (
size_t i = 0;
i < rRanges.
size(); ++
i)
4073 if (rRanges[ i].aStart.Tab() == rRange.Sheet)
4079 aNotSheetRanges.
push_back( rRanges[ i ] );
4082 ScMarkData aMarkData(GetDocument()->GetSheetLimits());
4083 aMarkData.MarkFromRangeList( aSheetRanges,
false );
4085 static_cast<SCROW>(rRange.StartRow),
4086 static_cast<SCTAB>(rRange.Sheet),
4087 static_cast<SCCOL>(rRange.EndColumn),
4088 static_cast<SCROW>(rRange.EndRow),
4089 static_cast<SCTAB>(rRange.Sheet));
4090 if (aMarkData.GetTableSelect( aRange.aStart.Tab() ))
4092 aMarkData.MarkToMulti();
4093 if (!aMarkData.IsAllMarked( aRange ) )
4094 throw container::NoSuchElementException();
4096 aMarkData.SetMultiMarkArea( aRange,
false );
4100 SetNewRanges(aNotSheetRanges);
4102 aMarkData.FillRangeListWithMarks( &aNew,
false );
4103 for (
size_t j = 0; j < aNew.
size(); ++j)
4105 AddRange(aNew[ j ],
false);
4109void SAL_CALL ScCellRangesObj::addRangeAddresses(
const uno::Sequence<table::CellRangeAddress >& rRanges,
4113 for (
const table::CellRangeAddress& rRange : rRanges)
4116 static_cast<SCROW>(rRange.StartRow),
4117 static_cast<SCTAB>(rRange.Sheet),
4118 static_cast<SCCOL>(rRange.EndColumn),
4119 static_cast<SCROW>(rRange.EndRow),
4120 static_cast<SCTAB>(rRange.Sheet));
4121 AddRange(aRange, bMergeRanges);
4125void SAL_CALL ScCellRangesObj::removeRangeAddresses(
const uno::Sequence<table::CellRangeAddress >& rRangeSeq )
4128 for (
const table::CellRangeAddress& rRange : rRangeSeq)
4130 removeRangeAddress(rRange);
4136static void lcl_RemoveNamedEntry( std::vector<ScCellRangesObj::ScNamedEntry>& rNamedEntries, std::u16string_view rName )
4138 sal_uInt16
nCount = rNamedEntries.size();
4140 if ( rNamedEntries[
n].
GetName() == rName )
4141 rNamedEntries.erase( rNamedEntries.begin() +
n );
4144void SAL_CALL ScCellRangesObj::insertByName(
const OUString& aName,
const uno::Any& aElement )
4152 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
4153 if ( pDocSh && xInterface.is() )
4155 ScCellRangesBase* pRangesImp =
dynamic_cast<ScCellRangesBase*
>( xInterface.get() );
4156 if ( pRangesImp && pRangesImp->GetDocShell() == pDocSh )
4160 if ( !
aName.isEmpty() )
4162 size_t nNamedCount = m_aNamedEntries.size();
4163 for (
size_t n = 0;
n < nNamedCount;
n++)
4166 throw container::ElementExistException();
4171 const ScRangeList& rAddRanges = pRangesImp->GetRangeList();
4172 size_t nAddCount = rAddRanges.
size();
4173 for (
size_t i = 0;
i < nAddCount;
i++ )
4174 aNew.
Join( rAddRanges[ i ] );
4178 if ( !
aName.isEmpty() && nAddCount == 1 )
4183 m_aNamedEntries.emplace_back( ScNamedEntry{
aName, rAddRanges[ 0 ]} );
4191 throw lang::IllegalArgumentException();
4196 std::u16string_view rName,
size_t& rIndex )
4205 if ( aRangeStr == rName )
4217 const OUString& rName,
ScRange& rFound )
4224 rFound = rRanges[
nIndex ];
4239 rFound = aCellRange;
4246 for (
const auto & rNamedEntry : rNamedEntries)
4247 if ( rNamedEntry.GetName() == rName )
4251 const ScRange& rComp = rNamedEntry.GetRange();
4264void SAL_CALL ScCellRangesObj::removeByName(
const OUString& aName )
4275 for (
size_t i = 0, nCount = rRanges.
size(); i < nCount; i++ )
4289 sal_uInt16
nCount = m_aNamedEntries.size();
4290 for (sal_uInt16 n=0;
n<
nCount && !bValid;
n++)
4294 aDiff.
push_back(m_aNamedEntries[n].GetRange());
4300 ScMarkData aMarkData(GetDocument()->GetSheetLimits());
4301 aMarkData.MarkFromRangeList( rRanges,
false );
4303 for (
size_t i = 0, nDiffCount = aDiff.
size(); i < nDiffCount; i++ )
4305 ScRange const & rDiffRange = aDiff[
i ];
4306 if (aMarkData.GetTableSelect( rDiffRange.
aStart.
Tab() ))
4307 aMarkData.SetMultiMarkArea( rDiffRange,
false );
4311 aMarkData.FillRangeListWithMarks( &aNew,
false );
4318 if (!m_aNamedEntries.empty())
4322 throw container::NoSuchElementException();
4327void SAL_CALL ScCellRangesObj::replaceByName(
const OUString& aName,
const uno::Any& aElement )
4331 removeByName( aName );
4332 insertByName( aName, aElement );
4337uno::Any SAL_CALL ScCellRangesObj::getByName(
const OUString& aName )
4346 pDocSh, aName, aRange))
4347 throw container::NoSuchElementException();
4349 uno::Reference<table::XCellRange> xRange;
4360 const ScRange& rRange, OUString& rName )
4362 sal_uInt16
nCount = rNamedEntries.size();
4364 if (rNamedEntries[
i].GetRange() == rRange)
4366 rName = rNamedEntries[
i].GetName();
4372uno::Sequence<OUString> SAL_CALL ScCellRangesObj::getElementNames()
4384 uno::Sequence<OUString>
aSeq(nCount);
4385 OUString* pAry =
aSeq.getArray();
4389 ScRange const & rRange = rRanges[
i ];
4390 if (m_aNamedEntries.empty() ||
4395 pAry[
i] = aRangeStr;
4402sal_Bool SAL_CALL ScCellRangesObj::hasByName(
const OUString& aName )
4414uno::Reference<container::XEnumeration> SAL_CALL ScCellRangesObj::createEnumeration()
4417 return new ScIndexEnumeration(
this,
"com.sun.star.sheet.SheetCellRangesEnumeration");
4422sal_Int32 SAL_CALL ScCellRangesObj::getCount()
4426 return rRanges.
size();
4429uno::Any SAL_CALL ScCellRangesObj::getByIndex( sal_Int32 nIndex )
4432 uno::Reference<table::XCellRange> xRange(GetObjectByIndex_Impl(nIndex));
4434 throw lang::IndexOutOfBoundsException();
4440uno::Type SAL_CALL ScCellRangesObj::getElementType()
4445sal_Bool SAL_CALL ScCellRangesObj::hasElements()
4449 return !rRanges.
empty();
4453OUString SAL_CALL ScCellRangesObj::getImplementationName()
4455 return "ScCellRangesObj";
4458sal_Bool SAL_CALL ScCellRangesObj::supportsService(
const OUString& rServiceName )
4463uno::Sequence<OUString> SAL_CALL ScCellRangesObj::getSupportedServiceNames()
4474 if (
auto pDocShell =
dynamic_cast<ScDocShell*
>( pObjSh) )
4480 ScCellRangesBase( pDocSh, rR ),
4493 ScCellRangesBase::RefChanged();
4496 OSL_ENSURE(rRanges.
size() == 1,
"What ranges ?!?!");
4497 if ( !rRanges.
empty() )
4499 const ScRange & rFirst = rRanges[0];