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>
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::script
;
30 using namespace ::com::sun::star::container
;
31 using namespace ::com::sun::star::beans
;
32 using namespace ::com::sun::star::lang
;
34 //= OEventDescriptorMapper
35 OEventDescriptorMapper::OEventDescriptorMapper(const Sequence
< ScriptEventDescriptor
>& _rEvents
)
37 sal_Int32 nEvents
= _rEvents
.getLength();
39 // translate the events
40 const ScriptEventDescriptor
* pEvents
= _rEvents
.getConstArray();
42 OUString sLibrary
, sLocalMacroName
;
43 for (sal_Int32 i
=0; i
<nEvents
; ++i
, ++pEvents
)
45 // the name of the event is build from listener interface and listener method name
46 sName
= pEvents
->ListenerType
;
47 sName
+= EVENT_NAME_SEPARATOR
;
48 sName
+= pEvents
->EventMethod
;
50 Sequence
< PropertyValue
>& rMappedEvent
= m_aMappedEvents
[sName
];
52 sLocalMacroName
= pEvents
->ScriptCode
;
54 if (pEvents
->ScriptType
== EVENT_STARBASIC
)
55 { // for StarBasic, the library name is part of the ScriptCode
56 sal_Int32 nPrefixLen
= sLocalMacroName
.indexOf( ':' );
57 DBG_ASSERT( 0 <= nPrefixLen
, "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
58 if ( 0 <= nPrefixLen
)
60 // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
61 sLibrary
= sLocalMacroName
.copy( 0, nPrefixLen
);
62 if (sLibrary
== EVENT_APPLICATION
)
63 sLibrary
= EVENT_STAROFFICE
;
65 sLocalMacroName
= sLocalMacroName
.copy( nPrefixLen
+ 1 );
67 // tree property values to describe one event ...
68 rMappedEvent
.realloc( sLibrary
.isEmpty() ? 2 : 3 );
71 rMappedEvent
[0] = PropertyValue(EVENT_TYPE
, -1, makeAny(pEvents
->ScriptType
), PropertyState_DIRECT_VALUE
);
74 rMappedEvent
[1] = PropertyValue(EVENT_LOCALMACRONAME
, -1, makeAny(sLocalMacroName
), PropertyState_DIRECT_VALUE
);
77 if ( !sLibrary
.isEmpty() )
78 rMappedEvent
[2] = PropertyValue(EVENT_LIBRARY
, -1, makeAny(sLibrary
), PropertyState_DIRECT_VALUE
);
82 rMappedEvent
.realloc( 2 );
83 rMappedEvent
[0] = PropertyValue(EVENT_TYPE
, -1, makeAny(pEvents
->ScriptType
), PropertyState_DIRECT_VALUE
);
85 rMappedEvent
[1] = PropertyValue(EVENT_SCRIPTURL
, -1, makeAny(pEvents
->ScriptCode
), PropertyState_DIRECT_VALUE
);
90 void SAL_CALL
OEventDescriptorMapper::replaceByName( const OUString
&, const Any
& ) throw(IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
92 throw IllegalArgumentException(
93 "replacing is not implemented for this wrapper class.", static_cast< ::cppu::OWeakObject
* >(this), 1);
96 Any SAL_CALL
OEventDescriptorMapper::getByName( const OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
98 MapString2PropertyValueSequence::const_iterator aPos
= m_aMappedEvents
.find(_rName
);
99 if (m_aMappedEvents
.end() == aPos
)
100 throw NoSuchElementException(
101 "There is no element named " + _rName
,
102 static_cast< ::cppu::OWeakObject
* >(this));
104 return makeAny(aPos
->second
);
107 Sequence
< OUString
> SAL_CALL
OEventDescriptorMapper::getElementNames( ) throw(RuntimeException
, std::exception
)
109 Sequence
< OUString
> aReturn(m_aMappedEvents
.size());
110 OUString
* pReturn
= aReturn
.getArray();
111 for ( MapString2PropertyValueSequence::const_iterator aCollect
= m_aMappedEvents
.begin();
112 aCollect
!= m_aMappedEvents
.end();
113 ++aCollect
, ++pReturn
115 *pReturn
= aCollect
->first
;
120 sal_Bool SAL_CALL
OEventDescriptorMapper::hasByName( const OUString
& _rName
) throw(RuntimeException
, std::exception
)
122 MapString2PropertyValueSequence::const_iterator aPos
= m_aMappedEvents
.find(_rName
);
123 return m_aMappedEvents
.end() != aPos
;
126 Type SAL_CALL
OEventDescriptorMapper::getElementType( ) throw(RuntimeException
, std::exception
)
128 return ::cppu::UnoType
<PropertyValue
>::get();
131 sal_Bool SAL_CALL
OEventDescriptorMapper::hasElements( ) throw(RuntimeException
, std::exception
)
133 return !m_aMappedEvents
.empty();
136 } // namespace xmloff
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */