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