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

Generated by: LCOV version 1.10