1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // must be first 32*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 33*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 34*cdf0e10cSrcweir #include <canvas/debug.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <comphelper/anytostring.hxx> 37*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 40*cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx> 41*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <cppcanvas/spritecanvas.hxx> 44*cdf0e10cSrcweir #include <canvas/canvastools.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/awt/WindowDescriptor.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/awt/XToolkit.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/awt/VclWindowPeerAttribute.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/frame/XSynchronousFrameLoader.hpp> 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir #include "viewappletshape.hxx" 64*cdf0e10cSrcweir #include "tools.hxx" 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir using namespace ::com::sun::star; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir namespace slideshow 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir namespace internal 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir ViewAppletShape::ViewAppletShape( const ViewLayerSharedPtr& rViewLayer, 74*cdf0e10cSrcweir const uno::Reference< drawing::XShape >& rxShape, 75*cdf0e10cSrcweir const ::rtl::OUString& rServiceName, 76*cdf0e10cSrcweir const char** pPropCopyTable, 77*cdf0e10cSrcweir sal_Size nNumPropEntries, 78*cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& rxContext ) : 79*cdf0e10cSrcweir mpViewLayer( rViewLayer ), 80*cdf0e10cSrcweir mxViewer(), 81*cdf0e10cSrcweir mxFrame(), 82*cdf0e10cSrcweir mxComponentContext( rxContext ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir ENSURE_OR_THROW( rxShape.is(), "ViewAppletShape::ViewAppletShape(): Invalid Shape" ); 85*cdf0e10cSrcweir ENSURE_OR_THROW( mpViewLayer, "ViewAppletShape::ViewAppletShape(): Invalid View" ); 86*cdf0e10cSrcweir ENSURE_OR_THROW( mpViewLayer->getCanvas(), "ViewAppletShape::ViewAppletShape(): Invalid ViewLayer canvas" ); 87*cdf0e10cSrcweir ENSURE_OR_THROW( mxComponentContext.is(), "ViewAppletShape::ViewAppletShape(): Invalid component context" ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir uno::Reference<lang::XMultiComponentFactory> xFactory( 90*cdf0e10cSrcweir mxComponentContext->getServiceManager(), 91*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir mxViewer.set( xFactory->createInstanceWithContext( rServiceName, 94*cdf0e10cSrcweir mxComponentContext), 95*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xShapePropSet( rxShape, 98*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 99*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > mxViewerPropSet( mxViewer, 100*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // copy shape properties to applet viewer 103*cdf0e10cSrcweir ::rtl::OUString aPropName; 104*cdf0e10cSrcweir for( sal_Size i=0; i<nNumPropEntries; ++i ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir aPropName = ::rtl::OUString::createFromAscii( pPropCopyTable[i] ); 107*cdf0e10cSrcweir mxViewerPropSet->setPropertyValue( aPropName, 108*cdf0e10cSrcweir xShapePropSet->getPropertyValue( 109*cdf0e10cSrcweir aPropName )); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // --------------------------------------------------------------------- 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir ViewAppletShape::~ViewAppletShape() 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir try 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir endApplet(); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir catch (uno::Exception &) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir OSL_ENSURE( false, rtl::OUStringToOString( 124*cdf0e10cSrcweir comphelper::anyToString( 125*cdf0e10cSrcweir cppu::getCaughtException() ), 126*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // --------------------------------------------------------------------- 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir ViewLayerSharedPtr ViewAppletShape::getViewLayer() const 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir return mpViewLayer; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // --------------------------------------------------------------------- 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir bool ViewAppletShape::startApplet( const ::basegfx::B2DRectangle& rBounds ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir ENSURE_OR_RETURN_FALSE( mpViewLayer && mpViewLayer->getCanvas() && mpViewLayer->getCanvas()->getUNOCanvas().is(), 142*cdf0e10cSrcweir "ViewAppletShape::startApplet(): Invalid or disposed view" ); 143*cdf0e10cSrcweir try 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas(); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( pCanvas->getUNOCanvas()->getDevice(), 148*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xParentWindow( 151*cdf0e10cSrcweir xPropSet->getPropertyValue( 152*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Window" )), 153*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir uno::Reference<lang::XMultiComponentFactory> xFactory( 156*cdf0e10cSrcweir mxComponentContext->getServiceManager() ); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir if( xFactory.is() ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir // create an awt window to contain the applet 161*cdf0e10cSrcweir // ========================================== 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir uno::Reference< awt::XToolkit > xToolkit( 164*cdf0e10cSrcweir xFactory->createInstanceWithContext( 165*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.awt.Toolkit" ), 166*cdf0e10cSrcweir mxComponentContext ), 167*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_SIMPLE, 170*cdf0e10cSrcweir ::rtl::OUString(), 171*cdf0e10cSrcweir uno::Reference< awt::XWindowPeer >(xParentWindow, 172*cdf0e10cSrcweir uno::UNO_QUERY_THROW), 173*cdf0e10cSrcweir 0, 174*cdf0e10cSrcweir awt::Rectangle(), 175*cdf0e10cSrcweir awt::WindowAttribute::SHOW 176*cdf0e10cSrcweir | awt::VclWindowPeerAttribute::CLIPCHILDREN ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir uno::Reference< awt::XWindowPeer > xNewWinPeer( 179*cdf0e10cSrcweir xToolkit->createWindow( aOwnWinDescriptor )); 180*cdf0e10cSrcweir uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, 181*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // create a frame, and load the applet into it 185*cdf0e10cSrcweir // =========================================== 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir mxFrame.set( 188*cdf0e10cSrcweir xFactory->createInstanceWithContext( 189*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.frame.Frame" ), 190*cdf0e10cSrcweir mxComponentContext ), 191*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir mxFrame->initialize( xOwnWindow ); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir uno::Reference < frame::XSynchronousFrameLoader > xLoader( mxViewer, 196*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 197*cdf0e10cSrcweir xLoader->load( uno::Sequence < beans::PropertyValue >(), 198*cdf0e10cSrcweir mxFrame ); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // resize surrounding window and applet to current shape size 202*cdf0e10cSrcweir // ========================================================== 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir ::basegfx::B2DRange aTmpRange; 205*cdf0e10cSrcweir ::canvas::tools::calcTransformedRectBounds( aTmpRange, 206*cdf0e10cSrcweir rBounds, 207*cdf0e10cSrcweir mpViewLayer->getTransformation() ); 208*cdf0e10cSrcweir const ::basegfx::B2IRange& rPixelBounds( 209*cdf0e10cSrcweir ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange )); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir uno::Reference< awt::XWindow > xSurroundingWindow( mxFrame->getContainerWindow() ); 212*cdf0e10cSrcweir if( xSurroundingWindow.is() ) 213*cdf0e10cSrcweir xSurroundingWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()), 214*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getMinY()), 215*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getWidth()), 216*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getHeight()), 217*cdf0e10cSrcweir awt::PosSize::POSSIZE ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() ); 220*cdf0e10cSrcweir if( xAppletWindow.is() ) 221*cdf0e10cSrcweir xAppletWindow->setPosSize( 0, 0, 222*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getWidth()), 223*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getHeight()), 224*cdf0e10cSrcweir awt::PosSize::POSSIZE ); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir catch (uno::Exception &) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir return false; 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir return true; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // --------------------------------------------------------------------- 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir void ViewAppletShape::endApplet() 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir uno::Reference<util::XCloseable> xCloseable( 240*cdf0e10cSrcweir mxFrame, 241*cdf0e10cSrcweir uno::UNO_QUERY ); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir if( xCloseable.is() ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir xCloseable->close( sal_True ); 246*cdf0e10cSrcweir mxFrame.clear(); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir // --------------------------------------------------------------------- 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir bool ViewAppletShape::render( const ::basegfx::B2DRectangle& rBounds ) const 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas(); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir if( !pCanvas ) 257*cdf0e10cSrcweir return false; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if( !mxFrame.is() ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir // fill the shape background with black 262*cdf0e10cSrcweir fillRect( pCanvas, 263*cdf0e10cSrcweir rBounds, 264*cdf0e10cSrcweir 0xFFFFFFFFU ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir return true; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir bool ViewAppletShape::resize( const ::basegfx::B2DRectangle& rBounds ) const 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir if( !mxFrame.is() ) 273*cdf0e10cSrcweir return false; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir ::basegfx::B2DRange aTmpRange; 276*cdf0e10cSrcweir ::canvas::tools::calcTransformedRectBounds( aTmpRange, 277*cdf0e10cSrcweir rBounds, 278*cdf0e10cSrcweir mpViewLayer->getTransformation() ); 279*cdf0e10cSrcweir const ::basegfx::B2IRange& rPixelBounds( 280*cdf0e10cSrcweir ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange )); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir uno::Reference< awt::XWindow > xFrameWindow( mxFrame->getContainerWindow() ); 283*cdf0e10cSrcweir if( xFrameWindow.is() ) 284*cdf0e10cSrcweir xFrameWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()), 285*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getMinY()), 286*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getWidth()), 287*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getHeight()), 288*cdf0e10cSrcweir awt::PosSize::POSSIZE ); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() ); 291*cdf0e10cSrcweir if( xAppletWindow.is() ) 292*cdf0e10cSrcweir xAppletWindow->setPosSize( 0, 0, 293*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getWidth()), 294*cdf0e10cSrcweir static_cast<sal_Int32>(rPixelBounds.getHeight()), 295*cdf0e10cSrcweir awt::PosSize::POSSIZE ); 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir return true; 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir } 301