LCOV - code coverage report
Current view: top level - slideshow/source/engine/shapes - viewappletshape.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 102 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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/XToolkit.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                 :            :                     uno::Reference< awt::XToolkit > xToolkit(
     154                 :          0 :                         xFactory->createInstanceWithContext(
     155                 :            :                             ::rtl::OUString("com.sun.star.awt.Toolkit" ),
     156                 :          0 :                             mxComponentContext ),
     157                 :          0 :                         uno::UNO_QUERY_THROW );
     158                 :            : 
     159                 :            :                     awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_SIMPLE,
     160                 :            :                                                              ::rtl::OUString(),
     161                 :            :                                                              uno::Reference< awt::XWindowPeer >(xParentWindow,
     162                 :            :                                                                                                 uno::UNO_QUERY_THROW),
     163                 :            :                                                              0,
     164                 :            :                                                              awt::Rectangle(),
     165                 :            :                                                              awt::WindowAttribute::SHOW
     166                 :          0 :                                                              | awt::VclWindowPeerAttribute::CLIPCHILDREN );
     167                 :            : 
     168                 :            :                     uno::Reference< awt::XWindowPeer > xNewWinPeer(
     169                 :          0 :                         xToolkit->createWindow( aOwnWinDescriptor ));
     170                 :            :                     uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer,
     171                 :          0 :                                                                uno::UNO_QUERY_THROW );
     172                 :            : 
     173                 :            : 
     174                 :            :                     // create a frame, and load the applet into it
     175                 :            :                     // ===========================================
     176                 :            : 
     177                 :            :                     mxFrame.set(
     178                 :          0 :                         xFactory->createInstanceWithContext(
     179                 :            :                             ::rtl::OUString("com.sun.star.frame.Frame" ),
     180                 :          0 :                             mxComponentContext ),
     181                 :          0 :                         uno::UNO_QUERY_THROW );
     182                 :            : 
     183                 :          0 :                     mxFrame->initialize( xOwnWindow );
     184                 :            : 
     185                 :            :                     uno::Reference < frame::XSynchronousFrameLoader > xLoader( mxViewer,
     186                 :          0 :                                                                                uno::UNO_QUERY_THROW );
     187                 :          0 :                     xLoader->load( uno::Sequence < beans::PropertyValue >(),
     188                 :          0 :                                    mxFrame );
     189                 :            : 
     190                 :            : 
     191                 :            :                     // resize surrounding window and applet to current shape size
     192                 :            :                     // ==========================================================
     193                 :            : 
     194                 :          0 :                     ::basegfx::B2DRange aTmpRange;
     195                 :            :                     ::canvas::tools::calcTransformedRectBounds( aTmpRange,
     196                 :            :                                                                 rBounds,
     197                 :          0 :                                                                 mpViewLayer->getTransformation() );
     198                 :            :                     const ::basegfx::B2IRange& rPixelBounds(
     199                 :          0 :                         ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
     200                 :            : 
     201                 :          0 :                     uno::Reference< awt::XWindow > xSurroundingWindow( mxFrame->getContainerWindow() );
     202                 :          0 :                     if( xSurroundingWindow.is() )
     203                 :          0 :                         xSurroundingWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
     204                 :            :                                                         static_cast<sal_Int32>(rPixelBounds.getMinY()),
     205                 :          0 :                                                         static_cast<sal_Int32>(rPixelBounds.getWidth()),
     206                 :          0 :                                                         static_cast<sal_Int32>(rPixelBounds.getHeight()),
     207                 :          0 :                                                         awt::PosSize::POSSIZE );
     208                 :            : 
     209                 :          0 :                     uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
     210                 :          0 :                     if( xAppletWindow.is() )
     211                 :          0 :                         xAppletWindow->setPosSize( 0, 0,
     212                 :          0 :                                                    static_cast<sal_Int32>(rPixelBounds.getWidth()),
     213                 :          0 :                                                    static_cast<sal_Int32>(rPixelBounds.getHeight()),
     214                 :          0 :                                                    awt::PosSize::POSSIZE );
     215                 :          0 :                 }
     216                 :            :             }
     217                 :          0 :             catch (uno::Exception &)
     218                 :            :             {
     219                 :          0 :                 return false;
     220                 :            :             }
     221                 :            : 
     222                 :          0 :             return true;
     223                 :            :         }
     224                 :            : 
     225                 :            :         // ---------------------------------------------------------------------
     226                 :            : 
     227                 :          0 :         void ViewAppletShape::endApplet()
     228                 :            :         {
     229                 :            :             uno::Reference<util::XCloseable> xCloseable(
     230                 :            :                 mxFrame,
     231                 :          0 :                 uno::UNO_QUERY );
     232                 :            : 
     233                 :          0 :             if( xCloseable.is() )
     234                 :            :             {
     235                 :          0 :                 xCloseable->close( sal_True );
     236                 :          0 :                 mxFrame.clear();
     237                 :          0 :             }
     238                 :          0 :         }
     239                 :            : 
     240                 :            :         // ---------------------------------------------------------------------
     241                 :            : 
     242                 :          0 :         bool ViewAppletShape::render( const ::basegfx::B2DRectangle& rBounds ) const
     243                 :            :         {
     244                 :          0 :             ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();
     245                 :            : 
     246                 :          0 :             if( !pCanvas )
     247                 :          0 :                 return false;
     248                 :            : 
     249                 :          0 :             if( !mxFrame.is() )
     250                 :            :             {
     251                 :            :                 // fill the shape background with black
     252                 :            :                 fillRect( pCanvas,
     253                 :            :                           rBounds,
     254                 :          0 :                           0xFFFFFFFFU );
     255                 :            :             }
     256                 :            : 
     257                 :          0 :             return true;
     258                 :            :         }
     259                 :            : 
     260                 :          0 :         bool ViewAppletShape::resize( const ::basegfx::B2DRectangle& rBounds ) const
     261                 :            :         {
     262                 :          0 :             if( !mxFrame.is() )
     263                 :          0 :                 return false;
     264                 :            : 
     265                 :          0 :             ::basegfx::B2DRange aTmpRange;
     266                 :            :             ::canvas::tools::calcTransformedRectBounds( aTmpRange,
     267                 :            :                                                         rBounds,
     268                 :          0 :                                                         mpViewLayer->getTransformation() );
     269                 :            :             const ::basegfx::B2IRange& rPixelBounds(
     270                 :          0 :                 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
     271                 :            : 
     272                 :          0 :             uno::Reference< awt::XWindow > xFrameWindow( mxFrame->getContainerWindow() );
     273                 :          0 :             if( xFrameWindow.is() )
     274                 :          0 :                 xFrameWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
     275                 :            :                                           static_cast<sal_Int32>(rPixelBounds.getMinY()),
     276                 :          0 :                                           static_cast<sal_Int32>(rPixelBounds.getWidth()),
     277                 :          0 :                                           static_cast<sal_Int32>(rPixelBounds.getHeight()),
     278                 :          0 :                                           awt::PosSize::POSSIZE );
     279                 :            : 
     280                 :          0 :             uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
     281                 :          0 :             if( xAppletWindow.is() )
     282                 :          0 :                 xAppletWindow->setPosSize( 0, 0,
     283                 :          0 :                                            static_cast<sal_Int32>(rPixelBounds.getWidth()),
     284                 :          0 :                                            static_cast<sal_Int32>(rPixelBounds.getHeight()),
     285                 :          0 :                                            awt::PosSize::POSSIZE );
     286                 :            : 
     287                 :          0 :             return true;
     288                 :            :         }
     289                 :            :     }
     290                 :            : }
     291                 :            : 
     292                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10