LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - eventuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 89 0.0 %
Date: 2012-08-25 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 152 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2008 by Sun Microsystems, Inc.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "eventuno.hxx"
      31                 :            : #include "miscuno.hxx"
      32                 :            : #include "docsh.hxx"
      33                 :            : #include "sheetevents.hxx"
      34                 :            : #include "unonames.hxx"
      35                 :            : #include <vcl/svapp.hxx>
      36                 :            : 
      37                 :            : using namespace ::com::sun::star;
      38                 :            : 
      39                 :            : //------------------------------------------------------------------------
      40                 :            : 
      41         [ #  # ]:          0 : SC_SIMPLE_SERVICE_INFO( ScSheetEventsObj, "ScSheetEventsObj", "com.sun.star.document.Events" )
      42                 :            : 
      43                 :            : //------------------------------------------------------------------------
      44                 :            : 
      45                 :          0 : ScSheetEventsObj::ScSheetEventsObj(ScDocShell* pDocSh, SCTAB nT) :
      46                 :            :     mpDocShell( pDocSh ),
      47         [ #  # ]:          0 :     mnTab( nT )
      48                 :            : {
      49         [ #  # ]:          0 :     mpDocShell->GetDocument()->AddUnoObject(*this);
      50                 :          0 : }
      51                 :            : 
      52         [ #  # ]:          0 : ScSheetEventsObj::~ScSheetEventsObj()
      53                 :            : {
      54         [ #  # ]:          0 :     if (mpDocShell)
      55         [ #  # ]:          0 :         mpDocShell->GetDocument()->RemoveUnoObject(*this);
      56         [ #  # ]:          0 : }
      57                 :            : 
      58                 :          0 : void ScSheetEventsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
      59                 :            : {
      60                 :            :     //! reference update
      61   [ #  #  #  # ]:          0 :     if ( rHint.ISA( SfxSimpleHint ) &&
                 [ #  # ]
      62                 :          0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
      63                 :            :     {
      64                 :          0 :         mpDocShell = NULL;
      65                 :            :     }
      66                 :          0 : }
      67                 :            : 
      68                 :          0 : sal_Int32 lcl_GetEventFromName( const rtl::OUString& aName )
      69                 :            : {
      70         [ #  # ]:          0 :     for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
      71         [ #  # ]:          0 :         if ( aName == ScSheetEvents::GetEventName(nEvent) )
      72                 :          0 :             return nEvent;
      73                 :            : 
      74                 :          0 :     return -1;      // not found
      75                 :            : }
      76                 :            : 
      77                 :            : // XNameReplace
      78                 :            : 
      79                 :          0 : void SAL_CALL ScSheetEventsObj::replaceByName( const rtl::OUString& aName, const uno::Any& aElement )
      80                 :            :     throw(lang::IllegalArgumentException, container::NoSuchElementException,
      81                 :            :           lang::WrappedTargetException, uno::RuntimeException)
      82                 :            : {
      83         [ #  # ]:          0 :     SolarMutexGuard aGuard;
      84         [ #  # ]:          0 :     if (!mpDocShell)
      85         [ #  # ]:          0 :         throw uno::RuntimeException();
      86                 :            : 
      87         [ #  # ]:          0 :     sal_Int32 nEvent = lcl_GetEventFromName(aName);
      88         [ #  # ]:          0 :     if (nEvent < 0)
      89         [ #  # ]:          0 :         throw container::NoSuchElementException();
      90                 :            : 
      91         [ #  # ]:          0 :     ScSheetEvents aNewEvents;
      92         [ #  # ]:          0 :     const ScSheetEvents* pOldEvents = mpDocShell->GetDocument()->GetSheetEvents(mnTab);
      93         [ #  # ]:          0 :     if (pOldEvents)
      94         [ #  # ]:          0 :         aNewEvents = *pOldEvents;
      95                 :            : 
      96                 :          0 :     rtl::OUString aScript;
      97         [ #  # ]:          0 :     if ( aElement.hasValue() )      // empty Any -> reset event
      98                 :            :     {
      99         [ #  # ]:          0 :         uno::Sequence<beans::PropertyValue> aPropSeq;
     100 [ #  # ][ #  # ]:          0 :         if ( aElement >>= aPropSeq )
     101                 :            :         {
     102                 :          0 :             sal_Int32 nPropCount = aPropSeq.getLength();
     103         [ #  # ]:          0 :             for (sal_Int32 nPos=0; nPos<nPropCount; ++nPos)
     104                 :            :             {
     105         [ #  # ]:          0 :                 const beans::PropertyValue& rProp = aPropSeq[nPos];
     106         [ #  # ]:          0 :                 if ( rProp.Name.compareToAscii( SC_UNO_EVENTTYPE ) == 0 )
     107                 :            :                 {
     108                 :          0 :                     rtl::OUString aEventType;
     109         [ #  # ]:          0 :                     if ( rProp.Value >>= aEventType )
     110                 :            :                     {
     111                 :            :                         // only "Script" is supported
     112         [ #  # ]:          0 :                         if ( aEventType.compareToAscii( SC_UNO_SCRIPT ) != 0 )
     113         [ #  # ]:          0 :                             throw lang::IllegalArgumentException();
     114                 :          0 :                     }
     115                 :            :                 }
     116         [ #  # ]:          0 :                 else if ( rProp.Name.compareToAscii( SC_UNO_SCRIPT ) == 0 )
     117                 :          0 :                     rProp.Value >>= aScript;
     118                 :            :             }
     119         [ #  # ]:          0 :         }
     120                 :            :     }
     121         [ #  # ]:          0 :     if (!aScript.isEmpty())
     122         [ #  # ]:          0 :         aNewEvents.SetScript( nEvent, &aScript );
     123                 :            :     else
     124         [ #  # ]:          0 :         aNewEvents.SetScript( nEvent, NULL );       // reset
     125                 :            : 
     126         [ #  # ]:          0 :     mpDocShell->GetDocument()->SetSheetEvents( mnTab, &aNewEvents );
     127 [ #  # ][ #  # ]:          0 :     mpDocShell->SetDocumentModified();
                 [ #  # ]
     128                 :          0 : }
     129                 :            : 
     130                 :            : // XNameAccess
     131                 :            : 
     132                 :          0 : uno::Any SAL_CALL ScSheetEventsObj::getByName( const rtl::OUString& aName )
     133                 :            :     throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     134                 :            : {
     135         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     136         [ #  # ]:          0 :     sal_Int32 nEvent = lcl_GetEventFromName(aName);
     137         [ #  # ]:          0 :     if (nEvent < 0)
     138         [ #  # ]:          0 :         throw container::NoSuchElementException();
     139                 :            : 
     140                 :          0 :     const rtl::OUString* pScript = NULL;
     141         [ #  # ]:          0 :     if (mpDocShell)
     142                 :            :     {
     143         [ #  # ]:          0 :         const ScSheetEvents* pEvents = mpDocShell->GetDocument()->GetSheetEvents(mnTab);
     144         [ #  # ]:          0 :         if (pEvents)
     145         [ #  # ]:          0 :             pScript = pEvents->GetScript(nEvent);
     146                 :            :     }
     147                 :            : 
     148                 :          0 :     uno::Any aRet;
     149         [ #  # ]:          0 :     if (pScript)
     150                 :            :     {
     151         [ #  # ]:          0 :         uno::Sequence<beans::PropertyValue> aPropSeq( 2 );
     152         [ #  # ]:          0 :         aPropSeq[0] = beans::PropertyValue(
     153                 :            :                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EventType")), -1,
     154 [ #  # ][ #  # ]:          0 :                         uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Script")) ), beans::PropertyState_DIRECT_VALUE );
                 [ #  # ]
     155         [ #  # ]:          0 :         aPropSeq[1] = beans::PropertyValue(
     156                 :            :                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Script")), -1,
     157 [ #  # ][ #  # ]:          0 :                         uno::makeAny( *pScript ), beans::PropertyState_DIRECT_VALUE );
     158 [ #  # ][ #  # ]:          0 :         aRet <<= aPropSeq;
     159                 :            :     }
     160                 :            :     // empty Any if nothing was set
     161         [ #  # ]:          0 :     return aRet;
     162                 :            : }
     163                 :            : 
     164                 :          0 : uno::Sequence<rtl::OUString> SAL_CALL ScSheetEventsObj::getElementNames() throw(uno::RuntimeException)
     165                 :            : {
     166         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     167         [ #  # ]:          0 :     uno::Sequence<rtl::OUString> aNames(SC_SHEETEVENT_COUNT);
     168         [ #  # ]:          0 :     for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
     169 [ #  # ][ #  # ]:          0 :         aNames[nEvent] = ScSheetEvents::GetEventName(nEvent);
     170         [ #  # ]:          0 :     return aNames;
     171                 :            : }
     172                 :            : 
     173                 :          0 : sal_Bool SAL_CALL ScSheetEventsObj::hasByName( const ::rtl::OUString& aName ) throw(uno::RuntimeException)
     174                 :            : {
     175         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     176         [ #  # ]:          0 :     sal_Int32 nEvent = lcl_GetEventFromName(aName);
     177         [ #  # ]:          0 :     return (nEvent >= 0);
     178                 :            : }
     179                 :            : 
     180                 :            : // XElementAccess
     181                 :            : 
     182                 :          0 : uno::Type SAL_CALL ScSheetEventsObj::getElementType() throw(uno::RuntimeException)
     183                 :            : {
     184         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     185 [ #  # ][ #  # ]:          0 :     return getCppuType((uno::Sequence<beans::PropertyValue>*)0);
     186                 :            : }
     187                 :            : 
     188                 :          0 : sal_Bool SAL_CALL ScSheetEventsObj::hasElements() throw(uno::RuntimeException)
     189                 :            : {
     190         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     191         [ #  # ]:          0 :     if (mpDocShell)
     192                 :          0 :         return sal_True;
     193         [ #  # ]:          0 :     return false;
     194                 :            : }
     195                 :            : 
     196                 :            : 
     197                 :            : 
     198                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10