bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / forms / eventimport.cxx
blobd61fe5f4f9b77ac41accd910a40e5c77ecfda943
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
26 //.........................................................................
27 namespace xmloff
29 //.........................................................................
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;
36 //=====================================================================
37 //= OFormEventsImportContext
38 //=====================================================================
39 //---------------------------------------------------------------------
40 OFormEventsImportContext::OFormEventsImportContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rLocalName, IEventAttacher& _rEventAttacher)
41 :XMLEventsImportContext(_rImport, _nPrefix, _rLocalName)
42 ,m_rEventAttacher(_rEventAttacher)
46 //---------------------------------------------------------------------
47 void OFormEventsImportContext::EndElement()
49 Sequence< ScriptEventDescriptor > aTranslated(aCollectEvents.size());
50 ScriptEventDescriptor* pTranslated = aTranslated.getArray();
52 // loop through the collected events and translate them
53 const PropertyValue* pEventDescription;
54 const PropertyValue* pEventDescriptionEnd;
55 sal_Int32 nSeparatorPos = -1;
56 for ( EventsVector::const_iterator aEvent = aCollectEvents.begin();
57 aEvent != aCollectEvents.end();
58 ++aEvent, ++pTranslated
61 // the name of the event is built from ListenerType::EventMethod
62 nSeparatorPos = aEvent->first.indexOf(EVENT_NAME_SEPARATOR);
63 OSL_ENSURE(-1 != nSeparatorPos, "OFormEventsImportContext::EndElement: invalid (unrecognized) event name!");
64 pTranslated->ListenerType = aEvent->first.copy(0, nSeparatorPos);
65 pTranslated->EventMethod = aEvent->first.copy(nSeparatorPos + sizeof(EVENT_NAME_SEPARATOR) - 1);
67 OUString sLibrary;
69 // the local macro name and the event type are specified as properties
70 pEventDescription = aEvent->second.getConstArray();
71 pEventDescriptionEnd = pEventDescription + aEvent->second.getLength();
72 for (;pEventDescription != pEventDescriptionEnd; ++pEventDescription)
74 if ((pEventDescription->Name.equals(EVENT_LOCALMACRONAME)) ||
75 (pEventDescription->Name.equals(EVENT_SCRIPTURL)))
76 pEventDescription->Value >>= pTranslated->ScriptCode;
77 else if (pEventDescription->Name.equals(EVENT_TYPE))
78 pEventDescription->Value >>= pTranslated->ScriptType;
79 else if (pEventDescription->Name.equals(EVENT_LIBRARY))
80 pEventDescription->Value >>= sLibrary;
83 if (pTranslated->ScriptType.equals(EVENT_STARBASIC))
85 if (sLibrary.equals(EVENT_STAROFFICE))
86 sLibrary = EVENT_APPLICATION;
88 if ( !sLibrary.isEmpty() )
90 // for StarBasic, the library is prepended
91 sal_Unicode cLibSeparator = ':';
92 sLibrary += OUString( &cLibSeparator, 1 );
94 sLibrary += pTranslated->ScriptCode;
95 pTranslated->ScriptCode = sLibrary;
99 // register the events
100 m_rEventAttacher.registerEvents(aTranslated);
102 XMLEventsImportContext::EndElement();
105 //=====================================================================
106 //= ODefaultEventAttacherManager
107 //=====================================================================
109 ODefaultEventAttacherManager::~ODefaultEventAttacherManager()
113 //-------------------------------------------------------------------------
114 void ODefaultEventAttacherManager::registerEvents(const Reference< XPropertySet >& _rxElement,
115 const Sequence< ScriptEventDescriptor >& _rEvents)
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 m_aEvents[_rxElement] = _rEvents;
123 //-------------------------------------------------------------------------
124 void ODefaultEventAttacherManager::setEvents(const Reference< XIndexAccess >& _rxContainer)
126 Reference< XEventAttacherManager > xEventManager(_rxContainer, UNO_QUERY);
127 if (!xEventManager.is())
129 OSL_FAIL("ODefaultEventAttacherManager::setEvents: invalid argument!");
130 return;
133 // loop through all elements
134 sal_Int32 nCount = _rxContainer->getCount();
135 Reference< XPropertySet > xCurrent;
136 ConstMapPropertySet2ScriptSequenceIterator aRegisteredEventsPos;
137 for (sal_Int32 i=0; i<nCount; ++i)
139 ::cppu::extractInterface(xCurrent, _rxContainer->getByIndex(i));
140 if (xCurrent.is())
142 aRegisteredEventsPos = m_aEvents.find(xCurrent);
143 if (m_aEvents.end() != aRegisteredEventsPos)
144 xEventManager->registerScriptEvents(i, aRegisteredEventsPos->second);
149 //.........................................................................
150 } // namespace xmloff
151 //.........................................................................
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */