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

Generated by: LCOV version 1.10