Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "eventimport.hxx"
30 : : #include <com/sun/star/script/XEventAttacherManager.hpp>
31 : : #include <com/sun/star/beans/PropertyValue.hpp>
32 : : #include <comphelper/extract.hxx>
33 : : #include "strings.hxx"
34 : :
35 : : //.........................................................................
36 : : namespace xmloff
37 : : {
38 : : //.........................................................................
39 : :
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::beans;
42 : : using namespace ::com::sun::star::script;
43 : : using namespace ::com::sun::star::container;
44 : :
45 : : //=====================================================================
46 : : //= OFormEventsImportContext
47 : : //=====================================================================
48 : : //---------------------------------------------------------------------
49 : 14 : OFormEventsImportContext::OFormEventsImportContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, IEventAttacher& _rEventAttacher)
50 : : :XMLEventsImportContext(_rImport, _nPrefix, _rLocalName)
51 : 14 : ,m_rEventAttacher(_rEventAttacher)
52 : : {
53 : 14 : }
54 : :
55 : : //---------------------------------------------------------------------
56 : 14 : void OFormEventsImportContext::EndElement()
57 : : {
58 [ + - ]: 14 : Sequence< ScriptEventDescriptor > aTranslated(aCollectEvents.size());
59 [ + - ]: 14 : ScriptEventDescriptor* pTranslated = aTranslated.getArray();
60 : :
61 : : // loop through the collected events and translate them
62 : : const PropertyValue* pEventDescription;
63 : : const PropertyValue* pEventDescriptionEnd;
64 : 14 : sal_Int32 nSeparatorPos = -1;
65 [ + - ][ + - ]: 56 : for ( EventsVector::const_iterator aEvent = aCollectEvents.begin();
[ + + ]
66 : 28 : aEvent != aCollectEvents.end();
67 : : ++aEvent, ++pTranslated
68 : : )
69 : : {
70 : : // the name of the event is built from ListenerType::EventMethod
71 [ + - ]: 14 : nSeparatorPos = aEvent->first.indexOf(EVENT_NAME_SEPARATOR);
72 : : OSL_ENSURE(-1 != nSeparatorPos, "OFormEventsImportContext::EndElement: invalid (unrecognized) event name!");
73 : 14 : pTranslated->ListenerType = aEvent->first.copy(0, nSeparatorPos);
74 : 14 : pTranslated->EventMethod = aEvent->first.copy(nSeparatorPos + EVENT_NAME_SEPARATOR.length);
75 : :
76 : 14 : ::rtl::OUString sLibrary;
77 : :
78 : : // the local macro name and the event type are specified as properties
79 : 14 : pEventDescription = aEvent->second.getConstArray();
80 : 14 : pEventDescriptionEnd = pEventDescription + aEvent->second.getLength();
81 [ + + ]: 48 : for (;pEventDescription != pEventDescriptionEnd; ++pEventDescription)
82 : : {
83 [ + + + + ]: 62 : if ((pEventDescription->Name.equalsAsciiL(EVENT_LOCALMACRONAME.ascii, EVENT_LOCALMACRONAME.length)) ||
[ + + ]
84 : 28 : (pEventDescription->Name.equalsAsciiL(EVENT_SCRIPTURL.ascii, EVENT_SCRIPTURL.length)))
85 : 14 : pEventDescription->Value >>= pTranslated->ScriptCode;
86 [ + + ]: 20 : else if (pEventDescription->Name.equalsAsciiL(EVENT_TYPE.ascii, EVENT_TYPE.length))
87 : 14 : pEventDescription->Value >>= pTranslated->ScriptType;
88 [ + - ]: 6 : else if (pEventDescription->Name.equalsAsciiL(EVENT_LIBRARY.ascii, EVENT_LIBRARY.length))
89 : 6 : pEventDescription->Value >>= sLibrary;
90 : : }
91 : :
92 [ + + ]: 14 : if (pTranslated->ScriptType.equalsAsciiL(EVENT_STARBASIC.ascii, EVENT_STARBASIC.length))
93 : : {
94 [ - + ]: 6 : if (sLibrary.equalsAsciiL(EVENT_STAROFFICE.ascii, EVENT_STAROFFICE.length))
95 [ # # ]: 0 : sLibrary = EVENT_APPLICATION;
96 : :
97 [ + - ]: 6 : if ( !sLibrary.isEmpty() )
98 : : {
99 : : // for StarBasic, the library is prepended
100 : 6 : sal_Unicode cLibSeparator = ':';
101 : 6 : sLibrary += ::rtl::OUString( &cLibSeparator, 1 );
102 : : }
103 : 6 : sLibrary += pTranslated->ScriptCode;
104 : 6 : pTranslated->ScriptCode = sLibrary;
105 : : }
106 : 14 : }
107 : :
108 : : // register the events
109 [ + - ]: 14 : m_rEventAttacher.registerEvents(aTranslated);
110 : :
111 [ + - ][ + - ]: 14 : XMLEventsImportContext::EndElement();
112 : 14 : }
113 : :
114 : : //=====================================================================
115 : : //= ODefaultEventAttacherManager
116 : : //=====================================================================
117 : :
118 : 366 : ODefaultEventAttacherManager::~ODefaultEventAttacherManager()
119 : : {
120 [ - + ]: 366 : }
121 : :
122 : : //-------------------------------------------------------------------------
123 : 14 : void ODefaultEventAttacherManager::registerEvents(const Reference< XPropertySet >& _rxElement,
124 : : const Sequence< ScriptEventDescriptor >& _rEvents)
125 : : {
126 : : OSL_ENSURE(m_aEvents.end() == m_aEvents.find(_rxElement),
127 : : "ODefaultEventAttacherManager::registerEvents: already have events for this object!");
128 : : // for the moment, only remember the script events
129 : 14 : m_aEvents[_rxElement] = _rEvents;
130 : 14 : }
131 : :
132 : : //-------------------------------------------------------------------------
133 : 24 : void ODefaultEventAttacherManager::setEvents(const Reference< XIndexAccess >& _rxContainer)
134 : : {
135 [ + - ]: 24 : Reference< XEventAttacherManager > xEventManager(_rxContainer, UNO_QUERY);
136 [ - + ]: 24 : if (!xEventManager.is())
137 : : {
138 : : OSL_FAIL("ODefaultEventAttacherManager::setEvents: invalid argument!");
139 : 24 : return;
140 : : }
141 : :
142 : : // loop through all elements
143 [ + - ][ + - ]: 24 : sal_Int32 nCount = _rxContainer->getCount();
144 : 24 : Reference< XPropertySet > xCurrent;
145 : 24 : ConstMapPropertySet2ScriptSequenceIterator aRegisteredEventsPos;
146 [ + + ]: 73 : for (sal_Int32 i=0; i<nCount; ++i)
147 : : {
148 [ + - ][ + - ]: 49 : ::cppu::extractInterface(xCurrent, _rxContainer->getByIndex(i));
[ + - ]
149 [ + - ]: 49 : if (xCurrent.is())
150 : : {
151 [ + - ]: 49 : aRegisteredEventsPos = m_aEvents.find(xCurrent);
152 [ + + ]: 49 : if (m_aEvents.end() != aRegisteredEventsPos)
153 [ + - ][ + - ]: 14 : xEventManager->registerScriptEvents(i, aRegisteredEventsPos->second);
154 : : }
155 [ + - ]: 24 : }
156 : : }
157 : :
158 : : //.........................................................................
159 : : } // namespace xmloff
160 : : //.........................................................................
161 : :
162 : :
163 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|