include/svx/annotation/Annotation.hxx           |    1 
 include/svx/annotation/IAnnotationPopup.hxx     |   37 +++++++
 include/svx/annotation/ObjectAnnotationData.hxx |    9 +
 sd/Library_sd.mk                                |    1 
 sd/source/core/sdpage2.cxx                      |    1 
 sd/source/ui/annotations/AnnotationPopup.cxx    |  115 ++++++++++++++++++++++++
 sd/source/ui/annotations/AnnotationPopup.hxx    |   46 +++++++++
 sd/source/ui/annotations/annotationmanager.cxx  |    3 
 sd/source/ui/func/fusel.cxx                     |   12 ++
 svx/source/svdraw/svdobj.cxx                    |   41 ++++++--
 svx/source/svdraw/svdotxed.cxx                  |    9 +
 11 files changed, 262 insertions(+), 13 deletions(-)

New commits:
commit 7235eec702299190754af3a81186ac0aa82d5be3
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Jun 7 12:15:28 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Jun 11 12:49:15 2024 +0200

    annot: make annotation pop-up window working again
    
    The code to open AnnotatationWindow was removed in the previous
    change as it needed to be changed to make it work with annotation
    (sdr) object.
    
    Change-Id: Ic75e4fca6b46359f29762bc4735a76204aeb90f3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168514
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Tested-by: Jenkins

diff --git a/include/svx/annotation/IAnnotationPopup.hxx 
b/include/svx/annotation/IAnnotationPopup.hxx
new file mode 100644
index 000000000000..8a705ef1e935
--- /dev/null
+++ b/include/svx/annotation/IAnnotationPopup.hxx
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <svx/svxdllapi.h>
+
+#include <svx/annotation/Annotation.hxx>
+
+namespace sdr::annotation
+{
+class SVXCORE_DLLPUBLIC IAnnotationPopup
+{
+protected:
+    rtl::Reference<sdr::annotation::Annotation> mxAnnotation;
+
+public:
+    IAnnotationPopup(rtl::Reference<sdr::annotation::Annotation> const& 
pAnnotation)
+        : mxAnnotation(pAnnotation)
+    {
+    }
+
+    virtual ~IAnnotationPopup() {}
+
+    virtual void openPopup() = 0;
+    virtual void closePopup() = 0;
+};
+
+} // end sdr::annotation
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/annotation/ObjectAnnotationData.hxx 
b/include/svx/annotation/ObjectAnnotationData.hxx
index 44776638e64f..50a2f80c80ac 100644
--- a/include/svx/annotation/ObjectAnnotationData.hxx
+++ b/include/svx/annotation/ObjectAnnotationData.hxx
@@ -11,6 +11,7 @@
 
 #include <svx/svxdllapi.h>
 #include <svx/annotation/Annotation.hxx>
+#include <svx/annotation/IAnnotationPopup.hxx>
 
 namespace sdr::annotation
 {
@@ -20,6 +21,13 @@ class ObjectAnnotationData
 public:
     bool mbIsAnnotation : 1 = false;
     rtl::Reference<sdr::annotation::Annotation> mxAnnotation;
+    std::unique_ptr<sdr::annotation::IAnnotationPopup> mpAnnotationPopup;
+
+    void openPopup()
+    {
+        if (mbIsAnnotation && mpAnnotationPopup)
+            mpAnnotationPopup->openPopup();
+    }
 };
 }
 
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index 5da9c10b2adf..01a1d8f491e0 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -212,6 +212,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
        sd/source/ui/animations/SlideTransitionPane \
        sd/source/ui/animations/motionpathtag \
        sd/source/ui/annotations/annotationmanager \
+       sd/source/ui/annotations/AnnotationPopup \
        sd/source/ui/annotations/annotationwindow \
        sd/source/ui/app/optsitem \
        sd/source/ui/app/sddll \
diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index 620871e1cae8..45563bdf0c70 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -619,6 +619,7 @@ void 
SdPage::removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation
         SdrObject* pObject = GetObj(nObjectIndex);
         if (pObject->isAnnotationObject() && 
pObject->getAnnotationData()->mxAnnotation == xAnnotation)
         {
+            pObject->getAnnotationData()->mpAnnotationPopup->closePopup();
             RemoveObject(nObjectIndex);
         }
     }
