diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2024-06-20 17:10:01 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-06-20 14:06:51 +0200 |
commit | 6289ad39e851c709111b582e4390a097b30e2cae (patch) | |
tree | f4ce68108881258fb404dfb3459cb43813a4f829 /sd | |
parent | 51dfbb1fce61dfb2e1d4c91350d2299e6dc3e04d (diff) |
annot: clone annotations in SdrObjects when the page is duplicated
When the page is duplicated we need to clone all SdrObjects and
with that also all the annotations contained in the SdrObjects.
The annotations must also be added to the page, so that we can
find them quickly.
Previously we only cloned the annotations and relied that the
SdrObjects would be automagically be created, but as the SdrObject
are also cloned this creates a mess with duplicated objects with
annotatins for the wrong page or annotation objects with missing
annotation.
Change-Id: I4bf53e4bd387fad9b0a8e4f43edd57c3d0fd34cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169256
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
(cherry picked from commit c3281e071526f7efa9b7646a993476fc3f6ff8db)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169260
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/inc/Annotation.hxx | 3 | ||||
-rw-r--r-- | sd/source/core/annotations/Annotation.cxx | 21 | ||||
-rw-r--r-- | sd/source/core/sdpage2.cxx | 16 | ||||
-rw-r--r-- | sd/source/ui/annotations/annotationmanager.cxx | 22 |
4 files changed, 39 insertions, 23 deletions
diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx index 8d9f34501e0d..616888357894 100644 --- a/sd/inc/Annotation.hxx +++ b/sd/inc/Annotation.hxx @@ -53,7 +53,7 @@ std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation(rtl::Reference class SAL_DLLPUBLIC_RTTI Annotation final : public sdr::annotation::Annotation { public: - explicit Annotation( const css::uno::Reference<css::uno::XComponentContext>& context, SdPage* pPage ); + explicit Annotation(const css::uno::Reference<css::uno::XComponentContext>& context, SdrPage* pPage); Annotation(const Annotation&) = delete; Annotation& operator=(const Annotation&) = delete; @@ -82,6 +82,7 @@ public: virtual void SAL_CALL setDateTime(const css::util::DateTime & the_value) override; void createChangeUndo(); + rtl::Reference<sdr::annotation::Annotation> clone(SdrPage* pTargetPage) override; private: void createChangeUndoImpl(std::unique_lock<std::mutex>& g); diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx index 4f442dbbaa1c..3036ded07e8c 100644 --- a/sd/source/core/annotations/Annotation.cxx +++ b/sd/source/core/annotations/Annotation.cxx @@ -78,7 +78,7 @@ rtl::Reference<sdr::annotation::Annotation> createAnnotationAndAddToPage(SdPage* return xAnnotation; } -Annotation::Annotation(const uno::Reference<uno::XComponentContext>& context, SdPage* pPage) +Annotation::Annotation(const uno::Reference<uno::XComponentContext>& context, SdrPage* pPage) : sdr::annotation::Annotation(context, pPage) { } @@ -243,6 +243,25 @@ void Annotation::createChangeUndoImpl(std::unique_lock<std::mutex>& g) } } +rtl::Reference<sdr::annotation::Annotation> Annotation::clone(SdrPage* pTargetPage) +{ + rtl::Reference<sdr::annotation::Annotation> aNewAnnotation; + aNewAnnotation = new sd::Annotation(comphelper::getProcessComponentContext(), pTargetPage); + aNewAnnotation->setPosition(getPosition()); + aNewAnnotation->setSize(getSize()); + aNewAnnotation->setAuthor(getAuthor()); + aNewAnnotation->setInitials(getInitials()); + aNewAnnotation->setDateTime(getDateTime()); + aNewAnnotation->setCreationInfo(getCreationInfo()); + + uno::Reference<css::text::XTextCopy> xSourceRange (getTextRange(), uno::UNO_QUERY); + uno::Reference<css::text::XTextCopy> xRange (aNewAnnotation->getTextRange(), uno::UNO_QUERY); + if (xSourceRange.is() && xRange.is()) + xRange->copyText(xSourceRange); + + return aNewAnnotation; +} + std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation(rtl::Reference<sdr::annotation::Annotation>& xAnnotation, bool bInsert) { if (xAnnotation) diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx index 45563bdf0c70..7b0abf63fad7 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -377,22 +377,6 @@ void SdPage::lateInit(const SdPage& rSrcPage) // animations rSrcPage.cloneAnimations(*this); - // annotations - for (auto const& rSourceAnnotation : rSrcPage.maAnnotations) - { - rtl::Reference<sdr::annotation::Annotation> aNewAnnotation = createAnnotation(); - aNewAnnotation->setPosition(rSourceAnnotation->getPosition()); - aNewAnnotation->setSize(rSourceAnnotation->getSize()); - aNewAnnotation->setAuthor(rSourceAnnotation->getAuthor()); - aNewAnnotation->setInitials(rSourceAnnotation->getInitials()); - aNewAnnotation->setDateTime(rSourceAnnotation->getDateTime()); - uno::Reference<css::text::XTextCopy> xSourceRange (rSourceAnnotation->getTextRange(), uno::UNO_QUERY); - uno::Reference<css::text::XTextCopy> xRange (aNewAnnotation->getTextRange(), uno::UNO_QUERY); - if(xSourceRange.is() && xRange.is()) - xRange->copyText(xSourceRange); - addAnnotation(aNewAnnotation, -1); - } - // fix user calls for duplicated slide SdrObjListIter aSourceIter( &rSrcPage, SdrIterMode::DeepWithGroups ); SdrObjListIter aTargetIter( this, SdrIterMode::DeepWithGroups ); diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index ec6f0a14d6c6..64262a233471 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -981,10 +981,25 @@ void AnnotationManagerImpl::SyncAnnotationObjects() if (!mxCurrentPage.is() || !mpDoc) return; - auto xViewShell = mrBase.GetMainViewShell(); - if (!xViewShell) + sd::DrawDocShell* pDocShell = dynamic_cast<sd::DrawDocShell*>(SfxObjectShell::Current()); + sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr; + + if (!pViewShell) + { + pViewShell = mrBase.GetMainViewShell().get(); + if (!pViewShell) + return; + } + + auto* pView = pViewShell->GetView(); + if (!pView) return; + if (!pView->GetSdrPageView()) + return; + + auto& rModel = pView->getSdrModelFromSdrView(); + sal_Int32 nIndex = 1; bool bAnnotatonInserted = false; for (auto const& xAnnotation : mxCurrentPage->getAnnotations()) @@ -1001,9 +1016,6 @@ void AnnotationManagerImpl::SyncAnnotationObjects() auto const& rInfo = xAnnotation->getCreationInfo(); - auto* pView = xViewShell->GetView(); - auto& rModel = pView->getSdrModelFromSdrView(); - auto aRealPoint2D = xAnnotation->getPosition(); Point aPosition(::tools::Long(aRealPoint2D.X * 100.0), ::tools::Long(aRealPoint2D.Y * 100.0)); |