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 #ifdef SOLARIS 32*cdf0e10cSrcweir // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8 33*cdf0e10cSrcweir #include <ctime> 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 37*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/frame/XFrameActionListener.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/frame/FrameActionEvent.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/frame/FrameAction.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 45*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 46*cdf0e10cSrcweir #include <svl/eitem.hxx> 47*cdf0e10cSrcweir #include <svl/intitem.hxx> 48*cdf0e10cSrcweir #include <svl/stritem.hxx> 49*cdf0e10cSrcweir #include <svl/visitem.hxx> 50*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #ifndef GCC 53*cdf0e10cSrcweir #endif 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <sfx2/app.hxx> 56*cdf0e10cSrcweir #include <sfx2/appuno.hxx> 57*cdf0e10cSrcweir #include "statcach.hxx" 58*cdf0e10cSrcweir #include <sfx2/msg.hxx> 59*cdf0e10cSrcweir #include <sfx2/ctrlitem.hxx> 60*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 61*cdf0e10cSrcweir #include "sfxtypes.hxx" 62*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx> 63*cdf0e10cSrcweir #include <sfx2/unoctitm.hxx> 64*cdf0e10cSrcweir #include <sfx2/msgpool.hxx> 65*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir using namespace ::com::sun::star; 68*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 69*cdf0e10cSrcweir using namespace ::com::sun::star::util; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir //==================================================================== 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir DBG_NAME(SfxStateCache) 74*cdf0e10cSrcweir DBG_NAME(SfxStateCacheSetState) 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir SFX_IMPL_XINTERFACE_2( BindDispatch_Impl, OWeakObject, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener ) 77*cdf0e10cSrcweir SFX_IMPL_XTYPEPROVIDER_2( BindDispatch_Impl, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener ) 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //----------------------------------------------------------------------------- 80*cdf0e10cSrcweir BindDispatch_Impl::BindDispatch_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > & rDisp, const ::com::sun::star::util::URL& rURL, SfxStateCache *pStateCache, const SfxSlot* pS ) 81*cdf0e10cSrcweir : xDisp( rDisp ) 82*cdf0e10cSrcweir , aURL( rURL ) 83*cdf0e10cSrcweir , pCache( pStateCache ) 84*cdf0e10cSrcweir , pSlot( pS ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir DBG_ASSERT( pCache && pSlot, "Invalid BindDispatch!"); 87*cdf0e10cSrcweir aStatus.IsEnabled = sal_True; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir void SAL_CALL BindDispatch_Impl::disposing( const ::com::sun::star::lang::EventObject& ) throw( ::com::sun::star::uno::RuntimeException ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir if ( xDisp.is() ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir xDisp->removeStatusListener( (::com::sun::star::frame::XStatusListener*) this, aURL ); 95*cdf0e10cSrcweir xDisp = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > (); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir void SAL_CALL BindDispatch_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent ) throw( ::com::sun::star::uno::RuntimeException ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir aStatus = rEvent; 102*cdf0e10cSrcweir if ( !pCache ) 103*cdf0e10cSrcweir return; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > xRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY ); 106*cdf0e10cSrcweir if ( aStatus.Requery ) 107*cdf0e10cSrcweir pCache->Invalidate( sal_True ); 108*cdf0e10cSrcweir else 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir SfxPoolItem *pItem=NULL; 111*cdf0e10cSrcweir sal_uInt16 nId = pCache->GetId(); 112*cdf0e10cSrcweir SfxItemState eState = SFX_ITEM_DISABLED; 113*cdf0e10cSrcweir // pCache->Invalidate( sal_False ); 114*cdf0e10cSrcweir if ( !aStatus.IsEnabled ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir // default 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir else if (aStatus.State.hasValue()) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir eState = SFX_ITEM_AVAILABLE; 121*cdf0e10cSrcweir ::com::sun::star::uno::Any aAny = aStatus.State; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir ::com::sun::star::uno::Type pType = aAny.getValueType(); 124*cdf0e10cSrcweir if ( pType == ::getBooleanCppuType() ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir sal_Bool bTemp = false; 127*cdf0e10cSrcweir aAny >>= bTemp ; 128*cdf0e10cSrcweir pItem = new SfxBoolItem( nId, bTemp ); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir else if ( pType == ::getCppuType((const sal_uInt16*)0) ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir sal_uInt16 nTemp = 0; 133*cdf0e10cSrcweir aAny >>= nTemp ; 134*cdf0e10cSrcweir pItem = new SfxUInt16Item( nId, nTemp ); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir else if ( pType == ::getCppuType((const sal_uInt32*)0) ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir sal_uInt32 nTemp = 0; 139*cdf0e10cSrcweir aAny >>= nTemp ; 140*cdf0e10cSrcweir pItem = new SfxUInt32Item( nId, nTemp ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir else if ( pType == ::getCppuType((const ::rtl::OUString*)0) ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir ::rtl::OUString sTemp ; 145*cdf0e10cSrcweir aAny >>= sTemp ; 146*cdf0e10cSrcweir pItem = new SfxStringItem( nId, sTemp ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir if ( pSlot ) 151*cdf0e10cSrcweir pItem = pSlot->GetType()->CreateItem(); 152*cdf0e10cSrcweir if ( pItem ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir pItem->SetWhich( nId ); 155*cdf0e10cSrcweir pItem->PutValue( aAny ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir else 158*cdf0e10cSrcweir pItem = new SfxVoidItem( nId ); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir else 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir // DONTCARE status 164*cdf0e10cSrcweir pItem = new SfxVoidItem(0); 165*cdf0e10cSrcweir eState = SFX_ITEM_UNKNOWN; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir for ( SfxControllerItem *pCtrl = pCache->GetItemLink(); 169*cdf0e10cSrcweir pCtrl; 170*cdf0e10cSrcweir pCtrl = pCtrl->GetItemLink() ) 171*cdf0e10cSrcweir pCtrl->StateChanged( nId, eState, pItem ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir delete pItem; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir void BindDispatch_Impl::Release() 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir if ( xDisp.is() ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir xDisp->removeStatusListener( (::com::sun::star::frame::XStatusListener*) this, aURL ); 182*cdf0e10cSrcweir xDisp = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > (); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir pCache = NULL; 186*cdf0e10cSrcweir release(); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir const ::com::sun::star::frame::FeatureStateEvent& BindDispatch_Impl::GetStatus() const 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir return aStatus; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir void BindDispatch_Impl::Dispatch( uno::Sequence < beans::PropertyValue > aProps, sal_Bool bForceSynchron ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir if ( xDisp.is() && aStatus.IsEnabled ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir sal_Int32 nLength = aProps.getLength(); 199*cdf0e10cSrcweir aProps.realloc(nLength+1); 200*cdf0e10cSrcweir aProps[nLength].Name = DEFINE_CONST_UNICODE("SynchronMode"); 201*cdf0e10cSrcweir aProps[nLength].Value <<= bForceSynchron ; 202*cdf0e10cSrcweir xDisp->dispatch( aURL, aProps ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //-------------------------------------------------------------------- 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir /* Dieser Konstruktor fuer einen ungueltigen Cache, der sich also 209*cdf0e10cSrcweir bei der ersten Anfrage zun"achst updated. 210*cdf0e10cSrcweir */ 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir SfxStateCache::SfxStateCache( sal_uInt16 nFuncId ): 213*cdf0e10cSrcweir pDispatch( 0 ), 214*cdf0e10cSrcweir nId(nFuncId), 215*cdf0e10cSrcweir pInternalController(0), 216*cdf0e10cSrcweir pController(0), 217*cdf0e10cSrcweir pLastItem( 0 ), 218*cdf0e10cSrcweir eLastState( 0 ), 219*cdf0e10cSrcweir bItemVisible( sal_True ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir DBG_MEMTEST(); 222*cdf0e10cSrcweir DBG_CTOR(SfxStateCache, 0); 223*cdf0e10cSrcweir bCtrlDirty = sal_True; 224*cdf0e10cSrcweir bSlotDirty = sal_True; 225*cdf0e10cSrcweir bItemDirty = sal_True; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir //-------------------------------------------------------------------- 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir /* Der Destruktor pr"uft per Assertion, ob noch Controller angemeldet 231*cdf0e10cSrcweir sind. 232*cdf0e10cSrcweir */ 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir SfxStateCache::~SfxStateCache() 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir DBG_MEMTEST(); 237*cdf0e10cSrcweir DBG_DTOR(SfxStateCache, 0); 238*cdf0e10cSrcweir DBG_ASSERT( pController == 0 && pInternalController == 0, "es sind noch Controller angemeldet" ); 239*cdf0e10cSrcweir if ( !IsInvalidItem(pLastItem) ) 240*cdf0e10cSrcweir delete pLastItem; 241*cdf0e10cSrcweir if ( pDispatch ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir pDispatch->Release(); 244*cdf0e10cSrcweir pDispatch = NULL; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir //-------------------------------------------------------------------- 249*cdf0e10cSrcweir // invalidates the cache (next request will force update) 250*cdf0e10cSrcweir void SfxStateCache::Invalidate( sal_Bool bWithMsg ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir bCtrlDirty = sal_True; 253*cdf0e10cSrcweir if ( bWithMsg ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir bSlotDirty = sal_True; 256*cdf0e10cSrcweir aSlotServ.SetSlot( 0 ); 257*cdf0e10cSrcweir if ( pDispatch ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir pDispatch->Release(); 260*cdf0e10cSrcweir pDispatch = NULL; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //-------------------------------------------------------------------- 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir // gets the corresponding function from the dispatcher or the cache 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir const SfxSlotServer* SfxStateCache::GetSlotServer( SfxDispatcher &rDispat , const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir DBG_MEMTEST(); 272*cdf0e10cSrcweir DBG_CHKTHIS(SfxStateCache, 0); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir if ( bSlotDirty ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir // get the SlotServer; we need it for internal controllers anyway, but also in most cases 277*cdf0e10cSrcweir rDispat._FindServer( nId, aSlotServ, sal_False ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir DBG_ASSERT( !pDispatch, "Old Dispatch not removed!" ); 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir // we don't need to check the dispatch provider if we only have an internal controller 282*cdf0e10cSrcweir if ( xProv.is() ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir const SfxSlot* pSlot = aSlotServ.GetSlot(); 285*cdf0e10cSrcweir if ( !pSlot ) 286*cdf0e10cSrcweir // get the slot - even if it is disabled on the dispatcher 287*cdf0e10cSrcweir pSlot = SfxSlotPool::GetSlotPool( rDispat.GetFrame() ).GetSlot( nId ); 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir if ( !pSlot || !pSlot->pUnoName ) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir bSlotDirty = sal_False; 292*cdf0e10cSrcweir bCtrlDirty = sal_True; 293*cdf0e10cSrcweir return aSlotServ.GetSlot()? &aSlotServ: 0; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir // create the dispatch URL from the slot data 297*cdf0e10cSrcweir ::com::sun::star::util::URL aURL; 298*cdf0e10cSrcweir ::rtl::OUString aCmd = DEFINE_CONST_UNICODE(".uno:"); 299*cdf0e10cSrcweir aURL.Protocol = aCmd; 300*cdf0e10cSrcweir aURL.Path = ::rtl::OUString::createFromAscii( pSlot->GetUnoName() ); 301*cdf0e10cSrcweir aCmd += aURL.Path; 302*cdf0e10cSrcweir aURL.Complete = aCmd; 303*cdf0e10cSrcweir aURL.Main = aCmd; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir // try to get a dispatch object for this command 306*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 ); 307*cdf0e10cSrcweir if ( xDisp.is() ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir // test the dispatch object if it is just a wrapper for a SfxDispatcher 310*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel( xDisp, ::com::sun::star::uno::UNO_QUERY ); 311*cdf0e10cSrcweir SfxOfficeDispatch* pDisp = NULL; 312*cdf0e10cSrcweir if ( xTunnel.is() ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier()); 315*cdf0e10cSrcweir pDisp = reinterpret_cast< SfxOfficeDispatch* >(sal::static_int_cast< sal_IntPtr >( nImplementation )); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir if ( pDisp ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir // The intercepting object is an SFX component 321*cdf0e10cSrcweir // If this dispatch object does not use the wanted dispatcher or the AppDispatcher, it's treated like any other UNO component 322*cdf0e10cSrcweir // (intercepting by internal dispatches) 323*cdf0e10cSrcweir SfxDispatcher *pDispatcher = pDisp->GetDispatcher_Impl(); 324*cdf0e10cSrcweir if ( pDispatcher == &rDispat || pDispatcher == SFX_APP()->GetAppDispatcher_Impl() ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir // so we can use it directly 327*cdf0e10cSrcweir bSlotDirty = sal_False; 328*cdf0e10cSrcweir bCtrlDirty = sal_True; 329*cdf0e10cSrcweir return aSlotServ.GetSlot()? &aSlotServ: 0; 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir // so the dispatch object isn't a SfxDispatcher wrapper or it is one, but it uses another dispatcher, but not rDispat 334*cdf0e10cSrcweir pDispatch = new BindDispatch_Impl( xDisp, aURL, this, pSlot ); 335*cdf0e10cSrcweir pDispatch->acquire(); 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // flags must be set before adding StatusListener because the dispatch object will set the state 338*cdf0e10cSrcweir bSlotDirty = sal_False; 339*cdf0e10cSrcweir bCtrlDirty = sal_True; 340*cdf0e10cSrcweir xDisp->addStatusListener( pDispatch, aURL ); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir else if ( rDispat.GetFrame() ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchProvider > xFrameProv( 345*cdf0e10cSrcweir rDispat.GetFrame()->GetFrame().GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY ); 346*cdf0e10cSrcweir if ( xFrameProv != xProv ) 347*cdf0e10cSrcweir return GetSlotServer( rDispat, xFrameProv ); 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir bSlotDirty = sal_False; 352*cdf0e10cSrcweir bCtrlDirty = sal_True; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir // we *always* return a SlotServer (if there is one); but in case of an external dispatch we might not use it 356*cdf0e10cSrcweir // for the "real" (non internal) controllers 357*cdf0e10cSrcweir return aSlotServ.GetSlot()? &aSlotServ: 0; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir //-------------------------------------------------------------------- 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir // Status setzen in allen Controllern 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir void SfxStateCache::SetState 366*cdf0e10cSrcweir ( 367*cdf0e10cSrcweir SfxItemState eState, // <SfxItemState> von 'pState' 368*cdf0e10cSrcweir const SfxPoolItem* pState, // Status des Slots, ggf. 0 oder -1 369*cdf0e10cSrcweir sal_Bool bMaybeDirty 370*cdf0e10cSrcweir ) 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir /* [Beschreibung] 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir Diese Methode verteilt die Status auf alle an dieser SID gebundenen 375*cdf0e10cSrcweir <SfxControllerItem>s. Ist der Wert derselbe wie zuvor und wurde in- 376*cdf0e10cSrcweir zwischen weder ein Controller angemeldet, noch ein Controller invalidiert, 377*cdf0e10cSrcweir dann wird kein Wert weitergeleitet. Dadurch wird z.B. Flackern in 378*cdf0e10cSrcweir ListBoxen vermieden. 379*cdf0e10cSrcweir */ 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir // if ( pDispatch ) 383*cdf0e10cSrcweir // return; 384*cdf0e10cSrcweir SetState_Impl( eState, pState, bMaybeDirty ); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir //-------------------------------------------------------------------- 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir void SfxStateCache::SetVisibleState( sal_Bool bShow ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir SfxItemState eState( SFX_ITEM_AVAILABLE ); 392*cdf0e10cSrcweir const SfxPoolItem* pState( NULL ); 393*cdf0e10cSrcweir sal_Bool bNotify( sal_False ); 394*cdf0e10cSrcweir sal_Bool bDeleteItem( sal_False ); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir if ( bShow != bItemVisible ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir bItemVisible = bShow; 399*cdf0e10cSrcweir if ( bShow ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir if ( IsInvalidItem(pLastItem) || ( pLastItem == NULL )) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir pState = new SfxVoidItem( nId ); 404*cdf0e10cSrcweir bDeleteItem = sal_True; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir else 407*cdf0e10cSrcweir pState = pLastItem; 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir eState = eLastState; 410*cdf0e10cSrcweir bNotify = ( pState != 0 ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir else 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir pState = new SfxVisibilityItem( nId, sal_False ); 415*cdf0e10cSrcweir bDeleteItem = sal_True; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir // Controller updaten 419*cdf0e10cSrcweir if ( !pDispatch && pController ) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir for ( SfxControllerItem *pCtrl = pController; 422*cdf0e10cSrcweir pCtrl; 423*cdf0e10cSrcweir pCtrl = pCtrl->GetItemLink() ) 424*cdf0e10cSrcweir pCtrl->StateChanged( nId, eState, pState ); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir if ( pInternalController ) 428*cdf0e10cSrcweir pInternalController->StateChanged( nId, eState, pState ); 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir if ( !bDeleteItem ) 431*cdf0e10cSrcweir delete pState; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //-------------------------------------------------------------------- 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir void SfxStateCache::SetState_Impl 438*cdf0e10cSrcweir ( 439*cdf0e10cSrcweir SfxItemState eState, // <SfxItemState> von 'pState' 440*cdf0e10cSrcweir const SfxPoolItem* pState, // Status des Slots, ggf. 0 oder -1 441*cdf0e10cSrcweir sal_Bool bMaybeDirty 442*cdf0e10cSrcweir ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir (void)bMaybeDirty; //unused 445*cdf0e10cSrcweir DBG_MEMTEST(); 446*cdf0e10cSrcweir DBG_CHKTHIS(SfxStateCache, 0); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir // wenn zwischen Enter- und LeaveRegistrations ein hartes Update kommt 449*cdf0e10cSrcweir // k"onnen zwischenzeitlich auch Cached ohne Controller exisitieren 450*cdf0e10cSrcweir if ( !pController && !pInternalController ) 451*cdf0e10cSrcweir return; 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir DBG_ASSERT( bMaybeDirty || !bSlotDirty, "setting state of dirty message" ); 454*cdf0e10cSrcweir // DBG_ASSERT( bCtrlDirty || ( aSlotServ.GetSlot() && aSlotServ.GetSlot()->IsMode(SFX_SLOT_VOLATILE) ), ! Discussed with MBA 455*cdf0e10cSrcweir // "setting state of non dirty controller" ); 456*cdf0e10cSrcweir DBG_ASSERT( SfxControllerItem::GetItemState(pState) == eState, "invalid SfxItemState" ); 457*cdf0e10cSrcweir DBG_PROFSTART(SfxStateCacheSetState); 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir // m"ussen die Controller "uberhaupt benachrichtigt werden? 460*cdf0e10cSrcweir bool bNotify = bItemDirty; 461*cdf0e10cSrcweir if ( !bItemDirty ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir bool bBothAvailable = pLastItem && pState && 464*cdf0e10cSrcweir !IsInvalidItem(pState) && !IsInvalidItem(pLastItem); 465*cdf0e10cSrcweir DBG_ASSERT( !bBothAvailable || pState != pLastItem, "setting state with own item" ); 466*cdf0e10cSrcweir if ( bBothAvailable ) 467*cdf0e10cSrcweir bNotify = pState->Type() != pLastItem->Type() || 468*cdf0e10cSrcweir *pState != *pLastItem; 469*cdf0e10cSrcweir else 470*cdf0e10cSrcweir bNotify = ( pState != pLastItem ) || ( eState != eLastState ); 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir if ( bNotify ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir // Controller updaten 476*cdf0e10cSrcweir if ( !pDispatch && pController ) 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir for ( SfxControllerItem *pCtrl = pController; 479*cdf0e10cSrcweir pCtrl; 480*cdf0e10cSrcweir pCtrl = pCtrl->GetItemLink() ) 481*cdf0e10cSrcweir pCtrl->StateChanged( nId, eState, pState ); 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir if ( pInternalController ) 485*cdf0e10cSrcweir ((SfxDispatchController_Impl *)pInternalController)->StateChanged( nId, eState, pState, &aSlotServ ); 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir // neuen Wert merken 488*cdf0e10cSrcweir if ( !IsInvalidItem(pLastItem) ) 489*cdf0e10cSrcweir DELETEZ(pLastItem); 490*cdf0e10cSrcweir if ( pState && !IsInvalidItem(pState) ) 491*cdf0e10cSrcweir pLastItem = pState->Clone(); 492*cdf0e10cSrcweir else 493*cdf0e10cSrcweir pLastItem = 0; 494*cdf0e10cSrcweir eLastState = eState; 495*cdf0e10cSrcweir bItemDirty = sal_False; 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir bCtrlDirty = sal_False; 499*cdf0e10cSrcweir DBG_PROFSTOP(SfxStateCacheSetState); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir //-------------------------------------------------------------------- 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir // alten Status in allen Controllern nochmal setzen 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir void SfxStateCache::SetCachedState( sal_Bool bAlways ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir DBG_MEMTEST(); 510*cdf0e10cSrcweir DBG_CHKTHIS(SfxStateCache, 0); 511*cdf0e10cSrcweir DBG_ASSERT(pController==NULL||pController->GetId()==nId, "Cache mit falschem ControllerItem" ); 512*cdf0e10cSrcweir DBG_PROFSTART(SfxStateCacheSetState); 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // nur updaten wenn cached item vorhanden und auch verarbeitbar 515*cdf0e10cSrcweir // (Wenn der State gesendet wird, mu\s sichergestellt sein, da\s ein 516*cdf0e10cSrcweir // Slotserver vorhanden ist, s. SfxControllerItem::GetCoreMetric() ) 517*cdf0e10cSrcweir if ( bAlways || ( !bItemDirty && !bSlotDirty ) ) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir // Controller updaten 520*cdf0e10cSrcweir if ( !pDispatch && pController ) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir for ( SfxControllerItem *pCtrl = pController; 523*cdf0e10cSrcweir pCtrl; 524*cdf0e10cSrcweir pCtrl = pCtrl->GetItemLink() ) 525*cdf0e10cSrcweir pCtrl->StateChanged( nId, eLastState, pLastItem ); 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir if ( pInternalController ) 529*cdf0e10cSrcweir ((SfxDispatchController_Impl *)pInternalController)->StateChanged( nId, eLastState, pLastItem, &aSlotServ ); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir // Controller sind jetzt ok 532*cdf0e10cSrcweir bCtrlDirty = sal_True; 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir DBG_PROFSTOP(SfxStateCacheSetState); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir //-------------------------------------------------------------------- 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir // FloatingWindows in allen Controls mit dieser Id zerstoeren 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir void SfxStateCache::DeleteFloatingWindows() 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir DBG_MEMTEST(); 546*cdf0e10cSrcweir DBG_CHKTHIS(SfxStateCache, 0); 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir SfxControllerItem *pNextCtrl=0; 549*cdf0e10cSrcweir for ( SfxControllerItem *pCtrl=pController; pCtrl; pCtrl=pNextCtrl ) 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir DBG_TRACE((ByteString("pCtrl: ").Append(ByteString::CreateFromInt64((sal_uIntPtr)pCtrl))).GetBuffer()); 552*cdf0e10cSrcweir pNextCtrl = pCtrl->GetItemLink(); 553*cdf0e10cSrcweir pCtrl->DeleteFloatingWindow(); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SfxStateCache::GetDispatch() const 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir if ( pDispatch ) 560*cdf0e10cSrcweir return pDispatch->xDisp; 561*cdf0e10cSrcweir return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > (); 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir void SfxStateCache::Dispatch( const SfxItemSet* pSet, sal_Bool bForceSynchron ) 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir // protect pDispatch against destruction in the call 567*cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::frame::XStatusListener > xKeepAlive( pDispatch ); 568*cdf0e10cSrcweir if ( pDispatch ) 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > aArgs; 571*cdf0e10cSrcweir if (pSet) 572*cdf0e10cSrcweir TransformItems( nId, *pSet, aArgs ); 573*cdf0e10cSrcweir pDispatch->Dispatch( aArgs, bForceSynchron ); 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir 578