1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::drawing::framework
;
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;
45 namespace sdext
{ namespace presenter
{
47 //===== PresenterSlidePreview =================================================
49 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
),
61 mnSlideAspectRatio(28.0 / 21.0),
67 || ! rxAnchorPane
.is()
68 || ! rpPresenterController
.is())
70 throw RuntimeException(
71 "PresenterSlidePreview can not be constructed due to empty argument",
72 static_cast<XWeak
*>(this));
75 mxWindow
= rxAnchorPane
->getWindow();
76 mxCanvas
= rxAnchorPane
->getCanvas();
80 mxWindow
->addWindowListener(this);
81 mxWindow
->addPaintListener(this);
83 Reference
<awt::XWindowPeer
> xPeer (mxWindow
, UNO_QUERY
);
85 xPeer
->setBackground(util::Color(0xff000000));
87 mxWindow
->setVisible(sal_True
);
90 if (mpPresenterController
.get() != NULL
)
91 mnSlideAspectRatio
= mpPresenterController
->GetSlideAspectRatio();
93 Reference
<lang::XMultiComponentFactory
> xFactory (rxContext
->getServiceManager(), UNO_QUERY
);
95 mxPreviewRenderer
= Reference
<drawing::XSlideRenderer
>(
96 xFactory
->createInstanceWithContext(
97 OUString("com.sun.star.drawing.SlideRenderer"),
100 mpBitmaps
.reset(new PresenterBitmapContainer(
101 OUString("PresenterScreenSettings/ScrollBar/Bitmaps"),
102 ::boost::shared_ptr
<PresenterBitmapContainer
>(),
108 PresenterSlidePreview::~PresenterSlidePreview()
112 void SAL_CALL
PresenterSlidePreview::disposing()
116 mxWindow
->removeWindowListener(this);
117 mxWindow
->removePaintListener(this);
122 Reference
<lang::XComponent
> xComponent (mxPreviewRenderer
, UNO_QUERY
);
124 xComponent
->dispose();
127 //----- XResourceId -----------------------------------------------------------
129 Reference
<XResourceId
> SAL_CALL
PresenterSlidePreview::getResourceId()
130 throw (RuntimeException
, std::exception
)
135 sal_Bool SAL_CALL
PresenterSlidePreview::isAnchorOnly()
136 throw (RuntimeException
, std::exception
)
141 //----- XWindowListener -------------------------------------------------------
143 void SAL_CALL
PresenterSlidePreview::windowResized (const awt::WindowEvent
& rEvent
)
144 throw (RuntimeException
, std::exception
)
148 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
152 void SAL_CALL
PresenterSlidePreview::windowMoved (const awt::WindowEvent
& rEvent
)
153 throw (RuntimeException
, std::exception
)
158 void SAL_CALL
PresenterSlidePreview::windowShown (const lang::EventObject
& rEvent
)
159 throw (RuntimeException
, std::exception
)
163 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
167 void SAL_CALL
PresenterSlidePreview::windowHidden (const lang::EventObject
& rEvent
)
168 throw (RuntimeException
, std::exception
)
173 //----- XPaintListener --------------------------------------------------------
175 void SAL_CALL
PresenterSlidePreview::windowPaint (const awt::PaintEvent
& rEvent
)
176 throw (RuntimeException
, std::exception
)
180 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
182 Paint(awt::Rectangle(
185 rEvent
.UpdateRect
.Width
,
186 rEvent
.UpdateRect
.Height
));
189 //----- lang::XEventListener --------------------------------------------------
191 void SAL_CALL
PresenterSlidePreview::disposing (const lang::EventObject
& rEvent
)
192 throw (RuntimeException
, std::exception
)
194 if (rEvent
.Source
== mxWindow
)
202 //----- XDrawView -------------------------------------------------------------
204 void SAL_CALL
PresenterSlidePreview::setCurrentPage (const Reference
<drawing::XDrawPage
>& rxSlide
)
205 throw (RuntimeException
, std::exception
)
208 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
212 Reference
<drawing::XDrawPage
> SAL_CALL
PresenterSlidePreview::getCurrentPage()
213 throw (RuntimeException
, std::exception
)
221 void PresenterSlidePreview::SetSlide (const Reference
<drawing::XDrawPage
>& rxPage
)
223 mxCurrentSlide
= rxPage
;
226 Reference
<beans::XPropertySet
> xPropertySet (mxCurrentSlide
, UNO_QUERY
);
227 if (xPropertySet
.is())
229 awt::Size aSlideSize
;
232 xPropertySet
->getPropertyValue(
233 OUString("Width")) >>= aSlideSize
.Width
;
234 xPropertySet
->getPropertyValue(
235 OUString("Height")) >>= aSlideSize
.Height
;
237 catch (beans::UnknownPropertyException
&)
243 // The preview is not transparent, therefore only this window, not its
244 // parent, has to be invalidated.
245 mpPresenterController
->GetPaintManager()->Invalidate(mxWindow
);
248 void PresenterSlidePreview::Paint (const awt::Rectangle
& rBoundingBox
)
251 if ( ! mxWindow
.is())
253 if ( ! mxCanvas
.is())
255 if ( ! mxPreviewRenderer
.is())
258 // Make sure that a preview in the correct size exists.
259 awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
261 bool bCustomAnimation
= false;
262 bool bTransition
= false;
263 if( mxCurrentSlide
.is() )
265 bCustomAnimation
= PresenterController::HasCustomAnimation(mxCurrentSlide
);
266 bTransition
= PresenterController::HasTransition(mxCurrentSlide
);
269 if ( ! mxPreview
.is() && mxCurrentSlide
.is())
271 // Create a new preview bitmap.
272 mxPreview
= mxPreviewRenderer
->createPreviewForCanvas(
274 awt::Size(aWindowBox
.Width
, aWindowBox
.Height
),
279 // Determine the bounding box of the preview.
280 awt::Rectangle aPreviewBox
;
283 const geometry::IntegerSize2D
aPreviewSize (mxPreview
->getSize());
284 aPreviewBox
= awt::Rectangle(
285 (aWindowBox
.Width
- aPreviewSize
.Width
)/2,
286 (aWindowBox
.Height
- aPreviewSize
.Height
)/2,
288 aPreviewSize
.Height
);
292 if (mnSlideAspectRatio
> 0)
294 const awt::Size
aPreviewSize (mxPreviewRenderer
->calculatePreviewSize(
295 mnSlideAspectRatio
,awt::Size(aWindowBox
.Width
, aWindowBox
.Height
)));
296 aPreviewBox
= awt::Rectangle(
297 (aWindowBox
.Width
- aPreviewSize
.Width
)/2,
298 (aWindowBox
.Height
- aPreviewSize
.Height
)/2,
300 aPreviewSize
.Height
);
304 // Paint the background.
305 mpPresenterController
->GetCanvasHelper()->Paint(
306 mpPresenterController
->GetViewBackground(mxViewId
->getResourceURL()),
309 awt::Rectangle(0,0,aWindowBox
.Width
,aWindowBox
.Height
),
312 // Paint the preview.
313 const rendering::ViewState
aViewState(
314 geometry::AffineMatrix2D(1,0,0, 0,1,0),
317 Sequence
<double> aBackgroundColor(4);
318 rendering::RenderState
aRenderState (
319 geometry::AffineMatrix2D(1, 0, aPreviewBox
.X
, 0, 1, aPreviewBox
.Y
),
322 rendering::CompositeOperation::SOURCE
);
323 PresenterCanvasHelper::SetDeviceColor(aRenderState
, 0x00000000);
326 mxCanvas
->drawBitmap(mxPreview
, aViewState
, aRenderState
);
329 const awt::Rectangle
aTransitionPreviewBox(5, aWindowBox
.Height
-20, 0, 0);
330 SharedBitmapDescriptor aTransitionDescriptor
= mpBitmaps
->GetBitmap("Transition");
331 Reference
<rendering::XBitmap
> xTransitionIcon (aTransitionDescriptor
->GetNormalBitmap());
332 rendering::RenderState
aTransitionRenderState (
333 geometry::AffineMatrix2D(1, 0, aTransitionPreviewBox
.X
, 0, 1, aTransitionPreviewBox
.Y
),
336 rendering::CompositeOperation::SOURCE
);
337 mxCanvas
->drawBitmap(xTransitionIcon
, aViewState
, aTransitionRenderState
);
339 if( bCustomAnimation
)
341 const awt::Rectangle
aAnimationPreviewBox(5, aWindowBox
.Height
-40, 0, 0);
342 SharedBitmapDescriptor aAnimationDescriptor
= mpBitmaps
->GetBitmap("Animation");
343 Reference
<rendering::XBitmap
> xAnimationIcon (aAnimationDescriptor
->GetNormalBitmap());
344 rendering::RenderState
aAnimationRenderState (
345 geometry::AffineMatrix2D(1, 0, aAnimationPreviewBox
.X
, 0, 1, aAnimationPreviewBox
.Y
),
348 rendering::CompositeOperation::SOURCE
);
349 mxCanvas
->drawBitmap(xAnimationIcon
, aViewState
, aAnimationRenderState
);
354 if (mnSlideAspectRatio
> 0)
356 Reference
<rendering::XPolyPolygon2D
> xPolygon (
357 PresenterGeometryHelper::CreatePolygon(aPreviewBox
, mxCanvas
->getDevice()));
359 mxCanvas
->fillPolyPolygon(xPolygon
, aViewState
, aRenderState
);
363 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxCanvas
, UNO_QUERY
);
364 if (xSpriteCanvas
.is())
365 xSpriteCanvas
->updateScreen(sal_False
);
368 void PresenterSlidePreview::Resize()
370 if (mxPreviewRenderer
.is() && mxPreview
.is())
372 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
373 const awt::Size
aNewPreviewSize (mxPreviewRenderer
->calculatePreviewSize(
375 awt::Size(aWindowBox
.Width
, aWindowBox
.Height
)));
376 const geometry::IntegerSize2D
aPreviewSize (mxPreview
->getSize());
377 if (aNewPreviewSize
.Width
==aPreviewSize
.Width
378 && aNewPreviewSize
.Height
==aPreviewSize
.Height
)
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
386 SetSlide(mxCurrentSlide
);
389 void PresenterSlidePreview::ThrowIfDisposed()
390 throw (::com::sun::star::lang::DisposedException
)
392 if (PresenterSlidePreviewInterfaceBase::rBHelper
.bDisposed
|| PresenterSlidePreviewInterfaceBase::rBHelper
.bInDispose
)
394 throw lang::DisposedException (
395 "PresenterSlidePreview object has already been disposed",
396 static_cast<uno::XWeak
*>(this));
400 } } // end of namespace ::sd::presenter
402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */