xref: /aoo42x/main/sfx2/source/control/unoctitm.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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <svl/eitem.hxx>
33*cdf0e10cSrcweir #include <svl/stritem.hxx>
34*cdf0e10cSrcweir #include <svl/intitem.hxx>
35*cdf0e10cSrcweir #include <svl/itemset.hxx>
36*cdf0e10cSrcweir #include <svl/visitem.hxx>
37*cdf0e10cSrcweir #include <svtools/javacontext.hxx>
38*cdf0e10cSrcweir #include <svl/itempool.hxx>
39*cdf0e10cSrcweir #include <tools/urlobj.hxx>
40*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/frame/XFrameActionListener.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/FrameActionEvent.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/FrameAction.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemStatus.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemState.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/frame/status/Visibility.hpp>
51*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
52*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
53*cdf0e10cSrcweir #include <vos/mutex.hxx>
54*cdf0e10cSrcweir #include <uno/current_context.hxx>
55*cdf0e10cSrcweir #include <vcl/svapp.hxx>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include <sfx2/app.hxx>
58*cdf0e10cSrcweir #include <sfx2/unoctitm.hxx>
59*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
60*cdf0e10cSrcweir #include <sfx2/frame.hxx>
61*cdf0e10cSrcweir #include <sfx2/ctrlitem.hxx>
62*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
63*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
64*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
65*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
66*cdf0e10cSrcweir #include <sfx2/request.hxx>
67*cdf0e10cSrcweir #include "statcach.hxx"
68*cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
69*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir namespace css = ::com::sun::star;
72*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
73*cdf0e10cSrcweir using namespace ::com::sun::star::util;
74*cdf0e10cSrcweir //long nOfficeDispatchCount = 0;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir enum URLTypeId
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     URLType_BOOL,
79*cdf0e10cSrcweir     URLType_BYTE,
80*cdf0e10cSrcweir     URLType_SHORT,
81*cdf0e10cSrcweir     URLType_LONG,
82*cdf0e10cSrcweir     URLType_HYPER,
83*cdf0e10cSrcweir     URLType_STRING,
84*cdf0e10cSrcweir     URLType_FLOAT,
85*cdf0e10cSrcweir     URLType_DOUBLE,
86*cdf0e10cSrcweir     URLType_COUNT
87*cdf0e10cSrcweir };
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir const char* URLTypeNames[URLType_COUNT] =
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir     "bool",
92*cdf0e10cSrcweir     "byte",
93*cdf0e10cSrcweir     "short",
94*cdf0e10cSrcweir     "long",
95*cdf0e10cSrcweir     "hyper",
96*cdf0e10cSrcweir     "string",
97*cdf0e10cSrcweir     "float",
98*cdf0e10cSrcweir     "double"
99*cdf0e10cSrcweir };
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir SFX_IMPL_XINTERFACE_2( SfxUnoControllerItem, OWeakObject, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
102*cdf0e10cSrcweir SFX_IMPL_XTYPEPROVIDER_2( SfxUnoControllerItem, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir SfxUnoControllerItem::SfxUnoControllerItem( SfxControllerItem *pItem, SfxBindings& rBind, const String& rCmd )
105*cdf0e10cSrcweir 	: pCtrlItem( pItem )
106*cdf0e10cSrcweir     , pBindings( &rBind )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	DBG_ASSERT( !pCtrlItem || !pCtrlItem->IsBound(), "ControllerItem fehlerhaft!" );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	aCommand.Complete = rCmd;
111*cdf0e10cSrcweir     Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
112*cdf0e10cSrcweir     xTrans->parseStrict( aCommand );
113*cdf0e10cSrcweir 	pBindings->RegisterUnoController_Impl( this );
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir SfxUnoControllerItem::~SfxUnoControllerItem()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir 	// tell bindings to forget this controller ( if still connected )
119*cdf0e10cSrcweir 	if ( pBindings )
120*cdf0e10cSrcweir 		pBindings->ReleaseUnoController_Impl( this );
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir void SfxUnoControllerItem::UnBind()
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	// connection to SfxControllerItem is lost
126*cdf0e10cSrcweir 	pCtrlItem = NULL;
127*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >  aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
128*cdf0e10cSrcweir 	ReleaseDispatch();
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir void SAL_CALL SfxUnoControllerItem::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& rEvent) throw ( ::com::sun::star::uno::RuntimeException )
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
134*cdf0e10cSrcweir 	DBG_ASSERT( pCtrlItem, "dispatch implementation didn't respect our previous removeStatusListener call!" );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	if ( rEvent.Requery )
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		// Fehler kann nur passieren, wenn das alte Dispatch fehlerhaft implementiert
139*cdf0e10cSrcweir 		// ist, also removeStatusListener nicht gefunzt hat. Aber sowas soll
140*cdf0e10cSrcweir 		// ja vorkommen ...
141*cdf0e10cSrcweir 		// Also besser vor ReleaseDispatch gegen Abflug sch"utzen!
142*cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >  aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY  );
143*cdf0e10cSrcweir 		ReleaseDispatch();
144*cdf0e10cSrcweir 		if ( pCtrlItem )
145*cdf0e10cSrcweir 			GetNewDispatch(); 		// asynchron ??
146*cdf0e10cSrcweir 	}
147*cdf0e10cSrcweir 	else if ( pCtrlItem )
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		SfxItemState eState = SFX_ITEM_DISABLED;
150*cdf0e10cSrcweir 		SfxPoolItem* pItem = NULL;
151*cdf0e10cSrcweir 		if ( rEvent.IsEnabled )
152*cdf0e10cSrcweir 		{
153*cdf0e10cSrcweir 			eState = SFX_ITEM_AVAILABLE;
154*cdf0e10cSrcweir 			::com::sun::star::uno::Type pType =	rEvent.State.getValueType();
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 			if ( pType == ::getBooleanCppuType() )
157*cdf0e10cSrcweir 			{
158*cdf0e10cSrcweir 				sal_Bool bTemp = false;
159*cdf0e10cSrcweir 				rEvent.State >>= bTemp ;
160*cdf0e10cSrcweir 				pItem = new SfxBoolItem( pCtrlItem->GetId(), bTemp );
161*cdf0e10cSrcweir 			}
162*cdf0e10cSrcweir 			else if ( pType == ::getCppuType((const sal_uInt16*)0) )
163*cdf0e10cSrcweir 			{
164*cdf0e10cSrcweir 				sal_uInt16 nTemp = 0;
165*cdf0e10cSrcweir 				rEvent.State >>= nTemp ;
166*cdf0e10cSrcweir 				pItem = new SfxUInt16Item( pCtrlItem->GetId(), nTemp );
167*cdf0e10cSrcweir 			}
168*cdf0e10cSrcweir 			else if ( pType == ::getCppuType((const sal_uInt32*)0) )
169*cdf0e10cSrcweir 			{
170*cdf0e10cSrcweir 				sal_uInt32 nTemp = 0;
171*cdf0e10cSrcweir 				rEvent.State >>= nTemp ;
172*cdf0e10cSrcweir 				pItem = new SfxUInt32Item( pCtrlItem->GetId(), nTemp );
173*cdf0e10cSrcweir 			}
174*cdf0e10cSrcweir 			else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
175*cdf0e10cSrcweir 			{
176*cdf0e10cSrcweir 				::rtl::OUString sTemp ;
177*cdf0e10cSrcweir 				rEvent.State >>= sTemp ;
178*cdf0e10cSrcweir 				pItem = new SfxStringItem( pCtrlItem->GetId(), sTemp );
179*cdf0e10cSrcweir 			}
180*cdf0e10cSrcweir 			else
181*cdf0e10cSrcweir 				pItem = new SfxVoidItem( pCtrlItem->GetId() );
182*cdf0e10cSrcweir 		}
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 		pCtrlItem->StateChanged( pCtrlItem->GetId(), eState, pItem );
185*cdf0e10cSrcweir 		delete pItem;
186*cdf0e10cSrcweir 	}
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir void  SAL_CALL SfxUnoControllerItem::disposing( const ::com::sun::star::lang::EventObject& ) throw ( ::com::sun::star::uno::RuntimeException )
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >  aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
192*cdf0e10cSrcweir 	ReleaseDispatch();
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir void SfxUnoControllerItem::ReleaseDispatch()
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir 	if ( xDispatch.is() )
198*cdf0e10cSrcweir 	{
199*cdf0e10cSrcweir 		xDispatch->removeStatusListener( (::com::sun::star::frame::XStatusListener*) this, aCommand );
200*cdf0e10cSrcweir 		xDispatch = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > ();
201*cdf0e10cSrcweir 	}
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir void SfxUnoControllerItem::GetNewDispatch()
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir 	if ( !pBindings )
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir 		// Bindings released
209*cdf0e10cSrcweir 		DBG_ERROR( "Tried to get dispatch, but no Bindings!" );
210*cdf0e10cSrcweir 		return;
211*cdf0e10cSrcweir 	}
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 	// forget old dispatch
214*cdf0e10cSrcweir 	xDispatch = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > ();
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	// no arms, no cookies !
217*cdf0e10cSrcweir 	if ( !pBindings->GetDispatcher_Impl() || !pBindings->GetDispatcher_Impl()->GetFrame() )
218*cdf0e10cSrcweir 		return;
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	SfxFrame& rFrame = pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame();
221*cdf0e10cSrcweir 	SfxFrame *pParent = rFrame.GetParentFrame();
222*cdf0e10cSrcweir 	if ( pParent )
223*cdf0e10cSrcweir 		// parent may intercept
224*cdf0e10cSrcweir 		xDispatch = TryGetDispatch( pParent );
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	if ( !xDispatch.is() )
227*cdf0e10cSrcweir 	{
228*cdf0e10cSrcweir 		// no interception
229*cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >  xFrame = rFrame.GetFrameInterface();
230*cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >  xProv( xFrame, ::com::sun::star::uno::UNO_QUERY );
231*cdf0e10cSrcweir 		if ( xProv.is() )
232*cdf0e10cSrcweir 			xDispatch = xProv->queryDispatch( aCommand, ::rtl::OUString(), 0 );
233*cdf0e10cSrcweir 	}
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 	if ( xDispatch.is() )
236*cdf0e10cSrcweir 		xDispatch->addStatusListener( (::com::sun::star::frame::XStatusListener*) this, aCommand );
237*cdf0e10cSrcweir 	else if ( pCtrlItem )
238*cdf0e10cSrcweir 		pCtrlItem->StateChanged( pCtrlItem->GetId(), SFX_ITEM_DISABLED, NULL );
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >  SfxUnoControllerItem::TryGetDispatch( SfxFrame *pFrame )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >  xDisp;
244*cdf0e10cSrcweir 	SfxFrame *pParent = pFrame->GetParentFrame();
245*cdf0e10cSrcweir 	if ( pParent )
246*cdf0e10cSrcweir 		// parent may intercept
247*cdf0e10cSrcweir 		xDisp = TryGetDispatch( pParent );
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	// only components may intercept
250*cdf0e10cSrcweir 	if ( !xDisp.is() && pFrame->HasComponent() )
251*cdf0e10cSrcweir 	{
252*cdf0e10cSrcweir 		// no interception
253*cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pFrame->GetFrameInterface();
254*cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >  xProv( xFrame, ::com::sun::star::uno::UNO_QUERY );
255*cdf0e10cSrcweir 		if ( xProv.is() )
256*cdf0e10cSrcweir 			xDisp = xProv->queryDispatch( aCommand, ::rtl::OUString(), 0 );
257*cdf0e10cSrcweir 	}
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	return xDisp;
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir void SfxUnoControllerItem::Execute()
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir 	// dispatch the resource
265*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq(1);
266*cdf0e10cSrcweir     aSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Referer") );
267*cdf0e10cSrcweir     aSeq[0].Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("private:select") );
268*cdf0e10cSrcweir 	if ( xDispatch.is() )
269*cdf0e10cSrcweir         xDispatch->dispatch( aCommand, aSeq );
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir void SfxUnoControllerItem::ReleaseBindings()
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir 	// connection to binding is lost; so forget the binding and the dispatch
275*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >  aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
276*cdf0e10cSrcweir 	ReleaseDispatch();
277*cdf0e10cSrcweir 	if ( pBindings )
278*cdf0e10cSrcweir 		pBindings->ReleaseUnoController_Impl( this );
279*cdf0e10cSrcweir 	pBindings = NULL;
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir void SfxStatusDispatcher::ReleaseAll()
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir 	::com::sun::star::lang::EventObject aObject;
285*cdf0e10cSrcweir 	aObject.Source = (::cppu::OWeakObject*) this;
286*cdf0e10cSrcweir 	aListeners.disposeAndClear( aObject );
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir void SAL_CALL SfxStatusDispatcher::dispatch( const ::com::sun::star::util::URL&, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& ) throw ( ::com::sun::star::uno::RuntimeException )
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir void SAL_CALL SfxStatusDispatcher::dispatchWithNotification(
294*cdf0e10cSrcweir     const ::com::sun::star::util::URL&,
295*cdf0e10cSrcweir     const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >&,
296*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& ) throw( ::com::sun::star::uno::RuntimeException )
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir SFX_IMPL_XINTERFACE_2( SfxStatusDispatcher, OWeakObject, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::frame::XDispatch )
301*cdf0e10cSrcweir SFX_IMPL_XTYPEPROVIDER_2( SfxStatusDispatcher, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::frame::XDispatch )
302*cdf0e10cSrcweir //IMPLNAME "com.sun.star.comp.sfx2.StatusDispatcher",
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir SfxStatusDispatcher::SfxStatusDispatcher()
305*cdf0e10cSrcweir 	: aListeners( aMutex )
306*cdf0e10cSrcweir {
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir void SAL_CALL SfxStatusDispatcher::addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL) throw ( ::com::sun::star::uno::RuntimeException )
310*cdf0e10cSrcweir {
311*cdf0e10cSrcweir 	aListeners.addInterface( aURL.Complete, aListener );
312*cdf0e10cSrcweir 	if ( aURL.Complete.compareToAscii(".uno:LifeTime")==0 )
313*cdf0e10cSrcweir 	{
314*cdf0e10cSrcweir 		::com::sun::star::frame::FeatureStateEvent aEvent;
315*cdf0e10cSrcweir 		aEvent.FeatureURL = aURL;
316*cdf0e10cSrcweir 		aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
317*cdf0e10cSrcweir 		aEvent.IsEnabled = sal_True;
318*cdf0e10cSrcweir 		aEvent.Requery = sal_False;
319*cdf0e10cSrcweir 		aListener->statusChanged( aEvent );
320*cdf0e10cSrcweir 	}
321*cdf0e10cSrcweir }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir void SAL_CALL SfxStatusDispatcher::removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL ) throw ( ::com::sun::star::uno::RuntimeException )
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir 	aListeners.removeInterface( aURL.Complete, aListener );
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir SFX_IMPL_XINTERFACE_1( SfxOfficeDispatch, SfxStatusDispatcher, ::com::sun::star::lang::XUnoTunnel )
329*cdf0e10cSrcweir SFX_IMPL_XTYPEPROVIDER_2( SfxOfficeDispatch, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::lang::XUnoTunnel )
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir //-------------------------------------------------------------------------
333*cdf0e10cSrcweir // XUnoTunnel
334*cdf0e10cSrcweir sal_Int64 SAL_CALL SfxOfficeDispatch::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
335*cdf0e10cSrcweir {
336*cdf0e10cSrcweir     if ( aIdentifier == impl_getStaticIdentifier() )
337*cdf0e10cSrcweir         return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
338*cdf0e10cSrcweir     else
339*cdf0e10cSrcweir         return 0;
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir /* ASDBG
343*cdf0e10cSrcweir void* SfxOfficeDispatch::getImplementation(Reflection *p)
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir 	if( p == ::getCppuType((const SfxOfficeDispatch*)0) )
346*cdf0e10cSrcweir 		return this;
347*cdf0e10cSrcweir 	else
348*cdf0e10cSrcweir 		return ::cppu::OWeakObject::getImplementation(p);
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir Reflection* ::getCppuType((const SfxOfficeDispatch*)0)
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir 	static StandardClassReflection aRefl(
355*cdf0e10cSrcweir 		0,
356*cdf0e10cSrcweir 		createStandardClass(
357*cdf0e10cSrcweir 			"SfxOfficeDispatch", ::cppu::OWeakObject::get::cppu::OWeakObjectIdlClass(),
358*cdf0e10cSrcweir 			1,
359*cdf0e10cSrcweir 			::getCppuType((const ::com::sun::star::frame::XDispatch*)0) ) );
360*cdf0e10cSrcweir 	return &aRefl;
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir */
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir SfxOfficeDispatch::SfxOfficeDispatch( SfxBindings& rBindings, SfxDispatcher* pDispat, const SfxSlot* pSlot, const ::com::sun::star::util::URL& rURL )
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir //    nOfficeDispatchCount++;
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir     // this object is an adapter that shows a ::com::sun::star::frame::XDispatch-Interface to the outside and uses a SfxControllerItem to monitor a state
369*cdf0e10cSrcweir     pControllerItem = new SfxDispatchController_Impl( this, &rBindings, pDispat, pSlot, rURL );
370*cdf0e10cSrcweir }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir SfxOfficeDispatch::SfxOfficeDispatch( SfxDispatcher* pDispat, const SfxSlot* pSlot, const ::com::sun::star::util::URL& rURL )
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir //    nOfficeDispatchCount++;
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir     // this object is an adapter that shows a ::com::sun::star::frame::XDispatch-Interface to the outside and uses a SfxControllerItem to monitor a state
377*cdf0e10cSrcweir     pControllerItem = new SfxDispatchController_Impl( this, NULL, pDispat, pSlot, rURL );
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir SfxOfficeDispatch::~SfxOfficeDispatch()
381*cdf0e10cSrcweir {
382*cdf0e10cSrcweir //    --nOfficeDispatchCount;
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir     if ( pControllerItem )
385*cdf0e10cSrcweir     {
386*cdf0e10cSrcweir         // when dispatch object is released, destroy its connection to this object and destroy it
387*cdf0e10cSrcweir         pControllerItem->UnBindController();
388*cdf0e10cSrcweir         delete pControllerItem;
389*cdf0e10cSrcweir     }
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< sal_Int8 >& SfxOfficeDispatch::impl_getStaticIdentifier()
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir     // {38 57 CA 80 09 36 11 d4 83 FE 00 50 04 52 6B 21}
395*cdf0e10cSrcweir     static sal_uInt8 pGUID[16] = { 0x38, 0x57, 0xCA, 0x80, 0x09, 0x36, 0x11, 0xd4, 0x83, 0xFE, 0x00, 0x50, 0x04, 0x52, 0x6B, 0x21 };
396*cdf0e10cSrcweir     static ::com::sun::star::uno::Sequence< sal_Int8 > seqID((sal_Int8*)pGUID,16) ;
397*cdf0e10cSrcweir     return seqID ;
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir void SAL_CALL SfxOfficeDispatch::dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw ( ::com::sun::star::uno::RuntimeException )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     // ControllerItem is the Impl class
404*cdf0e10cSrcweir     if ( pControllerItem )
405*cdf0e10cSrcweir     {
406*cdf0e10cSrcweir         // The JavaContext contains an interaction handler which is used when
407*cdf0e10cSrcweir         // the creation of a Java Virtual Machine fails. The second parameter
408*cdf0e10cSrcweir         // indicates, that there shall only be one user notification (message box)
409*cdf0e10cSrcweir         // even if the same error (interaction) reoccurs. The effect is, that if a
410*cdf0e10cSrcweir         // user selects a menu entry than they may get only one notification that
411*cdf0e10cSrcweir         // a JRE is not selected.
412*cdf0e10cSrcweir         com::sun::star::uno::ContextLayer layer(
413*cdf0e10cSrcweir             new svt::JavaContext( com::sun::star::uno::getCurrentContext(),
414*cdf0e10cSrcweir                                   true) );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir         pControllerItem->dispatch( aURL, aArgs, ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchResultListener >() );
417*cdf0e10cSrcweir     }
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir void SAL_CALL SfxOfficeDispatch::dispatchWithNotification( const ::com::sun::star::util::URL& aURL,
421*cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
422*cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException )
423*cdf0e10cSrcweir {
424*cdf0e10cSrcweir     // ControllerItem is the Impl class
425*cdf0e10cSrcweir     if ( pControllerItem )
426*cdf0e10cSrcweir     {
427*cdf0e10cSrcweir         // see comment for SfxOfficeDispatch::dispatch
428*cdf0e10cSrcweir         com::sun::star::uno::ContextLayer layer(
429*cdf0e10cSrcweir             new svt::JavaContext( com::sun::star::uno::getCurrentContext(),
430*cdf0e10cSrcweir                                   true) );
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir         pControllerItem->dispatch( aURL, aArgs, rListener );
433*cdf0e10cSrcweir     }
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir void SAL_CALL SfxOfficeDispatch::addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL) throw ( ::com::sun::star::uno::RuntimeException )
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir     GetListeners().addInterface( aURL.Complete, aListener );
439*cdf0e10cSrcweir     if ( pControllerItem )
440*cdf0e10cSrcweir     {
441*cdf0e10cSrcweir         // ControllerItem is the Impl class
442*cdf0e10cSrcweir         pControllerItem->addStatusListener( aListener, aURL );
443*cdf0e10cSrcweir     }
444*cdf0e10cSrcweir }
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir SfxDispatcher* SfxOfficeDispatch::GetDispatcher_Impl()
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir     return pControllerItem->GetDispatcher();
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir void SfxOfficeDispatch::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir     if ( pControllerItem )
454*cdf0e10cSrcweir         pControllerItem->SetFrame( xFrame );
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir void SfxOfficeDispatch::SetMasterUnoCommand( sal_Bool bSet )
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     if ( pControllerItem )
460*cdf0e10cSrcweir         pControllerItem->setMasterSlaveCommand( bSet );
461*cdf0e10cSrcweir }
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir sal_Bool SfxOfficeDispatch::IsMasterUnoCommand() const
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir     if ( pControllerItem )
466*cdf0e10cSrcweir         return pControllerItem->isMasterSlaveCommand();
467*cdf0e10cSrcweir     return sal_False;
468*cdf0e10cSrcweir }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir // Determine if URL contains a master/slave command which must be handled a little bit different
471*cdf0e10cSrcweir sal_Bool SfxOfficeDispatch::IsMasterUnoCommand( const ::com::sun::star::util::URL& aURL )
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir     if ( aURL.Protocol.equalsAscii( ".uno:" ) &&
474*cdf0e10cSrcweir          ( aURL.Path.indexOf( '.' ) > 0 ))
475*cdf0e10cSrcweir         return sal_True;
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir     return sal_False;
478*cdf0e10cSrcweir }
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir rtl::OUString SfxOfficeDispatch::GetMasterUnoCommand( const ::com::sun::star::util::URL& aURL )
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir     rtl::OUString aMasterCommand;
483*cdf0e10cSrcweir     if ( IsMasterUnoCommand( aURL ))
484*cdf0e10cSrcweir     {
485*cdf0e10cSrcweir         sal_Int32 nIndex = aURL.Path.indexOf( '.' );
486*cdf0e10cSrcweir         if ( nIndex > 0 )
487*cdf0e10cSrcweir             aMasterCommand = aURL.Path.copy( 0, nIndex );
488*cdf0e10cSrcweir     }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir     return aMasterCommand;
491*cdf0e10cSrcweir }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir SfxDispatchController_Impl::SfxDispatchController_Impl(
494*cdf0e10cSrcweir     SfxOfficeDispatch*                 pDisp,
495*cdf0e10cSrcweir     SfxBindings*                       pBind,
496*cdf0e10cSrcweir     SfxDispatcher*                     pDispat,
497*cdf0e10cSrcweir     const SfxSlot*                     pSlot,
498*cdf0e10cSrcweir     const ::com::sun::star::util::URL& rURL )
499*cdf0e10cSrcweir     : aDispatchURL( rURL )
500*cdf0e10cSrcweir     , pDispatcher( pDispat )
501*cdf0e10cSrcweir     , pBindings( pBind )
502*cdf0e10cSrcweir     , pLastState( 0 )
503*cdf0e10cSrcweir     , nSlot( pSlot->GetSlotId() )
504*cdf0e10cSrcweir     , pDispatch( pDisp )
505*cdf0e10cSrcweir     , bMasterSlave( sal_False )
506*cdf0e10cSrcweir     , bVisible( sal_True )
507*cdf0e10cSrcweir     , pUnoName( pSlot->pUnoName )
508*cdf0e10cSrcweir {
509*cdf0e10cSrcweir     if ( aDispatchURL.Protocol.equalsAscii("slot:") && pUnoName )
510*cdf0e10cSrcweir     {
511*cdf0e10cSrcweir         ByteString aTmp(".uno:");
512*cdf0e10cSrcweir         aTmp += pUnoName;
513*cdf0e10cSrcweir         aDispatchURL.Complete = ::rtl::OUString::createFromAscii( aTmp.GetBuffer() );
514*cdf0e10cSrcweir         Reference < ::com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
515*cdf0e10cSrcweir         xTrans->parseStrict( aDispatchURL );
516*cdf0e10cSrcweir     }
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir     SetId( nSlot );
519*cdf0e10cSrcweir     if ( pBindings )
520*cdf0e10cSrcweir     {
521*cdf0e10cSrcweir         // Bind immediately to enable the cache to recycle dispatches when asked for the same command
522*cdf0e10cSrcweir         // a command in "slot" or in ".uno" notation must be treated as identical commands!
523*cdf0e10cSrcweir         pBindings->ENTERREGISTRATIONS();
524*cdf0e10cSrcweir         BindInternal_Impl( nSlot, pBindings );
525*cdf0e10cSrcweir         pBindings->LEAVEREGISTRATIONS();
526*cdf0e10cSrcweir     }
527*cdf0e10cSrcweir }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir SfxDispatchController_Impl::~SfxDispatchController_Impl()
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir 	if ( pLastState && !IsInvalidItem( pLastState ) )
532*cdf0e10cSrcweir 		delete pLastState;
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir     if ( pDispatch )
535*cdf0e10cSrcweir     {
536*cdf0e10cSrcweir         // disconnect
537*cdf0e10cSrcweir         pDispatch->pControllerItem = NULL;
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir         // force all listeners to release the dispatch object
540*cdf0e10cSrcweir         ::com::sun::star::lang::EventObject aObject;
541*cdf0e10cSrcweir         aObject.Source = (::cppu::OWeakObject*) pDispatch;
542*cdf0e10cSrcweir         pDispatch->GetListeners().disposeAndClear( aObject );
543*cdf0e10cSrcweir     }
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir void SfxDispatchController_Impl::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame)
547*cdf0e10cSrcweir {
548*cdf0e10cSrcweir     xFrame = _xFrame;
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir void SfxDispatchController_Impl::setMasterSlaveCommand( sal_Bool bSet )
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir     bMasterSlave = bSet;
554*cdf0e10cSrcweir }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir sal_Bool SfxDispatchController_Impl::isMasterSlaveCommand() const
557*cdf0e10cSrcweir {
558*cdf0e10cSrcweir     return bMasterSlave;
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir void SfxDispatchController_Impl::UnBindController()
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir     pDispatch = NULL;
564*cdf0e10cSrcweir     if ( IsBound() )
565*cdf0e10cSrcweir     {
566*cdf0e10cSrcweir         GetBindings().ENTERREGISTRATIONS();
567*cdf0e10cSrcweir         SfxControllerItem::UnBind();
568*cdf0e10cSrcweir         GetBindings().LEAVEREGISTRATIONS();
569*cdf0e10cSrcweir     }
570*cdf0e10cSrcweir }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir void SfxDispatchController_Impl::addParametersToArgs( const com::sun::star::util::URL& aURL, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) const
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir     // Extract the parameter from the URL and put them into the property value sequence
575*cdf0e10cSrcweir     sal_Int32 nQueryIndex = aURL.Complete.indexOf( '?' );
576*cdf0e10cSrcweir     if ( nQueryIndex > 0 )
577*cdf0e10cSrcweir     {
578*cdf0e10cSrcweir         rtl::OUString aParamString( aURL.Complete.copy( nQueryIndex+1 ));
579*cdf0e10cSrcweir         sal_Int32 nIndex = 0;
580*cdf0e10cSrcweir         do
581*cdf0e10cSrcweir         {
582*cdf0e10cSrcweir             rtl::OUString aToken = aParamString.getToken( 0, '&', nIndex );
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir             sal_Int32 nParmIndex = 0;
585*cdf0e10cSrcweir             rtl::OUString aParamType;
586*cdf0e10cSrcweir             rtl::OUString aParamName = aToken.getToken( 0, '=', nParmIndex );
587*cdf0e10cSrcweir             rtl::OUString aValue     = (nParmIndex!=-1) ? aToken.getToken( 0, '=', nParmIndex ) : ::rtl::OUString();
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir             if ( aParamName.getLength() > 0 )
590*cdf0e10cSrcweir             {
591*cdf0e10cSrcweir                 nParmIndex = 0;
592*cdf0e10cSrcweir                 aToken = aParamName;
593*cdf0e10cSrcweir                 aParamName = (nParmIndex!=-1) ? aToken.getToken( 0, ':', nParmIndex ) : ::rtl::OUString();
594*cdf0e10cSrcweir                 aParamType = (nParmIndex!=-1) ? aToken.getToken( 0, ':', nParmIndex ) : ::rtl::OUString();
595*cdf0e10cSrcweir             }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir             sal_Int32 nLen = rArgs.getLength();
598*cdf0e10cSrcweir             rArgs.realloc( nLen+1 );
599*cdf0e10cSrcweir             rArgs[nLen].Name = aParamName;
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir             if ( aParamType.getLength() == 0 )
602*cdf0e10cSrcweir             {
603*cdf0e10cSrcweir                 // Default: LONG
604*cdf0e10cSrcweir                 rArgs[nLen].Value <<= aValue.toInt32();
605*cdf0e10cSrcweir             }
606*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_BOOL], 4 ))
607*cdf0e10cSrcweir             {
608*cdf0e10cSrcweir                 // sal_Bool support
609*cdf0e10cSrcweir                 rArgs[nLen].Value <<= aValue.toBoolean();
610*cdf0e10cSrcweir             }
611*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_BYTE], 4 ))
612*cdf0e10cSrcweir             {
613*cdf0e10cSrcweir                 // sal_uInt8 support
614*cdf0e10cSrcweir                 rArgs[nLen].Value <<= sal_Int8( aValue.toInt32() );
615*cdf0e10cSrcweir             }
616*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_LONG], 4 ))
617*cdf0e10cSrcweir             {
618*cdf0e10cSrcweir                 // LONG support
619*cdf0e10cSrcweir                 rArgs[nLen].Value <<= aValue.toInt32();
620*cdf0e10cSrcweir             }
621*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_SHORT], 5 ))
622*cdf0e10cSrcweir             {
623*cdf0e10cSrcweir                 // SHORT support
624*cdf0e10cSrcweir                 rArgs[nLen].Value <<= sal_Int8( aValue.toInt32() );
625*cdf0e10cSrcweir             }
626*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_HYPER], 5 ))
627*cdf0e10cSrcweir             {
628*cdf0e10cSrcweir                 // HYPER support
629*cdf0e10cSrcweir                 rArgs[nLen].Value <<= aValue.toInt64();
630*cdf0e10cSrcweir             }
631*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_FLOAT], 5 ))
632*cdf0e10cSrcweir             {
633*cdf0e10cSrcweir                 // FLOAT support
634*cdf0e10cSrcweir                 rArgs[nLen].Value <<= aValue.toFloat();
635*cdf0e10cSrcweir             }
636*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_STRING], 6 ))
637*cdf0e10cSrcweir             {
638*cdf0e10cSrcweir                 // STRING support
639*cdf0e10cSrcweir                 rArgs[nLen].Value <<= rtl::OUString( INetURLObject::decode( aValue, '%', INetURLObject::DECODE_WITH_CHARSET ));
640*cdf0e10cSrcweir             }
641*cdf0e10cSrcweir             else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_DOUBLE], 6))
642*cdf0e10cSrcweir             {
643*cdf0e10cSrcweir                 // DOUBLE support
644*cdf0e10cSrcweir                 rArgs[nLen].Value <<= aValue.toDouble();
645*cdf0e10cSrcweir             }
646*cdf0e10cSrcweir         }
647*cdf0e10cSrcweir         while ( nIndex >= 0 );
648*cdf0e10cSrcweir     }
649*cdf0e10cSrcweir }
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir SfxMapUnit SfxDispatchController_Impl::GetCoreMetric( SfxItemPool& rPool, sal_uInt16 nSlotId )
652*cdf0e10cSrcweir {
653*cdf0e10cSrcweir     sal_uInt16 nWhich = rPool.GetWhich( nSlotId );
654*cdf0e10cSrcweir     return rPool.GetMetric( nWhich );
655*cdf0e10cSrcweir }
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir rtl::OUString SfxDispatchController_Impl::getSlaveCommand( const ::com::sun::star::util::URL& rURL )
658*cdf0e10cSrcweir {
659*cdf0e10cSrcweir     rtl::OUString   aSlaveCommand;
660*cdf0e10cSrcweir     sal_Int32       nIndex = rURL.Path.indexOf( '.' );
661*cdf0e10cSrcweir     if (( nIndex > 0 ) && ( nIndex < rURL.Path.getLength() ))
662*cdf0e10cSrcweir         aSlaveCommand = rURL.Path.copy( nIndex+1 );
663*cdf0e10cSrcweir     return aSlaveCommand;
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir void SAL_CALL SfxDispatchController_Impl::dispatch( const ::com::sun::star::util::URL& aURL,
667*cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
668*cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException )
669*cdf0e10cSrcweir {
670*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
671*cdf0e10cSrcweir     if (
672*cdf0e10cSrcweir         pDispatch &&
673*cdf0e10cSrcweir         (
674*cdf0e10cSrcweir          (aURL.Protocol.equalsAsciiL( ".uno:", 5 ) && aURL.Path == aDispatchURL.Path) ||
675*cdf0e10cSrcweir          (aURL.Protocol.equalsAsciiL( "slot:", 5 ) && aURL.Path.toInt32() == GetId())
676*cdf0e10cSrcweir         )
677*cdf0e10cSrcweir        )
678*cdf0e10cSrcweir 	{
679*cdf0e10cSrcweir         /*
680*cdf0e10cSrcweir         if ( !IsBound() && pBindings )
681*cdf0e10cSrcweir         {
682*cdf0e10cSrcweir             pBindings->ENTERREGISTRATIONS();
683*cdf0e10cSrcweir             BindInternal_Impl( nSlot, pBindings );
684*cdf0e10cSrcweir             pBindings->LEAVEREGISTRATIONS();
685*cdf0e10cSrcweir         } */
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir         if ( !pDispatcher && pBindings )
688*cdf0e10cSrcweir             pDispatcher = GetBindings().GetDispatcher_Impl();
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lNewArgs;
691*cdf0e10cSrcweir         sal_Int32 nCount = aArgs.getLength();
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir         // Support for URL based arguments
694*cdf0e10cSrcweir         INetURLObject aURLObj( aURL.Complete );
695*cdf0e10cSrcweir         if ( aURLObj.HasParam() )
696*cdf0e10cSrcweir             addParametersToArgs( aURL, lNewArgs );
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir         // Try to find call mode and frame name inside given arguments...
699*cdf0e10cSrcweir         SfxCallMode nCall = SFX_CALLMODE_STANDARD;
700*cdf0e10cSrcweir         sal_Int32   nMarkArg = -1;
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir         // Filter arguments which shouldn't be part of the sequence property value
703*cdf0e10cSrcweir         sal_Bool    bTemp = sal_Bool();
704*cdf0e10cSrcweir         sal_uInt16  nModifier(0);
705*cdf0e10cSrcweir         std::vector< ::com::sun::star::beans::PropertyValue > aAddArgs;
706*cdf0e10cSrcweir         for( sal_Int32 n=0; n<nCount; n++ )
707*cdf0e10cSrcweir         {
708*cdf0e10cSrcweir             const ::com::sun::star::beans::PropertyValue& rProp = aArgs[n];
709*cdf0e10cSrcweir             if( rProp.Name.equalsAsciiL("SynchronMode",12))
710*cdf0e10cSrcweir             {
711*cdf0e10cSrcweir 				if( rProp.Value >>=bTemp )
712*cdf0e10cSrcweir                 	nCall = bTemp ? SFX_CALLMODE_SYNCHRON : SFX_CALLMODE_ASYNCHRON;
713*cdf0e10cSrcweir             }
714*cdf0e10cSrcweir             else if( rProp.Name.equalsAsciiL("Bookmark",8))
715*cdf0e10cSrcweir             {
716*cdf0e10cSrcweir                 nMarkArg = n;
717*cdf0e10cSrcweir                 aAddArgs.push_back( aArgs[n] );
718*cdf0e10cSrcweir             }
719*cdf0e10cSrcweir             else if( rProp.Name.equalsAsciiL("KeyModifier",11))
720*cdf0e10cSrcweir                 rProp.Value >>= nModifier;
721*cdf0e10cSrcweir             else
722*cdf0e10cSrcweir                 aAddArgs.push_back( aArgs[n] );
723*cdf0e10cSrcweir         }
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir         // Add needed arguments to sequence property value
726*cdf0e10cSrcweir         sal_uInt32 nAddArgs = aAddArgs.size();
727*cdf0e10cSrcweir         if ( nAddArgs > 0 )
728*cdf0e10cSrcweir         {
729*cdf0e10cSrcweir             sal_uInt32 nIndex( lNewArgs.getLength() );
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir             lNewArgs.realloc( lNewArgs.getLength()+aAddArgs.size() );
732*cdf0e10cSrcweir             for ( sal_uInt32 i = 0; i < nAddArgs; i++ )
733*cdf0e10cSrcweir                 lNewArgs[nIndex++] = aAddArgs[i];
734*cdf0e10cSrcweir         }
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir         // Overwrite possible detected sychron argument, if real listener exists (currently no other way)
737*cdf0e10cSrcweir         if ( rListener.is() )
738*cdf0e10cSrcweir             nCall = SFX_CALLMODE_SYNCHRON;
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir         if( GetId() == SID_JUMPTOMARK && nMarkArg == - 1 )
741*cdf0e10cSrcweir         {
742*cdf0e10cSrcweir 			// we offer dispatches for SID_JUMPTOMARK if the URL points to a bookmark inside the document
743*cdf0e10cSrcweir 			// so we must retrieve this as an argument from the parsed URL
744*cdf0e10cSrcweir             lNewArgs.realloc( lNewArgs.getLength()+1 );
745*cdf0e10cSrcweir             nMarkArg = lNewArgs.getLength()-1;
746*cdf0e10cSrcweir 	        lNewArgs[nMarkArg].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Bookmark"));
747*cdf0e10cSrcweir 	        lNewArgs[nMarkArg].Value <<= aURL.Mark;
748*cdf0e10cSrcweir         }
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir         css::uno::Reference< css::frame::XFrame > xFrameRef(xFrame.get(), css::uno::UNO_QUERY);
751*cdf0e10cSrcweir         if (! xFrameRef.is() && pDispatcher)
752*cdf0e10cSrcweir         {
753*cdf0e10cSrcweir             SfxViewFrame* pViewFrame = pDispatcher->GetFrame();
754*cdf0e10cSrcweir             if (pViewFrame)
755*cdf0e10cSrcweir                 xFrameRef = pViewFrame->GetFrame().GetFrameInterface();
756*cdf0e10cSrcweir         }
757*cdf0e10cSrcweir         SfxAllItemSet aInternalSet( SFX_APP()->GetPool() );
758*cdf0e10cSrcweir         if (xFrameRef.is()) // an empty set is no problem ... but an empty frame reference can be a problem !
759*cdf0e10cSrcweir             aInternalSet.Put( SfxUnoFrameItem( SID_FILLFRAME, xFrameRef ) );
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir         sal_Bool bSuccess = sal_False;
762*cdf0e10cSrcweir         sal_Bool bFailure = sal_False;
763*cdf0e10cSrcweir         const SfxPoolItem* pItem = NULL;
764*cdf0e10cSrcweir         SfxShell* pShell( 0 );
765*cdf0e10cSrcweir         // #i102619# Retrieve metric from shell before execution - the shell could be destroyed after execution
766*cdf0e10cSrcweir         SfxMapUnit eMapUnit( SFX_MAPUNIT_100TH_MM );
767*cdf0e10cSrcweir         if ( pDispatcher->GetBindings() )
768*cdf0e10cSrcweir         {
769*cdf0e10cSrcweir             if ( !pDispatcher->IsLocked( GetId() ) )
770*cdf0e10cSrcweir             {
771*cdf0e10cSrcweir                 const SfxSlot *pSlot = 0;
772*cdf0e10cSrcweir                 if ( pDispatcher->GetShellAndSlot_Impl( GetId(), &pShell, &pSlot, sal_False,
773*cdf0e10cSrcweir                         SFX_CALLMODE_MODAL==(nCall&SFX_CALLMODE_MODAL), sal_False ) )
774*cdf0e10cSrcweir                 {
775*cdf0e10cSrcweir                     if ( bMasterSlave )
776*cdf0e10cSrcweir                     {
777*cdf0e10cSrcweir                         // Extract slave command and add argument to the args list. Master slot MUST
778*cdf0e10cSrcweir                         // have a argument that has the same name as the master slot and type is SfxStringItem.
779*cdf0e10cSrcweir                         sal_Int32 nIndex = lNewArgs.getLength();
780*cdf0e10cSrcweir                         lNewArgs.realloc( nIndex+1 );
781*cdf0e10cSrcweir                         lNewArgs[nIndex].Name   = rtl::OUString::createFromAscii( pSlot->pUnoName );
782*cdf0e10cSrcweir                         lNewArgs[nIndex].Value  = makeAny( SfxDispatchController_Impl::getSlaveCommand( aDispatchURL ));
783*cdf0e10cSrcweir                     }
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir                     eMapUnit = GetCoreMetric( pShell->GetPool(), GetId() );
786*cdf0e10cSrcweir                     SfxAllItemSet aSet( pShell->GetPool() );
787*cdf0e10cSrcweir                     TransformParameters( GetId(), lNewArgs, aSet, pSlot );
788*cdf0e10cSrcweir                     if ( aSet.Count() )
789*cdf0e10cSrcweir                     {
790*cdf0e10cSrcweir                         // execute with arguments - call directly
791*cdf0e10cSrcweir                         pItem = pDispatcher->Execute( GetId(), nCall, &aSet, &aInternalSet, nModifier );
792*cdf0e10cSrcweir                         bSuccess = (pItem != NULL);
793*cdf0e10cSrcweir                     }
794*cdf0e10cSrcweir                     else
795*cdf0e10cSrcweir                     {
796*cdf0e10cSrcweir                         // execute using bindings, enables support for toggle/enum etc.
797*cdf0e10cSrcweir                         SfxRequest aReq( GetId(), nCall, pShell->GetPool() );
798*cdf0e10cSrcweir                         aReq.SetModifier( nModifier );
799*cdf0e10cSrcweir                         aReq.SetInternalArgs_Impl(aInternalSet);
800*cdf0e10cSrcweir                         pDispatcher->GetBindings()->Execute_Impl( aReq, pSlot, pShell );
801*cdf0e10cSrcweir                         pItem = aReq.GetReturnValue();
802*cdf0e10cSrcweir                         bSuccess = aReq.IsDone() || pItem != NULL;
803*cdf0e10cSrcweir                         bFailure = aReq.IsCancelled();
804*cdf0e10cSrcweir                     }
805*cdf0e10cSrcweir                 }
806*cdf0e10cSrcweir #ifdef DBG_UTIL
807*cdf0e10cSrcweir                 else
808*cdf0e10cSrcweir                     DBG_WARNING("MacroPlayer: Unknown slot dispatched!");
809*cdf0e10cSrcweir #endif
810*cdf0e10cSrcweir             }
811*cdf0e10cSrcweir         }
812*cdf0e10cSrcweir         else
813*cdf0e10cSrcweir         {
814*cdf0e10cSrcweir             eMapUnit = GetCoreMetric( SFX_APP()->GetPool(), GetId() );
815*cdf0e10cSrcweir             // AppDispatcher
816*cdf0e10cSrcweir             SfxAllItemSet aSet( SFX_APP()->GetPool() );
817*cdf0e10cSrcweir             TransformParameters( GetId(), lNewArgs, aSet );
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir             if ( aSet.Count() )
820*cdf0e10cSrcweir                 pItem = pDispatcher->Execute( GetId(), nCall, &aSet, &aInternalSet, nModifier );
821*cdf0e10cSrcweir             else
822*cdf0e10cSrcweir                 // SfxRequests take empty sets as argument sets, GetArgs() returning non-zero!
823*cdf0e10cSrcweir                 pItem = pDispatcher->Execute( GetId(), nCall, 0, &aInternalSet, nModifier );
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir             // no bindings, no invalidate ( usually done in SfxDispatcher::Call_Impl()! )
826*cdf0e10cSrcweir 			if ( SfxApplication::Get() )
827*cdf0e10cSrcweir 			{
828*cdf0e10cSrcweir             	SfxDispatcher* pAppDispat = SFX_APP()->GetAppDispatcher_Impl();
829*cdf0e10cSrcweir             	if ( pAppDispat )
830*cdf0e10cSrcweir             	{
831*cdf0e10cSrcweir                 	const SfxPoolItem* pState=0;
832*cdf0e10cSrcweir                  	SfxItemState eState = pDispatcher->QueryState( GetId(), pState );
833*cdf0e10cSrcweir                 	StateChanged( GetId(), eState, pState );
834*cdf0e10cSrcweir             	}
835*cdf0e10cSrcweir 			}
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir             bSuccess = (pItem != NULL);
838*cdf0e10cSrcweir         }
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir         if ( rListener.is() )
841*cdf0e10cSrcweir         {
842*cdf0e10cSrcweir             ::com::sun::star::frame::DispatchResultEvent aEvent;
843*cdf0e10cSrcweir             if ( bSuccess )
844*cdf0e10cSrcweir                 aEvent.State = com::sun::star::frame::DispatchResultState::SUCCESS;
845*cdf0e10cSrcweir //            else if ( bFailure )
846*cdf0e10cSrcweir             else
847*cdf0e10cSrcweir                 aEvent.State = com::sun::star::frame::DispatchResultState::FAILURE;
848*cdf0e10cSrcweir //            else
849*cdf0e10cSrcweir //                aEvent.State = com::sun::star::frame::DispatchResultState::DONTKNOW;
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir             aEvent.Source = (::com::sun::star::frame::XDispatch*) pDispatch;
852*cdf0e10cSrcweir             if ( bSuccess && pItem && !pItem->ISA(SfxVoidItem) )
853*cdf0e10cSrcweir             {
854*cdf0e10cSrcweir                 sal_uInt16 nSubId( 0 );
855*cdf0e10cSrcweir                 if ( eMapUnit == SFX_MAPUNIT_TWIP )
856*cdf0e10cSrcweir                     nSubId |= CONVERT_TWIPS;
857*cdf0e10cSrcweir                 pItem->QueryValue( aEvent.Result, (sal_uInt8)nSubId );
858*cdf0e10cSrcweir             }
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir             rListener->dispatchFinished( aEvent );
861*cdf0e10cSrcweir         }
862*cdf0e10cSrcweir 	}
863*cdf0e10cSrcweir }
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir SfxDispatcher* SfxDispatchController_Impl::GetDispatcher()
866*cdf0e10cSrcweir {
867*cdf0e10cSrcweir     if ( !pDispatcher && pBindings )
868*cdf0e10cSrcweir         pDispatcher = GetBindings().GetDispatcher_Impl();
869*cdf0e10cSrcweir     return pDispatcher;
870*cdf0e10cSrcweir }
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir void SAL_CALL SfxDispatchController_Impl::addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL) throw ( ::com::sun::star::uno::RuntimeException )
873*cdf0e10cSrcweir {
874*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
875*cdf0e10cSrcweir     if ( !pDispatch )
876*cdf0e10cSrcweir         return;
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir     /*if ( !IsBound() && pBindings )
879*cdf0e10cSrcweir     {
880*cdf0e10cSrcweir         pBindings->ENTERREGISTRATIONS();
881*cdf0e10cSrcweir         BindInternal_Impl( nSlot, pBindings );
882*cdf0e10cSrcweir         pBindings->LEAVEREGISTRATIONS();
883*cdf0e10cSrcweir     } */
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir     // Use alternative QueryState call to have a valid UNO representation of the state.
886*cdf0e10cSrcweir     ::com::sun::star::uno::Any aState;
887*cdf0e10cSrcweir     if ( !pDispatcher && pBindings )
888*cdf0e10cSrcweir         pDispatcher = GetBindings().GetDispatcher_Impl();
889*cdf0e10cSrcweir     SfxItemState eState = pDispatcher->QueryState( GetId(), aState );
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir     if ( eState == SFX_ITEM_DONTCARE )
892*cdf0e10cSrcweir     {
893*cdf0e10cSrcweir         // Use special uno struct to transport don't care state
894*cdf0e10cSrcweir         ::com::sun::star::frame::status::ItemStatus aItemStatus;
895*cdf0e10cSrcweir         aItemStatus.State = ::com::sun::star::frame::status::ItemState::dont_care;
896*cdf0e10cSrcweir         aState = makeAny( aItemStatus );
897*cdf0e10cSrcweir     }
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir     ::com::sun::star::frame::FeatureStateEvent  aEvent;
900*cdf0e10cSrcweir     aEvent.FeatureURL = aURL;
901*cdf0e10cSrcweir     aEvent.Source     = (::com::sun::star::frame::XDispatch*) pDispatch;
902*cdf0e10cSrcweir     aEvent.Requery    = sal_False;
903*cdf0e10cSrcweir     if ( bVisible )
904*cdf0e10cSrcweir     {
905*cdf0e10cSrcweir 	    aEvent.IsEnabled  = eState != SFX_ITEM_DISABLED;
906*cdf0e10cSrcweir 	    aEvent.State      = aState;
907*cdf0e10cSrcweir     }
908*cdf0e10cSrcweir     else
909*cdf0e10cSrcweir     {
910*cdf0e10cSrcweir         ::com::sun::star::frame::status::Visibility aVisibilityStatus;
911*cdf0e10cSrcweir         aVisibilityStatus.bVisible = sal_False;
912*cdf0e10cSrcweir 
913*cdf0e10cSrcweir         // MBA: we might decide to *not* disable "invisible" slots, but this would be
914*cdf0e10cSrcweir         // a change that needs to adjust at least the testtool
915*cdf0e10cSrcweir         aEvent.IsEnabled           = sal_False;
916*cdf0e10cSrcweir         aEvent.State               = makeAny( aVisibilityStatus );
917*cdf0e10cSrcweir     }
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir     aListener->statusChanged( aEvent );
920*cdf0e10cSrcweir }
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer* pSlotServ )
923*cdf0e10cSrcweir {
924*cdf0e10cSrcweir     if ( !pDispatch )
925*cdf0e10cSrcweir         return;
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir     // Bindings instance notifies controller about a state change, listeners must be notified also
928*cdf0e10cSrcweir     // Don't cache visibility state changes as they are volatile. We need our real state to send it
929*cdf0e10cSrcweir     // to our controllers after visibility is set to true.
930*cdf0e10cSrcweir 	sal_Bool bNotify = sal_True;
931*cdf0e10cSrcweir     if ( pState && !IsInvalidItem( pState ) )
932*cdf0e10cSrcweir     {
933*cdf0e10cSrcweir         if ( !pState->ISA( SfxVisibilityItem ) )
934*cdf0e10cSrcweir         {
935*cdf0e10cSrcweir             sal_Bool bBothAvailable = pLastState && !IsInvalidItem(pLastState);
936*cdf0e10cSrcweir             if ( bBothAvailable )
937*cdf0e10cSrcweir                 bNotify = pState->Type() != pLastState->Type() || *pState != *pLastState;
938*cdf0e10cSrcweir             if ( pLastState && !IsInvalidItem( pLastState ) )
939*cdf0e10cSrcweir                 delete pLastState;
940*cdf0e10cSrcweir             pLastState = !IsInvalidItem(pState) ? pState->Clone() : pState;
941*cdf0e10cSrcweir             bVisible = sal_True;
942*cdf0e10cSrcweir         }
943*cdf0e10cSrcweir         else
944*cdf0e10cSrcweir             bVisible = ((SfxVisibilityItem *)pState)->GetValue();
945*cdf0e10cSrcweir     }
946*cdf0e10cSrcweir     else
947*cdf0e10cSrcweir     {
948*cdf0e10cSrcweir         if ( pLastState && !IsInvalidItem( pLastState ) )
949*cdf0e10cSrcweir             delete pLastState;
950*cdf0e10cSrcweir         pLastState = pState;
951*cdf0e10cSrcweir     }
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete );
954*cdf0e10cSrcweir 	if ( bNotify && pContnr )
955*cdf0e10cSrcweir 	{
956*cdf0e10cSrcweir         ::com::sun::star::uno::Any aState;
957*cdf0e10cSrcweir         if ( ( eState >= SFX_ITEM_AVAILABLE ) && pState && !IsInvalidItem( pState ) && !pState->ISA(SfxVoidItem) )
958*cdf0e10cSrcweir         {
959*cdf0e10cSrcweir             // Retrieve metric from pool to have correct sub ID when calling QueryValue
960*cdf0e10cSrcweir             sal_uInt16     nSubId( 0 );
961*cdf0e10cSrcweir             SfxMapUnit eMapUnit( SFX_MAPUNIT_100TH_MM );
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir             // retrieve the core metric
964*cdf0e10cSrcweir             // it's enough to check the objectshell, the only shell that does not use the pool of the document
965*cdf0e10cSrcweir             // is SfxViewFrame, but it hasn't any metric parameters
966*cdf0e10cSrcweir             // TODO/LATER: what about the FormShell? Does it use any metric data?! Perhaps it should use the Pool of the document!
967*cdf0e10cSrcweir             if ( pSlotServ && pDispatcher )
968*cdf0e10cSrcweir             {
969*cdf0e10cSrcweir                 SfxShell* pShell = pDispatcher->GetShell( pSlotServ->GetShellLevel() );
970*cdf0e10cSrcweir                 DBG_ASSERT( pShell, "Can't get core metric without shell!" );
971*cdf0e10cSrcweir                 if ( pShell )
972*cdf0e10cSrcweir                     eMapUnit = GetCoreMetric( pShell->GetPool(), nSID );
973*cdf0e10cSrcweir             }
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir             if ( eMapUnit == SFX_MAPUNIT_TWIP )
976*cdf0e10cSrcweir                 nSubId |= CONVERT_TWIPS;
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir             pState->QueryValue( aState, (sal_uInt8)nSubId );
979*cdf0e10cSrcweir         }
980*cdf0e10cSrcweir         else if ( eState == SFX_ITEM_DONTCARE )
981*cdf0e10cSrcweir         {
982*cdf0e10cSrcweir             // Use special uno struct to transport don't care state
983*cdf0e10cSrcweir             ::com::sun::star::frame::status::ItemStatus aItemStatus;
984*cdf0e10cSrcweir             aItemStatus.State = ::com::sun::star::frame::status::ItemState::dont_care;
985*cdf0e10cSrcweir             aState = makeAny( aItemStatus );
986*cdf0e10cSrcweir         }
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir 		::com::sun::star::frame::FeatureStateEvent aEvent;
989*cdf0e10cSrcweir 		aEvent.FeatureURL = aDispatchURL;
990*cdf0e10cSrcweir         aEvent.Source = (::com::sun::star::frame::XDispatch*) pDispatch;
991*cdf0e10cSrcweir 		aEvent.IsEnabled = eState != SFX_ITEM_DISABLED;
992*cdf0e10cSrcweir 		aEvent.Requery = sal_False;
993*cdf0e10cSrcweir 		aEvent.State = aState;
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir 		::cppu::OInterfaceIteratorHelper aIt( *pContnr );
996*cdf0e10cSrcweir 		while( aIt.hasMoreElements() )
997*cdf0e10cSrcweir         {
998*cdf0e10cSrcweir             try
999*cdf0e10cSrcweir             {
1000*cdf0e10cSrcweir                 ((::com::sun::star::frame::XStatusListener *)aIt.next())->statusChanged( aEvent );
1001*cdf0e10cSrcweir             }
1002*cdf0e10cSrcweir             catch( ::com::sun::star::uno::RuntimeException& )
1003*cdf0e10cSrcweir             {
1004*cdf0e10cSrcweir                 aIt.remove();
1005*cdf0e10cSrcweir             }
1006*cdf0e10cSrcweir         }
1007*cdf0e10cSrcweir 	}
1008*cdf0e10cSrcweir }
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1011*cdf0e10cSrcweir {
1012*cdf0e10cSrcweir     StateChanged( nSID, eState, pState, 0 );
1013*cdf0e10cSrcweir }
1014