diff --git a/sd/source/ui/annotations/AnnotationPopup.cxx 
b/sd/source/ui/annotations/AnnotationPopup.cxx
new file mode 100644
index 000000000000..068d48796302
--- /dev/null
+++ b/sd/source/ui/annotations/AnnotationPopup.cxx
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <com/sun/star/geometry/RealPoint2D.hpp>
+#include <com/sun/star/office/XAnnotation.hpp>
+
+#include "AnnotationPopup.hxx"
+#include <rtl/ustrbuf.hxx>
+
+#include <utility>
+#include <vcl/commandevent.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/settings.hxx>
+#include <vcl/weldutils.hxx>
+
+#include <svx/sdr/overlay/overlayanimatedbitmapex.hxx>
+#include <svx/sdr/overlay/overlaybitmapex.hxx>
+#include <svx/sdr/overlay/overlaypolypolygon.hxx>
+#include <svx/svdpagv.hxx>
+#include <svx/sdrpagewindow.hxx>
+#include <svx/sdrpaintwindow.hxx>
+#include <svx/svddrgmt.hxx>
+#include <tools/debug.hxx>
+#include <sfx2/objsh.hxx>
+
+#include <View.hxx>
+#include <sdresid.hxx>
+#include <strings.hrc>
+#include "annotationmanagerimpl.hxx"
+#include "annotationwindow.hxx"
+#include <svx/annotation/Annotation.hxx>
+#include <Annotation.hxx>
+#include <ViewShell.hxx>
+#include <Window.hxx>
+#include <drawdoc.hxx>
+#include <DrawDocShell.hxx>
+
+using namespace ::com::sun::star;
+
+namespace sd
+{
+AnnotationPopup::AnnotationPopup(rtl::Reference<sdr::annotation::Annotation> 
const& xAnnotation)
+    : sdr::annotation::IAnnotationPopup(xAnnotation)
+{
+}
+
+AnnotationPopup::~AnnotationPopup() {}
+
+IMPL_LINK_NOARG(AnnotationPopup, PopupModeEndHdl, weld::Popover&, void) { 
closePopup(); }
+
+void AnnotationPopup::closePopup()
+{
+    if (mpAnnotationWindow)
+    {
+        mpAnnotationWindow->SaveToDocument();
+        mpAnnotationWindow.reset();
+    }
+}
+
+void AnnotationPopup::openPopup()
+{
+    if (!mxAnnotation.is())
+        return;
+
+    sd::DrawDocShell* pDocShell = 
dynamic_cast<sd::DrawDocShell*>(SfxObjectShell::Current());
+    sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : 
nullptr;
+
+    if (!pViewShell)
+        return;
+
+    auto* pView = pViewShell->GetView();
+    if (!pView)
+        return;
+
+    if (!mpAnnotationWindow)
+    {
+        OutputDevice* pOut = pView->GetFirstOutputDevice();
+        vcl::Window* pWindow = pOut ? pOut->GetOwnerWindow() : nullptr;
+        if (pWindow)
+        {
+            auto aRealPosition2D = mxAnnotation->getPosition();
+            Point aPosition(::tools::Long(aRealPosition2D.X * 100.0),
+                            ::tools::Long(aRealPosition2D.Y * 100.0));
+            Point aPositionPixel = pWindow->LogicToPixel(aPosition);
+
+            aPositionPixel.AdjustX(4);
+            aPositionPixel.AdjustY(1);
+
+            auto aRealSize2D = mxAnnotation->getSize();
+            Size aSize(::tools::Long(aRealSize2D.Width * 100.0),
+                       ::tools::Long(aRealSize2D.Height * 100.0));
+            Size aSizePixel = pWindow->LogicToPixel(aSize);
+
+            ::tools::Rectangle aRectangle(aPositionPixel, aSizePixel);
+
+            weld::Window* pParent = weld::GetPopupParent(*pWindow, aRectangle);
+            mpAnnotationWindow.reset(
+                new AnnotationWindow(pParent, aRectangle, pDocShell, 
mxAnnotation));
+            mpAnnotationWindow->connect_closed(LINK(this, AnnotationPopup, 
PopupModeEndHdl));
+        }
+    }
+
+    if (mpAnnotationWindow)
+        mpAnnotationWindow->StartEdit();
+}
+
+} // end of namespace sd
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/annotations/AnnotationPopup.hxx 
b/sd/source/ui/annotations/AnnotationPopup.hxx
new file mode 100644
index 000000000000..f7305ad9eecc
--- /dev/null
+++ b/sd/source/ui/annotations/AnnotationPopup.hxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <svx/annotation/IAnnotationPopup.hxx>
+#include <vcl/weld.hxx>
+
+namespace com::sun::star::office
+{
+class XAnnotation;
+}
+namespace sdr::annotation
+{
+class Annotation;
+}
+
+namespace sd
+{
+class View;
+class AnnotationWindow;
+
+class AnnotationPopup final : public sdr::annotation::IAnnotationPopup
+{
+public:
+    AnnotationPopup(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation);
+    virtual ~AnnotationPopup() override;
+
+    void openPopup() override;
+    void closePopup() override;
+
+private:
+    DECL_LINK(PopupModeEndHdl, weld::Popover&, void);
+
+    std::unique_ptr<AnnotationWindow> mpAnnotationWindow;
+};
+
+} // end of namespace sd
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index ee5662fd2bcf..9a4d241f44e3 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -63,6 +63,7 @@
 #include <strings.hrc>
 
 #include <Annotation.hxx>
