LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - eventuno.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 89 0.0 %
Date: 2014-04-14 Functions: 0 14 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             : #include "eventuno.hxx"
      22             : #include "miscuno.hxx"
      23             : #include "docsh.hxx"
      24             : #include "sheetevents.hxx"
      25             : #include "unonames.hxx"
      26             : #include <vcl/svapp.hxx>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : 
      30           0 : SC_SIMPLE_SERVICE_INFO( ScSheetEventsObj, "ScSheetEventsObj", "com.sun.star.document.Events" )
      31             : 
      32           0 : ScSheetEventsObj::ScSheetEventsObj(ScDocShell* pDocSh, SCTAB nT) :
      33             :     mpDocShell( pDocSh ),
      34           0 :     mnTab( nT )
      35             : {
      36           0 :     mpDocShell->GetDocument()->AddUnoObject(*this);
      37           0 : }
      38             : 
      39           0 : ScSheetEventsObj::~ScSheetEventsObj()
      40             : {
      41           0 :     if (mpDocShell)
      42           0 :         mpDocShell->GetDocument()->RemoveUnoObject(*this);
      43           0 : }
      44             : 
      45           0 : void ScSheetEventsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
      46             : {
      47             :     //! reference update
      48           0 :     if ( rHint.ISA( SfxSimpleHint ) &&
      49           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
      50             :     {
      51           0 :         mpDocShell = NULL;
      52             :     }
      53           0 : }
      54             : 
      55           0 : static sal_Int32 lcl_GetEventFromName( const OUString& aName )
      56             : {
      57           0 :     for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
      58           0 :         if ( aName == ScSheetEvents::GetEventName(nEvent) )
      59           0 :             return nEvent;
      60             : 
      61           0 :     return -1;      // not found
      62             : }
      63             : 
      64             : // XNameReplace
      65             : 
      66           0 : void SAL_CALL ScSheetEventsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
      67             :     throw(lang::IllegalArgumentException, container::NoSuchElementException,
      68             :           lang::WrappedTargetException, uno::RuntimeException, std::exception)
      69             : {
      70           0 :     SolarMutexGuard aGuard;
      71           0 :     if (!mpDocShell)
      72           0 :         throw uno::RuntimeException();
      73             : 
      74           0 :     sal_Int32 nEvent = lcl_GetEventFromName(aName);
      75           0 :     if (nEvent < 0)
      76           0 :         throw container::NoSuchElementException();
      77             : 
      78           0 :     ScSheetEvents aNewEvents;
      79           0 :     const ScSheetEvents* pOldEvents = mpDocShell->GetDocument()->GetSheetEvents(mnTab);
      80           0 :     if (pOldEvents)
      81           0 :         aNewEvents = *pOldEvents;
      82             : 
      83           0 :     OUString aScript;
      84           0 :     if ( aElement.hasValue() )      // empty Any -> reset event
      85             :     {
      86           0 :         uno::Sequence<beans::PropertyValue> aPropSeq;
      87           0 :         if ( aElement >>= aPropSeq )
      88             :         {
      89           0 :             sal_Int32 nPropCount = aPropSeq.getLength();
      90           0 :             for (sal_Int32 nPos=0; nPos<nPropCount; ++nPos)
      91             :             {
      92           0 :                 const beans::PropertyValue& rProp = aPropSeq[nPos];
      93           0 :                 if ( rProp.Name.equalsAscii( SC_UNO_EVENTTYPE ) )
      94             :                 {
      95           0 :                     OUString aEventType;
      96           0 :                     if ( rProp.Value >>= aEventType )
      97             :                     {
      98             :                         // only "Script" is supported
      99           0 :                         if ( aEventType.compareToAscii( SC_UNO_SCRIPT ) != 0 )
     100           0 :                             throw lang::IllegalArgumentException();
     101           0 :                     }
     102             :                 }
     103           0 :                 else if ( rProp.Name.equalsAscii( SC_UNO_SCRIPT ) )
     104           0 :                     rProp.Value >>= aScript;
     105             :             }
     106           0 :         }
     107             :     }
     108           0 :     if (!aScript.isEmpty())
     109           0 :         aNewEvents.SetScript( nEvent, &aScript );
     110             :     else
     111           0 :         aNewEvents.SetScript( nEvent, NULL );       // reset
     112             : 
     113           0 :     mpDocShell->GetDocument()->SetSheetEvents( mnTab, &aNewEvents );
     114           0 :     mpDocShell->SetDocumentModified();
     115           0 : }
     116             : 
     117             : // XNameAccess
     118             : 
     119           0 : uno::Any SAL_CALL ScSheetEventsObj::getByName( const OUString& aName )
     120             :     throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     121             : {
     122           0 :     SolarMutexGuard aGuard;
     123           0 :     sal_Int32 nEvent = lcl_GetEventFromName(aName);
     124           0 :     if (nEvent < 0)
     125           0 :         throw container::NoSuchElementException();
     126             : 
     127           0 :     const OUString* pScript = NULL;
     128           0 :     if (mpDocShell)
     129             :     {
     130           0 :         const ScSheetEvents* pEvents = mpDocShell->GetDocument()->GetSheetEvents(mnTab);
     131           0 :         if (pEvents)
     132           0 :             pScript = pEvents->GetScript(nEvent);
     133             :     }
     134             : 
     135           0 :     uno::Any aRet;
     136           0 :     if (pScript)
     137             :     {
     138           0 :         uno::Sequence<beans::PropertyValue> aPropSeq( 2 );
     139           0 :         aPropSeq[0] = beans::PropertyValue(
     140             :                         OUString("EventType"), -1,
     141           0 :                         uno::makeAny( OUString("Script") ), beans::PropertyState_DIRECT_VALUE );
     142           0 :         aPropSeq[1] = beans::PropertyValue(
     143             :                         OUString("Script"), -1,
     144           0 :                         uno::makeAny( *pScript ), beans::PropertyState_DIRECT_VALUE );
     145           0 :         aRet <<= aPropSeq;
     146             :     }
     147             :     // empty Any if nothing was set
     148           0 :     return aRet;
     149             : }
     150             : 
     151           0 : uno::Sequence<OUString> SAL_CALL ScSheetEventsObj::getElementNames() throw(uno::RuntimeException, std::exception)
     152             : {
     153           0 :     SolarMutexGuard aGuard;
     154           0 :     uno::Sequence<OUString> aNames(SC_SHEETEVENT_COUNT);
     155           0 :     for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
     156           0 :         aNames[nEvent] = ScSheetEvents::GetEventName(nEvent);
     157           0 :     return aNames;
     158             : }
     159             : 
     160           0 : sal_Bool SAL_CALL ScSheetEventsObj::hasByName( const OUString& aName ) throw(uno::RuntimeException, std::exception)
     161             : {
     162           0 :     SolarMutexGuard aGuard;
     163           0 :     sal_Int32 nEvent = lcl_GetEventFromName(aName);
     164           0 :     return (nEvent >= 0);
     165             : }
     166             : 
     167             : // XElementAccess
     168             : 
     169           0 : uno::Type SAL_CALL ScSheetEventsObj::getElementType() throw(uno::RuntimeException, std::exception)
     170             : {
     171           0 :     SolarMutexGuard aGuard;
     172           0 :     return getCppuType((uno::Sequence<beans::PropertyValue>*)0);
     173             : }
     174             : 
     175           0 : sal_Bool SAL_CALL ScSheetEventsObj::hasElements() throw(uno::RuntimeException, std::exception)
     176             : {
     177           0 :     SolarMutexGuard aGuard;
     178           0 :     if (mpDocShell)
     179           0 :         return sal_True;
     180           0 :     return false;
     181             : }
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10