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>
101#include <stlsheet.hxx>
116#include <globstr.hrc>
118#include <unonames.hxx>
130#include <tokenarray.hxx>
253 return &aCellsPropertySet;
363 return &aRangePropertySet;
479 return &aCellPropertySet;
593 return &aColumnPropertySet;
705 return &aRowPropertySet;
829 return &aSheetPropertySet;
843 return aEditPropertyMap_Impl;
848 return &aEditPropertySet;
884 uno::Reference<beans::XPropertySetInfo> xInfo(rSource.getPropertySetInfo());
887 const uno::Sequence<beans::Property>
aSeq(xInfo->getProperties());
888 for (
const beans::Property& rProp :
aSeq)
890 OUString
aName(rProp.Name);
891 rDest.setPropertyValue(
aName, rSource.getPropertyValue(
aName ) );
899 throw std::out_of_range(
"empty range");
900 const ScRange & rFirst = rRanges[0];
906 if ( rRanges.
size() == 1 )
908 const ScRange & rRange = rRanges[0];
917template<
typename BorderLineType>
918const ::editeng::SvxBorderLine* lcl_getBorderLine(
935 return lcl_getBorderLine( rLine, rStruct);
941 return lcl_getBorderLine( rLine, rStruct);
945template<
typename TableBorderType>
956 rInner.
SetValid( SvxBoxInfoItemValidFlags::TOP, rBorder.IsTopLineValid );
957 rInner.
SetValid( SvxBoxInfoItemValidFlags::BOTTOM, rBorder.IsBottomLineValid );
958 rInner.
SetValid( SvxBoxInfoItemValidFlags::LEFT, rBorder.IsLeftLineValid );
959 rInner.
SetValid( SvxBoxInfoItemValidFlags::RIGHT, rBorder.IsRightLineValid );
960 rInner.
SetValid( SvxBoxInfoItemValidFlags::HORI, rBorder.IsHorizontalLineValid );
961 rInner.
SetValid( SvxBoxInfoItemValidFlags::VERT, rBorder.IsVerticalLineValid );
962 rInner.
SetValid( SvxBoxInfoItemValidFlags::DISTANCE, rBorder.IsDistanceValid );
969 lcl_fillBoxItems( rOuter, rInner, rBorder);
974 lcl_fillBoxItems( rOuter, rInner, rBorder);
989template<
typename TableBorderItem>
991 bool bInvalidateHorVerDist )
1001 rBorder.IsTopLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::TOP);
1002 rBorder.IsBottomLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::BOTTOM);
1003 rBorder.IsLeftLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::LEFT);
1004 rBorder.IsRightLineValid = rInner.
IsValid(SvxBoxInfoItemValidFlags::RIGHT);
1005 rBorder.IsHorizontalLineValid = !bInvalidateHorVerDist && rInner.
IsValid(SvxBoxInfoItemValidFlags::HORI);
1006 rBorder.IsVerticalLineValid = !bInvalidateHorVerDist && rInner.
IsValid(SvxBoxInfoItemValidFlags::VERT);
1007 rBorder.IsDistanceValid = !bInvalidateHorVerDist && rInner.
IsValid(SvxBoxInfoItemValidFlags::DISTANCE);
1014 table::TableBorder aBorder;
1015 lcl_fillTableBorder( aBorder, rOuter, rInner, bInvalidateHorVerDist);
1022 table::TableBorder2 aBorder;
1023 lcl_fillTableBorder( aBorder, rOuter, rInner, bInvalidateHorVerDist);
1040 ScRange const & rRange = rRanges[
i ];
1046 pUndoDoc->InitUndo( rDoc, nTab, nTab );
1048 pUndoDoc->AddUndoTab( nTab, nTab );
1063 std::make_unique<ScUndoBorder>( pDocShell, rRanges, std::move(pUndoDoc), rOuter, rInner ) );
1076 const uno::Sequence< uno::Sequence<uno::Any> >& aData )
1087 if ( !rDoc.
IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) )
1093 sal_Int32 nCols = 0;
1094 sal_Int32 nRows =
aData.getLength();
1096 nCols =
aData[0].getLength();
1098 if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 )
1108 pUndoDoc->InitUndo( rDoc, nTab, nTab );
1114 bool bError =
false;
1115 SCROW nDocRow = nStartRow;
1116 for (
const uno::Sequence<uno::Any>& rColSeq :
aData)
1118 if ( rColSeq.getLength() == nCols )
1120 SCCOL nDocCol = nStartCol;
1121 for (
const uno::Any& rElement : rColSeq)
1125 switch( rElement.getValueTypeClass() )
1127 case uno::TypeClass_VOID:
1130 rDoc.
SetError( nDocCol, nDocRow, nTab, FormulaError::NotAvailable );
1136 case uno::TypeClass_BYTE:
1137 case uno::TypeClass_SHORT:
1138 case uno::TypeClass_UNSIGNED_SHORT:
1139 case uno::TypeClass_LONG:
1140 case uno::TypeClass_UNSIGNED_LONG:
1141 case uno::TypeClass_FLOAT:
1142 case uno::TypeClass_DOUBLE:
1150 case uno::TypeClass_STRING:
1154 if ( !aUStr.isEmpty() )
1174 case uno::TypeClass_SEQUENCE:
1176 uno::Sequence< sheet::FormulaToken > aTokens;
1177 if ( rElement >>= aTokens )
1207 std::make_unique<ScUndoPaste>(
1208 &rDocShell,
ScRange(nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab),
1221 const uno::Sequence< uno::Sequence<OUString> >& aData,
1232 if ( !rDoc.
IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) )
1238 sal_Int32 nCols = 0;
1239 sal_Int32 nRows =
aData.getLength();
1241 nCols =
aData[0].getLength();
1243 if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 )
1253 pUndoDoc->InitUndo( rDoc, nTab, nTab );
1259 bool bError =
false;
1260 SCROW nDocRow = nStartRow;
1261 for (
const uno::Sequence<OUString>& rColSeq :
aData)
1263 if ( rColSeq.getLength() == nCols )
1265 SCCOL nDocCol = nStartCol;
1266 for (
const OUString& aText : rColSeq)
1268 ScAddress aPos( nDocCol, nDocRow, nTab );
1304 std::make_unique<ScUndoPaste>( &rDocShell,
1305 ScRange(nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab), aDestMark,
1359 OUString aTempString = aVal;
1360 bool bIsNumberFormat(pFormatter->
IsNumberFormat(aTempString, nNumFmt, fDummy));
1361 if ( bIsNumberFormat )
1362 aTempString =
"'" + aTempString;
1363 else if ( aTempString.startsWith(
"'") )
1367 if ( bEnglish || ( pFormatter->
GetType(nNumFmt) != SvNumFormatType::TEXT ) )
1368 aTempString =
"'" + aTempString;
1377 pDocShell( pDocSh ),
1379 bChartColAsHdr( false ),
1380 bChartRowAsHdr( false ),
1381 bCursorOnly( false ),
1382 bGotDataChangedHint( false ),
1383 aValueListeners( 0 )
1386 aCellRange.PutInOrder();
1387 aRanges.push_back( aCellRange );
1399 pDocShell( pDocSh ),
1400 aRanges(
std::move( aR )),
1402 bChartColAsHdr( false ),
1403 bChartRowAsHdr( false ),
1404 bCursorOnly( false ),
1405 bGotDataChangedHint( false ),
1406 aValueListeners( 0 )
1416ScCellRangesBase::~ScCellRangesBase()
1424 pDocShell->GetDocument().RemoveUnoObject(*
this);
1426 ForgetCurrentAttrs();
1429 pValueListener.reset();
1435void ScCellRangesBase::ForgetCurrentAttrs()
1437 pCurrentFlat.reset();
1438 pCurrentDeep.reset();
1439 moCurrentDataSet.reset();
1440 moNoDfltCurrentDataSet.reset();
1445void ScCellRangesBase::ForgetMarkData()
1454 if ( !pCurrentFlat && pDocShell )
1459 return pCurrentFlat.get();
1466 if ( !pCurrentDeep && pDocShell )
1471 return pCurrentDeep.get();
1474SfxItemSet* ScCellRangesBase::GetCurrentDataSet(
bool bNoDflt)
1476 if(!moCurrentDataSet)
1482 moCurrentDataSet.emplace( pPattern->
GetItemSet() );
1483 moNoDfltCurrentDataSet.emplace( pPattern->
GetItemSet() );
1484 moCurrentDataSet->ClearInvalidItems();
1489 if (moNoDfltCurrentDataSet)
1490 return &*moNoDfltCurrentDataSet;
1494 if (moCurrentDataSet)
1495 return &*moCurrentDataSet;
1500const ScMarkData* ScCellRangesBase::GetMarkData()
1504 pMarkData.reset(
new ScMarkData(GetDocument()->GetSheetLimits(), aRanges) );
1506 return pMarkData.get();
1512 if ( nId == SfxHintId::Dying )
1515 ForgetCurrentAttrs();
1516 pDocShell =
nullptr;
1519 if ( m_refCount > 0 && !aValueListeners.empty() )
1523 lang::EventObject
aEvent;
1525 for (uno::Reference<util::XModifyListener> & xValueListener : aValueListeners)
1526 xValueListener->disposing( aEvent );
1528 aValueListeners.clear();
1534 else if ( nId == SfxHintId::DataChanged )
1537 ForgetCurrentAttrs();
1539 if ( bGotDataChangedHint && pDocShell )
1549 lang::EventObject
aEvent;
1555 for (
const uno::Reference<util::XModifyListener> & xValueListener : aValueListeners)
1558 bGotDataChangedHint =
false;
1561 else if ( nId == SfxHintId::ScCalcAll )
1566 if ( !aValueListeners.empty() )
1567 bGotDataChangedHint =
true;
1569 else if (
auto pRefHint =
dynamic_cast<const ScUpdateRefHint*
>(&rHint) )
1572 std::unique_ptr<ScRangeList> pUndoRanges;
1576 if ( aRanges.UpdateReference( pRefHint->GetMode(), &rDoc, pRefHint->GetRange(),
1577 pRefHint->GetDx(), pRefHint->GetDy(), pRefHint->GetDz() ) )
1580 && aRanges.size() == 1
1585 ScRange & rR = aRanges.front();
1594 if ( !aValueListeners.empty() )
1595 bGotDataChangedHint =
true;
1603 if ( pUndoHint->GetObjectId() == nObjectId )
1607 aRanges = pUndoHint->GetRanges();
1610 if ( !aValueListeners.empty() )
1611 bGotDataChangedHint =
true;
1616void ScCellRangesBase::RefChanged()
1620 if ( pValueListener && !aValueListeners.empty() )
1622 pValueListener->EndListeningAll();
1625 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
1629 ForgetCurrentAttrs();
1633ScDocument* ScCellRangesBase::GetDocument()
const
1636 return &pDocShell->GetDocument();
1643 if ( pDocShell || !pDocSh )
1649 aCellRange.PutInOrder();
1650 aRanges.RemoveAll();
1651 aRanges.push_back( aCellRange );
1653 pDocShell->GetDocument().AddUnoObject(*
this);
1658void ScCellRangesBase::AddRange(
const ScRange& rRange,
const bool bMergeRanges)
1661 aRanges.Join(rRange);
1663 aRanges.push_back(rRange);
1667void ScCellRangesBase::SetNewRange(
const ScRange& rNew)
1670 aCellRange.PutInOrder();
1672 aRanges.RemoveAll();
1673 aRanges.push_back( aCellRange );
1677void ScCellRangesBase::SetNewRanges(
const ScRangeList& rNew)
1683void ScCellRangesBase::SetCursorOnly(
bool bSet )
1691void ScCellRangesBase::PaintGridRanges_Impl( )
1693 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i)
1699double SAL_CALL ScCellRangesBase::computeFunction( sheet::GeneralFunction nFunction )
1703 aMark.MarkToSimple();
1704 if (!aMark.IsMarked())
1705 aMark.SetMarkNegative(
true);
1713 throw uno::RuntimeException();
1719void SAL_CALL ScCellRangesBase::clearContents( sal_Int32 nContentFlags )
1722 if ( !aRanges.empty() )
1729 pDocShell->GetDocFunc().DeleteContents( *GetMarkData(), nDelFlags,
true, true );
1738 return pPropSet->getPropertyMap();
1742 sal_uInt16& rItemWhich )
1750 rItemWhich = pEntry->
nWID;
1752 switch ( pEntry->
nWID )
1772beans::PropertyState ScCellRangesBase::GetOnePropertyState( sal_uInt16 nItemWhich,
const SfxItemPropertyMapEntry* pEntry )
1774 beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE;
1789 if ( eState == SfxItemState::SET )
1790 eRet = beans::PropertyState_DIRECT_VALUE;
1791 else if ( eState == SfxItemState::DEFAULT )
1792 eRet = beans::PropertyState_DEFAULT_VALUE;
1793 else if ( eState == SfxItemState::DONTCARE )
1794 eRet = beans::PropertyState_AMBIGUOUS_VALUE;
1797 OSL_FAIL(
"unknown ItemState");
1804 eRet = beans::PropertyState_DIRECT_VALUE;
1808 const ScStyleSheet* pStyle = pDocShell->GetDocument().GetSelectionStyle(*GetMarkData());
1810 eRet = beans::PropertyState_DIRECT_VALUE;
1812 eRet = beans::PropertyState_AMBIGUOUS_VALUE;
1815 eRet = beans::PropertyState_DEFAULT_VALUE;
1820beans::PropertyState SAL_CALL ScCellRangesBase::getPropertyState(
const OUString& aPropertyName )
1823 if ( aRanges.empty() )
1824 throw uno::RuntimeException();
1827 sal_uInt16 nItemWhich = 0;
1830 return GetOnePropertyState( nItemWhich, pEntry );
1833uno::Sequence<beans::PropertyState> SAL_CALL ScCellRangesBase::getPropertyStates(
1834 const uno::Sequence<OUString>& aPropertyNames )
1840 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
1841 std::transform(aPropertyNames.begin(), aPropertyNames.end(), aRet.getArray(),
1842 [
this, &rPropertyMap](
const auto& rName) -> beans::PropertyState {
1843 sal_uInt16 nItemWhich = 0;
1844 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( rName );
1845 lcl_GetPropertyWhich( pEntry, nItemWhich );
1846 return GetOnePropertyState(nItemWhich, pEntry);
1851void SAL_CALL ScCellRangesBase::setPropertyToDefault(
const OUString& aPropertyName )
1858 sal_uInt16 nItemWhich = 0;
1863 if ( !aRanges.empty() )
1869 sal_uInt16 aWIDs[3];
1870 aWIDs[0] = nItemWhich;
1878 pDocShell->GetDocFunc().ClearItems( *GetMarkData(), aWIDs,
true );
1884 bChartColAsHdr =
false;
1886 bChartRowAsHdr =
false;
1889 OUString aStyleName(
ScResId( STR_STYLENAME_STANDARD ) );
1890 pDocShell->GetDocFunc().ApplyStyle( *GetMarkData(), aStyleName,
true );
1895uno::Any SAL_CALL ScCellRangesBase::getPropertyDefault(
const OUString& aPropertyName )
1916 switch ( pEntry->
nWID )
1927 pPropSet->getPropertyValue(aPropertyName, rSet, aAny);
1932 switch ( pEntry->
nWID )
1940 ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Para );
1969 aAny <<= uno::Reference<sheet::XSheetConditionalEntries>(
1983 aAny <<= uno::Reference<beans::XPropertySet>(
2001uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellRangesBase::getPropertySetInfo()
2004 static uno::Reference<beans::XPropertySetInfo> aRef(
2011 sal_uInt16& rFirstItemId, sal_uInt16& rSecondItemId )
2013 rFirstItemId = rEntry.
nWID;
2017 switch ( rEntry.
nWID )
2027 sal_Int32 nIntVal = 0;
2028 if ( !(rValue >>= nIntVal) )
2029 throw lang::IllegalArgumentException();
2057 sal_Int16 nIntVal = 0;
2058 if ( !(rValue >>= nIntVal) )
2059 throw lang::IllegalArgumentException();
2067 sal_Int32 nRotVal = 0;
2068 if ( !(rValue >>= nRotVal) )
2069 throw lang::IllegalArgumentException();
2082 table::CellOrientation eOrient;
2083 if( rValue >>= eOrient )
2087 case table::CellOrientation_STANDARD:
2090 case table::CellOrientation_TOPBOTTOM:
2095 case table::CellOrientation_BOTTOMTOP:
2100 case table::CellOrientation_STACKED:
2118void SAL_CALL ScCellRangesBase::setPropertyValue(
2119 const OUString& aPropertyName,
const uno::Any& aValue )
2123 if ( !pDocShell || aRanges.empty() )
2124 throw uno::RuntimeException();
2129 throw beans::UnknownPropertyException(aPropertyName);
2131 SetOnePropertyValue( pEntry, aValue );
2141 if ( !aRanges.empty() )
2156 sal_uInt16 nFirstItem, nSecondItem;
2160 if ( nWhich != nFirstItem && nWhich != nSecondItem )
2163 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), aPattern,
true );
2167 switch ( pEntry->
nWID )
2175 for (
size_t i = 0, n = aRanges.size(); i < n; ++i)
2177 ScRange const & rRange = aRanges[
i];
2184 OUString
aStr = aCell.getString(&rDoc);
2186 aEngine.SetEditTextObjectPool(rDoc.
GetEditPool());
2194 SfxItemSet aAttr = aEngine.GetEmptyItemSet();
2195 aEngine.SetText(aStr);
2200 aEngine.QuickSetAttribs(aAttr,
ESelection(0, 0, 0,
aStr.getLength()));
2203 rDoc.
SetEditText(aRanges[0].aStart, aEngine.CreateTextObject());
2220 aStrVal, SfxStyleFamily::Para ));
2221 pDocShell->GetDocFunc().ApplyStyle( *GetMarkData(), aString,
true );
2226 table::TableBorder aBorder;
2227 if ( !aRanges.empty() && ( aValue >>= aBorder ) )
2239 table::TableBorder2 aBorder2;
2240 if ( !aRanges.empty() && ( aValue >>= aBorder2 ) )
2254 uno::Reference<sheet::XSheetConditionalEntries> xInterface(aValue, uno::UNO_QUERY);
2255 if ( !aRanges.empty() && xInterface.is() )
2268 SCTAB nTab = aRanges.front().aStart.Tab();
2273 for (
size_t i = 0;
i < aRanges.size(); ++
i)
2276 aRanges[i].aStart.Col(), aRanges[
i].aStart.Row(),
2277 aRanges[
i].aEnd.Col(), aRanges[
i].aEnd.Row() );
2283 auto pNew = std::make_unique<ScConditionalFormat>( 0, &rDoc );
2284 pFormat->
FillFormat( *pNew, rDoc, eGrammar );
2285 pNew->SetRange( aRanges );
2286 pDocShell->GetDocFunc().ReplaceConditionalFormat( 0, std::move(pNew), nTab, aRanges );
2290 for (
size_t i = 0;
i < aRanges.size(); ++
i)
2292 pDocShell->SetDocumentModified();
2301 uno::Reference<beans::XPropertySet> xInterface(aValue, uno::UNO_QUERY);
2302 if ( !aRanges.empty() && xInterface.is() )
2315 std::unique_ptr<ScValidationData> pNewData(
2322 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), aPattern,
true );
2331uno::Any SAL_CALL ScCellRangesBase::getPropertyValue(
const OUString& aPropertyName )
2335 if ( !pDocShell || aRanges.empty() )
2336 throw uno::RuntimeException();
2341 throw beans::UnknownPropertyException(aPropertyName);
2344 GetOnePropertyValue( pEntry, aAny );
2358 switch ( pEntry->
nWID )
2369 GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang );
2370 rAny <<= static_cast<sal_Int32>(nOldFormat);
2385 pPropSet->getPropertyValue(*pEntry, *pDataSet, rAny);
2390 switch ( pEntry->
nWID )
2393 rAny <<= bChartColAsHdr;
2396 rAny <<= bChartRowAsHdr;
2400 OUString aStyleName;
2401 const ScStyleSheet* pStyle = pDocShell->GetDocument().GetSelectionStyle(*GetMarkData());
2403 aStyleName = pStyle->
GetName();
2405 aStyleName, SfxStyleFamily::Para );
2412 if ( !aRanges.empty() )
2414 const ScRange & rFirst = aRanges[ 0 ];
2420 aMark.SetMarkArea( rFirst );
2421 aMark.SelectTable( rFirst.
aStart.
Tab(),
true );
2449 rAny <<= uno::Reference<sheet::XSheetConditionalEntries>(
2469 rAny <<= uno::Reference<beans::XPropertySet>(
2490 rAny <<= pPattern->
GetKey();
2496void SAL_CALL ScCellRangesBase::addPropertyChangeListener(
const OUString& ,
2497 const uno::Reference<beans::XPropertyChangeListener>& )
2500 if ( aRanges.empty() )
2501 throw uno::RuntimeException();
2503 OSL_FAIL(
"not implemented");
2506void SAL_CALL ScCellRangesBase::removePropertyChangeListener(
const OUString& ,
2507 const uno::Reference<beans::XPropertyChangeListener>& )
2510 if ( aRanges.empty() )
2511 throw uno::RuntimeException();
2513 OSL_FAIL(
"not implemented");
2516void SAL_CALL ScCellRangesBase::addVetoableChangeListener(
const OUString&,
2517 const uno::Reference<beans::XVetoableChangeListener>&)
2519 OSL_FAIL(
"not implemented");
2522void SAL_CALL ScCellRangesBase::removeVetoableChangeListener(
const OUString&,
2523 const uno::Reference<beans::XVetoableChangeListener>&)
2525 OSL_FAIL(
"not implemented");
2530void SAL_CALL ScCellRangesBase::setPropertyValues(
const uno::Sequence< OUString >& aPropertyNames,
2531 const uno::Sequence< uno::Any >& aValues )
2535 sal_Int32
nCount(aPropertyNames.getLength());
2536 sal_Int32 nValues(aValues.getLength());
2537 if (nCount != nValues)
2538 throw lang::IllegalArgumentException();
2540 if ( !(pDocShell && nCount) )
2544 const OUString* pNames = aPropertyNames.getConstArray();
2556 pEntryArray[
i] = pEntry;
2563 SetOnePropertyValue( pEntry, pValues[i] );
2565 catch ( lang::IllegalArgumentException& )
2574 std::unique_ptr<ScPatternAttr> pOldPattern;
2575 std::unique_ptr<ScPatternAttr> pNewPattern;
2588 pOldPattern.reset(
new ScPatternAttr( *GetCurrentAttrsDeep() ));
2589 pOldPattern->GetItemSet().ClearInvalidItems();
2595 sal_uInt16 nFirstItem, nSecondItem;
2600 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nFirstItem ) );
2602 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nSecondItem ) );
2607 SetOnePropertyValue( pEntry, pValues[i] );
2612 if ( pNewPattern && !aRanges.empty() )
2613 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), *pNewPattern,
true );
2616uno::Sequence<uno::Any> SAL_CALL ScCellRangesBase::getPropertyValues(
2617 const uno::Sequence< OUString >& aPropertyNames )
2623 uno::Sequence<uno::Any> aRet(aPropertyNames.getLength());
2624 uno::Any* pProperties = aRet.getArray();
2625 for(sal_Int32 i = 0;
i < aPropertyNames.getLength();
i++)
2628 GetOnePropertyValue( pEntry, pProperties[i] );
2633void SAL_CALL ScCellRangesBase::addPropertiesChangeListener(
const uno::Sequence< OUString >& ,
2634 const uno::Reference< beans::XPropertiesChangeListener >& )
2636 OSL_FAIL(
"not implemented");
2639void SAL_CALL ScCellRangesBase::removePropertiesChangeListener(
const uno::Reference< beans::XPropertiesChangeListener >& )
2641 OSL_FAIL(
"not implemented");
2644void SAL_CALL ScCellRangesBase::firePropertiesChangeEvent(
const uno::Sequence< OUString >& ,
2645 const uno::Reference< beans::XPropertiesChangeListener >& )
2647 OSL_FAIL(
"not implemented");
2652 if ( pDocShell && (rHint.
GetId() == SfxHintId::ScDataChanged))
2658 bGotDataChangedHint =
true;
2663uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::setPropertyValuesTolerant(
const uno::Sequence< OUString >& aPropertyNames,
2664 const uno::Sequence< uno::Any >& aValues )
2668 sal_Int32
nCount(aPropertyNames.getLength());
2669 sal_Int32 nValues(aValues.getLength());
2670 if (nCount != nValues)
2671 throw lang::IllegalArgumentException();
2673 if ( pDocShell && nCount )
2675 uno::Sequence < beans::SetPropertyTolerantFailed > aReturns(nCount);
2676 beans::SetPropertyTolerantFailed* pReturns = aReturns.getArray();
2679 const OUString* pNames = aPropertyNames.getConstArray();
2691 pMapArray[
i] = pEntry;
2698 SetOnePropertyValue( pEntry, pValues[i] );
2700 catch ( lang::IllegalArgumentException& )
2709 std::unique_ptr<ScPatternAttr> pOldPattern;
2710 std::unique_ptr<ScPatternAttr> pNewPattern;
2712 sal_Int32 nFailed(0);
2718 if ( pEntry && ((pEntry->
nFlags & beans::PropertyAttribute::READONLY) == 0))
2724 pOldPattern.reset(
new ScPatternAttr( *GetCurrentAttrsDeep() ));
2725 pOldPattern->GetItemSet().ClearInvalidItems();
2732 sal_uInt16 nFirstItem, nSecondItem;
2737 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nFirstItem ) );
2739 pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nSecondItem ) );
2741 catch ( lang::IllegalArgumentException& )
2743 pReturns[nFailed].Name = pNames[
i];
2744 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
2752 SetOnePropertyValue( pEntry, pValues[i] );
2754 catch ( lang::IllegalArgumentException& )
2756 pReturns[nFailed].Name = pNames[
i];
2757 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
2763 pReturns[nFailed].Name = pNames[
i];
2765 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
2767 pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2771 if ( pNewPattern && !aRanges.empty() )
2772 pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), *pNewPattern,
true );
2774 aReturns.realloc(nFailed);
2778 return uno::Sequence < beans::SetPropertyTolerantFailed >();
2781uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL ScCellRangesBase::getPropertyValuesTolerant(
const uno::Sequence< OUString >& aPropertyNames )
2785 sal_Int32
nCount(aPropertyNames.getLength());
2786 uno::Sequence < beans::GetPropertyTolerantResult > aReturns(nCount);
2787 beans::GetPropertyTolerantResult* pReturns = aReturns.getArray();
2791 for(sal_Int32 i = 0;
i <
nCount;
i++)
2796 pReturns[
i].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2800 sal_uInt16 nItemWhich = 0;
2802 pReturns[
i].State = GetOnePropertyState( nItemWhich, pEntry );
2803 GetOnePropertyValue( pEntry, pReturns[i].Value );
2804 pReturns[
i].Result = beans::TolerantPropertySetResultType::SUCCESS;
2810uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL ScCellRangesBase::getDirectPropertyValuesTolerant(
const uno::Sequence< OUString >& aPropertyNames )
2814 sal_Int32
nCount(aPropertyNames.getLength());
2815 uno::Sequence < beans::GetDirectPropertyTolerantResult > aReturns(nCount);
2816 beans::GetDirectPropertyTolerantResult* pReturns = aReturns.getArray();
2821 for(sal_Int32 i = 0;
i <
nCount;
i++)
2826 pReturns[
i].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2830 sal_uInt16 nItemWhich = 0;
2832 pReturns[j].State = GetOnePropertyState( nItemWhich, pEntry );
2833 if (pReturns[j].
State == beans::PropertyState_DIRECT_VALUE)
2835 GetOnePropertyValue( pEntry, pReturns[j].Value );
2836 pReturns[j].Result = beans::TolerantPropertySetResultType::SUCCESS;
2837 pReturns[j].Name = aPropertyNames[
i];
2843 aReturns.realloc(j);
2849void SAL_CALL ScCellRangesBase::decrementIndent()
2852 if ( pDocShell && !aRanges.empty() )
2856 aMarkData.MarkToMulti();
2857 pDocShell->GetDocFunc().ChangeIndent( aMarkData,
false,
true );
2861void SAL_CALL ScCellRangesBase::incrementIndent()
2864 if ( pDocShell && !aRanges.empty() )
2868 aMarkData.MarkToMulti();
2869 pDocShell->GetDocFunc().ChangeIndent( aMarkData,
true,
true );
2875std::unique_ptr<ScMemChart> ScCellRangesBase::CreateMemChart_Impl()
const
2877 if ( pDocShell && !aRanges.empty() )
2880 if ( aRanges.size() == 1 )
2886 const ScDocument & rDoc = pDocShell->GetDocument();
2887 const ScRange & rRange = aRanges[0];
2895 if (!pDocShell->GetDocument().GetDataStart( nTab, nStartX, nStartY ))
2903 if (!pDocShell->GetDocument().GetTableArea( nTab, nEndX, nEndY ))
2909 xChartRanges =
new ScRangeList(
ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
2912 if (!xChartRanges.
is())
2917 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
2919 return aArr.CreateMemChart();
2924uno::Sequence< uno::Sequence<double> > SAL_CALL ScCellRangesBase::getData()
2927 std::unique_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
2930 sal_Int32 nColCount = pMemChart->GetColCount();
2931 sal_Int32 nRowCount =
static_cast<sal_Int32
>(pMemChart->GetRowCount());
2933 uno::Sequence< uno::Sequence<double> > aRowSeq( nRowCount );
2934 uno::Sequence<double>* pRowAry = aRowSeq.getArray();
2935 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
2937 uno::Sequence<double> aColSeq( nColCount );
2938 double* pColAry = aColSeq.getArray();
2939 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
2940 pColAry[nCol] = pMemChart->GetData( nCol, nRow );
2942 pRowAry[nRow] = aColSeq;
2951ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( sal_Int32 nDataColumns, sal_Int32 nDataRows )
const
2953 if ( aRanges.size() == 1 )
2955 const ScDocument & rDoc = pDocShell->GetDocument();
2956 const ScRange & rRange = aRanges[0];
2964 sal_Int32 nEndColumn = nDataColumns - 1 + ( bChartColAsHdr ? 1 : 0 );
2965 if ( nEndColumn < 0 )
2967 if ( nEndColumn > rDoc.
MaxCol() )
2968 nEndColumn = rDoc.
MaxCol();
2970 sal_Int32 nEndRow = nDataRows - 1 + ( bChartRowAsHdr ? 1 : 0 );
2973 if ( nEndRow > rDoc.
MaxRow() )
2977 return xChartRanges;
2984void SAL_CALL ScCellRangesBase::setData(
const uno::Sequence< uno::Sequence<double> >& aData )
2988 sal_Int32 nRowCount =
aData.getLength();
2989 sal_Int32 nColCount = nRowCount ?
aData[0].getLength() : 0;
2990 ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, nRowCount );
2991 if ( pDocShell && xChartRanges.
is() )
2995 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
3002 for (sal_Int32 nRow=0; nRow<nRowCount; nRow++)
3004 const uno::Sequence<double>& rRowSeq =
aData[nRow];
3005 const double* pArray = rRowSeq.getConstArray();
3006 nColCount = rRowSeq.getLength();
3007 for (sal_Int32 nCol=0; nCol<nColCount; nCol++)
3010 sal::static_int_cast<SCCOL>(nCol),
3011 sal::static_int_cast<SCROW>(nRow) );
3014 double fVal = pArray[nCol];
3015 if ( fVal == DBL_MIN )
3018 rDoc.
SetValue(*pPos, pArray[nCol]);
3024 PaintGridRanges_Impl();
3025 pDocShell->SetDocumentModified();
3026 ForceChartListener_Impl();
3033 throw uno::RuntimeException();
3036uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getRowDescriptions()
3039 std::unique_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
3042 sal_Int32 nRowCount =
static_cast<sal_Int32
>(pMemChart->GetRowCount());
3043 uno::Sequence<OUString>
aSeq( nRowCount );
3044 OUString* pAry =
aSeq.getArray();
3045 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
3046 pAry[nRow] = pMemChart->GetRowText(nRow);
3053void SAL_CALL ScCellRangesBase::setRowDescriptions(
3054 const uno::Sequence<OUString>& aRowDescriptions )
3058 if ( bChartColAsHdr )
3060 sal_Int32 nRowCount = aRowDescriptions.getLength();
3061 ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( 1, nRowCount );
3062 if ( pDocShell && xChartRanges.
is() )
3066 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
3072 const OUString* pArray = aRowDescriptions.getConstArray();
3073 for (sal_Int32 nRow=0; nRow<nRowCount; nRow++)
3076 static_cast<SCSIZE>(nRow) );
3079 const OUString&
aStr = pArray[nRow];
3092 PaintGridRanges_Impl();
3093 pDocShell->SetDocumentModified();
3094 ForceChartListener_Impl();
3102 throw uno::RuntimeException();
3105uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getColumnDescriptions()
3108 std::unique_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
3111 sal_Int32 nColCount = pMemChart->GetColCount();
3112 uno::Sequence<OUString>
aSeq( nColCount );
3113 OUString* pAry =
aSeq.getArray();
3114 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
3115 pAry[nCol] = pMemChart->GetColText(nCol);
3122void SAL_CALL ScCellRangesBase::setColumnDescriptions(
3123 const uno::Sequence<OUString>& aColumnDescriptions )
3127 if ( bChartRowAsHdr )
3129 sal_Int32 nColCount = aColumnDescriptions.getLength();
3130 ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, 1 );
3131 if ( pDocShell && xChartRanges.
is() )
3135 aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
3141 const OUString* pArray = aColumnDescriptions.getConstArray();
3142 for (sal_Int32 nCol=0; nCol<nColCount; nCol++)
3145 sal::static_int_cast<SCCOL>(nCol) );
3148 const OUString&
aStr = pArray[nCol];
3161 PaintGridRanges_Impl();
3162 pDocShell->SetDocumentModified();
3163 ForceChartListener_Impl();
3171 throw uno::RuntimeException();
3174void ScCellRangesBase::ForceChartListener_Impl()
3187 for (
auto const& it : rListeners)
3191 if (
p->GetUnoSource() ==
static_cast<chart::XChartData*
>(
this) &&
p->IsDirty())
3196void SAL_CALL ScCellRangesBase::addChartDataChangeEventListener(
const uno::Reference<
3197 chart::XChartDataChangeEventListener >& aListener )
3200 if ( !pDocShell || aRanges.empty() )
3209 if (
aName.isEmpty())
3214 pListener->
SetUno( aListener,
this );
3215 pColl->
insert( pListener );
3219void SAL_CALL ScCellRangesBase::removeChartDataChangeEventListener(
const uno::Reference<
3220 chart::XChartDataChangeEventListener >& aListener )
3223 if ( pDocShell && !aRanges.empty() )
3227 pColl->
FreeUno( aListener,
this );
3231double SAL_CALL ScCellRangesBase::getNotANumber()
3237sal_Bool SAL_CALL ScCellRangesBase::isNotANumber(
double nNumber )
3240 return (nNumber == DBL_MIN);
3245void SAL_CALL ScCellRangesBase::addModifyListener(
const uno::Reference<util::XModifyListener>& aListener)
3248 if ( aRanges.empty() )
3249 throw uno::RuntimeException();
3251 aValueListeners.emplace_back( aListener );
3253 if ( aValueListeners.size() == 1 )
3255 if (!pValueListener)
3256 pValueListener.reset(
new ScLinkListener(
LINK(
this, ScCellRangesBase, ValueListenerHdl ) ) );
3259 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; i++)
3266void SAL_CALL ScCellRangesBase::removeModifyListener(
const uno::Reference<util::XModifyListener>& aListener )
3270 if ( aRanges.empty() )
3271 throw uno::RuntimeException();
3275 sal_uInt16
nCount = aValueListeners.size();
3276 for ( sal_uInt16 n=nCount;
n--; )
3278 uno::Reference<util::XModifyListener>& rObj = aValueListeners[
n];
3279 if ( rObj == aListener )
3281 aValueListeners.erase( aValueListeners.begin() + n );
3283 if ( aValueListeners.empty() )
3286 pValueListener->EndListeningAll();
3298uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryVisibleCells()
3309 SCCOL nCol = 0, nLastCol;
3310 while (nCol <= rDoc.
MaxCol())
3312 if (rDoc.
ColHidden(nCol, nTab,
nullptr, &nLastCol))
3314 aMarkData.SetMultiMarkArea(
ScRange(nCol, 0, nTab, nLastCol, rDoc.
MaxRow(), nTab),
false);
3316 nCol = nLastCol + 1;
3319 SCROW nRow = 0, nLastRow;
3320 while (nRow <= rDoc.
MaxRow())
3322 if (rDoc.
RowHidden(nRow, nTab,
nullptr, &nLastRow))
3324 aMarkData.SetMultiMarkArea(
ScRange(0, nRow, nTab, rDoc.
MaxCol(), nLastRow, nTab),
false);
3326 nRow = nLastRow + 1;
3330 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3331 return new ScCellRangesObj( pDocShell, aNewRanges );
3337uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryEmptyCells()
3347 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i)
3349 ScRange const & rRange = aRanges[
i ];
3352 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3355 if (!aIter.isEmpty())
3356 aMarkData.SetMultiMarkArea(aIter.GetPos(),
false);
3363 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3365 return new ScCellRangesObj( pDocShell, aNewRanges );
3371uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryContentCells(
3372 sal_Int16 nContentFlags )
3382 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
3384 ScRange const & rRange = aRanges[
i ];
3387 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3390 switch (aIter.getType())
3393 if ( nContentFlags & sheet::CellFlags::STRING )
3397 if ( (nContentFlags & sheet::CellFlags::STRING) || (nContentFlags & sheet::CellFlags::FORMATTED) )
3405 if ( (nContentFlags & (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME))
3406 == (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME) )
3415 if ((nTyp == SvNumFormatType::DATE) || (nTyp == SvNumFormatType::TIME) ||
3416 (nTyp == SvNumFormatType::DATETIME))
3418 if ( nContentFlags & sheet::CellFlags::DATETIME )
3423 if ( nContentFlags & sheet::CellFlags::VALUE )
3435 aMarkData.SetMultiMarkArea(aIter.GetPos());
3439 if (nContentFlags & sheet::CellFlags::ANNOTATION)
3441 std::vector<sc::NoteEntry> aNotes;
3444 for (
const auto& i : aNotes)
3446 aMarkData.SetMultiMarkArea(
i.maPos);
3451 if (aMarkData.IsMultiMarked())
3452 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3454 return new ScCellRangesObj( pDocShell, aNewRanges );
3460uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryFormulaCells(
3461 sal_Int32 nResultFlags )
3471 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
3473 ScRange const & rRange = aRanges[
i ];
3476 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3482 if (pFCell->
GetErrCode() != FormulaError::NONE)
3484 if ( nResultFlags & sheet::FormulaResult::ERROR )
3489 if ( nResultFlags & sheet::FormulaResult::VALUE )
3494 if ( nResultFlags & sheet::FormulaResult::STRING )
3499 aMarkData.SetMultiMarkArea(aIter.GetPos());
3505 if (aMarkData.IsMultiMarked())
3506 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3508 return new ScCellRangesObj( pDocShell, aNewRanges );
3514uno::Reference<sheet::XSheetCellRanges> ScCellRangesBase::QueryDifferences_Impl(
3515 const table::CellAddress& aCompare,
bool bColumnDiff)
3519 size_t nRangeCount = aRanges.size();
3530 ScRange aCmpRange, aCellRange;
3532 aCmpRange =
ScRange( 0,nCmpPos,nTab, rDoc.
MaxCol(),nCmpPos,nTab );
3536 for (
bool bHasCell = aCmpIter.first(); bHasCell; bHasCell = aCmpIter.next())
3538 SCCOLROW nCellPos = bColumnDiff ?
static_cast<SCCOLROW>(aCmpIter.GetPos().Col()) :
static_cast<SCCOLROW>(aCmpIter.GetPos().Row());
3540 aCellRange =
ScRange(
static_cast<SCCOL>(nCellPos),0,nTab,
3541 static_cast<SCCOL>(nCellPos),rDoc.
MaxRow(),nTab );
3543 aCellRange =
ScRange( 0,nCellPos,nTab, rDoc.
MaxCol(),nCellPos,nTab );
3545 for (i=0;
i<nRangeCount;
i++)
3547 ScRange aRange( aRanges[ i ] );
3548 if ( aRange.Intersects( aCellRange ) )
3552 aRange.aStart.SetCol(
static_cast<SCCOL>(nCellPos));
3553 aRange.aEnd.SetCol(
static_cast<SCCOL>(nCellPos));
3557 aRange.aStart.SetRow(nCellPos);
3558 aRange.aEnd.SetRow(nCellPos);
3560 aMarkData.SetMultiMarkArea( aRange );
3569 for (i=0;
i<nRangeCount;
i++)
3571 ScRange const & rRange = aRanges[
i ];
3574 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3577 aCmpAddr =
ScAddress( aIter.GetPos().Col(), nCmpPos, aIter.GetPos().Tab() );
3579 aCmpAddr =
ScAddress(
static_cast<SCCOL>(nCmpPos), aIter.GetPos().Row(), aIter.GetPos().Tab() );
3581 ScRange aOneRange(aIter.GetPos());
3582 if (!aIter.equalsWithoutFormat(aCmpAddr))
3583 aMarkData.SetMultiMarkArea( aOneRange );
3585 aMarkData.SetMultiMarkArea( aOneRange,
false );
3590 if (aMarkData.IsMultiMarked())
3591 aMarkData.FillRangeListWithMarks( &aNewRanges,
false );
3593 return new ScCellRangesObj( pDocShell, aNewRanges );
3598uno::Reference<sheet::XSheetCellRanges > SAL_CALL ScCellRangesBase::queryColumnDifferences(
3599 const table::CellAddress& aCompare )
3602 return QueryDifferences_Impl( aCompare,
true );
3605uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryRowDifferences(
3606 const table::CellAddress& aCompare )
3609 return QueryDifferences_Impl( aCompare,
false );
3612uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryIntersection(
3613 const table::CellRangeAddress& aRange )
3616 ScRange aMask(
static_cast<SCCOL>(aRange.StartColumn),
static_cast<SCROW>(aRange.StartRow), aRange.Sheet,
3617 static_cast<SCCOL>(aRange.EndColumn),
static_cast<SCROW>(aRange.EndRow), aRange.Sheet );
3620 for (
size_t i = 0, nCount = aRanges.size(); i < nCount; ++i )
3622 ScRange aTemp( aRanges[ i ] );
3623 if ( aTemp.Intersects( aMask ) )
3624 aNew.
Join(
ScRange( std::max( aTemp.aStart.Col(), aMask.aStart.Col() ),
3625 std::max( aTemp.aStart.Row(), aMask.aStart.Row() ),
3626 std::max( aTemp.aStart.Tab(), aMask.aStart.Tab() ),
3627 std::min( aTemp.aEnd.Col(), aMask.aEnd.Col() ),
3628 std::min( aTemp.aEnd.Row(), aMask.aEnd.Row() ),
3629 std::min( aTemp.aEnd.Tab(), aMask.aEnd.Tab() ) ) );
3632 return new ScCellRangesObj( pDocShell, aNew );
3637uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryPrecedents(
3653 aMarkData.MarkFromRangeList( aNewRanges,
false );
3655 for (
size_t nR = 0, nCount = aNewRanges.
size(); nR<nCount; ++nR)
3657 ScRange const & rRange = aNewRanges[ nR];
3659 for (
bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
3666 while ( aRefIter.GetNextRef( aRefRange) )
3668 if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aRefRange ) )
3670 aMarkData.SetMultiMarkArea(aRefRange);
3675 aMarkData.FillRangeListWithMarks( &aNewRanges,
true );
3677 while ( bRecursive && bFound );
3679 return new ScCellRangesObj( pDocShell, aNewRanges );
3685uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryDependents(
3701 aMarkData.MarkFromRangeList( aNewRanges,
false );
3706 for (
bool bHasCell = aCellIter.first(); bHasCell; bHasCell = aCellIter.next())
3714 while ( aIter.GetNextRef( aRefRange) && !bMark )
3716 size_t nRangesCount = aNewRanges.
size();
3717 for (
size_t nR = 0; nR < nRangesCount; ++nR)
3719 ScRange const & rRange = aNewRanges[ nR ];
3729 ScRange aCellRange(aCellIter.GetPos());
3730 if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aCellRange ) )
3732 aMarkData.SetMultiMarkArea(aCellRange);
3736 aMarkData.FillRangeListWithMarks( &aNewRanges,
true );
3738 while ( bRecursive && bFound );
3740 return new ScCellRangesObj( pDocShell, aNewRanges );
3748uno::Reference<util::XSearchDescriptor> SAL_CALL ScCellRangesBase::createSearchDescriptor()
3753uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangesBase::findAll(
3754 const uno::Reference<util::XSearchDescriptor>& xDesc )
3758 uno::Reference<container::XIndexAccess> xRet;
3759 if ( pDocShell && xDesc.is() )
3768 pSearchItem->
SetCommand( SvxSearchCmd::FIND_ALL );
3774 OUString aDummyUndo;
3779 bool bMatchedRangesWereClamped =
false;
3781 *pSearchItem, nCol, nRow, nTab, aMark, aMatchedRanges, aDummyUndo,
nullptr, bMatchedRangesWereClamped);
3785 xRet.set(
new ScCellRangesObj( pDocShell, aMatchedRanges ));
3793uno::Reference<uno::XInterface> ScCellRangesBase::Find_Impl(
3794 const uno::Reference<util::XSearchDescriptor>& xDesc,
3797 uno::Reference<uno::XInterface> xRet;
3798 if ( pDocShell && xDesc.is() )
3807 pSearchItem->
SetCommand( SvxSearchCmd::FIND );
3817 pLastPos->
GetVars( nCol, nRow, nTab );
3824 OUString aDummyUndo;
3826 bool bMatchedRangesWereClamped;
3828 *pSearchItem, nCol, nRow, nTab, aMark, aMatchedRanges, aDummyUndo,
nullptr, bMatchedRangesWereClamped);
3831 ScAddress aFoundPos( nCol, nRow, nTab );
3840uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findFirst(
3841 const uno::Reference<util::XSearchDescriptor>& xDesc )
3844 return Find_Impl( xDesc,
nullptr );
3847uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findNext(
3848 const uno::Reference<uno::XInterface>& xStartAt,
3849 const uno::Reference<util::XSearchDescriptor >& xDesc )
3852 if ( xStartAt.is() )
3854 ScCellRangesBase* pRangesImp =
dynamic_cast<ScCellRangesBase*
>( xStartAt.get() );
3855 if ( pRangesImp && pRangesImp->GetDocShell() == pDocShell )
3857 const ScRangeList& rStartRanges = pRangesImp->GetRangeList();
3858 if ( rStartRanges.
size() == 1 )
3860 ScAddress aStartPos = rStartRanges[ 0 ].aStart;
3861 return Find_Impl( xDesc, &aStartPos );
3870uno::Reference<util::XReplaceDescriptor> SAL_CALL ScCellRangesBase::createReplaceDescriptor()
3875sal_Int32 SAL_CALL ScCellRangesBase::replaceAll(
const uno::Reference<util::XSearchDescriptor>& xDesc )
3878 sal_uInt64 nReplaced = 0;
3879 if ( pDocShell && xDesc.is() )
3889 pSearchItem->
SetCommand( SvxSearchCmd::REPLACE_ALL );
3896 bool bProtected = !pDocShell->IsEditable();
3897 for (
const auto& rTab : aMark)
3899 if (rTab >= nTabCount)
3910 SCTAB nTab = aMark.GetFirstSelected();
3919 pUndoDoc->InitUndo( rDoc, nTab, nTab );
3921 for (
const auto& rTab : aMark)
3923 if (rTab >= nTabCount)
3925 if (rTab != nTab && bUndo)
3926 pUndoDoc->AddUndoTab( rTab, rTab );
3928 std::unique_ptr<ScMarkData> pUndoMark;
3932 bool bFound =
false;
3936 bool bMatchedRangesWereClamped;
3938 *pSearchItem, nCol, nRow, nTab, aMark, aMatchedRanges, aUndoStr, pUndoDoc.get(), bMatchedRangesWereClamped );
3942 nReplaced = pUndoDoc->GetCellCount();
3944 pDocShell->GetUndoManager()->AddUndoAction(
3945 std::make_unique<ScUndoReplace>( pDocShell, *pUndoMark, nCol, nRow, nTab,
3946 aUndoStr, std::move(pUndoDoc), pSearchItem ) );
3948 pDocShell->PostPaintGridAll();
3949 pDocShell->SetDocumentModified();
3959 : ScCellRangesBase(pDocSh, rR)
3963ScCellRangesObj::~ScCellRangesObj()
3967void ScCellRangesObj::RefChanged()
3969 ScCellRangesBase::RefChanged();
3983 return ScCellRangesBase::queryInterface( rType );
3986void SAL_CALL ScCellRangesObj::acquire() noexcept
3988 ScCellRangesBase::acquire();
3991void SAL_CALL ScCellRangesObj::release() noexcept
3993 ScCellRangesBase::release();
3996uno::Sequence<uno::Type> SAL_CALL ScCellRangesObj::getTypes()
3999 ScCellRangesBase::getTypes(),
4000 uno::Sequence<uno::Type>
4009uno::Sequence<sal_Int8> SAL_CALL ScCellRangesObj::getImplementationId()
4011 return css::uno::Sequence<sal_Int8>();
4020 if ( pDocSh && nIndex >= 0 && nIndex < sal::static_int_cast<sal_Int32>(rRanges.
size()) )
4032uno::Sequence<table::CellRangeAddress> SAL_CALL ScCellRangesObj::getRangeAddresses()
4038 if ( pDocSh && nCount )
4040 table::CellRangeAddress aRangeAddress;
4041 uno::Sequence<table::CellRangeAddress>
aSeq(nCount);
4042 table::CellRangeAddress* pAry =
aSeq.getArray();
4046 pAry[
i] = aRangeAddress;
4054uno::Reference<container::XEnumerationAccess> SAL_CALL ScCellRangesObj::getCells()
4070OUString SAL_CALL ScCellRangesObj::getRangeAddressesAsString()
4083void SAL_CALL ScCellRangesObj::addRangeAddress(
const table::CellRangeAddress& rRange,
4088 static_cast<SCROW>(rRange.StartRow),
4089 static_cast<SCTAB>(rRange.Sheet),
4090 static_cast<SCCOL>(rRange.EndColumn),
4091 static_cast<SCROW>(rRange.EndRow),
4092 static_cast<SCTAB>(rRange.Sheet));
4093 AddRange(aRange, bMergeRanges);
4098 sal_uInt16
nCount = rNamedEntries.size();
4100 if ( rNamedEntries[
n].GetRange() == rRange )
4101 rNamedEntries.erase( rNamedEntries.begin() +
n );
4104void SAL_CALL ScCellRangesObj::removeRangeAddress(
const table::CellRangeAddress& rRange )
4111 for (
size_t i = 0;
i < rRanges.
size(); ++
i)
4113 if (rRanges[ i].aStart.Tab() == rRange.Sheet)
4119 aNotSheetRanges.
push_back( rRanges[ i ] );
4122 ScMarkData aMarkData(GetDocument()->GetSheetLimits());
4123 aMarkData.MarkFromRangeList( aSheetRanges,
false );
4125 static_cast<SCROW>(rRange.StartRow),
4126 static_cast<SCTAB>(rRange.Sheet),
4127 static_cast<SCCOL>(rRange.EndColumn),
4128 static_cast<SCROW>(rRange.EndRow),
4129 static_cast<SCTAB>(rRange.Sheet));
4130 if (aMarkData.GetTableSelect( aRange.aStart.Tab() ))
4132 aMarkData.MarkToMulti();
4133 if (!aMarkData.IsAllMarked( aRange ) )
4134 throw container::NoSuchElementException();
4136 aMarkData.SetMultiMarkArea( aRange,
false );
4140 SetNewRanges(aNotSheetRanges);
4142 aMarkData.FillRangeListWithMarks( &aNew,
false );
4143 for (
size_t j = 0; j < aNew.
size(); ++j)
4145 AddRange(aNew[ j ],
false);
4149void SAL_CALL ScCellRangesObj::addRangeAddresses(
const uno::Sequence<table::CellRangeAddress >& rRanges,
4153 for (
const table::CellRangeAddress& rRange : rRanges)
4156 static_cast<SCROW>(rRange.StartRow),
4157 static_cast<SCTAB>(rRange.Sheet),
4158 static_cast<SCCOL>(rRange.EndColumn),
4159 static_cast<SCROW>(rRange.EndRow),
4160 static_cast<SCTAB>(rRange.Sheet));
4161 AddRange(aRange, bMergeRanges);
4165void SAL_CALL ScCellRangesObj::removeRangeAddresses(
const uno::Sequence<table::CellRangeAddress >& rRangeSeq )
4168 for (
const table::CellRangeAddress& rRange : rRangeSeq)
4170 removeRangeAddress(rRange);
4176static void lcl_RemoveNamedEntry( std::vector<ScCellRangesObj::ScNamedEntry>& rNamedEntries, std::u16string_view rName )
4178 sal_uInt16
nCount = rNamedEntries.size();
4180 if ( rNamedEntries[
n].
GetName() == rName )
4181 rNamedEntries.erase( rNamedEntries.begin() +
n );
4184void SAL_CALL ScCellRangesObj::insertByName(
const OUString& aName,
const uno::Any& aElement )
4192 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
4193 if ( pDocSh && xInterface.is() )
4195 ScCellRangesBase* pRangesImp =
dynamic_cast<ScCellRangesBase*
>( xInterface.get() );
4196 if ( pRangesImp && pRangesImp->GetDocShell() == pDocSh )
4200 if ( !
aName.isEmpty() )
4202 size_t nNamedCount = m_aNamedEntries.size();
4203 for (
size_t n = 0;
n < nNamedCount;
n++)
4206 throw container::ElementExistException();
4211 const ScRangeList& rAddRanges = pRangesImp->GetRangeList();
4212 size_t nAddCount = rAddRanges.
size();
4213 for (
size_t i = 0;
i < nAddCount;
i++ )
4214 aNew.
Join( rAddRanges[ i ] );
4218 if ( !
aName.isEmpty() && nAddCount == 1 )
4223 m_aNamedEntries.emplace_back( ScNamedEntry{
aName, rAddRanges[ 0 ]} );
4231 throw lang::IllegalArgumentException();
4236 std::u16string_view rName,
size_t& rIndex )
4245 if ( aRangeStr == rName )
4257 const OUString& rName,
ScRange& rFound )
4264 rFound = rRanges[
nIndex ];
4279 rFound = aCellRange;
4286 for (
const auto & rNamedEntry : rNamedEntries)
4287 if ( rNamedEntry.GetName() == rName )
4291 const ScRange& rComp = rNamedEntry.GetRange();
4304void SAL_CALL ScCellRangesObj::removeByName(
const OUString& aName )
4315 for (
size_t i = 0, nCount = rRanges.
size(); i < nCount; i++ )
4329 sal_uInt16
nCount = m_aNamedEntries.size();
4330 for (sal_uInt16 n=0;