include/svx/annotation/Annotation.hxx | 2 + sd/source/ui/annotations/annotationmanager.cxx | 22 +-------------- sd/source/ui/annotations/annotationwindow.cxx | 35 +++++++++++++++++++------ sd/source/ui/annotations/annotationwindow.hxx | 11 ++++--- svx/source/annotation/Annotation.cxx | 15 ++++++++++ 5 files changed, 52 insertions(+), 33 deletions(-)
New commits: commit 586d9531c8027dbc49c550a3d36d9e1f3c51cd21 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Jun 17 14:39:34 2024 +0900 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Jun 18 13:31:04 2024 +0200 annot: update object text when annotation text changes 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/+/168981 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/svx/annotation/Annotation.hxx b/include/svx/annotation/Annotation.hxx index 8ffaad3f0997..21e6b76261ad 100644 --- a/include/svx/annotation/Annotation.hxx +++ b/include/svx/annotation/Annotation.hxx @@ -178,6 +178,8 @@ public: CreationInfo const& getCreationInfo() { return maCreationInfo; } void setCreationInfo(CreationInfo const& rCreationInfo) { maCreationInfo = rCreationInfo; } + + SdrObject* findAnnotationObject(); }; /** Vector of annotations */ diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index 87cfa6014806..27f06efb20f9 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -181,24 +181,6 @@ OUString getAnnotationDateTimeString( const Reference< XAnnotation >& xAnnotatio return sRet; } -namespace -{ - -SdrObject* findAnnotationObjectMatching(rtl::Reference<sdr::annotation::Annotation> 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() ) @@ -456,7 +438,7 @@ void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq) auto pSdAnnotation = static_cast<sd::Annotation*>(xAnnotation.get()); pSdAnnotation->createChangeUndo(); - SdrObject* pObject = findAnnotationObjectMatching(xAnnotation); + SdrObject* pObject = xAnnotation->findAnnotationObject(); if (pObject && nPositionX >= 0 && nPositionY >= 0) { double fX = convertTwipToMm100(nPositionX); @@ -1017,7 +999,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 0b98f606498a..04945f11431a 100644 --- a/sd/source/ui/annotations/annotationwindow.cxx +++ b/sd/source/ui/annotations/annotationwindow.cxx @@ -54,6 +54,9 @@ #include <ViewShell.hxx> #include <drawdoc.hxx> #include <svx/annotation/TextAPI.hxx> +#include <svx/annotation/Annotation.hxx> +#include <svx/annotation/ObjectAnnotationData.hxx> +#include <svx/svdorect.hxx> #include <sdresid.hxx> #include <memory> @@ -208,7 +211,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 Reference<XAnnotation>& xAnnotation) + rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) : mxBuilder(Application::CreateBuilder(pParent, "modules/simpress/ui/annotation.ui")) , mxPopover(mxBuilder->weld_popover("Annotation")) , mxContainer(mxBuilder->weld_widget("container")) @@ -304,15 +307,17 @@ IMPL_LINK(AnnotationWindow, MenuItemSelectedHdl, const OUString&, rIdent, void) if (!pDispatcher) return; + uno::Reference<office::XAnnotation> xUnoAnnotation(mxAnnotation); + if (rIdent == ".uno:ReplyToAnnotation") { - const SfxUnoAnyItem aItem( SID_REPLYTO_POSTIT, Any( mxAnnotation ) ); + const SfxUnoAnyItem aItem( SID_REPLYTO_POSTIT, Any( xUnoAnnotation ) ); pDispatcher->ExecuteList(SID_REPLYTO_POSTIT, SfxCallMode::ASYNCHRON, { &aItem }); } else if (rIdent == ".uno:DeleteAnnotation") { - const SfxUnoAnyItem aItem( SID_DELETE_POSTIT, Any( mxAnnotation ) ); + const SfxUnoAnyItem aItem( SID_DELETE_POSTIT, Any( xUnoAnnotation ) ); pDispatcher->ExecuteList(SID_DELETE_POSTIT, SfxCallMode::ASYNCHRON, { &aItem }); } @@ -493,9 +498,9 @@ sdr::annotation::TextApiObject* getTextApiObject( const Reference< XAnnotation > return nullptr; } -void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotation ) +void AnnotationWindow::setAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) { - if( (xAnnotation == mxAnnotation) || !xAnnotation.is() ) + if (xAnnotation == mxAnnotation || !xAnnotation.is()) return; mxAnnotation = xAnnotation; @@ -506,7 +511,7 @@ void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotatio mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor(); mpOutliner->Clear(); - auto* pTextApi = getTextApiObject( mxAnnotation ); + auto* pTextApi = getTextApiObject(mxAnnotation); if( pTextApi ) { @@ -587,6 +592,18 @@ void AnnotationWindow::SaveToDocument() // set current time to changed annotation xAnnotation->setDateTime( getCurrentDateTime() ); + rtl::Reference<sdr::annotation::Annotation> xSdrAnnotation = dynamic_cast<sdr::annotation::Annotation*>(xAnnotation.get()); + if (xSdrAnnotation && xSdrAnnotation->getCreationInfo().meType == sdr::annotation::AnnotationType::FreeText) + { + SdrObject* pObject = xSdrAnnotation->findAnnotationObject(); + SdrRectObj* pRectangleObject = pObject ? dynamic_cast<SdrRectObj*>(pObject) : nullptr; + if (pRectangleObject) + { + OUString aString = xSdrAnnotation->getTextRange()->getString(); + pRectangleObject->SetText(aString); + } + } + if( mpDoc->IsUndoEnabled() ) mpDoc->EndUndo(); @@ -732,15 +749,17 @@ bool AnnotationTextWindow::Command(const CommandEvent& rCEvt) auto sId = xMenu->popup_at_rect(pPopupParent, aRect); + uno::Reference<office::XAnnotation> xUnoAnnotation(mrContents.getAnnotation()); + if (sId == ".uno:ReplyToAnnotation") { - const SfxUnoAnyItem aItem( SID_REPLYTO_POSTIT, Any( xAnnotation ) ); + const SfxUnoAnyItem aItem( SID_REPLYTO_POSTIT, Any( xUnoAnnotation ) ); pDispatcher->ExecuteList(SID_REPLYTO_POSTIT, SfxCallMode::ASYNCHRON, { &aItem }); } else if (sId == ".uno:DeleteAnnotation") { - const SfxUnoAnyItem aItem( SID_DELETE_POSTIT, Any( xAnnotation ) ); + const SfxUnoAnyItem aItem( SID_DELETE_POSTIT, 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 <vcl/weld.hxx> #include <tools/long.hxx> #include <svx/weldeditview.hxx> +#include <svx/annotation/Annotation.hxx> -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<sdr::annotation::Annotation> mxAnnotation; public: Color maColor; @@ -98,12 +99,12 @@ private: void InitControls(); void SetMapMode(const MapMode& rNewMapMode); - void setAnnotation(const css::uno::Reference<css::office::XAnnotation>& xAnnotation); + void setAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation); static sal_Int32 GetPrefScrollbarWidth() { return 16; } public: AnnotationWindow(weld::Window* pParent, const ::tools::Rectangle& rRect, DrawDocShell* pDocShell, - const css::uno::Reference<css::office::XAnnotation>& xAnnotation); + const rtl::Reference<sdr::annotation::Annotation>& xAnnotation); void connect_closed(const Link<weld::Popover&, void>& rLink) { mxPopover->connect_closed(rLink); } @@ -112,7 +113,7 @@ public: void SetScrollbar(); void StartEdit(); - const css::uno::Reference<css::office::XAnnotation>& getAnnotation() const { return mxAnnotation; } + const rtl::Reference<sdr::annotation::Annotation>& getAnnotation() const { return mxAnnotation; } void SaveToDocument(); diff --git a/svx/source/annotation/Annotation.cxx b/svx/source/annotation/Annotation.cxx index d2689474c2e0..6f96af5e7300 100644 --- a/svx/source/annotation/Annotation.cxx +++ b/svx/source/annotation/Annotation.cxx @@ -8,6 +8,7 @@ */ #include <svx/annotation/Annotation.hxx> +#include <svx/annotation/ObjectAnnotationData.hxx> #include <svx/svdpage.hxx> #include <tools/json_writer.hxx> #include <sfx2/viewsh.hxx> @@ -200,6 +201,20 @@ void SAL_CALL Annotation::disposing() } } +SdrObject* Annotation::findAnnotationObject() +{ + SdrPage const* pPage = getPage(); + + for (size_t i = 0; i < pPage->GetObjCount(); ++i) + { + SdrObject* pObject = pPage->GetObj(i); + if (pObject->isAnnotationObject() + && pObject->getAnnotationData()->mxAnnotation.get() == this) + return pObject; + } + return nullptr; +} + } // namespace sdr::annotation /* vim:set shiftwidth=4 softtabstop=4 expandtab: */