/src/libreoffice/xmloff/source/forms/eventimport.cxx
Line | Count | Source |
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 <osl/diagnose.h> |
24 | | #include "strings.hxx" |
25 | | |
26 | | namespace xmloff |
27 | | { |
28 | | |
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; |
33 | | |
34 | | //= OFormEventsImportContext |
35 | | OFormEventsImportContext::OFormEventsImportContext(SvXMLImport& _rImport, IEventAttacher& _rEventAttacher) |
36 | 0 | :XMLEventsImportContext(_rImport) |
37 | 0 | ,m_rEventAttacher(_rEventAttacher) |
38 | 0 | { |
39 | 0 | } |
40 | | |
41 | | void OFormEventsImportContext::endFastElement(sal_Int32 ) |
42 | 0 | { |
43 | 0 | Sequence< ScriptEventDescriptor > aTranslated(m_aCollectEvents.size()); |
44 | 0 | ScriptEventDescriptor* pTranslated = aTranslated.getArray(); |
45 | | |
46 | | // loop through the collected events and translate them |
47 | 0 | sal_Int32 nSeparatorPos = -1; |
48 | 0 | for ( const auto& rEvent : m_aCollectEvents ) |
49 | 0 | { |
50 | | // the name of the event is built from ListenerType::EventMethod |
51 | 0 | nSeparatorPos = rEvent.first.indexOf(EVENT_NAME_SEPARATOR); |
52 | 0 | OSL_ENSURE(-1 != nSeparatorPos, "OFormEventsImportContext::EndElement: invalid (unrecognized) event name!"); |
53 | 0 | pTranslated->ListenerType = rEvent.first.copy(0, nSeparatorPos); |
54 | 0 | pTranslated->EventMethod = rEvent.first.copy(nSeparatorPos + sizeof(EVENT_NAME_SEPARATOR) - 1); |
55 | |
|
56 | 0 | OUString sLibrary; |
57 | | |
58 | | // the local macro name and the event type are specified as properties |
59 | 0 | const PropertyValue* pEventDescription = rEvent.second.getConstArray(); |
60 | 0 | const PropertyValue* pEventDescriptionEnd = pEventDescription + rEvent.second.getLength(); |
61 | 0 | for (;pEventDescription != pEventDescriptionEnd; ++pEventDescription) |
62 | 0 | { |
63 | 0 | if (pEventDescription->Name == EVENT_LOCALMACRONAME || |
64 | 0 | pEventDescription->Name == EVENT_SCRIPTURL) |
65 | 0 | pEventDescription->Value >>= pTranslated->ScriptCode; |
66 | 0 | else if (pEventDescription->Name == EVENT_TYPE) |
67 | 0 | pEventDescription->Value >>= pTranslated->ScriptType; |
68 | 0 | else if (pEventDescription->Name == EVENT_LIBRARY) |
69 | 0 | pEventDescription->Value >>= sLibrary; |
70 | 0 | } |
71 | |
|
72 | 0 | if (pTranslated->ScriptType == EVENT_STARBASIC) |
73 | 0 | { |
74 | 0 | if (sLibrary == EVENT_STAROFFICE) |
75 | 0 | sLibrary = EVENT_APPLICATION; |
76 | |
|
77 | 0 | if ( !sLibrary.isEmpty() ) |
78 | 0 | { |
79 | | // for StarBasic, the library is prepended |
80 | 0 | sLibrary += ":"; |
81 | 0 | } |
82 | 0 | sLibrary += pTranslated->ScriptCode; |
83 | 0 | pTranslated->ScriptCode = sLibrary; |
84 | 0 | } |
85 | |
|
86 | 0 | ++pTranslated; |
87 | 0 | } |
88 | | |
89 | | // register the events |
90 | 0 | m_rEventAttacher.registerEvents(aTranslated); |
91 | 0 | } |
92 | | |
93 | | //= ODefaultEventAttacherManager |
94 | | |
95 | | ODefaultEventAttacherManager::~ODefaultEventAttacherManager() |
96 | 14.7k | { |
97 | 14.7k | } |
98 | | |
99 | | void ODefaultEventAttacherManager::registerEvents(const Reference< XPropertySet >& _rxElement, |
100 | | const Sequence< ScriptEventDescriptor >& _rEvents) |
101 | 0 | { |
102 | 0 | OSL_ENSURE(m_aEvents.end() == m_aEvents.find(_rxElement), |
103 | 0 | "ODefaultEventAttacherManager::registerEvents: already have events for this object!"); |
104 | | // for the moment, only remember the script events |
105 | 0 | m_aEvents[_rxElement] = _rEvents; |
106 | 0 | } |
107 | | |
108 | | void ODefaultEventAttacherManager::setEvents(const Reference< XIndexAccess >& _rxContainer) |
109 | 0 | { |
110 | 0 | Reference< XEventAttacherManager > xEventManager(_rxContainer, UNO_QUERY); |
111 | 0 | if (!xEventManager.is()) |
112 | 0 | { |
113 | 0 | OSL_FAIL("ODefaultEventAttacherManager::setEvents: invalid argument!"); |
114 | 0 | return; |
115 | 0 | } |
116 | | |
117 | | // loop through all elements |
118 | 0 | sal_Int32 nCount = _rxContainer->getCount(); |
119 | 0 | Reference< XPropertySet > xCurrent; |
120 | 0 | MapPropertySet2ScriptSequence::const_iterator aRegisteredEventsPos; |
121 | 0 | for (sal_Int32 i=0; i<nCount; ++i) |
122 | 0 | { |
123 | 0 | xCurrent.set(_rxContainer->getByIndex(i), css::uno::UNO_QUERY); |
124 | 0 | if (xCurrent.is()) |
125 | 0 | { |
126 | 0 | aRegisteredEventsPos = m_aEvents.find(xCurrent); |
127 | 0 | if (m_aEvents.end() != aRegisteredEventsPos) |
128 | 0 | xEventManager->registerScriptEvents(i, aRegisteredEventsPos->second); |
129 | 0 | } |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | | } // namespace xmloff |
134 | | |
135 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |