Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / xmloff / source / forms / eventimport.cxx
blobae909fd9e9c07665e3f68ee270ffe6572a02bff7
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 <osl/diagnose.h>
24 #include "strings.hxx"
26 namespace xmloff
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::script;
32 using namespace ::com::sun::star::container;
34 //= OFormEventsImportContext
35 OFormEventsImportContext::OFormEventsImportContext(SvXMLImport& _rImport, IEventAttacher& _rEventAttacher)
36 :XMLEventsImportContext(_rImport)
37 ,m_rEventAttacher(_rEventAttacher)
41 void OFormEventsImportContext::endFastElement(sal_Int32 )
43 Sequence< ScriptEventDescriptor > aTranslated(m_aCollectEvents.size());
44 ScriptEventDescriptor* pTranslated = aTranslated.getArray();
46 // loop through the collected events and translate them
47 sal_Int32 nSeparatorPos = -1;
48 for ( const auto& rEvent : m_aCollectEvents )
50 // the name of the event is built from ListenerType::EventMethod
51 nSeparatorPos = rEvent.first.indexOf(EVENT_NAME_SEPARATOR);
52 OSL_ENSURE(-1 != nSeparatorPos, "OFormEventsImportContext::EndElement: invalid (unrecognized) event name!");
53 pTranslated->ListenerType = rEvent.first.copy(0, nSeparatorPos);
54 pTranslated->EventMethod = rEvent.first.copy(nSeparatorPos + sizeof(EVENT_NAME_SEPARATOR) - 1);
56 OUString sLibrary;
58 // the local macro name and the event type are specified as properties
59 const PropertyValue* pEventDescription = rEvent.second.getConstArray();
60 const PropertyValue* pEventDescriptionEnd = pEventDescription + rEvent.second.getLength();
61 for (;pEventDescription != pEventDescriptionEnd; ++pEventDescription)
63 if (pEventDescription->Name == EVENT_LOCALMACRONAME ||
64 pEventDescription->Name == EVENT_SCRIPTURL)
65 pEventDescription->Value >>= pTranslated->ScriptCode;
66 else if (pEventDescription->Name == EVENT_TYPE)
67 pEventDescription->Value >>= pTranslated->ScriptType;
68 else if (pEventDescription->Name == EVENT_LIBRARY)
69 pEventDescription->Value >>= sLibrary;
72 if (pTranslated->ScriptType == EVENT_STARBASIC)
74 if (sLibrary == EVENT_STAROFFICE)
75 sLibrary = EVENT_APPLICATION;
77 if ( !sLibrary.isEmpty() )
79 // for StarBasic, the library is prepended
80 sLibrary += ":";
82 sLibrary += pTranslated->ScriptCode;
83 pTranslated->ScriptCode = sLibrary;
86 ++pTranslated;
89 // register the events
90 m_rEventAttacher.registerEvents(aTranslated);
93 //= ODefaultEventAttacherManager
95 ODefaultEventAttacherManager::~ODefaultEventAttacherManager()
99 void ODefaultEventAttacherManager::registerEvents(const Reference< XPropertySet >& _rxElement,
100 const Sequence< ScriptEventDescriptor >& _rEvents)
102 OSL_ENSURE(m_aEvents.end() == m_aEvents.find(_rxElement),
103 "ODefaultEventAttacherManager::registerEvents: already have events for this object!");
104 // for the moment, only remember the script events
105 m_aEvents[_rxElement] = _rEvents;
108 void ODefaultEventAttacherManager::setEvents(const Reference< XIndexAccess >& _rxContainer)
110 Reference< XEventAttacherManager > xEventManager(_rxContainer, UNO_QUERY);
111 if (!xEventManager.is())
113 OSL_FAIL("ODefaultEventAttacherManager::setEvents: invalid argument!");
114 return;
117 // loop through all elements
118 sal_Int32 nCount = _rxContainer->getCount();
119 Reference< XPropertySet > xCurrent;
120 MapPropertySet2ScriptSequence::const_iterator aRegisteredEventsPos;
121 for (sal_Int32 i=0; i<nCount; ++i)
123 xCurrent.set(_rxContainer->getByIndex(i), css::uno::UNO_QUERY);
124 if (xCurrent.is())
126 aRegisteredEventsPos = m_aEvents.find(xCurrent);
127 if (m_aEvents.end() != aRegisteredEventsPos)
128 xEventManager->registerScriptEvents(i, aRegisteredEventsPos->second);
133 } // namespace xmloff
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */