/src/libreoffice/sd/source/ui/annotations/AnnotationPopup.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | */ |
9 | | |
10 | | #include <com/sun/star/geometry/RealPoint2D.hpp> |
11 | | #include <com/sun/star/office/XAnnotation.hpp> |
12 | | |
13 | | #include "AnnotationPopup.hxx" |
14 | | #include <rtl/ustrbuf.hxx> |
15 | | |
16 | | #include <utility> |
17 | | #include <vcl/commandevent.hxx> |
18 | | #include <vcl/svapp.hxx> |
19 | | #include <vcl/settings.hxx> |
20 | | #include <vcl/weldutils.hxx> |
21 | | |
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> |
31 | | |
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> |
43 | | |
44 | | using namespace ::com::sun::star; |
45 | | |
46 | | namespace sd |
47 | | { |
48 | | AnnotationPopup::AnnotationPopup(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) |
49 | 0 | : sdr::annotation::IAnnotationPopup(xAnnotation) |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | 0 | AnnotationPopup::~AnnotationPopup() {} |
54 | | |
55 | 0 | IMPL_LINK_NOARG(AnnotationPopup, PopupModeEndHdl, weld::Popover&, void) { closePopup(); } |
56 | | |
57 | | void AnnotationPopup::closePopup() |
58 | 0 | { |
59 | 0 | if (mpAnnotationWindow) |
60 | 0 | { |
61 | 0 | mpAnnotationWindow->SaveToDocument(); |
62 | 0 | mpAnnotationWindow.reset(); |
63 | 0 | } |
64 | 0 | } |
65 | | |
66 | | void AnnotationPopup::openPopup() |
67 | 0 | { |
68 | 0 | if (!mxAnnotation.is()) |
69 | 0 | return; |
70 | | |
71 | 0 | sd::DrawDocShell* pDocShell = dynamic_cast<sd::DrawDocShell*>(SfxObjectShell::Current()); |
72 | 0 | sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr; |
73 | |
|
74 | 0 | if (!pViewShell) |
75 | 0 | return; |
76 | | |
77 | 0 | if (!mpAnnotationWindow) |
78 | 0 | { |
79 | 0 | vcl::Window* pWindow = pViewShell->GetActiveWindow(); |
80 | 0 | if (pWindow) |
81 | 0 | { |
82 | 0 | auto aRealPosition2D = mxAnnotation->getPosition(); |
83 | 0 | Point aPosition(::tools::Long(aRealPosition2D.X * 100.0), |
84 | 0 | ::tools::Long(aRealPosition2D.Y * 100.0)); |
85 | 0 | Point aPositionPixel = pWindow->LogicToPixel(aPosition); |
86 | |
|
87 | 0 | aPositionPixel.AdjustX(4); |
88 | 0 | aPositionPixel.AdjustY(1); |
89 | |
|
90 | 0 | auto aRealSize2D = mxAnnotation->getSize(); |
91 | 0 | Size aSize(::tools::Long(aRealSize2D.Width * 100.0), |
92 | 0 | ::tools::Long(aRealSize2D.Height * 100.0)); |
93 | 0 | Size aSizePixel = pWindow->LogicToPixel(aSize); |
94 | |
|
95 | 0 | ::tools::Rectangle aRectangle(aPositionPixel, aSizePixel); |
96 | |
|
97 | 0 | weld::Window* pParent = weld::GetPopupParent(*pWindow, aRectangle); |
98 | 0 | mpAnnotationWindow.reset( |
99 | 0 | new AnnotationWindow(pParent, aRectangle, pDocShell, mxAnnotation)); |
100 | 0 | mpAnnotationWindow->connect_closed(LINK(this, AnnotationPopup, PopupModeEndHdl)); |
101 | 0 | } |
102 | 0 | } |
103 | |
|
104 | 0 | if (mpAnnotationWindow) |
105 | 0 | mpAnnotationWindow->StartEdit(); |
106 | 0 | } |
107 | | |
108 | | } // end of namespace sd |
109 | | |
110 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |