xref: /aoo42x/main/sfx2/source/control/request.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchStatement.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
36*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
39*cdf0e10cSrcweir #include <svl/itemiter.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #ifndef _ARGS_HXX //autogen
42*cdf0e10cSrcweir #include <svl/itempool.hxx>
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir #include <svtools/itemdel.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #ifndef GCC
49*cdf0e10cSrcweir #endif
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <svl/smplhint.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include <sfx2/request.hxx>
54*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
55*cdf0e10cSrcweir #include <sfx2/msg.hxx>
56*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
57*cdf0e10cSrcweir #include "macro.hxx"
58*cdf0e10cSrcweir #include <sfx2/objface.hxx>
59*cdf0e10cSrcweir #include <sfx2/appuno.hxx>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //===================================================================
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir using namespace ::com::sun::star;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir struct SfxRequest_Impl: public SfxListener
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir /* 	[Beschreibung]
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	Implementations-Struktur der Klasse <SfxRequest>.
70*cdf0e10cSrcweir */
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir 	SfxRequest*			pAnti;		 // Owner wegen sterbendem Pool
74*cdf0e10cSrcweir 	String				aTarget;	 // ggf. von App gesetztes Zielobjekt
75*cdf0e10cSrcweir 	SfxItemPool*        pPool;		 // ItemSet mit diesem Pool bauen
76*cdf0e10cSrcweir 	SfxPoolItem*		pRetVal;	 // R"uckgabewert geh"ort sich selbst
77*cdf0e10cSrcweir     SfxShell*           pShell;      // ausgef"uhrt an dieser Shell
78*cdf0e10cSrcweir 	const SfxSlot*		pSlot;		 // ausgef"uhrter Slot
79*cdf0e10cSrcweir 	sal_uInt16              nModifier;   // welche Modifier waren gedrueckt?
80*cdf0e10cSrcweir 	sal_Bool				bDone;		 // "uberhaupt ausgef"uhrt
81*cdf0e10cSrcweir 	sal_Bool				bIgnored;	 // vom User abgebrochen
82*cdf0e10cSrcweir 	sal_Bool				bCancelled;	 // nicht mehr zustellen
83*cdf0e10cSrcweir 	sal_Bool				bUseTarget;	 // aTarget wurde von Applikation gesetzt
84*cdf0e10cSrcweir 	sal_uInt16  			nCallMode;   // Synch/Asynch/API/Record
85*cdf0e10cSrcweir     sal_Bool                bAllowRecording;
86*cdf0e10cSrcweir 	SfxAllItemSet*      pInternalArgs;
87*cdf0e10cSrcweir     SfxViewFrame*       pViewFrame;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 						SfxRequest_Impl( SfxRequest *pOwner )
92*cdf0e10cSrcweir 						: pAnti( pOwner)
93*cdf0e10cSrcweir 						, pPool(0)
94*cdf0e10cSrcweir 						, nModifier(0)
95*cdf0e10cSrcweir 						, bCancelled(sal_False)
96*cdf0e10cSrcweir 						, nCallMode( SFX_CALLMODE_SYNCHRON )
97*cdf0e10cSrcweir 						, bAllowRecording( sal_False )
98*cdf0e10cSrcweir 						, pInternalArgs( 0 )
99*cdf0e10cSrcweir 						, pViewFrame(0)
100*cdf0e10cSrcweir 						{}
101*cdf0e10cSrcweir 	~SfxRequest_Impl() { delete pInternalArgs; }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	void				SetPool( SfxItemPool *pNewPool );
105*cdf0e10cSrcweir 	virtual void		Notify( SfxBroadcaster &rBC, const SfxHint &rHint );
106*cdf0e10cSrcweir     void                Record( const uno::Sequence < beans::PropertyValue >& rArgs );
107*cdf0e10cSrcweir };
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir //====================================================================
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir void SfxRequest_Impl::Notify( SfxBroadcaster&, const SfxHint &rHint )
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir 	SfxSimpleHint *pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint);
115*cdf0e10cSrcweir 	if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
116*cdf0e10cSrcweir 		pAnti->Cancel();
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir //====================================================================
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void SfxRequest_Impl::SetPool( SfxItemPool *pNewPool )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	if ( pNewPool != pPool )
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		if ( pPool )
126*cdf0e10cSrcweir 			EndListening( pPool->BC() );
127*cdf0e10cSrcweir 		pPool = pNewPool;
128*cdf0e10cSrcweir 		if ( pNewPool )
129*cdf0e10cSrcweir 			StartListening( pNewPool->BC() );
130*cdf0e10cSrcweir 	}
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //====================================================================
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir SfxRequest::~SfxRequest()
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	DBG_MEMTEST();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	// nicht mit Done() marktierte Requests mit 'rem' rausschreiben
141*cdf0e10cSrcweir 	if ( pImp->xRecorder.is() && !pImp->bDone && !pImp->bIgnored )
142*cdf0e10cSrcweir         pImp->Record( uno::Sequence < beans::PropertyValue >() );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	// Objekt abr"aumen
145*cdf0e10cSrcweir 	delete pArgs;
146*cdf0e10cSrcweir 	if ( pImp->pRetVal )
147*cdf0e10cSrcweir 		DeleteItemOnIdle(pImp->pRetVal);
148*cdf0e10cSrcweir 	delete pImp;
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir //--------------------------------------------------------------------
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir SfxRequest::SfxRequest
154*cdf0e10cSrcweir (
155*cdf0e10cSrcweir 	const SfxRequest& rOrig
156*cdf0e10cSrcweir )
157*cdf0e10cSrcweir :	SfxHint( rOrig ),
158*cdf0e10cSrcweir     nSlot(rOrig.nSlot),
159*cdf0e10cSrcweir 	pArgs(rOrig.pArgs? new SfxAllItemSet(*rOrig.pArgs): 0),
160*cdf0e10cSrcweir 	pImp( new SfxRequest_Impl(this) )
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir 	DBG_MEMTEST();
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     pImp->bAllowRecording = rOrig.pImp->bAllowRecording;
165*cdf0e10cSrcweir     pImp->bDone = sal_False;
166*cdf0e10cSrcweir 	pImp->bIgnored = sal_False;
167*cdf0e10cSrcweir 	pImp->pRetVal = 0;
168*cdf0e10cSrcweir 	pImp->pShell = 0;
169*cdf0e10cSrcweir 	pImp->pSlot = 0;
170*cdf0e10cSrcweir 	pImp->nCallMode = rOrig.pImp->nCallMode;
171*cdf0e10cSrcweir 	pImp->bUseTarget = rOrig.pImp->bUseTarget;
172*cdf0e10cSrcweir 	pImp->aTarget = rOrig.pImp->aTarget;
173*cdf0e10cSrcweir 	pImp->nModifier = rOrig.pImp->nModifier;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     // deep copy needed !
176*cdf0e10cSrcweir     pImp->pInternalArgs = (rOrig.pImp->pInternalArgs ? new SfxAllItemSet(*rOrig.pImp->pInternalArgs) : 0);
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	if ( pArgs )
179*cdf0e10cSrcweir 		pImp->SetPool( pArgs->GetPool() );
180*cdf0e10cSrcweir 	else
181*cdf0e10cSrcweir 		pImp->SetPool( rOrig.pImp->pPool );
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir //--------------------------------------------------------------------
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir SfxRequest::SfxRequest
187*cdf0e10cSrcweir (
188*cdf0e10cSrcweir     SfxViewFrame*   pViewFrame,
189*cdf0e10cSrcweir     sal_uInt16          nSlotId
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir )
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir /*	[Beschreibung]
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	Mit diesem Konstruktor k"onnen Events, die nicht "uber den SfxDispatcher
196*cdf0e10cSrcweir 	gelaufen sind (z.B aus KeyInput() oder Mouse-Events) nachtr"aglich
197*cdf0e10cSrcweir 	recorded werden. Dazu wird eine SfxRequest-Instanz mit diesem Konstruktor
198*cdf0e10cSrcweir 	erzeugt und dann genauso verfahren, wie mit einem SfxRequest, der in
199*cdf0e10cSrcweir 	eine <Slot-Execute-Methode> als Parameter gegeben wird.
200*cdf0e10cSrcweir */
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir :	nSlot(nSlotId),
203*cdf0e10cSrcweir 	pArgs(0),
204*cdf0e10cSrcweir 	pImp( new SfxRequest_Impl(this) )
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir 	DBG_MEMTEST();
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 	pImp->bDone = sal_False;
209*cdf0e10cSrcweir 	pImp->bIgnored = sal_False;
210*cdf0e10cSrcweir     pImp->SetPool( &pViewFrame->GetPool() );
211*cdf0e10cSrcweir 	pImp->pRetVal = 0;
212*cdf0e10cSrcweir 	pImp->pShell = 0;
213*cdf0e10cSrcweir     pImp->pSlot = 0;
214*cdf0e10cSrcweir 	pImp->nCallMode = SFX_CALLMODE_SYNCHRON;
215*cdf0e10cSrcweir 	pImp->bUseTarget = sal_False;
216*cdf0e10cSrcweir     pImp->pViewFrame = pViewFrame;
217*cdf0e10cSrcweir     if( pImp->pViewFrame->GetDispatcher()->GetShellAndSlot_Impl( nSlotId, &pImp->pShell, &pImp->pSlot, sal_True, sal_True ) )
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         pImp->SetPool( &pImp->pShell->GetPool() );
220*cdf0e10cSrcweir         pImp->xRecorder = SfxRequest::GetMacroRecorder( pViewFrame );
221*cdf0e10cSrcweir         pImp->aTarget = pImp->pShell->GetName();
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir #ifdef DBG_UTIL
224*cdf0e10cSrcweir     else
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         ByteString aStr( "Recording unsupported slot: ");
227*cdf0e10cSrcweir         aStr += ByteString::CreateFromInt32( pImp->pPool->GetSlotId(nSlotId) );
228*cdf0e10cSrcweir         DBG_ERROR( aStr.GetBuffer() );
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir #endif
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir //--------------------------------------------------------------------
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir SfxRequest::SfxRequest
237*cdf0e10cSrcweir (
238*cdf0e10cSrcweir 	sal_uInt16 			nSlotId, 	// auszuf"uhrende <Slot-Id>
239*cdf0e10cSrcweir 	SfxCallMode 	nMode,		// Synch/API/...
240*cdf0e10cSrcweir 	SfxItemPool&	rPool 		// ggf. f"ur das SfxItemSet f"ur Parameter
241*cdf0e10cSrcweir )
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir // creates a SfxRequest without arguments
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir :	nSlot(nSlotId),
246*cdf0e10cSrcweir 	pArgs(0),
247*cdf0e10cSrcweir 	pImp( new SfxRequest_Impl(this) )
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir 	DBG_MEMTEST();
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	pImp->bDone = sal_False;
252*cdf0e10cSrcweir 	pImp->bIgnored = sal_False;
253*cdf0e10cSrcweir 	pImp->SetPool( &rPool );
254*cdf0e10cSrcweir 	pImp->pRetVal = 0;
255*cdf0e10cSrcweir 	pImp->pShell = 0;
256*cdf0e10cSrcweir 	pImp->pSlot = 0;
257*cdf0e10cSrcweir 	pImp->nCallMode = nMode;
258*cdf0e10cSrcweir 	pImp->bUseTarget = sal_False;
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir SfxRequest::SfxRequest
262*cdf0e10cSrcweir (
263*cdf0e10cSrcweir 	const SfxSlot* pSlot, 	// auszuf"uhrende <Slot-Id>
264*cdf0e10cSrcweir 	const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& rArgs,
265*cdf0e10cSrcweir 	SfxCallMode 	nMode,		// Synch/API/...
266*cdf0e10cSrcweir 	SfxItemPool&	rPool 		// ggf. f"ur das SfxItemSet f"ur Parameter
267*cdf0e10cSrcweir )
268*cdf0e10cSrcweir :	nSlot(pSlot->GetSlotId()),
269*cdf0e10cSrcweir 	pArgs(new SfxAllItemSet(rPool)),
270*cdf0e10cSrcweir 	pImp( new SfxRequest_Impl(this) )
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir 	DBG_MEMTEST();
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 	pImp->bDone = sal_False;
275*cdf0e10cSrcweir 	pImp->bIgnored = sal_False;
276*cdf0e10cSrcweir 	pImp->SetPool( &rPool );
277*cdf0e10cSrcweir 	pImp->pRetVal = 0;
278*cdf0e10cSrcweir 	pImp->pShell = 0;
279*cdf0e10cSrcweir 	pImp->pSlot = 0;
280*cdf0e10cSrcweir 	pImp->nCallMode = nMode;
281*cdf0e10cSrcweir 	pImp->bUseTarget = sal_False;
282*cdf0e10cSrcweir 	TransformParameters( nSlot, rArgs, *pArgs, pSlot );
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir //-----------------------------------------------------------------------
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir SfxRequest::SfxRequest
288*cdf0e10cSrcweir (
289*cdf0e10cSrcweir 	sal_uInt16 					nSlotId,
290*cdf0e10cSrcweir 	sal_uInt16					nMode,
291*cdf0e10cSrcweir 	const SfxAllItemSet&	rSfxArgs
292*cdf0e10cSrcweir )
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir // creates a SfxRequest with arguments
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir :	nSlot(nSlotId),
297*cdf0e10cSrcweir 	pArgs(new SfxAllItemSet(rSfxArgs)),
298*cdf0e10cSrcweir 	pImp( new SfxRequest_Impl(this) )
299*cdf0e10cSrcweir {
300*cdf0e10cSrcweir 	DBG_MEMTEST();
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 	pImp->bDone = sal_False;
303*cdf0e10cSrcweir 	pImp->bIgnored = sal_False;
304*cdf0e10cSrcweir 	pImp->SetPool( rSfxArgs.GetPool() );
305*cdf0e10cSrcweir 	pImp->pRetVal = 0;
306*cdf0e10cSrcweir 	pImp->pShell = 0;
307*cdf0e10cSrcweir 	pImp->pSlot = 0;
308*cdf0e10cSrcweir 	pImp->nCallMode = nMode;
309*cdf0e10cSrcweir 	pImp->bUseTarget = sal_False;
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir //--------------------------------------------------------------------
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir sal_uInt16 SfxRequest::GetCallMode() const
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir 	return pImp->nCallMode;
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir //--------------------------------------------------------------------
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir sal_Bool SfxRequest::IsSynchronCall() const
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir 	return SFX_CALLMODE_SYNCHRON == ( SFX_CALLMODE_SYNCHRON & pImp->nCallMode );
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir //--------------------------------------------------------------------
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir void SfxRequest::SetSynchronCall( sal_Bool bSynchron )
328*cdf0e10cSrcweir {
329*cdf0e10cSrcweir 	if ( bSynchron )
330*cdf0e10cSrcweir 		pImp->nCallMode |= SFX_CALLMODE_SYNCHRON;
331*cdf0e10cSrcweir 	else
332*cdf0e10cSrcweir 		pImp->nCallMode &= ~(sal_uInt16) SFX_CALLMODE_SYNCHRON;
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir void SfxRequest::SetInternalArgs_Impl( const SfxAllItemSet& rArgs )
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	delete pImp->pInternalArgs;
338*cdf0e10cSrcweir 	pImp->pInternalArgs = new SfxAllItemSet( rArgs );
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir const SfxItemSet* SfxRequest::GetInternalArgs_Impl() const
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir 	return pImp->pInternalArgs;
344*cdf0e10cSrcweir }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir //--------------------------------------------------------------------
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir void SfxRequest_Impl::Record
350*cdf0e10cSrcweir (
351*cdf0e10cSrcweir     const uno::Sequence < beans::PropertyValue >& rArgs    // aktuelle Parameter
352*cdf0e10cSrcweir )
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir /*	[Beschreibung]
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir 	Interne Hilfsmethode zum erzeugen einer <SfxMacroStatement>-Instanz,
357*cdf0e10cSrcweir 	welche den bereits ausgef"uhrten SfxRequest wiederholbar beschreibt.
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 	Die erzeugte Instanz, auf die ein Pointer zur"uckgeliefert wird
360*cdf0e10cSrcweir 	geht in das Eigentum des Aufrufers "uber.
361*cdf0e10cSrcweir */
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir     String aCommand = String::CreateFromAscii(".uno:");
365*cdf0e10cSrcweir     aCommand.AppendAscii( pSlot->GetUnoName() );
366*cdf0e10cSrcweir 	::rtl::OUString aCmd( aCommand );
367*cdf0e10cSrcweir     if(xRecorder.is())
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir 		uno::Reference< container::XIndexReplace > xReplace( xRecorder, uno::UNO_QUERY );
370*cdf0e10cSrcweir 		if ( xReplace.is() && aCmd.compareToAscii(".uno:InsertText") == COMPARE_EQUAL )
371*cdf0e10cSrcweir 		{
372*cdf0e10cSrcweir 			sal_Int32 nCount = xReplace->getCount();
373*cdf0e10cSrcweir 			if ( nCount )
374*cdf0e10cSrcweir 			{
375*cdf0e10cSrcweir 				frame::DispatchStatement aStatement;
376*cdf0e10cSrcweir 				uno::Any aElement = xReplace->getByIndex(nCount-1);
377*cdf0e10cSrcweir 				if ( (aElement >>= aStatement) && aStatement.aCommand == aCmd )
378*cdf0e10cSrcweir 				{
379*cdf0e10cSrcweir 					::rtl::OUString aStr;
380*cdf0e10cSrcweir 					::rtl::OUString aNew;
381*cdf0e10cSrcweir 		            aStatement.aArgs[0].Value >>= aStr;
382*cdf0e10cSrcweir 					rArgs[0].Value >>= aNew;
383*cdf0e10cSrcweir 					aStr += aNew;
384*cdf0e10cSrcweir 		            aStatement.aArgs[0].Value <<= aStr;
385*cdf0e10cSrcweir 					aElement <<= aStatement;
386*cdf0e10cSrcweir 					xReplace->replaceByIndex( nCount-1, aElement );
387*cdf0e10cSrcweir 					return;
388*cdf0e10cSrcweir 				}
389*cdf0e10cSrcweir 			}
390*cdf0e10cSrcweir 		}
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory(
393*cdf0e10cSrcweir                 ::comphelper::getProcessServiceFactory(),
394*cdf0e10cSrcweir                 com::sun::star::uno::UNO_QUERY);
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::util::XURLTransformer > xTransform(
397*cdf0e10cSrcweir                 xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")),
398*cdf0e10cSrcweir                 com::sun::star::uno::UNO_QUERY);
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir         com::sun::star::util::URL aURL;
401*cdf0e10cSrcweir         aURL.Complete = aCmd;
402*cdf0e10cSrcweir         xTransform->parseStrict(aURL);
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir         if (bDone)
405*cdf0e10cSrcweir             xRecorder->recordDispatch(aURL,rArgs);
406*cdf0e10cSrcweir         else
407*cdf0e10cSrcweir             xRecorder->recordDispatchAsComment(aURL,rArgs);
408*cdf0e10cSrcweir     }
409*cdf0e10cSrcweir }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir //--------------------------------------------------------------------
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir void SfxRequest::Record_Impl
414*cdf0e10cSrcweir (
415*cdf0e10cSrcweir     SfxShell& rSh,    // die <SfxShell>, die den Request ausgef"uhrt hat
416*cdf0e10cSrcweir 	const SfxSlot&	rSlot, 	// der <SfxSlot>, der den Request ausgef"uhrt hat
417*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder,  // der Recorder, mit dem aufgezeichnet wird
418*cdf0e10cSrcweir     SfxViewFrame* pViewFrame
419*cdf0e10cSrcweir )
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir /*	[Beschreibung]
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 	Diese interne Methode markiert den SfxRequest als in dem angegebenen
424*cdf0e10cSrcweir 	SfxMakro aufzuzeichnen.
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 	Pointer auf die Parameter werden in Done() wieder verwendet, m"usseb
427*cdf0e10cSrcweir 	dann also noch leben.
428*cdf0e10cSrcweir */
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir 	DBG_MEMTEST();
432*cdf0e10cSrcweir 	pImp->pShell = &rSh;
433*cdf0e10cSrcweir 	pImp->pSlot = &rSlot;
434*cdf0e10cSrcweir     pImp->xRecorder = xRecorder;
435*cdf0e10cSrcweir 	pImp->aTarget = rSh.GetName();
436*cdf0e10cSrcweir     pImp->pViewFrame = pViewFrame;
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir //--------------------------------------------------------------------
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir void SfxRequest::SetArgs( const SfxAllItemSet& rArgs )
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	delete pArgs;
444*cdf0e10cSrcweir 	pArgs = new SfxAllItemSet(rArgs);
445*cdf0e10cSrcweir 	pImp->SetPool( pArgs->GetPool() );
446*cdf0e10cSrcweir }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir //--------------------------------------------------------------------
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir void SfxRequest::AppendItem(const SfxPoolItem &rItem)
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir 	if(!pArgs)
453*cdf0e10cSrcweir 		pArgs = new SfxAllItemSet(*pImp->pPool);
454*cdf0e10cSrcweir 	pArgs->Put(rItem, rItem.Which());
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir //--------------------------------------------------------------------
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir void SfxRequest::RemoveItem( sal_uInt16 nID )
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir 	if (pArgs)
462*cdf0e10cSrcweir 	{
463*cdf0e10cSrcweir 		pArgs->ClearItem(nID);
464*cdf0e10cSrcweir 		if ( !pArgs->Count() )
465*cdf0e10cSrcweir 			DELETEZ(pArgs);
466*cdf0e10cSrcweir 	}
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir //--------------------------------------------------------------------
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir const SfxPoolItem* SfxRequest::GetArg
472*cdf0e10cSrcweir (
473*cdf0e10cSrcweir 	sal_uInt16 			nSlotId, 	// Slot-Id oder Which-Id des Parameters
474*cdf0e10cSrcweir 	bool 		bDeep,	 	// false: nicht in Parent-ItemSets suchen
475*cdf0e10cSrcweir 	TypeId			aType		// != 0:  RTTI Pruefung mit Assertion
476*cdf0e10cSrcweir ) 	const
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	return GetItem( pArgs, nSlotId, bDeep, aType );
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir //--------------------------------------------------------------------
483*cdf0e10cSrcweir const SfxPoolItem* SfxRequest::GetItem
484*cdf0e10cSrcweir (
485*cdf0e10cSrcweir 	const SfxItemSet* pArgs,
486*cdf0e10cSrcweir 	sal_uInt16 			nSlotId, 	// Slot-Id oder Which-Id des Parameters
487*cdf0e10cSrcweir 	bool    		bDeep,	 	// false: nicht in Parent-ItemSets suchen
488*cdf0e10cSrcweir 	TypeId			aType		// != 0:  RTTI Pruefung mit Assertion
489*cdf0e10cSrcweir )
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir /*	[Beschreibung]
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 	Mit dieser Methode wird der Zugriff auf einzelne Parameter im
494*cdf0e10cSrcweir 	SfxRequest wesentlich vereinfacht. Insbesondere wird die Typpr"ufung
495*cdf0e10cSrcweir 	(per Assertion) durchgef"uhrt, wodurch die Applikations-Sourcen
496*cdf0e10cSrcweir 	wesentlich "ubersichtlicher werden. In der PRODUCT-Version wird
497*cdf0e10cSrcweir 	eine 0 zur"uckgegeben, wenn das gefundene Item nicht von der
498*cdf0e10cSrcweir 	angegebenen Klasse ist.
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir 	[Beispiel]
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 	void MyShell::Execute( SfxRequest &rReq )
504*cdf0e10cSrcweir 	{
505*cdf0e10cSrcweir 		switch ( rReq.GetSlot() )
506*cdf0e10cSrcweir 		{
507*cdf0e10cSrcweir 			case SID_MY:
508*cdf0e10cSrcweir 			{
509*cdf0e10cSrcweir 				...
510*cdf0e10cSrcweir 				// ein Beispiel ohne Verwendung des Makros
511*cdf0e10cSrcweir 				const SfxInt32Item *pPosItem = (const SfxUInt32Item*)
512*cdf0e10cSrcweir 					rReq.GetArg( SID_POS, sal_False, TYPE(SfxInt32Item) );
513*cdf0e10cSrcweir 				sal_uInt16 nPos = pPosItem ? pPosItem->GetValue() : 0;
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 				// ein Beispiel mit Verwendung des Makros
516*cdf0e10cSrcweir 				SFX_REQUEST_ARG(rReq, pSizeItem, SfxInt32Item, SID_SIZE, sal_False);
517*cdf0e10cSrcweir 				sal_uInt16 nSize = pSizeItem ? pPosItem->GetValue() : 0;
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir 				...
520*cdf0e10cSrcweir 			}
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 			...
523*cdf0e10cSrcweir 		}
524*cdf0e10cSrcweir 	}
525*cdf0e10cSrcweir */
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir {
528*cdf0e10cSrcweir 	if ( pArgs )
529*cdf0e10cSrcweir 	{
530*cdf0e10cSrcweir 		// ggf. in Which-Id umrechnen
531*cdf0e10cSrcweir 		sal_uInt16 nWhich = pArgs->GetPool()->GetWhich(nSlotId);
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 		// ist das Item gesetzt oder bei bDeep==TRUE verf"ugbar?
534*cdf0e10cSrcweir 		const SfxPoolItem *pItem = 0;
535*cdf0e10cSrcweir 		if ( ( bDeep ? SFX_ITEM_AVAILABLE : SFX_ITEM_SET )
536*cdf0e10cSrcweir 			 <= pArgs->GetItemState( nWhich, bDeep, &pItem ) )
537*cdf0e10cSrcweir 		{
538*cdf0e10cSrcweir 			// stimmt der Typ "uberein?
539*cdf0e10cSrcweir 			if ( !pItem || pItem->IsA(aType) )
540*cdf0e10cSrcweir 				return pItem;
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 			// Item da aber falsch => Programmierfehler
543*cdf0e10cSrcweir 			DBG_ERROR(  "invalid argument type" );
544*cdf0e10cSrcweir 		}
545*cdf0e10cSrcweir 	}
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 	// keine Parameter, nicht gefunden oder falschen Typ gefunden
548*cdf0e10cSrcweir 	return 0;
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir //--------------------------------------------------------------------
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir void SfxRequest::SetReturnValue(const SfxPoolItem &rItem)
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir 	DBG_ASSERT(!pImp->pRetVal, "Returnwert mehrfach setzen?");
556*cdf0e10cSrcweir 	if(pImp->pRetVal)
557*cdf0e10cSrcweir 		delete pImp->pRetVal;
558*cdf0e10cSrcweir 	pImp->pRetVal = rItem.Clone();
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir //--------------------------------------------------------------------
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir const SfxPoolItem* SfxRequest::GetReturnValue() const
564*cdf0e10cSrcweir {
565*cdf0e10cSrcweir 	return pImp->pRetVal;
566*cdf0e10cSrcweir }
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir //--------------------------------------------------------------------
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir void SfxRequest::Done
571*cdf0e10cSrcweir (
572*cdf0e10cSrcweir 	const SfxItemSet&	rSet,   /* 	von der Applikation mitgeteilte Parameter,
573*cdf0e10cSrcweir 									die z.B. in einem Dialog vom Benuter
574*cdf0e10cSrcweir 									erfragt wurden, ggf. 0 falls keine
575*cdf0e10cSrcweir 									Parameter gesetzt wurden */
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 	bool 			bKeep	/*  true (default)
578*cdf0e10cSrcweir 									'rSet' wird gepeichert und ist "uber
579*cdf0e10cSrcweir 									GetArgs() abfragbar
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir 									false
582*cdf0e10cSrcweir 									'rSet' wird nicht kopiert (schneller) */
583*cdf0e10cSrcweir )
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir /*	[Beschreibung]
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir 	Diese Methode mu\s in der <Execute-Methode> des <SfxSlot>s gerufen
588*cdf0e10cSrcweir 	werden, der den SfxRequest ausgef"uhrt hat, wenn die Ausf"uhrung
589*cdf0e10cSrcweir 	tats"achlich stattgefunden hat. Wird 'Done()' nicht gerufen, gilt
590*cdf0e10cSrcweir 	der SfxRequest als abgebrochen.
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 	Etwaige Returnwerte werden nur durchgereicht, wenn 'Done()' gerufen
593*cdf0e10cSrcweir 	wurde. Ebenso werden beim Aufzeichnen von Makros nur echte
594*cdf0e10cSrcweir 	Statements erzeugt, wenn 'Done()' gerufen wurde; f"ur SfxRequests,
595*cdf0e10cSrcweir 	die nicht derart gekennzeichnet wurden, wird anstelle dessen eine
596*cdf0e10cSrcweir 	auf die abgebrochene Funktion hinweisende Bemerkung ('rem') eingf"ugt.
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 	[Anmerkung]
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir 	'Done()' wird z.B. nicht gerufen, wenn ein durch die Funktion gestarteter
602*cdf0e10cSrcweir 	Dialog vom Benutzer	abgebrochen wurde oder das Ausf"uhren aufgrund
603*cdf0e10cSrcweir 	eines falschen Kontextes (ohne Verwendung separater <SfxShell>s)
604*cdf0e10cSrcweir 	nicht durchgef"uhrt werden konnte. 'Done()' mu\s sehr wohl gerufen
605*cdf0e10cSrcweir 	werden, wenn das Ausf"uhren der Funktion zu einem regul"aren Fehler
606*cdf0e10cSrcweir 	f"uhrte (z.B. Datei konnte nicht ge"offnet werden).
607*cdf0e10cSrcweir */
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir {
610*cdf0e10cSrcweir 	Done_Impl( &rSet );
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir 	// ggf. Items merken, damit StarDraw sie abfragen kann
613*cdf0e10cSrcweir 	if ( bKeep )
614*cdf0e10cSrcweir 	{
615*cdf0e10cSrcweir 		if ( !pArgs )
616*cdf0e10cSrcweir 		{
617*cdf0e10cSrcweir 			pArgs = new SfxAllItemSet( rSet );
618*cdf0e10cSrcweir 			pImp->SetPool( pArgs->GetPool() );
619*cdf0e10cSrcweir 		}
620*cdf0e10cSrcweir 		else
621*cdf0e10cSrcweir 		{
622*cdf0e10cSrcweir 			SfxItemIter aIter(rSet);
623*cdf0e10cSrcweir 			const SfxPoolItem* pItem = aIter.FirstItem();
624*cdf0e10cSrcweir 			while(pItem)
625*cdf0e10cSrcweir 			{
626*cdf0e10cSrcweir 				if(!IsInvalidItem(pItem))
627*cdf0e10cSrcweir 					pArgs->Put(*pItem,pItem->Which());
628*cdf0e10cSrcweir 				pItem = aIter.NextItem();
629*cdf0e10cSrcweir 			}
630*cdf0e10cSrcweir 		}
631*cdf0e10cSrcweir 	}
632*cdf0e10cSrcweir }
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir //--------------------------------------------------------------------
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir void SfxRequest::Done( sal_Bool bRelease )
638*cdf0e10cSrcweir //	[<SfxRequest::Done(SfxItemSet&)>]
639*cdf0e10cSrcweir {
640*cdf0e10cSrcweir 	Done_Impl( pArgs );
641*cdf0e10cSrcweir 	if( bRelease )
642*cdf0e10cSrcweir 		DELETEZ( pArgs );
643*cdf0e10cSrcweir }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir //--------------------------------------------------------------------
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir void SfxRequest::ForgetAllArgs()
648*cdf0e10cSrcweir {
649*cdf0e10cSrcweir     DELETEZ( pArgs );
650*cdf0e10cSrcweir     DELETEZ( pImp->pInternalArgs );
651*cdf0e10cSrcweir }
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir //--------------------------------------------------------------------
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir sal_Bool SfxRequest::IsCancelled() const
656*cdf0e10cSrcweir {
657*cdf0e10cSrcweir 	return pImp->bCancelled;
658*cdf0e10cSrcweir }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir //--------------------------------------------------------------------
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir void SfxRequest::Cancel()
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir /*	[Beschreibung]
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir 	Markiert diesen Request als nicht mehr auszufuehren. Wird z.B. gerufen,
667*cdf0e10cSrcweir 	wenn das Ziel (genauer dessen Pool) stirbt.
668*cdf0e10cSrcweir */
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir {
671*cdf0e10cSrcweir 	pImp->bCancelled = sal_True;
672*cdf0e10cSrcweir 	pImp->SetPool( 0 );
673*cdf0e10cSrcweir 	DELETEZ( pArgs );
674*cdf0e10cSrcweir }
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir //--------------------------------------------------------------------
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir void SfxRequest::Ignore()
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir /*	[Beschreibung]
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir 	Wird diese Methode anstelle von <SfxRequest::Done()> gerufen, dann
684*cdf0e10cSrcweir 	wird dieser Request nicht recorded.
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir 	[Bespiel]
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir 	Das Selektieren von Tools im StarDraw soll nicht aufgezeichnet werden,
690*cdf0e10cSrcweir 	dieselben Slots sollen aber zum erzeugen der von den Tools zu
691*cdf0e10cSrcweir 	erzeugenden Objekte verwendet werde. Also kann nicht NoRecord
692*cdf0e10cSrcweir 	angegeben werden, dennoch soll u.U. nicht aufgezeichnet werden.
693*cdf0e10cSrcweir */
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir {
696*cdf0e10cSrcweir 	// als tats"achlich ausgef"uhrt markieren
697*cdf0e10cSrcweir 	pImp->bIgnored = sal_True;
698*cdf0e10cSrcweir }
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir //--------------------------------------------------------------------
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir void SfxRequest::Done_Impl
703*cdf0e10cSrcweir (
704*cdf0e10cSrcweir 	const SfxItemSet*	pSet	/* 	von der Applikation mitgeteilte Parameter,
705*cdf0e10cSrcweir 									die z.B. in einem Dialog vom Benuter
706*cdf0e10cSrcweir 									erfragt wurden, ggf. 0 falls keine
707*cdf0e10cSrcweir 									Parameter gesetzt wurden */
708*cdf0e10cSrcweir )
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir /*	[Beschreibung]
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir 	Interne Methode zum als 'done' markieren des SfxRequest und zum Auswerten
713*cdf0e10cSrcweir     der Parameter in 'pSet' falls aufgezeichnet wird.
714*cdf0e10cSrcweir */
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir {
717*cdf0e10cSrcweir 	// als tats"achlich ausgef"uhrt markieren
718*cdf0e10cSrcweir 	pImp->bDone = sal_True;
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir 	// nicht Recorden
721*cdf0e10cSrcweir 	if ( !pImp->xRecorder.is() )
722*cdf0e10cSrcweir 		return;
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 	// wurde ein anderer Slot ausgef"uhrt als angefordert (Delegation)
725*cdf0e10cSrcweir 	if ( nSlot != pImp->pSlot->GetSlotId() )
726*cdf0e10cSrcweir 	{
727*cdf0e10cSrcweir 		// Slot neu suchen
728*cdf0e10cSrcweir 		pImp->pSlot = pImp->pShell->GetInterface()->GetSlot(nSlot);
729*cdf0e10cSrcweir 		DBG_ASSERT( pImp->pSlot, "delegated SlotId not found" );
730*cdf0e10cSrcweir 		if ( !pImp->pSlot ) // Hosentr"ger und G"urtel
731*cdf0e10cSrcweir 			return;
732*cdf0e10cSrcweir 	}
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir 	// record-f"ahig?
735*cdf0e10cSrcweir     // neues Recorden verwendet UnoName!
736*cdf0e10cSrcweir     if ( !pImp->pSlot->pUnoName )
737*cdf0e10cSrcweir     {
738*cdf0e10cSrcweir         ByteString aStr( "Recording not exported slot: ");
739*cdf0e10cSrcweir         aStr += ByteString::CreateFromInt32( pImp->pSlot->GetSlotId() );
740*cdf0e10cSrcweir         DBG_ERROR( aStr.GetBuffer() );
741*cdf0e10cSrcweir     }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     if ( !pImp->pSlot->pUnoName ) // Hosentr"ger und G"urtel
744*cdf0e10cSrcweir         return;
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir 	// "ofters ben"otigte Werte
747*cdf0e10cSrcweir 	SfxItemPool &rPool = pImp->pShell->GetPool();
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir 	// Property-Slot?
750*cdf0e10cSrcweir 	if ( !pImp->pSlot->IsMode(SFX_SLOT_METHOD) )
751*cdf0e10cSrcweir 	{
752*cdf0e10cSrcweir 		// des Property als SfxPoolItem besorgen
753*cdf0e10cSrcweir 		const SfxPoolItem *pItem;
754*cdf0e10cSrcweir 		sal_uInt16 nWhich = rPool.GetWhich(pImp->pSlot->GetSlotId());
755*cdf0e10cSrcweir         SfxItemState eState = pSet ? pSet->GetItemState( nWhich, sal_False, &pItem ) : SFX_ITEM_UNKNOWN;
756*cdf0e10cSrcweir #ifdef DBG_UTIL
757*cdf0e10cSrcweir         if ( SFX_ITEM_SET != eState )
758*cdf0e10cSrcweir         {
759*cdf0e10cSrcweir             ByteString aStr( "Recording property not available: ");
760*cdf0e10cSrcweir             aStr += ByteString::CreateFromInt32( pImp->pSlot->GetSlotId() );
761*cdf0e10cSrcweir             DBG_ERROR( aStr.GetBuffer() );
762*cdf0e10cSrcweir         }
763*cdf0e10cSrcweir #endif
764*cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > aSeq;
765*cdf0e10cSrcweir 		if ( eState == SFX_ITEM_SET )
766*cdf0e10cSrcweir             TransformItems( pImp->pSlot->GetSlotId(), *pSet, aSeq, pImp->pSlot );
767*cdf0e10cSrcweir         pImp->Record( aSeq );
768*cdf0e10cSrcweir 	}
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir 	// alles in ein einziges Statement aufzeichnen?
771*cdf0e10cSrcweir 	else if ( pImp->pSlot->IsMode(SFX_SLOT_RECORDPERSET) )
772*cdf0e10cSrcweir 	{
773*cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > aSeq;
774*cdf0e10cSrcweir         if ( pSet )
775*cdf0e10cSrcweir             TransformItems( pImp->pSlot->GetSlotId(), *pSet, aSeq, pImp->pSlot );
776*cdf0e10cSrcweir         pImp->Record( aSeq );
777*cdf0e10cSrcweir 	}
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir 	// jedes Item als einzelnes Statement recorden
780*cdf0e10cSrcweir 	else if ( pImp->pSlot->IsMode(SFX_SLOT_RECORDPERITEM) )
781*cdf0e10cSrcweir 	{
782*cdf0e10cSrcweir 		if ( pSet )
783*cdf0e10cSrcweir 		{
784*cdf0e10cSrcweir 			// "uber die Items iterieren
785*cdf0e10cSrcweir 			SfxItemIter aIter(*pSet);
786*cdf0e10cSrcweir             for ( const SfxPoolItem* pItem = aIter.FirstItem(); pItem; pItem = aIter.NextItem() )
787*cdf0e10cSrcweir 			{
788*cdf0e10cSrcweir 				// die Slot-Id f"ur das einzelne Item ermitteln
789*cdf0e10cSrcweir 				sal_uInt16 nSlotId = rPool.GetSlotId( pItem->Which() );
790*cdf0e10cSrcweir 				if ( nSlotId == nSlot )
791*cdf0e10cSrcweir 				{
792*cdf0e10cSrcweir 					// mit Hosentr"ager und G"urtel reparieren des falschen Flags
793*cdf0e10cSrcweir 					DBG_ERROR( "recursion RecordPerItem - use RecordPerSet!" );
794*cdf0e10cSrcweir 					SfxSlot *pSlot = (SfxSlot*) pImp->pSlot;
795*cdf0e10cSrcweir 					pSlot->nFlags &= ~((sal_uIntPtr)SFX_SLOT_RECORDPERITEM);
796*cdf0e10cSrcweir 					pSlot->nFlags &=  SFX_SLOT_RECORDPERSET;
797*cdf0e10cSrcweir 				}
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir 				// einen Sub-Request recorden
800*cdf0e10cSrcweir                 SfxRequest aReq( pImp->pViewFrame, nSlotId );
801*cdf0e10cSrcweir                 if ( aReq.pImp->pSlot )
802*cdf0e10cSrcweir                     aReq.AppendItem( *pItem );
803*cdf0e10cSrcweir                 aReq.Done();
804*cdf0e10cSrcweir 			}
805*cdf0e10cSrcweir 		}
806*cdf0e10cSrcweir 		else
807*cdf0e10cSrcweir 		{
808*cdf0e10cSrcweir 			HACK(hierueber nochmal nachdenken)
809*cdf0e10cSrcweir             pImp->Record( uno::Sequence < beans::PropertyValue >() );
810*cdf0e10cSrcweir 		}
811*cdf0e10cSrcweir 	}
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir //--------------------------------------------------------------------
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir sal_Bool SfxRequest::IsDone() const
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir /*	[Beschreibung]
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir 	Mit dieser Methode kann abgefragt werden, ob der SfxRequest tats"achlich
821*cdf0e10cSrcweir 	ausgef"uhrt wurde oder nicht. Wurde ein SfxRequest nicht ausgef"uhrt,
822*cdf0e10cSrcweir 	liegt dies z.B. daran, da\s der Benutzer abgebrochen hat oder
823*cdf0e10cSrcweir 	der Kontext f"ur diesen Request falsch war, dieses aber nicht "uber
824*cdf0e10cSrcweir 	eine separate <SfxShell> realisiert wurde.
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir 	SfxRequest-Instanzen, die hier sal_False liefern, werden nicht recorded.
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir 	[Querverweise]
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir 	<SfxRequest::Done(const SfxItemSet&)>
832*cdf0e10cSrcweir 	<SfxRequest::Done()>
833*cdf0e10cSrcweir */
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir {
836*cdf0e10cSrcweir 	return pImp->bDone;
837*cdf0e10cSrcweir }
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir //--------------------------------------------------------------------
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir SfxMacro* SfxRequest::GetRecordingMacro()
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir /*	[Beschreibung]
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir 	Mit dieser Methode kann abgefragt werden, ob und in welchem <SfxMacro>
846*cdf0e10cSrcweir 	die SfxRequests gerade aufgezeichnet werden.
847*cdf0e10cSrcweir */
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir {
850*cdf0e10cSrcweir     return NULL;
851*cdf0e10cSrcweir }
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir //--------------------------------------------------------------------
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > SfxRequest::GetMacroRecorder( SfxViewFrame* pView )
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir /*  [Beschreibung]
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir     Hier wird versucht einen Recorder fuer dispatch() Aufrufe vom Frame zu bekommen.
860*cdf0e10cSrcweir     Dieser ist dort per Property an einem Supplier verfuegbar - aber nur dann, wenn
861*cdf0e10cSrcweir     recording angeschaltet wurde.
862*cdf0e10cSrcweir     (Siehe auch SfxViewFrame::MiscExec_Impl() und SID_RECORDING)
863*cdf0e10cSrcweir */
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir {
866*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
869*cdf0e10cSrcweir         (pView ? pView : SfxViewFrame::Current())->GetFrame().GetFrameInterface(),
870*cdf0e10cSrcweir         com::sun::star::uno::UNO_QUERY);
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir     if(xSet.is())
873*cdf0e10cSrcweir     {
874*cdf0e10cSrcweir         com::sun::star::uno::Any aProp = xSet->getPropertyValue(rtl::OUString::createFromAscii("DispatchRecorderSupplier"));
875*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
876*cdf0e10cSrcweir         aProp >>= xSupplier;
877*cdf0e10cSrcweir         if(xSupplier.is())
878*cdf0e10cSrcweir             xRecorder = xSupplier->getDispatchRecorder();
879*cdf0e10cSrcweir     }
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir     return xRecorder;
882*cdf0e10cSrcweir }
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir sal_Bool SfxRequest::HasMacroRecorder( SfxViewFrame* pView )
885*cdf0e10cSrcweir {
886*cdf0e10cSrcweir     return GetMacroRecorder( pView ).is();
887*cdf0e10cSrcweir }
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir //--------------------------------------------------------------------
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir sal_Bool SfxRequest::IsAPI() const
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir /*	[Beschreibung]
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir 	Liefert sal_True, wenn dieser SfxRequest von einer API (z.B. BASIC)
897*cdf0e10cSrcweir 	erzeugt wurde, sonst sal_False.
898*cdf0e10cSrcweir */
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir {
901*cdf0e10cSrcweir 	return SFX_CALLMODE_API == ( SFX_CALLMODE_API & pImp->nCallMode );
902*cdf0e10cSrcweir }
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir //--------------------------------------------------------------------
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir bool SfxRequest::IsRecording() const
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir /*	[Beschreibung]
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir 	Liefert sal_True, wenn dieser SfxRequest recorded werden soll, d.h.
912*cdf0e10cSrcweir 	1. zu Zeit ein Makro aufgezeichnet wird
913*cdf0e10cSrcweir 	2. dieser Request "uberhaupt aufgezeichnet wird
914*cdf0e10cSrcweir 	3. der Request nicht von reiner API (z.B. BASIC) ausgeht,
915*cdf0e10cSrcweir 	sonst sal_False.
916*cdf0e10cSrcweir */
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir {
919*cdf0e10cSrcweir     return ( AllowsRecording() && GetMacroRecorder().is() );
920*cdf0e10cSrcweir }
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir //--------------------------------------------------------------------
923*cdf0e10cSrcweir void SfxRequest::SetModifier( sal_uInt16 nModi )
924*cdf0e10cSrcweir {
925*cdf0e10cSrcweir 	pImp->nModifier = nModi;
926*cdf0e10cSrcweir }
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir //--------------------------------------------------------------------
929*cdf0e10cSrcweir sal_uInt16 SfxRequest::GetModifier() const
930*cdf0e10cSrcweir {
931*cdf0e10cSrcweir 	return pImp->nModifier;
932*cdf0e10cSrcweir }
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir //--------------------------------------------------------------------
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir void SfxRequest::SetTarget( const String &rTarget )
937*cdf0e10cSrcweir 
938*cdf0e10cSrcweir /*	[Beschreibung]
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir 	Mit dieser Methode kann das zu recordende Zielobjekt umgesetzt werden.
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir 	[Beispiel]
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 	Die BASIC-Methode 'Open' wird zwar von der Shell 'Application' ausgef"uhrt,
946*cdf0e10cSrcweir 	aber am Objekt 'Documents' (global) recorded:
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir 		rReq.SetTarget( "Documents" );
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir 	Dies f"uhrt dann zu:
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir 		Documents.Open( ... )
953*cdf0e10cSrcweir */
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir {
956*cdf0e10cSrcweir 	pImp->aTarget = rTarget;
957*cdf0e10cSrcweir 	pImp->bUseTarget = sal_True;
958*cdf0e10cSrcweir }
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir void SfxRequest::AllowRecording( sal_Bool bSet )
961*cdf0e10cSrcweir {
962*cdf0e10cSrcweir     pImp->bAllowRecording = bSet;
963*cdf0e10cSrcweir }
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir sal_Bool SfxRequest::AllowsRecording() const
966*cdf0e10cSrcweir {
967*cdf0e10cSrcweir     sal_Bool bAllow = pImp->bAllowRecording;
968*cdf0e10cSrcweir     if( !bAllow )
969*cdf0e10cSrcweir         bAllow = ( SFX_CALLMODE_API != ( SFX_CALLMODE_API & pImp->nCallMode ) ) &&
970*cdf0e10cSrcweir                  ( SFX_CALLMODE_RECORD == ( SFX_CALLMODE_RECORD & pImp->nCallMode ) );
971*cdf0e10cSrcweir     return bAllow;
972*cdf0e10cSrcweir }
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir void SfxRequest::ReleaseArgs()
975*cdf0e10cSrcweir {
976*cdf0e10cSrcweir     DELETEZ( pArgs );
977*cdf0e10cSrcweir     DELETEZ( pImp->pInternalArgs );
978*cdf0e10cSrcweir }
979