include/svx/annotation/ObjectAnnotationData.hxx | 9 ++++ sd/source/core/sdpage2.cxx | 4 -- sd/source/ui/annotations/annotationmanager.cxx | 46 +++++++++++++++++------- sd/source/ui/annotations/annotationwindow.hxx | 2 - sd/source/ui/func/fusel.cxx | 5 -- sd/source/ui/inc/annotationmanager.hxx | 3 + 6 files changed, 48 insertions(+), 21 deletions(-)
New commits: commit 481e230e834c903e7ec0f045c20039910ad894ed Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jan 7 12:12:52 2025 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Jan 7 05:44:09 2025 +0100 tdf#162246 use main ViewShell when synching the annotations Current ViewShell is not always available, but we use the main ViewShell most of the time anyway in AnnotationManager, so use that when annotation synching. Use only the current ViewShell when opening the annotation pop-up window. Change-Id: Ibbc8e0859d0b91617577148e76e8293cb8015941 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179849 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index 7c8de65421bd..cfcfa52ef971 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -1010,17 +1010,12 @@ void AnnotationManagerImpl::SyncAnnotationObjects() if (!mxCurrentPage.is() || !mpDoc) return; - sd::DrawDocShell* pDocShell = dynamic_cast<sd::DrawDocShell*>(SfxObjectShell::Current()); - sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr; + std::shared_ptr<DrawViewShell> pDrawViewShell = std::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()); - if (!pViewShell) - { - pViewShell = mrBase.GetMainViewShell().get(); - if (!pViewShell) - return; - } + if (!pDrawViewShell) + return; - auto* pView = pViewShell->GetView(); + auto* pView = pDrawViewShell->GetView(); if (!pView) return; commit d3afb7acebc023340aef5d70d4f35cecb359cd54 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jan 7 11:58:19 2025 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Jan 7 05:43:58 2025 +0100 tdf#164529 support annotation selection with edit (trigger pop-up) In some instances we want to select the annotation and edit them at the same time - trigger pop-up. This change adds back support for that. Also properly close the pop-ups when the view shell and window are destroyed. Change-Id: I17abeb39a7500001b148b8923eb9028d297a40a3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179664 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/annotation/ObjectAnnotationData.hxx b/include/svx/annotation/ObjectAnnotationData.hxx index f7dc220d789d..bedbb1a0da29 100644 --- a/include/svx/annotation/ObjectAnnotationData.hxx +++ b/include/svx/annotation/ObjectAnnotationData.hxx @@ -19,6 +19,8 @@ namespace sdr::annotation class ObjectAnnotationData { public: + ~ObjectAnnotationData() { closePopup(); } + /// The annotation rtl::Reference<sdr::annotation::Annotation> mxAnnotation; @@ -31,6 +33,13 @@ public: if (mpAnnotationPopup) mpAnnotationPopup->openPopup(); } + + /// Close popup for the annotation + void closePopup() + { + if (mpAnnotationPopup) + mpAnnotationPopup->closePopup(); + } }; } diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx index 794b30f2c592..08194915d4a0 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -603,9 +603,7 @@ void SdPage::removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation SdrObject* pObject = GetObj(nObjectIndex); if (pObject->isAnnotationObject() && pObject->getAnnotationData()->mxAnnotation == xAnnotation) { - auto& pAnnotationPopup = pObject->getAnnotationData()->mpAnnotationPopup; - if (pAnnotationPopup) - pAnnotationPopup->closePopup(); + pObject->getAnnotationData()->closePopup(); RemoveObject(nObjectIndex); } } diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index ec876c667aaa..7c8de65421bd 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/office/XAnnotationAccess.hpp> #include <comphelper/lok.hxx> #include <svx/svxids.hrc> +#include <svx/svditer.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> @@ -208,6 +209,22 @@ void AnnotationManagerImpl::init() // WeakComponentImplHelper void AnnotationManagerImpl::disposing (std::unique_lock<std::mutex>&) { + for (sal_uInt16 i = 0; i < mpDoc->GetPageCount(); i++) + { + SdrPage* pPage = mpDoc->GetPage(i); + SdrObjListIter aIterator(pPage, SdrIterMode::DeepWithGroups); + while (aIterator.IsMore()) + { + SdrObject* pObject = aIterator.Next(); + if (pObject) + { + auto& xAnnotationData = pObject->getAnnotationData(); + if (xAnnotationData) + xAnnotationData->closePopup(); + } + } + } + try { uno::Reference<document::XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); @@ -875,9 +892,19 @@ void AnnotationManagerImpl::SelectNextAnnotation(bool bForward) while( true ); } -void AnnotationManagerImpl::SelectAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, bool /*bEdit*/) +void AnnotationManagerImpl::SelectAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, bool bEdit) { mxSelectedAnnotation = xAnnotation; + if (bEdit) + { + SdrObject* pObject = xAnnotation->findAnnotationObject(); + if (pObject) + { + auto& pAnnotationData = pObject->getAnnotationData(); + if (pAnnotationData) + pAnnotationData->openPopup(); + } + } } void AnnotationManagerImpl::GetSelectedAnnotation( rtl::Reference<sdr::annotation::Annotation>& xAnnotation ) @@ -1292,9 +1319,9 @@ void AnnotationManager::GetAnnotationState(SfxItemSet& rItemSet) mxImpl->GetAnnotationState(rItemSet); } -void AnnotationManager::SelectAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) +void AnnotationManager::SelectAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, bool bEdit) { - mxImpl->SelectAnnotation(xAnnotation); + mxImpl->SelectAnnotation(xAnnotation, bEdit); } } // end sd diff --git a/sd/source/ui/annotations/annotationwindow.hxx b/sd/source/ui/annotations/annotationwindow.hxx index 31f82348b371..d7f3d98e10b0 100644 --- a/sd/source/ui/annotations/annotationwindow.hxx +++ b/sd/source/ui/annotations/annotationwindow.hxx @@ -105,6 +105,7 @@ private: public: AnnotationWindow(weld::Window* pParent, const ::tools::Rectangle& rRect, DrawDocShell* pDocShell, const rtl::Reference<sdr::annotation::Annotation>& xAnnotation); + ~AnnotationWindow(); void connect_closed(const Link<weld::Popover&, void>& rLink) { mxPopover->connect_closed(rLink); } @@ -131,7 +132,6 @@ public: OutlinerView* GetOutlinerView() { return mpOutlinerView.get();} ::Outliner* GetOutliner() { return mpOutliner.get();} - ~AnnotationWindow(); void SetColor(); }; diff --git a/sd/source/ui/func/fusel.cxx b/sd/source/ui/func/fusel.cxx index bc2da0ced224..aa43a76ee91b 100644 --- a/sd/source/ui/func/fusel.cxx +++ b/sd/source/ui/func/fusel.cxx @@ -869,10 +869,7 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt) { auto* pDrawViewShell = dynamic_cast<DrawViewShell*>(mpViewShell); if (pDrawViewShell && pDrawViewShell->getAnnotationManagerPtr()) - { - pDrawViewShell->getAnnotationManagerPtr()->SelectAnnotation(pAnnotationData->mxAnnotation); - } - pAnnotationData->openPopup(); + pDrawViewShell->getAnnotationManagerPtr()->SelectAnnotation(pAnnotationData->mxAnnotation, true); } return true; } diff --git a/sd/source/ui/inc/annotationmanager.hxx b/sd/source/ui/inc/annotationmanager.hxx index 25bf5503384e..b9af2ecca1b3 100644 --- a/sd/source/ui/inc/annotationmanager.hxx +++ b/sd/source/ui/inc/annotationmanager.hxx @@ -42,7 +42,8 @@ public: void ExecuteAnnotation(SfxRequest const& rRequest); void GetAnnotationState(SfxItemSet& rItemSet); - void SelectAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation); + void SelectAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, + bool bEdit = false); private: ::rtl::Reference<AnnotationManagerImpl> mxImpl;