Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "PresenterSlidePreview.hxx"
21 : #include "PresenterCanvasHelper.hxx"
22 : #include "PresenterGeometryHelper.hxx"
23 : #include "PresenterPaintManager.hxx"
24 : #include "PresenterScrollBar.hxx"
25 : #include "PresenterBitmapContainer.hxx"
26 : #include <com/sun/star/awt/XWindow.hpp>
27 : #include <com/sun/star/awt/XWindowPeer.hpp>
28 : #include <com/sun/star/beans/XPropertySet.hpp>
29 : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
30 : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
31 : #include <com/sun/star/drawing/framework/XPane.hpp>
32 : #include <com/sun/star/rendering/CompositeOperation.hpp>
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::drawing::framework;
37 :
38 : namespace
39 : {
40 : // Use a super sample factor greater than 1 to achive a poor mans
41 : // antialiasing effect for slide previews.
42 : const sal_Int16 gnSuperSampleFactor = 2;
43 : }
44 :
45 : namespace sdext { namespace presenter {
46 :
47 : //===== PresenterSlidePreview =================================================
48 :
49 0 : PresenterSlidePreview::PresenterSlidePreview (
50 : const Reference<XComponentContext>& rxContext,
51 : const Reference<XResourceId>& rxViewId,
52 : const Reference<XPane>& rxAnchorPane,
53 : const ::rtl::Reference<PresenterController>& rpPresenterController)
54 : : PresenterSlidePreviewInterfaceBase(m_aMutex),
55 : mpPresenterController(rpPresenterController),
56 : mxPane(rxAnchorPane),
57 : mxViewId(rxViewId),
58 : mxPreviewRenderer(),
59 : mxPreview(),
60 : mxCurrentSlide(),
61 : mnSlideAspectRatio(28.0 / 21.0),
62 : mxWindow(),
63 0 : mxCanvas()
64 : {
65 0 : if ( ! rxContext.is()
66 0 : || ! rxViewId.is()
67 0 : || ! rxAnchorPane.is()
68 0 : || ! rpPresenterController.is())
69 : {
70 : throw RuntimeException(
71 : OUString(
72 : "PresenterSlidePreview can not be constructed due to empty argument"),
73 0 : static_cast<XWeak*>(this));
74 : }
75 :
76 0 : mxWindow = rxAnchorPane->getWindow();
77 0 : mxCanvas = rxAnchorPane->getCanvas();
78 :
79 0 : if (mxWindow.is())
80 : {
81 0 : mxWindow->addWindowListener(this);
82 0 : mxWindow->addPaintListener(this);
83 :
84 0 : Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY);
85 0 : if (xPeer.is())
86 0 : xPeer->setBackground(util::Color(0xff000000));
87 :
88 0 : mxWindow->setVisible(sal_True);
89 : }
90 :
91 0 : if (mpPresenterController.get() != NULL)
92 0 : mnSlideAspectRatio = mpPresenterController->GetSlideAspectRatio();
93 :
94 0 : Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager(), UNO_QUERY);
95 0 : if (xFactory.is())
96 0 : mxPreviewRenderer = Reference<drawing::XSlideRenderer>(
97 0 : xFactory->createInstanceWithContext(
98 : OUString("com.sun.star.drawing.SlideRenderer"),
99 0 : rxContext),
100 0 : UNO_QUERY);
101 : mpBitmaps.reset(new PresenterBitmapContainer(
102 : OUString("PresenterScreenSettings/ScrollBar/Bitmaps"),
103 : ::boost::shared_ptr<PresenterBitmapContainer>(),
104 : rxContext,
105 0 : mxCanvas));
106 0 : Resize();
107 0 : }
108 :
109 0 : PresenterSlidePreview::~PresenterSlidePreview (void)
110 : {
111 0 : }
112 :
113 0 : void SAL_CALL PresenterSlidePreview::disposing (void)
114 : {
115 0 : if (mxWindow.is())
116 : {
117 0 : mxWindow->removeWindowListener(this);
118 0 : mxWindow->removePaintListener(this);
119 0 : mxWindow = NULL;
120 0 : mxCanvas = NULL;
121 : }
122 :
123 0 : Reference<lang::XComponent> xComponent (mxPreviewRenderer, UNO_QUERY);
124 0 : if (xComponent.is())
125 0 : xComponent->dispose();
126 0 : }
127 :
128 : //----- XResourceId -----------------------------------------------------------
129 :
130 0 : Reference<XResourceId> SAL_CALL PresenterSlidePreview::getResourceId (void)
131 : throw (RuntimeException, std::exception)
132 : {
133 0 : return mxViewId;
134 : }
135 :
136 0 : sal_Bool SAL_CALL PresenterSlidePreview::isAnchorOnly (void)
137 : throw (RuntimeException, std::exception)
138 : {
139 0 : return false;
140 : }
141 :
142 : //----- XWindowListener -------------------------------------------------------
143 :
144 0 : void SAL_CALL PresenterSlidePreview::windowResized (const awt::WindowEvent& rEvent)
145 : throw (RuntimeException, std::exception)
146 : {
147 : (void)rEvent;
148 0 : ThrowIfDisposed();
149 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
150 0 : Resize();
151 0 : }
152 :
153 0 : void SAL_CALL PresenterSlidePreview::windowMoved (const awt::WindowEvent& rEvent)
154 : throw (RuntimeException, std::exception)
155 : {
156 : (void)rEvent;
157 0 : }
158 :
159 0 : void SAL_CALL PresenterSlidePreview::windowShown (const lang::EventObject& rEvent)
160 : throw (RuntimeException, std::exception)
161 : {
162 : (void)rEvent;
163 0 : ThrowIfDisposed();
164 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
165 0 : Resize();
166 0 : }
167 :
168 0 : void SAL_CALL PresenterSlidePreview::windowHidden (const lang::EventObject& rEvent)
169 : throw (RuntimeException, std::exception)
170 : {
171 : (void)rEvent;
172 0 : }
173 :
174 : //----- XPaintListener --------------------------------------------------------
175 :
176 0 : void SAL_CALL PresenterSlidePreview::windowPaint (const awt::PaintEvent& rEvent)
177 : throw (RuntimeException, std::exception)
178 : {
179 0 : ThrowIfDisposed();
180 :
181 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
182 0 : if (mxWindow.is())
183 : Paint(awt::Rectangle(
184 : rEvent.UpdateRect.X,
185 : rEvent.UpdateRect.Y,
186 : rEvent.UpdateRect.Width,
187 0 : rEvent.UpdateRect.Height));
188 0 : }
189 :
190 : //----- lang::XEventListener --------------------------------------------------
191 :
192 0 : void SAL_CALL PresenterSlidePreview::disposing (const lang::EventObject& rEvent)
193 : throw (RuntimeException, std::exception)
194 : {
195 0 : if (rEvent.Source == mxWindow)
196 : {
197 0 : mxWindow = NULL;
198 0 : mxCanvas = NULL;
199 0 : mxPreview = NULL;
200 : }
201 0 : }
202 :
203 : //----- XDrawView -------------------------------------------------------------
204 :
205 0 : void SAL_CALL PresenterSlidePreview::setCurrentPage (const Reference<drawing::XDrawPage>& rxSlide)
206 : throw (RuntimeException, std::exception)
207 : {
208 0 : ThrowIfDisposed();
209 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
210 0 : SetSlide(rxSlide);
211 0 : }
212 :
213 0 : Reference<drawing::XDrawPage> SAL_CALL PresenterSlidePreview::getCurrentPage (void)
214 : throw (RuntimeException, std::exception)
215 : {
216 0 : ThrowIfDisposed();
217 0 : return NULL;
218 : }
219 :
220 :
221 :
222 0 : void PresenterSlidePreview::SetSlide (const Reference<drawing::XDrawPage>& rxPage)
223 : {
224 0 : mxCurrentSlide = rxPage;
225 0 : mxPreview = NULL;
226 :
227 0 : Reference<beans::XPropertySet> xPropertySet (mxCurrentSlide, UNO_QUERY);
228 0 : if (xPropertySet.is())
229 : {
230 0 : awt::Size aSlideSize;
231 : try
232 : {
233 0 : xPropertySet->getPropertyValue(
234 0 : OUString("Width")) >>= aSlideSize.Width;
235 0 : xPropertySet->getPropertyValue(
236 0 : OUString("Height")) >>= aSlideSize.Height;
237 : }
238 0 : catch (beans::UnknownPropertyException&)
239 : {
240 : OSL_ASSERT(false);
241 : }
242 : }
243 :
244 : // The preview is not transparent, therefore only this window, not its
245 : // parent, has to be invalidated.
246 0 : mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
247 0 : }
248 :
249 0 : void PresenterSlidePreview::Paint (const awt::Rectangle& rBoundingBox)
250 : {
251 : (void)rBoundingBox;
252 0 : if ( ! mxWindow.is())
253 0 : return;
254 0 : if ( ! mxCanvas.is())
255 0 : return;
256 0 : if ( ! mxPreviewRenderer.is())
257 0 : return;
258 :
259 : // Make sure that a preview in the correct size exists.
260 0 : awt::Rectangle aWindowBox (mxWindow->getPosSize());
261 :
262 0 : bool bCustomAnimation = false;
263 0 : bool bTransition = false;
264 0 : if( mxCurrentSlide.is() )
265 : {
266 0 : bCustomAnimation = mpPresenterController->HasCustomAnimation(mxCurrentSlide);
267 0 : bTransition = mpPresenterController->HasTransition(mxCurrentSlide);
268 : }
269 :
270 0 : if ( ! mxPreview.is() && mxCurrentSlide.is())
271 : {
272 : // Create a new preview bitmap.
273 0 : mxPreview = mxPreviewRenderer->createPreviewForCanvas(
274 : mxCurrentSlide,
275 : awt::Size(aWindowBox.Width, aWindowBox.Height),
276 : gnSuperSampleFactor,
277 0 : mxCanvas);
278 : }
279 :
280 : // Determine the bounding box of the preview.
281 0 : awt::Rectangle aPreviewBox;
282 0 : if (mxPreview.is())
283 : {
284 0 : const geometry::IntegerSize2D aPreviewSize (mxPreview->getSize());
285 : aPreviewBox = awt::Rectangle(
286 0 : (aWindowBox.Width - aPreviewSize.Width)/2,
287 0 : (aWindowBox.Height - aPreviewSize.Height)/2,
288 : aPreviewSize.Width,
289 0 : aPreviewSize.Height);
290 : }
291 : else
292 : {
293 0 : if (mnSlideAspectRatio > 0)
294 : {
295 0 : const awt::Size aPreviewSize (mxPreviewRenderer->calculatePreviewSize(
296 0 : mnSlideAspectRatio,awt::Size(aWindowBox.Width, aWindowBox.Height)));
297 : aPreviewBox = awt::Rectangle(
298 0 : (aWindowBox.Width - aPreviewSize.Width)/2,
299 0 : (aWindowBox.Height - aPreviewSize.Height)/2,
300 : aPreviewSize.Width,
301 0 : aPreviewSize.Height);
302 : }
303 : }
304 :
305 : // Paint the background.
306 : mpPresenterController->GetCanvasHelper()->Paint(
307 0 : mpPresenterController->GetViewBackground(mxViewId->getResourceURL()),
308 : mxCanvas,
309 : rBoundingBox,
310 : awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height),
311 0 : aPreviewBox);
312 :
313 : // Paint the preview.
314 : const rendering::ViewState aViewState(
315 : geometry::AffineMatrix2D(1,0,0, 0,1,0),
316 0 : NULL);
317 :
318 0 : Sequence<double> aBackgroundColor(4);
319 : rendering::RenderState aRenderState (
320 : geometry::AffineMatrix2D(1, 0, aPreviewBox.X, 0, 1, aPreviewBox.Y),
321 : NULL,
322 : aBackgroundColor,
323 0 : rendering::CompositeOperation::SOURCE);
324 0 : PresenterCanvasHelper::SetDeviceColor(aRenderState, 0x00000000);
325 0 : if (mxPreview.is())
326 : {
327 0 : mxCanvas->drawBitmap(mxPreview, aViewState, aRenderState);
328 0 : if( bTransition )
329 : {
330 0 : const awt::Rectangle aTransitionPreviewBox(5, aWindowBox.Height-20, 0, 0);
331 0 : SharedBitmapDescriptor aTransitionDescriptor = mpBitmaps->GetBitmap("Transition");
332 0 : Reference<rendering::XBitmap> xTransitionIcon (aTransitionDescriptor->GetNormalBitmap());
333 : rendering::RenderState aTransitionRenderState (
334 : geometry::AffineMatrix2D(1, 0, aTransitionPreviewBox.X, 0, 1, aTransitionPreviewBox.Y),
335 : NULL,
336 : aBackgroundColor,
337 0 : rendering::CompositeOperation::SOURCE);
338 0 : mxCanvas->drawBitmap(xTransitionIcon, aViewState, aTransitionRenderState);
339 : }
340 0 : if( bCustomAnimation )
341 : {
342 0 : const awt::Rectangle aAnimationPreviewBox(5, aWindowBox.Height-40, 0, 0);
343 0 : SharedBitmapDescriptor aAnimationDescriptor = mpBitmaps->GetBitmap("Animation");
344 0 : Reference<rendering::XBitmap> xAnimationIcon (aAnimationDescriptor->GetNormalBitmap());
345 : rendering::RenderState aAnimationRenderState (
346 : geometry::AffineMatrix2D(1, 0, aAnimationPreviewBox.X, 0, 1, aAnimationPreviewBox.Y),
347 : NULL,
348 : aBackgroundColor,
349 0 : rendering::CompositeOperation::SOURCE);
350 0 : mxCanvas->drawBitmap(xAnimationIcon, aViewState, aAnimationRenderState);
351 : }
352 : }
353 : else
354 : {
355 0 : if (mnSlideAspectRatio > 0)
356 : {
357 : Reference<rendering::XPolyPolygon2D> xPolygon (
358 0 : PresenterGeometryHelper::CreatePolygon(aPreviewBox, mxCanvas->getDevice()));
359 0 : if (xPolygon.is())
360 0 : mxCanvas->fillPolyPolygon(xPolygon, aViewState, aRenderState);
361 : }
362 : }
363 :
364 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
365 0 : if (xSpriteCanvas.is())
366 0 : xSpriteCanvas->updateScreen(sal_False);
367 : }
368 :
369 0 : void PresenterSlidePreview::Resize (void)
370 : {
371 0 : if (mxPreviewRenderer.is() && mxPreview.is())
372 : {
373 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
374 0 : const awt::Size aNewPreviewSize (mxPreviewRenderer->calculatePreviewSize(
375 : mnSlideAspectRatio,
376 0 : awt::Size(aWindowBox.Width, aWindowBox.Height)));
377 0 : const geometry::IntegerSize2D aPreviewSize (mxPreview->getSize());
378 0 : if (aNewPreviewSize.Width==aPreviewSize.Width
379 0 : && aNewPreviewSize.Height==aPreviewSize.Height)
380 : {
381 : // The size of the window may have changed but the preview would
382 : // be painted in the same size (but not necessarily at the same
383 : // position.)
384 0 : return;
385 : }
386 : }
387 0 : SetSlide(mxCurrentSlide);
388 : }
389 :
390 0 : void PresenterSlidePreview::ThrowIfDisposed (void)
391 : throw (::com::sun::star::lang::DisposedException)
392 : {
393 0 : if (PresenterSlidePreviewInterfaceBase::rBHelper.bDisposed || PresenterSlidePreviewInterfaceBase::rBHelper.bInDispose)
394 : {
395 : throw lang::DisposedException (
396 : OUString( "PresenterSlidePreview object has already been disposed"),
397 0 : static_cast<uno::XWeak*>(this));
398 : }
399 0 : }
400 :
401 : } } // end of namespace ::sd::presenter
402 :
403 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|