LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/config - evntconf.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 104 1.9 %
Date: 2012-12-27 Functions: 6 28 21.4 %
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             : #include <boost/scoped_ptr.hpp>
      22             : 
      23             : #include <vcl/msgbox.hxx>
      24             : #include <svl/lstner.hxx>
      25             : #include <basic/basmgr.hxx>
      26             : #include <basic/sbmod.hxx>
      27             : #include <basic/sbx.hxx>
      28             : #include <sot/storage.hxx>
      29             : #include <unotools/securityoptions.hxx>
      30             : 
      31             : #include <rtl/ustring.h>
      32             : #include <com/sun/star/uno/Any.hxx>
      33             : #include <framework/eventsconfiguration.hxx>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <sfx2/evntconf.hxx>
      36             : 
      37             : #include <sfx2/docfile.hxx>
      38             : #include <sfx2/app.hxx>
      39             : #include <sfx2/objsh.hxx>
      40             : #include <sfx2/dispatch.hxx>
      41             : #include "sfx2/sfxresid.hxx"
      42             : #include "eventsupplier.hxx"
      43             : 
      44             : #include <com/sun/star/beans/PropertyValue.hpp>
      45             : #include <com/sun/star/container/XNameReplace.hpp>
      46             : #include <com/sun/star/document/XEventsSupplier.hpp>
      47             : #include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
      48             : #include <com/sun/star/uno/Sequence.hxx>
      49             : #include <com/sun/star/uno/Reference.hxx>
      50             : 
      51             : // -----------------------------------------------------------------------
      52      145844 : TYPEINIT1(SfxEventHint, SfxHint);
      53           0 : TYPEINIT1(SfxEventNamesItem, SfxPoolItem);
      54       49193 : TYPEINIT1(SfxViewEventHint, SfxEventHint);
      55             : 
      56             : using namespace com::sun::star;
      57             : 
      58           0 : SfxEventNamesList& SfxEventNamesList::operator=( const SfxEventNamesList& rTbl )
      59             : {
      60           0 :     DelDtor();
      61           0 :     for ( size_t i = 0, n = rTbl.size(); i < n; ++i )
      62             :     {
      63           0 :         SfxEventName* pTmp = rTbl.at( i );
      64           0 :         SfxEventName* pNew = new SfxEventName( *pTmp );
      65           0 :         aEventNamesList.push_back( pNew );
      66             :     }
      67           0 :     return *this;
      68             : }
      69             : 
      70           0 : void SfxEventNamesList::DelDtor()
      71             : {
      72           0 :     for ( size_t i = 0, n = aEventNamesList.size(); i < n; ++i )
      73           0 :         delete aEventNamesList[ i ];
      74           0 :     aEventNamesList.clear();
      75           0 : }
      76             : 
      77           0 : int SfxEventNamesItem::operator==( const SfxPoolItem& rAttr ) const
      78             : {
      79             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
      80             : 
      81           0 :     const SfxEventNamesList& rOwn = aEventsList;
      82           0 :     const SfxEventNamesList& rOther = ( (SfxEventNamesItem&) rAttr ).aEventsList;
      83             : 
      84           0 :     if ( rOwn.size() != rOther.size() )
      85           0 :         return sal_False;
      86             : 
      87           0 :     for ( size_t nNo = 0, nCnt = rOwn.size(); nNo < nCnt; ++nNo )
      88             :     {
      89           0 :         const SfxEventName *pOwn = rOwn.at( nNo );
      90           0 :         const SfxEventName *pOther = rOther.at( nNo );
      91           0 :         if (    pOwn->mnId != pOther->mnId ||
      92           0 :                 pOwn->maEventName != pOther->maEventName ||
      93           0 :                 pOwn->maUIName != pOther->maUIName )
      94           0 :             return sal_False;
      95             :     }
      96             : 
      97           0 :     return sal_True;
      98             : 
      99             : }
     100             : 
     101           0 : SfxItemPresentation SfxEventNamesItem::GetPresentation( SfxItemPresentation,
     102             :                                     SfxMapUnit,
     103             :                                     SfxMapUnit,
     104             :                                     XubString &rText,
     105             :                                     const IntlWrapper* ) const
     106             : {
     107           0 :     rText.Erase();
     108           0 :     return SFX_ITEM_PRESENTATION_NONE;
     109             : }
     110             : 
     111           0 : SfxPoolItem* SfxEventNamesItem::Clone( SfxItemPool *) const
     112             : {
     113           0 :     return new SfxEventNamesItem(*this);
     114             : }
     115             : 
     116           0 : SfxPoolItem* SfxEventNamesItem::Create(SvStream &, sal_uInt16) const
     117             : {
     118             :     OSL_FAIL("not streamable!");
     119           0 :     return new SfxEventNamesItem(Which());
     120             : }
     121             : 
     122           0 : SvStream& SfxEventNamesItem::Store(SvStream &rStream, sal_uInt16 ) const
     123             : {
     124             :     OSL_FAIL("not streamable!");
     125           0 :     return rStream;
     126             : }
     127             : 
     128           0 : sal_uInt16 SfxEventNamesItem::GetVersion( sal_uInt16 ) const
     129             : {
     130             :     OSL_FAIL("not streamable!");
     131           0 :     return 0;
     132             : }
     133             : 
     134           0 : void SfxEventNamesItem::AddEvent( const String& rName, const String& rUIName, sal_uInt16 nID )
     135             : {
     136           0 :     aEventsList.push_back( new SfxEventName( nID, rName, rUIName.Len() ? rUIName : rName ) );
     137           0 : }
     138             : 
     139             : 
     140             : //==========================================================================
     141             : 
     142             : //--------------------------------------------------------------------------
     143           0 : uno::Any CreateEventData_Impl( const SvxMacro *pMacro )
     144             : {
     145             : /*
     146             :     This function converts a SvxMacro into an Any containing three
     147             :     properties. These properties are EventType and Script. Possible
     148             :     values for EventType ar StarBasic, JavaScript, ...
     149             :     The Script property should contain the URL to the macro and looks
     150             :     like "macro://./standard.module1.main()"
     151             : 
     152             :     If pMacro is NULL, we return an empty property sequence, so PropagateEvent_Impl
     153             :     can delete an event binding.
     154             : */
     155           0 :     uno::Any aEventData;
     156             : 
     157           0 :     if ( pMacro )
     158             :     {
     159           0 :         if ( pMacro->GetScriptType() == STARBASIC )
     160             :         {
     161           0 :             uno::Sequence < beans::PropertyValue > aProperties(3);
     162           0 :             beans::PropertyValue *pValues = aProperties.getArray();
     163             : 
     164           0 :             ::rtl::OUString aType(STAR_BASIC );
     165           0 :             ::rtl::OUString aLib  = pMacro->GetLibName();
     166           0 :             ::rtl::OUString aMacro = pMacro->GetMacName();
     167             : 
     168           0 :             pValues[ 0 ].Name = ::rtl::OUString(PROP_EVENT_TYPE );
     169           0 :             pValues[ 0 ].Value <<= aType;
     170             : 
     171           0 :             pValues[ 1 ].Name = ::rtl::OUString(PROP_LIBRARY );
     172           0 :             pValues[ 1 ].Value <<= aLib;
     173             : 
     174           0 :             pValues[ 2 ].Name = ::rtl::OUString(PROP_MACRO_NAME );
     175           0 :             pValues[ 2 ].Value <<= aMacro;
     176             : 
     177           0 :             aEventData <<= aProperties;
     178             :         }
     179           0 :         else if ( pMacro->GetScriptType() == EXTENDED_STYPE )
     180             :         {
     181           0 :             uno::Sequence < beans::PropertyValue > aProperties(2);
     182           0 :             beans::PropertyValue *pValues = aProperties.getArray();
     183             : 
     184           0 :             ::rtl::OUString aLib   = pMacro->GetLibName();
     185           0 :             ::rtl::OUString aMacro = pMacro->GetMacName();
     186             : 
     187           0 :             pValues[ 0 ].Name = ::rtl::OUString(PROP_EVENT_TYPE );
     188           0 :             pValues[ 0 ].Value <<= aLib;
     189             : 
     190           0 :             pValues[ 1 ].Name = ::rtl::OUString(PROP_SCRIPT );
     191           0 :             pValues[ 1 ].Value <<= aMacro;
     192             : 
     193           0 :             aEventData <<= aProperties;
     194             :         }
     195           0 :         else if ( pMacro->GetScriptType() == JAVASCRIPT )
     196             :         {
     197           0 :             uno::Sequence < beans::PropertyValue > aProperties(2);
     198           0 :             beans::PropertyValue *pValues = aProperties.getArray();
     199             : 
     200           0 :             ::rtl::OUString aMacro  = pMacro->GetMacName();
     201             : 
     202           0 :             pValues[ 0 ].Name = ::rtl::OUString(PROP_EVENT_TYPE );
     203           0 :             pValues[ 0 ].Value <<= ::rtl::OUString(SVX_MACRO_LANGUAGE_JAVASCRIPT);
     204             : 
     205           0 :             pValues[ 1 ].Name = ::rtl::OUString(PROP_MACRO_NAME );
     206           0 :             pValues[ 1 ].Value <<= aMacro;
     207             : 
     208           0 :             aEventData <<= aProperties;
     209             :         }
     210             :         else
     211             :         {
     212             :             SAL_WARN( "sfx2.config", "CreateEventData_Impl(): ScriptType not supported!");
     213             :         }
     214             :     }
     215             :     else
     216             :     {
     217           0 :         uno::Sequence < beans::PropertyValue > aProperties;
     218           0 :         aEventData <<= aProperties;
     219             :     }
     220             : 
     221           0 :     return aEventData;
     222             : }
     223             : 
     224             : //--------------------------------------------------------------------------
     225           0 : void PropagateEvent_Impl( SfxObjectShell *pDoc, rtl::OUString aEventName, const SvxMacro* pMacro )
     226             : {
     227           0 :     uno::Reference < document::XEventsSupplier > xSupplier;
     228           0 :     if ( pDoc )
     229             :     {
     230           0 :         xSupplier = uno::Reference < document::XEventsSupplier >( pDoc->GetModel(), uno::UNO_QUERY );
     231             :     }
     232             :     else
     233             :     {
     234             :         xSupplier = uno::Reference < document::XEventsSupplier >
     235             :                 ( frame::GlobalEventBroadcaster::create(::comphelper::getProcessComponentContext()),
     236           0 :                   uno::UNO_QUERY );
     237             :     }
     238             : 
     239           0 :     if ( xSupplier.is() )
     240             :     {
     241           0 :         uno::Reference < container::XNameReplace > xEvents = xSupplier->getEvents();
     242           0 :         if ( !aEventName.isEmpty() )
     243             :         {
     244           0 :             uno::Any aEventData = CreateEventData_Impl( pMacro );
     245             : 
     246             :             try
     247             :             {
     248           0 :                 xEvents->replaceByName( aEventName, aEventData );
     249             :             }
     250           0 :             catch( const ::com::sun::star::lang::IllegalArgumentException& )
     251             :             {
     252             :                 SAL_WARN( "sfx2.config", "PropagateEvents_Impl: caught IllegalArgumentException" );
     253             :             }
     254           0 :             catch( const ::com::sun::star::container::NoSuchElementException& )
     255             :             {
     256             :                 SAL_WARN( "sfx2.config", "PropagateEvents_Impl: caught NoSuchElementException" );
     257           0 :             }
     258             :         }
     259             :         else {
     260             :             DBG_WARNING( "PropagateEvents_Impl: Got unkown event" );
     261           0 :         }
     262           0 :     }
     263           0 : }
     264             : 
     265             : //--------------------------------------------------------------------------------------------------------
     266           0 : void SfxEventConfiguration::ConfigureEvent( rtl::OUString aName, const SvxMacro& rMacro, SfxObjectShell *pDoc )
     267             : {
     268           0 :     boost::scoped_ptr<SvxMacro> pMacro;
     269           0 :     if ( rMacro.HasMacro() )
     270           0 :         pMacro.reset( new SvxMacro( rMacro.GetMacName(), rMacro.GetLibName(), rMacro.GetScriptType() ) );
     271           0 :     PropagateEvent_Impl( pDoc ? pDoc : 0, aName, pMacro.get() );
     272           0 : }
     273             : 
     274             : // -------------------------------------------------------------------------------------------------------
     275           0 : SvxMacro* SfxEventConfiguration::ConvertToMacro( const com::sun::star::uno::Any& rElement, SfxObjectShell* pDoc, sal_Bool bBlowUp )
     276             : {
     277           0 :     return SfxEvents_Impl::ConvertToMacro( rElement, pDoc, bBlowUp );
     278             : }
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10