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 #include <com/sun/star/uno/Reference.h> 31*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/frame/XNotifyingDispatch.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchResultListener.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/system/XSystemShellExecute.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h> 53*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 54*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 55*cdf0e10cSrcweir #include <rtl/ustring.hxx> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 59*cdf0e10cSrcweir #include <comphelper/synchronousdispatch.hxx> 60*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 61*cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx> 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 64*cdf0e10cSrcweir #include <svl/intitem.hxx> 65*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 66*cdf0e10cSrcweir #include <svl/stritem.hxx> 67*cdf0e10cSrcweir #include <svl/eitem.hxx> 68*cdf0e10cSrcweir #include <sfx2/doctempl.hxx> 69*cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 70*cdf0e10cSrcweir #include <framework/preventduplicateinteraction.hxx> 71*cdf0e10cSrcweir #include <svtools/ehdl.hxx> 72*cdf0e10cSrcweir #include <basic/sbxobj.hxx> 73*cdf0e10cSrcweir #include <svl/urihelper.hxx> 74*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 75*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 76*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 77*cdf0e10cSrcweir #include <svtools/templdlg.hxx> 78*cdf0e10cSrcweir #include <osl/file.hxx> 79*cdf0e10cSrcweir #include <unotools/extendedsecurityoptions.hxx> 80*cdf0e10cSrcweir #include <comphelper/docpasswordhelper.hxx> 81*cdf0e10cSrcweir #include <vcl/svapp.hxx> 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir #include <vos/mutex.hxx> 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir #include <rtl/logfile.hxx> 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir #include <sfx2/app.hxx> 88*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 89*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 90*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 91*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 92*cdf0e10cSrcweir #include <sfx2/new.hxx> 93*cdf0e10cSrcweir #include <sfx2/objitem.hxx> 94*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 95*cdf0e10cSrcweir #include <svl/slstitm.hxx> 96*cdf0e10cSrcweir #include "objshimp.hxx" 97*cdf0e10cSrcweir #include "openflag.hxx" 98*cdf0e10cSrcweir #include <sfx2/passwd.hxx> 99*cdf0e10cSrcweir #include "referers.hxx" 100*cdf0e10cSrcweir #include <sfx2/request.hxx> 101*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 102*cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 103*cdf0e10cSrcweir #include "app.hrc" 104*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 105*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx> 106*cdf0e10cSrcweir #include <sfx2/objface.hxx> 107*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 108*cdf0e10cSrcweir #include <sfx2/docfac.hxx> 109*cdf0e10cSrcweir #include <sfx2/event.hxx> 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 112*cdf0e10cSrcweir #include <svl/svstdarr.hxx> 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir using namespace ::com::sun::star; 115*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 116*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 117*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 118*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 119*cdf0e10cSrcweir using namespace ::com::sun::star::util; 120*cdf0e10cSrcweir using namespace ::com::sun::star::system; 121*cdf0e10cSrcweir using namespace ::com::sun::star::task; 122*cdf0e10cSrcweir using namespace ::com::sun::star::container; 123*cdf0e10cSrcweir using namespace ::cppu; 124*cdf0e10cSrcweir using namespace ::sfx2; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir namespace css = ::com::sun::star; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //========================================================================= 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir class SfxOpenDocStatusListener_Impl : public WeakImplHelper1< XDispatchResultListener > 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir public: 133*cdf0e10cSrcweir sal_Bool bFinished; 134*cdf0e10cSrcweir sal_Bool bSuccess; 135*cdf0e10cSrcweir virtual void SAL_CALL dispatchFinished( const DispatchResultEvent& Event ) throw(RuntimeException); 136*cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& Source ) throw(RuntimeException); 137*cdf0e10cSrcweir SfxOpenDocStatusListener_Impl() 138*cdf0e10cSrcweir : bFinished( sal_False ) 139*cdf0e10cSrcweir , bSuccess( sal_False ) 140*cdf0e10cSrcweir {} 141*cdf0e10cSrcweir }; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir void SAL_CALL SfxOpenDocStatusListener_Impl::dispatchFinished( const DispatchResultEvent& aEvent ) throw(RuntimeException) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir bSuccess = ( aEvent.State == DispatchResultState::SUCCESS ); 146*cdf0e10cSrcweir bFinished = sal_True; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir void SAL_CALL SfxOpenDocStatusListener_Impl::disposing( const EventObject& ) throw(RuntimeException) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir SfxObjectShellRef SfxApplication::DocAlreadyLoaded 154*cdf0e10cSrcweir ( 155*cdf0e10cSrcweir const String& rName, // Name des Dokuments mit Pfad 156*cdf0e10cSrcweir sal_Bool bSilent, // sal_True: nicht nach neuer Sicht fragen 157*cdf0e10cSrcweir sal_Bool bActivate, // soll bestehende Sicht aktiviert werden 158*cdf0e10cSrcweir sal_Bool bForbidVisible, 159*cdf0e10cSrcweir const String* pPostStr 160*cdf0e10cSrcweir ) 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir /* [Beschreibung] 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir Stellt fest, ob ein Dokument mit dem Namen 'rName' bereits geladen 165*cdf0e10cSrcweir ist und liefert einen Pointer darauf zu"uck. 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir Ist das Dokument noch nicht geladen, wird ein 0-Pointer zur"uckgeliefert. 168*cdf0e10cSrcweir */ 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir // zu suchenden Namen als URL aufbereiten 172*cdf0e10cSrcweir INetURLObject aUrlToFind( rName ); 173*cdf0e10cSrcweir DBG_ASSERT( aUrlToFind.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL" ); 174*cdf0e10cSrcweir String aPostString; 175*cdf0e10cSrcweir if ( pPostStr ) 176*cdf0e10cSrcweir aPostString = *pPostStr; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // noch offen? 179*cdf0e10cSrcweir SfxObjectShellRef xDoc; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if ( !aUrlToFind.HasError() ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir // dann bei den normal geoeffneten Docs 184*cdf0e10cSrcweir if ( !xDoc.Is() ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir xDoc = SfxObjectShell::GetFirst( 0, sal_False ); // auch hidden Docs 187*cdf0e10cSrcweir while( xDoc.Is() ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir if ( xDoc->GetMedium() && 190*cdf0e10cSrcweir xDoc->GetCreateMode() == SFX_CREATE_MODE_STANDARD && 191*cdf0e10cSrcweir !xDoc->IsAbortingImport() && !xDoc->IsLoading() ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir // Vergleiche anhand der URLs 194*cdf0e10cSrcweir INetURLObject aUrl( xDoc->GetMedium()->GetName() ); 195*cdf0e10cSrcweir if ( !aUrl.HasError() && aUrl == aUrlToFind && 196*cdf0e10cSrcweir (!bForbidVisible || !SfxViewFrame::GetFirst( xDoc, sal_True )) && 197*cdf0e10cSrcweir !xDoc->IsLoading()) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir break; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir xDoc = SfxObjectShell::GetNext( *xDoc, 0, sal_False ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // gefunden? 208*cdf0e10cSrcweir if ( xDoc.Is() && bActivate ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir DBG_ASSERT( 211*cdf0e10cSrcweir !bForbidVisible, "Unsichtbares kann nicht aktiviert werden" ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir SfxViewFrame* pFrame; 214*cdf0e10cSrcweir for( pFrame = SfxViewFrame::GetFirst( xDoc ); 215*cdf0e10cSrcweir pFrame && !pFrame->IsVisible(); 216*cdf0e10cSrcweir pFrame = SfxViewFrame::GetNext( *pFrame, xDoc ) ) ; 217*cdf0e10cSrcweir if ( pFrame ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir SfxViewFrame *pCur = SfxViewFrame::Current(); 220*cdf0e10cSrcweir if ( !bSilent && pFrame == pCur ) 221*cdf0e10cSrcweir InfoBox( 0, SfxResId(RID_DOCALREADYLOADED_DLG)).Execute(); 222*cdf0e10cSrcweir if ( bActivate ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir pFrame->MakeActive_Impl( sal_True ); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir return xDoc; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir //==================================================================== 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir void SetTemplate_Impl( const String &rFileName, 234*cdf0e10cSrcweir const String &rLongName, 235*cdf0e10cSrcweir SfxObjectShell *pDoc) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir // write TemplateName to DocumentInfo of document 238*cdf0e10cSrcweir // TemplateDate stays as default (=current date) 239*cdf0e10cSrcweir pDoc->ResetFromTemplate( rLongName, rFileName ); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir //==================================================================== 243*cdf0e10cSrcweir class SfxDocPasswordVerifier : public ::comphelper::IDocPasswordVerifier 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir public: 246*cdf0e10cSrcweir inline explicit SfxDocPasswordVerifier( const Reference< embed::XStorage >& rxStorage ) : 247*cdf0e10cSrcweir mxStorage( rxStorage ) {} 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir virtual ::comphelper::DocPasswordVerifierResult 250*cdf0e10cSrcweir verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData ); 251*cdf0e10cSrcweir virtual ::comphelper::DocPasswordVerifierResult 252*cdf0e10cSrcweir verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir private: 256*cdf0e10cSrcweir Reference< embed::XStorage > mxStorage; 257*cdf0e10cSrcweir }; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir //-------------------------------------------------------------------- 260*cdf0e10cSrcweir ::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( rPassword ); 263*cdf0e10cSrcweir return verifyEncryptionData( o_rEncryptionData ); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir //-------------------------------------------------------------------- 268*cdf0e10cSrcweir ::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir ::comphelper::DocPasswordVerifierResult eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD; 271*cdf0e10cSrcweir try 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir // check the encryption data 274*cdf0e10cSrcweir // if the data correct is the stream will be opened successfuly 275*cdf0e10cSrcweir // and immediatelly closed 276*cdf0e10cSrcweir ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( mxStorage, rEncryptionData ); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir mxStorage->openStreamElement( 279*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ), 280*cdf0e10cSrcweir embed::ElementModes::READ | embed::ElementModes::NOCREATE ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // no exception -> success 283*cdf0e10cSrcweir eResult = ::comphelper::DocPasswordVerifierResult_OK; 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir catch( const packages::WrongPasswordException& ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir catch( const uno::Exception& ) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir // unknown error, report it as wrong password 292*cdf0e10cSrcweir // TODO/LATER: we need an additional way to report unknown problems in this case 293*cdf0e10cSrcweir eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir return eResult; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir //==================================================================== 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir //-------------------------------------------------------------------- 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir sal_uInt32 CheckPasswd_Impl 303*cdf0e10cSrcweir ( 304*cdf0e10cSrcweir //Window *pWin, // Parent des Dialogs 305*cdf0e10cSrcweir SfxObjectShell* pDoc, 306*cdf0e10cSrcweir SfxItemPool& /*rPool*/, // Pool, falls ein Set erzeugt werden mus 307*cdf0e10cSrcweir SfxMedium* pFile // das Medium, dessen Passwort gfs. erfragt werden soll 308*cdf0e10cSrcweir ) 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir /* [Beschreibung] 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir Zu einem Medium das Passwort erfragen; funktioniert nur, wenn es sich 313*cdf0e10cSrcweir um einen Storage handelt. 314*cdf0e10cSrcweir Wenn in der Documentinfo das Passwort-Flag gesetzt ist, wird 315*cdf0e10cSrcweir das Passwort vom Benutzer per Dialog erfragt und an dem Set 316*cdf0e10cSrcweir des Mediums gesetzt; das Set wird, wenn nicht vorhanden, erzeugt. 317*cdf0e10cSrcweir */ 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir sal_uIntPtr nRet = ERRCODE_NONE; 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir if( ( !pFile->GetFilter() || pFile->IsStorage() ) ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage = pFile->GetStorage( sal_True ); 324*cdf0e10cSrcweir if( xStorage.is() ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xStorageProps( xStorage, uno::UNO_QUERY ); 327*cdf0e10cSrcweir if ( xStorageProps.is() ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir sal_Bool bIsEncrypted = sal_False; 330*cdf0e10cSrcweir try { 331*cdf0e10cSrcweir xStorageProps->getPropertyValue( ::rtl::OUString::createFromAscii("HasEncryptedEntries") ) 332*cdf0e10cSrcweir >>= bIsEncrypted; 333*cdf0e10cSrcweir } catch( uno::Exception& ) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir // TODO/LATER: 336*cdf0e10cSrcweir // the storage either has no encrypted elements or it's just 337*cdf0e10cSrcweir // does not allow to detect it, probably it should be implemented laiter 338*cdf0e10cSrcweir /* 339*cdf0e10cSrcweir bIsEncrypted = ( aInfo.Load( xStorage ) && aInfo.IsPasswd() ); 340*cdf0e10cSrcweir */ 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir if ( bIsEncrypted ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir Window* pWin = pDoc ? pDoc->GetDialogParent( pFile ) : NULL; 346*cdf0e10cSrcweir if ( pWin ) 347*cdf0e10cSrcweir pWin->Show(); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir nRet = ERRCODE_SFX_CANTGETPASSWD; 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir SfxItemSet *pSet = pFile->GetItemSet(); 352*cdf0e10cSrcweir if( pSet ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = pFile->GetInteractionHandler(); 355*cdf0e10cSrcweir if( xInteractionHandler.is() ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir // use the comphelper password helper to request a password 358*cdf0e10cSrcweir ::rtl::OUString aPassword; 359*cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False); 360*cdf0e10cSrcweir if ( pPasswordItem ) 361*cdf0e10cSrcweir aPassword = pPasswordItem->GetValue(); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aEncryptionData; 364*cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False); 365*cdf0e10cSrcweir if ( pEncryptionDataItem ) 366*cdf0e10cSrcweir pEncryptionDataItem->GetValue() >>= aEncryptionData; 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir ::rtl::OUString aDocumentName = INetURLObject( pFile->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET ); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir SfxDocPasswordVerifier aVerifier( xStorage ); 371*cdf0e10cSrcweir aEncryptionData = ::comphelper::DocPasswordHelper::requestAndVerifyDocPassword( 372*cdf0e10cSrcweir aVerifier, aEncryptionData, aPassword, xInteractionHandler, aDocumentName, comphelper::DocPasswordRequestType_STANDARD ); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir pSet->ClearItem( SID_PASSWORD ); 375*cdf0e10cSrcweir pSet->ClearItem( SID_ENCRYPTIONDATA ); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir if ( aEncryptionData.getLength() > 0 ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) ); 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir try 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir // update the version list of the medium using the new password 384*cdf0e10cSrcweir pFile->GetVersionList(); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir catch( uno::Exception& ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir // TODO/LATER: set the error code 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir nRet = ERRCODE_NONE; 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir else 394*cdf0e10cSrcweir nRet = ERRCODE_IO_ABORT; 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir else 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir OSL_ENSURE( sal_False, "A storage must implement XPropertySet interface!" ); 402*cdf0e10cSrcweir nRet = ERRCODE_SFX_CANTGETPASSWD; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir return nRet; 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir //-------------------------------------------------------------------- 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir sal_uIntPtr SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const String &rFileName, sal_Bool bCopy, SfxItemSet* pSet ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir const SfxFilter* pFilter = NULL; 416*cdf0e10cSrcweir SfxMedium aMedium( rFileName, ( STREAM_READ | STREAM_SHARE_DENYNONE ), sal_False ); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir if ( !aMedium.GetStorage( sal_True ).is() ) 419*cdf0e10cSrcweir aMedium.GetInStream(); 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir if ( aMedium.GetError() ) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir delete pSet; 424*cdf0e10cSrcweir return aMedium.GetErrorCode(); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir aMedium.UseInteractionHandler( sal_True ); 428*cdf0e10cSrcweir sal_uIntPtr nErr = GetFilterMatcher().GuessFilter( aMedium,&pFilter,SFX_FILTER_TEMPLATE, 0 ); 429*cdf0e10cSrcweir if ( 0 != nErr) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir delete pSet; 432*cdf0e10cSrcweir return ERRCODE_SFX_NOTATEMPLATE; 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir if( !pFilter || !pFilter->IsAllowedAsTemplate() ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir delete pSet; 438*cdf0e10cSrcweir return ERRCODE_SFX_NOTATEMPLATE; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir if ( pFilter->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir DBG_ASSERT( !xDoc.Is(), "Sorry, not implemented!" ); 444*cdf0e10cSrcweir delete pSet; 445*cdf0e10cSrcweir SfxStringItem aName( SID_FILE_NAME, rFileName ); 446*cdf0e10cSrcweir SfxStringItem aReferer( SID_REFERER, String::CreateFromAscii("private:user") ); 447*cdf0e10cSrcweir SfxStringItem aFlags( SID_OPTIONS, String::CreateFromAscii("T") ); 448*cdf0e10cSrcweir SfxBoolItem aHidden( SID_HIDDEN, sal_True ); 449*cdf0e10cSrcweir const SfxPoolItem *pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, &aName, &aHidden, &aReferer, &aFlags, 0L ); 450*cdf0e10cSrcweir const SfxObjectItem *pObj = PTR_CAST( SfxObjectItem, pRet ); 451*cdf0e10cSrcweir if ( pObj ) 452*cdf0e10cSrcweir xDoc = PTR_CAST( SfxObjectShell, pObj->GetShell() ); 453*cdf0e10cSrcweir else 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir const SfxViewFrameItem *pView = PTR_CAST( SfxViewFrameItem, pRet ); 456*cdf0e10cSrcweir if ( pView ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir SfxViewFrame *pFrame = pView->GetFrame(); 459*cdf0e10cSrcweir if ( pFrame ) 460*cdf0e10cSrcweir xDoc = pFrame->GetObjectShell(); 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir if ( !xDoc.Is() ) 465*cdf0e10cSrcweir return ERRCODE_SFX_DOLOADFAILED; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir else 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir if ( !xDoc.Is() ) 470*cdf0e10cSrcweir xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName() ); 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir SfxMedium *pMedium = new SfxMedium( rFileName, STREAM_STD_READ, sal_False, pFilter, pSet ); 473*cdf0e10cSrcweir if(!xDoc->DoLoad(pMedium)) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir ErrCode nErrCode = xDoc->GetErrorCode(); 476*cdf0e10cSrcweir xDoc->DoClose(); 477*cdf0e10cSrcweir xDoc.Clear(); 478*cdf0e10cSrcweir return nErrCode; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir if( bCopy ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir try 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir // TODO: introduce error handling 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir uno::Reference< embed::XStorage > xTempStorage = ::comphelper::OStorageHelper::GetTemporaryStorage(); 489*cdf0e10cSrcweir if( !xTempStorage.is() ) 490*cdf0e10cSrcweir throw uno::RuntimeException(); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir xDoc->GetStorage()->copyToStorage( xTempStorage ); 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir //REMOVE // the following operations should be done in one step 495*cdf0e10cSrcweir //REMOVE xDoc->DoHandsOff(); 496*cdf0e10cSrcweir if ( !xDoc->DoSaveCompleted( new SfxMedium( xTempStorage, String() ) ) ) 497*cdf0e10cSrcweir throw uno::RuntimeException(); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir catch( uno::Exception& ) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir xDoc->DoClose(); 502*cdf0e10cSrcweir xDoc.Clear(); 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir // TODO: transfer correct error outside 505*cdf0e10cSrcweir return ERRCODE_SFX_GENERAL; 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir SetTemplate_Impl( rFileName, String(), xDoc ); 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir else 511*cdf0e10cSrcweir SetTemplate_Impl( rFileName, String(), xDoc ); 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir xDoc->SetNoName(); 514*cdf0e10cSrcweir xDoc->InvalidateName(); 515*cdf0e10cSrcweir xDoc->SetModified(sal_False); 516*cdf0e10cSrcweir xDoc->ResetError(); 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel ( xDoc->GetModel(), ::com::sun::star::uno::UNO_QUERY ); 519*cdf0e10cSrcweir if ( xModel.is() ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir SfxItemSet* pNew = xDoc->GetMedium()->GetItemSet()->Clone(); 522*cdf0e10cSrcweir pNew->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL ); 523*cdf0e10cSrcweir pNew->ClearItem( SID_FILTER_NAME ); 524*cdf0e10cSrcweir //pNew->Put( SfxStringItem( SID_FILTER_NAME, xDoc->GetFactory().GetFilter(0)->GetFilterName() ) ); 525*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs; 526*cdf0e10cSrcweir TransformItems( SID_OPENDOC, *pNew, aArgs ); 527*cdf0e10cSrcweir sal_Int32 nLength = aArgs.getLength(); 528*cdf0e10cSrcweir aArgs.realloc( nLength + 1 ); 529*cdf0e10cSrcweir aArgs[nLength].Name = DEFINE_CONST_UNICODE("Title"); 530*cdf0e10cSrcweir aArgs[nLength].Value <<= ::rtl::OUString( xDoc->GetTitle( SFX_TITLE_DETECT ) ); 531*cdf0e10cSrcweir xModel->attachResource( ::rtl::OUString(), aArgs ); 532*cdf0e10cSrcweir delete pNew; 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir return xDoc->GetErrorCode(); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir //-------------------------------------------------------------------- 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir void SfxApplication::NewDocDirectExec_Impl( SfxRequest& rReq ) 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir DBG_MEMTEST(); 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pFactoryItem, SfxStringItem, SID_NEWDOCDIRECT, sal_False); 545*cdf0e10cSrcweir String aFactName; 546*cdf0e10cSrcweir if ( pFactoryItem ) 547*cdf0e10cSrcweir aFactName = pFactoryItem->GetValue(); 548*cdf0e10cSrcweir else 549*cdf0e10cSrcweir aFactName = SvtModuleOptions().GetDefaultModuleName(); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, GetPool() ); 553*cdf0e10cSrcweir String aFact = String::CreateFromAscii("private:factory/"); 554*cdf0e10cSrcweir aFact += aFactName; 555*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aFact ) ); 556*cdf0e10cSrcweir aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, GetFrame() ) ); 557*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii( "_default" ) ) ); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir // TODO/LATER: Should the other arguments be transfered as well? 560*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pDefaultPathItem, SfxStringItem, SID_DEFAULTFILEPATH, sal_False); 561*cdf0e10cSrcweir if ( pDefaultPathItem ) 562*cdf0e10cSrcweir aReq.AppendItem( *pDefaultPathItem ); 563*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pDefaultNameItem, SfxStringItem, SID_DEFAULTFILENAME, sal_False); 564*cdf0e10cSrcweir if ( pDefaultNameItem ) 565*cdf0e10cSrcweir aReq.AppendItem( *pDefaultNameItem ); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir SFX_APP()->ExecuteSlot( aReq ); 568*cdf0e10cSrcweir const SfxViewFrameItem* pItem = PTR_CAST( SfxViewFrameItem, aReq.GetReturnValue() ); 569*cdf0e10cSrcweir if ( pItem ) 570*cdf0e10cSrcweir rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) ); 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir //-------------------------------------------------------------------- 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir void SfxApplication::NewDocExec_Impl( SfxRequest& rReq ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir DBG_MEMTEST(); 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir // keine Parameter vom BASIC nur Factory angegeben? 580*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pTemplNameItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False); 581*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pTemplFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False); 582*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pTemplRegionNameItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, sal_False); 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir SfxObjectShellLock xDoc; 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir String aTemplateRegion, aTemplateName, aTemplateFileName; 587*cdf0e10cSrcweir sal_Bool bDirect = sal_False; // "uber FileName anstelle Region/Template 588*cdf0e10cSrcweir SfxErrorContext aEc(ERRCTX_SFX_NEWDOC); 589*cdf0e10cSrcweir if ( !pTemplNameItem && !pTemplFileNameItem ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir Window* pTopWin = GetTopWindow(); 592*cdf0e10cSrcweir SvtDocumentTemplateDialog* pDocTemplDlg = new SvtDocumentTemplateDialog( NULL ); 593*cdf0e10cSrcweir int nRet = pDocTemplDlg->Execute(); 594*cdf0e10cSrcweir sal_Bool bNewWin = sal_False; 595*cdf0e10cSrcweir if ( nRet == RET_OK ) 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir rReq.Done(); 598*cdf0e10cSrcweir if ( pTopWin != GetTopWindow() ) 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir // the dialogue opens a document -> a new TopWindow appears 601*cdf0e10cSrcweir pTopWin = GetTopWindow(); 602*cdf0e10cSrcweir bNewWin = sal_True; 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir delete pDocTemplDlg; 607*cdf0e10cSrcweir if ( bNewWin && pTopWin ) 608*cdf0e10cSrcweir // after the destruction of the dialogue its parent comes to top, 609*cdf0e10cSrcweir // but we want that the new document is on top 610*cdf0e10cSrcweir pTopWin->ToTop(); 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir return; 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir else 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir // Template-Name 617*cdf0e10cSrcweir if ( pTemplNameItem ) 618*cdf0e10cSrcweir aTemplateName = pTemplNameItem->GetValue(); 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir // Template-Region 621*cdf0e10cSrcweir if ( pTemplRegionNameItem ) 622*cdf0e10cSrcweir aTemplateRegion = pTemplRegionNameItem->GetValue(); 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir // Template-File-Name 625*cdf0e10cSrcweir if ( pTemplFileNameItem ) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir aTemplateFileName = pTemplFileNameItem->GetValue(); 628*cdf0e10cSrcweir bDirect = sal_True; 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir sal_uIntPtr lErr = 0; 633*cdf0e10cSrcweir SfxItemSet* pSet = new SfxAllItemSet( GetPool() ); 634*cdf0e10cSrcweir pSet->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 635*cdf0e10cSrcweir if ( !bDirect ) 636*cdf0e10cSrcweir { 637*cdf0e10cSrcweir SfxDocumentTemplates aTmpFac; 638*cdf0e10cSrcweir if( !aTemplateFileName.Len() ) 639*cdf0e10cSrcweir aTmpFac.GetFull( aTemplateRegion, aTemplateName, aTemplateFileName ); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir if( !aTemplateFileName.Len() ) 642*cdf0e10cSrcweir lErr = ERRCODE_SFX_TEMPLATENOTFOUND; 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir INetURLObject aObj( aTemplateFileName ); 646*cdf0e10cSrcweir SfxErrorContext aEC( ERRCTX_SFX_LOADTEMPLATE, aObj.PathToFileName() ); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir if ( lErr != ERRCODE_NONE ) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir sal_uIntPtr lFatalErr = ERRCODE_TOERROR(lErr); 651*cdf0e10cSrcweir if ( lFatalErr ) 652*cdf0e10cSrcweir ErrorHandler::HandleError(lErr); 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir else 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir SfxCallMode eMode = SFX_CALLMODE_SYNCHRON; 657*cdf0e10cSrcweir 658*cdf0e10cSrcweir const SfxPoolItem *pRet=0; 659*cdf0e10cSrcweir SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE("private:user") ); 660*cdf0e10cSrcweir SfxStringItem aTarget( SID_TARGETNAME, DEFINE_CONST_UNICODE("_default") ); 661*cdf0e10cSrcweir if ( aTemplateFileName.Len() ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL!" ); 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir SfxStringItem aName( SID_FILE_NAME, aObj.GetMainURL( INetURLObject::NO_DECODE ) ); 666*cdf0e10cSrcweir SfxStringItem aTemplName( SID_TEMPLATE_NAME, aTemplateName ); 667*cdf0e10cSrcweir SfxStringItem aTemplRegionName( SID_TEMPLATE_REGIONNAME, aTemplateRegion ); 668*cdf0e10cSrcweir pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, eMode, &aName, &aTarget, &aReferer, &aTemplName, &aTemplRegionName, 0L ); 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir else 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir SfxStringItem aName( SID_FILE_NAME, DEFINE_CONST_UNICODE("private:factory") ); 673*cdf0e10cSrcweir pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, eMode, &aName, &aTarget, &aReferer, 0L ); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir if ( pRet ) 677*cdf0e10cSrcweir rReq.SetReturnValue( *pRet ); 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir 681*cdf0e10cSrcweir //--------------------------------------------------------------------------- 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq ) 684*cdf0e10cSrcweir { 685*cdf0e10cSrcweir DBG_MEMTEST(); 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir sal_uInt16 nSID = rReq.GetSlot(); 688*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 689*cdf0e10cSrcweir if ( pFileNameItem ) 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir String aCommand( pFileNameItem->GetValue() ); 692*cdf0e10cSrcweir const SfxSlot* pSlot = GetInterface()->GetSlot( aCommand ); 693*cdf0e10cSrcweir if ( pSlot ) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir pFileNameItem = NULL; 696*cdf0e10cSrcweir } 697*cdf0e10cSrcweir else 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir sal_Int32 nIndex = aCommand.SearchAscii("slot:"); 700*cdf0e10cSrcweir if ( !nIndex ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir sal_uInt16 nSlotId = (sal_uInt16) String( aCommand, 5, aCommand.Len()-5 ).ToInt32(); 703*cdf0e10cSrcweir if ( nSlotId == SID_OPENDOC ) 704*cdf0e10cSrcweir pFileNameItem = NULL; 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir } 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir if ( !pFileNameItem ) 710*cdf0e10cSrcweir { 711*cdf0e10cSrcweir // get FileName from dialog 712*cdf0e10cSrcweir SvStringsDtor* pURLList = NULL; 713*cdf0e10cSrcweir String aFilter; 714*cdf0e10cSrcweir SfxItemSet* pSet = NULL; 715*cdf0e10cSrcweir String aPath; 716*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pFolderNameItem, SfxStringItem, SID_PATH, sal_False ); 717*cdf0e10cSrcweir if ( pFolderNameItem ) 718*cdf0e10cSrcweir aPath = pFolderNameItem->GetValue(); 719*cdf0e10cSrcweir else if ( nSID == SID_OPENTEMPLATE ) 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir aPath = SvtPathOptions().GetTemplatePath(); 722*cdf0e10cSrcweir sal_Int32 nTokenCount = aPath.GetTokenCount( ';' ); 723*cdf0e10cSrcweir aPath = aPath.GetToken( 724*cdf0e10cSrcweir sal::static_int_cast< xub_StrLen >( 725*cdf0e10cSrcweir nTokenCount ? ( nTokenCount - 1 ) : 0 ), 726*cdf0e10cSrcweir ';' ); 727*cdf0e10cSrcweir } 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG; 730*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pSystemDialogItem, SfxBoolItem, SID_FILE_DIALOG, sal_False ); 731*cdf0e10cSrcweir if ( pSystemDialogItem ) 732*cdf0e10cSrcweir nDialog = pSystemDialogItem->GetValue() ? SFX2_IMPL_DIALOG_SYSTEM : SFX2_IMPL_DIALOG_OOO; 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir String sStandardDir; 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pStandardDirItem, SfxStringItem, SID_STANDARD_DIR, sal_False ); 737*cdf0e10cSrcweir if ( pStandardDirItem ) 738*cdf0e10cSrcweir sStandardDir = pStandardDirItem->GetValue(); 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > aBlackList; 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pBlackListItem, SfxStringListItem, SID_BLACK_LIST, sal_False ); 743*cdf0e10cSrcweir if ( pBlackListItem ) 744*cdf0e10cSrcweir pBlackListItem->GetStringList( aBlackList ); 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir sal_uIntPtr nErr = sfx2::FileOpenDialog_Impl( 748*cdf0e10cSrcweir WB_OPEN | SFXWB_MULTISELECTION | SFXWB_SHOWVERSIONS, String(), pURLList, aFilter, pSet, &aPath, nDialog, sStandardDir, aBlackList ); 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir if ( nErr == ERRCODE_ABORT ) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir delete pURLList; 753*cdf0e10cSrcweir return; 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir rReq.SetArgs( *(SfxAllItemSet*)pSet ); 757*cdf0e10cSrcweir if (aFilter.Len() >0 ) 758*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( SID_FILTER_NAME, aFilter ) ); 759*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) ); 760*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( SID_REFERER, String::CreateFromAscii(SFX_REFERER_USER) ) ); 761*cdf0e10cSrcweir delete pSet; 762*cdf0e10cSrcweir 763*cdf0e10cSrcweir if ( pURLList->Count() ) 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir if ( nSID == SID_OPENTEMPLATE ) 766*cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, sal_False ) ); 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir // This helper wraps an existing (or may new created InteractionHandler) 769*cdf0e10cSrcweir // intercept all incoming interactions and provide usefull informations 770*cdf0e10cSrcweir // later if the following transaction was finished. 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir ::framework::PreventDuplicateInteraction* pHandler = new ::framework::PreventDuplicateInteraction(::comphelper::getProcessServiceFactory()); 773*cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler > xHandler (static_cast< css::task::XInteractionHandler* >(pHandler), css::uno::UNO_QUERY); 774*cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler > xWrappedHandler; 775*cdf0e10cSrcweir 776*cdf0e10cSrcweir // wrap existing handler or create new UUI handler 777*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False); 778*cdf0e10cSrcweir if (pInteractionItem) 779*cdf0e10cSrcweir { 780*cdf0e10cSrcweir pInteractionItem->GetValue() >>= xWrappedHandler; 781*cdf0e10cSrcweir rReq.RemoveItem( SID_INTERACTIONHANDLER ); 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir if (xWrappedHandler.is()) 784*cdf0e10cSrcweir pHandler->setHandler(xWrappedHandler); 785*cdf0e10cSrcweir else 786*cdf0e10cSrcweir pHandler->useDefaultUUIHandler(); 787*cdf0e10cSrcweir rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHandler)) ); 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir // define rules for this handler 790*cdf0e10cSrcweir css::uno::Type aInteraction = ::getCppuType(static_cast< css::task::ErrorCodeRequest* >(0)); 791*cdf0e10cSrcweir ::framework::PreventDuplicateInteraction::InteractionInfo aRule (aInteraction, 1); 792*cdf0e10cSrcweir pHandler->addInteractionRule(aRule); 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < pURLList->Count(); ++i ) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir String aURL = *(pURLList->GetObject(i)); 797*cdf0e10cSrcweir rReq.RemoveItem( SID_FILE_NAME ); 798*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( SID_FILE_NAME, aURL ) ); 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir // synchron ausf"uhren, damit beim Reschedulen nicht schon das n"achste Dokument 801*cdf0e10cSrcweir // geladen wird 802*cdf0e10cSrcweir // TODO/LATER: use URLList argument and always remove one document after another, each step in asychronous execution, until finished 803*cdf0e10cSrcweir // but only if reschedule is a problem 804*cdf0e10cSrcweir GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, *rReq.GetArgs() ); 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir // check for special interaction "NO MORE DOCUMENTS ALLOWED" and 807*cdf0e10cSrcweir // break loop then. Otherwise we risk showing the same interaction more then once. 808*cdf0e10cSrcweir if ( pHandler->getInteractionInfo(aInteraction, &aRule) ) 809*cdf0e10cSrcweir { 810*cdf0e10cSrcweir if (aRule.m_nCallCount > 0) 811*cdf0e10cSrcweir { 812*cdf0e10cSrcweir if (aRule.m_xRequest.is()) 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir css::task::ErrorCodeRequest aRequest; 815*cdf0e10cSrcweir if (aRule.m_xRequest->getRequest() >>= aRequest) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir if (aRequest.ErrCode == 818*cdf0e10cSrcweir sal::static_int_cast< sal_Int32 >( 819*cdf0e10cSrcweir ERRCODE_SFX_NOMOREDOCUMENTSALLOWED)) 820*cdf0e10cSrcweir break; 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir } 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir delete pURLList; 828*cdf0e10cSrcweir return; 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir delete pURLList; 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir if ( !rReq.IsSynchronCall() ) 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir // now check wether a stream is already there 836*cdf0e10cSrcweir // if not: download it in a thread and restart the call 837*cdf0e10cSrcweir // return; 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir sal_Bool bHyperlinkUsed = sal_False; 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir if ( SID_OPENURL == nSID ) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir // SID_OPENURL does the same as SID_OPENDOC! 845*cdf0e10cSrcweir rReq.SetSlot( SID_OPENDOC ); 846*cdf0e10cSrcweir nSID = SID_OPENDOC; 847*cdf0e10cSrcweir } 848*cdf0e10cSrcweir else if ( nSID == SID_OPENTEMPLATE ) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, sal_False ) ); 851*cdf0e10cSrcweir } 852*cdf0e10cSrcweir // pass URL to OS by using ShellExecuter or open it internal 853*cdf0e10cSrcweir // if it seams to be an own format. 854*cdf0e10cSrcweir /* Attention! 855*cdf0e10cSrcweir There exist two possibilities to open hyperlinks: 856*cdf0e10cSrcweir a) using SID_OPENHYPERLINK (new) 857*cdf0e10cSrcweir b) using SID_BROWSE (old) 858*cdf0e10cSrcweir */ 859*cdf0e10cSrcweir else if ( nSID == SID_OPENHYPERLINK ) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir rReq.SetSlot( SID_OPENDOC ); 862*cdf0e10cSrcweir nSID = SID_OPENDOC; 863*cdf0e10cSrcweir bHyperlinkUsed = sal_True; 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir // no else here! It's optional ... 867*cdf0e10cSrcweir if (!bHyperlinkUsed) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pHyperLinkUsedItem, SfxBoolItem, SID_BROWSE, sal_False); 870*cdf0e10cSrcweir if ( pHyperLinkUsedItem ) 871*cdf0e10cSrcweir bHyperlinkUsed = pHyperLinkUsedItem->GetValue(); 872*cdf0e10cSrcweir // no "official" item, so remove it from ItemSet before using UNO-API 873*cdf0e10cSrcweir rReq.RemoveItem( SID_BROWSE ); 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pFileName, SfxStringItem, SID_FILE_NAME, sal_False ); 877*cdf0e10cSrcweir String aFileName = pFileName->GetValue(); 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir String aReferer; 880*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pRefererItem, SfxStringItem, SID_REFERER, sal_False ); 881*cdf0e10cSrcweir if ( pRefererItem ) 882*cdf0e10cSrcweir aReferer = pRefererItem->GetValue(); 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pFileFlagsItem, SfxStringItem, SID_OPTIONS, sal_False); 885*cdf0e10cSrcweir if ( pFileFlagsItem ) 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir String aFileFlags = pFileFlagsItem->GetValue(); 888*cdf0e10cSrcweir aFileFlags.ToUpperAscii(); 889*cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 0x0054 ) ) // T = 54h 890*cdf0e10cSrcweir { 891*cdf0e10cSrcweir rReq.RemoveItem( SID_TEMPLATE ); 892*cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 893*cdf0e10cSrcweir } 894*cdf0e10cSrcweir 895*cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 0x0048 ) ) // H = 48h 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir rReq.RemoveItem( SID_HIDDEN ); 898*cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( SID_HIDDEN, sal_True ) ); 899*cdf0e10cSrcweir } 900*cdf0e10cSrcweir 901*cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 0x0052 ) ) // R = 52h 902*cdf0e10cSrcweir { 903*cdf0e10cSrcweir rReq.RemoveItem( SID_DOC_READONLY ); 904*cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 905*cdf0e10cSrcweir } 906*cdf0e10cSrcweir 907*cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 0x0042 ) ) // B = 42h 908*cdf0e10cSrcweir { 909*cdf0e10cSrcweir rReq.RemoveItem( SID_PREVIEW ); 910*cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( SID_PREVIEW, sal_True ) ); 911*cdf0e10cSrcweir } 912*cdf0e10cSrcweir 913*cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 0x0053 ) ) // S = 53h 914*cdf0e10cSrcweir { 915*cdf0e10cSrcweir // not supported anymore 916*cdf0e10cSrcweir //rReq.RemoveItem( SID_SILENT ); 917*cdf0e10cSrcweir //rReq.AppendItem( SfxBoolItem( SID_SILENT, sal_True ) ); 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir rReq.RemoveItem( SID_OPTIONS ); 921*cdf0e10cSrcweir } 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir // Mark without URL cannot be handled by hyperlink code 924*cdf0e10cSrcweir if ( bHyperlinkUsed && aFileName.Len() && aFileName.GetChar(0) != '#' ) 925*cdf0e10cSrcweir { 926*cdf0e10cSrcweir Reference< ::com::sun::star::document::XTypeDetection > xTypeDetection( 927*cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance( 928*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" )), 929*cdf0e10cSrcweir UNO_QUERY ); 930*cdf0e10cSrcweir if ( xTypeDetection.is() ) 931*cdf0e10cSrcweir { 932*cdf0e10cSrcweir URL aURL; 933*cdf0e10cSrcweir ::rtl::OUString aTypeName; 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir aURL.Complete = aFileName; 936*cdf0e10cSrcweir Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( 937*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY ); 938*cdf0e10cSrcweir xTrans->parseStrict( aURL ); 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir INetProtocol aINetProtocol = INetURLObject( aURL.Complete ).GetProtocol(); 941*cdf0e10cSrcweir SvtExtendedSecurityOptions aExtendedSecurityOptions; 942*cdf0e10cSrcweir SvtExtendedSecurityOptions::OpenHyperlinkMode eMode = aExtendedSecurityOptions.GetOpenHyperlinkMode(); 943*cdf0e10cSrcweir if ( eMode == SvtExtendedSecurityOptions::OPEN_WITHSECURITYCHECK ) 944*cdf0e10cSrcweir { 945*cdf0e10cSrcweir if ( aINetProtocol == INET_PROT_FILE ) 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir /*!!! pb: #i49802# no security warning any longer 948*cdf0e10cSrcweir // Check if file URL is a directory. This is not insecure! 949*cdf0e10cSrcweir osl::Directory aDir( aURL.Main ); 950*cdf0e10cSrcweir sal_Bool bIsDir = ( aDir.open() == osl::Directory::E_None ); 951*cdf0e10cSrcweir 952*cdf0e10cSrcweir if ( !bIsDir && !aExtendedSecurityOptions.IsSecureHyperlink( aURL.Complete ) ) 953*cdf0e10cSrcweir { 954*cdf0e10cSrcweir // Security check for local files depending on the extension 955*cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 956*cdf0e10cSrcweir Window *pWindow = SFX_APP()->GetTopWindow(); 957*cdf0e10cSrcweir 958*cdf0e10cSrcweir String aSecurityWarningBoxTitle( SfxResId( RID_SECURITY_WARNING_TITLE )); 959*cdf0e10cSrcweir WarningBox aSecurityWarningBox( pWindow, SfxResId( RID_SECURITY_WARNING_HYPERLINK )); 960*cdf0e10cSrcweir aSecurityWarningBox.SetText( aSecurityWarningBoxTitle ); 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir // Replace %s with the real file name 963*cdf0e10cSrcweir String aMsgText = aSecurityWarningBox.GetMessText(); 964*cdf0e10cSrcweir String aMainURL( aURL.Main ); 965*cdf0e10cSrcweir String aFileName; 966*cdf0e10cSrcweir 967*cdf0e10cSrcweir utl::LocalFileHelper::ConvertURLToPhysicalName( aMainURL, aFileName ); 968*cdf0e10cSrcweir aMsgText.SearchAndReplaceAscii( "%s", aFileName ); 969*cdf0e10cSrcweir aSecurityWarningBox.SetMessText( aMsgText ); 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir if( aSecurityWarningBox.Execute() == RET_NO ) 972*cdf0e10cSrcweir return; 973*cdf0e10cSrcweir } 974*cdf0e10cSrcweir */ 975*cdf0e10cSrcweir } 976*cdf0e10cSrcweir } 977*cdf0e10cSrcweir else if ( eMode == SvtExtendedSecurityOptions::OPEN_NEVER && aINetProtocol != INET_PROT_VND_SUN_STAR_HELP ) 978*cdf0e10cSrcweir { 979*cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 980*cdf0e10cSrcweir Window *pWindow = SFX_APP()->GetTopWindow(); 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir String aSecurityWarningBoxTitle( SfxResId( RID_SECURITY_WARNING_TITLE )); 983*cdf0e10cSrcweir WarningBox aSecurityWarningBox( pWindow, SfxResId( RID_SECURITY_WARNING_NO_HYPERLINKS )); 984*cdf0e10cSrcweir aSecurityWarningBox.SetText( aSecurityWarningBoxTitle ); 985*cdf0e10cSrcweir aSecurityWarningBox.Execute(); 986*cdf0e10cSrcweir return; 987*cdf0e10cSrcweir } 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir aTypeName = xTypeDetection->queryTypeByURL( aURL.Main ); 990*cdf0e10cSrcweir SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher(); 991*cdf0e10cSrcweir const SfxFilter* pFilter = rMatcher.GetFilter4EA( aTypeName ); 992*cdf0e10cSrcweir if ( !pFilter || !( pFilter->IsOwnFormat() )) 993*cdf0e10cSrcweir { 994*cdf0e10cSrcweir // hyperlink does not link to own type => special handling (http, ftp) browser and (other external protocols) OS 995*cdf0e10cSrcweir Reference< XSystemShellExecute > xSystemShellExecute( ::comphelper::getProcessServiceFactory()->createInstance( 996*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" )), UNO_QUERY ); 997*cdf0e10cSrcweir if ( xSystemShellExecute.is() ) 998*cdf0e10cSrcweir { 999*cdf0e10cSrcweir if ( aINetProtocol == INET_PROT_MAILTO ) 1000*cdf0e10cSrcweir { 1001*cdf0e10cSrcweir // don't dispatch mailto hyperlink to desktop dispatcher 1002*cdf0e10cSrcweir rReq.RemoveItem( SID_TARGETNAME ); 1003*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_self") ) ); 1004*cdf0e10cSrcweir } 1005*cdf0e10cSrcweir else if ( aINetProtocol == INET_PROT_FTP || 1006*cdf0e10cSrcweir aINetProtocol == INET_PROT_HTTP || 1007*cdf0e10cSrcweir aINetProtocol == INET_PROT_HTTPS ) 1008*cdf0e10cSrcweir { 1009*cdf0e10cSrcweir try 1010*cdf0e10cSrcweir { 1011*cdf0e10cSrcweir // start browser 1012*cdf0e10cSrcweir ::rtl::OUString aURLString( aURL.Complete ); 1013*cdf0e10cSrcweir xSystemShellExecute->execute( aURLString, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS ); 1014*cdf0e10cSrcweir } 1015*cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 1016*cdf0e10cSrcweir { 1017*cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1018*cdf0e10cSrcweir Window *pWindow = SFX_APP()->GetTopWindow(); 1019*cdf0e10cSrcweir ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute(); 1020*cdf0e10cSrcweir } 1021*cdf0e10cSrcweir catch ( ::com::sun::star::system::SystemShellExecuteException& ) 1022*cdf0e10cSrcweir { 1023*cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1024*cdf0e10cSrcweir Window *pWindow = SFX_APP()->GetTopWindow(); 1025*cdf0e10cSrcweir ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute(); 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir return; 1029*cdf0e10cSrcweir } 1030*cdf0e10cSrcweir else 1031*cdf0e10cSrcweir { 1032*cdf0e10cSrcweir // check for "internal" protocols that should not be forwarded to the system 1033*cdf0e10cSrcweir Sequence < ::rtl::OUString > aProtocols(2); 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir // add special protocols that always should be treated as internal 1036*cdf0e10cSrcweir aProtocols[0] = ::rtl::OUString::createFromAscii("private:*"); 1037*cdf0e10cSrcweir aProtocols[1] = ::rtl::OUString::createFromAscii("vnd.sun.star.*"); 1038*cdf0e10cSrcweir 1039*cdf0e10cSrcweir try 1040*cdf0e10cSrcweir { 1041*cdf0e10cSrcweir // get registered protocol handlers from configuration 1042*cdf0e10cSrcweir Reference < XNameAccess > xAccess( ::comphelper::ConfigurationHelper::openConfig( ::comphelper::getProcessServiceFactory(), 1043*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("org.openoffice.Office.ProtocolHandler/HandlerSet"), ::comphelper::ConfigurationHelper::E_READONLY ), UNO_QUERY ); 1044*cdf0e10cSrcweir if ( xAccess.is() ) 1045*cdf0e10cSrcweir { 1046*cdf0e10cSrcweir Sequence < ::rtl::OUString > aNames = xAccess->getElementNames(); 1047*cdf0e10cSrcweir for ( sal_Int32 nName = 0; nName < aNames.getLength(); nName ++) 1048*cdf0e10cSrcweir { 1049*cdf0e10cSrcweir Reference < XPropertySet > xSet; 1050*cdf0e10cSrcweir Any aRet = xAccess->getByName( aNames[nName] ); 1051*cdf0e10cSrcweir aRet >>= xSet; 1052*cdf0e10cSrcweir if ( xSet.is() ) 1053*cdf0e10cSrcweir { 1054*cdf0e10cSrcweir // copy protocols 1055*cdf0e10cSrcweir aRet = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("Protocols") ); 1056*cdf0e10cSrcweir Sequence < ::rtl::OUString > aTmp; 1057*cdf0e10cSrcweir aRet >>= aTmp; 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir // todo: add operator+= to SequenceAsVector class and use SequenceAsVector for aProtocols 1060*cdf0e10cSrcweir sal_Int32 nLength = aProtocols.getLength(); 1061*cdf0e10cSrcweir aProtocols.realloc( nLength+aTmp.getLength() ); 1062*cdf0e10cSrcweir for ( sal_Int32 n=0; n<aTmp.getLength(); n++ ) 1063*cdf0e10cSrcweir aProtocols[(++nLength)-1] = aTmp[n]; 1064*cdf0e10cSrcweir } 1065*cdf0e10cSrcweir } 1066*cdf0e10cSrcweir } 1067*cdf0e10cSrcweir } 1068*cdf0e10cSrcweir catch ( Exception& ) 1069*cdf0e10cSrcweir { 1070*cdf0e10cSrcweir // registered protocols could not be read 1071*cdf0e10cSrcweir } 1072*cdf0e10cSrcweir 1073*cdf0e10cSrcweir sal_Bool bFound = sal_False; 1074*cdf0e10cSrcweir for ( sal_Int32 nProt=0; nProt<aProtocols.getLength(); nProt++ ) 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir WildCard aPattern(aProtocols[nProt]); 1077*cdf0e10cSrcweir if ( aPattern.Matches( aURL.Complete ) ) 1078*cdf0e10cSrcweir { 1079*cdf0e10cSrcweir bFound = sal_True; 1080*cdf0e10cSrcweir break; 1081*cdf0e10cSrcweir } 1082*cdf0e10cSrcweir } 1083*cdf0e10cSrcweir 1084*cdf0e10cSrcweir if ( !bFound ) 1085*cdf0e10cSrcweir { 1086*cdf0e10cSrcweir sal_Bool bLoadInternal = sal_False; 1087*cdf0e10cSrcweir 1088*cdf0e10cSrcweir // security reservation: => we have to check the referer before executing 1089*cdf0e10cSrcweir if (SFX_APP()->IsSecureURL(rtl::OUString(), &aReferer)) 1090*cdf0e10cSrcweir { 1091*cdf0e10cSrcweir ::rtl::OUString aURLString( aURL.Complete ); 1092*cdf0e10cSrcweir 1093*cdf0e10cSrcweir try 1094*cdf0e10cSrcweir { 1095*cdf0e10cSrcweir // give os this file 1096*cdf0e10cSrcweir xSystemShellExecute->execute( aURLString, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS ); 1097*cdf0e10cSrcweir } 1098*cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 1099*cdf0e10cSrcweir { 1100*cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1101*cdf0e10cSrcweir Window *pWindow = SFX_APP()->GetTopWindow(); 1102*cdf0e10cSrcweir ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute(); 1103*cdf0e10cSrcweir } 1104*cdf0e10cSrcweir catch ( ::com::sun::star::system::SystemShellExecuteException& ) 1105*cdf0e10cSrcweir { 1106*cdf0e10cSrcweir if ( !pFilter ) 1107*cdf0e10cSrcweir { 1108*cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1109*cdf0e10cSrcweir Window *pWindow = SFX_APP()->GetTopWindow(); 1110*cdf0e10cSrcweir ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute(); 1111*cdf0e10cSrcweir } 1112*cdf0e10cSrcweir else 1113*cdf0e10cSrcweir { 1114*cdf0e10cSrcweir rReq.RemoveItem( SID_TARGETNAME ); 1115*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) ); 1116*cdf0e10cSrcweir bLoadInternal = sal_True; 1117*cdf0e10cSrcweir } 1118*cdf0e10cSrcweir } 1119*cdf0e10cSrcweir } 1120*cdf0e10cSrcweir else 1121*cdf0e10cSrcweir { 1122*cdf0e10cSrcweir SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aURL.Complete ); 1123*cdf0e10cSrcweir ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED ); 1124*cdf0e10cSrcweir } 1125*cdf0e10cSrcweir 1126*cdf0e10cSrcweir if ( !bLoadInternal ) 1127*cdf0e10cSrcweir return; 1128*cdf0e10cSrcweir } 1129*cdf0e10cSrcweir } 1130*cdf0e10cSrcweir } 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir else 1133*cdf0e10cSrcweir { 1134*cdf0e10cSrcweir // hyperlink document must be loaded into a new frame 1135*cdf0e10cSrcweir rReq.RemoveItem( SID_TARGETNAME ); 1136*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) ); 1137*cdf0e10cSrcweir } 1138*cdf0e10cSrcweir } 1139*cdf0e10cSrcweir } 1140*cdf0e10cSrcweir 1141*cdf0e10cSrcweir if ( !SFX_APP()->IsSecureURL( INetURLObject(aFileName), &aReferer ) ) 1142*cdf0e10cSrcweir { 1143*cdf0e10cSrcweir SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aFileName ); 1144*cdf0e10cSrcweir ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED ); 1145*cdf0e10cSrcweir return; 1146*cdf0e10cSrcweir } 1147*cdf0e10cSrcweir 1148*cdf0e10cSrcweir SfxFrame* pTargetFrame = NULL; 1149*cdf0e10cSrcweir Reference< XFrame > xTargetFrame; 1150*cdf0e10cSrcweir 1151*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False); 1152*cdf0e10cSrcweir if ( pFrameItem ) 1153*cdf0e10cSrcweir pTargetFrame = pFrameItem->GetFrame(); 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir if ( !pTargetFrame ) 1156*cdf0e10cSrcweir { 1157*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pUnoFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False); 1158*cdf0e10cSrcweir if ( pUnoFrameItem ) 1159*cdf0e10cSrcweir xTargetFrame = pUnoFrameItem->GetFrame(); 1160*cdf0e10cSrcweir } 1161*cdf0e10cSrcweir 1162*cdf0e10cSrcweir if ( !pTargetFrame && !xTargetFrame.is() && SfxViewFrame::Current() ) 1163*cdf0e10cSrcweir pTargetFrame = &SfxViewFrame::Current()->GetFrame(); 1164*cdf0e10cSrcweir 1165*cdf0e10cSrcweir // check if caller has set a callback 1166*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pLinkItem, SfxLinkItem, SID_DONELINK, sal_False ); 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir // remove from Itemset, because it confuses the parameter transformation 1169*cdf0e10cSrcweir if ( pLinkItem ) 1170*cdf0e10cSrcweir pLinkItem = (SfxLinkItem*) pLinkItem->Clone(); 1171*cdf0e10cSrcweir 1172*cdf0e10cSrcweir rReq.RemoveItem( SID_DONELINK ); 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir // check if the view must be hidden 1175*cdf0e10cSrcweir sal_Bool bHidden = sal_False; 1176*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pHidItem, SfxBoolItem, SID_HIDDEN, sal_False); 1177*cdf0e10cSrcweir if ( pHidItem ) 1178*cdf0e10cSrcweir bHidden = pHidItem->GetValue(); 1179*cdf0e10cSrcweir 1180*cdf0e10cSrcweir // This request is a UI call. We have to set the right values inside the MediaDescriptor 1181*cdf0e10cSrcweir // for: InteractionHandler, StatusIndicator, MacroExecutionMode and DocTemplate. 1182*cdf0e10cSrcweir // But we have to look for already existing values or for real hidden requests. 1183*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pPreviewItem, SfxBoolItem, SID_PREVIEW, sal_False); 1184*cdf0e10cSrcweir if (!bHidden && ( !pPreviewItem || !pPreviewItem->GetValue() ) ) 1185*cdf0e10cSrcweir { 1186*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False); 1187*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , sal_False); 1188*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , sal_False); 1189*cdf0e10cSrcweir 1190*cdf0e10cSrcweir if (!pInteractionItem) 1191*cdf0e10cSrcweir { 1192*cdf0e10cSrcweir Reference < ::com::sun::star::task::XInteractionHandler > xHdl( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY ); 1193*cdf0e10cSrcweir if (xHdl.is()) 1194*cdf0e10cSrcweir rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) ); 1195*cdf0e10cSrcweir } 1196*cdf0e10cSrcweir if (!pMacroExecItem) 1197*cdf0e10cSrcweir rReq.AppendItem( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) ); 1198*cdf0e10cSrcweir if (!pDocTemplateItem) 1199*cdf0e10cSrcweir rReq.AppendItem( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) ); 1200*cdf0e10cSrcweir } 1201*cdf0e10cSrcweir 1202*cdf0e10cSrcweir // extract target name 1203*cdf0e10cSrcweir ::rtl::OUString aTarget; 1204*cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pTargetItem, SfxStringItem, SID_TARGETNAME, sal_False); 1205*cdf0e10cSrcweir if ( pTargetItem ) 1206*cdf0e10cSrcweir aTarget = pTargetItem->GetValue(); 1207*cdf0e10cSrcweir else 1208*cdf0e10cSrcweir { 1209*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pNewViewItem, SfxBoolItem, SID_OPEN_NEW_VIEW, sal_False ); 1210*cdf0e10cSrcweir if ( pNewViewItem && pNewViewItem->GetValue() ) 1211*cdf0e10cSrcweir aTarget = String::CreateFromAscii("_blank" ); 1212*cdf0e10cSrcweir } 1213*cdf0e10cSrcweir 1214*cdf0e10cSrcweir if ( bHidden ) 1215*cdf0e10cSrcweir { 1216*cdf0e10cSrcweir aTarget = String::CreateFromAscii("_blank"); 1217*cdf0e10cSrcweir DBG_ASSERT( rReq.IsSynchronCall() || pLinkItem, "Hidden load process must be done synchronously!" ); 1218*cdf0e10cSrcweir } 1219*cdf0e10cSrcweir 1220*cdf0e10cSrcweir Reference < XController > xController; 1221*cdf0e10cSrcweir // if ( ( !bIsBlankTarget && pFrame ) || pLinkItem || !rReq.IsSynchronCall() ) 1222*cdf0e10cSrcweir // { 1223*cdf0e10cSrcweir // if a frame is given, it must be used for the starting point of the targetting mechanism 1224*cdf0e10cSrcweir // this code is also used if asynchronous loading is possible, because loadComponent always is synchron 1225*cdf0e10cSrcweir if ( !xTargetFrame.is() ) 1226*cdf0e10cSrcweir { 1227*cdf0e10cSrcweir if ( pTargetFrame ) 1228*cdf0e10cSrcweir { 1229*cdf0e10cSrcweir xTargetFrame = pTargetFrame->GetFrameInterface(); 1230*cdf0e10cSrcweir } 1231*cdf0e10cSrcweir else 1232*cdf0e10cSrcweir { 1233*cdf0e10cSrcweir xTargetFrame.set( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY ); 1234*cdf0e10cSrcweir } 1235*cdf0e10cSrcweir } 1236*cdf0e10cSrcweir 1237*cdf0e10cSrcweir // make URL ready 1238*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pURLItem, SfxStringItem, SID_FILE_NAME, sal_False ); 1239*cdf0e10cSrcweir aFileName = pURLItem->GetValue(); 1240*cdf0e10cSrcweir if( aFileName.Len() && aFileName.GetChar(0) == '#' ) // Mark without URL 1241*cdf0e10cSrcweir { 1242*cdf0e10cSrcweir SfxViewFrame *pView = pTargetFrame ? pTargetFrame->GetCurrentViewFrame() : 0; 1243*cdf0e10cSrcweir if ( !pView ) 1244*cdf0e10cSrcweir pView = SfxViewFrame::Current(); 1245*cdf0e10cSrcweir pView->GetViewShell()->JumpToMark( aFileName.Copy(1) ); 1246*cdf0e10cSrcweir rReq.SetReturnValue( SfxViewFrameItem( 0, pView ) ); 1247*cdf0e10cSrcweir return; 1248*cdf0e10cSrcweir } 1249*cdf0e10cSrcweir 1250*cdf0e10cSrcweir // convert items to properties for framework API calls 1251*cdf0e10cSrcweir Sequence < PropertyValue > aArgs; 1252*cdf0e10cSrcweir TransformItems( SID_OPENDOC, *rReq.GetArgs(), aArgs ); 1253*cdf0e10cSrcweir 1254*cdf0e10cSrcweir // TODO/LATER: either remove LinkItem or create an asynchronous process for it 1255*cdf0e10cSrcweir if( bHidden || pLinkItem || rReq.IsSynchronCall() ) 1256*cdf0e10cSrcweir { 1257*cdf0e10cSrcweir // if loading must be done synchron, we must wait for completion to get a return value 1258*cdf0e10cSrcweir // find frame by myself; I must konw the exact frame to get the controller for the return value from it 1259*cdf0e10cSrcweir //if( aTarget.getLength() ) 1260*cdf0e10cSrcweir // xTargetFrame = xTargetFrame->findFrame( aTarget, FrameSearchFlag::ALL ); 1261*cdf0e10cSrcweir Reference < XComponent > xComp; 1262*cdf0e10cSrcweir 1263*cdf0e10cSrcweir try 1264*cdf0e10cSrcweir { 1265*cdf0e10cSrcweir xComp = ::comphelper::SynchronousDispatch::dispatch( xTargetFrame, aFileName, aTarget, 0, aArgs ); 1266*cdf0e10cSrcweir // Reference < XComponentLoader > xLoader( xTargetFrame, UNO_QUERY ); 1267*cdf0e10cSrcweir // xComp = xLoader->loadComponentFromURL( aFileName, aTarget, 0, aArgs ); 1268*cdf0e10cSrcweir } 1269*cdf0e10cSrcweir catch(const RuntimeException&) 1270*cdf0e10cSrcweir { 1271*cdf0e10cSrcweir throw; 1272*cdf0e10cSrcweir } 1273*cdf0e10cSrcweir catch(const ::com::sun::star::uno::Exception&) 1274*cdf0e10cSrcweir { 1275*cdf0e10cSrcweir } 1276*cdf0e10cSrcweir 1277*cdf0e10cSrcweir Reference < XModel > xModel( xComp, UNO_QUERY ); 1278*cdf0e10cSrcweir if ( xModel.is() ) 1279*cdf0e10cSrcweir xController = xModel->getCurrentController(); 1280*cdf0e10cSrcweir else 1281*cdf0e10cSrcweir xController = Reference < XController >( xComp, UNO_QUERY ); 1282*cdf0e10cSrcweir 1283*cdf0e10cSrcweir } 1284*cdf0e10cSrcweir else 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir URL aURL; 1287*cdf0e10cSrcweir aURL.Complete = aFileName; 1288*cdf0e10cSrcweir Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY ); 1289*cdf0e10cSrcweir xTrans->parseStrict( aURL ); 1290*cdf0e10cSrcweir 1291*cdf0e10cSrcweir Reference < XDispatchProvider > xProv( xTargetFrame, UNO_QUERY ); 1292*cdf0e10cSrcweir Reference < XDispatch > xDisp = xProv.is() ? xProv->queryDispatch( aURL, aTarget, FrameSearchFlag::ALL ) : Reference < XDispatch >();; 1293*cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, "PERFORMANCE - SfxApplication::OpenDocExec_Impl" ); 1294*cdf0e10cSrcweir if ( xDisp.is() ) 1295*cdf0e10cSrcweir xDisp->dispatch( aURL, aArgs ); 1296*cdf0e10cSrcweir } 1297*cdf0e10cSrcweir /* 1298*cdf0e10cSrcweir } 1299*cdf0e10cSrcweir else 1300*cdf0e10cSrcweir { 1301*cdf0e10cSrcweir // synchron loading without a given frame or as blank frame 1302*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 1303*cdf0e10cSrcweir 1304*cdf0e10cSrcweir // Desktop service must exists! dont catch() or check for problems here ... 1305*cdf0e10cSrcweir // But loading of documents can fail by other reasons. Handle it more gracefully. 1306*cdf0e10cSrcweir Reference < XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY ); 1307*cdf0e10cSrcweir Reference < XComponent > xComp; 1308*cdf0e10cSrcweir try 1309*cdf0e10cSrcweir { 1310*cdf0e10cSrcweir xComp = xDesktop->loadComponentFromURL( pFileNameItem->GetValue(), aTarget, 0, aArgs ); 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir catch(const RuntimeException&) 1313*cdf0e10cSrcweir { 1314*cdf0e10cSrcweir throw; 1315*cdf0e10cSrcweir } 1316*cdf0e10cSrcweir catch(const ::com::sun::star::uno::Exception&) 1317*cdf0e10cSrcweir { 1318*cdf0e10cSrcweir xDesktop.clear(); 1319*cdf0e10cSrcweir xComp.clear(); 1320*cdf0e10cSrcweir } 1321*cdf0e10cSrcweir 1322*cdf0e10cSrcweir Reference < XModel > xModel( xComp, UNO_QUERY ); 1323*cdf0e10cSrcweir if ( xModel.is() ) 1324*cdf0e10cSrcweir xController = xModel->getCurrentController(); 1325*cdf0e10cSrcweir else 1326*cdf0e10cSrcweir xController = Reference < XController >( xComp, UNO_QUERY ); 1327*cdf0e10cSrcweir }*/ 1328*cdf0e10cSrcweir 1329*cdf0e10cSrcweir if ( xController.is() ) 1330*cdf0e10cSrcweir { 1331*cdf0e10cSrcweir // try to find the SfxFrame for the controller 1332*cdf0e10cSrcweir SfxFrame* pCntrFrame = NULL; 1333*cdf0e10cSrcweir for ( SfxViewShell* pShell = SfxViewShell::GetFirst( 0, sal_False ); pShell; pShell = SfxViewShell::GetNext( *pShell, 0, sal_False ) ) 1334*cdf0e10cSrcweir { 1335*cdf0e10cSrcweir if ( pShell->GetController() == xController ) 1336*cdf0e10cSrcweir { 1337*cdf0e10cSrcweir pCntrFrame = &pShell->GetViewFrame()->GetFrame(); 1338*cdf0e10cSrcweir break; 1339*cdf0e10cSrcweir } 1340*cdf0e10cSrcweir } 1341*cdf0e10cSrcweir 1342*cdf0e10cSrcweir if ( pCntrFrame ) 1343*cdf0e10cSrcweir { 1344*cdf0e10cSrcweir SfxObjectShell* pSh = pCntrFrame->GetCurrentDocument(); 1345*cdf0e10cSrcweir DBG_ASSERT( pSh, "Controller without ObjectShell ?!" ); 1346*cdf0e10cSrcweir 1347*cdf0e10cSrcweir rReq.SetReturnValue( SfxViewFrameItem( 0, pCntrFrame->GetCurrentViewFrame() ) ); 1348*cdf0e10cSrcweir 1349*cdf0e10cSrcweir if ( bHidden ) 1350*cdf0e10cSrcweir pSh->RestoreNoDelete(); 1351*cdf0e10cSrcweir } 1352*cdf0e10cSrcweir } 1353*cdf0e10cSrcweir 1354*cdf0e10cSrcweir if ( pLinkItem ) 1355*cdf0e10cSrcweir { 1356*cdf0e10cSrcweir SfxPoolItem* pRet = rReq.GetReturnValue()->Clone(); 1357*cdf0e10cSrcweir pLinkItem->GetValue().Call(pRet); 1358*cdf0e10cSrcweir delete pLinkItem; 1359*cdf0e10cSrcweir } 1360*cdf0e10cSrcweir } 1361