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 #include <cppuhelper/weak.hxx> 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #include <embeddoc.hxx> 30*cdf0e10cSrcweir #include <docholder.hxx> 31*cdf0e10cSrcweir #include <intercept.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir using namespace ::com::sun::star; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #define IUL 6 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > Interceptor::m_aInterceptedURL(IUL); 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir struct equalOUString 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir bool operator()( 49*cdf0e10cSrcweir const rtl::OUString& rKey1, 50*cdf0e10cSrcweir const rtl::OUString& rKey2 ) const 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir return !!( rKey1 == rKey2 ); 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir }; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir struct hashOUString 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir size_t operator()( const rtl::OUString& rName ) const 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir return rName.hashCode(); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir }; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir class StatusChangeListenerContainer 68*cdf0e10cSrcweir : public ::cppu::OMultiTypeInterfaceContainerHelperVar< 69*cdf0e10cSrcweir rtl::OUString,hashOUString,equalOUString> 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir public: 72*cdf0e10cSrcweir StatusChangeListenerContainer( ::osl::Mutex& aMutex ) 73*cdf0e10cSrcweir : cppu::OMultiTypeInterfaceContainerHelperVar< 74*cdf0e10cSrcweir rtl::OUString,hashOUString,equalOUString>(aMutex) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir void SAL_CALL 81*cdf0e10cSrcweir Interceptor::addEventListener( 82*cdf0e10cSrcweir const uno::Reference<lang::XEventListener >& Listener ) 83*cdf0e10cSrcweir throw( uno::RuntimeException ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir if ( ! m_pDisposeEventListeners ) 88*cdf0e10cSrcweir m_pDisposeEventListeners = 89*cdf0e10cSrcweir new cppu::OInterfaceContainerHelper( m_aMutex ); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir m_pDisposeEventListeners->addInterface( Listener ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir void SAL_CALL 96*cdf0e10cSrcweir Interceptor::removeEventListener( 97*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& Listener ) 98*cdf0e10cSrcweir throw( uno::RuntimeException ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir if ( m_pDisposeEventListeners ) 103*cdf0e10cSrcweir m_pDisposeEventListeners->removeInterface( Listener ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void SAL_CALL Interceptor::dispose() 108*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir lang::EventObject aEvt; 111*cdf0e10cSrcweir aEvt.Source = static_cast< frame::XDispatch* >( this ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) 116*cdf0e10cSrcweir m_pDisposeEventListeners->disposeAndClear( aEvt ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir if(m_pStatCL) 119*cdf0e10cSrcweir m_pStatCL->disposeAndClear( aEvt ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir m_xSlaveDispatchProvider = 0; 122*cdf0e10cSrcweir m_xMasterDispatchProvider = 0; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir Interceptor::Interceptor( 128*cdf0e10cSrcweir const ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl >& xOleAccess, 129*cdf0e10cSrcweir DocumentHolder* pDocH, 130*cdf0e10cSrcweir sal_Bool bLink ) 131*cdf0e10cSrcweir : m_xOleAccess( xOleAccess ), 132*cdf0e10cSrcweir m_xDocHLocker( static_cast< ::cppu::OWeakObject* >( pDocH ) ), 133*cdf0e10cSrcweir m_pDocH(pDocH), 134*cdf0e10cSrcweir m_pStatCL(0), 135*cdf0e10cSrcweir m_pDisposeEventListeners(0), 136*cdf0e10cSrcweir m_bLink( bLink ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir m_aInterceptedURL[0] = rtl::OUString( 139*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(".uno:Save")); 140*cdf0e10cSrcweir m_aInterceptedURL[1] = rtl::OUString( 141*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAll")); 142*cdf0e10cSrcweir m_aInterceptedURL[2] = rtl::OUString( 143*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc")); 144*cdf0e10cSrcweir m_aInterceptedURL[3] = rtl::OUString( 145*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(".uno:CloseWin")); 146*cdf0e10cSrcweir m_aInterceptedURL[4] = rtl::OUString( 147*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(".uno:CloseFrame")); 148*cdf0e10cSrcweir m_aInterceptedURL[5] = rtl::OUString( 149*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAs")); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir Interceptor::~Interceptor() 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir if( m_pDisposeEventListeners ) 156*cdf0e10cSrcweir delete m_pDisposeEventListeners; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir if(m_pStatCL) 159*cdf0e10cSrcweir delete m_pStatCL; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir DocumentHolder* pTmpDocH = NULL; 162*cdf0e10cSrcweir uno::Reference< uno::XInterface > xLock; 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 165*cdf0e10cSrcweir xLock = m_xDocHLocker.get(); 166*cdf0e10cSrcweir if ( xLock.is() ) 167*cdf0e10cSrcweir pTmpDocH = m_pDocH; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir if ( pTmpDocH ) 171*cdf0e10cSrcweir pTmpDocH->ClearInterceptor(); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir void Interceptor::DisconnectDocHolder() 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 177*cdf0e10cSrcweir m_xDocHLocker.clear(); 178*cdf0e10cSrcweir m_pDocH = NULL; 179*cdf0e10cSrcweir m_xOleAccess = NULL; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //XDispatch 183*cdf0e10cSrcweir void SAL_CALL 184*cdf0e10cSrcweir Interceptor::dispatch( 185*cdf0e10cSrcweir const util::URL& URL, 186*cdf0e10cSrcweir const uno::Sequence< 187*cdf0e10cSrcweir beans::PropertyValue >& Arguments ) 188*cdf0e10cSrcweir throw (uno::RuntimeException) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl > xOleAccess; 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 193*cdf0e10cSrcweir xOleAccess = m_xOleAccess; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if ( xOleAccess.is() ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir LockedEmbedDocument_Impl aDocLock = xOleAccess->GetEmbedDocument(); 199*cdf0e10cSrcweir if ( aDocLock.GetEmbedDocument() ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir if( !m_bLink && URL.Complete == m_aInterceptedURL[0]) 202*cdf0e10cSrcweir aDocLock.GetEmbedDocument()->SaveObject(); 203*cdf0e10cSrcweir else if(!m_bLink 204*cdf0e10cSrcweir && ( URL.Complete == m_aInterceptedURL[2] || 205*cdf0e10cSrcweir URL.Complete == m_aInterceptedURL[3] || 206*cdf0e10cSrcweir URL.Complete == m_aInterceptedURL[4] ) ) 207*cdf0e10cSrcweir aDocLock.GetEmbedDocument()->Close( 0 ); 208*cdf0e10cSrcweir else if ( URL.Complete == m_aInterceptedURL[5] ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aNewArgs = Arguments; 211*cdf0e10cSrcweir sal_Int32 nInd = 0; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir while( nInd < aNewArgs.getLength() ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir if ( aNewArgs[nInd].Name.equalsAscii( "SaveTo" ) ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir aNewArgs[nInd].Value <<= sal_True; 218*cdf0e10cSrcweir break; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir nInd++; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir if ( nInd == aNewArgs.getLength() ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir aNewArgs.realloc( nInd + 1 ); 226*cdf0e10cSrcweir aNewArgs[nInd].Name = ::rtl::OUString::createFromAscii( "SaveTo" ); 227*cdf0e10cSrcweir aNewArgs[nInd].Value <<= sal_True; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir uno::Reference< frame::XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch( 231*cdf0e10cSrcweir URL, ::rtl::OUString::createFromAscii( "_self" ), 0 ); 232*cdf0e10cSrcweir if ( xDispatch.is() ) 233*cdf0e10cSrcweir xDispatch->dispatch( URL, aNewArgs ); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir void Interceptor::generateFeatureStateEvent() 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir if( m_pStatCL ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir DocumentHolder* pTmpDocH = NULL; 245*cdf0e10cSrcweir uno::Reference< uno::XInterface > xLock; 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 248*cdf0e10cSrcweir xLock = m_xDocHLocker.get(); 249*cdf0e10cSrcweir if ( xLock.is() ) 250*cdf0e10cSrcweir pTmpDocH = m_pDocH; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir ::rtl::OUString aTitle; 254*cdf0e10cSrcweir if ( pTmpDocH ) 255*cdf0e10cSrcweir aTitle = pTmpDocH->getTitle(); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir for(int i = 0; i < IUL; ++i) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir if( i == 1 || m_bLink && i != 5 ) 260*cdf0e10cSrcweir continue; 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir cppu::OInterfaceContainerHelper* pICH = 263*cdf0e10cSrcweir m_pStatCL->getContainer(m_aInterceptedURL[i]); 264*cdf0e10cSrcweir uno::Sequence<uno::Reference<uno::XInterface> > aSeq; 265*cdf0e10cSrcweir if(pICH) 266*cdf0e10cSrcweir aSeq = pICH->getElements(); 267*cdf0e10cSrcweir if(!aSeq.getLength()) 268*cdf0e10cSrcweir continue; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir frame::FeatureStateEvent aStateEvent; 271*cdf0e10cSrcweir aStateEvent.IsEnabled = sal_True; 272*cdf0e10cSrcweir aStateEvent.Requery = sal_False; 273*cdf0e10cSrcweir if(i == 0) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0]; 277*cdf0e10cSrcweir aStateEvent.FeatureDescriptor = rtl::OUString( 278*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Update")); 279*cdf0e10cSrcweir aStateEvent.State <<= (rtl::OUString( 280*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("($1) ")) + 281*cdf0e10cSrcweir aTitle); 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir else if ( i == 5 ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir aStateEvent.FeatureURL.Complete = m_aInterceptedURL[5]; 287*cdf0e10cSrcweir aStateEvent.FeatureDescriptor = rtl::OUString( 288*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("SaveCopyTo")); 289*cdf0e10cSrcweir aStateEvent.State <<= (rtl::OUString( 290*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("($3)"))); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir else 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i]; 295*cdf0e10cSrcweir aStateEvent.FeatureDescriptor = rtl::OUString( 296*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Close and Return")); 297*cdf0e10cSrcweir aStateEvent.State <<= (rtl::OUString( 298*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("($2) ")) + 299*cdf0e10cSrcweir aTitle); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir for(sal_Int32 k = 0; k < aSeq.getLength(); ++k) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir uno::Reference<frame::XStatusListener> 306*cdf0e10cSrcweir Control(aSeq[k],uno::UNO_QUERY); 307*cdf0e10cSrcweir if(Control.is()) 308*cdf0e10cSrcweir Control->statusChanged(aStateEvent); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir void SAL_CALL 317*cdf0e10cSrcweir Interceptor::addStatusListener( 318*cdf0e10cSrcweir const uno::Reference< 319*cdf0e10cSrcweir frame::XStatusListener >& Control, 320*cdf0e10cSrcweir const util::URL& URL ) 321*cdf0e10cSrcweir throw ( 322*cdf0e10cSrcweir uno::RuntimeException 323*cdf0e10cSrcweir ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir if(!Control.is()) 326*cdf0e10cSrcweir return; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir if( !m_bLink && URL.Complete == m_aInterceptedURL[0] ) 329*cdf0e10cSrcweir { // Save 330*cdf0e10cSrcweir DocumentHolder* pTmpDocH = NULL; 331*cdf0e10cSrcweir uno::Reference< uno::XInterface > xLock; 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 334*cdf0e10cSrcweir xLock = m_xDocHLocker.get(); 335*cdf0e10cSrcweir if ( xLock.is() ) 336*cdf0e10cSrcweir pTmpDocH = m_pDocH; 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir ::rtl::OUString aTitle; 340*cdf0e10cSrcweir if ( pTmpDocH ) 341*cdf0e10cSrcweir aTitle = pTmpDocH->getTitle(); 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir frame::FeatureStateEvent aStateEvent; 344*cdf0e10cSrcweir aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0]; 345*cdf0e10cSrcweir aStateEvent.FeatureDescriptor = rtl::OUString( 346*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Update")); 347*cdf0e10cSrcweir aStateEvent.IsEnabled = sal_True; 348*cdf0e10cSrcweir aStateEvent.Requery = sal_False; 349*cdf0e10cSrcweir aStateEvent.State <<= (rtl::OUString( 350*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("($1) ")) + 351*cdf0e10cSrcweir aTitle ); 352*cdf0e10cSrcweir Control->statusChanged(aStateEvent); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 356*cdf0e10cSrcweir if(!m_pStatCL) 357*cdf0e10cSrcweir m_pStatCL = 358*cdf0e10cSrcweir new StatusChangeListenerContainer(m_aMutex); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir m_pStatCL->addInterface(URL.Complete,Control); 362*cdf0e10cSrcweir return; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir sal_Int32 i = 2; 366*cdf0e10cSrcweir if ( !m_bLink 367*cdf0e10cSrcweir && ( URL.Complete == m_aInterceptedURL[i] || 368*cdf0e10cSrcweir URL.Complete == m_aInterceptedURL[++i] || 369*cdf0e10cSrcweir URL.Complete == m_aInterceptedURL[++i] ) ) 370*cdf0e10cSrcweir { // Close and return 371*cdf0e10cSrcweir DocumentHolder* pTmpDocH = NULL; 372*cdf0e10cSrcweir uno::Reference< uno::XInterface > xLock; 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 375*cdf0e10cSrcweir xLock = m_xDocHLocker.get(); 376*cdf0e10cSrcweir if ( xLock.is() ) 377*cdf0e10cSrcweir pTmpDocH = m_pDocH; 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir ::rtl::OUString aTitle; 381*cdf0e10cSrcweir if ( pTmpDocH ) 382*cdf0e10cSrcweir aTitle = pTmpDocH->getTitle(); 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir frame::FeatureStateEvent aStateEvent; 385*cdf0e10cSrcweir aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i]; 386*cdf0e10cSrcweir aStateEvent.FeatureDescriptor = rtl::OUString( 387*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Close and Return")); 388*cdf0e10cSrcweir aStateEvent.IsEnabled = sal_True; 389*cdf0e10cSrcweir aStateEvent.Requery = sal_False; 390*cdf0e10cSrcweir aStateEvent.State <<= (rtl::OUString( 391*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("($2) ")) + 392*cdf0e10cSrcweir aTitle ); 393*cdf0e10cSrcweir Control->statusChanged(aStateEvent); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 398*cdf0e10cSrcweir if(!m_pStatCL) 399*cdf0e10cSrcweir m_pStatCL = 400*cdf0e10cSrcweir new StatusChangeListenerContainer(m_aMutex); 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir m_pStatCL->addInterface(URL.Complete,Control); 404*cdf0e10cSrcweir return; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir if(URL.Complete == m_aInterceptedURL[5]) 408*cdf0e10cSrcweir { // SaveAs 409*cdf0e10cSrcweir frame::FeatureStateEvent aStateEvent; 410*cdf0e10cSrcweir aStateEvent.FeatureURL.Complete = m_aInterceptedURL[5]; 411*cdf0e10cSrcweir aStateEvent.FeatureDescriptor = rtl::OUString( 412*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("SaveCopyTo")); 413*cdf0e10cSrcweir aStateEvent.IsEnabled = sal_True; 414*cdf0e10cSrcweir aStateEvent.Requery = sal_False; 415*cdf0e10cSrcweir aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($3)"))); 416*cdf0e10cSrcweir Control->statusChanged(aStateEvent); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 420*cdf0e10cSrcweir if(!m_pStatCL) 421*cdf0e10cSrcweir m_pStatCL = 422*cdf0e10cSrcweir new StatusChangeListenerContainer(m_aMutex); 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir m_pStatCL->addInterface(URL.Complete,Control); 426*cdf0e10cSrcweir return; 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir void SAL_CALL 433*cdf0e10cSrcweir Interceptor::removeStatusListener( 434*cdf0e10cSrcweir const uno::Reference< 435*cdf0e10cSrcweir frame::XStatusListener >& Control, 436*cdf0e10cSrcweir const util::URL& URL ) 437*cdf0e10cSrcweir throw ( 438*cdf0e10cSrcweir uno::RuntimeException 439*cdf0e10cSrcweir ) 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir if(!(Control.is() && m_pStatCL)) 442*cdf0e10cSrcweir return; 443*cdf0e10cSrcweir else { 444*cdf0e10cSrcweir m_pStatCL->removeInterface(URL.Complete,Control); 445*cdf0e10cSrcweir return; 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir //XInterceptorInfo 451*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > 452*cdf0e10cSrcweir SAL_CALL 453*cdf0e10cSrcweir Interceptor::getInterceptedURLs( ) 454*cdf0e10cSrcweir throw ( 455*cdf0e10cSrcweir uno::RuntimeException 456*cdf0e10cSrcweir ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir // now implemented as update 459*cdf0e10cSrcweir if ( m_bLink ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aResult( 2 ); 462*cdf0e10cSrcweir aResult[0] = m_aInterceptedURL[1]; 463*cdf0e10cSrcweir aResult[1] = m_aInterceptedURL[5]; 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir return aResult; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir return m_aInterceptedURL; 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir // XDispatchProvider 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir uno::Reference< frame::XDispatch > SAL_CALL 475*cdf0e10cSrcweir Interceptor::queryDispatch( 476*cdf0e10cSrcweir const util::URL& URL, 477*cdf0e10cSrcweir const ::rtl::OUString& TargetFrameName, 478*cdf0e10cSrcweir sal_Int32 SearchFlags ) 479*cdf0e10cSrcweir throw ( 480*cdf0e10cSrcweir uno::RuntimeException 481*cdf0e10cSrcweir ) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 484*cdf0e10cSrcweir if( !m_bLink && URL.Complete == m_aInterceptedURL[0] ) 485*cdf0e10cSrcweir return (frame::XDispatch*)this; 486*cdf0e10cSrcweir else if(URL.Complete == m_aInterceptedURL[1]) 487*cdf0e10cSrcweir return (frame::XDispatch*)0 ; 488*cdf0e10cSrcweir else if( !m_bLink && URL.Complete == m_aInterceptedURL[2] ) 489*cdf0e10cSrcweir return (frame::XDispatch*)this; 490*cdf0e10cSrcweir else if( !m_bLink && URL.Complete == m_aInterceptedURL[3] ) 491*cdf0e10cSrcweir return (frame::XDispatch*)this; 492*cdf0e10cSrcweir else if( !m_bLink && URL.Complete == m_aInterceptedURL[4] ) 493*cdf0e10cSrcweir return (frame::XDispatch*)this; 494*cdf0e10cSrcweir else if(URL.Complete == m_aInterceptedURL[5]) 495*cdf0e10cSrcweir return (frame::XDispatch*)this; 496*cdf0e10cSrcweir else { 497*cdf0e10cSrcweir if(m_xSlaveDispatchProvider.is()) 498*cdf0e10cSrcweir return m_xSlaveDispatchProvider->queryDispatch( 499*cdf0e10cSrcweir URL,TargetFrameName,SearchFlags); 500*cdf0e10cSrcweir else 501*cdf0e10cSrcweir return uno::Reference<frame::XDispatch>(0); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL 506*cdf0e10cSrcweir Interceptor::queryDispatches( 507*cdf0e10cSrcweir const uno::Sequence<frame::DispatchDescriptor >& Requests ) 508*cdf0e10cSrcweir throw ( 509*cdf0e10cSrcweir uno::RuntimeException 510*cdf0e10cSrcweir ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir uno::Sequence< uno::Reference< frame::XDispatch > > aRet; 513*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 514*cdf0e10cSrcweir if(m_xSlaveDispatchProvider.is()) 515*cdf0e10cSrcweir aRet = m_xSlaveDispatchProvider->queryDispatches(Requests); 516*cdf0e10cSrcweir else 517*cdf0e10cSrcweir aRet.realloc(Requests.getLength()); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir for(sal_Int32 i = 0; i < Requests.getLength(); ++i) 520*cdf0e10cSrcweir if ( !m_bLink && m_aInterceptedURL[0] == Requests[i].FeatureURL.Complete ) 521*cdf0e10cSrcweir aRet[i] = (frame::XDispatch*) this; 522*cdf0e10cSrcweir else if(m_aInterceptedURL[1] == Requests[i].FeatureURL.Complete) 523*cdf0e10cSrcweir aRet[i] = (frame::XDispatch*) 0; 524*cdf0e10cSrcweir else if( !m_bLink && m_aInterceptedURL[2] == Requests[i].FeatureURL.Complete ) 525*cdf0e10cSrcweir aRet[i] = (frame::XDispatch*) this; 526*cdf0e10cSrcweir else if( !m_bLink && m_aInterceptedURL[3] == Requests[i].FeatureURL.Complete ) 527*cdf0e10cSrcweir aRet[i] = (frame::XDispatch*) this; 528*cdf0e10cSrcweir else if( !m_bLink && m_aInterceptedURL[4] == Requests[i].FeatureURL.Complete ) 529*cdf0e10cSrcweir aRet[i] = (frame::XDispatch*) this; 530*cdf0e10cSrcweir else if(m_aInterceptedURL[5] == Requests[i].FeatureURL.Complete) 531*cdf0e10cSrcweir aRet[i] = (frame::XDispatch*) this; 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir return aRet; 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir //XDispatchProviderInterceptor 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > SAL_CALL 541*cdf0e10cSrcweir Interceptor::getSlaveDispatchProvider( ) 542*cdf0e10cSrcweir throw ( 543*cdf0e10cSrcweir uno::RuntimeException 544*cdf0e10cSrcweir ) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 547*cdf0e10cSrcweir return m_xSlaveDispatchProvider; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir void SAL_CALL 551*cdf0e10cSrcweir Interceptor::setSlaveDispatchProvider( 552*cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& NewDispatchProvider ) 553*cdf0e10cSrcweir throw ( 554*cdf0e10cSrcweir uno::RuntimeException 555*cdf0e10cSrcweir ) 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 558*cdf0e10cSrcweir m_xSlaveDispatchProvider = NewDispatchProvider; 559*cdf0e10cSrcweir } 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > SAL_CALL 563*cdf0e10cSrcweir Interceptor::getMasterDispatchProvider( ) 564*cdf0e10cSrcweir throw ( 565*cdf0e10cSrcweir uno::RuntimeException 566*cdf0e10cSrcweir ) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 569*cdf0e10cSrcweir return m_xMasterDispatchProvider; 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir void SAL_CALL 574*cdf0e10cSrcweir Interceptor::setMasterDispatchProvider( 575*cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& NewSupplier ) 576*cdf0e10cSrcweir throw ( 577*cdf0e10cSrcweir uno::RuntimeException 578*cdf0e10cSrcweir ) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 581*cdf0e10cSrcweir m_xMasterDispatchProvider = NewSupplier; 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir // Fix strange warnings about some 585*cdf0e10cSrcweir // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions. 586*cdf0e10cSrcweir // warning C4505: 'xxx' : unreferenced local function has been removed 587*cdf0e10cSrcweir #if defined(_MSC_VER) 588*cdf0e10cSrcweir #pragma warning(disable: 4505) 589*cdf0e10cSrcweir #endif 590