LCOV - code coverage report
Current view: top level - slideshow/source/engine/shapes - viewappletshape.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 98 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : // must be first
      22             : #include <canvas/verbosetrace.hxx>
      23             : #include <tools/diagnose_ex.h>
      24             : #include <canvas/debug.hxx>
      25             : 
      26             : #include <comphelper/anytostring.hxx>
      27             : #include <cppuhelper/exc_hlp.hxx>
      28             : 
      29             : #include <basegfx/matrix/b2dhommatrix.hxx>
      30             : #include <basegfx/range/b2irange.hxx>
      31             : #include <basegfx/tools/canvastools.hxx>
      32             : 
      33             : #include <cppcanvas/spritecanvas.hxx>
      34             : #include <canvas/canvastools.hxx>
      35             : 
      36             : #include <com/sun/star/uno/XComponentContext.hpp>
      37             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      38             : #include <com/sun/star/rendering/XCanvas.hpp>
      39             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      40             : #include <com/sun/star/beans/XPropertySet.hpp>
      41             : #include <com/sun/star/beans/PropertyValue.hpp>
      42             : #include <com/sun/star/util/XCloseable.hpp>
      43             : #include <com/sun/star/awt/WindowDescriptor.hpp>
      44             : #include <com/sun/star/awt/Toolkit.hpp>
      45             : #include <com/sun/star/awt/XWindow2.hpp>
      46             : #include <com/sun/star/awt/XWindowPeer.hpp>
      47             : #include <com/sun/star/awt/WindowAttribute.hpp>
      48             : #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
      49             : #include <com/sun/star/awt/PosSize.hpp>
      50             : #include <com/sun/star/frame/Frame.hpp>
      51             : #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
      52             : 
      53             : #include "viewappletshape.hxx"
      54             : #include "tools.hxx"
      55             : 
      56             : 
      57             : using namespace ::com::sun::star;
      58             : 
      59             : namespace slideshow
      60             : {
      61             :     namespace internal
      62             :     {
      63           0 :         ViewAppletShape::ViewAppletShape( const ViewLayerSharedPtr&                       rViewLayer,
      64             :                                           const uno::Reference< drawing::XShape >&        rxShape,
      65             :                                           const OUString&                          rServiceName,
      66             :                                           const char**                                    pPropCopyTable,
      67             :                                           sal_Size                                        nNumPropEntries,
      68             :                                           const uno::Reference< uno::XComponentContext >& rxContext ) :
      69             :             mpViewLayer( rViewLayer ),
      70             :             mxViewer(),
      71             :             mxFrame(),
      72           0 :             mxComponentContext( rxContext )
      73             :         {
      74           0 :             ENSURE_OR_THROW( rxShape.is(), "ViewAppletShape::ViewAppletShape(): Invalid Shape" );
      75           0 :             ENSURE_OR_THROW( mpViewLayer, "ViewAppletShape::ViewAppletShape(): Invalid View" );
      76           0 :             ENSURE_OR_THROW( mpViewLayer->getCanvas(), "ViewAppletShape::ViewAppletShape(): Invalid ViewLayer canvas" );
      77           0 :             ENSURE_OR_THROW( mxComponentContext.is(), "ViewAppletShape::ViewAppletShape(): Invalid component context" );
      78             : 
      79             :             uno::Reference<lang::XMultiComponentFactory> xFactory(
      80           0 :                 mxComponentContext->getServiceManager(),
      81           0 :                 uno::UNO_QUERY_THROW );
      82             : 
      83           0 :             mxViewer.set( xFactory->createInstanceWithContext( rServiceName,
      84           0 :                                                                mxComponentContext),
      85           0 :                           uno::UNO_QUERY_THROW );
      86             : 
      87             :             uno::Reference< beans::XPropertySet > xShapePropSet( rxShape,
      88           0 :                                                                  uno::UNO_QUERY_THROW );
      89             :             uno::Reference< beans::XPropertySet > mxViewerPropSet( mxViewer,
      90           0 :                                                                    uno::UNO_QUERY_THROW );
      91             : 
      92             :             // copy shape properties to applet viewer
      93           0 :             OUString aPropName;
      94           0 :             for( sal_Size i=0; i<nNumPropEntries; ++i )
      95             :             {
      96           0 :                 aPropName = OUString::createFromAscii( pPropCopyTable[i] );
      97           0 :                 mxViewerPropSet->setPropertyValue( aPropName,
      98           0 :                                                    xShapePropSet->getPropertyValue(
      99           0 :                                                        aPropName ));
     100           0 :             }
     101           0 :         }
     102             : 
     103             : 
     104             : 
     105           0 :         ViewAppletShape::~ViewAppletShape()
     106             :         {
     107             :             try
     108             :             {
     109           0 :                 endApplet();
     110             :             }
     111           0 :             catch (uno::Exception &)
     112             :             {
     113             :                 OSL_FAIL( OUStringToOString(
     114             :                                 comphelper::anyToString(
     115             :                                     cppu::getCaughtException() ),
     116             :                                 RTL_TEXTENCODING_UTF8 ).getStr() );
     117             :             }
     118           0 :         }
     119             : 
     120             : 
     121             : 
     122           0 :         ViewLayerSharedPtr ViewAppletShape::getViewLayer() const
     123             :         {
     124           0 :             return mpViewLayer;
     125             :         }
     126             : 
     127             : 
     128             : 
     129           0 :         bool ViewAppletShape::startApplet( const ::basegfx::B2DRectangle& rBounds )
     130             :         {
     131           0 :             ENSURE_OR_RETURN_FALSE( mpViewLayer && mpViewLayer->getCanvas() && mpViewLayer->getCanvas()->getUNOCanvas().is(),
     132             :                                "ViewAppletShape::startApplet(): Invalid or disposed view" );
     133             :             try
     134             :             {
     135           0 :                 ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();
     136             : 
     137           0 :                 uno::Reference< beans::XPropertySet > xPropSet( pCanvas->getUNOCanvas()->getDevice(),
     138           0 :                                                                 uno::UNO_QUERY_THROW );
     139             : 
     140             :                 uno::Reference< awt::XWindow2 > xParentWindow(
     141           0 :                     xPropSet->getPropertyValue(
     142           0 :                         OUString("Window" )),
     143           0 :                     uno::UNO_QUERY_THROW );
     144             : 
     145             :                 uno::Reference<lang::XMultiComponentFactory> xFactory(
     146           0 :                     mxComponentContext->getServiceManager() );
     147             : 
     148           0 :                 if( xFactory.is() )
     149             :                 {
     150             :                     // create an awt window to contain the applet
     151             :                     // ==========================================
     152             : 
     153           0 :                     uno::Reference< awt::XToolkit2 > xToolkit = awt::Toolkit::create(mxComponentContext);
     154             : 
     155             :                     awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_SIMPLE,
     156             :                                                              OUString(),
     157             :                                                              uno::Reference< awt::XWindowPeer >(xParentWindow,
     158             :                                                                                                 uno::UNO_QUERY_THROW),
     159             :                                                              0,
     160             :                                                              awt::Rectangle(),
     161             :                                                              awt::WindowAttribute::SHOW
     162           0 :                                                              | awt::VclWindowPeerAttribute::CLIPCHILDREN );
     163             : 
     164             :                     uno::Reference< awt::XWindowPeer > xNewWinPeer(
     165           0 :                         xToolkit->createWindow( aOwnWinDescriptor ));
     166             :                     uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer,
     167           0 :                                                                uno::UNO_QUERY_THROW );
     168             : 
     169             : 
     170             :                     // create a frame, and load the applet into it
     171             :                     // ===========================================
     172             : 
     173           0 :                     mxFrame = frame::Frame::create( mxComponentContext );
     174           0 :                     mxFrame->initialize( xOwnWindow );
     175             : 
     176             :                     uno::Reference < frame::XSynchronousFrameLoader > xLoader( mxViewer,
     177           0 :                                                                                uno::UNO_QUERY_THROW );
     178           0 :                     xLoader->load( uno::Sequence < beans::PropertyValue >(),
     179           0 :                                    uno::Reference<frame::XFrame>(mxFrame, uno::UNO_QUERY_THROW) );
     180             : 
     181             : 
     182             :                     // resize surrounding window and applet to current shape size
     183             :                     // ==========================================================
     184             : 
     185           0 :                     ::basegfx::B2DRange aTmpRange;
     186             :                     ::canvas::tools::calcTransformedRectBounds( aTmpRange,
     187             :                                                                 rBounds,
     188           0 :                                                                 mpViewLayer->getTransformation() );
     189             :                     const ::basegfx::B2IRange& rPixelBounds(
     190           0 :                         ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
     191             : 
     192           0 :                     uno::Reference< awt::XWindow > xSurroundingWindow( mxFrame->getContainerWindow() );
     193           0 :                     if( xSurroundingWindow.is() )
     194           0 :                         xSurroundingWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
     195             :                                                         static_cast<sal_Int32>(rPixelBounds.getMinY()),
     196           0 :                                                         static_cast<sal_Int32>(rPixelBounds.getWidth()),
     197           0 :                                                         static_cast<sal_Int32>(rPixelBounds.getHeight()),
     198           0 :                                                         awt::PosSize::POSSIZE );
     199             : 
     200           0 :                     uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
     201           0 :                     if( xAppletWindow.is() )
     202           0 :                         xAppletWindow->setPosSize( 0, 0,
     203           0 :                                                    static_cast<sal_Int32>(rPixelBounds.getWidth()),
     204           0 :                                                    static_cast<sal_Int32>(rPixelBounds.getHeight()),
     205           0 :                                                    awt::PosSize::POSSIZE );
     206           0 :                 }
     207             :             }
     208           0 :             catch (uno::Exception &)
     209             :             {
     210           0 :                 return false;
     211             :             }
     212             : 
     213           0 :             return true;
     214             :         }
     215             : 
     216             : 
     217             : 
     218           0 :         void ViewAppletShape::endApplet()
     219             :         {
     220             :             uno::Reference<util::XCloseable> xCloseable(
     221             :                 mxFrame,
     222           0 :                 uno::UNO_QUERY );
     223             : 
     224           0 :             if( xCloseable.is() )
     225             :             {
     226           0 :                 xCloseable->close( sal_True );
     227           0 :                 mxFrame.clear();
     228           0 :             }
     229           0 :         }
     230             : 
     231             : 
     232             : 
     233           0 :         bool ViewAppletShape::render( const ::basegfx::B2DRectangle& rBounds ) const
     234             :         {
     235           0 :             ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();
     236             : 
     237           0 :             if( !pCanvas )
     238           0 :                 return false;
     239             : 
     240           0 :             if( !mxFrame.is() )
     241             :             {
     242             :                 // fill the shape background with black
     243             :                 fillRect( pCanvas,
     244             :                           rBounds,
     245           0 :                           0xFFFFFFFFU );
     246             :             }
     247             : 
     248           0 :             return true;
     249             :         }
     250             : 
     251           0 :         bool ViewAppletShape::resize( const ::basegfx::B2DRectangle& rBounds ) const
     252             :         {
     253           0 :             if( !mxFrame.is() )
     254           0 :                 return false;
     255             : 
     256           0 :             ::basegfx::B2DRange aTmpRange;
     257             :             ::canvas::tools::calcTransformedRectBounds( aTmpRange,
     258             :                                                         rBounds,
     259           0 :                                                         mpViewLayer->getTransformation() );
     260             :             const ::basegfx::B2IRange& rPixelBounds(
     261           0 :                 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
     262             : 
     263           0 :             uno::Reference< awt::XWindow > xFrameWindow( mxFrame->getContainerWindow() );
     264           0 :             if( xFrameWindow.is() )
     265           0 :                 xFrameWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
     266             :                                           static_cast<sal_Int32>(rPixelBounds.getMinY()),
     267           0 :                                           static_cast<sal_Int32>(rPixelBounds.getWidth()),
     268           0 :                                           static_cast<sal_Int32>(rPixelBounds.getHeight()),
     269           0 :                                           awt::PosSize::POSSIZE );
     270             : 
     271           0 :             uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
     272           0 :             if( xAppletWindow.is() )
     273           0 :                 xAppletWindow->setPosSize( 0, 0,
     274           0 :                                            static_cast<sal_Int32>(rPixelBounds.getWidth()),
     275           0 :                                            static_cast<sal_Int32>(rPixelBounds.getHeight()),
     276           0 :                                            awt::PosSize::POSSIZE );
     277             : 
     278           0 :             return true;
     279             :         }
     280             :     }
     281             : }
     282             : 
     283             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11