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_PRESENTERTOOLBAR_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTOOLBAR_HXX
22 
23 #include "PresenterController.hxx"
24 #include "PresenterViewFactory.hxx"
25 
26 #include <cppuhelper/basemutex.hxx>
27 #include <cppuhelper/compbase.hxx>
28 #include <com/sun/star/awt/XMouseListener.hpp>
29 #include <com/sun/star/awt/XMouseMotionListener.hpp>
30 #include <com/sun/star/awt/XPaintListener.hpp>
31 #include <com/sun/star/awt/XWindowListener.hpp>
32 #include <com/sun/star/drawing/XDrawPage.hpp>
33 #include <com/sun/star/drawing/XDrawView.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 
38 #include <functional>
39 
40 namespace sdext::presenter {
41 
42 typedef cppu::WeakComponentImplHelper<
43     css::awt::XWindowListener,
44     css::awt::XPaintListener,
45     css::awt::XMouseListener,
46     css::awt::XMouseMotionListener,
47     css::drawing::XDrawView
48     > PresenterToolBarInterfaceBase;
49 
50 typedef cppu::WeakComponentImplHelper<
51     css::awt::XPaintListener,
52     css::drawing::framework::XView,
53     css::drawing::XDrawView
54     > PresenterToolBarViewInterfaceBase;
55 
56 /** A simple tool bar that can display bitmapped buttons and labels.  At the
57     moment there are buttons for moving to the next and previous slide and
58     to the next effect.  A label displays the index of the current slide
59     and the total number of slides.
60 */
61 class PresenterToolBar
62     : private ::cppu::BaseMutex,
63       public PresenterToolBarInterfaceBase,
64       public CachablePresenterView
65 {
66 public:
67     typedef ::std::function<void ()> Action;
68 
69     enum Anchor { Left, Center };
70 
71     PresenterToolBar (
72         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
73         const css::uno::Reference<css::awt::XWindow>& rxWindow,
74         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
75         const ::rtl::Reference<PresenterController>& rpPresenterController,
76         const Anchor eAnchor);
77     virtual ~PresenterToolBar() override;
78     PresenterToolBar(const PresenterToolBar&) = delete;
79     PresenterToolBar& operator=(const PresenterToolBar&) = delete;
80 
81     void Initialize (
82         const OUString& rsConfigurationPath);
83 
84     virtual void SAL_CALL disposing() override;
85 
86     void InvalidateArea (
87         const css::awt::Rectangle& rRepaintBox,
88         const bool bSynchronous);
89 
90     void RequestLayout();
91     css::geometry::RealSize2D const & GetMinimalSize();
92     const ::rtl::Reference<PresenterController>& GetPresenterController() const;
93     const css::uno::Reference<css::uno::XComponentContext>& GetComponentContext() const;
94 
95     // lang::XEventListener
96 
97     virtual void SAL_CALL
98         disposing (const css::lang::EventObject& rEventObject) override;
99 
100     // XWindowListener
101 
102     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent) override;
103 
104     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent) override;
105 
106     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent) override;
107 
108     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent) override;
109 
110     // XPaintListener
111 
112     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent) override;
113 
114     // XMouseListener
115 
116     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent) override;
117 
118     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent) override;
119 
120     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent) override;
121 
122     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent) override;
123 
124     // XMouseMotionListener
125 
126     virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent) override;
127 
128     virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent) override;
129 
130     // XDrawView
131 
132     virtual void SAL_CALL setCurrentPage (
133         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide) override;
134 
135     virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage() override;
136 
137     class Context;
138 
139 private:
140     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
141 
142     class ElementContainerPart;
143     typedef std::shared_ptr<ElementContainerPart> SharedElementContainerPart;
144     typedef ::std::vector<SharedElementContainerPart> ElementContainer;
145     ElementContainer maElementContainer;
146     SharedElementContainerPart mpCurrentContainerPart;
147     css::uno::Reference<css::awt::XWindow> mxWindow;
148     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
149     css::uno::Reference<css::presentation::XSlideShowController> mxSlideShowController;
150     css::uno::Reference<css::drawing::XDrawPage> mxCurrentSlide;
151     ::rtl::Reference<PresenterController> mpPresenterController;
152     bool mbIsLayoutPending;
153     const Anchor meAnchor;
154     /** The minimal size that is necessary to display all elements without
155         overlap and with minimal gaps between them.
156     */
157     css::geometry::RealSize2D maMinimalSize;
158 
159     void CreateControls (
160         const OUString& rsConfigurationPath);
161     void Layout (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
162     css::geometry::RealSize2D CalculatePartSize (
163         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
164         const SharedElementContainerPart& rpPart,
165         const bool bIsHorizontal);
166     static void LayoutPart (
167         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
168         const SharedElementContainerPart& rpPart,
169         const css::geometry::RealRectangle2D& rBoundingBox,
170         const css::geometry::RealSize2D& rPartSize,
171         const bool bIsHorizontal);
172     void Paint (
173         const css::awt::Rectangle& rUpdateBox,
174         const css::rendering::ViewState& rViewState);
175 
176     void UpdateSlideNumber();
177 
178     void CheckMouseOver (
179         const css::awt::MouseEvent& rEvent,
180         const bool bOverWindow,
181         const bool bMouseDown=false);
182 
183     void ProcessEntry (
184         const css::uno::Reference<css::beans::XPropertySet>& rProperties,
185         Context const & rContext);
186 
187     /** @throws css::lang::DisposedException when the object has already been
188         disposed.
189     */
190     void ThrowIfDisposed() const;
191 };
192 
193 /** View for the PresenterToolBar.
194 */
195 class PresenterToolBarView
196     : private ::cppu::BaseMutex,
197       public PresenterToolBarViewInterfaceBase
198 {
199 public:
200     explicit PresenterToolBarView (
201         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
202         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
203         const css::uno::Reference<css::frame::XController>& rxController,
204         const ::rtl::Reference<PresenterController>& rpPresenterController);
205     virtual ~PresenterToolBarView() override;
206     PresenterToolBarView(const PresenterToolBarView&) = delete;
207     PresenterToolBarView& operator=(const PresenterToolBarView&) = delete;
208 
209     virtual void SAL_CALL disposing() override;
210 
211     const ::rtl::Reference<PresenterToolBar>& GetPresenterToolBar() const;
212 
213     // XPaintListener
214 
215     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent) override;
216 
217     // lang::XEventListener
218 
219     virtual void SAL_CALL
220         disposing (const css::lang::EventObject& rEventObject) override;
221 
222     // XResourceId
223 
224     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId() override;
225 
226     virtual sal_Bool SAL_CALL isAnchorOnly() override;
227 
228     // XDrawView
229 
230     virtual void SAL_CALL setCurrentPage (
231         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide) override;
232 
233     virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage() override;
234 
235 private:
236     //    css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
237     css::uno::Reference<css::drawing::framework::XPane> mxPane;
238     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
239     css::uno::Reference<css::awt::XWindow> mxWindow;
240     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
241     ::rtl::Reference<PresenterController> mpPresenterController;
242     ::rtl::Reference<PresenterToolBar> mpToolBar;
243 
244 };
245 
246 } // end of namespace ::sdext::presenter
247 
248 #endif
249 
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
251