remove assert looking for new compatibilityMode DOCX
[LibreOffice.git] / sd / source / ui / annotations / AnnotationPopup.cxx
blob491f77a7d1aa51e161137926843864a0e254fc48
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <com/sun/star/geometry/RealPoint2D.hpp>
11 #include <com/sun/star/office/XAnnotation.hpp>
13 #include "AnnotationPopup.hxx"
14 #include <rtl/ustrbuf.hxx>
16 #include <utility>
17 #include <vcl/commandevent.hxx>
18 #include <vcl/svapp.hxx>
19 #include <vcl/settings.hxx>
20 #include <vcl/weldutils.hxx>
22 #include <svx/sdr/overlay/overlayanimatedbitmapex.hxx>
23 #include <svx/sdr/overlay/overlaybitmapex.hxx>
24 #include <svx/sdr/overlay/overlaypolypolygon.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <svx/sdrpagewindow.hxx>
27 #include <svx/sdrpaintwindow.hxx>
28 #include <svx/svddrgmt.hxx>
29 #include <tools/debug.hxx>
30 #include <sfx2/objsh.hxx>
32 #include <View.hxx>
33 #include <sdresid.hxx>
34 #include <strings.hrc>
35 #include "annotationmanagerimpl.hxx"
36 #include "annotationwindow.hxx"
37 #include <svx/annotation/Annotation.hxx>
38 #include <Annotation.hxx>
39 #include <ViewShell.hxx>
40 #include <Window.hxx>
41 #include <drawdoc.hxx>
42 #include <DrawDocShell.hxx>
44 using namespace ::com::sun::star;
46 namespace sd
48 AnnotationPopup::AnnotationPopup(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation)
49 : sdr::annotation::IAnnotationPopup(xAnnotation)
53 AnnotationPopup::~AnnotationPopup() {}
55 IMPL_LINK_NOARG(AnnotationPopup, PopupModeEndHdl, weld::Popover&, void) { closePopup(); }
57 void AnnotationPopup::closePopup()
59 if (mpAnnotationWindow)
61 mpAnnotationWindow->SaveToDocument();
62 mpAnnotationWindow.reset();
66 void AnnotationPopup::openPopup()
68 if (!mxAnnotation.is())
69 return;
71 sd::DrawDocShell* pDocShell = dynamic_cast<sd::DrawDocShell*>(SfxObjectShell::Current());
72 sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
74 if (!pViewShell)
75 return;
77 if (!mpAnnotationWindow)
79 vcl::Window* pWindow = pViewShell->GetActiveWindow();
80 if (pWindow)
82 auto aRealPosition2D = mxAnnotation->getPosition();
83 Point aPosition(::tools::Long(aRealPosition2D.X * 100.0),
84 ::tools::Long(aRealPosition2D.Y * 100.0));
85 Point aPositionPixel = pWindow->LogicToPixel(aPosition);
87 aPositionPixel.AdjustX(4);
88 aPositionPixel.AdjustY(1);
90 auto aRealSize2D = mxAnnotation->getSize();
91 Size aSize(::tools::Long(aRealSize2D.Width * 100.0),
92 ::tools::Long(aRealSize2D.Height * 100.0));
93 Size aSizePixel = pWindow->LogicToPixel(aSize);
95 ::tools::Rectangle aRectangle(aPositionPixel, aSizePixel);
97 weld::Window* pParent = weld::GetPopupParent(*pWindow, aRectangle);
98 mpAnnotationWindow.reset(
99 new AnnotationWindow(pParent, aRectangle, pDocShell, mxAnnotation));
100 mpAnnotationWindow->connect_closed(LINK(this, AnnotationPopup, PopupModeEndHdl));
104 if (mpAnnotationWindow)
105 mpAnnotationWindow->StartEdit();
108 } // end of namespace sd
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */