diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2024-06-07 12:15:28 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-06-18 11:19:46 +0200 |
commit | 0aae22f0a19064ba6b67b9008762f693967228a8 (patch) | |
tree | d56b4110c2ec0229ff26c314d398028f534339b3 | |
parent | d65acecc180c437f4c564fb5b3c4ad985986801c (diff) |
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/+/168651
Tested-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | include/svx/annotation/IAnnotationPopup.hxx | 37 | ||||
-rw-r--r-- | include/svx/annotation/ObjectAnnotationData.hxx | 8 | ||||
-rw-r--r-- | sd/Library_sd.mk | 1 | ||||
-rw-r--r-- | sd/source/core/sdpage2.cxx | 1 | ||||
-rw-r--r-- | sd/source/ui/annotations/AnnotationPopup.cxx | 115 | ||||
-rw-r--r-- | sd/source/ui/annotations/AnnotationPopup.hxx | 46 | ||||
-rw-r--r-- | sd/source/ui/annotations/annotationmanager.cxx | 3 | ||||
-rw-r--r-- | sd/source/ui/func/fusel.cxx | 12 |
8 files changed, 221 insertions, 2 deletions
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 bb4da5be6d75..e6eb7c82540c 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -213,6 +213,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 044cb642c8c0..da415e8e5a8e 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -620,6 +620,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 117ca7002808..86dcac409840 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> @@ -954,11 +955,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 501a99369248..6673271232e3 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> @@ -659,6 +660,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()) { /********************************************************************** @@ -678,7 +680,7 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt) } mpView->SetDragWithCopy(bDragWithCopy); - bool bWasDragged(mpView->EndDragObj( mpView->IsDragWithCopy() )); + bWasDragged = mpView->EndDragObj(mpView->IsDragWithCopy()); mpView->ForceMarkedToAnotherPage(); @@ -855,6 +857,14 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt) pSingleObj = mpView->GetMarkedObjectList().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() ) ) || |