+#include "AnnotationPopup.hxx"
 #include <DrawDocShell.hxx>
 #include <DrawViewShell.hxx>
 #include <sdresid.hxx>
@@ -951,11 +952,11 @@ SdrObject* 
AnnotationManagerImpl::findAnnotationObjectMatching(rtl::Reference<sd
 
 namespace
 {
-
 void applyAnnotationCommon(SdrObject& rObject, 
rtl::Reference<sdr::annotation::Annotation> const& xAnnotation)
 {
     rObject.setAsAnnotationObject(true);
     auto& xAnnotationData = rObject.getAnnotationData();
+    xAnnotationData->mpAnnotationPopup.reset(new AnnotationPopup(xAnnotation));
     xAnnotationData->mxAnnotation = xAnnotation;
     rObject.SetPrintable(false);
 }
diff --git a/sd/source/ui/func/fusel.cxx b/sd/source/ui/func/fusel.cxx
index 56a0816128ce..0b4def5bb2b0 100644
--- a/sd/source/ui/func/fusel.cxx
+++ b/sd/source/ui/func/fusel.cxx
@@ -56,6 +56,7 @@
 
 #include <svx/sdrhittesthelper.hxx>
 #include <svx/diagram/IDiagramHelper.hxx>
+#include <svx/annotation/ObjectAnnotationData.hxx>
 
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
@@ -661,6 +662,7 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt)
     sal_uInt16 nHitLog = sal_uInt16 ( 
mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
     sal_uInt16 nDrgLog = sal_uInt16 ( 
mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
 
+    bool bWasDragged = false;
     if (mpView->IsFrameDragSingles() || !mpView->HasMarkablePoints())
     {
         /**********************************************************************
@@ -680,7 +682,7 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt)
             }
 
             mpView->SetDragWithCopy(bDragWithCopy);
-            bool bWasDragged(mpView->EndDragObj( mpView->IsDragWithCopy() ));
+            bWasDragged = mpView->EndDragObj(mpView->IsDragWithCopy());
 
             mpView->ForceMarkedToAnotherPage();
 
@@ -859,6 +861,14 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt)
             pSingleObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
         }
 
+        if (!bWasDragged && pSingleObj && pSingleObj->isAnnotationObject() && 
rMEvt.IsLeft())
+        {
+            auto& pAnnotationData = pSingleObj->getAnnotationData();
+            if (pAnnotationData)
+                pAnnotationData->openPopup();
+            return true;
+        }
+
         if ( (nSlotId != SID_OBJECT_SELECT && nMarkCount==0)                   
 ||
              ( mpView->GetDragMode() == SdrDragMode::Crook &&
               !mpView->IsCrookAllowed( mpView->IsCrookNoContortion() ) ) ||
commit 2dc9d587cb38145141a4821006a09606e6625c35
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Jun 7 12:31:10 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Jun 11 12:49:05 2024 +0200

    annot: update annotation position, size, text when those change
    
    Change-Id: I345f4c714ed4ca0c8277e0aedf5ea4b5cd70ea70
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168513
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Tested-by: Jenkins

diff --git a/include/svx/annotation/Annotation.hxx 
b/include/svx/annotation/Annotation.hxx
index 4001d97f406f..8ea57af4d88f 100644
--- a/include/svx/annotation/Annotation.hxx
+++ b/include/svx/annotation/Annotation.hxx
@@ -146,6 +146,7 @@ public:
 
     OUString GetText();
     void SetText(OUString const& rText);
+    rtl::Reference<sdr::annotation::TextApiObject> getTextApiObject() { return 
m_TextRange; }
 
     SdrModel* GetModel() const;
     SdrPage const* getPage() const { return mpPage; }
diff --git a/include/svx/annotation/ObjectAnnotationData.hxx 
b/include/svx/annotation/ObjectAnnotationData.hxx
index bdba8ab5a5b9..44776638e64f 100644
--- a/include/svx/annotation/ObjectAnnotationData.hxx
+++ b/include/svx/annotation/ObjectAnnotationData.hxx
@@ -10,6 +10,7 @@
 #pragma once
 
 #include <svx/svxdllapi.h>
+#include <svx/annotation/Annotation.hxx>
 
 namespace sdr::annotation
 {
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 9da8c5662f12..34101b755ea7 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -1533,15 +1533,24 @@ void SdrObject::NbcShear(const Point& rRef, Degree100 
/*nAngle*/, double tn, boo
     SetGlueReallyAbsolute(false);
 }
 
-void SdrObject::Move(const Size& rSiz)
+void SdrObject::Move(const Size& rSize)
 {
-    if (rSiz.Width()!=0 || rSiz.Height()!=0) {
-        tools::Rectangle aBoundRect0; if (m_pUserCall!=nullptr) 
aBoundRect0=GetLastBoundRect();
-        NbcMove(rSiz);
-        SetChanged();
-        BroadcastObjectChange();
-        SendUserCall(SdrUserCallType::MoveOnly,aBoundRect0);
+    if (rSize.Width() == 0 && rSize.Height() == 0)
+        return;
+
+    tools::Rectangle aBoundRect0;
+    if (m_pUserCall != nullptr)
+        aBoundRect0 = GetLastBoundRect();
+    NbcMove(rSize);
+    if (isAnnotationObject())
+    {
+        auto& rRect = GetCurrentBoundRect();
+        css::geometry::RealPoint2D aNewPosition(rRect.Left() / 100.0, 
rRect.Top() / 100.0);
+        getAnnotationData()->mxAnnotation->SetPosition(aNewPosition);
     }
+    SetChanged();
+    BroadcastObjectChange();
+    SendUserCall(SdrUserCallType::MoveOnly, aBoundRect0);
 }
 
 void SdrObject::NbcCrop(const basegfx::B2DPoint& /*aRef*/, double /*fxFact*/, 
double /*fyFact*/)
@@ -1562,11 +1571,23 @@ void SdrObject::Resize(const Point& rRef, const 
Fraction& xFact, const Fraction&
         mpImpl->meRelativeHeightRelation = text::RelOrientation::PAGE_FRAME;
         mpImpl->mnRelativeHeight.reset();
     }
-    tools::Rectangle aBoundRect0; if (m_pUserCall!=nullptr) 
aBoundRect0=GetLastBoundRect();
-    NbcResize(rRef,xFact,yFact);
+    tools::Rectangle aBoundRect0;
+
+    if (m_pUserCall != nullptr)
+        aBoundRect0 = GetLastBoundRect();
+
+    NbcResize(rRef, xFact, yFact);
+
+    if (isAnnotationObject())
+    {
+        auto& rRect = GetCurrentBoundRect();
+        css::geometry::RealSize2D aNewSize(rRect.GetWidth() / 100.0, 
rRect.GetHeight() / 100.0);
+        getAnnotationData()->mxAnnotation->SetSize(aNewSize);
+    }
+
     SetChanged();
     BroadcastObjectChange();
-    SendUserCall(SdrUserCallType::Resize,aBoundRect0);
+    SendUserCall(SdrUserCallType::Resize, aBoundRect0);
 }
 
 void SdrObject::Crop(const basegfx::B2DPoint& rRef, double fxFact, double 
fyFact)
diff --git a/svx/source/svdraw/svdotxed.cxx b/svx/source/svdraw/svdotxed.cxx
index 4ecca10951e9..adcdb6a578a1 100644
--- a/svx/source/svdraw/svdotxed.cxx
+++ b/svx/source/svdraw/svdotxed.cxx
@@ -29,7 +29,7 @@
 #include <editeng/eeitem.hxx>
 #include <svx/sdtfchim.hxx>
 #include <textchain.hxx>
-
+#include <svx/annotation/ObjectAnnotationData.hxx>
 
 bool SdrTextObj::HasTextEdit() const
 {
@@ -286,6 +286,13 @@ void SdrTextObj::EndTextEdit(SdrOutliner& rOutl)
         } else { // If we are not doing in-chaining switching just set the 
ParaObject
             SetOutlinerParaObject(std::move(pNewText));
         }
+
+        if (isAnnotationObject())
+        {
+            auto 
xTextAPI(getAnnotationData()->mxAnnotation->getTextApiObject());
+            std::optional<OutlinerParaObject> pAnnotationText = 
rOutl.CreateParaObject(0, rOutl.GetParagraphCount());
+            xTextAPI->SetText(*pAnnotationText);
+        }
     }
 
     /* Chaining-related code */

Reply via email to