LCOV - code coverage report
Current view: top level - sfx2/source/doc - plugin.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 117 0.9 %
Date: 2012-08-25 Functions: 1 29 3.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 224 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                 :            : #include "plugin.hxx"
      22                 :            : #include <com/sun/star/plugin/PluginManager.hpp>
      23                 :            : #include <com/sun/star/plugin/XPluginManager.hpp>
      24                 :            : #include <com/sun/star/plugin/PluginMode.hpp>
      25                 :            : #include <com/sun/star/awt/XControl.hpp>
      26                 :            : 
      27                 :            : #include <comphelper/componentcontext.hxx>
      28                 :            : #include <rtl/ustring.hxx>
      29                 :            : #include <toolkit/helper/vclunohelper.hxx>
      30                 :            : #include <svtools/miscopt.hxx>
      31                 :            : #include <vcl/window.hxx>
      32                 :            : 
      33                 :            : using namespace ::com::sun::star;
      34                 :            : 
      35                 :            : namespace sfx2
      36                 :            : {
      37                 :            : 
      38         [ #  # ]:          0 : class PluginWindow_Impl : public Window
      39                 :            : {
      40                 :            : public:
      41                 :            :     uno::Reference < awt::XWindow > xWindow;
      42                 :          0 :     PluginWindow_Impl( Window* pParent )
      43                 :          0 :      : Window( pParent, WB_CLIPCHILDREN )
      44                 :          0 :      {}
      45                 :            : 
      46                 :            :      virtual void Resize();
      47                 :            : };
      48                 :            : 
      49                 :          0 : void PluginWindow_Impl::Resize()
      50                 :            : {
      51                 :          0 :     Size aSize( GetOutputSizePixel() );
      52         [ #  # ]:          0 :     if ( xWindow.is() )
      53 [ #  # ][ #  # ]:          0 :         xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_SIZE );
      54                 :          0 : }
      55                 :            : 
      56                 :            : #define PROPERTY_UNBOUND 0
      57                 :            : 
      58                 :            : #define WID_COMMANDS    1
      59                 :            : #define WID_MIMETYPE    2
      60                 :            : #define WID_URL         3
      61                 :          0 : const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl()
      62                 :            : {
      63                 :            :     static SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] =
      64                 :            :     {
      65         [ #  # ]:          0 :         { MAP_CHAR_LEN("PluginCommands"), WID_COMMANDS, &::getCppuType((::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >*)0), PROPERTY_UNBOUND, 0},
      66         [ #  # ]:          0 :         { MAP_CHAR_LEN("PluginMimeType"), WID_MIMETYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      67         [ #  # ]:          0 :         { MAP_CHAR_LEN("PluginURL"),      WID_URL     , &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      68                 :            :         {0,0,0,0,0,0}
      69 [ #  # ][ #  # ]:          0 :     };
                 [ #  # ]
      70                 :          0 :     return aPluginPropertyMap_Impl;
      71                 :            : }
      72                 :            : 
      73 [ #  # ][ #  # ]:        546 : SFX_IMPL_XSERVICEINFO( PluginObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.PluginObject" )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      74 [ #  # ][ #  # ]:          0 : SFX_IMPL_SINGLEFACTORY( PluginObject );
      75                 :            : 
      76                 :          0 : PluginObject::PluginObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
      77                 :            :     : mxFact( rFact )
      78 [ #  # ][ #  # ]:          0 :     , maPropMap( lcl_GetPluginPropertyMap_Impl() )
                 [ #  # ]
      79                 :            : {
      80                 :          0 : }
      81                 :            : 
      82         [ #  # ]:          0 : PluginObject::~PluginObject()
      83                 :            : {
      84         [ #  # ]:          0 : }
      85                 :            : 
      86                 :          0 : void SAL_CALL PluginObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
      87                 :            : {
      88         [ #  # ]:          0 :     if ( aArguments.getLength() )
      89                 :          0 :         aArguments[0] >>= mxObj;
      90                 :          0 : }
      91                 :            : 
      92                 :          0 : sal_Bool SAL_CALL PluginObject::load(
      93                 :            :     const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
      94                 :            :     const uno::Reference < frame::XFrame >& xFrame )
      95                 :            : throw( uno::RuntimeException )
      96                 :            : {
      97 [ #  # ][ #  # ]:          0 :     uno::Reference< plugin::XPluginManager > xPMgr( plugin::PluginManager::create(comphelper::ComponentContext(mxFact).getUNOContext()) );
         [ #  # ][ #  # ]
      98                 :            : 
      99 [ #  # ][ #  # ]:          0 :     if ( SvtMiscOptions().IsPluginsEnabled() )
         [ #  # ][ #  # ]
     100                 :            :     {
     101 [ #  # ][ #  # ]:          0 :         Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
                 [ #  # ]
     102 [ #  # ][ #  # ]:          0 :         PluginWindow_Impl* pWin = new PluginWindow_Impl( pParent );
     103         [ #  # ]:          0 :         pWin->SetSizePixel( pParent->GetOutputSizePixel() );
     104         [ #  # ]:          0 :         pWin->SetBackground();
     105         [ #  # ]:          0 :         pWin->Show();
     106                 :            : 
     107                 :          0 :         size_t nCount = maCmdList.size();
     108 [ #  # ][ #  # ]:          0 :         uno::Sequence < ::rtl::OUString > aCmds( nCount ), aArgs( nCount );
     109 [ #  # ][ #  # ]:          0 :         ::rtl::OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray();
     110         [ #  # ]:          0 :         for( size_t i = 0; i < nCount; i++ )
     111                 :            :         {
     112         [ #  # ]:          0 :             pCmds[i] = maCmdList[ i ].GetCommand();
     113         [ #  # ]:          0 :             pArgs[i] = maCmdList[ i ].GetArgument();
     114                 :            :         }
     115                 :            : 
     116         [ #  # ]:          0 :         mxPlugin = xPMgr->createPluginFromURL(
     117         [ #  # ]:          0 :             xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(),
     118 [ #  # ][ #  # ]:          0 :             uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL );
         [ #  # ][ #  # ]
     119                 :            : 
     120         [ #  # ]:          0 :         if ( mxPlugin.is() )
     121                 :            :         {
     122         [ #  # ]:          0 :             uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY );
     123         [ #  # ]:          0 :             if ( xWindow.is() )
     124                 :            :             {
     125         [ #  # ]:          0 :                 pWin->xWindow = xWindow;
     126         [ #  # ]:          0 :                 pWin->Resize();
     127 [ #  # ][ #  # ]:          0 :                 xWindow->setVisible( sal_True );
     128                 :            :             }
     129                 :            : 
     130                 :            :             try
     131                 :            :             {
     132         [ #  # ]:          0 :                 uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY );
     133         [ #  # ]:          0 :                 if( xControl.is() )
     134                 :            :                 {
     135 [ #  # ][ #  # ]:          0 :                     uno::Reference< awt::XControlModel > xModel = xControl->getModel();
     136         [ #  # ]:          0 :                     uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY );
     137         [ #  # ]:          0 :                     if( xProp.is() )
     138                 :            :                     {
     139 [ #  # ][ #  # ]:          0 :                         uno::Any aValue = xProp->getPropertyValue( ::rtl::OUString( "URL"  ) );
     140                 :          0 :                         aValue >>= maURL;
     141 [ #  # ][ #  # ]:          0 :                         aValue = xProp->getPropertyValue( ::rtl::OUString( "TYPE"  ) );
     142                 :          0 :                         aValue >>= maMimeType;
     143                 :          0 :                     }
     144         [ #  # ]:          0 :                 }
     145                 :            :             }
     146         [ #  # ]:          0 :             catch( const uno::Exception& )
     147                 :            :             {
     148                 :          0 :             }
     149                 :            :         }
     150                 :            : 
     151 [ #  # ][ #  # ]:          0 :         uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
     152                 :            : 
     153                 :            :         // we must destroy the plugin before the parent is destroyed
     154 [ #  # ][ #  # ]:          0 :         xWindow->addEventListener( this );
                 [ #  # ]
     155 [ #  # ][ #  # ]:          0 :         xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
     156 [ #  # ][ #  # ]:          0 :         return mxPlugin.is() ? sal_True : sal_False;
                 [ #  # ]
     157                 :            :     }
     158                 :            : 
     159                 :          0 :     return sal_False;
     160                 :            : }
     161                 :            : 
     162                 :          0 : void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException )
     163                 :            : {
     164         [ #  # ]:          0 :     uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY );
     165         [ #  # ]:          0 :     if (xComp.is())
     166 [ #  # ][ #  # ]:          0 :         xComp->dispose();
     167         [ #  # ]:          0 :     mxPlugin = 0;
     168                 :          0 : }
     169                 :            : 
     170                 :          0 : void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
     171                 :            : {
     172                 :          0 : }
     173                 :            : 
     174                 :          0 : void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
     175                 :            : {
     176                 :          0 : }
     177                 :            : 
     178                 :          0 : void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
     179                 :            : {
     180                 :          0 : }
     181                 :            : 
     182                 :          0 : void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
     183                 :            : {
     184                 :          0 :     cancel();
     185                 :          0 : }
     186                 :            : 
     187                 :          0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
     188                 :            : {
     189 [ #  # ][ #  # ]:          0 :     static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( maPropMap );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     190                 :          0 :     return xInfo;
     191                 :            : }
     192                 :            : 
     193                 :          0 : void SAL_CALL PluginObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
     194                 :            :     throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
     195                 :            : {
     196         [ #  # ]:          0 :     if ( aPropertyName == "PluginURL" )
     197                 :            :     {
     198                 :          0 :         aAny >>= maURL;
     199                 :            :     }
     200         [ #  # ]:          0 :     else if ( aPropertyName == "PluginMimeType" )
     201                 :            :     {
     202                 :          0 :         aAny >>= maMimeType;
     203                 :            :     }
     204         [ #  # ]:          0 :     else if ( aPropertyName == "PluginCommands" )
     205                 :            :     {
     206                 :          0 :         maCmdList.clear();
     207         [ #  # ]:          0 :         uno::Sequence < beans::PropertyValue > aCommandSequence;
     208 [ #  # ][ #  # ]:          0 :         if( aAny >>= aCommandSequence )
     209 [ #  # ][ #  # ]:          0 :             maCmdList.FillFromSequence( aCommandSequence );
     210                 :            :     }
     211                 :            :     else
     212         [ #  # ]:          0 :          throw beans::UnknownPropertyException();
     213                 :          0 : }
     214                 :            : 
     215                 :          0 : uno::Any SAL_CALL PluginObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
     216                 :            :         throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     217                 :            : {
     218                 :          0 :     uno::Any aAny;
     219         [ #  # ]:          0 :     if ( aPropertyName == "PluginURL" )
     220                 :            :     {
     221         [ #  # ]:          0 :         aAny <<= maURL;
     222                 :            :     }
     223         [ #  # ]:          0 :     else if ( aPropertyName == "PluginMimeType" )
     224                 :            :     {
     225         [ #  # ]:          0 :         aAny <<= maMimeType;
     226                 :            :     }
     227         [ #  # ]:          0 :     else if ( aPropertyName == "PluginCommands" )
     228                 :            :     {
     229         [ #  # ]:          0 :         uno::Sequence< beans::PropertyValue > aCommandSequence;
     230         [ #  # ]:          0 :         maCmdList.FillSequence( aCommandSequence );
     231 [ #  # ][ #  # ]:          0 :         aAny <<= aCommandSequence;
     232                 :            :     }
     233                 :            :     else
     234         [ #  # ]:          0 :          throw beans::UnknownPropertyException();
     235                 :          0 :     return aAny;
     236                 :            : }
     237                 :            : 
     238                 :          0 : void SAL_CALL PluginObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
     239                 :            : {
     240                 :          0 : }
     241                 :            : 
     242                 :          0 : void SAL_CALL PluginObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
     243                 :            : {
     244                 :          0 : }
     245                 :            : 
     246                 :          0 : void SAL_CALL PluginObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
     247                 :            : {
     248                 :          0 : }
     249                 :            : 
     250                 :          0 : void SAL_CALL PluginObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
     251                 :            : {
     252                 :          0 : }
     253                 :            : 
     254                 :            : }
     255                 :            : 
     256                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10