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  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_SHAPEMANAGERIMPL_HXX
20 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_SHAPEMANAGERIMPL_HXX
21 
22 #include <com/sun/star/drawing/XDrawPage.hpp>
23 #include <com/sun/star/uno/Reference.hxx>
24 
25 #include <shape.hxx>
26 #include <subsettableshapemanager.hxx>
27 #include <eventmultiplexer.hxx>
28 #include "layermanager.hxx"
29 #include <viewupdate.hxx>
30 #include <shapemaps.hxx>
31 #include <cursormanager.hxx>
32 #include <hyperlinkarea.hxx>
33 #include <listenercontainer.hxx>
34 #include <shapelistenereventhandler.hxx>
35 #include <mouseeventhandler.hxx>
36 
37 #include <set>
38 #include <map>
39 #include <memory>
40 
41 namespace slideshow::internal {
42 
43 /** Listener class for shape events
44 
45     This helper class registers itself on each view, and
46     broadcasts the XShapeEventListener events. The mouse motion
47     events are needed for setting the shape cursor.
48 */
49 class ShapeManagerImpl : public SubsettableShapeManager,
50                          public ShapeListenerEventHandler,
51                          public MouseEventHandler,
52                          public ViewUpdate,
53                          public std::enable_shared_from_this<ShapeManagerImpl>
54 {
55 public:
56     /** Create a shape event broadcaster
57 
58         @param rEventMultiplexer
59         The slideshow-global event source, where this class
60         registers its event handlers.
61     */
62     ShapeManagerImpl( EventMultiplexer&            rMultiplexer,
63                       LayerManagerSharedPtr const& rLayerManager,
64                       CursorManager&               rCursorManager,
65                       const ShapeEventListenerMap& rGlobalListenersMap,
66                       const ShapeCursorMap&        rGlobalCursorMap,
67                       const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage);
68 
69     /// Forbid copy construction
70     ShapeManagerImpl(const ShapeManagerImpl&) = delete;
71 
72     /// Forbid copy assignment
73     ShapeManagerImpl& operator=(const ShapeManagerImpl&) = delete;
74 
75     /** Enables event listening.
76 
77         The initial slide content on the background layer
78         is already rendered (e.g. from a previous slide
79         transition).
80      */
81     void activate();
82 
83     /** Disables event listening.
84      */
85     void deactivate();
86 
87     // Disposable interface
88 
89 
90     virtual void dispose() override;
91 
92 private:
93 
94     // MouseEventHandler interface
95 
96 
97     virtual bool handleMousePressed(
98         css::awt::MouseEvent const& evt ) override;
99     virtual bool handleMouseReleased(
100         css::awt::MouseEvent const& evt ) override;
101     virtual bool handleMouseDragged(
102         css::awt::MouseEvent const& evt ) override;
103     virtual bool handleMouseMoved(
104         css::awt::MouseEvent const& evt ) override;
105 
106 
107     // ViewUpdate interface
108 
109 
110     virtual bool update() override;
111     virtual bool needsUpdate() const override;
112 
113 
114     // ShapeManager interface
115 
116 
117     virtual void enterAnimationMode( const AnimatableShapeSharedPtr& rShape ) override;
118     virtual void leaveAnimationMode( const AnimatableShapeSharedPtr& rShape ) override;
119     virtual void notifyShapeUpdate( const ShapeSharedPtr& rShape ) override;
120     virtual ShapeSharedPtr lookupShape(
121         css::uno::Reference< css::drawing::XShape > const & xShape ) const override;
122     virtual const XShapeToShapeMap& getXShapeToShapeMap() const override;
123     virtual void addHyperlinkArea( const HyperlinkAreaSharedPtr& rArea ) override;
124 
125 
126     // SubsettableShapeManager interface
127 
128 
129     virtual AttributableShapeSharedPtr getSubsetShape(
130         const AttributableShapeSharedPtr& rOrigShape,
131         const DocTreeNode&                rTreeNode ) override;
132     virtual void revokeSubset(
133         const AttributableShapeSharedPtr& rOrigShape,
134         const AttributableShapeSharedPtr& rSubsetShape ) override;
135 
136     virtual void addIntrinsicAnimationHandler(
137         const IntrinsicAnimationEventHandlerSharedPtr& rHandler ) override;
138     virtual void removeIntrinsicAnimationHandler(
139         const IntrinsicAnimationEventHandlerSharedPtr& rHandler ) override;
140     virtual void notifyIntrinsicAnimationsEnabled() override;
141     virtual void notifyIntrinsicAnimationsDisabled() override;
142 
143 
144     // ShapeListenerEventHandler
145 
146 
147     virtual bool listenerAdded( const css::uno::Reference< css::drawing::XShape>& xShape ) override;
148 
149     virtual bool listenerRemoved( const css::uno::Reference< css::drawing::XShape>& xShape ) override;
150 
151     void cursorChanged( const css::uno::Reference< css::drawing::XShape>&   xShape,
152                               sal_Int16                                     nCursor );
153 
154 
155     OUString checkForHyperlink( ::basegfx::B2DPoint const& hitPos )const;
156     OUString checkForImageMap( css::awt::MouseEvent const& evt ) const;
157 
158 
159     typedef std::map<ShapeSharedPtr,
160                      std::shared_ptr< ::comphelper::OInterfaceContainerHelper2 >,
161                      Shape::lessThanShape>        ShapeToListenersMap;
162     typedef std::map<ShapeSharedPtr, sal_Int16,
163                        Shape::lessThanShape>      ShapeToCursorMap;
164     typedef std::set<HyperlinkAreaSharedPtr,
165                      HyperlinkArea::lessThanArea> AreaSet;
166 
167     typedef ThreadUnsafeListenerContainer<
168         IntrinsicAnimationEventHandlerSharedPtr,
169         std::vector<IntrinsicAnimationEventHandlerSharedPtr> > ImplIntrinsicAnimationEventHandlers;
170 
171     EventMultiplexer&                   mrMultiplexer;
172     LayerManagerSharedPtr               mpLayerManager;
173     CursorManager&                      mrCursorManager;
174     const ShapeEventListenerMap&        mrGlobalListenersMap;
175     const ShapeCursorMap&               mrGlobalCursorMap;
176     ShapeToListenersMap                 maShapeListenerMap;
177     ShapeToCursorMap                    maShapeCursorMap;
178     AreaSet                             maHyperlinkShapes;
179     ImplIntrinsicAnimationEventHandlers maIntrinsicAnimationEventHandlers;
180     bool                                mbEnabled;
181     const css::uno::Reference<css::drawing::XDrawPage> mxDrawPage;
182 };
183 
184 } // namespace presentation::internal
185 
186 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_SHAPEMANAGERIMPL_HXX
187 
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
189