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 : : #include <com/sun/star/frame/DispatchStatement.hpp>
21 : : #include <com/sun/star/container/XIndexReplace.hpp>
22 : : #include <com/sun/star/beans/PropertyValue.hpp>
23 : : #include <com/sun/star/uno/Sequence.hxx>
24 : : #include <com/sun/star/beans/XPropertySet.hpp>
25 : : #include <com/sun/star/util/URLTransformer.hpp>
26 : : #include <com/sun/star/util/XURLTransformer.hpp>
27 : : #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
28 : : #include <svl/itemiter.hxx>
29 : :
30 : : #include <svl/itempool.hxx>
31 : : #include <svtools/itemdel.hxx>
32 : :
33 : : #include <comphelper/componentcontext.hxx>
34 : : #include <comphelper/processfactory.hxx>
35 : :
36 : : #include <svl/smplhint.hxx>
37 : :
38 : : #include <sfx2/request.hxx>
39 : : #include <sfx2/dispatch.hxx>
40 : : #include <sfx2/msg.hxx>
41 : : #include <sfx2/viewfrm.hxx>
42 : : #include <sfx2/objface.hxx>
43 : : #include <sfx2/appuno.hxx>
44 : : #include <rtl/strbuf.hxx>
45 : :
46 : : //===================================================================
47 : :
48 : : using namespace ::com::sun::star;
49 : :
50 : : struct SfxRequest_Impl: public SfxListener
51 : :
52 : : /* [Description]
53 : :
54 : : Implementation structur of the <SfxRequest> class.
55 : : */
56 : :
57 : : {
58 : : SfxRequest* pAnti; // Owner because of dying pool
59 : : String aTarget; // if possible from target object set by App
60 : : SfxItemPool* pPool; // ItemSet build with this pool
61 : : SfxPoolItem* pRetVal; // Return value belongs to itself
62 : : SfxShell* pShell; // run from this shell
63 : : const SfxSlot* pSlot; // executed Slot
64 : : sal_uInt16 nModifier; // which Modifier was pressed?
65 : : sal_Bool bDone; // at all executed
66 : : sal_Bool bIgnored; // Cancelled by the User
67 : : sal_Bool bCancelled; // no longer notify
68 : : sal_Bool bUseTarget; // aTarget was set by Application
69 : : sal_uInt16 nCallMode; // Synch/Asynch/API/Record
70 : : sal_Bool bAllowRecording;
71 : : SfxAllItemSet* pInternalArgs;
72 : : SfxViewFrame* pViewFrame;
73 : :
74 : : com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
75 : :
76 : 2909 : SfxRequest_Impl( SfxRequest *pOwner )
77 : : : pAnti( pOwner)
78 : : , pPool(0)
79 : : , nModifier(0)
80 : : , bCancelled(sal_False)
81 : : , nCallMode( SFX_CALLMODE_SYNCHRON )
82 : : , bAllowRecording( sal_False )
83 : : , pInternalArgs( 0 )
84 [ + - ]: 2909 : , pViewFrame(0)
85 : 2909 : {}
86 [ + + ][ + - ]: 5748 : ~SfxRequest_Impl() { delete pInternalArgs; }
[ + - ][ - + ]
87 : :
88 : :
89 : : void SetPool( SfxItemPool *pNewPool );
90 : : virtual void Notify( SfxBroadcaster &rBC, const SfxHint &rHint );
91 : : void Record( const uno::Sequence < beans::PropertyValue >& rArgs );
92 : : };
93 : :
94 : :
95 : : //====================================================================
96 : :
97 : 31 : void SfxRequest_Impl::Notify( SfxBroadcaster&, const SfxHint &rHint )
98 : : {
99 [ + - ][ + - ]: 31 : SfxSimpleHint *pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint);
100 [ + - ][ + - ]: 31 : if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
[ + - ]
101 : 31 : pAnti->Cancel();
102 : 31 : }
103 : :
104 : : //====================================================================
105 : :
106 : 2940 : void SfxRequest_Impl::SetPool( SfxItemPool *pNewPool )
107 : : {
108 [ + - ]: 2940 : if ( pNewPool != pPool )
109 : : {
110 [ + + ]: 2940 : if ( pPool )
111 : 31 : EndListening( pPool->BC() );
112 : 2940 : pPool = pNewPool;
113 [ + + ]: 2940 : if ( pNewPool )
114 : 2909 : StartListening( pNewPool->BC() );
115 : : }
116 : 2940 : }
117 : :
118 : : //====================================================================
119 : :
120 : :
121 : 2874 : SfxRequest::~SfxRequest()
122 : : {
123 : : // Leave out Done() marked requests with 'rem'
124 [ + + ][ + - ]: 2874 : if ( pImp->xRecorder.is() && !pImp->bDone && !pImp->bIgnored )
[ + - ][ + + ]
125 [ + - ][ + - ]: 2 : pImp->Record( uno::Sequence < beans::PropertyValue >() );
[ + - ]
126 : :
127 : : // Clear object
128 [ + + ][ + - ]: 2874 : delete pArgs;
129 [ + + ]: 2874 : if ( pImp->pRetVal )
130 [ + - ]: 18 : DeleteItemOnIdle(pImp->pRetVal);
131 [ + - ][ + - ]: 2874 : delete pImp;
132 [ - + ]: 3801 : }
133 : : //--------------------------------------------------------------------
134 : :
135 : :
136 : 1015 : SfxRequest::SfxRequest
137 : : (
138 : : const SfxRequest& rOrig
139 : : )
140 : : : SfxHint( rOrig ),
141 : : nSlot(rOrig.nSlot),
142 [ + - ]: 614 : pArgs(rOrig.pArgs? new SfxAllItemSet(*rOrig.pArgs): 0),
143 [ + + ][ + - ]: 1629 : pImp( new SfxRequest_Impl(this) )
[ + - ][ + - ]
144 : : {
145 : 1015 : pImp->bAllowRecording = rOrig.pImp->bAllowRecording;
146 : 1015 : pImp->bDone = sal_False;
147 : 1015 : pImp->bIgnored = sal_False;
148 : 1015 : pImp->pRetVal = 0;
149 : 1015 : pImp->pShell = 0;
150 : 1015 : pImp->pSlot = 0;
151 : 1015 : pImp->nCallMode = rOrig.pImp->nCallMode;
152 : 1015 : pImp->bUseTarget = rOrig.pImp->bUseTarget;
153 [ + - ]: 1015 : pImp->aTarget = rOrig.pImp->aTarget;
154 : 1015 : pImp->nModifier = rOrig.pImp->nModifier;
155 : :
156 : : // deep copy needed !
157 [ + + ][ + - ]: 1015 : pImp->pInternalArgs = (rOrig.pImp->pInternalArgs ? new SfxAllItemSet(*rOrig.pImp->pInternalArgs) : 0);
[ + - ]
158 : :
159 [ + + ]: 1015 : if ( pArgs )
160 [ + - ]: 614 : pImp->SetPool( pArgs->GetPool() );
161 : : else
162 [ + - ]: 401 : pImp->SetPool( rOrig.pImp->pPool );
163 : 1015 : }
164 : : //--------------------------------------------------------------------
165 : :
166 : :
167 : 0 : SfxRequest::SfxRequest
168 : : (
169 : : SfxViewFrame* pViewFrame,
170 : : sal_uInt16 nSlotId
171 : :
172 : : )
173 : :
174 : : /* [Description]
175 : :
176 : : With this constructor events can subsequently be recorded that are not run
177 : : across SfxDispatcher (eg from KeyInput() or mouse events). For this, a
178 : : SfxRequest instance is created by this constructor and then proceed
179 : : exactly as with a SfxRequest that in a <Slot-Execute-Method> is given as a
180 : : parameter.
181 : : */
182 : :
183 : : : nSlot(nSlotId),
184 : : pArgs(0),
185 [ # # ][ # # ]: 0 : pImp( new SfxRequest_Impl(this) )
186 : : {
187 : 0 : pImp->bDone = sal_False;
188 : 0 : pImp->bIgnored = sal_False;
189 [ # # ]: 0 : pImp->SetPool( &pViewFrame->GetPool() );
190 : 0 : pImp->pRetVal = 0;
191 : 0 : pImp->pShell = 0;
192 : 0 : pImp->pSlot = 0;
193 : 0 : pImp->nCallMode = SFX_CALLMODE_SYNCHRON;
194 : 0 : pImp->bUseTarget = sal_False;
195 : 0 : pImp->pViewFrame = pViewFrame;
196 [ # # ][ # # ]: 0 : if( pImp->pViewFrame->GetDispatcher()->GetShellAndSlot_Impl( nSlotId, &pImp->pShell, &pImp->pSlot, sal_True, sal_True ) )
197 : : {
198 [ # # ]: 0 : pImp->SetPool( &pImp->pShell->GetPool() );
199 [ # # ][ # # ]: 0 : pImp->xRecorder = SfxRequest::GetMacroRecorder( pViewFrame );
200 [ # # ][ # # ]: 0 : pImp->aTarget = pImp->pShell->GetName();
201 : : }
202 : : #ifdef DBG_UTIL
203 : : else
204 : : {
205 : : rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
206 : : "Recording unsupported slot: "));
207 : : aStr.append(static_cast<sal_Int32>(pImp->pPool->GetSlotId(nSlotId)));
208 : : OSL_FAIL(aStr.getStr());
209 : : }
210 : : #endif
211 : 0 : }
212 : :
213 : : //--------------------------------------------------------------------
214 : :
215 : :
216 : 1168 : SfxRequest::SfxRequest
217 : : (
218 : : sal_uInt16 nSlotId, // executed <Slot-Id>
219 : : SfxCallMode nMode, // Synch/API/...
220 : : SfxItemPool& rPool // necessary for the SfxItemSet for parameters
221 : : )
222 : :
223 : : // creates a SfxRequest without arguments
224 : :
225 : : : nSlot(nSlotId),
226 : : pArgs(0),
227 [ + - ][ + - ]: 1168 : pImp( new SfxRequest_Impl(this) )
228 : : {
229 : 1168 : pImp->bDone = sal_False;
230 : 1168 : pImp->bIgnored = sal_False;
231 [ + - ]: 1168 : pImp->SetPool( &rPool );
232 : 1168 : pImp->pRetVal = 0;
233 : 1168 : pImp->pShell = 0;
234 : 1168 : pImp->pSlot = 0;
235 : 1168 : pImp->nCallMode = nMode;
236 : 1168 : pImp->bUseTarget = sal_False;
237 : 1168 : }
238 : :
239 : 0 : SfxRequest::SfxRequest
240 : : (
241 : : const SfxSlot* pSlot, // executed <Slot-Id>
242 : : const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& rArgs,
243 : : SfxCallMode nMode, // Synch/API/...
244 : : SfxItemPool& rPool // necessary for the SfxItemSet for parameters
245 : : )
246 : 0 : : nSlot(pSlot->GetSlotId()),
247 [ # # ]: 0 : pArgs(new SfxAllItemSet(rPool)),
248 [ # # ][ # # ]: 0 : pImp( new SfxRequest_Impl(this) )
[ # # ]
249 : : {
250 : 0 : pImp->bDone = sal_False;
251 : 0 : pImp->bIgnored = sal_False;
252 [ # # ]: 0 : pImp->SetPool( &rPool );
253 : 0 : pImp->pRetVal = 0;
254 : 0 : pImp->pShell = 0;
255 : 0 : pImp->pSlot = 0;
256 : 0 : pImp->nCallMode = nMode;
257 : 0 : pImp->bUseTarget = sal_False;
258 [ # # ]: 0 : TransformParameters( nSlot, rArgs, *pArgs, pSlot );
259 : 0 : }
260 : :
261 : : //-----------------------------------------------------------------------
262 : :
263 : 726 : SfxRequest::SfxRequest
264 : : (
265 : : sal_uInt16 nSlotId,
266 : : sal_uInt16 nMode,
267 : : const SfxAllItemSet& rSfxArgs
268 : : )
269 : :
270 : : // creates a SfxRequest with arguments
271 : :
272 : : : nSlot(nSlotId),
273 [ + - ]: 726 : pArgs(new SfxAllItemSet(rSfxArgs)),
274 [ + - ][ + - ]: 1452 : pImp( new SfxRequest_Impl(this) )
[ + - ]
275 : : {
276 : 726 : pImp->bDone = sal_False;
277 : 726 : pImp->bIgnored = sal_False;
278 [ + - ]: 726 : pImp->SetPool( rSfxArgs.GetPool() );
279 : 726 : pImp->pRetVal = 0;
280 : 726 : pImp->pShell = 0;
281 : 726 : pImp->pSlot = 0;
282 : 726 : pImp->nCallMode = nMode;
283 : 726 : pImp->bUseTarget = sal_False;
284 : 726 : }
285 : : //--------------------------------------------------------------------
286 : :
287 : 50 : sal_uInt16 SfxRequest::GetCallMode() const
288 : : {
289 : 50 : return pImp->nCallMode;
290 : : }
291 : :
292 : : //--------------------------------------------------------------------
293 : :
294 : 0 : sal_Bool SfxRequest::IsSynchronCall() const
295 : : {
296 : 0 : return SFX_CALLMODE_SYNCHRON == ( SFX_CALLMODE_SYNCHRON & pImp->nCallMode );
297 : : }
298 : :
299 : : //--------------------------------------------------------------------
300 : :
301 : 755 : void SfxRequest::SetSynchronCall( sal_Bool bSynchron )
302 : : {
303 [ - + ]: 755 : if ( bSynchron )
304 : 0 : pImp->nCallMode |= SFX_CALLMODE_SYNCHRON;
305 : : else
306 : 755 : pImp->nCallMode &= ~(sal_uInt16) SFX_CALLMODE_SYNCHRON;
307 : 755 : }
308 : :
309 : 62 : void SfxRequest::SetInternalArgs_Impl( const SfxAllItemSet& rArgs )
310 : : {
311 [ - + ]: 62 : delete pImp->pInternalArgs;
312 [ + - ]: 62 : pImp->pInternalArgs = new SfxAllItemSet( rArgs );
313 : 62 : }
314 : :
315 : 0 : const SfxItemSet* SfxRequest::GetInternalArgs_Impl() const
316 : : {
317 : 0 : return pImp->pInternalArgs;
318 : : }
319 : :
320 : : //--------------------------------------------------------------------
321 : :
322 : :
323 : 2 : void SfxRequest_Impl::Record
324 : : (
325 : : const uno::Sequence < beans::PropertyValue >& rArgs // current Parameter
326 : : )
327 : :
328 : : /* [Description]
329 : :
330 : : Internal helper method to create a repeatable description of the just
331 : : executed SfxRequest.
332 : : */
333 : :
334 : : {
335 [ + - ]: 2 : String aCommand = rtl::OUString(".uno:");
336 [ + - ]: 2 : aCommand.AppendAscii( pSlot->GetUnoName() );
337 [ + - ]: 2 : ::rtl::OUString aCmd( aCommand );
338 [ + - ]: 2 : if(xRecorder.is())
339 : : {
340 [ + - ]: 2 : uno::Reference< container::XIndexReplace > xReplace( xRecorder, uno::UNO_QUERY );
341 [ + - ][ + - ]: 2 : if ( xReplace.is() && aCmd.compareToAscii(".uno:InsertText") == COMPARE_EQUAL )
[ + - ]
342 : : {
343 [ + - ][ + - ]: 2 : sal_Int32 nCount = xReplace->getCount();
344 [ - + ]: 2 : if ( nCount )
345 : : {
346 [ # # ]: 0 : frame::DispatchStatement aStatement;
347 [ # # ][ # # ]: 0 : uno::Any aElement = xReplace->getByIndex(nCount-1);
348 [ # # ][ # # ]: 0 : if ( (aElement >>= aStatement) && aStatement.aCommand == aCmd )
[ # # ][ # # ]
349 : : {
350 : 0 : ::rtl::OUString aStr;
351 : 0 : ::rtl::OUString aNew;
352 [ # # ]: 0 : aStatement.aArgs[0].Value >>= aStr;
353 : 0 : rArgs[0].Value >>= aNew;
354 : 0 : aStr += aNew;
355 [ # # ][ # # ]: 0 : aStatement.aArgs[0].Value <<= aStr;
356 [ # # ]: 0 : aElement <<= aStatement;
357 [ # # ][ # # ]: 0 : xReplace->replaceByIndex( nCount-1, aElement );
358 : 2 : return;
359 [ # # ][ # # ]: 0 : }
[ # # ]
360 : : }
361 : : }
362 : :
363 : : com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory(
364 : : ::comphelper::getProcessServiceFactory(),
365 [ + - ][ + - ]: 2 : com::sun::star::uno::UNO_QUERY);
366 : :
367 [ + - ][ + - ]: 2 : uno::Reference< util::XURLTransformer > xTransform( util::URLTransformer::create( ::comphelper::ComponentContext(xFactory).getUNOContext() ) );
[ + - ][ + - ]
368 : :
369 : 2 : com::sun::star::util::URL aURL;
370 : 2 : aURL.Complete = aCmd;
371 [ + - ][ + - ]: 2 : xTransform->parseStrict(aURL);
372 : :
373 [ - + ]: 2 : if (bDone)
374 [ # # ][ # # ]: 0 : xRecorder->recordDispatch(aURL,rArgs);
375 : : else
376 [ + - ][ + - ]: 2 : xRecorder->recordDispatchAsComment(aURL,rArgs);
[ + - ]
377 [ - + ][ + - ]: 2 : }
[ + - ]
378 : : }
379 : :
380 : : //--------------------------------------------------------------------
381 : :
382 : 2 : void SfxRequest::Record_Impl
383 : : (
384 : : SfxShell& rSh, // the <SfxShell>, which has excecuted the Request
385 : : const SfxSlot& rSlot, // the <SfxSlot>, which has executed the Request
386 : : com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder,
387 : : SfxViewFrame* pViewFrame
388 : : )
389 : :
390 : : /* [Description]
391 : :
392 : : This internal method marks the specified SfxMakro SfxRequest as recorded in
393 : : SfxMakro. Pointer to the parameters in Done() is used again, thus has to
394 : : still be alive.
395 : : */
396 : :
397 : : {
398 : 2 : pImp->pShell = &rSh;
399 : 2 : pImp->pSlot = &rSlot;
400 : 2 : pImp->xRecorder = xRecorder;
401 : 2 : pImp->aTarget = rSh.GetName();
402 : 2 : pImp->pViewFrame = pViewFrame;
403 : 2 : }
404 : :
405 : : //--------------------------------------------------------------------
406 : :
407 : 0 : void SfxRequest::SetArgs( const SfxAllItemSet& rArgs )
408 : : {
409 [ # # ]: 0 : delete pArgs;
410 [ # # ]: 0 : pArgs = new SfxAllItemSet(rArgs);
411 : 0 : pImp->SetPool( pArgs->GetPool() );
412 : 0 : }
413 : :
414 : : //--------------------------------------------------------------------
415 : :
416 : 38 : void SfxRequest::AppendItem(const SfxPoolItem &rItem)
417 : : {
418 [ + + ]: 38 : if(!pArgs)
419 [ + - ]: 32 : pArgs = new SfxAllItemSet(*pImp->pPool);
420 : 38 : pArgs->Put(rItem, rItem.Which());
421 : 38 : }
422 : :
423 : : //--------------------------------------------------------------------
424 : :
425 : 0 : void SfxRequest::RemoveItem( sal_uInt16 nID )
426 : : {
427 [ # # ]: 0 : if (pArgs)
428 : : {
429 : 0 : pArgs->ClearItem(nID);
430 [ # # ]: 0 : if ( !pArgs->Count() )
431 [ # # ]: 0 : DELETEZ(pArgs);
432 : : }
433 : 0 : }
434 : :
435 : : //--------------------------------------------------------------------
436 : :
437 : 132 : const SfxPoolItem* SfxRequest::GetArg
438 : : (
439 : : sal_uInt16 nSlotId, // Slot-Id or Which-Id of the parameters
440 : : bool bDeep, // sal_False: do not seach in the Parent-ItemSets
441 : : TypeId aType // != 0: RTTI check with Assertion
442 : : ) const
443 : : {
444 : 132 : return GetItem( pArgs, nSlotId, bDeep, aType );
445 : : }
446 : :
447 : :
448 : : //--------------------------------------------------------------------
449 : 372525 : const SfxPoolItem* SfxRequest::GetItem
450 : : (
451 : : const SfxItemSet* pArgs,
452 : : sal_uInt16 nSlotId, // Slot-Id or Which-Id of the parameters
453 : : bool bDeep, // sal_False: do not seach in the Parent-ItemSets
454 : : TypeId aType // != 0: RTTI check with Assertion
455 : : )
456 : :
457 : : /* [Description]
458 : :
459 : : With this method the access to individual parameters in the SfxRequest is
460 : : simplified. In particular the type-examination (by Assertion) is performed,
461 : : whereby the application source code will be much clearer. In the product-
462 : : version is a 0 returned, if the found item is not of the specified class.
463 : :
464 : : [Example]
465 : :
466 : : void MyShell::Execute( SfxRequest &rReq )
467 : : {
468 : : switch ( rReq.GetSlot() )
469 : : {
470 : : case SID_MY:
471 : : {
472 : : ...
473 : : // An Example on not using the macros
474 : : const SfxInt32Item *pPosItem = (const SfxUInt32Item*)
475 : : rReq.GetArg( SID_POS, sal_False, TYPE(SfxInt32Item) );
476 : : sal_uInt16 nPos = pPosItem ? pPosItem->GetValue() : 0;
477 : :
478 : : // An Example on using the macros
479 : : SFX_REQUEST_ARG(rReq, pSizeItem, SfxInt32Item, SID_SIZE, sal_False);
480 : : sal_uInt16 nSize = pSizeItem ? pPosItem->GetValue() : 0;
481 : :
482 : : ...
483 : : }
484 : :
485 : : ...
486 : : }
487 : : }
488 : : */
489 : :
490 : : {
491 [ + + ]: 372525 : if ( pArgs )
492 : : {
493 : : // Which may be converted to ID
494 [ + - ]: 363826 : sal_uInt16 nWhich = pArgs->GetPool()->GetWhich(nSlotId);
495 : :
496 : : // Is the item set or available at bDeep == sal_True?
497 : 363826 : const SfxPoolItem *pItem = 0;
498 [ - + ][ + + ]: 727652 : if ( ( bDeep ? SFX_ITEM_AVAILABLE : SFX_ITEM_SET )
499 [ + - ]: 363826 : <= pArgs->GetItemState( nWhich, bDeep, &pItem ) )
500 : : {
501 : : // Compare type
502 [ + - ][ + - ]: 43451 : if ( !pItem || pItem->IsA(aType) )
[ + - ][ + - ]
503 : 363826 : return pItem;
504 : :
505 : : // Item of wrong type => Programming error
506 : : OSL_FAIL( "invalid argument type" );
507 : : }
508 : : }
509 : :
510 : : // No Parameter, not found or wrong type
511 : 372525 : return 0;
512 : : }
513 : :
514 : : //--------------------------------------------------------------------
515 : :
516 : 18 : void SfxRequest::SetReturnValue(const SfxPoolItem &rItem)
517 : : {
518 : : DBG_ASSERT(!pImp->pRetVal, "Set Return value multiple times?");
519 [ - + ]: 18 : if(pImp->pRetVal)
520 [ # # ]: 0 : delete pImp->pRetVal;
521 : 18 : pImp->pRetVal = rItem.Clone();
522 : 18 : }
523 : :
524 : : //--------------------------------------------------------------------
525 : :
526 : 1395 : const SfxPoolItem* SfxRequest::GetReturnValue() const
527 : : {
528 : 1395 : return pImp->pRetVal;
529 : : }
530 : :
531 : : //--------------------------------------------------------------------
532 : :
533 : 0 : void SfxRequest::Done
534 : : (
535 : : const SfxItemSet& rSet, /* parameters passed on by the application,
536 : : that for example were asked for by the user
537 : : in a dialogue, 0 if no parameters have been
538 : : set */
539 : :
540 : : bool bKeep /* true (default)
541 : : 'rSet' is saved and GetArgs() queriable.
542 : :
543 : : false
544 : : 'rSet' is not copied (faster) */
545 : : )
546 : :
547 : : /* [Description]
548 : :
549 : : This method must be called in the <Execute-Method> of the <SfxSlot>s, which
550 : : has performed the SfxRequest when the execution actually took place. If
551 : : 'Done()' is not called, then the SfxRequest is considered canceled.
552 : :
553 : : Any return values are passed only when 'Done()' was called. Similar, when
554 : : recording a macro only true statements are generated if 'Done()' was
555 : : called; for SfxRequests that were not identified as such will instead
556 : : be commented out by inserting ('rem').
557 : :
558 : : [Note]
559 : :
560 : : 'Done ()' is not called, for example when a dialoge started by the function
561 : : was canceled by the user or if the execution could not be performed due to
562 : : a wrong context (without use of separate <SfxShell>s). 'Done ()' will be
563 : : launched, when executing the function led to a regular error
564 : : (for example, file could not be opened).
565 : : */
566 : :
567 : : {
568 : 0 : Done_Impl( &rSet );
569 : :
570 : : // Keep items if possible, so they can be queried by StarDraw.
571 [ # # ]: 0 : if ( bKeep )
572 : : {
573 [ # # ]: 0 : if ( !pArgs )
574 : : {
575 [ # # ]: 0 : pArgs = new SfxAllItemSet( rSet );
576 : 0 : pImp->SetPool( pArgs->GetPool() );
577 : : }
578 : : else
579 : : {
580 [ # # ]: 0 : SfxItemIter aIter(rSet);
581 : 0 : const SfxPoolItem* pItem = aIter.FirstItem();
582 [ # # ]: 0 : while(pItem)
583 : : {
584 [ # # ]: 0 : if(!IsInvalidItem(pItem))
585 [ # # ]: 0 : pArgs->Put(*pItem,pItem->Which());
586 [ # # ]: 0 : pItem = aIter.NextItem();
587 [ # # ]: 0 : }
588 : : }
589 : : }
590 : 0 : }
591 : :
592 : : //--------------------------------------------------------------------
593 : :
594 : :
595 : 755 : void SfxRequest::Done( sal_Bool bRelease )
596 : : // [<SfxRequest::Done(SfxItemSet&)>]
597 : : {
598 : 755 : Done_Impl( pArgs );
599 [ - + ]: 755 : if( bRelease )
600 [ # # ]: 0 : DELETEZ( pArgs );
601 : 755 : }
602 : :
603 : : //--------------------------------------------------------------------
604 : :
605 : 0 : void SfxRequest::ForgetAllArgs()
606 : : {
607 [ # # ]: 0 : DELETEZ( pArgs );
608 [ # # ]: 0 : DELETEZ( pImp->pInternalArgs );
609 : 0 : }
610 : :
611 : : //--------------------------------------------------------------------
612 : :
613 : 755 : sal_Bool SfxRequest::IsCancelled() const
614 : : {
615 : 755 : return pImp->bCancelled;
616 : : }
617 : :
618 : : //--------------------------------------------------------------------
619 : :
620 : 31 : void SfxRequest::Cancel()
621 : :
622 : : /* [Description]
623 : :
624 : : Marks this request as no longer executable. For example, if called when
625 : : the target (more precisely, its pool) dies.
626 : : */
627 : :
628 : : {
629 : 31 : pImp->bCancelled = sal_True;
630 : 31 : pImp->SetPool( 0 );
631 [ + + ]: 31 : DELETEZ( pArgs );
632 : 31 : }
633 : :
634 : : //--------------------------------------------------------------------
635 : :
636 : :
637 : 1312 : void SfxRequest::Ignore()
638 : :
639 : : /* [Description]
640 : :
641 : : If this method is called instead of <SfxRequest::Done()>, then this
642 : : request is not recorded.
643 : :
644 : : [Example]
645 : :
646 : : The selecting of tools in StarDraw should not be recorded, but the same
647 : : slots are to be used from the generation of the tools to the generated
648 : : objects. Thus can NoRecords not be specified, i.e. should not be recorded.
649 : : */
650 : :
651 : : {
652 : : // Mark as actually executed
653 : 1312 : pImp->bIgnored = sal_True;
654 : 1312 : }
655 : :
656 : : //--------------------------------------------------------------------
657 : :
658 : 755 : void SfxRequest::Done_Impl
659 : : (
660 : : const SfxItemSet* pSet /* parameters passed on by the application,
661 : : that for example were asked for by the user
662 : : in a dialogue, 0 if no parameters have been
663 : : set */
664 : :
665 : : )
666 : :
667 : : /* [Description]
668 : :
669 : : Internal method to mark SfxRequest with 'done' and to evaluate the
670 : : parameters in 'pSet' in case it is recorded.
671 : : */
672 : :
673 : : {
674 : : // Mark as actually executed
675 : 755 : pImp->bDone = sal_True;
676 : :
677 : : // not Recording
678 [ + - ]: 755 : if ( !pImp->xRecorder.is() )
679 : 755 : return;
680 : :
681 : : // was running a different slot than requested (Delegation)
682 [ # # ]: 0 : if ( nSlot != pImp->pSlot->GetSlotId() )
683 : : {
684 : : // Search Slot again
685 : 0 : pImp->pSlot = pImp->pShell->GetInterface()->GetSlot(nSlot);
686 : : DBG_ASSERT( pImp->pSlot, "delegated SlotId not found" );
687 [ # # ]: 0 : if ( !pImp->pSlot ) // playing it safe
688 : 0 : return;
689 : : }
690 : :
691 : : // recordable?
692 : : // new Recording uses UnoName!
693 [ # # ]: 0 : if ( !pImp->pSlot->pUnoName )
694 : : {
695 : : rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
696 [ # # ]: 0 : "Recording not exported slot: "));
697 [ # # ]: 0 : aStr.append(static_cast<sal_Int32>(pImp->pSlot->GetSlotId()));
698 : 0 : OSL_FAIL(aStr.getStr());
699 : : }
700 : :
701 [ # # ]: 0 : if ( !pImp->pSlot->pUnoName ) // playing it safe
702 : 0 : return;
703 : :
704 : : // often required values
705 : 0 : SfxItemPool &rPool = pImp->pShell->GetPool();
706 : :
707 : : // Property-Slot?
708 [ # # ]: 0 : if ( !pImp->pSlot->IsMode(SFX_SLOT_METHOD) )
709 : : {
710 : : // get the property as SfxPoolItem
711 : : const SfxPoolItem *pItem;
712 [ # # ]: 0 : sal_uInt16 nWhich = rPool.GetWhich(pImp->pSlot->GetSlotId());
713 [ # # ][ # # ]: 0 : SfxItemState eState = pSet ? pSet->GetItemState( nWhich, sal_False, &pItem ) : SFX_ITEM_UNKNOWN;
714 : : #ifdef DBG_UTIL
715 : : if ( SFX_ITEM_SET != eState )
716 : : {
717 : : rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
718 : : "Recording property not available: "));
719 : : aStr.append(static_cast<sal_Int32>(pImp->pSlot->GetSlotId()));
720 : : OSL_FAIL(aStr.getStr());
721 : : }
722 : : #endif
723 [ # # ]: 0 : uno::Sequence < beans::PropertyValue > aSeq;
724 [ # # ]: 0 : if ( eState == SFX_ITEM_SET )
725 [ # # ]: 0 : TransformItems( pImp->pSlot->GetSlotId(), *pSet, aSeq, pImp->pSlot );
726 [ # # ][ # # ]: 0 : pImp->Record( aSeq );
727 : : }
728 : :
729 : : // record everything in a single statement?
730 [ # # ]: 0 : else if ( pImp->pSlot->IsMode(SFX_SLOT_RECORDPERSET) )
731 : : {
732 [ # # ]: 0 : uno::Sequence < beans::PropertyValue > aSeq;
733 [ # # ]: 0 : if ( pSet )
734 [ # # ]: 0 : TransformItems( pImp->pSlot->GetSlotId(), *pSet, aSeq, pImp->pSlot );
735 [ # # ][ # # ]: 0 : pImp->Record( aSeq );
736 : : }
737 : :
738 : : // record each item as a single statement
739 [ # # ]: 0 : else if ( pImp->pSlot->IsMode(SFX_SLOT_RECORDPERITEM) )
740 : : {
741 [ # # ]: 0 : if ( pSet )
742 : : {
743 : : // iterate over Items
744 [ # # ]: 0 : SfxItemIter aIter(*pSet);
745 [ # # ][ # # ]: 0 : for ( const SfxPoolItem* pItem = aIter.FirstItem(); pItem; pItem = aIter.NextItem() )
746 : : {
747 : : // to determine the slot ID for the individual item
748 [ # # ]: 0 : sal_uInt16 nSlotId = rPool.GetSlotId( pItem->Which() );
749 [ # # ]: 0 : if ( nSlotId == nSlot )
750 : : {
751 : : // play it safe; repair the wrong flags
752 : : OSL_FAIL( "recursion RecordPerItem - use RecordPerSet!" );
753 : 0 : SfxSlot *pSlot = (SfxSlot*) pImp->pSlot;
754 : 0 : pSlot->nFlags &= ~((sal_uIntPtr)SFX_SLOT_RECORDPERITEM);
755 : 0 : pSlot->nFlags &= SFX_SLOT_RECORDPERSET;
756 : : }
757 : :
758 : : // Record a Sub-Request
759 [ # # ]: 0 : SfxRequest aReq( pImp->pViewFrame, nSlotId );
760 [ # # ]: 0 : if ( aReq.pImp->pSlot )
761 [ # # ]: 0 : aReq.AppendItem( *pItem );
762 [ # # ]: 0 : aReq.Done();
763 [ # # ][ # # ]: 0 : }
764 : : }
765 : : else
766 : : {
767 : : //HACK(think about this again)
768 [ # # ]: 755 : pImp->Record( uno::Sequence < beans::PropertyValue >() );
769 : : }
770 : : }
771 : : }
772 : :
773 : : //--------------------------------------------------------------------
774 : :
775 : 967 : sal_Bool SfxRequest::IsDone() const
776 : :
777 : : /* [Description]
778 : :
779 : : With this method it can be queried whether the SfxRequest was actually
780 : : executed or not. If a SfxRequest was not executed, then this is for example
781 : : because it was canceled by the user or the context for this request was
782 : : wrong, this was not implemented on a separate <SfxShell>.
783 : :
784 : : SfxRequest instances that return sal_False will not be recorded.
785 : :
786 : : [Cross-reference]
787 : :
788 : : <SfxRequest::Done(const SfxItemSet&)>
789 : : <SfxRequest::Done()>
790 : : */
791 : :
792 : : {
793 : 967 : return pImp->bDone;
794 : : }
795 : :
796 : : //--------------------------------------------------------------------
797 : :
798 : 0 : com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > SfxRequest::GetMacroRecorder( SfxViewFrame* pView )
799 : :
800 : : /* [Description]
801 : :
802 : : This recorder is an attempt for dispatch () to get calls from the Frame.
803 : : This is then available through a property by a supplier but only when
804 : : recording was turned on.
805 : :
806 : : (See also SfxViewFrame::MiscExec_Impl() and SID_RECORDING)
807 : : */
808 : :
809 : : {
810 : 0 : com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
811 : :
812 : : com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
813 [ # # ][ # # ]: 0 : (pView ? pView : SfxViewFrame::Current())->GetFrame().GetFrameInterface(),
[ # # ]
814 [ # # ][ # # ]: 0 : com::sun::star::uno::UNO_QUERY);
815 : :
816 [ # # ]: 0 : if(xSet.is())
817 : : {
818 [ # # ][ # # ]: 0 : com::sun::star::uno::Any aProp = xSet->getPropertyValue(rtl::OUString("DispatchRecorderSupplier"));
819 : 0 : com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
820 [ # # ]: 0 : aProp >>= xSupplier;
821 [ # # ]: 0 : if(xSupplier.is())
822 [ # # ][ # # ]: 0 : xRecorder = xSupplier->getDispatchRecorder();
[ # # ]
823 : : }
824 : :
825 : 0 : return xRecorder;
826 : : }
827 : :
828 : 0 : sal_Bool SfxRequest::HasMacroRecorder( SfxViewFrame* pView )
829 : : {
830 : 0 : return GetMacroRecorder( pView ).is();
831 : : }
832 : :
833 : :
834 : : //--------------------------------------------------------------------
835 : :
836 : 2 : sal_Bool SfxRequest::IsAPI() const
837 : :
838 : : /* [Description]
839 : :
840 : : Returns sal_True if this SfxRequest was generated by an API (for example BASIC),
841 : : otherwise sal_False.
842 : : */
843 : :
844 : : {
845 : 2 : return SFX_CALLMODE_API == ( SFX_CALLMODE_API & pImp->nCallMode );
846 : : }
847 : :
848 : : //--------------------------------------------------------------------
849 : 234 : void SfxRequest::SetModifier( sal_uInt16 nModi )
850 : : {
851 : 234 : pImp->nModifier = nModi;
852 : 234 : }
853 : :
854 : : //--------------------------------------------------------------------
855 : 260 : sal_uInt16 SfxRequest::GetModifier() const
856 : : {
857 : 260 : return pImp->nModifier;
858 : : }
859 : :
860 : : //--------------------------------------------------------------------
861 : :
862 : 770 : void SfxRequest::AllowRecording( sal_Bool bSet )
863 : : {
864 : 770 : pImp->bAllowRecording = bSet;
865 : 770 : }
866 : :
867 : 755 : sal_Bool SfxRequest::AllowsRecording() const
868 : : {
869 : 755 : sal_Bool bAllow = pImp->bAllowRecording;
870 [ + + ]: 755 : if( !bAllow )
871 : : bAllow = ( SFX_CALLMODE_API != ( SFX_CALLMODE_API & pImp->nCallMode ) ) &&
872 [ + - ][ - + ]: 16 : ( SFX_CALLMODE_RECORD == ( SFX_CALLMODE_RECORD & pImp->nCallMode ) );
873 : 755 : return bAllow;
874 : : }
875 : :
876 : 0 : void SfxRequest::ReleaseArgs()
877 : : {
878 [ # # ]: 0 : DELETEZ( pArgs );
879 [ # # ]: 0 : DELETEZ( pImp->pInternalArgs );
880 : 0 : }
881 : :
882 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|