20#include <config_features.h>
43#include <com/sun/star/awt/XWindow.hpp>
44#include <com/sun/star/beans/XPropertySet.hpp>
45#include <com/sun/star/lang/XComponent.hpp>
46#include <com/sun/star/lang/NoSupportException.hpp>
47#include <com/sun/star/media/XPlayer.hpp>
48#include <com/sun/star/media/XPlayerWindow.hpp>
49#include <com/sun/star/presentation/XSlideShowView.hpp>
50#include <com/sun/star/rendering/XCanvas.hpp>
61 uno::Reference< drawing::XShape > xShape,
62 uno::Reference< uno::XComponentContext > xContext ) :
63 mpViewLayer( rViewLayer ),
64 maWindowOffset( 0, 0 ),
73 ENSURE_OR_THROW( mpViewLayer,
"ViewMediaShape::ViewMediaShape(): Invalid View" );
74 ENSURE_OR_THROW( mpViewLayer->getCanvas(),
"ViewMediaShape::ViewMediaShape(): Invalid ViewLayer canvas" );
84 ViewMediaShape::~ViewMediaShape()
90 catch (
const uno::Exception &)
101 void ViewMediaShape::startMedia()
110 void ViewMediaShape::endMedia()
113 if( mxPlayerWindow.is() )
115 mxPlayerWindow->dispose();
116 mxPlayerWindow.clear();
119 mpMediaWindow.disposeAndClear();
128 if( xComponent.is() )
129 xComponent->dispose();
135 void ViewMediaShape::pauseMedia()
141 void ViewMediaShape::setMediaTime(
double fTime)
144 mxPlayer->setMediaTime(fTime);
147 void ViewMediaShape::setLooping(
bool bLooping)
151 mxPlayer->setPlaybackLoop(bLooping);
155 bool ViewMediaShape::render( const ::basegfx::B2DRectangle& rBounds )
const
157#if !HAVE_FEATURE_AVMEDIA
165 if( !mpMediaWindow && !mxPlayerWindow.is() )
171 xPropSet->getPropertyValue(
"FallbackGraphic") >>= xGraphic;
179 rendering::ViewState aViewState;
180 aViewState.AffineTransform = pCanvas->getViewState().AffineTransform;
182 rendering::RenderState aRenderState;
183 ::canvas::tools::initRenderState( aRenderState );
187 const ::basegfx::B2DVector aScale( rBounds.getWidth() / aBmpSize.Width(),
188 rBounds.getHeight() / aBmpSize.Height() );
190 aScale, rBounds.getMinimum()));
191 ::canvas::tools::setRenderStateTransform( aRenderState, aTranslation );
193 pCanvas->getUNOCanvas()->drawBitmap( xBitmap,
201 bool ViewMediaShape::resize( const ::basegfx::B2DRectangle& rNewBounds )
const
210 if( !mxPlayerWindow.is() )
222 const awt::Rectangle aRect( xParentWindow->getPosSize() );
224 maWindowOffset.X = aRect.X;
225 maWindowOffset.Y = aRect.Y;
229 ::canvas::tools::calcTransformedRectBounds( aTmpRange,
231 mpViewLayer->getTransformation() );
232 const ::basegfx::B2IRange& rRangePix(
233 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
235 mxPlayerWindow->setEnable( !rRangePix.isEmpty() );
237 if( rRangePix.isEmpty() )
240 awt::Rectangle aCanvasArea;
243 aCanvasArea = xUnoView->getUnoView()->getCanvasArea();
245 const Point aPosPixel( rRangePix.getMinX() + maWindowOffset.X + aCanvasArea.X,
246 rRangePix.getMinY() + maWindowOffset.Y + aCanvasArea.Y );
247 const Size aSizePixel( rRangePix.getMaxX() - rRangePix.getMinX(),
248 rRangePix.getMaxY() - rRangePix.getMinY() );
252 mpMediaWindow->SetPosSizePixel( aPosPixel, aSizePixel );
253 mxPlayerWindow->setPosSize( 0, 0,
259 mxPlayerWindow->setPosSize( aPosPixel.
X(), aPosPixel.
Y(),
268 bool ViewMediaShape::implInitialize( const ::basegfx::B2DRectangle& rBounds )
270 if( !mxPlayer.is() &&
mxShape.is() )
273 "ViewMediaShape::implInitialize(): Invalid layer canvas" );
282 xPropSet.set(
mxShape, uno::UNO_QUERY );
289 xPropSet->getPropertyValue(
"MediaMimeType") >>= sMimeType;
290 if ((xPropSet->getPropertyValue(
"PrivateTempFileURL") >>=
aURL)
293 implInitializeMediaPlayer(
aURL, sMimeType );
295 else if (xPropSet->getPropertyValue(
"MediaURL") >>=
aURL)
297 implInitializeMediaPlayer(
aURL, sMimeType );
304 if( ::canvas::tools::getDeviceInfo( xCanvas, aDeviceParams ).
getLength() > 1 )
306 implInitializePlayerWindow( rBounds, aDeviceParams );
310 implSetMediaProperties( xPropSet );
312 catch( uno::RuntimeException& )
316 catch( uno::Exception& )
323 return mxPlayer.is() || mxPlayerWindow.is();
332 mxPlayer->setMediaTime( 0.0 );
341 mxPlayer->setPlaybackLoop( bLoop );
349 sal_Int16 nVolumeDB(0);
353 mxPlayer->setVolumeDB( nVolumeDB );
355 if( mxPlayerWindow.is() )
357 media::ZoomLevel eZoom(media::ZoomLevel_FIT_TO_WINDOW);
361 mxPlayerWindow->setZoomLevel( eZoom );
366 void ViewMediaShape::implInitializeMediaPlayer(
const OUString& rMediaURL,
const OUString& rMimeType )
368#if !HAVE_FEATURE_AVMEDIA
377 if( !rMediaURL.isEmpty() )
382 catch( uno::RuntimeException& )
386 catch(
const uno::Exception& )
388 throw lang::NoSupportException(
"No video support for " + rMediaURL );
394 void ViewMediaShape::implInitializePlayerWindow( const ::basegfx::B2DRectangle& rBounds,
397 SAL_INFO(
"slideshow",
"ViewMediaShape::implInitializePlayerWindow" );
398 if( mpMediaWindow || rBounds.isEmpty() )
405 rVCLDeviceParams[ 1 ] >>= aVal;
413 ::canvas::tools::calcTransformedRectBounds( aTmpRange,
415 mpViewLayer->getTransformation() );
416 const ::basegfx::B2IRange& rRangePix(
417 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
419 if( !rRangePix.isEmpty() )
421 awt::Rectangle aAWTRect( rRangePix.getMinX(),
423 rRangePix.getMaxX() - rRangePix.getMinX(),
424 rRangePix.getMaxY() - rRangePix.getMinY() );
426 mpMediaWindow.disposeAndClear();
431 awt::Rectangle aCanvasArea = xUnoView->getUnoView()->getCanvasArea();
432 aAWTRect.X += aCanvasArea.X;
433 aAWTRect.Y += aCanvasArea.Y;
435 mpMediaWindow->SetPosSizePixel(
Point( aAWTRect.X, aAWTRect.Y ),
436 Size( aAWTRect.Width, aAWTRect.Height ) );
438 mpMediaWindow->SetBackground(
COL_BLACK );
439 mpMediaWindow->SetParentClipMode( ParentClipMode::NoClip );
440 mpMediaWindow->EnableEraseBackground(
false );
441 mpMediaWindow->SetForwardKey(
true );
442 mpMediaWindow->SetMouseTransparent(
true );
443 mpMediaWindow->Show();
447 sal_IntPtr nParentWindowHandle(0);
448 const SystemEnvData* pEnvData = mpMediaWindow->GetSystemData();
451 nParentWindowHandle = mpMediaWindow->GetParentWindowHandle();
453 aAWTRect.X = aAWTRect.Y = 0;
460 pMediaItem = &pMediaObj->getMediaProperties();
466 uno::Any(
reinterpret_cast< sal_IntPtr
>( mpMediaWindow.get() )),
468 uno::Any(
reinterpret_cast< sal_IntPtr
>( pMediaItem ))
471 mxPlayerWindow.set( mxPlayer->createPlayerWindow( aArgs ) );
473 if( mxPlayerWindow.is() )
475 mxPlayerWindow->setVisible(
true );
476 mxPlayerWindow->setEnable(
true );
480 if( !mxPlayerWindow.is() )
484 mpMediaWindow.disposeAndClear();
489 catch( uno::RuntimeException& )
493 catch( uno::Exception& )
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
::basegfx::B2DRectangle maBounds
const Size & GetSizePixel() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
virtual vcl::Window * GetOwnerWindow() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static VclPtr< reference_type > Create(Arg &&... arg)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define ENSURE_OR_RETURN_FALSE(c, m)
#define ENSURE_OR_THROW(c, m)
#define SAL_INFO(area, stream)
double getLength(const B2DPolygon &rCandidate)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
std::shared_ptr< Canvas > CanvasSharedPtr
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
std::shared_ptr< ViewLayer > ViewLayerSharedPtr
std::shared_ptr< UnoView > UnoViewSharedPtr
uno::Reference< drawing::XShape > const mxShape
WinBits const WB_CLIPCHILDREN