1*d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*d119d52dSAndrew Rist * distributed with this work for additional information 6*d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9*d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10*d119d52dSAndrew Rist * 11*d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*d119d52dSAndrew Rist * 13*d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*d119d52dSAndrew Rist * software distributed under the License is distributed on an 15*d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17*d119d52dSAndrew Rist * specific language governing permissions and limitations 18*d119d52dSAndrew Rist * under the License. 19*d119d52dSAndrew Rist * 20*d119d52dSAndrew Rist *************************************************************/ 21*d119d52dSAndrew Rist 22*d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 28cdf0e10cSrcweir #include <vcl/msgbox.hxx> 29cdf0e10cSrcweir #include <tools/urlobj.hxx> 30cdf0e10cSrcweir #include <tools/stream.hxx> 31cdf0e10cSrcweir #include <sot/formats.hxx> 32cdf0e10cSrcweir #include <svtools/filter.hxx> 33cdf0e10cSrcweir #include <sfx2/lnkbase.hxx> 34cdf0e10cSrcweir #include <sfx2/app.hxx> 35cdf0e10cSrcweir #include <sfx2/progress.hxx> 36cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 37cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 38cdf0e10cSrcweir #include <sot/exchange.hxx> 39cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 40cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 41cdf0e10cSrcweir #include <sfx2/docfac.hxx> 42cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp> 43cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx> 44cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 45cdf0e10cSrcweir #include <sfx2/linkmgr.hxx> 46cdf0e10cSrcweir #include <sfx2/opengrf.hxx> 47cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 48cdf0e10cSrcweir #include "fileobj.hxx" 49cdf0e10cSrcweir #include "app.hrc" 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace css = ::com::sun::star; 52cdf0e10cSrcweir 53cdf0e10cSrcweir #define FILETYPE_TEXT 1 54cdf0e10cSrcweir #define FILETYPE_GRF 2 55cdf0e10cSrcweir #define FILETYPE_OBJECT 3 56cdf0e10cSrcweir 57cdf0e10cSrcweir struct Impl_DownLoadData 58cdf0e10cSrcweir { 59cdf0e10cSrcweir Graphic aGrf; 60cdf0e10cSrcweir Timer aTimer; 61cdf0e10cSrcweir 62cdf0e10cSrcweir Impl_DownLoadData( const Link& rLink ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir aTimer.SetTimeout( 100 ); 65cdf0e10cSrcweir aTimer.SetTimeoutHdl( rLink ); 66cdf0e10cSrcweir aGrf.SetDefaultType(); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir ~Impl_DownLoadData() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir aTimer.Stop(); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir }; 73cdf0e10cSrcweir 74cdf0e10cSrcweir // -------------------------------------------------------------------------- 75cdf0e10cSrcweir 76cdf0e10cSrcweir 77cdf0e10cSrcweir SvFileObject::SvFileObject() : 78cdf0e10cSrcweir pDownLoadData( NULL ), pOldParent( NULL ), nType( FILETYPE_TEXT ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir bLoadAgain = sal_True; 81cdf0e10cSrcweir bSynchron = bLoadError = bWaitForData = bDataReady = bNativFormat = 82cdf0e10cSrcweir bClearMedium = bStateChangeCalled = bInCallDownLoad = sal_False; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweir SvFileObject::~SvFileObject() 87cdf0e10cSrcweir { 88cdf0e10cSrcweir if ( xMed.Is() ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir xMed->SetDataAvailableLink( Link() ); 91cdf0e10cSrcweir xMed->SetDoneLink( Link() ); 92cdf0e10cSrcweir xMed.Clear(); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir delete pDownLoadData; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir 98cdf0e10cSrcweir sal_Bool SvFileObject::GetData( ::com::sun::star::uno::Any & rData, 99cdf0e10cSrcweir const String & rMimeType, 100cdf0e10cSrcweir sal_Bool bGetSynchron ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir sal_uIntPtr nFmt = SotExchange::GetFormatStringId( rMimeType ); 103cdf0e10cSrcweir switch( nType ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir case FILETYPE_TEXT: 106cdf0e10cSrcweir if( FORMAT_FILE == nFmt ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir // das Medium muss in der Applikation geoffnet werden, um die 109cdf0e10cSrcweir // relativen Datei Links aufzuloesen!!!! Wird ueber den 110cdf0e10cSrcweir // LinkManager und damit von dessen Storage erledigt. 111cdf0e10cSrcweir rData <<= rtl::OUString( sFileNm ); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir break; 114cdf0e10cSrcweir 115cdf0e10cSrcweir case FILETYPE_GRF: 116cdf0e10cSrcweir if( !bLoadError ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir SfxMediumRef xTmpMed; 119cdf0e10cSrcweir 120cdf0e10cSrcweir if( FORMAT_GDIMETAFILE == nFmt || FORMAT_BITMAP == nFmt || 121cdf0e10cSrcweir SOT_FORMATSTR_ID_SVXB == nFmt ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir Graphic aGrf; 124cdf0e10cSrcweir 125cdf0e10cSrcweir //JP 15.07.98: Bug 52959 126cdf0e10cSrcweir // falls das Nativformat doch erwuenscht ist, muss am 127cdf0e10cSrcweir // Ende das Flag zurueckgesetzt werden. 128cdf0e10cSrcweir // wird einzig und allein im sw/ndgrf.cxx benutzt, wenn der Link vom 129cdf0e10cSrcweir // GraphicNode entfernt wird. 130cdf0e10cSrcweir sal_Bool bOldNativFormat = bNativFormat; 131cdf0e10cSrcweir //!!?? bNativFormat = 0 != (ASPECT_ICON & pSvData->GetAspect()); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // falls gedruckt werden soll, warten wir bis die 134cdf0e10cSrcweir // Daten vorhanden sind 135cdf0e10cSrcweir if( bGetSynchron ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir // testhalber mal ein LoadFile rufen um das nach- 138cdf0e10cSrcweir // laden ueberahaupt anzustossen 139cdf0e10cSrcweir if( !xMed.Is() ) 140cdf0e10cSrcweir LoadFile_Impl(); 141cdf0e10cSrcweir 142cdf0e10cSrcweir if( !bInCallDownLoad ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir xTmpMed = xMed; 145cdf0e10cSrcweir while( bWaitForData ) 146cdf0e10cSrcweir Application::Reschedule(); 147cdf0e10cSrcweir 148cdf0e10cSrcweir xMed = xTmpMed; 149cdf0e10cSrcweir bClearMedium = sal_True; 150cdf0e10cSrcweir } 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir if( pDownLoadData || 154cdf0e10cSrcweir ( !bWaitForData && ( xMed.Is() || // wurde als URL geladen 155cdf0e10cSrcweir ( bSynchron && LoadFile_Impl() && xMed.Is() ) )) ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir // falls 158cdf0e10cSrcweir 159cdf0e10cSrcweir // falls es uebers Internet gesogen wurde, nicht 160cdf0e10cSrcweir // wieder versuchen 161cdf0e10cSrcweir if( !bGetSynchron ) 162cdf0e10cSrcweir bLoadAgain = !xMed->IsRemote(); 163cdf0e10cSrcweir bLoadError = !GetGraphic_Impl( aGrf, xMed->GetInStream() ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir else if( !LoadFile_Impl() || 166cdf0e10cSrcweir !GetGraphic_Impl( aGrf, xMed.Is() ? xMed->GetInStream() : 0 )) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if( !xMed.Is() ) 169cdf0e10cSrcweir break; 170cdf0e10cSrcweir aGrf.SetDefaultType(); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir if( SOT_FORMATSTR_ID_SVXB != nFmt ) 174cdf0e10cSrcweir nFmt = (bLoadError || GRAPHIC_BITMAP == aGrf.GetType()) 175cdf0e10cSrcweir ? FORMAT_BITMAP 176cdf0e10cSrcweir : FORMAT_GDIMETAFILE; 177cdf0e10cSrcweir 178cdf0e10cSrcweir SvMemoryStream aMemStm( 0, 65535 ); 179cdf0e10cSrcweir switch ( nFmt ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir case SOT_FORMATSTR_ID_SVXB: 182cdf0e10cSrcweir if( GRAPHIC_NONE != aGrf.GetType() ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); 185cdf0e10cSrcweir aMemStm << aGrf; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir break; 188cdf0e10cSrcweir 189cdf0e10cSrcweir case FORMAT_BITMAP: 190cdf0e10cSrcweir if( !aGrf.GetBitmap().IsEmpty()) 191cdf0e10cSrcweir aMemStm << aGrf.GetBitmap(); 192cdf0e10cSrcweir break; 193cdf0e10cSrcweir 194cdf0e10cSrcweir default: 195cdf0e10cSrcweir if( aGrf.GetGDIMetaFile().GetActionCount() ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir GDIMetaFile aMeta( aGrf.GetGDIMetaFile() ); 198cdf0e10cSrcweir aMeta.Write( aMemStm ); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir } 201cdf0e10cSrcweir rData <<= css::uno::Sequence< sal_Int8 >( (sal_Int8*) aMemStm.GetData(), 202cdf0e10cSrcweir aMemStm.Seek( STREAM_SEEK_TO_END ) ); 203cdf0e10cSrcweir 204cdf0e10cSrcweir bNativFormat = bOldNativFormat; 205cdf0e10cSrcweir 206cdf0e10cSrcweir // alles fertig? 207cdf0e10cSrcweir if( xMed.Is() && !bSynchron && bClearMedium ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir xMed.Clear(); 210cdf0e10cSrcweir bClearMedium = sal_False; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir } 214cdf0e10cSrcweir break; 215cdf0e10cSrcweir case FILETYPE_OBJECT: 216cdf0e10cSrcweir // TODO/LATER: possibility to insert a new object 217cdf0e10cSrcweir rData <<= rtl::OUString( sFileNm ); 218cdf0e10cSrcweir break; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir return sal_True/*0 != aTypeList.Count()*/; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir 226cdf0e10cSrcweir sal_Bool SvFileObject::Connect( sfx2::SvBaseLink* pLink ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir if( !pLink || !pLink->GetLinkManager() ) 229cdf0e10cSrcweir return sal_False; 230cdf0e10cSrcweir 231cdf0e10cSrcweir // teste doch mal, ob nicht ein anderer Link mit der gleichen 232cdf0e10cSrcweir // Verbindung schon existiert 233cdf0e10cSrcweir pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sFileNm, 0, &sFilter ); 234cdf0e10cSrcweir 235cdf0e10cSrcweir if( OBJECT_CLIENT_GRF == pLink->GetObjType() ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir SfxObjectShellRef pShell = pLink->GetLinkManager()->GetPersist(); 238cdf0e10cSrcweir if( pShell.Is() ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir if( pShell->IsAbortingImport() ) 241cdf0e10cSrcweir return sal_False; 242cdf0e10cSrcweir 243cdf0e10cSrcweir if( pShell->GetMedium() ) 244cdf0e10cSrcweir sReferer = pShell->GetMedium()->GetName(); 245cdf0e10cSrcweir } 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir switch( pLink->GetObjType() ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir case OBJECT_CLIENT_GRF: 251cdf0e10cSrcweir nType = FILETYPE_GRF; 252cdf0e10cSrcweir bSynchron = pLink->IsSynchron(); 253cdf0e10cSrcweir break; 254cdf0e10cSrcweir 255cdf0e10cSrcweir case OBJECT_CLIENT_FILE: 256cdf0e10cSrcweir nType = FILETYPE_TEXT; 257cdf0e10cSrcweir break; 258cdf0e10cSrcweir 259cdf0e10cSrcweir case OBJECT_CLIENT_OLE: 260cdf0e10cSrcweir nType = FILETYPE_OBJECT; 261cdf0e10cSrcweir // TODO/LATER: introduce own type to be used for exchanging 262cdf0e10cSrcweir break; 263cdf0e10cSrcweir 264cdf0e10cSrcweir default: 265cdf0e10cSrcweir return sal_False; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir SetUpdateTimeout( 0 ); 269cdf0e10cSrcweir 270cdf0e10cSrcweir // und jetzt bei diesem oder gefundenem Pseudo-Object anmelden 271cdf0e10cSrcweir AddDataAdvise( pLink, SotExchange::GetFormatMimeType( pLink->GetContentType()), 0 ); 272cdf0e10cSrcweir return sal_True; 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir 276cdf0e10cSrcweir sal_Bool SvFileObject::LoadFile_Impl() 277cdf0e10cSrcweir { 278cdf0e10cSrcweir // wir sind noch im Laden!! 279cdf0e10cSrcweir if( bWaitForData || !bLoadAgain || xMed.Is() || pDownLoadData ) 280cdf0e10cSrcweir return sal_False; 281cdf0e10cSrcweir 282cdf0e10cSrcweir // z.Z. nur auf die aktuelle DocShell 283cdf0e10cSrcweir xMed = new SfxMedium( sFileNm, STREAM_STD_READ, sal_True ); 284cdf0e10cSrcweir SvLinkSource::StreamToLoadFrom aStreamToLoadFrom = 285cdf0e10cSrcweir getStreamToLoadFrom(); 286cdf0e10cSrcweir xMed->setStreamToLoadFrom( 287cdf0e10cSrcweir aStreamToLoadFrom.m_xInputStreamToLoadFrom, 288cdf0e10cSrcweir aStreamToLoadFrom.m_bIsReadOnly); 289cdf0e10cSrcweir // setStreamToLoadFrom(0,0); 290cdf0e10cSrcweir if( sReferer.Len() ) 291cdf0e10cSrcweir xMed->SetReferer( sReferer ); 292cdf0e10cSrcweir 293cdf0e10cSrcweir if( !bSynchron ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir bLoadAgain = bDataReady = bInNewData = sal_False; 296cdf0e10cSrcweir bWaitForData = sal_True; 297cdf0e10cSrcweir 298cdf0e10cSrcweir SfxMediumRef xTmpMed = xMed; 299cdf0e10cSrcweir xMed->SetDataAvailableLink( STATIC_LINK( this, SvFileObject, LoadGrfNewData_Impl ) ); 300cdf0e10cSrcweir bInCallDownLoad = sal_True; 301cdf0e10cSrcweir xMed->DownLoad( STATIC_LINK( this, SvFileObject, LoadGrfReady_Impl ) ); 302cdf0e10cSrcweir bInCallDownLoad = sal_False; 303cdf0e10cSrcweir 304cdf0e10cSrcweir bClearMedium = !xMed.Is(); 305cdf0e10cSrcweir if( bClearMedium ) 306cdf0e10cSrcweir xMed = xTmpMed; // falls gleich im DownLoad schon schluss ist 307cdf0e10cSrcweir return bDataReady; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir bWaitForData = sal_True; 311cdf0e10cSrcweir bDataReady = bInNewData = sal_False; 312cdf0e10cSrcweir xMed->DownLoad(); 313cdf0e10cSrcweir bLoadAgain = !xMed->IsRemote(); 314cdf0e10cSrcweir bWaitForData = sal_False; 315cdf0e10cSrcweir 316cdf0e10cSrcweir // Grafik ist fertig, also DataChanged von der Statusaederung schicken: 317cdf0e10cSrcweir SendStateChg_Impl( xMed->GetInStream() && xMed->GetInStream()->GetError() 318cdf0e10cSrcweir ? sfx2::LinkManager::STATE_LOAD_ERROR : sfx2::LinkManager::STATE_LOAD_OK ); 319cdf0e10cSrcweir return sal_True; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir 323cdf0e10cSrcweir sal_Bool SvFileObject::GetGraphic_Impl( Graphic& rGrf, SvStream* pStream ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir GraphicFilter* pGF = GraphicFilter::GetGraphicFilter(); 326cdf0e10cSrcweir 327cdf0e10cSrcweir const sal_uInt16 nFilter = sFilter.Len() && pGF->GetImportFormatCount() 328cdf0e10cSrcweir ? pGF->GetImportFormatNumber( sFilter ) 329cdf0e10cSrcweir : GRFILTER_FORMAT_DONTKNOW; 330cdf0e10cSrcweir 331cdf0e10cSrcweir String aEmptyStr; 332cdf0e10cSrcweir int nRes; 333cdf0e10cSrcweir 334cdf0e10cSrcweir // vermeiden, dass ein native Link angelegt wird 335cdf0e10cSrcweir if( ( !pStream || !pDownLoadData ) && !rGrf.IsLink() && 336cdf0e10cSrcweir !rGrf.GetContext() && !bNativFormat ) 337cdf0e10cSrcweir rGrf.SetLink( GfxLink() ); 338cdf0e10cSrcweir 339cdf0e10cSrcweir if( !pStream ) 340cdf0e10cSrcweir nRes = xMed.Is() ? GRFILTER_OPENERROR 341cdf0e10cSrcweir : pGF->ImportGraphic( rGrf, INetURLObject(sFileNm), 342cdf0e10cSrcweir nFilter ); 343cdf0e10cSrcweir else if( !pDownLoadData ) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir pStream->Seek( STREAM_SEEK_TO_BEGIN ); 346cdf0e10cSrcweir nRes = pGF->ImportGraphic( rGrf, aEmptyStr, *pStream, nFilter ); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir else 349cdf0e10cSrcweir { 350cdf0e10cSrcweir nRes = pGF->ImportGraphic( pDownLoadData->aGrf, aEmptyStr, 351cdf0e10cSrcweir *pStream, nFilter ); 352cdf0e10cSrcweir 353cdf0e10cSrcweir if( pDownLoadData ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir rGrf = pDownLoadData->aGrf; 356cdf0e10cSrcweir if( GRAPHIC_NONE == rGrf.GetType() ) 357cdf0e10cSrcweir rGrf.SetDefaultType(); 358cdf0e10cSrcweir 359cdf0e10cSrcweir 360cdf0e10cSrcweir if( !pDownLoadData->aGrf.GetContext() ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir xMed->SetDataAvailableLink( Link() ); 363cdf0e10cSrcweir // xMed->SetDoneLink( Link() ); 364cdf0e10cSrcweir delete pDownLoadData, pDownLoadData = 0; 365cdf0e10cSrcweir bDataReady = sal_True; 366cdf0e10cSrcweir bWaitForData = sal_False; 367cdf0e10cSrcweir } 368cdf0e10cSrcweir else if( sal_False ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir // Timer aufsetzen, um zurueck zukehren 371cdf0e10cSrcweir pDownLoadData->aTimer.Start(); 372cdf0e10cSrcweir } 373cdf0e10cSrcweir } 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir if( pStream && ERRCODE_IO_PENDING == pStream->GetError() ) 377cdf0e10cSrcweir pStream->ResetError(); 378cdf0e10cSrcweir 379cdf0e10cSrcweir #ifdef DBG_UTIL 380cdf0e10cSrcweir if( nRes ) 381cdf0e10cSrcweir { 382cdf0e10cSrcweir if( xMed.Is() && !pStream ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir DBG_WARNING3( "GrafikFehler [%d] - [%s] URL[%s]", 385cdf0e10cSrcweir nRes, 386cdf0e10cSrcweir xMed->GetPhysicalName().GetBuffer(), 387cdf0e10cSrcweir sFileNm.GetBuffer() ); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir else 390cdf0e10cSrcweir { 391cdf0e10cSrcweir DBG_WARNING2( "GrafikFehler [%d] - [%s]", 392cdf0e10cSrcweir nRes, sFileNm.GetBuffer() ); 393cdf0e10cSrcweir } 394cdf0e10cSrcweir } 395cdf0e10cSrcweir #endif 396cdf0e10cSrcweir 397cdf0e10cSrcweir return GRFILTER_OK == nRes; 398cdf0e10cSrcweir } 399cdf0e10cSrcweir 400cdf0e10cSrcweir /** detect the filter of the given file 401cdf0e10cSrcweir 402cdf0e10cSrcweir @param _rURL 403cdf0e10cSrcweir specifies the URL of the file which filter is to detected.<br/> 404cdf0e10cSrcweir If the URL doesn't denote a valid (existent and accessible) file, the 405cdf0e10cSrcweir request is silently dropped. 406cdf0e10cSrcweir */ 407cdf0e10cSrcweir String impl_getFilter( const String& _rURL ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir String sFilter; 410cdf0e10cSrcweir if ( _rURL.Len() == 0 ) 411cdf0e10cSrcweir return sFilter; 412cdf0e10cSrcweir 413cdf0e10cSrcweir try 414cdf0e10cSrcweir { 415cdf0e10cSrcweir css::uno::Reference< ::com::sun::star::document::XTypeDetection > xTypeDetection( 416cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance( 417cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection") ), 418cdf0e10cSrcweir css::uno::UNO_QUERY ); 419cdf0e10cSrcweir if ( xTypeDetection.is() ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir ::comphelper::MediaDescriptor aDescr; 422cdf0e10cSrcweir aDescr[ ::comphelper::MediaDescriptor::PROP_URL() ] <<= ::rtl::OUString( _rURL ); 423cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > aDescrList = 424cdf0e10cSrcweir aDescr.getAsConstPropertyValueList(); 425cdf0e10cSrcweir ::rtl::OUString sType = xTypeDetection->queryTypeByDescriptor( aDescrList, sal_True ); 426cdf0e10cSrcweir if ( sType.getLength() ) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xTypeCont( xTypeDetection, 429cdf0e10cSrcweir css::uno::UNO_QUERY ); 430cdf0e10cSrcweir if ( xTypeCont.is() ) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lTypeProps( xTypeCont->getByName( sType ) ); 433cdf0e10cSrcweir sFilter = lTypeProps.getUnpackedValueOrDefault( 434cdf0e10cSrcweir ::rtl::OUString::createFromAscii("PreferredFilter"), ::rtl::OUString() ); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir } 439cdf0e10cSrcweir catch( const css::uno::Exception& ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir return sFilter; 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir void SvFileObject::Edit( Window* pParent, sfx2::SvBaseLink* pLink, const Link& rEndEditHdl ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir aEndEditLink = rEndEditHdl; 449cdf0e10cSrcweir String sFile, sRange, sTmpFilter; 450cdf0e10cSrcweir if( pLink && pLink->GetLinkManager() ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sFile, &sRange, &sTmpFilter ); 453cdf0e10cSrcweir 454cdf0e10cSrcweir switch( pLink->GetObjType() ) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir case OBJECT_CLIENT_GRF: 457cdf0e10cSrcweir { 458cdf0e10cSrcweir nType = FILETYPE_GRF; // falls noch nicht gesetzt 459cdf0e10cSrcweir 460cdf0e10cSrcweir SvxOpenGraphicDialog aDlg(SfxResId(RID_SVXSTR_EDITGRFLINK)); 461cdf0e10cSrcweir aDlg.EnableLink(sal_False); 462cdf0e10cSrcweir aDlg.SetPath( sFile, sal_True ); 463cdf0e10cSrcweir aDlg.SetCurrentFilter( sTmpFilter ); 464cdf0e10cSrcweir 465cdf0e10cSrcweir if( !aDlg.Execute() ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir sFile = aDlg.GetPath(); 468cdf0e10cSrcweir sFile += ::sfx2::cTokenSeperator; 469cdf0e10cSrcweir sFile += ::sfx2::cTokenSeperator; 470cdf0e10cSrcweir sFile += aDlg.GetCurrentFilter(); 471cdf0e10cSrcweir 472cdf0e10cSrcweir if ( aEndEditLink.IsSet() ) 473cdf0e10cSrcweir aEndEditLink.Call( &sFile ); 474cdf0e10cSrcweir } 475cdf0e10cSrcweir else 476cdf0e10cSrcweir sFile.Erase(); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir break; 479cdf0e10cSrcweir 480cdf0e10cSrcweir case OBJECT_CLIENT_OLE: 481cdf0e10cSrcweir { 482cdf0e10cSrcweir nType = FILETYPE_OBJECT; // if not set already 483cdf0e10cSrcweir pOldParent = Application::GetDefDialogParent(); 484cdf0e10cSrcweir Application::SetDefDialogParent( pParent ); 485cdf0e10cSrcweir 486cdf0e10cSrcweir ::sfx2::FileDialogHelper* pFileDlg = 487cdf0e10cSrcweir pLink->GetFileDialog( (SFXWB_INSERT | WB_3DLOOK), String() ); 488cdf0e10cSrcweir pFileDlg->StartExecuteModal( LINK( this, SvFileObject, DialogClosedHdl ) ); 489cdf0e10cSrcweir } 490cdf0e10cSrcweir break; 491cdf0e10cSrcweir 492cdf0e10cSrcweir case OBJECT_CLIENT_FILE: 493cdf0e10cSrcweir { 494cdf0e10cSrcweir nType = FILETYPE_TEXT; // if not set already 495cdf0e10cSrcweir pOldParent = Application::GetDefDialogParent(); 496cdf0e10cSrcweir Application::SetDefDialogParent( pParent ); 497cdf0e10cSrcweir 498cdf0e10cSrcweir String sFactory; 499cdf0e10cSrcweir SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist(); 500cdf0e10cSrcweir if ( pShell ) 501cdf0e10cSrcweir sFactory = pShell->GetFactory().GetFactoryName(); 502cdf0e10cSrcweir 503cdf0e10cSrcweir ::sfx2::FileDialogHelper* pFileDlg = 504cdf0e10cSrcweir pLink->GetFileDialog( (SFXWB_INSERT | WB_3DLOOK), sFactory ); 505cdf0e10cSrcweir pFileDlg->StartExecuteModal( LINK( this, SvFileObject, DialogClosedHdl ) ); 506cdf0e10cSrcweir } 507cdf0e10cSrcweir break; 508cdf0e10cSrcweir 509cdf0e10cSrcweir default: 510cdf0e10cSrcweir sFile.Erase(); 511cdf0e10cSrcweir } 512cdf0e10cSrcweir } 513cdf0e10cSrcweir } 514cdf0e10cSrcweir 515cdf0e10cSrcweir IMPL_STATIC_LINK( SvFileObject, LoadGrfReady_Impl, void*, EMPTYARG ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir // wenn wir von hier kommen, kann es kein Fehler mehr sein 518cdf0e10cSrcweir pThis->bLoadError = sal_False; 519cdf0e10cSrcweir pThis->bWaitForData = sal_False; 520cdf0e10cSrcweir pThis->bInCallDownLoad = sal_False; 521cdf0e10cSrcweir 522cdf0e10cSrcweir if( !pThis->bInNewData && !pThis->bDataReady ) 523cdf0e10cSrcweir { 524cdf0e10cSrcweir // Grafik ist fertig, also DataChanged von der Status- 525cdf0e10cSrcweir // aederung schicken: 526cdf0e10cSrcweir pThis->bDataReady = sal_True; 527cdf0e10cSrcweir pThis->SendStateChg_Impl( sfx2::LinkManager::STATE_LOAD_OK ); 528cdf0e10cSrcweir 529cdf0e10cSrcweir // und dann nochmal die Daten senden 530cdf0e10cSrcweir pThis->NotifyDataChanged(); 531cdf0e10cSrcweir } 532cdf0e10cSrcweir 533cdf0e10cSrcweir if( pThis->bDataReady ) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir pThis->bLoadAgain = sal_True; 536cdf0e10cSrcweir if( pThis->xMed.Is() ) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir pThis->xMed->SetDataAvailableLink( Link() ); 539cdf0e10cSrcweir pThis->xMed->SetDoneLink( Link() ); 540cdf0e10cSrcweir 541cdf0e10cSrcweir Application::PostUserEvent( 542cdf0e10cSrcweir STATIC_LINK( pThis, SvFileObject, DelMedium_Impl ), 543cdf0e10cSrcweir new SfxMediumRef( pThis->xMed )); 544cdf0e10cSrcweir pThis->xMed.Clear(); 545cdf0e10cSrcweir } 546cdf0e10cSrcweir if( pThis->pDownLoadData ) 547cdf0e10cSrcweir delete pThis->pDownLoadData, pThis->pDownLoadData = 0; 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir return 0; 551cdf0e10cSrcweir } 552cdf0e10cSrcweir 553cdf0e10cSrcweir IMPL_STATIC_LINK( SvFileObject, DelMedium_Impl, SfxMediumRef*, pDelMed ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir (void)pThis; 556cdf0e10cSrcweir delete pDelMed; 557cdf0e10cSrcweir return 0; 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir IMPL_STATIC_LINK( SvFileObject, LoadGrfNewData_Impl, void*, EMPTYARG ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir // wenn wir von hier kommen, kann es kein Fehler mehr sein 563cdf0e10cSrcweir if( pThis->bInNewData ) 564cdf0e10cSrcweir return 0; 565cdf0e10cSrcweir 566cdf0e10cSrcweir pThis->bInNewData = sal_True; 567cdf0e10cSrcweir pThis->bLoadError = sal_False; 568cdf0e10cSrcweir 569cdf0e10cSrcweir if( !pThis->pDownLoadData ) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir pThis->pDownLoadData = new Impl_DownLoadData( 572cdf0e10cSrcweir STATIC_LINK( pThis, SvFileObject, LoadGrfNewData_Impl ) ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir // Null-Link setzen, damit keine temporaeren Grafiken 575cdf0e10cSrcweir // rausgeswapt werden; der Filter prueft, ob schon 576cdf0e10cSrcweir // ein Link gesetzt ist => falls dies zutrifft, wird 577cdf0e10cSrcweir // _kein_ neuer Link gesetzt; der Link muss hier gesetzt werden, 578cdf0e10cSrcweir // (bevor das erste Mal gefiltert wird), um zu verhindern, 579cdf0e10cSrcweir // dass der Kontext zurueckgesetzt wird (aynchrones Laden) 580cdf0e10cSrcweir if( !pThis->bNativFormat ) 581cdf0e10cSrcweir { 582cdf0e10cSrcweir static GfxLink aDummyLink; 583cdf0e10cSrcweir pThis->pDownLoadData->aGrf.SetLink( aDummyLink ); 584cdf0e10cSrcweir } 585cdf0e10cSrcweir } 586cdf0e10cSrcweir 587cdf0e10cSrcweir pThis->NotifyDataChanged(); 588cdf0e10cSrcweir 589cdf0e10cSrcweir SvStream* pStrm = pThis->xMed.Is() ? pThis->xMed->GetInStream() : 0; 590cdf0e10cSrcweir if( pStrm && pStrm->GetError() ) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir if( ERRCODE_IO_PENDING == pStrm->GetError() ) 593cdf0e10cSrcweir pStrm->ResetError(); 594cdf0e10cSrcweir 595cdf0e10cSrcweir // im DataChanged ein DataReady? 596cdf0e10cSrcweir else if( pThis->bWaitForData && pThis->pDownLoadData ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir pThis->bLoadError = sal_True; 599cdf0e10cSrcweir } 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir if( pThis->bDataReady ) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir // Grafik ist fertig, also DataChanged von der Status- 605cdf0e10cSrcweir // aederung schicken: 606cdf0e10cSrcweir pThis->SendStateChg_Impl( pStrm->GetError() ? sfx2::LinkManager::STATE_LOAD_ERROR : sfx2::LinkManager::STATE_LOAD_OK ); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir pThis->bInNewData = sal_False; 610cdf0e10cSrcweir return 0; 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir IMPL_LINK( SvFileObject, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg ) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir String sFile; 616cdf0e10cSrcweir Application::SetDefDialogParent( pOldParent ); 617cdf0e10cSrcweir 618cdf0e10cSrcweir if ( FILETYPE_TEXT == nType || FILETYPE_OBJECT == nType ) 619cdf0e10cSrcweir { 620cdf0e10cSrcweir if ( _pFileDlg && _pFileDlg->GetError() == ERRCODE_NONE ) 621cdf0e10cSrcweir { 622cdf0e10cSrcweir String sURL( _pFileDlg->GetPath() ); 623cdf0e10cSrcweir sFile = sURL; 624cdf0e10cSrcweir sFile += ::sfx2::cTokenSeperator; 625cdf0e10cSrcweir sFile += ::sfx2::cTokenSeperator; 626cdf0e10cSrcweir sFile += impl_getFilter( sURL ); 627cdf0e10cSrcweir } 628cdf0e10cSrcweir } 629cdf0e10cSrcweir else 630cdf0e10cSrcweir { 631cdf0e10cSrcweir DBG_ERRORFILE( "SvFileObject::DialogClosedHdl(): wrong file type" ); 632cdf0e10cSrcweir } 633cdf0e10cSrcweir 634cdf0e10cSrcweir if ( aEndEditLink.IsSet() ) 635cdf0e10cSrcweir aEndEditLink.Call( &sFile ); 636cdf0e10cSrcweir return 0; 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir /* [Beschreibung] 640cdf0e10cSrcweir 641cdf0e10cSrcweir Die Methode stellt fest, ob aus einem DDE-Object die Daten gelesen 642cdf0e10cSrcweir werden kann. 643cdf0e10cSrcweir Zurueckgegeben wird: 644cdf0e10cSrcweir ERRCODE_NONE wenn sie komplett gelesen wurde 645cdf0e10cSrcweir ERRCODE_SO_PENDING wenn sie noch nicht komplett gelesen wurde 646cdf0e10cSrcweir ERRCODE_SO_FALSE sonst 647cdf0e10cSrcweir */ 648cdf0e10cSrcweir sal_Bool SvFileObject::IsPending() const 649cdf0e10cSrcweir { 650cdf0e10cSrcweir return FILETYPE_GRF == nType && !bLoadError && 651cdf0e10cSrcweir ( pDownLoadData || bWaitForData ); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir sal_Bool SvFileObject::IsDataComplete() const 654cdf0e10cSrcweir { 655cdf0e10cSrcweir sal_Bool bRet = sal_False; 656cdf0e10cSrcweir if( FILETYPE_GRF != nType ) 657cdf0e10cSrcweir bRet = sal_True; 658cdf0e10cSrcweir else if( !bLoadError && ( !bWaitForData && !pDownLoadData )) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir SvFileObject* pThis = (SvFileObject*)this; 661cdf0e10cSrcweir if( bDataReady || 662cdf0e10cSrcweir ( bSynchron && pThis->LoadFile_Impl() && xMed.Is() ) ) 663cdf0e10cSrcweir bRet = sal_True; 664cdf0e10cSrcweir else 665cdf0e10cSrcweir { 666cdf0e10cSrcweir INetURLObject aUrl( sFileNm ); 667cdf0e10cSrcweir if( aUrl.HasError() || 668cdf0e10cSrcweir INET_PROT_NOT_VALID == aUrl.GetProtocol() ) 669cdf0e10cSrcweir bRet = sal_True; 670cdf0e10cSrcweir } 671cdf0e10cSrcweir } 672cdf0e10cSrcweir return bRet; 673cdf0e10cSrcweir } 674cdf0e10cSrcweir 675cdf0e10cSrcweir 676cdf0e10cSrcweir 677cdf0e10cSrcweir void SvFileObject::CancelTransfers() 678cdf0e10cSrcweir { 679cdf0e10cSrcweir // und aus dem Cache austragen, wenn man mitten im Laden ist 680cdf0e10cSrcweir if( !bDataReady ) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir // nicht noch mal aufsetzen 683cdf0e10cSrcweir bLoadAgain = sal_False; 684cdf0e10cSrcweir bDataReady = bLoadError = bWaitForData = sal_True; 685cdf0e10cSrcweir SendStateChg_Impl( sfx2::LinkManager::STATE_LOAD_ABORT ); 686cdf0e10cSrcweir } 687cdf0e10cSrcweir } 688cdf0e10cSrcweir 689cdf0e10cSrcweir 690cdf0e10cSrcweir void SvFileObject::SendStateChg_Impl( sfx2::LinkManager::LinkState nState ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir if( !bStateChangeCalled && HasDataLinks() ) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir css::uno::Any aAny; 695cdf0e10cSrcweir aAny <<= rtl::OUString::valueOf( (sal_Int32)nState ); 696cdf0e10cSrcweir DataChanged( SotExchange::GetFormatName( 697cdf0e10cSrcweir sfx2::LinkManager::RegisterStatusInfoId()), aAny ); 698cdf0e10cSrcweir bStateChangeCalled = sal_True; 699cdf0e10cSrcweir } 700cdf0e10cSrcweir } 701cdf0e10cSrcweir 702cdf0e10cSrcweir 703