LCOV - code coverage report
Current view: top level - xmloff/source/forms - eventimport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 54 98.1 %
Date: 2014-11-03 Functions: 5 6 83.3 %
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 "eventimport.hxx"
      21             : #include <com/sun/star/script/XEventAttacherManager.hpp>
      22             : #include <com/sun/star/beans/PropertyValue.hpp>
      23             : #include "strings.hxx"
      24             : 
      25             : namespace xmloff
      26             : {
      27             : 
      28             :     using namespace ::com::sun::star::uno;
      29             :     using namespace ::com::sun::star::beans;
      30             :     using namespace ::com::sun::star::script;
      31             :     using namespace ::com::sun::star::container;
      32             : 
      33             :     //= OFormEventsImportContext
      34          16 :     OFormEventsImportContext::OFormEventsImportContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rLocalName, IEventAttacher& _rEventAttacher)
      35             :         :XMLEventsImportContext(_rImport, _nPrefix, _rLocalName)
      36          16 :         ,m_rEventAttacher(_rEventAttacher)
      37             :     {
      38          16 :     }
      39             : 
      40          16 :     void OFormEventsImportContext::EndElement()
      41             :     {
      42          16 :         Sequence< ScriptEventDescriptor > aTranslated(aCollectEvents.size());
      43          16 :         ScriptEventDescriptor* pTranslated = aTranslated.getArray();
      44             : 
      45             :         // loop through the collected events and translate them
      46             :         const PropertyValue* pEventDescription;
      47             :         const PropertyValue* pEventDescriptionEnd;
      48          16 :         sal_Int32 nSeparatorPos = -1;
      49          96 :         for (   EventsVector::const_iterator aEvent = aCollectEvents.begin();
      50          64 :                 aEvent != aCollectEvents.end();
      51             :                 ++aEvent, ++pTranslated
      52             :             )
      53             :         {
      54             :             // the name of the event is built from ListenerType::EventMethod
      55          16 :             nSeparatorPos = aEvent->first.indexOf(EVENT_NAME_SEPARATOR);
      56             :             OSL_ENSURE(-1 != nSeparatorPos, "OFormEventsImportContext::EndElement: invalid (unrecognized) event name!");
      57          16 :             pTranslated->ListenerType = aEvent->first.copy(0, nSeparatorPos);
      58          16 :             pTranslated->EventMethod = aEvent->first.copy(nSeparatorPos + sizeof(EVENT_NAME_SEPARATOR) - 1);
      59             : 
      60          16 :             OUString sLibrary;
      61             : 
      62             :             // the local macro name and the event type are specified as properties
      63          16 :             pEventDescription       =                       aEvent->second.getConstArray();
      64          16 :             pEventDescriptionEnd    =   pEventDescription + aEvent->second.getLength();
      65          54 :             for (;pEventDescription != pEventDescriptionEnd; ++pEventDescription)
      66             :             {
      67         140 :                 if ((pEventDescription->Name.equals(EVENT_LOCALMACRONAME)) ||
      68         102 :                     (pEventDescription->Name.equals(EVENT_SCRIPTURL)))
      69          16 :                     pEventDescription->Value >>= pTranslated->ScriptCode;
      70          22 :                 else if (pEventDescription->Name.equals(EVENT_TYPE))
      71          16 :                     pEventDescription->Value >>= pTranslated->ScriptType;
      72           6 :                 else if (pEventDescription->Name.equals(EVENT_LIBRARY))
      73           6 :                     pEventDescription->Value >>= sLibrary;
      74             :             }
      75             : 
      76          16 :             if (pTranslated->ScriptType.equals(EVENT_STARBASIC))
      77             :             {
      78           6 :                 if (sLibrary.equals(EVENT_STAROFFICE))
      79           0 :                     sLibrary = EVENT_APPLICATION;
      80             : 
      81           6 :                 if ( !sLibrary.isEmpty() )
      82             :                 {
      83             :                     // for StarBasic, the library is prepended
      84           6 :                     sal_Unicode cLibSeparator = ':';
      85           6 :                     sLibrary += OUString( &cLibSeparator, 1 );
      86             :                 }
      87           6 :                 sLibrary += pTranslated->ScriptCode;
      88           6 :                 pTranslated->ScriptCode = sLibrary;
      89             :             }
      90          16 :         }
      91             : 
      92             :         // register the events
      93          16 :         m_rEventAttacher.registerEvents(aTranslated);
      94             : 
      95          16 :         XMLEventsImportContext::EndElement();
      96          16 :     }
      97             : 
      98             :     //= ODefaultEventAttacherManager
      99             : 
     100        1762 :     ODefaultEventAttacherManager::~ODefaultEventAttacherManager()
     101             :     {
     102        1762 :     }
     103             : 
     104          16 :     void ODefaultEventAttacherManager::registerEvents(const Reference< XPropertySet >& _rxElement,
     105             :         const Sequence< ScriptEventDescriptor >& _rEvents)
     106             :     {
     107             :         OSL_ENSURE(m_aEvents.end() == m_aEvents.find(_rxElement),
     108             :             "ODefaultEventAttacherManager::registerEvents: already have events for this object!");
     109             :         // for the moment, only remember the script events
     110          16 :         m_aEvents[_rxElement] = _rEvents;
     111          16 :     }
     112             : 
     113          36 :     void ODefaultEventAttacherManager::setEvents(const Reference< XIndexAccess >& _rxContainer)
     114             :     {
     115          36 :         Reference< XEventAttacherManager > xEventManager(_rxContainer, UNO_QUERY);
     116          36 :         if (!xEventManager.is())
     117             :         {
     118             :             OSL_FAIL("ODefaultEventAttacherManager::setEvents: invalid argument!");
     119          36 :             return;
     120             :         }
     121             : 
     122             :         // loop through all elements
     123          36 :         sal_Int32 nCount = _rxContainer->getCount();
     124          72 :         Reference< XPropertySet > xCurrent;
     125          36 :         MapPropertySet2ScriptSequence::const_iterator aRegisteredEventsPos;
     126         112 :         for (sal_Int32 i=0; i<nCount; ++i)
     127             :         {
     128          76 :             xCurrent.set(_rxContainer->getByIndex(i), css::uno::UNO_QUERY);
     129          76 :             if (xCurrent.is())
     130             :             {
     131          76 :                 aRegisteredEventsPos = m_aEvents.find(xCurrent);
     132          76 :                 if (m_aEvents.end() != aRegisteredEventsPos)
     133          16 :                     xEventManager->registerScriptEvents(i, aRegisteredEventsPos->second);
     134             :             }
     135          36 :         }
     136             :     }
     137             : 
     138             : }   // namespace xmloff
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10