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 achieve 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 : "PresenterSlidePreview can not be constructed due to empty argument",
72 0 : static_cast<XWeak*>(this));
73 : }
74 :
75 0 : mxWindow = rxAnchorPane->getWindow();
76 0 : mxCanvas = rxAnchorPane->getCanvas();
77 :
78 0 : if (mxWindow.is())
79 : {
80 0 : mxWindow->addWindowListener(this);
81 0 : mxWindow->addPaintListener(this);
82 :
83 0 : Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY);
84 0 : if (xPeer.is())
85 0 : xPeer->setBackground(util::Color(0xff000000));
86 :
87 0 : mxWindow->setVisible(sal_True);
88 : }
89 :
90 0 : if (mpPresenterController.get() != NULL)
91 0 : mnSlideAspectRatio = mpPresenterController->GetSlideAspectRatio();
92 :
93 0 : Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager(), UNO_QUERY);
94 0 : if (xFactory.is())
95 0 : mxPreviewRenderer = Reference<drawing::XSlideRenderer>(
96 0 : xFactory->createInstanceWithContext(
97 : OUString("com.sun.star.drawing.SlideRenderer"),
98 0 : rxContext),
99 0 : UNO_QUERY);
100 : mpBitmaps.reset(new PresenterBitmapContainer(
101 : OUString("PresenterScreenSettings/ScrollBar/Bitmaps"),
102 : ::boost::shared_ptr<PresenterBitmapContainer>(),
103 : rxContext,
104 0 : mxCanvas));
105 0 : Resize();
106 0 : }
107 :
108 0 : PresenterSlidePreview::~PresenterSlidePreview (void)
109 : {
110 0 : }
111 :
112 0 : void SAL_CALL PresenterSlidePreview::disposing (void)
113 : {
114 0 : if (mxWindow.is())
115 : {
116 0 : mxWindow->removeWindowListener(this);
117 0 : mxWindow->removePaintListener(this);
118 0 : mxWindow = NULL;
119 0 : mxCanvas = NULL;
120 : }
121 :
122 0 : Reference<lang::XComponent> xComponent (mxPreviewRenderer, UNO_QUERY);
123 0 : if (xComponent.is())
124 0 : xComponent->dispose();
125 0 : }
126 :
127 : //----- XResourceId -----------------------------------------------------------
128 :
129 0 : Reference<XResourceId> SAL_CALL PresenterSlidePreview::getResourceId (void)
130 : throw (RuntimeException, std::exception)
131 : {
132 0 : return mxViewId;
133 : }
134 :
135 0 : sal_Bool SAL_CALL PresenterSlidePreview::isAnchorOnly (void)
136 : throw (RuntimeException, std::exception)
137 : {
138 0 : return false;
139 : }
140 :
141 : //----- XWindowListener -------------------------------------------------------
142 :
143 0 : void SAL_CALL PresenterSlidePreview::windowResized (const awt::WindowEvent& rEvent)
144 : throw (RuntimeException, std::exception)
145 : {
146 : (void)rEvent;
147 0 : ThrowIfDisposed();
148 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
149 0 : Resize();
150 0 : }
151 :
152 0 : void SAL_CALL PresenterSlidePreview::windowMoved (const awt::WindowEvent& rEvent)
153 : throw (RuntimeException, std::exception)
154 : {
155 : (void)rEvent;
156 0 : }
157 :
158 0 : void SAL_CALL PresenterSlidePreview::windowShown (const lang::EventObject& rEvent)
159 : throw (RuntimeException, std::exception)
160 : {
161 : (void)rEvent;
162 0 : ThrowIfDisposed();
163 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
164 0 : Resize();
165 0 : }
166 :
167 0 : void SAL_CALL PresenterSlidePreview::windowHidden (const lang::EventObject& rEvent)
168 : throw (RuntimeException, std::exception)
169 : {
170 : (void)rEvent;
171 0 : }
172 :
173 : //----- XPaintListener --------------------------------------------------------
174 :
175 0 : void SAL_CALL PresenterSlidePreview::windowPaint (const awt::PaintEvent& rEvent)
176 : throw (RuntimeException, std::exception)
177 : {
178 0 : ThrowIfDisposed();
179 :
180 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
181 0 : if (mxWindow.is())
182 : Paint(awt::Rectangle(
183 : rEvent.UpdateRect.X,
184 : rEvent.UpdateRect.Y,
185 : rEvent.UpdateRect.Width,
186 0 : rEvent.UpdateRect.Height));
187 0 : }
188 :
189 : //----- lang::XEventListener --------------------------------------------------
190 :
191 0 : void SAL_CALL PresenterSlidePreview::disposing (const lang::EventObject& rEvent)
192 : throw (RuntimeException, std::exception)
193 : {
194 0 : if (rEvent.Source == mxWindow)
195 : {
196 0 : mxWindow = NULL;
197 0 : mxCanvas = NULL;
198 0 : mxPreview = NULL;
199 : }
200 0 : }
201 :
202 : //----- XDrawView -------------------------------------------------------------
203 :
204 0 : void SAL_CALL PresenterSlidePreview::setCurrentPage (const Reference<drawing::XDrawPage>& rxSlide)
205 : throw (RuntimeException, std::exception)
206 : {
207 0 : ThrowIfDisposed();
208 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
209 0 : SetSlide(rxSlide);
210 0 : }
211 :
212 0 : Reference<drawing::XDrawPage> SAL_CALL PresenterSlidePreview::getCurrentPage (void)
213 : throw (RuntimeException, std::exception)
214 : {
215 0 : ThrowIfDisposed();
216 0 : return NULL;
217 : }
218 :
219 :
220 :
221 0 : void PresenterSlidePreview::SetSlide (const Reference<drawing::XDrawPage>& rxPage)
222 : {
223 0 : mxCurrentSlide = rxPage;
224 0 : mxPreview = NULL;
225 :
226 0 : Reference<beans::XPropertySet> xPropertySet (mxCurrentSlide, UNO_QUERY);
227 0 : if (xPropertySet.is())
228 : {
229 0 : awt::Size aSlideSize;
230 : try
231 : {
232 0 : xPropertySet->getPropertyValue(
233 0 : OUString("Width")) >>= aSlideSize.Width;
234 0 : xPropertySet->getPropertyValue(
235 0 : OUString("Height")) >>= aSlideSize.Height;
236 : }
237 0 : catch (beans::UnknownPropertyException&)
238 : {
239 : OSL_ASSERT(false);
240 : }
241 : }
242 :
243 : // The preview is not transparent, therefore only this window, not its
244 : // parent, has to be invalidated.
245 0 : mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
246 0 : }
247 :
248 0 : void PresenterSlidePreview::Paint (const awt::Rectangle& rBoundingBox)
249 : {
250 : (void)rBoundingBox;
251 0 : if ( ! mxWindow.is())
252 0 : return;
253 0 : if ( ! mxCanvas.is())
254 0 : return;
255 0 : if ( ! mxPreviewRenderer.is())
256 0 : return;
257 :
258 : // Make sure that a preview in the correct size exists.
259 0 : awt::Rectangle aWindowBox (mxWindow->getPosSize());
260 :
261 0 : bool bCustomAnimation = false;
262 0 : bool bTransition = false;
263 0 : if( mxCurrentSlide.is() )
264 : {
265 0 : bCustomAnimation = mpPresenterController->HasCustomAnimation(mxCurrentSlide);
266 0 : bTransition = mpPresenterController->HasTransition(mxCurrentSlide);
267 : }
268 :
269 0 : if ( ! mxPreview.is() && mxCurrentSlide.is())
270 : {
271 : // Create a new preview bitmap.
272 0 : mxPreview = mxPreviewRenderer->createPreviewForCanvas(
273 : mxCurrentSlide,
274 : awt::Size(aWindowBox.Width, aWindowBox.Height),
275 : gnSuperSampleFactor,
276 0 : mxCanvas);
277 : }
278 :
279 : // Determine the bounding box of the preview.
280 0 : awt::Rectangle aPreviewBox;
281 0 : if (mxPreview.is())
282 : {
283 0 : const geometry::IntegerSize2D aPreviewSize (mxPreview->getSize());
284 : aPreviewBox = awt::Rectangle(
285 0 : (aWindowBox.Width - aPreviewSize.Width)/2,
286 0 : (aWindowBox.Height - aPreviewSize.Height)/2,
287 : aPreviewSize.Width,
288 0 : aPreviewSize.Height);
289 : }
290 : else
291 : {
292 0 : if (mnSlideAspectRatio > 0)
293 : {
294 0 : const awt::Size aPreviewSize (mxPreviewRenderer->calculatePreviewSize(
295 0 : mnSlideAspectRatio,awt::Size(aWindowBox.Width, aWindowBox.Height)));
296 : aPreviewBox = awt::Rectangle(
297 0 : (aWindowBox.Width - aPreviewSize.Width)/2,
298 0 : (aWindowBox.Height - aPreviewSize.Height)/2,
299 : aPreviewSize.Width,
300 0 : aPreviewSize.Height);
301 : }
302 : }
303 :
304 : // Paint the background.
305 : mpPresenterController->GetCanvasHelper()->Paint(
306 0 : mpPresenterController->GetViewBackground(mxViewId->getResourceURL()),
307 : mxCanvas,
308 : rBoundingBox,
309 : awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height),
310 0 : aPreviewBox);
311 :
312 : // Paint the preview.
313 : const rendering::ViewState aViewState(
314 : geometry::AffineMatrix2D(1,0,0, 0,1,0),
315 0 : NULL);
316 :
317 0 : Sequence<double> aBackgroundColor(4);
318 : rendering::RenderState aRenderState (
319 : geometry::AffineMatrix2D(1, 0, aPreviewBox.X, 0, 1, aPreviewBox.Y),
320 : NULL,
321 : aBackgroundColor,
322 0 : rendering::CompositeOperation::SOURCE);
323 0 : PresenterCanvasHelper::SetDeviceColor(aRenderState, 0x00000000);
324 0 : if (mxPreview.is())
325 : {
326 0 : mxCanvas->drawBitmap(mxPreview, aViewState, aRenderState);
327 0 : if( bTransition )
328 : {
329 0 : const awt::Rectangle aTransitionPreviewBox(5, aWindowBox.Height-20, 0, 0);
330 0 : SharedBitmapDescriptor aTransitionDescriptor = mpBitmaps->GetBitmap("Transition");
331 0 : Reference<rendering::XBitmap> xTransitionIcon (aTransitionDescriptor->GetNormalBitmap());
332 : rendering::RenderState aTransitionRenderState (
333 : geometry::AffineMatrix2D(1, 0, aTransitionPreviewBox.X, 0, 1, aTransitionPreviewBox.Y),
334 : NULL,
335 : aBackgroundColor,
336 0 : rendering::CompositeOperation::SOURCE);
337 0 : mxCanvas->drawBitmap(xTransitionIcon, aViewState, aTransitionRenderState);
338 : }
339 0 : if( bCustomAnimation )
340 : {
341 0 : const awt::Rectangle aAnimationPreviewBox(5, aWindowBox.Height-40, 0, 0);
342 0 : SharedBitmapDescriptor aAnimationDescriptor = mpBitmaps->GetBitmap("Animation");
343 0 : Reference<rendering::XBitmap> xAnimationIcon (aAnimationDescriptor->GetNormalBitmap());
344 : rendering::RenderState aAnimationRenderState (
345 : geometry::AffineMatrix2D(1, 0, aAnimationPreviewBox.X, 0, 1, aAnimationPreviewBox.Y),
346 : NULL,
347 : aBackgroundColor,
348 0 : rendering::CompositeOperation::SOURCE);
349 0 : mxCanvas->drawBitmap(xAnimationIcon, aViewState, aAnimationRenderState);
350 : }
351 : }
352 : else
353 : {
354 0 : if (mnSlideAspectRatio > 0)
355 : {
356 : Reference<rendering::XPolyPolygon2D> xPolygon (
357 0 : PresenterGeometryHelper::CreatePolygon(aPreviewBox, mxCanvas->getDevice()));
358 0 : if (xPolygon.is())
359 0 : mxCanvas->fillPolyPolygon(xPolygon, aViewState, aRenderState);
360 : }
361 : }
362 :
363 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
364 0 : if (xSpriteCanvas.is())
365 0 : xSpriteCanvas->updateScreen(sal_False);
366 : }
367 :
368 0 : void PresenterSlidePreview::Resize (void)
369 : {
370 0 : if (mxPreviewRenderer.is() && mxPreview.is())
371 : {
372 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
373 0 : const awt::Size aNewPreviewSize (mxPreviewRenderer->calculatePreviewSize(
374 : mnSlideAspectRatio,
375 0 : awt::Size(aWindowBox.Width, aWindowBox.Height)));
376 0 : const geometry::IntegerSize2D aPreviewSize (mxPreview->getSize());
377 0 : if (aNewPreviewSize.Width==aPreviewSize.Width
378 0 : && aNewPreviewSize.Height==aPreviewSize.Height)
379 : {
380 : // The size of the window may have changed but the preview would
381 : // be painted in the same size (but not necessarily at the same
382 : // position.)
383 0 : return;
384 : }
385 : }
386 0 : SetSlide(mxCurrentSlide);
387 : }
388 :
389 0 : void PresenterSlidePreview::ThrowIfDisposed (void)
390 : throw (::com::sun::star::lang::DisposedException)
391 : {
392 0 : if (PresenterSlidePreviewInterfaceBase::rBHelper.bDisposed || PresenterSlidePreviewInterfaceBase::rBHelper.bInDispose)
393 : {
394 : throw lang::DisposedException (
395 : "PresenterSlidePreview object has already been disposed",
396 0 : static_cast<uno::XWeak*>(this));
397 : }
398 0 : }
399 :
400 : } } // end of namespace ::sd::presenter
401 :
402 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|