1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SDEXT_PRESENTER_PRESENTER_SLIDE_SORTER_HXX
25 #define SDEXT_PRESENTER_PRESENTER_SLIDE_SORTER_HXX
26 
27 #include "PresenterController.hxx"
28 #include "PresenterPaneContainer.hxx"
29 #include "PresenterViewFactory.hxx"
30 #include <cppuhelper/basemutex.hxx>
31 #include <cppuhelper/compbase8.hxx>
32 #include <com/sun/star/awt/XPaintListener.hpp>
33 #include <com/sun/star/awt/XWindowListener.hpp>
34 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
35 #include <com/sun/star/drawing/XDrawView.hpp>
36 #include <com/sun/star/drawing/XSlidePreviewCache.hpp>
37 #include <com/sun/star/drawing/framework/XView.hpp>
38 #include <com/sun/star/drawing/framework/XResourceId.hpp>
39 #include <com/sun/star/frame/XController.hpp>
40 #include <com/sun/star/geometry/RealRectangle2D.hpp>
41 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
42 #include <com/sun/star/rendering/XSprite.hpp>
43 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
44 
45 namespace css = ::com::sun::star;
46 
47 namespace {
48     typedef cppu::WeakComponentImplHelper8<
49         css::drawing::framework::XView,
50         css::awt::XWindowListener,
51         css::awt::XPaintListener,
52         css::beans::XPropertyChangeListener,
53         css::drawing::XSlidePreviewCacheListener,
54         css::awt::XMouseListener,
55         css::awt::XMouseMotionListener,
56         css::drawing::XDrawView
57         > PresenterSlideSorterInterfaceBase;
58 }
59 
60 namespace sdext { namespace presenter {
61 
62 class PresenterButton;
63 class PresenterScrollBar;
64 
65 /** A simple slide sorter for the presenter screen.  It uses a preview cache
66     to create the slide previews.  Painting is done via a canvas.
67 */
68 class PresenterSlideSorter
69     : private ::cppu::BaseMutex,
70       public PresenterSlideSorterInterfaceBase,
71       public CachablePresenterView
72 {
73 public:
74     PresenterSlideSorter (
75         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
76         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
77         const css::uno::Reference<css::frame::XController>& rxController,
78         const ::rtl::Reference<PresenterController>& rpPresenterController);
79     virtual ~PresenterSlideSorter (void);
80 
81     virtual void SAL_CALL disposing (void);
82 
83     void SetActiveState (const bool bIsActive);
84 
85 
86     // lang::XEventListener
87 
88     virtual void SAL_CALL
89         disposing (const css::lang::EventObject& rEventObject)
90         throw (css::uno::RuntimeException);
91 
92 
93     // XWindowListener
94 
95     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
96         throw (css::uno::RuntimeException);
97 
98     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
99         throw (css::uno::RuntimeException);
100 
101     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
102         throw (css::uno::RuntimeException);
103 
104     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
105         throw (css::uno::RuntimeException);
106 
107 
108     // XPaintListener
109 
110     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
111         throw (css::uno::RuntimeException);
112 
113 
114     // XMouseListener
115 
116     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
117         throw(css::uno::RuntimeException);
118 
119     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
120         throw(css::uno::RuntimeException);
121 
122     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
123         throw(css::uno::RuntimeException);
124 
125     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
126         throw(css::uno::RuntimeException);
127 
128 
129     // XMouseMotionListener
130 
131     virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent)
132         throw (css::uno::RuntimeException);
133 
134     virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent)
135         throw (css::uno::RuntimeException);
136 
137 
138     // XResourceId
139 
140     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId (void)
141         throw (css::uno::RuntimeException);
142 
143     virtual sal_Bool SAL_CALL isAnchorOnly (void)
144         throw (com::sun::star::uno::RuntimeException);
145 
146 
147     // XPropertyChangeListener
148 
149     virtual void SAL_CALL propertyChange (
150         const css::beans::PropertyChangeEvent& rEvent)
151         throw(css::uno::RuntimeException);
152 
153 
154     // XSlidePreviewCacheListener
155 
156     virtual void SAL_CALL notifyPreviewCreation (
157         sal_Int32 nSlideIndex)
158         throw(css::uno::RuntimeException);
159 
160 
161     // XDrawView
162 
163     virtual void SAL_CALL setCurrentPage (
164         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide)
165         throw (css::uno::RuntimeException);
166 
167     virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage (void)
168         throw (css::uno::RuntimeException);
169 
170 private:
171     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
172     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
173     css::uno::Reference<css::drawing::framework::XPane> mxPane;
174     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
175     css::uno::Reference<css::awt::XWindow> mxWindow;
176     ::rtl::Reference<PresenterController> mpPresenterController;
177     css::uno::Reference<css::presentation::XSlideShowController> mxSlideShowController;
178     css::uno::Reference<css::drawing::XSlidePreviewCache> mxPreviewCache;
179     bool mbIsPaintPending;
180     bool mbIsLayoutPending;
181     class Layout;
182     ::boost::shared_ptr<Layout> mpLayout;
183     ::rtl::Reference<PresenterScrollBar> mpHorizontalScrollBar;
184     ::rtl::Reference<PresenterScrollBar> mpVerticalScrollBar;
185     ::rtl::Reference<PresenterButton> mpCloseButton;
186     class MouseOverManager;
187     ::boost::scoped_ptr<MouseOverManager> mpMouseOverManager;
188     sal_Int32 mnSlideIndexMousePressed;
189     sal_Int32 mnCurrentSlideIndex;
190     sal_Int32 mnSeparatorY;
191     css::util::Color maSeparatorColor;
192     css::awt::Point maCloseButtonCenter;
193     css::awt::Rectangle maCurrentSlideFrameBoundingBox;
194     class CurrentSlideFrameRenderer;
195     ::boost::shared_ptr<CurrentSlideFrameRenderer> mpCurrentSlideFrameRenderer;
196     css::uno::Reference<css::rendering::XPolyPolygon2D> mxPreviewFrame;
197 
198     void UpdateLayout (void);
199     css::geometry::RealRectangle2D PlaceScrollBars (
200         const css::geometry::RealRectangle2D& rUpperBox);
201     void PlaceCloseButton (
202         const PresenterPaneContainer::SharedPaneDescriptor& rpPane,
203         const css::awt::Rectangle& rCenterBox,
204     const sal_Int32 nLeftFrameWidth);
205     void ClearBackground (
206         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
207         const css::awt::Rectangle& rRedrawArea);
208     double GetSlideAspectRatio (void) const;
209     css::uno::Reference<css::rendering::XBitmap> GetPreview (const sal_Int32 nSlideIndex);
210     void PaintPreview (
211         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
212         const css::awt::Rectangle& rUpdateBox,
213         const sal_Int32 nSlideIndex);
214     void Paint (const css::awt::Rectangle& rUpdateBox);
215     void SetHorizontalOffset (const double nXOffset);
216     void SetVerticalOffset (const double nYOffset);
217     void GotoSlide (const sal_Int32 nSlideIndex);
218     bool ProvideCanvas (void);
219 
220     /** This method throws a DisposedException when the object has already been
221         disposed.
222     */
223     void ThrowIfDisposed (void)
224         throw (css::lang::DisposedException);
225 };
226 
227 } } // end of namespace ::sdext::presenter
228 
229 #endif
230