diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2024-06-17 14:39:34 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-06-17 10:24:21 +0200 |
commit | 4fbb4242d924c0a7a43a10c4ecd4a33f8b339310 (patch) | |
tree | f26ddf843f5afe2c2d57b0c81881ba4a8a010328 /sd/source/ui/annotations | |
parent | 23052214e026745fc5d8e780b91630e1f8dea205 (diff) |
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/+/168977
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sd/source/ui/annotations')
-rw-r--r-- | sd/source/ui/annotations/annotationmanager.cxx | 22 | ||||
-rw-r--r-- | sd/source/ui/annotations/annotationwindow.cxx | 36 | ||||
-rw-r--r-- | sd/source/ui/annotations/annotationwindow.hxx | 11 |
3 files changed, 36 insertions, 33 deletions
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<office::XAnnotation>& 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() ) @@ -443,7 +425,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); @@ -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 <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> @@ -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<office::XAnnotation>& xAnnotation) + rtl::Reference<sdr::annotation::Annotation> 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<office::XAnnotation> 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<office::XA return nullptr; } -void AnnotationWindow::setAnnotation(const uno::Reference<office::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; @@ -502,7 +508,7 @@ void AnnotationWindow::setAnnotation(const uno::Reference<office::XAnnotation>& 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<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(); @@ -754,15 +772,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, 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 <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(); |