merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / forms / eventexport.cxx
blob45a679bd40ef42b56e77c3f8ad59546f4c792c90
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: eventexport.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "eventexport.hxx"
34 #include <osl/diagnose.h>
35 #include "strings.hxx"
36 #include <tools/debug.hxx>
38 //.........................................................................
39 namespace xmloff
41 //.........................................................................
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::script;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::lang;
49 //=====================================================================
50 //= OEventDescriptorMapper
51 //=====================================================================
52 //---------------------------------------------------------------------
53 OEventDescriptorMapper::OEventDescriptorMapper(const Sequence< ScriptEventDescriptor >& _rEvents)
55 sal_Int32 nEvents = _rEvents.getLength();
57 // translate the events
58 const ScriptEventDescriptor* pEvents = _rEvents.getConstArray();
59 ::rtl::OUString sName;
60 ::rtl::OUString sLibrary, sLocalMacroName;
61 for (sal_Int32 i=0; i<nEvents; ++i, ++pEvents)
63 // the name of the event is build from listener interface and listener method name
64 sName = pEvents->ListenerType;
65 sName += EVENT_NAME_SEPARATOR;
66 sName += pEvents->EventMethod;
68 Sequence< PropertyValue >& rMappedEvent = m_aMappedEvents[sName];
70 sLocalMacroName = pEvents->ScriptCode;
71 sLibrary = ::rtl::OUString();
72 if ( 0 == pEvents->ScriptType.compareToAscii( EVENT_STARBASIC ) )
73 { // for StarBasic, the library name is part of the ScriptCode
74 sal_Int32 nPrefixLen = sLocalMacroName.indexOf( ':' );
75 DBG_ASSERT( 0 <= nPrefixLen, "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
76 if ( 0 <= nPrefixLen )
78 // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
79 sLibrary = sLocalMacroName.copy( 0, nPrefixLen );
80 if ( sLibrary.equalsAscii( EVENT_APPLICATION ) )
81 sLibrary = EVENT_STAROFFICE;
83 sLocalMacroName = sLocalMacroName.copy( nPrefixLen + 1 );
85 // tree property values to describe one event ...
86 rMappedEvent.realloc( sLibrary.getLength() ? 3 : 2 );
88 // ... the type
89 rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE);
91 // and the macro name
92 rMappedEvent[1] = PropertyValue(EVENT_LOCALMACRONAME, -1, makeAny(sLocalMacroName), PropertyState_DIRECT_VALUE);
94 // the library
95 if ( sLibrary.getLength() )
96 rMappedEvent[2] = PropertyValue(EVENT_LIBRARY, -1, makeAny(sLibrary), PropertyState_DIRECT_VALUE);
98 else
100 rMappedEvent.realloc( 2 );
101 rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE);
102 // and the macro name
103 rMappedEvent[1] = PropertyValue(EVENT_SCRIPTURL, -1, makeAny(pEvents->ScriptCode), PropertyState_DIRECT_VALUE);
108 //---------------------------------------------------------------------
109 void SAL_CALL OEventDescriptorMapper::replaceByName( const ::rtl::OUString&, const Any& ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
111 throw IllegalArgumentException(
112 ::rtl::OUString::createFromAscii("replacing is not implemented for this wrapper class."), static_cast< ::cppu::OWeakObject* >(this), 1);
115 //---------------------------------------------------------------------
116 Any SAL_CALL OEventDescriptorMapper::getByName( const ::rtl::OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
118 ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName);
119 if (m_aMappedEvents.end() == aPos)
120 throw NoSuchElementException(
121 ::rtl::OUString::createFromAscii("There is no element named ") += _rName,
122 static_cast< ::cppu::OWeakObject* >(this));
124 return makeAny(aPos->second);
127 //---------------------------------------------------------------------
128 Sequence< ::rtl::OUString > SAL_CALL OEventDescriptorMapper::getElementNames( ) throw(RuntimeException)
130 Sequence< ::rtl::OUString > aReturn(m_aMappedEvents.size());
131 ::rtl::OUString* pReturn = aReturn.getArray();
132 for ( ConstMapString2PropertyValueSequenceIterator aCollect = m_aMappedEvents.begin();
133 aCollect != m_aMappedEvents.end();
134 ++aCollect, ++pReturn
136 *pReturn = aCollect->first;
138 return aReturn;
141 //---------------------------------------------------------------------
142 sal_Bool SAL_CALL OEventDescriptorMapper::hasByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
144 ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName);
145 return m_aMappedEvents.end() != aPos;
148 //---------------------------------------------------------------------
149 Type SAL_CALL OEventDescriptorMapper::getElementType( ) throw(RuntimeException)
151 return ::getCppuType(static_cast< PropertyValue* >(NULL));
154 //---------------------------------------------------------------------
155 sal_Bool SAL_CALL OEventDescriptorMapper::hasElements( ) throw(RuntimeException)
157 return !m_aMappedEvents.empty();
160 //.........................................................................
161 } // namespace xmloff
162 //.........................................................................