LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/forms - eventimport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 54 3.7 %
Date: 2012-12-27 Functions: 1 6 16.7 %
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           0 :     OFormEventsImportContext::OFormEventsImportContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, IEventAttacher& _rEventAttacher)
      41             :         :XMLEventsImportContext(_rImport, _nPrefix, _rLocalName)
      42           0 :         ,m_rEventAttacher(_rEventAttacher)
      43             :     {
      44           0 :     }
      45             : 
      46             :     //---------------------------------------------------------------------
      47           0 :     void OFormEventsImportContext::EndElement()
      48             :     {
      49           0 :         Sequence< ScriptEventDescriptor > aTranslated(aCollectEvents.size());
      50           0 :         ScriptEventDescriptor* pTranslated = aTranslated.getArray();
      51             : 
      52             :         // loop through the collected events and translate them
      53             :         const PropertyValue* pEventDescription;
      54             :         const PropertyValue* pEventDescriptionEnd;
      55           0 :         sal_Int32 nSeparatorPos = -1;
      56           0 :         for (   EventsVector::const_iterator aEvent = aCollectEvents.begin();
      57           0 :                 aEvent != aCollectEvents.end();
      58             :                 ++aEvent, ++pTranslated
      59             :             )
      60             :         {
      61             :             // the name of the event is built from ListenerType::EventMethod
      62           0 :             nSeparatorPos = aEvent->first.indexOf(EVENT_NAME_SEPARATOR);
      63             :             OSL_ENSURE(-1 != nSeparatorPos, "OFormEventsImportContext::EndElement: invalid (unrecognized) event name!");
      64           0 :             pTranslated->ListenerType = aEvent->first.copy(0, nSeparatorPos);
      65           0 :             pTranslated->EventMethod = aEvent->first.copy(nSeparatorPos + EVENT_NAME_SEPARATOR.length);
      66             : 
      67           0 :             ::rtl::OUString sLibrary;
      68             : 
      69             :             // the local macro name and the event type are specified as properties
      70           0 :             pEventDescription       =                       aEvent->second.getConstArray();
      71           0 :             pEventDescriptionEnd    =   pEventDescription + aEvent->second.getLength();
      72           0 :             for (;pEventDescription != pEventDescriptionEnd; ++pEventDescription)
      73             :             {
      74           0 :                 if ((pEventDescription->Name.equalsAsciiL(EVENT_LOCALMACRONAME.ascii, EVENT_LOCALMACRONAME.length)) ||
      75           0 :                     (pEventDescription->Name.equalsAsciiL(EVENT_SCRIPTURL.ascii, EVENT_SCRIPTURL.length)))
      76           0 :                     pEventDescription->Value >>= pTranslated->ScriptCode;
      77           0 :                 else if (pEventDescription->Name.equalsAsciiL(EVENT_TYPE.ascii, EVENT_TYPE.length))
      78           0 :                     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           0 :             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           0 :         }
      98             : 
      99             :         // register the events
     100           0 :         m_rEventAttacher.registerEvents(aTranslated);
     101             : 
     102           0 :         XMLEventsImportContext::EndElement();
     103           0 :     }
     104             : 
     105             :     //=====================================================================
     106             :     //= ODefaultEventAttacherManager
     107             :     //=====================================================================
     108             : 
     109          82 :     ODefaultEventAttacherManager::~ODefaultEventAttacherManager()
     110             :     {
     111          82 :     }
     112             : 
     113             :     //-------------------------------------------------------------------------
     114           0 :     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           0 :         m_aEvents[_rxElement] = _rEvents;
     121           0 :     }
     122             : 
     123             :     //-------------------------------------------------------------------------
     124           0 :     void ODefaultEventAttacherManager::setEvents(const Reference< XIndexAccess >& _rxContainer)
     125             :     {
     126           0 :         Reference< XEventAttacherManager > xEventManager(_rxContainer, UNO_QUERY);
     127           0 :         if (!xEventManager.is())
     128             :         {
     129             :             OSL_FAIL("ODefaultEventAttacherManager::setEvents: invalid argument!");
     130           0 :             return;
     131             :         }
     132             : 
     133             :         // loop through all elements
     134           0 :         sal_Int32 nCount = _rxContainer->getCount();
     135           0 :         Reference< XPropertySet > xCurrent;
     136           0 :         ConstMapPropertySet2ScriptSequenceIterator aRegisteredEventsPos;
     137           0 :         for (sal_Int32 i=0; i<nCount; ++i)
     138             :         {
     139           0 :             ::cppu::extractInterface(xCurrent, _rxContainer->getByIndex(i));
     140           0 :             if (xCurrent.is())
     141             :             {
     142           0 :                 aRegisteredEventsPos = m_aEvents.find(xCurrent);
     143           0 :                 if (m_aEvents.end() != aRegisteredEventsPos)
     144           0 :                     xEventManager->registerScriptEvents(i, aRegisteredEventsPos->second);
     145             :             }
     146           0 :         }
     147             :     }
     148             : 
     149             : //.........................................................................
     150             : }   // namespace xmloff
     151             : //.........................................................................
     152             : 
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10