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