summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-03-02 06:57:53 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2024-03-02 08:45:03 +0100
commit68c6b970e45ac1971dd95c28a07063f38dc152e0 (patch)
treeef0a6779b09fde12cb2b8918d6f977b30a07ea26 /sc/source
parenta9bcd8a0c0afc4baa53570f7072e64b5ba72f89b (diff)
Simplify a bit
Change-Id: I5022d82e556f7cfb09f0dee397d93dd7514a22e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164202 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/data/drwlayer.cxx112
1 files changed, 57 insertions, 55 deletions
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 480b779918d5..72273c2ed4d5 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -1786,70 +1786,73 @@ void ScDrawLayer::CopyToClip( ScDocument* pClipDoc, SCTAB nTab, const tools::Rec
SdrObjListIter aIter( pSrcPage, SdrIterMode::Flat );
while (SdrObject* pOldObject = aIter.Next())
{
+ // do not copy internal objects (detective) and note captions
+ if (pOldObject->GetLayer() == SC_LAYER_INTERN)
+ continue;
+
+ const ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pOldObject);
+ if (IsNoteCaption(pObjData))
+ continue;
+
// Catch objects where the object itself is inside the rectangle to be copied.
bool bObjectInArea = rRange.Contains(pOldObject->GetCurrentBoundRect());
// Catch objects whose anchor is inside the rectangle to be copied.
- const ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pOldObject);
- if (pObjData)
- bObjectInArea = bObjectInArea || aClipRange.Contains(pObjData->maStart);
-
- // do not copy internal objects (detective) and note captions
- if (bObjectInArea && pOldObject->GetLayer() != SC_LAYER_INTERN
- && !IsNoteCaption(pOldObject))
+ if (!bObjectInArea && pObjData)
+ bObjectInArea = aClipRange.Contains(pObjData->maStart);
+ if (!bObjectInArea)
+ continue;
+
+ if (!pDestModel)
{
- if ( !pDestModel )
+ pDestModel = pClipDoc->GetDrawLayer(); // does the document already have a drawing layer?
+ if (!pDestModel)
{
- pDestModel = pClipDoc->GetDrawLayer(); // does the document already have a drawing layer?
- if ( !pDestModel )
- {
- // allocate drawing layer in clipboard document only if there are objects to copy
+ // allocate drawing layer in clipboard document only if there are objects to copy
- pClipDoc->InitDrawLayer(); //TODO: create contiguous pages
- pDestModel = pClipDoc->GetDrawLayer();
- }
- if (pDestModel)
- pDestPage = pDestModel->GetPage( static_cast<sal_uInt16>(nTab) );
+ pClipDoc->InitDrawLayer(); //TODO: create contiguous pages
+ pDestModel = pClipDoc->GetDrawLayer();
}
+ if (pDestModel)
+ pDestPage = pDestModel->GetPage(static_cast<sal_uInt16>(nTab));
+ }
- OSL_ENSURE( pDestPage, "no page" );
- if (pDestPage)
+ OSL_ENSURE(pDestPage, "no page");
+ if (pDestPage)
+ {
+ // Clone to target SdrModel
+ rtl::Reference<SdrObject> pNewObject(pOldObject->CloneSdrObject(*pDestModel));
+ uno::Reference< chart2::XChartDocument > xOldChart( ScChartHelper::GetChartFromSdrObject( pOldObject ) );
+ if(!xOldChart.is())//#i110034# do not move charts as they lose all their data references otherwise
{
- // Clone to target SdrModel
- rtl::Reference<SdrObject> pNewObject(pOldObject->CloneSdrObject(*pDestModel));
- uno::Reference< chart2::XChartDocument > xOldChart( ScChartHelper::GetChartFromSdrObject( pOldObject ) );
- if(!xOldChart.is())//#i110034# do not move charts as they lose all their data references otherwise
+ if (pObjData)
{
- if (pObjData)
- {
- // The object is anchored to cell. The position is determined by the start
- // address. Copying into the clipboard does not change the anchor.
- // ToDo: Adapt Offset relative to anchor cell size for cell anchored.
- // ToDo: Adapt Offset and size for cell-anchored with resize objects.
- // ToDo: Exclude object from resize if disallowed at object.
- }
- else
- {
- // The object is anchored to page. We make its position so, that the
- // cell behind the object will have the same address in clipboard document as
- // in source document. So we will be able to reconstruct the original cell
- // address from position when pasting the object.
- tools::Rectangle aObjRect = pOldObject->GetSnapRect();
- ScRange aPseudoAnchor
- = pDoc->GetRange(nTab, aObjRect, true /*bHiddenAsZero*/);
- tools::Rectangle aSourceCellRect
- = GetCellRect(*pDoc, aPseudoAnchor.aStart, false /*bMergedCell*/);
- tools::Rectangle aDestCellRect
- = GetCellRect(*pClipDoc, aPseudoAnchor.aStart, false);
- Point aMove = aDestCellRect.TopLeft() - aSourceCellRect.TopLeft();
- pNewObject->NbcMove(Size(aMove.getX(), aMove.getY()));
- }
+ // The object is anchored to cell. The position is determined by the start
+ // address. Copying into the clipboard does not change the anchor.
+ // ToDo: Adapt Offset relative to anchor cell size for cell anchored.
+ // ToDo: Adapt Offset and size for cell-anchored with resize objects.
+ // ToDo: Exclude object from resize if disallowed at object.
}
+ else
+ {
+ // The object is anchored to page. We make its position so, that the
+ // cell behind the object will have the same address in clipboard document as
+ // in source document. So we will be able to reconstruct the original cell
+ // address from position when pasting the object.
+ tools::Rectangle aObjRect = pOldObject->GetSnapRect();
+ ScRange aPseudoAnchor = pDoc->GetRange(nTab, aObjRect, true /*bHiddenAsZero*/);
+ tools::Rectangle aSourceCellRect
+ = GetCellRect(*pDoc, aPseudoAnchor.aStart, false /*bMergedCell*/);
+ tools::Rectangle aDestCellRect
+ = GetCellRect(*pClipDoc, aPseudoAnchor.aStart, false);
+ Point aMove = aDestCellRect.TopLeft() - aSourceCellRect.TopLeft();
+ pNewObject->NbcMove(Size(aMove.getX(), aMove.getY()));
+ }
+ }
- pDestPage->InsertObject( pNewObject.get() );
+ pDestPage->InsertObject(pNewObject.get());
- // no undo needed in clipboard document
- // charts are not updated
- }
+ // no undo needed in clipboard document
+ // charts are not updated
}
}
}
@@ -2890,16 +2893,15 @@ ScDrawObjData* ScDrawLayer::GetObjDataTab( SdrObject* pObj, SCTAB nTab )
return pData;
}
-bool ScDrawLayer::IsNoteCaption( SdrObject* pObj )
+bool ScDrawLayer::IsNoteCaption(const ScDrawObjData* pData)
{
- ScDrawObjData* pData = pObj ? GetObjData( pObj ) : nullptr;
return pData && pData->meType == ScDrawObjData::CellNote;
}
ScDrawObjData* ScDrawLayer::GetNoteCaptionData( SdrObject* pObj, SCTAB nTab )
{
- ScDrawObjData* pData = pObj ? GetObjDataTab( pObj, nTab ) : nullptr;
- return (pData && pData->meType == ScDrawObjData::CellNote) ? pData : nullptr;
+ ScDrawObjData* pData = GetObjDataTab(pObj, nTab);
+ return IsNoteCaption(pData) ? pData : nullptr;
}
ScMacroInfo* ScDrawLayer::GetMacroInfo( SdrObject* pObj, bool bCreate )