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