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 "PresenterBitmapContainer.hxx"
25 #include <com/sun/star/awt/XWindowPeer.hpp>
26 #include <com/sun/star/rendering/CompositeOperation.hpp>
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::drawing::framework
;
34 // Use a super sample factor greater than 1 to achieve a poor mans
35 // antialiasing effect for slide previews.
36 const sal_Int16 gnSuperSampleFactor
= 2;
39 namespace sdext::presenter
{
41 //===== PresenterSlidePreview =================================================
43 PresenterSlidePreview::PresenterSlidePreview (
44 const Reference
<XComponentContext
>& rxContext
,
45 const Reference
<XResourceId
>& rxViewId
,
46 const Reference
<XPane
>& rxAnchorPane
,
47 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
48 : PresenterSlidePreviewInterfaceBase(m_aMutex
),
49 mpPresenterController(rpPresenterController
),
51 mnSlideAspectRatio(28.0 / 21.0)
55 || ! rxAnchorPane
.is()
56 || ! rpPresenterController
.is())
58 throw RuntimeException(
59 u
"PresenterSlidePreview can not be constructed due to empty argument"_ustr
,
60 static_cast<XWeak
*>(this));
63 mxWindow
= rxAnchorPane
->getWindow();
64 mxCanvas
= rxAnchorPane
->getCanvas();
68 mxWindow
->addWindowListener(this);
69 mxWindow
->addPaintListener(this);
71 Reference
<awt::XWindowPeer
> xPeer (mxWindow
, UNO_QUERY
);
73 xPeer
->setBackground(util::Color(0xff000000));
75 mxWindow
->setVisible(true);
78 if (mpPresenterController
)
79 mnSlideAspectRatio
= mpPresenterController
->GetSlideAspectRatio();
81 Reference
<lang::XMultiComponentFactory
> xFactory
= rxContext
->getServiceManager();
83 mxPreviewRenderer
.set(
84 xFactory
->createInstanceWithContext(
85 u
"com.sun.star.drawing.SlideRenderer"_ustr
,
88 mpBitmaps
= std::make_shared
<PresenterBitmapContainer
>(
89 "PresenterScreenSettings/ScrollBar/Bitmaps",
90 std::shared_ptr
<PresenterBitmapContainer
>(),
96 PresenterSlidePreview::~PresenterSlidePreview()
100 void SAL_CALL
PresenterSlidePreview::disposing()
104 mxWindow
->removeWindowListener(this);
105 mxWindow
->removePaintListener(this);
110 Reference
<lang::XComponent
> xComponent (mxPreviewRenderer
, UNO_QUERY
);
112 xComponent
->dispose();
115 //----- XResourceId -----------------------------------------------------------
117 Reference
<XResourceId
> SAL_CALL
PresenterSlidePreview::getResourceId()
122 sal_Bool SAL_CALL
PresenterSlidePreview::isAnchorOnly()
127 //----- XWindowListener -------------------------------------------------------
129 void SAL_CALL
PresenterSlidePreview::windowResized (const awt::WindowEvent
&)
132 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
136 void SAL_CALL
PresenterSlidePreview::windowMoved (const awt::WindowEvent
&) {}
138 void SAL_CALL
PresenterSlidePreview::windowShown (const lang::EventObject
&)
141 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
145 void SAL_CALL
PresenterSlidePreview::windowHidden (const lang::EventObject
&) {}
147 //----- XPaintListener --------------------------------------------------------
149 void SAL_CALL
PresenterSlidePreview::windowPaint (const awt::PaintEvent
& rEvent
)
153 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
155 Paint(awt::Rectangle(
158 rEvent
.UpdateRect
.Width
,
159 rEvent
.UpdateRect
.Height
));
162 //----- lang::XEventListener --------------------------------------------------
164 void SAL_CALL
PresenterSlidePreview::disposing (const lang::EventObject
& rEvent
)
166 if (rEvent
.Source
== mxWindow
)
174 //----- XDrawView -------------------------------------------------------------
176 void SAL_CALL
PresenterSlidePreview::setCurrentPage (const Reference
<drawing::XDrawPage
>& rxSlide
)
179 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
183 Reference
<drawing::XDrawPage
> SAL_CALL
PresenterSlidePreview::getCurrentPage()
190 void PresenterSlidePreview::SetSlide (const Reference
<drawing::XDrawPage
>& rxPage
)
192 mxCurrentSlide
= rxPage
;
195 // The preview is not transparent, therefore only this window, not its
196 // parent, has to be invalidated.
197 mpPresenterController
->GetPaintManager()->Invalidate(mxWindow
);
200 void PresenterSlidePreview::Paint (const awt::Rectangle
& rBoundingBox
)
202 if ( ! mxWindow
.is())
204 if ( ! mxCanvas
.is())
206 if ( ! mxPreviewRenderer
.is())
209 // Make sure that a preview in the correct size exists.
210 awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
212 bool bCustomAnimation
= false;
213 bool bTransition
= false;
214 if( mxCurrentSlide
.is() )
216 bCustomAnimation
= PresenterController::HasCustomAnimation(mxCurrentSlide
);
217 bTransition
= PresenterController::HasTransition(mxCurrentSlide
);
220 if ( ! mxPreview
.is() && mxCurrentSlide
.is())
222 // Create a new preview bitmap.
223 mxPreview
= mxPreviewRenderer
->createPreviewForCanvas(
225 awt::Size(aWindowBox
.Width
, aWindowBox
.Height
),
230 // Determine the bounding box of the preview.
231 awt::Rectangle aPreviewBox
;
234 const geometry::IntegerSize2D
aPreviewSize (mxPreview
->getSize());
235 aPreviewBox
= awt::Rectangle(
236 (aWindowBox
.Width
- aPreviewSize
.Width
)/2,
237 (aWindowBox
.Height
- aPreviewSize
.Height
)/2,
239 aPreviewSize
.Height
);
243 if (mnSlideAspectRatio
> 0)
245 const awt::Size
aPreviewSize (mxPreviewRenderer
->calculatePreviewSize(
246 mnSlideAspectRatio
,awt::Size(aWindowBox
.Width
, aWindowBox
.Height
)));
247 aPreviewBox
= awt::Rectangle(
248 (aWindowBox
.Width
- aPreviewSize
.Width
)/2,
249 (aWindowBox
.Height
- aPreviewSize
.Height
)/2,
251 aPreviewSize
.Height
);
255 // Paint the background.
256 mpPresenterController
->GetCanvasHelper()->Paint(
257 mpPresenterController
->GetViewBackground(mxViewId
->getResourceURL()),
260 awt::Rectangle(0,0,aWindowBox
.Width
,aWindowBox
.Height
),
263 // Paint the preview.
264 const rendering::ViewState
aViewState(
265 geometry::AffineMatrix2D(1,0,0, 0,1,0),
268 Sequence
<double> aBackgroundColor(4);
269 rendering::RenderState
aRenderState (
270 geometry::AffineMatrix2D(1, 0, aPreviewBox
.X
, 0, 1, aPreviewBox
.Y
),
273 rendering::CompositeOperation::SOURCE
);
274 PresenterCanvasHelper::SetDeviceColor(aRenderState
, 0x00000000);
277 mxCanvas
->drawBitmap(mxPreview
, aViewState
, aRenderState
);
280 const awt::Rectangle
aTransitionPreviewBox(5, aWindowBox
.Height
-20, 0, 0);
281 SharedBitmapDescriptor aTransitionDescriptor
= mpBitmaps
->GetBitmap(u
"Transition"_ustr
);
282 Reference
<rendering::XBitmap
> xTransitionIcon (aTransitionDescriptor
->GetNormalBitmap());
283 rendering::RenderState
aTransitionRenderState (
284 geometry::AffineMatrix2D(1, 0, aTransitionPreviewBox
.X
, 0, 1, aTransitionPreviewBox
.Y
),
287 rendering::CompositeOperation::SOURCE
);
288 mxCanvas
->drawBitmap(xTransitionIcon
, aViewState
, aTransitionRenderState
);
290 if( bCustomAnimation
)
292 const awt::Rectangle
aAnimationPreviewBox(5, aWindowBox
.Height
-40, 0, 0);
293 SharedBitmapDescriptor aAnimationDescriptor
= mpBitmaps
->GetBitmap(u
"Animation"_ustr
);
294 Reference
<rendering::XBitmap
> xAnimationIcon (aAnimationDescriptor
->GetNormalBitmap());
295 rendering::RenderState
aAnimationRenderState (
296 geometry::AffineMatrix2D(1, 0, aAnimationPreviewBox
.X
, 0, 1, aAnimationPreviewBox
.Y
),
299 rendering::CompositeOperation::SOURCE
);
300 mxCanvas
->drawBitmap(xAnimationIcon
, aViewState
, aAnimationRenderState
);
305 if (mnSlideAspectRatio
> 0)
307 Reference
<rendering::XPolyPolygon2D
> xPolygon (
308 PresenterGeometryHelper::CreatePolygon(aPreviewBox
, mxCanvas
->getDevice()));
310 mxCanvas
->fillPolyPolygon(xPolygon
, aViewState
, aRenderState
);
314 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxCanvas
, UNO_QUERY
);
315 if (xSpriteCanvas
.is())
316 xSpriteCanvas
->updateScreen(false);
319 void PresenterSlidePreview::Resize()
321 if (mxPreviewRenderer
.is() && mxPreview
.is())
323 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
324 const awt::Size
aNewPreviewSize (mxPreviewRenderer
->calculatePreviewSize(
326 awt::Size(aWindowBox
.Width
, aWindowBox
.Height
)));
327 const geometry::IntegerSize2D
aPreviewSize (mxPreview
->getSize());
328 if (aNewPreviewSize
.Width
==aPreviewSize
.Width
329 && aNewPreviewSize
.Height
==aPreviewSize
.Height
)
331 // The size of the window may have changed but the preview would
332 // be painted in the same size (but not necessarily at the same
337 SetSlide(mxCurrentSlide
);
340 void PresenterSlidePreview::ThrowIfDisposed()
342 if (PresenterSlidePreviewInterfaceBase::rBHelper
.bDisposed
|| PresenterSlidePreviewInterfaceBase::rBHelper
.bInDispose
)
344 throw lang::DisposedException (
345 u
"PresenterSlidePreview object has already been disposed"_ustr
,
346 static_cast<uno::XWeak
*>(this));
350 } // end of namespace ::sdext::presenter
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */