From 4fbb4242d924c0a7a43a10c4ecd4a33f8b339310 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 17 Jun 2024 14:39:34 +0900 Subject: annot: update object text when annotation text changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the annotation text changes we need to sync this with the SDR object (if the object is showing the annotation text - like free text annotation). Also move annotation object searching to the annotation class, so it can be reused in AnnotationWindow. Also change uso of UNO XAnnotation in AnnotationWindow and use concrete type (sdr::annotation::Anootation) instead. Change-Id: I46db479ae8471c82ac58487a0125df15697245be Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168977 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sd/source/ui/annotations/annotationmanager.cxx | 22 ++-------------- sd/source/ui/annotations/annotationwindow.cxx | 36 ++++++++++++++++++++------ sd/source/ui/annotations/annotationwindow.hxx | 11 ++++---- 3 files changed, 36 insertions(+), 33 deletions(-) (limited to 'sd/source/ui/annotations') diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index a6918f9e15d8..ec6f0a14d6c6 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -167,24 +167,6 @@ OUString getAnnotationDateTimeString(const uno::Reference& return sRet; } -namespace -{ - -SdrObject* findAnnotationObjectMatching(rtl::Reference const& xAnnotation) -{ - SdrPage const* pPage = xAnnotation->getPage(); - - for (size_t i = 0; i < pPage->GetObjCount(); ++i) - { - SdrObject* pObject = pPage->GetObj(i); - if (pObject->isAnnotationObject() && pObject->getAnnotationData()->mxAnnotation == xAnnotation) - return pObject; - } - return nullptr; -} - -} // end anonymous ns - AnnotationManagerImpl::AnnotationManagerImpl( ViewShellBase& rViewShellBase ) : mrBase( rViewShellBase ) , mpDoc( rViewShellBase.GetDocument() ) @@ -443,7 +425,7 @@ void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq) auto pSdAnnotation = static_cast(xAnnotation.get()); pSdAnnotation->createChangeUndo(); - SdrObject* pObject = findAnnotationObjectMatching(xAnnotation); + SdrObject* pObject = xAnnotation->findAnnotationObject(); if (pObject && nPositionX >= 0 && nPositionY >= 0) { double fX = convertTwipToMm100(nPositionX); @@ -1007,7 +989,7 @@ void AnnotationManagerImpl::SyncAnnotationObjects() bool bAnnotatonInserted = false; for (auto const& xAnnotation : mxCurrentPage->getAnnotations()) { - SdrObject* pObject = findAnnotationObjectMatching(xAnnotation); + SdrObject* pObject = xAnnotation->findAnnotationObject(); if (pObject) continue; diff --git a/sd/source/ui/annotations/annotationwindow.cxx b/sd/source/ui/annotations/annotationwindow.cxx index b3d8778fe780..1430e2875e28 100644 --- a/sd/source/ui/annotations/annotationwindow.cxx +++ b/sd/source/ui/annotations/annotationwindow.cxx @@ -57,6 +57,9 @@ #include #include #include +#include +#include +#include #include #include @@ -207,7 +210,7 @@ void AnnotationTextWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea) // see SwAnnotationWin in sw for something similar AnnotationWindow::AnnotationWindow(weld::Window* pParent, const ::tools::Rectangle& rRect, DrawDocShell* pDocShell, - const uno::Reference& xAnnotation) + rtl::Reference const& xAnnotation) : mxBuilder(Application::CreateBuilder(pParent, u"modules/simpress/ui/annotation.ui"_ustr)) , mxPopover(mxBuilder->weld_popover(u"Annotation"_ustr)) , mxContainer(mxBuilder->weld_widget(u"container"_ustr)) @@ -300,15 +303,18 @@ IMPL_LINK(AnnotationWindow, MenuItemSelectedHdl, const OUString&, rIdent, void) if (!pDispatcher) return; + uno::Reference xUnoAnnotation(mxAnnotation); + if (rIdent == ".uno:ReplyToAnnotation") { - const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, uno::Any(mxAnnotation)); + + const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, uno::Any(xUnoAnnotation)); pDispatcher->ExecuteList(SID_REPLYTO_POSTIT, SfxCallMode::ASYNCHRON, { &aItem }); } else if (rIdent == ".uno:DeleteAnnotation") { - const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, uno::Any(mxAnnotation)); + const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, uno::Any(xUnoAnnotation)); pDispatcher->ExecuteList(SID_DELETE_POSTIT, SfxCallMode::ASYNCHRON, { &aItem }); } @@ -489,9 +495,9 @@ sdr::annotation::TextApiObject* getTextApiObject(const uno::Reference& xAnnotation) +void AnnotationWindow::setAnnotation(rtl::Reference const& xAnnotation) { - if( (xAnnotation == mxAnnotation) || !xAnnotation.is() ) + if (xAnnotation == mxAnnotation || !xAnnotation.is()) return; mxAnnotation = xAnnotation; @@ -502,7 +508,7 @@ void AnnotationWindow::setAnnotation(const uno::Reference& mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor(); mpOutliner->Clear(); - auto* pTextApi = getTextApiObject( mxAnnotation ); + auto* pTextApi = getTextApiObject(mxAnnotation); if( pTextApi ) { @@ -609,6 +615,18 @@ void AnnotationWindow::SaveToDocument() // set current time to changed annotation xAnnotation->setDateTime( getCurrentDateTime() ); + rtl::Reference xSdrAnnotation = dynamic_cast(xAnnotation.get()); + if (xSdrAnnotation && xSdrAnnotation->getCreationInfo().meType == sdr::annotation::AnnotationType::FreeText) + { + SdrObject* pObject = xSdrAnnotation->findAnnotationObject(); + SdrRectObj* pRectangleObject = pObject ? dynamic_cast(pObject) : nullptr; + if (pRectangleObject) + { + OUString aString = xSdrAnnotation->getTextRange()->getString(); + pRectangleObject->SetText(aString); + } + } + if( mpDoc->IsUndoEnabled() ) mpDoc->EndUndo(); @@ -754,15 +772,17 @@ bool AnnotationTextWindow::Command(const CommandEvent& rCEvt) auto sId = xMenu->popup_at_rect(pPopupParent, aRect); + uno::Reference xUnoAnnotation(mrContents.getAnnotation()); + if (sId == ".uno:ReplyToAnnotation") { - const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, uno::Any(xAnnotation)); + const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, uno::Any(xUnoAnnotation)); pDispatcher->ExecuteList(SID_REPLYTO_POSTIT, SfxCallMode::ASYNCHRON, { &aItem }); } else if (sId == ".uno:DeleteAnnotation") { - const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, uno::Any(xAnnotation)); + const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, uno::Any(xUnoAnnotation)); pDispatcher->ExecuteList(SID_DELETE_POSTIT, SfxCallMode::ASYNCHRON, { &aItem }); } diff --git a/sd/source/ui/annotations/annotationwindow.hxx b/sd/source/ui/annotations/annotationwindow.hxx index fd5919b40d06..31f82348b371 100644 --- a/sd/source/ui/annotations/annotationwindow.hxx +++ b/sd/source/ui/annotations/annotationwindow.hxx @@ -22,13 +22,14 @@ #include #include #include +#include -namespace com::sun::star::office { class XAnnotation; } class OutlinerView; class Outliner; class SvxLanguageItem; class SdDrawDocument; + namespace sdr::annotation { class TextApiObject; } namespace sd @@ -72,7 +73,7 @@ private: bool mbReadonly; bool mbProtected; - css::uno::Reference< css::office::XAnnotation > mxAnnotation; + rtl::Reference mxAnnotation; public: Color maColor; @@ -98,12 +99,12 @@ private: void InitControls(); void SetMapMode(const MapMode& rNewMapMode); - void setAnnotation(const css::uno::Reference& xAnnotation); + void setAnnotation(rtl::Reference const& xAnnotation); static sal_Int32 GetPrefScrollbarWidth() { return 16; } public: AnnotationWindow(weld::Window* pParent, const ::tools::Rectangle& rRect, DrawDocShell* pDocShell, - const css::uno::Reference& xAnnotation); + const rtl::Reference& xAnnotation); void connect_closed(const Link& rLink) { mxPopover->connect_closed(rLink); } @@ -112,7 +113,7 @@ public: void SetScrollbar(); void StartEdit(); - const css::uno::Reference& getAnnotation() const { return mxAnnotation; } + const rtl::Reference& getAnnotation() const { return mxAnnotation; } void SaveToDocument(); -- cgit