1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SDEXT_PRESENTER_CONTROLLER_HXX
29 #define SDEXT_PRESENTER_CONTROLLER_HXX
30 
31 #include "PresenterAccessibility.hxx"
32 #include "PresenterPaneContainer.hxx"
33 #include "PresenterTheme.hxx"
34 #include "PresenterSprite.hxx"
35 #include <cppuhelper/compbase6.hxx>
36 #include <cppuhelper/basemutex.hxx>
37 #include <com/sun/star/awt/FontDescriptor.hpp>
38 #include <com/sun/star/awt/XFocusListener.hpp>
39 #include <com/sun/star/awt/XKeyListener.hpp>
40 #include <com/sun/star/awt/XMouseListener.hpp>
41 #include <com/sun/star/drawing/XPresenterHelper.hpp>
42 #include <com/sun/star/frame/XController.hpp>
43 #include <com/sun/star/frame/XDispatch.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/presentation/XSlideShowController.hpp>
46 #include <com/sun/star/presentation/XSlideShowListener.hpp>
47 #include <com/sun/star/frame/XFrameActionListener.hpp>
48 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
49 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
50 #include <com/sun/star/drawing/framework/XPane.hpp>
51 #include <com/sun/star/uno/XComponentContext.hpp>
52 #include <com/sun/star/util/Color.hpp>
53 #include <com/sun/star/util/XURLTransformer.hpp>
54 #include <rtl/ref.hxx>
55 #include <map>
56 #include <vector>
57 #include <boost/function.hpp>
58 #include <boost/shared_ptr.hpp>
59 #include <boost/scoped_ptr.hpp>
60 
61 namespace css = ::com::sun::star;
62 
63 namespace sdext { namespace presenter {
64 
65 class PresenterAnimator;
66 class PresenterCanvasHelper;
67 class PresenterPaintManager;
68 class PresenterPaneAnimator;
69 class PresenterPaneContainer;
70 class PresenterPaneBorderPainter;
71 class PresenterTheme;
72 class PresenterWindowManager;
73 
74 namespace {
75     typedef ::cppu::WeakComponentImplHelper6 <
76         css::drawing::framework::XConfigurationChangeListener,
77         css::frame::XFrameActionListener,
78         css::awt::XKeyListener,
79         css::awt::XFocusListener,
80         css::awt::XMouseListener,
81         css::awt::XMouseMotionListener
82     > PresenterControllerInterfaceBase;
83 }
84 
85 
86 /** The controller of the presenter screen is responsible for telling the
87     individual views which slides to show.  Additionally it provides access
88     to frequently used values of the current theme.
89 */
90 class PresenterController
91     : protected ::cppu::BaseMutex,
92       public PresenterControllerInterfaceBase
93 {
94 public:
95     static ::rtl::Reference<PresenterController> Instance (
96         const css::uno::Reference<css::frame::XFrame>& rxFrame);
97 
98     PresenterController (
99         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
100         const css::uno::Reference<css::frame::XController>& rxController,
101         const css::uno::Reference<css::presentation::XSlideShowController>& rxSlideShowController,
102         const rtl::Reference<PresenterPaneContainer>& rpPaneContainer,
103         const css::uno::Reference<css::drawing::framework::XResourceId>& rxMainPaneId);
104     ~PresenterController (void);
105 
106     virtual void SAL_CALL disposing (void);
107 
108     void UpdateCurrentSlide (const sal_Int32 nOffset);
109 
110     SharedBitmapDescriptor
111         GetViewBackground (const ::rtl::OUString& rsViewURL) const;
112     PresenterTheme::SharedFontDescriptor
113         GetViewFont (const ::rtl::OUString& rsViewURL) const;
114     ::boost::shared_ptr<PresenterTheme> GetTheme (void) const;
115     ::rtl::Reference<PresenterWindowManager> GetWindowManager (void) const;
116     css::uno::Reference<css::presentation::XSlideShowController>
117         GetSlideShowController (void) const;
118     rtl::Reference<PresenterPaneContainer> GetPaneContainer (void) const;
119     ::rtl::Reference<PresenterPaneBorderPainter> GetPaneBorderPainter (void) const;
120     ::boost::shared_ptr<PresenterAnimator> GetAnimator (void) const;
121     ::boost::shared_ptr<PresenterCanvasHelper> GetCanvasHelper (void) const;
122     css::uno::Reference<css::drawing::XPresenterHelper> GetPresenterHelper (void) const;
123     ::boost::shared_ptr<PresenterPaintManager> GetPaintManager (void) const;
124     void HideSlideSorter (void);
125     double GetSlideAspectRatio (void) const;
126     void ShowView (const ::rtl::OUString& rsViewURL);
127     void HideView (const ::rtl::OUString& rsViewURL);
128     bool IsViewVisible (const ::rtl::OUString& rsViewURL) const;
129     void DispatchUnoCommand (const ::rtl::OUString& rsCommand) const;
130     css::uno::Reference<css::frame::XDispatch> GetDispatch (
131         const css::util::URL& rURL) const;
132     css::util::URL CreateURLFromString (const ::rtl::OUString& rsURL) const;
133     css::uno::Reference<css::drawing::framework::XConfigurationController>
134         GetConfigurationController (void) const;
135     css::uno::Reference<css::drawing::XDrawPage> GetCurrentSlide (void) const;
136     ::rtl::Reference<PresenterAccessible> GetAccessible (void) const;
137     void SetAccessibilityActiveState (const bool bIsActive);
138     bool IsAccessibilityActive (void) const;
139 
140     void HandleMouseClick (const css::awt::MouseEvent& rEvent);
141     void UpdatePaneTitles (void);
142 
143     /** Request activation or deactivation of (some of) the views according
144         to the given parameters.
145     */
146     void RequestViews (
147         const bool bIsSlideSorterActive,
148         const bool bIsNotesViewActive,
149         const bool bIsHelpViewActive);
150 
151     // XConfigurationChangeListener
152 
153     virtual void SAL_CALL notifyConfigurationChange (
154         const com::sun::star::drawing::framework::ConfigurationChangeEvent& rEvent)
155         throw (com::sun::star::uno::RuntimeException);
156 
157 
158     // XEventListener
159 
160     virtual void SAL_CALL disposing (
161         const com::sun::star::lang::EventObject& rEvent)
162         throw (com::sun::star::uno::RuntimeException);
163 
164 
165     // XFrameActionListener
166 
167     virtual void SAL_CALL frameAction (
168         const css::frame::FrameActionEvent& rEvent)
169         throw (com::sun::star::uno::RuntimeException);
170 
171 
172     // XKeyListener
173 
174     virtual void SAL_CALL keyPressed (const css::awt::KeyEvent& rEvent)
175         throw (css::uno::RuntimeException);
176     virtual void SAL_CALL keyReleased (const css::awt::KeyEvent& rEvent)
177         throw (css::uno::RuntimeException);
178 
179 
180     // XFocusListener
181 
182     virtual void SAL_CALL focusGained (const css::awt::FocusEvent& rEvent)
183         throw (css::uno::RuntimeException);
184     virtual void SAL_CALL focusLost (const css::awt::FocusEvent& rEvent)
185         throw (css::uno::RuntimeException);
186 
187 
188     // XMouseListener
189 
190     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
191         throw (css::uno::RuntimeException);
192 
193     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
194         throw (css::uno::RuntimeException);
195 
196     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
197         throw (css::uno::RuntimeException);
198 
199     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
200         throw (css::uno::RuntimeException);
201 
202 
203     // XMouseMotionListener
204 
205     virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent)
206         throw (css::uno::RuntimeException);
207 
208     virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent)
209         throw (css::uno::RuntimeException);
210 
211 private:
212     typedef ::std::map<css::uno::Reference<css::frame::XFrame>,rtl::Reference<PresenterController> > InstanceContainer;
213     static InstanceContainer maInstances;
214 
215     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
216     css::uno::Reference<css::rendering::XSpriteCanvas> mxCanvas;
217     css::uno::Reference<css::frame::XController> mxController;
218     css::uno::Reference<css::drawing::framework::XConfigurationController>
219         mxConfigurationController;
220     css::uno::Reference<css::presentation::XSlideShowController> mxSlideShowController;
221     css::uno::Reference<css::drawing::framework::XResourceId> mxMainPaneId;
222     rtl::Reference<PresenterPaneContainer> mpPaneContainer;
223     sal_Int32 mnCurrentSlideIndex;
224     css::uno::Reference<css::drawing::XDrawPage> mxCurrentSlide;
225     css::uno::Reference<css::drawing::XDrawPage> mxNextSlide;
226     ::rtl::Reference<PresenterWindowManager> mpWindowManager;
227     ::boost::shared_ptr<PresenterPaneAnimator> mpCurrentPaneAnimation;
228     sal_Int32 mnWindowBackgroundColor;
229     ::boost::shared_ptr<PresenterTheme> mpTheme;
230     css::uno::Reference<css::awt::XWindow> mxMainWindow;
231     ::rtl::Reference<PresenterPaneBorderPainter> mpPaneBorderPainter;
232     ::boost::shared_ptr<PresenterAnimator> mpAnimator;
233     ::boost::shared_ptr<PresenterCanvasHelper> mpCanvasHelper;
234     css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
235     ::boost::shared_ptr<PresenterPaintManager> mpPaintManager;
236     sal_Int32 mnPendingSlideNumber;
237     css::uno::Reference<css::util::XURLTransformer> mxUrlTransformer;
238     ::rtl::Reference<PresenterAccessible> mpAccessibleObject;
239     bool mbIsAccessibilityActive;
240 
241     void InitializePresenterScreen (void);
242     void InitializeSlideShowView (const css::uno::Reference<css::uno::XInterface>& rxView);
243     void GetSlides (const sal_Int32 nOffset);
244     void UpdateViews (void);
245     void InitializeMainPane (const css::uno::Reference<css::drawing::framework::XPane>& rxPane);
246     void LoadTheme (const css::uno::Reference<css::drawing::framework::XPane>& rxPane);
247     void UpdatePendingSlideNumber (const sal_Int32 nPendingSlideNumber);
248 
249     /** This method is called when the user pressed one of the numerical
250         keys.  Depending on the modifier, numeric keys switch to another
251         slide (no modifier), or change to another view (Ctrl modifier).
252         @param nKey
253             Numeric value that is printed on the pressed key.  For example
254             pressing the key '4' will result in the value 4, not the ASCII
255             code (0x34?).
256         @param nModifiers
257             The modifier bit field as provided by the key up event.
258     */
259     void HandleNumericKeyPress (const sal_Int32 nKey, const sal_Int32 nModifiers);
260 
261     void ThrowIfDisposed (void) const throw (::com::sun::star::lang::DisposedException);
262 };
263 
264 
265 } } // end of namespace ::sdext::presenter
266 
267 #endif
268