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