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_SLIDE_PREVIEW_HXX
25 #define SDEXT_PRESENTER_SLIDE_PREVIEW_HXX
26 
27 #include "PresenterController.hxx"
28 
29 #include <boost/noncopyable.hpp>
30 #include <com/sun/star/awt/XBitmap.hpp>
31 #include <com/sun/star/awt/XDisplayBitmap.hpp>
32 #include <com/sun/star/awt/XPaintListener.hpp>
33 #include <com/sun/star/awt/XWindowListener.hpp>
34 #include <com/sun/star/drawing/XDrawPage.hpp>
35 #include <com/sun/star/drawing/XDrawView.hpp>
36 #include <com/sun/star/drawing/XSlideRenderer.hpp>
37 #include <com/sun/star/drawing/framework/XPane.hpp>
38 #include <com/sun/star/drawing/framework/XView.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <cppuhelper/basemutex.hxx>
42 #include <cppuhelper/compbase4.hxx>
43 #include <rtl/ref.hxx>
44 
45 namespace css = ::com::sun::star;
46 
47 namespace sdext { namespace presenter {
48 
49 namespace {
50     typedef ::cppu::WeakComponentImplHelper4 <
51         css::drawing::framework::XView,
52         css::drawing::XDrawView,
53         css::awt::XPaintListener,
54         css::awt::XWindowListener
55     > PresenterSlidePreviewInterfaceBase;
56 }
57 
58 
59 /** Static preview of a slide.  Typically used for the preview of the next
60     slide.
61     This implementation shows a preview of the slide given to the
62     setCurrentSlide.  For showing the next slide the PresenterViewFactory
63     uses a derived class that overloads the setCurrentSlide() method.
64 */
65 class PresenterSlidePreview
66     : private ::boost::noncopyable,
67       private ::cppu::BaseMutex,
68       public PresenterSlidePreviewInterfaceBase
69 {
70 public:
71     PresenterSlidePreview (
72         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
73         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
74         const css::uno::Reference<css::drawing::framework::XPane>& rxAnchorPane,
75         const ::rtl::Reference<PresenterController>& rpPresenterController);
76     virtual ~PresenterSlidePreview (void);
77     virtual void SAL_CALL disposing (void);
78 
79 
80     // XResourceId
81 
82     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId (void)
83         throw (css::uno::RuntimeException);
84 
85     virtual sal_Bool SAL_CALL isAnchorOnly (void)
86         throw (com::sun::star::uno::RuntimeException);
87 
88     // XWindowListener
89 
90     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
91         throw (css::uno::RuntimeException);
92 
93     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
94         throw (css::uno::RuntimeException);
95 
96     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
97         throw (css::uno::RuntimeException);
98 
99     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
100         throw (css::uno::RuntimeException);
101 
102 
103     // XPaintListener
104 
105     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
106         throw (css::uno::RuntimeException);
107 
108 
109     // lang::XEventListener
110     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
111         throw (css::uno::RuntimeException);
112 
113 
114     // XDrawView
115 
116     virtual void SAL_CALL setCurrentPage (
117         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide)
118         throw (css::uno::RuntimeException);
119 
120     virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage (void)
121         throw (css::uno::RuntimeException);
122 
123 protected:
124     ::rtl::Reference<PresenterController> mpPresenterController;
125 
126 private:
127     css::uno::Reference<css::drawing::framework::XPane> mxPane;
128     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
129     css::uno::Reference<css::drawing::XSlideRenderer> mxPreviewRenderer;
130 
131     /** This Image holds the preview of the current slide.  After resize
132         requests the image may be empty.  This results eventually in a call
133         to ProvideSlide() in order to created a preview in the correct new
134         size.
135     */
136     css::uno::Reference<css::rendering::XBitmap> mxPreview;
137 
138     /**  The current slide for which a preview is displayed.  This may or
139         may not be the same as the current slide of the PresenterView.
140     */
141     css::uno::Reference<css::drawing::XDrawPage> mxCurrentSlide;
142     double mnSlideAspectRatio;
143 
144     css::uno::Reference<css::awt::XWindow> mxWindow;
145     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
146 
147     /** Set the given slide as the current slide of the called PresenterSlidePreview
148         object.
149     */
150     void SetSlide (const css::uno::Reference<css::drawing::XDrawPage>& rxPage);
151 
152     /** Paint the preview of the current slide centered in the window of the
153         anchor pane.
154     */
155     void Paint (const css::awt::Rectangle& rBoundingBox);
156 
157     /** React to a resize of the anchor pane.
158     */
159     void Resize (void);
160 
161     /** This method throws a DisposedException when the object has already been
162         disposed.
163     */
164     void ThrowIfDisposed (void) throw (css::lang::DisposedException);
165 };
166 
167 } } // end of namespace ::sd::presenter
168 
169 #endif
170