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

Generated by: LCOV version 1.11