LCOV - code coverage report
Current view: top level - libreoffice/slideshow/source/engine/shapes - viewappletshape.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 100 0.0 %
Date: 2012-12-27 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/XFrame.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 ::rtl::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 :             ::rtl::OUString aPropName;
      94           0 :             for( sal_Size i=0; i<nNumPropEntries; ++i )
      95             :             {
      96           0 :                 aPropName = ::rtl::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( rtl::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 :                         ::rtl::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             :                                                              ::rtl::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             :                     mxFrame.set(
     174           0 :                         xFactory->createInstanceWithContext(
     175             :                             ::rtl::OUString("com.sun.star.frame.Frame" ),
     176           0 :                             mxComponentContext ),
     177           0 :                         uno::UNO_QUERY_THROW );
     178             : 
     179           0 :                     mxFrame->initialize( xOwnWindow );
     180             : 
     181             :                     uno::Reference < frame::XSynchronousFrameLoader > xLoader( mxViewer,
     182           0 :                                                                                uno::UNO_QUERY_THROW );
     183           0 :                     xLoader->load( uno::Sequence < beans::PropertyValue >(),
     184           0 :                                    mxFrame );
     185             : 
     186             : 
     187             :                     // resize surrounding window and applet to current shape size
     188             :                     // ==========================================================
     189             : 
     190           0 :                     ::basegfx::B2DRange aTmpRange;
     191             :                     ::canvas::tools::calcTransformedRectBounds( aTmpRange,
     192             :                                                                 rBounds,
     193           0 :                                                                 mpViewLayer->getTransformation() );
     194             :                     const ::basegfx::B2IRange& rPixelBounds(
     195           0 :                         ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
     196             : 
     197           0 :                     uno::Reference< awt::XWindow > xSurroundingWindow( mxFrame->getContainerWindow() );
     198           0 :                     if( xSurroundingWindow.is() )
     199           0 :                         xSurroundingWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
     200             :                                                         static_cast<sal_Int32>(rPixelBounds.getMinY()),
     201           0 :                                                         static_cast<sal_Int32>(rPixelBounds.getWidth()),
     202           0 :                                                         static_cast<sal_Int32>(rPixelBounds.getHeight()),
     203           0 :                                                         awt::PosSize::POSSIZE );
     204             : 
     205           0 :                     uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
     206           0 :                     if( xAppletWindow.is() )
     207           0 :                         xAppletWindow->setPosSize( 0, 0,
     208           0 :                                                    static_cast<sal_Int32>(rPixelBounds.getWidth()),
     209           0 :                                                    static_cast<sal_Int32>(rPixelBounds.getHeight()),
     210           0 :                                                    awt::PosSize::POSSIZE );
     211           0 :                 }
     212             :             }
     213           0 :             catch (uno::Exception &)
     214             :             {
     215           0 :                 return false;
     216             :             }
     217             : 
     218           0 :             return true;
     219             :         }
     220             : 
     221             :         // ---------------------------------------------------------------------
     222             : 
     223           0 :         void ViewAppletShape::endApplet()
     224             :         {
     225             :             uno::Reference<util::XCloseable> xCloseable(
     226             :                 mxFrame,
     227           0 :                 uno::UNO_QUERY );
     228             : 
     229           0 :             if( xCloseable.is() )
     230             :             {
     231           0 :                 xCloseable->close( sal_True );
     232           0 :                 mxFrame.clear();
     233           0 :             }
     234           0 :         }
     235             : 
     236             :         // ---------------------------------------------------------------------
     237             : 
     238           0 :         bool ViewAppletShape::render( const ::basegfx::B2DRectangle& rBounds ) const
     239             :         {
     240           0 :             ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();
     241             : 
     242           0 :             if( !pCanvas )
     243           0 :                 return false;
     244             : 
     245           0 :             if( !mxFrame.is() )
     246             :             {
     247             :                 // fill the shape background with black
     248             :                 fillRect( pCanvas,
     249             :                           rBounds,
     250           0 :                           0xFFFFFFFFU );
     251             :             }
     252             : 
     253           0 :             return true;
     254             :         }
     255             : 
     256           0 :         bool ViewAppletShape::resize( const ::basegfx::B2DRectangle& rBounds ) const
     257             :         {
     258           0 :             if( !mxFrame.is() )
     259           0 :                 return false;
     260             : 
     261           0 :             ::basegfx::B2DRange aTmpRange;
     262             :             ::canvas::tools::calcTransformedRectBounds( aTmpRange,
     263             :                                                         rBounds,
     264           0 :                                                         mpViewLayer->getTransformation() );
     265             :             const ::basegfx::B2IRange& rPixelBounds(
     266           0 :                 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
     267             : 
     268           0 :             uno::Reference< awt::XWindow > xFrameWindow( mxFrame->getContainerWindow() );
     269           0 :             if( xFrameWindow.is() )
     270           0 :                 xFrameWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
     271             :                                           static_cast<sal_Int32>(rPixelBounds.getMinY()),
     272           0 :                                           static_cast<sal_Int32>(rPixelBounds.getWidth()),
     273           0 :                                           static_cast<sal_Int32>(rPixelBounds.getHeight()),
     274           0 :                                           awt::PosSize::POSSIZE );
     275             : 
     276           0 :             uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
     277           0 :             if( xAppletWindow.is() )
     278           0 :                 xAppletWindow->setPosSize( 0, 0,
     279           0 :                                            static_cast<sal_Int32>(rPixelBounds.getWidth()),
     280           0 :                                            static_cast<sal_Int32>(rPixelBounds.getHeight()),
     281           0 :                                            awt::PosSize::POSSIZE );
     282             : 
     283           0 :             return true;
     284             :         }
     285             :     }
     286             : }
     287             : 
     288             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10