Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include <boost/scoped_ptr.hpp>
22 : :
23 : : #include <vcl/msgbox.hxx>
24 : : #include <svl/lstner.hxx>
25 : : #include <basic/basmgr.hxx>
26 : : #include <basic/sbmod.hxx>
27 : : #include <basic/sbx.hxx>
28 : : #include <sot/storage.hxx>
29 : : #include <unotools/securityoptions.hxx>
30 : :
31 : : #include <rtl/ustring.h>
32 : : #include <com/sun/star/uno/Any.hxx>
33 : : #include <framework/eventsconfiguration.hxx>
34 : : #include <comphelper/processfactory.hxx>
35 : : #include <sfx2/evntconf.hxx>
36 : :
37 : : #include <sfx2/docfile.hxx>
38 : : #include <sfx2/app.hxx>
39 : : #include <sfx2/objsh.hxx>
40 : : #include <sfx2/dispatch.hxx>
41 : : #include "sfx2/sfxresid.hxx"
42 : : #include "eventsupplier.hxx"
43 : :
44 : : #include <com/sun/star/beans/PropertyValue.hpp>
45 : : #include <com/sun/star/container/XNameReplace.hpp>
46 : : #include <com/sun/star/document/XEventsSupplier.hpp>
47 : : #include <com/sun/star/uno/Sequence.hxx>
48 : : #include <com/sun/star/uno/Reference.hxx>
49 : :
50 : : // -----------------------------------------------------------------------
51 [ + + ][ - + ]: 1510882 : TYPEINIT1(SfxEventHint, SfxHint);
52 [ # # ][ # # ]: 0 : TYPEINIT1(SfxEventNamesItem, SfxPoolItem);
53 [ + + ][ + + ]: 460604 : TYPEINIT1(SfxViewEventHint, SfxEventHint);
54 : :
55 : : using namespace com::sun::star;
56 : :
57 : 0 : SfxEventNamesList& SfxEventNamesList::operator=( const SfxEventNamesList& rTbl )
58 : : {
59 : 0 : DelDtor();
60 [ # # ]: 0 : for ( size_t i = 0, n = rTbl.size(); i < n; ++i )
61 : : {
62 [ # # ]: 0 : SfxEventName* pTmp = rTbl.at( i );
63 [ # # ][ # # ]: 0 : SfxEventName* pNew = new SfxEventName( *pTmp );
64 [ # # ]: 0 : aEventNamesList.push_back( pNew );
65 : : }
66 : 0 : return *this;
67 : : }
68 : :
69 : 0 : void SfxEventNamesList::DelDtor()
70 : : {
71 [ # # ]: 0 : for ( size_t i = 0, n = aEventNamesList.size(); i < n; ++i )
72 [ # # ]: 0 : delete aEventNamesList[ i ];
73 : 0 : aEventNamesList.clear();
74 : 0 : }
75 : :
76 : 0 : int SfxEventNamesItem::operator==( const SfxPoolItem& rAttr ) const
77 : : {
78 : : DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
79 : :
80 : 0 : const SfxEventNamesList& rOwn = aEventsList;
81 : 0 : const SfxEventNamesList& rOther = ( (SfxEventNamesItem&) rAttr ).aEventsList;
82 : :
83 [ # # ]: 0 : if ( rOwn.size() != rOther.size() )
84 : 0 : return sal_False;
85 : :
86 [ # # ]: 0 : for ( size_t nNo = 0, nCnt = rOwn.size(); nNo < nCnt; ++nNo )
87 : : {
88 : 0 : const SfxEventName *pOwn = rOwn.at( nNo );
89 : 0 : const SfxEventName *pOther = rOther.at( nNo );
90 [ # # ][ # # : 0 : if ( pOwn->mnId != pOther->mnId ||
# # # # ]
91 : 0 : pOwn->maEventName != pOther->maEventName ||
92 : 0 : pOwn->maUIName != pOther->maUIName )
93 : 0 : return sal_False;
94 : : }
95 : :
96 : 0 : return sal_True;
97 : :
98 : : }
99 : :
100 : 0 : SfxItemPresentation SfxEventNamesItem::GetPresentation( SfxItemPresentation,
101 : : SfxMapUnit,
102 : : SfxMapUnit,
103 : : XubString &rText,
104 : : const IntlWrapper* ) const
105 : : {
106 : 0 : rText.Erase();
107 : 0 : return SFX_ITEM_PRESENTATION_NONE;
108 : : }
109 : :
110 : 0 : SfxPoolItem* SfxEventNamesItem::Clone( SfxItemPool *) const
111 : : {
112 [ # # ]: 0 : return new SfxEventNamesItem(*this);
113 : : }
114 : :
115 : 0 : SfxPoolItem* SfxEventNamesItem::Create(SvStream &, sal_uInt16) const
116 : : {
117 : : OSL_FAIL("not streamable!");
118 [ # # ]: 0 : return new SfxEventNamesItem(Which());
119 : : }
120 : :
121 : 0 : SvStream& SfxEventNamesItem::Store(SvStream &rStream, sal_uInt16 ) const
122 : : {
123 : : OSL_FAIL("not streamable!");
124 : 0 : return rStream;
125 : : }
126 : :
127 : 0 : sal_uInt16 SfxEventNamesItem::GetVersion( sal_uInt16 ) const
128 : : {
129 : : OSL_FAIL("not streamable!");
130 : 0 : return 0;
131 : : }
132 : :
133 : 0 : void SfxEventNamesItem::AddEvent( const String& rName, const String& rUIName, sal_uInt16 nID )
134 : : {
135 [ # # ][ # # ]: 0 : aEventsList.push_back( new SfxEventName( nID, rName, rUIName.Len() ? rUIName : rName ) );
136 : 0 : }
137 : :
138 : :
139 : : //==========================================================================
140 : :
141 : : //--------------------------------------------------------------------------
142 : 0 : uno::Any CreateEventData_Impl( const SvxMacro *pMacro )
143 : : {
144 : : /*
145 : : This function converts a SvxMacro into an Any containing three
146 : : properties. These properties are EventType and Script. Possible
147 : : values for EventType ar StarBasic, JavaScript, ...
148 : : The Script property should contain the URL to the macro and looks
149 : : like "macro://./standard.module1.main()"
150 : :
151 : : If pMacro is NULL, we return an empty property sequence, so PropagateEvent_Impl
152 : : can delete an event binding.
153 : : */
154 : 0 : uno::Any aEventData;
155 : :
156 [ # # ]: 0 : if ( pMacro )
157 : : {
158 [ # # ]: 0 : if ( pMacro->GetScriptType() == STARBASIC )
159 : : {
160 [ # # ]: 0 : uno::Sequence < beans::PropertyValue > aProperties(3);
161 [ # # ]: 0 : beans::PropertyValue *pValues = aProperties.getArray();
162 : :
163 : 0 : ::rtl::OUString aType(STAR_BASIC );
164 : 0 : ::rtl::OUString aLib = pMacro->GetLibName();
165 : 0 : ::rtl::OUString aMacro = pMacro->GetMacName();
166 : :
167 : 0 : pValues[ 0 ].Name = ::rtl::OUString(PROP_EVENT_TYPE );
168 [ # # ]: 0 : pValues[ 0 ].Value <<= aType;
169 : :
170 : 0 : pValues[ 1 ].Name = ::rtl::OUString(PROP_LIBRARY );
171 [ # # ]: 0 : pValues[ 1 ].Value <<= aLib;
172 : :
173 : 0 : pValues[ 2 ].Name = ::rtl::OUString(PROP_MACRO_NAME );
174 [ # # ]: 0 : pValues[ 2 ].Value <<= aMacro;
175 : :
176 [ # # ][ # # ]: 0 : aEventData <<= aProperties;
177 : : }
178 [ # # ]: 0 : else if ( pMacro->GetScriptType() == EXTENDED_STYPE )
179 : : {
180 [ # # ]: 0 : uno::Sequence < beans::PropertyValue > aProperties(2);
181 [ # # ]: 0 : beans::PropertyValue *pValues = aProperties.getArray();
182 : :
183 : 0 : ::rtl::OUString aLib = pMacro->GetLibName();
184 : 0 : ::rtl::OUString aMacro = pMacro->GetMacName();
185 : :
186 : 0 : pValues[ 0 ].Name = ::rtl::OUString(PROP_EVENT_TYPE );
187 [ # # ]: 0 : pValues[ 0 ].Value <<= aLib;
188 : :
189 : 0 : pValues[ 1 ].Name = ::rtl::OUString(PROP_SCRIPT );
190 [ # # ]: 0 : pValues[ 1 ].Value <<= aMacro;
191 : :
192 [ # # ][ # # ]: 0 : aEventData <<= aProperties;
193 : : }
194 [ # # ]: 0 : else if ( pMacro->GetScriptType() == JAVASCRIPT )
195 : : {
196 [ # # ]: 0 : uno::Sequence < beans::PropertyValue > aProperties(2);
197 [ # # ]: 0 : beans::PropertyValue *pValues = aProperties.getArray();
198 : :
199 : 0 : ::rtl::OUString aMacro = pMacro->GetMacName();
200 : :
201 : 0 : pValues[ 0 ].Name = ::rtl::OUString(PROP_EVENT_TYPE );
202 [ # # ]: 0 : pValues[ 0 ].Value <<= ::rtl::OUString(SVX_MACRO_LANGUAGE_JAVASCRIPT);
203 : :
204 : 0 : pValues[ 1 ].Name = ::rtl::OUString(PROP_MACRO_NAME );
205 [ # # ]: 0 : pValues[ 1 ].Value <<= aMacro;
206 : :
207 [ # # ][ # # ]: 0 : aEventData <<= aProperties;
208 : : }
209 : : else
210 : : {
211 : : SAL_WARN( "sfx2.config", "CreateEventData_Impl(): ScriptType not supported!");
212 : : }
213 : : }
214 : : else
215 : : {
216 [ # # ]: 0 : uno::Sequence < beans::PropertyValue > aProperties;
217 [ # # ][ # # ]: 0 : aEventData <<= aProperties;
218 : : }
219 : :
220 : 0 : return aEventData;
221 : : }
222 : :
223 : : //--------------------------------------------------------------------------
224 : 0 : void PropagateEvent_Impl( SfxObjectShell *pDoc, rtl::OUString aEventName, const SvxMacro* pMacro )
225 : : {
226 : 0 : uno::Reference < document::XEventsSupplier > xSupplier;
227 [ # # ]: 0 : if ( pDoc )
228 : : {
229 [ # # ][ # # ]: 0 : xSupplier = uno::Reference < document::XEventsSupplier >( pDoc->GetModel(), uno::UNO_QUERY );
[ # # ]
230 : : }
231 : : else
232 : : {
233 : : xSupplier = uno::Reference < document::XEventsSupplier >
234 [ # # ][ # # : 0 : ( ::comphelper::getProcessServiceFactory()->createInstance(
# # # ]
235 [ # # ][ # # ]: 0 : rtl::OUString("com.sun.star.frame.GlobalEventBroadcaster")), uno::UNO_QUERY );
[ # # ]
236 : : }
237 : :
238 [ # # ]: 0 : if ( xSupplier.is() )
239 : : {
240 [ # # ][ # # ]: 0 : uno::Reference < container::XNameReplace > xEvents = xSupplier->getEvents();
241 [ # # ]: 0 : if ( !aEventName.isEmpty() )
242 : : {
243 [ # # ]: 0 : uno::Any aEventData = CreateEventData_Impl( pMacro );
244 : :
245 : : try
246 : : {
247 [ # # ][ # # ]: 0 : xEvents->replaceByName( aEventName, aEventData );
248 : : }
249 [ # # ]: 0 : catch( const ::com::sun::star::lang::IllegalArgumentException& )
250 : : {
251 : : SAL_WARN( "sfx2.config", "PropagateEvents_Impl: caught IllegalArgumentException" );
252 : : }
253 [ # # ]: 0 : catch( const ::com::sun::star::container::NoSuchElementException& )
254 : : {
255 : : SAL_WARN( "sfx2.config", "PropagateEvents_Impl: caught NoSuchElementException" );
256 : 0 : }
257 : : }
258 : : else {
259 : : DBG_WARNING( "PropagateEvents_Impl: Got unkown event" );
260 : 0 : }
261 : 0 : }
262 : 0 : }
263 : :
264 : : //--------------------------------------------------------------------------------------------------------
265 : 0 : void SfxEventConfiguration::ConfigureEvent( rtl::OUString aName, const SvxMacro& rMacro, SfxObjectShell *pDoc )
266 : : {
267 : 0 : boost::scoped_ptr<SvxMacro> pMacro;
268 [ # # ]: 0 : if ( rMacro.HasMacro() )
269 [ # # ][ # # ]: 0 : pMacro.reset( new SvxMacro( rMacro.GetMacName(), rMacro.GetLibName(), rMacro.GetScriptType() ) );
[ # # ]
270 [ # # ][ # # ]: 0 : PropagateEvent_Impl( pDoc ? pDoc : 0, aName, pMacro.get() );
271 : 0 : }
272 : :
273 : : // -------------------------------------------------------------------------------------------------------
274 : 8 : SvxMacro* SfxEventConfiguration::ConvertToMacro( const com::sun::star::uno::Any& rElement, SfxObjectShell* pDoc, sal_Bool bBlowUp )
275 : : {
276 : 8 : return SfxEvents_Impl::ConvertToMacro( rElement, pDoc, bBlowUp );
277 : : }
278 : :
279 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|