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>
25 //.........................................................................
28 //.........................................................................
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::script
;
32 using namespace ::com::sun::star::container
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::lang
;
36 //=====================================================================
37 //= OEventDescriptorMapper
38 //=====================================================================
39 //---------------------------------------------------------------------
40 OEventDescriptorMapper::OEventDescriptorMapper(const Sequence
< ScriptEventDescriptor
>& _rEvents
)
42 sal_Int32 nEvents
= _rEvents
.getLength();
44 // translate the events
45 const ScriptEventDescriptor
* pEvents
= _rEvents
.getConstArray();
47 OUString sLibrary
, sLocalMacroName
;
48 for (sal_Int32 i
=0; i
<nEvents
; ++i
, ++pEvents
)
50 // the name of the event is build from listener interface and listener method name
51 sName
= pEvents
->ListenerType
;
52 sName
+= EVENT_NAME_SEPARATOR
;
53 sName
+= pEvents
->EventMethod
;
55 Sequence
< PropertyValue
>& rMappedEvent
= m_aMappedEvents
[sName
];
57 sLocalMacroName
= pEvents
->ScriptCode
;
59 if (pEvents
->ScriptType
.equals(EVENT_STARBASIC
))
60 { // for StarBasic, the library name is part of the ScriptCode
61 sal_Int32 nPrefixLen
= sLocalMacroName
.indexOf( ':' );
62 DBG_ASSERT( 0 <= nPrefixLen
, "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
63 if ( 0 <= nPrefixLen
)
65 // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
66 sLibrary
= sLocalMacroName
.copy( 0, nPrefixLen
);
67 if (sLibrary
.equals(EVENT_APPLICATION
))
68 sLibrary
= EVENT_STAROFFICE
;
70 sLocalMacroName
= sLocalMacroName
.copy( nPrefixLen
+ 1 );
72 // tree property values to describe one event ...
73 rMappedEvent
.realloc( sLibrary
.isEmpty() ? 2 : 3 );
76 rMappedEvent
[0] = PropertyValue(EVENT_TYPE
, -1, makeAny(pEvents
->ScriptType
), PropertyState_DIRECT_VALUE
);
79 rMappedEvent
[1] = PropertyValue(EVENT_LOCALMACRONAME
, -1, makeAny(sLocalMacroName
), PropertyState_DIRECT_VALUE
);
82 if ( !sLibrary
.isEmpty() )
83 rMappedEvent
[2] = PropertyValue(EVENT_LIBRARY
, -1, makeAny(sLibrary
), PropertyState_DIRECT_VALUE
);
87 rMappedEvent
.realloc( 2 );
88 rMappedEvent
[0] = PropertyValue(EVENT_TYPE
, -1, makeAny(pEvents
->ScriptType
), PropertyState_DIRECT_VALUE
);
90 rMappedEvent
[1] = PropertyValue(EVENT_SCRIPTURL
, -1, makeAny(pEvents
->ScriptCode
), PropertyState_DIRECT_VALUE
);
95 //---------------------------------------------------------------------
96 void SAL_CALL
OEventDescriptorMapper::replaceByName( const OUString
&, const Any
& ) throw(IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
)
98 throw IllegalArgumentException(
99 OUString("replacing is not implemented for this wrapper class."), static_cast< ::cppu::OWeakObject
* >(this), 1);
102 //---------------------------------------------------------------------
103 Any SAL_CALL
OEventDescriptorMapper::getByName( const OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
105 ConstMapString2PropertyValueSequenceIterator aPos
= m_aMappedEvents
.find(_rName
);
106 if (m_aMappedEvents
.end() == aPos
)
107 throw NoSuchElementException(
108 OUString("There is no element named ") += _rName
,
109 static_cast< ::cppu::OWeakObject
* >(this));
111 return makeAny(aPos
->second
);
114 //---------------------------------------------------------------------
115 Sequence
< OUString
> SAL_CALL
OEventDescriptorMapper::getElementNames( ) throw(RuntimeException
)
117 Sequence
< OUString
> aReturn(m_aMappedEvents
.size());
118 OUString
* pReturn
= aReturn
.getArray();
119 for ( ConstMapString2PropertyValueSequenceIterator aCollect
= m_aMappedEvents
.begin();
120 aCollect
!= m_aMappedEvents
.end();
121 ++aCollect
, ++pReturn
123 *pReturn
= aCollect
->first
;
128 //---------------------------------------------------------------------
129 sal_Bool SAL_CALL
OEventDescriptorMapper::hasByName( const OUString
& _rName
) throw(RuntimeException
)
131 ConstMapString2PropertyValueSequenceIterator aPos
= m_aMappedEvents
.find(_rName
);
132 return m_aMappedEvents
.end() != aPos
;
135 //---------------------------------------------------------------------
136 Type SAL_CALL
OEventDescriptorMapper::getElementType( ) throw(RuntimeException
)
138 return ::getCppuType(static_cast< PropertyValue
* >(NULL
));
141 //---------------------------------------------------------------------
142 sal_Bool SAL_CALL
OEventDescriptorMapper::hasElements( ) throw(RuntimeException
)
144 return !m_aMappedEvents
.empty();
147 //.........................................................................
148 } // namespace xmloff
149 //.........................................................................
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */