1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*70f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*70f497fbSAndrew Rist  * distributed with this work for additional information
6*70f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*70f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*70f497fbSAndrew Rist  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist  *
13*70f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist  * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
17*70f497fbSAndrew Rist  * specific language governing permissions and limitations
18*70f497fbSAndrew Rist  * under the License.
19*70f497fbSAndrew Rist  *
20*70f497fbSAndrew Rist  *************************************************************/
21*70f497fbSAndrew Rist 
22*70f497fbSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // must be first
28cdf0e10cSrcweir #include <canvas/debug.hxx>
29cdf0e10cSrcweir #include <tools/diagnose_ex.h>
30cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <math.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
35cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <vcl/window.hxx>
38cdf0e10cSrcweir #include <vcl/syschild.hxx>
39cdf0e10cSrcweir #include <vcl/salbtype.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
42cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
43cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
44cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
45cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
46cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
47cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx>
48cdf0e10cSrcweir #include <canvas/canvastools.hxx>
49cdf0e10cSrcweir #include <cppcanvas/vclfactory.hxx>
50cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
51cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
52cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <com/sun/star/media/XManager.hpp>
55cdf0e10cSrcweir #include <com/sun/star/media/XPlayer.hpp>
56cdf0e10cSrcweir #include <com/sun/star/media/XPlayerWindow.hpp>
57cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
58cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
59cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
61cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
62cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hdl>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include "viewmediashape.hxx"
65cdf0e10cSrcweir #include "mediashape.hxx"
66cdf0e10cSrcweir #include "tools.hxx"
67cdf0e10cSrcweir #include "unoview.hxx"
68cdf0e10cSrcweir 
69cdf0e10cSrcweir using namespace ::com::sun::star;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir namespace slideshow
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     namespace internal
74cdf0e10cSrcweir     {
ViewMediaShape(const ViewLayerSharedPtr & rViewLayer,const uno::Reference<drawing::XShape> & rxShape,const uno::Reference<uno::XComponentContext> & rxContext)75cdf0e10cSrcweir         ViewMediaShape::ViewMediaShape( const ViewLayerSharedPtr&                       rViewLayer,
76cdf0e10cSrcweir 										const uno::Reference< drawing::XShape >&        rxShape,
77cdf0e10cSrcweir                                         const uno::Reference< uno::XComponentContext >& rxContext ) :
78cdf0e10cSrcweir 			mpViewLayer( rViewLayer ),
79cdf0e10cSrcweir 			mpMediaWindow(),
80cdf0e10cSrcweir 			maWindowOffset( 0, 0 ),
81cdf0e10cSrcweir             maBounds(),
82cdf0e10cSrcweir 			mxShape( rxShape ),
83cdf0e10cSrcweir 			mxPlayer(),
84cdf0e10cSrcweir 			mxPlayerWindow(),
85cdf0e10cSrcweir             mxComponentContext( rxContext ),
86cdf0e10cSrcweir             mbIsSoundEnabled(true)
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             ENSURE_OR_THROW( mxShape.is(), "ViewMediaShape::ViewMediaShape(): Invalid Shape" );
89cdf0e10cSrcweir             ENSURE_OR_THROW( mpViewLayer, "ViewMediaShape::ViewMediaShape(): Invalid View" );
90cdf0e10cSrcweir             ENSURE_OR_THROW( mpViewLayer->getCanvas(), "ViewMediaShape::ViewMediaShape(): Invalid ViewLayer canvas" );
91cdf0e10cSrcweir             ENSURE_OR_THROW( mxComponentContext.is(), "ViewMediaShape::ViewMediaShape(): Invalid component context" );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir             UnoViewSharedPtr pUnoView (::boost::dynamic_pointer_cast<UnoView>(rViewLayer));
94cdf0e10cSrcweir             if (pUnoView)
95cdf0e10cSrcweir             {
96cdf0e10cSrcweir                 mbIsSoundEnabled = pUnoView->isSoundEnabled();
97cdf0e10cSrcweir             }
98cdf0e10cSrcweir         }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 		// ---------------------------------------------------------------------
101cdf0e10cSrcweir 
~ViewMediaShape()102cdf0e10cSrcweir 		ViewMediaShape::~ViewMediaShape()
103cdf0e10cSrcweir 		{
104cdf0e10cSrcweir             try
105cdf0e10cSrcweir             {
106cdf0e10cSrcweir                 endMedia();
107cdf0e10cSrcweir             }
108cdf0e10cSrcweir             catch (uno::Exception &)
109cdf0e10cSrcweir             {
110cdf0e10cSrcweir                 OSL_ENSURE( false, rtl::OUStringToOString(
111cdf0e10cSrcweir                                 comphelper::anyToString(
112cdf0e10cSrcweir                                     cppu::getCaughtException() ),
113cdf0e10cSrcweir                                 RTL_TEXTENCODING_UTF8 ).getStr() );
114cdf0e10cSrcweir             }
115cdf0e10cSrcweir 		}
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		// ---------------------------------------------------------------------
118cdf0e10cSrcweir 
getViewLayer() const119cdf0e10cSrcweir         ViewLayerSharedPtr ViewMediaShape::getViewLayer() const
120cdf0e10cSrcweir         {
121cdf0e10cSrcweir             return mpViewLayer;
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 		// ---------------------------------------------------------------------
125cdf0e10cSrcweir 
startMedia()126cdf0e10cSrcweir         bool ViewMediaShape::startMedia()
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             if( !mxPlayer.is() )
129cdf0e10cSrcweir 			    implInitialize( maBounds );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir             if( mxPlayer.is() && ( mxPlayer->getDuration() > 0.0 ) )
132cdf0e10cSrcweir 				mxPlayer->start();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 			return true;
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		// ---------------------------------------------------------------------
138cdf0e10cSrcweir 
endMedia()139cdf0e10cSrcweir         void ViewMediaShape::endMedia()
140cdf0e10cSrcweir         {
141cdf0e10cSrcweir 			// shutdown player window
142cdf0e10cSrcweir 			if( mxPlayerWindow.is() )
143cdf0e10cSrcweir 			{
144cdf0e10cSrcweir 				uno::Reference< lang::XComponent > xComponent( mxPlayerWindow, uno::UNO_QUERY );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 				if( xComponent.is() )
147cdf0e10cSrcweir 					xComponent->dispose();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 				mxPlayerWindow.clear();
150cdf0e10cSrcweir 			}
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             mpMediaWindow = ::std::auto_ptr< SystemChildWindow >();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 			// shutdown player
155cdf0e10cSrcweir 			if( mxPlayer.is() )
156cdf0e10cSrcweir 			{
157cdf0e10cSrcweir 				mxPlayer->stop();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 				uno::Reference< lang::XComponent > xComponent( mxPlayer, uno::UNO_QUERY );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 				if( xComponent.is() )
162cdf0e10cSrcweir 					xComponent->dispose();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 				mxPlayer.clear();
165cdf0e10cSrcweir 			}
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 		// ---------------------------------------------------------------------
169cdf0e10cSrcweir 
pauseMedia()170cdf0e10cSrcweir         void ViewMediaShape::pauseMedia()
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             if( mxPlayer.is() && ( mxPlayer->getDuration() > 0.0 ) )
173cdf0e10cSrcweir 				mxPlayer->stop();
174cdf0e10cSrcweir 		}
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		// ---------------------------------------------------------------------
177cdf0e10cSrcweir 
setMediaTime(double fTime)178cdf0e10cSrcweir         void ViewMediaShape::setMediaTime(double fTime)
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir             if( mxPlayer.is() && ( mxPlayer->getDuration() > 0.0 ) )
181cdf0e10cSrcweir 				mxPlayer->setMediaTime(fTime);
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 		// ---------------------------------------------------------------------
185cdf0e10cSrcweir 
render(const::basegfx::B2DRectangle & rBounds) const186cdf0e10cSrcweir         bool ViewMediaShape::render( const ::basegfx::B2DRectangle&	rBounds ) const
187cdf0e10cSrcweir         {
188cdf0e10cSrcweir             ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();;
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             if( !pCanvas )
191cdf0e10cSrcweir                 return false;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 			if( !mpMediaWindow.get() && !mxPlayerWindow.is() )
194cdf0e10cSrcweir 			{
195cdf0e10cSrcweir                 // fill the shape background with black
196cdf0e10cSrcweir                 fillRect( pCanvas,
197cdf0e10cSrcweir                           rBounds,
198cdf0e10cSrcweir                           0x000000FFU );
199cdf0e10cSrcweir 			}
200cdf0e10cSrcweir 
201cdf0e10cSrcweir             return true;
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir 
resize(const::basegfx::B2DRectangle & rNewBounds) const204cdf0e10cSrcweir         bool ViewMediaShape::resize( const ::basegfx::B2DRectangle&	rNewBounds ) const
205cdf0e10cSrcweir         {
206cdf0e10cSrcweir             maBounds = rNewBounds;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir             ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir             if( !pCanvas )
211cdf0e10cSrcweir                 return false;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 			if( !mxPlayerWindow.is() )
214cdf0e10cSrcweir                 return true;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xPropSet( pCanvas->getUNOCanvas()->getDevice(),
217cdf0e10cSrcweir                                                             uno::UNO_QUERY );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir             uno::Reference< awt::XWindow > xParentWindow;
220cdf0e10cSrcweir             if( xPropSet.is() &&
221cdf0e10cSrcweir                 getPropertyValue( xParentWindow,
222cdf0e10cSrcweir                                   xPropSet,
223cdf0e10cSrcweir                                   ::rtl::OUString::createFromAscii( "Window" )) )
224cdf0e10cSrcweir             {
225cdf0e10cSrcweir                 const awt::Rectangle aRect( xParentWindow->getPosSize() );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir                 maWindowOffset.X = aRect.X;
228cdf0e10cSrcweir                 maWindowOffset.Y = aRect.Y;
229cdf0e10cSrcweir             }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir             ::basegfx::B2DRange aTmpRange;
232cdf0e10cSrcweir             ::canvas::tools::calcTransformedRectBounds( aTmpRange,
233cdf0e10cSrcweir                                                         rNewBounds,
234cdf0e10cSrcweir                                                         mpViewLayer->getTransformation() );
235cdf0e10cSrcweir             const ::basegfx::B2IRange& rRangePix(
236cdf0e10cSrcweir                 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
237cdf0e10cSrcweir 
238cdf0e10cSrcweir             mxPlayerWindow->setEnable( !rRangePix.isEmpty() );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir             if( rRangePix.isEmpty() )
241cdf0e10cSrcweir                 return true;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir             const Point aPosPixel( rRangePix.getMinX() + maWindowOffset.X,
244cdf0e10cSrcweir                                    rRangePix.getMinY() + maWindowOffset.Y );
245cdf0e10cSrcweir             const Size	aSizePixel( rRangePix.getMaxX() - rRangePix.getMinX(),
246cdf0e10cSrcweir                                     rRangePix.getMaxY() - rRangePix.getMinY() );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             if( mpMediaWindow.get() )
249cdf0e10cSrcweir             {
250cdf0e10cSrcweir                 mpMediaWindow->SetPosSizePixel( aPosPixel, aSizePixel );
251cdf0e10cSrcweir                 mxPlayerWindow->setPosSize( 0, 0,
252cdf0e10cSrcweir                                             aSizePixel.Width(), aSizePixel.Height(),
253cdf0e10cSrcweir                                             0 );
254cdf0e10cSrcweir             }
255cdf0e10cSrcweir             else
256cdf0e10cSrcweir             {
257cdf0e10cSrcweir                 mxPlayerWindow->setPosSize( aPosPixel.X(), aPosPixel.Y(),
258cdf0e10cSrcweir                                             aSizePixel.Width(), aSizePixel.Height(),
259cdf0e10cSrcweir                                             0 );
260cdf0e10cSrcweir             }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 			return true;
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 		// ---------------------------------------------------------------------
266cdf0e10cSrcweir 
implInitialize(const::basegfx::B2DRectangle & rBounds)267cdf0e10cSrcweir 		bool ViewMediaShape::implInitialize( const ::basegfx::B2DRectangle& rBounds )
268cdf0e10cSrcweir 		{
269cdf0e10cSrcweir 			if( !mxPlayer.is() && mxShape.is() )
270cdf0e10cSrcweir 			{
271cdf0e10cSrcweir 				ENSURE_OR_RETURN_FALSE( mpViewLayer->getCanvas(),
272cdf0e10cSrcweir                                    "ViewMediaShape::update(): Invalid layer canvas" );
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 				uno::Reference< rendering::XCanvas > xCanvas( mpViewLayer->getCanvas()->getUNOCanvas() );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 				if( xCanvas.is() )
277cdf0e10cSrcweir 				{
278cdf0e10cSrcweir 					uno::Reference< beans::XPropertySet >	xPropSet;
279cdf0e10cSrcweir 					::rtl::OUString 						aURL;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 					try
282cdf0e10cSrcweir 					{
283cdf0e10cSrcweir 						xPropSet.set( mxShape, uno::UNO_QUERY );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 						// create Player
286cdf0e10cSrcweir 						if( xPropSet.is() &&
287cdf0e10cSrcweir 							( xPropSet->getPropertyValue(
288cdf0e10cSrcweir                                   ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaURL" ) ) ) >>=aURL ) )
289cdf0e10cSrcweir 						{
290cdf0e10cSrcweir 							implInitializeMediaPlayer( aURL );
291cdf0e10cSrcweir 						}
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 						// create visible object
294cdf0e10cSrcweir 						uno::Sequence< uno::Any > aDeviceParams;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 						if( ::canvas::tools::getDeviceInfo( xCanvas, aDeviceParams ).getLength() > 1 )
297cdf0e10cSrcweir 						{
298cdf0e10cSrcweir 							::rtl::OUString aImplName;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 							aDeviceParams[ 0 ] >>= aImplName;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 							if( aImplName.endsWithIgnoreAsciiCaseAsciiL(
303cdf0e10cSrcweir                                     RTL_CONSTASCII_STRINGPARAM("VCL") ))
304cdf0e10cSrcweir                             {
305cdf0e10cSrcweir 								implInitializeVCLBasedPlayerWindow( rBounds, aDeviceParams );
306cdf0e10cSrcweir                             }
307cdf0e10cSrcweir 							else if( aImplName.endsWithIgnoreAsciiCaseAsciiL(
308cdf0e10cSrcweir                                          RTL_CONSTASCII_STRINGPARAM("DX")) ||
309cdf0e10cSrcweir 									 aImplName.endsWithIgnoreAsciiCaseAsciiL(
310cdf0e10cSrcweir                                          RTL_CONSTASCII_STRINGPARAM("DX9")))
311cdf0e10cSrcweir                             {
312cdf0e10cSrcweir 								implInitializeDXBasedPlayerWindow( rBounds, aDeviceParams );
313cdf0e10cSrcweir                             }
314cdf0e10cSrcweir 						}
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 						// set player properties
317cdf0e10cSrcweir 						implSetMediaProperties( xPropSet );
318cdf0e10cSrcweir 					}
319cdf0e10cSrcweir                     catch( uno::RuntimeException& )
320cdf0e10cSrcweir                     {
321cdf0e10cSrcweir                         throw;
322cdf0e10cSrcweir                     }
323cdf0e10cSrcweir 					catch( uno::Exception& )
324cdf0e10cSrcweir 					{
325cdf0e10cSrcweir                         OSL_ENSURE( false,
326cdf0e10cSrcweir                                     rtl::OUStringToOString(
327cdf0e10cSrcweir                                         comphelper::anyToString( cppu::getCaughtException() ),
328cdf0e10cSrcweir                                         RTL_TEXTENCODING_UTF8 ).getStr() );
329cdf0e10cSrcweir 					}
330cdf0e10cSrcweir 				}
331cdf0e10cSrcweir 			}
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 			return mxPlayer.is() || mxPlayerWindow.is();
334cdf0e10cSrcweir 	    }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 		// ---------------------------------------------------------------------
337cdf0e10cSrcweir 
implSetMediaProperties(const uno::Reference<beans::XPropertySet> & rxProps)338cdf0e10cSrcweir 		void ViewMediaShape::implSetMediaProperties( const uno::Reference< beans::XPropertySet >& rxProps )
339cdf0e10cSrcweir 		{
340cdf0e10cSrcweir 			if( mxPlayer.is() )
341cdf0e10cSrcweir 			{
342cdf0e10cSrcweir 				mxPlayer->setMediaTime( 0.0 );
343cdf0e10cSrcweir 
344cdf0e10cSrcweir                 if( rxProps.is() )
345cdf0e10cSrcweir                 {
346cdf0e10cSrcweir 					sal_Bool bLoop( false );
347cdf0e10cSrcweir 					getPropertyValue( bLoop,
348cdf0e10cSrcweir                                       rxProps,
349cdf0e10cSrcweir                                       ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Loop" )));
350cdf0e10cSrcweir 					mxPlayer->setPlaybackLoop( bLoop );
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 					sal_Bool bMute( false );
353cdf0e10cSrcweir 					getPropertyValue( bMute,
354cdf0e10cSrcweir                                       rxProps,
355cdf0e10cSrcweir                                       ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Mute" )));
356cdf0e10cSrcweir 					mxPlayer->setMute( bMute || !mbIsSoundEnabled);
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 					sal_Int16 nVolumeDB(0);
359cdf0e10cSrcweir 					getPropertyValue( nVolumeDB,
360cdf0e10cSrcweir                                       rxProps,
361cdf0e10cSrcweir                                       ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VolumeDB" )));
362cdf0e10cSrcweir 					mxPlayer->setVolumeDB( nVolumeDB );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir                     if( mxPlayerWindow.is() )
365cdf0e10cSrcweir                     {
366cdf0e10cSrcweir 						media::ZoomLevel eZoom(media::ZoomLevel_FIT_TO_WINDOW);
367cdf0e10cSrcweir 						getPropertyValue( eZoom,
368cdf0e10cSrcweir                                           rxProps,
369cdf0e10cSrcweir                                           ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Zoom" )));
370cdf0e10cSrcweir 						mxPlayerWindow->setZoomLevel( eZoom );
371cdf0e10cSrcweir 					}
372cdf0e10cSrcweir 				}
373cdf0e10cSrcweir 			}
374cdf0e10cSrcweir 		}
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 		// ---------------------------------------------------------------------
377cdf0e10cSrcweir 
implInitializeMediaPlayer(const::rtl::OUString & rMediaURL)378cdf0e10cSrcweir 		void ViewMediaShape::implInitializeMediaPlayer( const ::rtl::OUString& rMediaURL )
379cdf0e10cSrcweir 		{
380cdf0e10cSrcweir 			if( !mxPlayer.is() )
381cdf0e10cSrcweir 			{
382cdf0e10cSrcweir 				try
383cdf0e10cSrcweir 				{
384cdf0e10cSrcweir 					if( rMediaURL.getLength() )
385cdf0e10cSrcweir 					{
386cdf0e10cSrcweir 						mxPlayer.set( avmedia::MediaWindow::createPlayer( rMediaURL ),
387cdf0e10cSrcweir                             uno::UNO_QUERY );
388cdf0e10cSrcweir 					}
389cdf0e10cSrcweir 				}
390cdf0e10cSrcweir                 catch( uno::RuntimeException& )
391cdf0e10cSrcweir                 {
392cdf0e10cSrcweir                     throw;
393cdf0e10cSrcweir                 }
394cdf0e10cSrcweir 				catch( const uno::Exception& )
395cdf0e10cSrcweir 				{
396cdf0e10cSrcweir                     throw lang::NoSupportException(
397cdf0e10cSrcweir                         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
398cdf0e10cSrcweir                                            "No video support for ") ) + rMediaURL,
399cdf0e10cSrcweir                         uno::Reference<uno::XInterface>() );
400cdf0e10cSrcweir 				}
401cdf0e10cSrcweir 			}
402cdf0e10cSrcweir 		}
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 		// ---------------------------------------------------------------------
405cdf0e10cSrcweir 
implInitializeVCLBasedPlayerWindow(const::basegfx::B2DRectangle & rBounds,const uno::Sequence<uno::Any> & rVCLDeviceParams)406cdf0e10cSrcweir 		bool ViewMediaShape::implInitializeVCLBasedPlayerWindow( const ::basegfx::B2DRectangle&   rBounds,
407cdf0e10cSrcweir 																 const uno::Sequence< uno::Any >& rVCLDeviceParams)
408cdf0e10cSrcweir 		{
409cdf0e10cSrcweir 			if( !mpMediaWindow.get() && !rBounds.isEmpty() )
410cdf0e10cSrcweir 			{
411cdf0e10cSrcweir 				try
412cdf0e10cSrcweir 				{
413cdf0e10cSrcweir 					sal_Int64 aVal=0;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 					rVCLDeviceParams[ 1 ] >>= aVal;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 					Window* pWindow = reinterpret_cast< Window* >( aVal );
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 					if( pWindow )
420cdf0e10cSrcweir 					{
421cdf0e10cSrcweir 						::basegfx::B2DRange aTmpRange;
422cdf0e10cSrcweir 						::canvas::tools::calcTransformedRectBounds( aTmpRange,
423cdf0e10cSrcweir                                                                     rBounds,
424cdf0e10cSrcweir 																	mpViewLayer->getTransformation() );
425cdf0e10cSrcweir                         const ::basegfx::B2IRange& rRangePix(
426cdf0e10cSrcweir                             ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 						if( !rRangePix.isEmpty() )
429cdf0e10cSrcweir 						{
430cdf0e10cSrcweir 							uno::Sequence< uno::Any > 	aArgs( 3 );
431cdf0e10cSrcweir 							awt::Rectangle				aAWTRect( rRangePix.getMinX(),
432cdf0e10cSrcweir 																  rRangePix.getMinY(),
433cdf0e10cSrcweir 														  		  rRangePix.getMaxX() - rRangePix.getMinX(),
434cdf0e10cSrcweir 														  		  rRangePix.getMaxY() - rRangePix.getMinY() );
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 							mpMediaWindow = ::std::auto_ptr< SystemChildWindow >( new
437cdf0e10cSrcweir                                                 SystemChildWindow( pWindow, WB_CLIPCHILDREN ) );
438cdf0e10cSrcweir 							mpMediaWindow->SetBackground( Color( COL_BLACK ) );
439cdf0e10cSrcweir 							mpMediaWindow->SetPosSizePixel( Point( aAWTRect.X, aAWTRect.Y ),
440cdf0e10cSrcweir                                                            Size( aAWTRect.Width, aAWTRect.Height ) );
441cdf0e10cSrcweir 							mpMediaWindow->Show();
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 							if( mxPlayer.is() )
444cdf0e10cSrcweir 							{
445cdf0e10cSrcweir 								aArgs[ 0 ] = uno::makeAny(
446cdf0e10cSrcweir                                     sal::static_int_cast< sal_IntPtr >( mpMediaWindow->GetParentWindowHandle() ) );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 								aAWTRect.X = aAWTRect.Y = 0;
449cdf0e10cSrcweir 								aArgs[ 1 ] = uno::makeAny( aAWTRect );
450cdf0e10cSrcweir 
451cdf0e10cSrcweir                                 aArgs[ 2 ] = uno::makeAny( reinterpret_cast< sal_IntPtr >( mpMediaWindow.get() ) );
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 								mxPlayerWindow.set( mxPlayer->createPlayerWindow( aArgs ) );
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 								if( mxPlayerWindow.is() )
456cdf0e10cSrcweir 								{
457cdf0e10cSrcweir 									mxPlayerWindow->setVisible( true );
458cdf0e10cSrcweir 									mxPlayerWindow->setEnable( true );
459cdf0e10cSrcweir 								}
460cdf0e10cSrcweir 							}
461cdf0e10cSrcweir 						}
462cdf0e10cSrcweir 					}
463cdf0e10cSrcweir 				}
464cdf0e10cSrcweir                 catch( uno::RuntimeException& )
465cdf0e10cSrcweir                 {
466cdf0e10cSrcweir                     throw;
467cdf0e10cSrcweir                 }
468cdf0e10cSrcweir 				catch( uno::Exception& )
469cdf0e10cSrcweir 				{
470cdf0e10cSrcweir                     OSL_ENSURE( false,
471cdf0e10cSrcweir                                 rtl::OUStringToOString(
472cdf0e10cSrcweir                                     comphelper::anyToString( cppu::getCaughtException() ),
473cdf0e10cSrcweir                                     RTL_TEXTENCODING_UTF8 ).getStr() );
474cdf0e10cSrcweir 				}
475cdf0e10cSrcweir 			}
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 			return mxPlayerWindow.is();
478cdf0e10cSrcweir 		}
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 		// ---------------------------------------------------------------------
481cdf0e10cSrcweir 
implInitializeDXBasedPlayerWindow(const::basegfx::B2DRectangle & rBounds,const uno::Sequence<uno::Any> & rDXDeviceParams)482cdf0e10cSrcweir 		bool ViewMediaShape::implInitializeDXBasedPlayerWindow( const ::basegfx::B2DRectangle&   rBounds,
483cdf0e10cSrcweir 																const uno::Sequence< uno::Any >& rDXDeviceParams )
484cdf0e10cSrcweir 		{
485cdf0e10cSrcweir             if( !mxPlayerWindow.is() )
486cdf0e10cSrcweir 	    	{
487cdf0e10cSrcweir         		try
488cdf0e10cSrcweir 		        {
489cdf0e10cSrcweir 				    if( rDXDeviceParams.getLength() == 2 )
490cdf0e10cSrcweir 				    {
491cdf0e10cSrcweir 					    sal_Int64 aWNDVal=0;
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 					    rDXDeviceParams[ 1 ] >>= aWNDVal;
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 					    if( aWNDVal )
496cdf0e10cSrcweir 					    {
497cdf0e10cSrcweir 						    ::basegfx::B2DRange aTmpRange;
498cdf0e10cSrcweir 						    ::canvas::tools::calcTransformedRectBounds( aTmpRange,
499cdf0e10cSrcweir                                                                         rBounds,
500cdf0e10cSrcweir 																	    mpViewLayer->getTransformation() );
501cdf0e10cSrcweir                             const ::basegfx::B2IRange& rRangePix(
502cdf0e10cSrcweir                                 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 						    if( !rRangePix.isEmpty() )
505cdf0e10cSrcweir 						    {
506cdf0e10cSrcweir 							    uno::Sequence< uno::Any > 	aArgs( 2 );
507cdf0e10cSrcweir 							    awt::Rectangle				aAWTRect( rRangePix.getMinX() + maWindowOffset.X,
508cdf0e10cSrcweir                                                                       rRangePix.getMinY() + maWindowOffset.Y,
509cdf0e10cSrcweir                                                                       rRangePix.getMaxX() - rRangePix.getMinX(),
510cdf0e10cSrcweir                                                                       rRangePix.getMaxY() - rRangePix.getMinY() );
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 							    if( mxPlayer.is() )
513cdf0e10cSrcweir 							    {
514cdf0e10cSrcweir 								    aArgs[ 0 ] = uno::makeAny( sal::static_int_cast< sal_Int32 >( aWNDVal) );
515cdf0e10cSrcweir 								    aArgs[ 1 ] = uno::makeAny( aAWTRect );
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 								    mxPlayerWindow.set( mxPlayer->createPlayerWindow( aArgs ) );
518cdf0e10cSrcweir 							    }
519cdf0e10cSrcweir 						    }
520cdf0e10cSrcweir 					    }
521cdf0e10cSrcweir 				    }
522cdf0e10cSrcweir     			}
523cdf0e10cSrcweir                 catch( uno::RuntimeException& )
524cdf0e10cSrcweir                 {
525cdf0e10cSrcweir                     throw;
526cdf0e10cSrcweir                 }
527cdf0e10cSrcweir 	    	    catch( uno::Exception& )
528cdf0e10cSrcweir 		        {
529cdf0e10cSrcweir                     OSL_ENSURE( false,
530cdf0e10cSrcweir                                 rtl::OUStringToOString(
531cdf0e10cSrcweir                                     comphelper::anyToString( cppu::getCaughtException() ),
532cdf0e10cSrcweir                                     RTL_TEXTENCODING_UTF8 ).getStr() );
533cdf0e10cSrcweir 		        }
534cdf0e10cSrcweir 		    }
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 			return mxPlayerWindow.is();
537cdf0e10cSrcweir 		}
538cdf0e10cSrcweir 	}
539cdf0e10cSrcweir }
540