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

Generated by: LCOV version 1.10