1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "eventexport.hxx"
21 #include <osl/diagnose.h>
22 #include "strings.hxx"
23 #include <tools/debug.hxx>
24 #include <comphelper/sequence.hxx>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::script
;
31 using namespace ::com::sun::star::container
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::lang
;
35 //= OEventDescriptorMapper
36 OEventDescriptorMapper::OEventDescriptorMapper(const Sequence
< ScriptEventDescriptor
>& _rEvents
)
38 sal_Int32 nEvents
= _rEvents
.getLength();
40 // translate the events
41 const ScriptEventDescriptor
* pEvents
= _rEvents
.getConstArray();
43 OUString sLibrary
, sLocalMacroName
;
44 for (sal_Int32 i
=0; i
<nEvents
; ++i
, ++pEvents
)
46 // the name of the event is build from listener interface and listener method name
47 sName
= pEvents
->ListenerType
;
48 sName
+= EVENT_NAME_SEPARATOR
;
49 sName
+= pEvents
->EventMethod
;
51 Sequence
< PropertyValue
>& rMappedEvent
= m_aMappedEvents
[sName
];
53 sLocalMacroName
= pEvents
->ScriptCode
;
55 if (pEvents
->ScriptType
== EVENT_STARBASIC
)
56 { // for StarBasic, the library name is part of the ScriptCode
57 sal_Int32 nPrefixLen
= sLocalMacroName
.indexOf( ':' );
58 DBG_ASSERT( 0 <= nPrefixLen
, "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
59 if ( 0 <= nPrefixLen
)
61 // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
62 sLibrary
= sLocalMacroName
.copy( 0, nPrefixLen
);
63 if (sLibrary
== EVENT_APPLICATION
)
64 sLibrary
= EVENT_STAROFFICE
;
66 sLocalMacroName
= sLocalMacroName
.copy( nPrefixLen
+ 1 );
68 // tree property values to describe one event ...
69 rMappedEvent
.realloc( sLibrary
.isEmpty() ? 2 : 3 );
72 rMappedEvent
[0] = PropertyValue(EVENT_TYPE
, -1, makeAny(pEvents
->ScriptType
), PropertyState_DIRECT_VALUE
);
75 rMappedEvent
[1] = PropertyValue(EVENT_LOCALMACRONAME
, -1, makeAny(sLocalMacroName
), PropertyState_DIRECT_VALUE
);
78 if ( !sLibrary
.isEmpty() )
79 rMappedEvent
[2] = PropertyValue(EVENT_LIBRARY
, -1, makeAny(sLibrary
), PropertyState_DIRECT_VALUE
);
83 rMappedEvent
.realloc( 2 );
84 rMappedEvent
[0] = PropertyValue(EVENT_TYPE
, -1, makeAny(pEvents
->ScriptType
), PropertyState_DIRECT_VALUE
);
86 rMappedEvent
[1] = PropertyValue(EVENT_SCRIPTURL
, -1, makeAny(pEvents
->ScriptCode
), PropertyState_DIRECT_VALUE
);
91 void SAL_CALL
OEventDescriptorMapper::replaceByName( const OUString
&, const Any
& ) throw(IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
93 throw IllegalArgumentException(
94 "replacing is not implemented for this wrapper class.", static_cast< ::cppu::OWeakObject
* >(this), 1);
97 Any SAL_CALL
OEventDescriptorMapper::getByName( const OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
99 MapString2PropertyValueSequence::const_iterator aPos
= m_aMappedEvents
.find(_rName
);
100 if (m_aMappedEvents
.end() == aPos
)
101 throw NoSuchElementException(
102 "There is no element named " + _rName
,
103 static_cast< ::cppu::OWeakObject
* >(this));
105 return makeAny(aPos
->second
);
108 Sequence
< OUString
> SAL_CALL
OEventDescriptorMapper::getElementNames( ) throw(RuntimeException
, std::exception
)
110 return comphelper::mapKeysToSequence(m_aMappedEvents
);
113 sal_Bool SAL_CALL
OEventDescriptorMapper::hasByName( const OUString
& _rName
) throw(RuntimeException
, std::exception
)
115 MapString2PropertyValueSequence::const_iterator aPos
= m_aMappedEvents
.find(_rName
);
116 return m_aMappedEvents
.end() != aPos
;
119 Type SAL_CALL
OEventDescriptorMapper::getElementType( ) throw(RuntimeException
, std::exception
)
121 return ::cppu::UnoType
<PropertyValue
>::get();
124 sal_Bool SAL_CALL
OEventDescriptorMapper::hasElements( ) throw(RuntimeException
, std::exception
)
126 return !m_aMappedEvents
.empty();
129 } // namespace xmloff
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */