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 
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERSLIDESORTER_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERSLIDESORTER_HXX
22 
23 #include <memory>
24 #include "PresenterController.hxx"
25 #include "PresenterPaneContainer.hxx"
26 #include "PresenterViewFactory.hxx"
27 #include <cppuhelper/basemutex.hxx>
28 #include <cppuhelper/compbase.hxx>
29 #include <com/sun/star/awt/XPaintListener.hpp>
30 #include <com/sun/star/awt/XWindowListener.hpp>
31 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
32 #include <com/sun/star/drawing/XDrawView.hpp>
33 #include <com/sun/star/drawing/XSlidePreviewCache.hpp>
34 #include <com/sun/star/drawing/framework/XView.hpp>
35 #include <com/sun/star/drawing/framework/XResourceId.hpp>
36 #include <com/sun/star/frame/XController.hpp>
37 #include <com/sun/star/geometry/RealRectangle2D.hpp>
38 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
39 
40 namespace sdext::presenter {
41 
42 class PresenterButton;
43 class PresenterScrollBar;
44 
45 typedef cppu::WeakComponentImplHelper<
46     css::drawing::framework::XView,
47     css::awt::XWindowListener,
48     css::awt::XPaintListener,
49     css::beans::XPropertyChangeListener,
50     css::drawing::XSlidePreviewCacheListener,
51     css::awt::XMouseListener,
52     css::awt::XMouseMotionListener,
53     css::drawing::XDrawView
54     > PresenterSlideSorterInterfaceBase;
55 
56 /** A simple slide sorter for the presenter screen.  It uses a preview cache
57     to create the slide previews.  Painting is done via a canvas.
58 */
59 class PresenterSlideSorter
60     : private ::cppu::BaseMutex,
61       public PresenterSlideSorterInterfaceBase,
62       public CachablePresenterView
63 {
64 public:
65     PresenterSlideSorter (
66         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
67         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
68         const css::uno::Reference<css::frame::XController>& rxController,
69         const ::rtl::Reference<PresenterController>& rpPresenterController);
70     virtual ~PresenterSlideSorter() override;
71 
72     virtual void SAL_CALL disposing() override;
73 
74     // lang::XEventListener
75 
76     virtual void SAL_CALL
77         disposing (const css::lang::EventObject& rEventObject) override;
78 
79     // XWindowListener
80 
81     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent) override;
82 
83     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent) override;
84 
85     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent) override;
86 
87     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent) override;
88 
89     // XPaintListener
90 
91     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent) override;
92 
93     // XMouseListener
94 
95     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent) override;
96 
97     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent) override;
98 
99     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent) override;
100 
101     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent) override;
102 
103     // XMouseMotionListener
104 
105     virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent) override;
106 
107     virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent) override;
108 
109     // XResourceId
110 
111     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId() override;
112 
113     virtual sal_Bool SAL_CALL isAnchorOnly() override;
114 
115     // XPropertyChangeListener
116 
117     virtual void SAL_CALL propertyChange (
118         const css::beans::PropertyChangeEvent& rEvent) override;
119 
120     // XSlidePreviewCacheListener
121 
122     virtual void SAL_CALL notifyPreviewCreation (
123         sal_Int32 nSlideIndex) override;
124 
125     // XDrawView
126 
127     virtual void SAL_CALL setCurrentPage (
128         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide) override;
129 
130     virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage() override;
131 
132 private:
133     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
134     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
135     css::uno::Reference<css::drawing::framework::XPane> mxPane;
136     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
137     css::uno::Reference<css::awt::XWindow> mxWindow;
138     ::rtl::Reference<PresenterController> mpPresenterController;
139     css::uno::Reference<css::presentation::XSlideShowController> mxSlideShowController;
140     css::uno::Reference<css::drawing::XSlidePreviewCache> mxPreviewCache;
141     bool mbIsLayoutPending;
142     class Layout;
143     std::shared_ptr<Layout> mpLayout;
144     ::rtl::Reference<PresenterScrollBar> mpVerticalScrollBar;
145     ::rtl::Reference<PresenterButton> mpCloseButton;
146     class MouseOverManager;
147     std::unique_ptr<MouseOverManager> mpMouseOverManager;
148     sal_Int32 mnSlideIndexMousePressed;
149     sal_Int32 mnCurrentSlideIndex;
150     sal_Int32 mnSeparatorY;
151     css::util::Color maSeparatorColor;
152     css::awt::Rectangle maCurrentSlideFrameBoundingBox;
153     class CurrentSlideFrameRenderer;
154     std::shared_ptr<CurrentSlideFrameRenderer> mpCurrentSlideFrameRenderer;
155     css::uno::Reference<css::rendering::XPolyPolygon2D> mxPreviewFrame;
156 
157     void UpdateLayout();
158     css::geometry::RealRectangle2D PlaceScrollBars (
159         const css::geometry::RealRectangle2D& rUpperBox);
160     void PlaceCloseButton (
161         const PresenterPaneContainer::SharedPaneDescriptor& rpPane,
162         const css::awt::Rectangle& rCenterBox,
163     const sal_Int32 nLeftFrameWidth);
164     void ClearBackground (
165         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
166         const css::awt::Rectangle& rRedrawArea);
167     double GetSlideAspectRatio() const;
168     css::uno::Reference<css::rendering::XBitmap> GetPreview (const sal_Int32 nSlideIndex);
169     void PaintPreview (
170         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
171         const css::awt::Rectangle& rUpdateBox,
172         const sal_Int32 nSlideIndex);
173     void Paint (const css::awt::Rectangle& rUpdateBox);
174     void SetHorizontalOffset (const double nXOffset);
175     void SetVerticalOffset (const double nYOffset);
176     void GotoSlide (const sal_Int32 nSlideIndex);
177     bool ProvideCanvas();
178 
179     /** @throws css::lang::DisposedException when the object has already been
180         disposed.
181     */
182     void ThrowIfDisposed();
183 };
184 
185 } // end of namespace ::sdext::presenter
186 
187 #endif
188 
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
190