Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include <vcl/wrkwin.hxx>
22 : : #include <vcl/msgbox.hxx>
23 : : #include <tools/urlobj.hxx>
24 : : #include <tools/stream.hxx>
25 : : #include <sot/formats.hxx>
26 : : #include <svtools/filter.hxx>
27 : : #include <sfx2/lnkbase.hxx>
28 : : #include <sfx2/app.hxx>
29 : : #include <sfx2/progress.hxx>
30 : : #include <sfx2/docfilt.hxx>
31 : : #include <sfx2/filedlghelper.hxx>
32 : : #include <sot/exchange.hxx>
33 : : #include <com/sun/star/uno/Any.hxx>
34 : : #include <com/sun/star/uno/Sequence.hxx>
35 : : #include <sfx2/docfac.hxx>
36 : : #include <com/sun/star/document/XTypeDetection.hpp>
37 : : #include <comphelper/mediadescriptor.hxx>
38 : : #include <comphelper/processfactory.hxx>
39 : : #include <sfx2/linkmgr.hxx>
40 : : #include <sfx2/opengrf.hxx>
41 : : #include "sfx2/sfxresid.hxx"
42 : : #include "fileobj.hxx"
43 : : #include "app.hrc"
44 : :
45 : : namespace css = ::com::sun::star;
46 : :
47 : : #define FILETYPE_TEXT 1
48 : : #define FILETYPE_GRF 2
49 : : #define FILETYPE_OBJECT 3
50 : :
51 : : struct Impl_DownLoadData
52 : : {
53 : : Graphic aGrf;
54 : : Timer aTimer;
55 : :
56 : : Impl_DownLoadData( const Link& rLink )
57 : : {
58 : : aTimer.SetTimeout( 100 );
59 : : aTimer.SetTimeoutHdl( rLink );
60 : : aGrf.SetDefaultType();
61 : : }
62 : 0 : ~Impl_DownLoadData()
63 [ # # ]: 0 : {
64 [ # # ]: 0 : aTimer.Stop();
65 : 0 : }
66 : : };
67 : :
68 : : // --------------------------------------------------------------------------
69 : :
70 : :
71 : 60 : SvFileObject::SvFileObject() :
72 [ + - ][ + - ]: 60 : pDownLoadData( NULL ), pOldParent( NULL ), nType( FILETYPE_TEXT )
[ + - ][ + - ]
73 : : {
74 : 60 : bLoadAgain = sal_True;
75 : : bSynchron = bLoadError = bWaitForData = bDataReady = bNativFormat =
76 : 60 : bClearMedium = bStateChangeCalled = bInCallDownLoad = sal_False;
77 : 60 : }
78 : :
79 : :
80 [ + - ][ + - ]: 54 : SvFileObject::~SvFileObject()
[ + - ][ + - ]
81 : : {
82 [ - + ]: 54 : if ( xMed.Is() )
83 : : {
84 [ # # ][ # # ]: 0 : xMed->SetDoneLink( Link() );
85 [ # # ]: 0 : xMed.Clear();
86 : : }
87 [ - + ][ # # ]: 54 : delete pDownLoadData;
88 [ - + ]: 108 : }
89 : :
90 : :
91 : 88 : sal_Bool SvFileObject::GetData( ::com::sun::star::uno::Any & rData,
92 : : const String & rMimeType,
93 : : sal_Bool bGetSynchron )
94 : : {
95 : 88 : sal_uIntPtr nFmt = SotExchange::GetFormatStringId( rMimeType );
96 [ + + - - ]: 88 : switch( nType )
97 : : {
98 : : case FILETYPE_TEXT:
99 [ + - ]: 44 : if( FORMAT_FILE == nFmt )
100 : : {
101 : : // The media in the application must be opened to lookup the
102 : : // relative file links!! This is done through the link manager
103 : : // of the Storage.
104 [ + - ]: 44 : rData <<= rtl::OUString( sFileNm );
105 : : }
106 : 44 : break;
107 : :
108 : : case FILETYPE_GRF:
109 [ + + ]: 44 : if( !bLoadError )
110 : : {
111 : 28 : SfxMediumRef xTmpMed;
112 : :
113 [ + - ][ + - ]: 28 : if( FORMAT_GDIMETAFILE == nFmt || FORMAT_BITMAP == nFmt ||
[ + - ]
114 : : SOT_FORMATSTR_ID_SVXB == nFmt )
115 : : {
116 [ + - ]: 28 : Graphic aGrf;
117 : :
118 : : // If the native format is reqested, has to be reset at the
119 : : // end of the flag. Is solely in the sw/ndgrf.cxx used when
120 : : // the link is removed form GraphicNode.
121 : 28 : sal_Bool bOldNativFormat = bNativFormat;
122 : :
123 : : // If about to print, waiting for the data to be available
124 [ + + ]: 28 : if( bGetSynchron )
125 : : {
126 : : // call a LoadFile every second time to test the loading
127 [ - + ]: 16 : if( !xMed.Is() )
128 [ # # ]: 0 : LoadFile_Impl();
129 : :
130 [ + - ]: 16 : if( !bInCallDownLoad )
131 : : {
132 [ + - ]: 16 : xTmpMed = xMed;
133 [ + + ]: 20 : while( bWaitForData )
134 [ + - ]: 4 : Application::Reschedule();
135 : :
136 [ + - ]: 16 : xMed = xTmpMed;
137 : 16 : bClearMedium = sal_True;
138 : : }
139 : : }
140 : :
141 [ + - ]: 56 : if( pDownLoadData ||
[ + - + + ]
[ - + ]
[ # # # # ]
[ + + ]
142 : 28 : ( !bWaitForData && ( xMed.Is() || // was loaded as URL
143 [ # # ]: 0 : ( bSynchron && LoadFile_Impl() && xMed.Is() ) )) )
144 : : {
145 : : // If it was loaded from the Internet, do not retry
146 [ - + ]: 16 : if( !bGetSynchron )
147 [ # # ]: 0 : bLoadAgain = !xMed->IsRemote();
148 [ + - ][ + - ]: 16 : bLoadError = !GetGraphic_Impl( aGrf, xMed->GetInStream() );
149 : : }
150 [ + - ][ - + ]: 12 : else if( !LoadFile_Impl() ||
[ # # ][ + - ]
151 [ # # ][ # # ]: 0 : !GetGraphic_Impl( aGrf, xMed.Is() ? xMed->GetInStream() : 0 ))
[ # # ]
152 : : {
153 [ - + ]: 12 : if( !xMed.Is() )
154 : : break;
155 [ + - ]: 12 : aGrf.SetDefaultType();
156 : : }
157 : :
158 [ - + ]: 28 : if( SOT_FORMATSTR_ID_SVXB != nFmt )
159 [ # # ]: 0 : nFmt = (bLoadError || GRAPHIC_BITMAP == aGrf.GetType())
160 : : ? FORMAT_BITMAP
161 [ # # ][ # # ]: 0 : : FORMAT_GDIMETAFILE;
162 : :
163 [ + - ]: 28 : SvMemoryStream aMemStm( 0, 65535 );
164 [ + - - ]: 28 : switch ( nFmt )
165 : : {
166 : : case SOT_FORMATSTR_ID_SVXB:
167 [ + - ][ + + ]: 28 : if( GRAPHIC_NONE != aGrf.GetType() )
168 : : {
169 : 12 : aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
170 [ + - ]: 12 : aMemStm << aGrf;
171 : : }
172 : 28 : break;
173 : :
174 : : case FORMAT_BITMAP:
175 [ # # ][ # # ]: 0 : if( !aGrf.GetBitmap().IsEmpty())
[ # # ]
176 [ # # ][ # # ]: 0 : aMemStm << aGrf.GetBitmap();
[ # # ]
177 : 0 : break;
178 : :
179 : : default:
180 [ # # ][ # # ]: 0 : if( aGrf.GetGDIMetaFile().GetActionSize() )
[ # # ]
181 : : {
182 [ # # ][ # # ]: 0 : GDIMetaFile aMeta( aGrf.GetGDIMetaFile() );
183 [ # # ][ # # ]: 0 : aMeta.Write( aMemStm );
184 : : }
185 : : }
186 [ + - ]: 28 : rData <<= css::uno::Sequence< sal_Int8 >( (sal_Int8*) aMemStm.GetData(),
187 [ + - ][ + - ]: 56 : aMemStm.Seek( STREAM_SEEK_TO_END ) );
[ + - ][ + - ]
188 : :
189 : 28 : bNativFormat = bOldNativFormat;
190 : :
191 : : // Everything ready?
192 [ + - ][ + - ]: 28 : if( xMed.Is() && !bSynchron && bClearMedium )
[ + + ][ + + ]
193 : : {
194 [ + - ]: 16 : xMed.Clear();
195 : 16 : bClearMedium = sal_False;
196 [ + - ][ + - ]: 28 : }
[ + - ]
197 [ + - ][ + - ]: 28 : }
198 : : }
199 : 44 : break;
200 : : case FILETYPE_OBJECT:
201 : : // TODO/LATER: possibility to insert a new object
202 [ # # ]: 0 : rData <<= rtl::OUString( sFileNm );
203 : 0 : break;
204 : : }
205 : 88 : return sal_True/*0 != aTypeList.Count()*/;
206 : : }
207 : :
208 : 60 : sal_Bool SvFileObject::Connect( sfx2::SvBaseLink* pLink )
209 : : {
210 [ + - ][ - + ]: 60 : if( !pLink || !pLink->GetLinkManager() )
[ - + ]
211 : 0 : return sal_False;
212 : :
213 : : // Test if not another link of the same connection already exists
214 : 60 : pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sFileNm, 0, &sFilter );
215 : :
216 [ + + ]: 60 : if( OBJECT_CLIENT_GRF == pLink->GetObjType() )
217 : : {
218 [ + - ]: 12 : SfxObjectShellRef pShell = pLink->GetLinkManager()->GetPersist();
219 [ + - ]: 12 : if( pShell.Is() )
220 : : {
221 [ + - ][ - + ]: 12 : if( pShell->IsAbortingImport() )
222 : 0 : return sal_False;
223 : :
224 [ + - ]: 12 : if( pShell->GetMedium() )
225 [ + - ][ + - ]: 12 : sReferer = pShell->GetMedium()->GetName();
226 [ + - ][ + - ]: 12 : }
227 : : }
228 : :
229 [ + + - - ]: 60 : switch( pLink->GetObjType() )
230 : : {
231 : : case OBJECT_CLIENT_GRF:
232 : 12 : nType = FILETYPE_GRF;
233 : 12 : bSynchron = pLink->IsSynchron();
234 : 12 : break;
235 : :
236 : : case OBJECT_CLIENT_FILE:
237 : 48 : nType = FILETYPE_TEXT;
238 : 48 : break;
239 : :
240 : : case OBJECT_CLIENT_OLE:
241 : 0 : nType = FILETYPE_OBJECT;
242 : : // TODO/LATER: introduce own type to be used for exchanging
243 : 0 : break;
244 : :
245 : : default:
246 : 0 : return sal_False;
247 : : }
248 : :
249 : 60 : SetUpdateTimeout( 0 );
250 : :
251 : : // and now register by this or other found Pseudo-Object
252 [ + - ]: 60 : AddDataAdvise( pLink, SotExchange::GetFormatMimeType( pLink->GetContentType()), 0 );
253 : 60 : return sal_True;
254 : : }
255 : :
256 : 12 : sal_Bool SvFileObject::LoadFile_Impl()
257 : : {
258 : : // We are still at Loading!!
259 [ + - ][ + - ]: 12 : if( bWaitForData || !bLoadAgain || xMed.Is() || pDownLoadData )
[ + - ][ - + ]
[ - + ]
260 : 0 : return sal_False;
261 : :
262 : : // at the moment on the current DocShell
263 [ + - ][ + - ]: 12 : xMed = new SfxMedium( sFileNm, STREAM_STD_READ );
[ + - ]
264 : : SvLinkSource::StreamToLoadFrom aStreamToLoadFrom =
265 [ + - ]: 12 : getStreamToLoadFrom();
266 : : xMed->setStreamToLoadFrom(
267 : : aStreamToLoadFrom.m_xInputStreamToLoadFrom,
268 [ + - ]: 12 : aStreamToLoadFrom.m_bIsReadOnly);
269 : :
270 [ + - ]: 12 : if( !bSynchron )
271 : : {
272 : 12 : bLoadAgain = bDataReady = bInNewData = sal_False;
273 : 12 : bWaitForData = sal_True;
274 : :
275 : 12 : SfxMediumRef xTmpMed = xMed;
276 : 12 : bInCallDownLoad = sal_True;
277 [ + - ][ + - ]: 12 : xMed->DownLoad( STATIC_LINK( this, SvFileObject, LoadGrfReady_Impl ) );
278 : 12 : bInCallDownLoad = sal_False;
279 : :
280 : 12 : bClearMedium = !xMed.Is();
281 [ - + ]: 12 : if( bClearMedium )
282 [ # # ]: 0 : xMed = xTmpMed; // If already finished in DownLoad
283 [ + - ]: 12 : return bDataReady;
284 : : }
285 : :
286 : 0 : bWaitForData = sal_True;
287 : 0 : bDataReady = bInNewData = sal_False;
288 [ # # ][ # # ]: 0 : xMed->DownLoad();
289 [ # # ]: 0 : bLoadAgain = !xMed->IsRemote();
290 : 0 : bWaitForData = sal_False;
291 : :
292 : : // Graphic is finished, also send DataChanged of the Status change:
293 [ # # ][ # # ]: 0 : SendStateChg_Impl( xMed->GetInStream() && xMed->GetInStream()->GetError()
294 [ # # # # ]: 0 : ? sfx2::LinkManager::STATE_LOAD_ERROR : sfx2::LinkManager::STATE_LOAD_OK );
[ # # ]
295 [ + - ]: 12 : return sal_True;
296 : : }
297 : :
298 : :
299 : 16 : sal_Bool SvFileObject::GetGraphic_Impl( Graphic& rGrf, SvStream* pStream )
300 : : {
301 [ + - ]: 16 : GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
302 : :
303 [ + - ]: 20 : const sal_uInt16 nFilter = sFilter.Len() && rGF.GetImportFormatCount()
304 : 4 : ? rGF.GetImportFormatNumber( sFilter )
305 [ + - ][ + - ]: 20 : : GRFILTER_FORMAT_DONTKNOW;
[ + + ]
306 : :
307 [ + - ]: 16 : String aEmptyStr;
308 : : int nRes;
309 : :
310 : : // To avoid that a native link is created
311 [ - + ][ # # ]: 32 : if( ( !pStream || !pDownLoadData ) && !rGrf.IsLink() &&
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
312 [ + - ]: 16 : !rGrf.GetContext() && !bNativFormat )
313 [ + - ][ + - ]: 16 : rGrf.SetLink( GfxLink() );
[ + - ]
314 : :
315 [ + - ]: 16 : if( !pStream )
316 : 16 : nRes = xMed.Is() ? GRFILTER_OPENERROR
317 : : : rGF.ImportGraphic( rGrf, INetURLObject(sFileNm),
318 [ # # ][ # # ]: 16 : nFilter );
[ # # ][ - + ]
[ # # ][ - + ]
[ # # # # ]
[ - + ]
319 [ # # ]: 0 : else if( !pDownLoadData )
320 : : {
321 [ # # ]: 0 : pStream->Seek( STREAM_SEEK_TO_BEGIN );
322 [ # # ]: 0 : nRes = rGF.ImportGraphic( rGrf, aEmptyStr, *pStream, nFilter );
323 : : }
324 : : else
325 : : {
326 : : nRes = rGF.ImportGraphic( pDownLoadData->aGrf, aEmptyStr,
327 [ # # ]: 0 : *pStream, nFilter );
328 : :
329 [ # # ]: 0 : if( pDownLoadData )
330 : : {
331 [ # # ]: 0 : rGrf = pDownLoadData->aGrf;
332 [ # # ][ # # ]: 0 : if( GRAPHIC_NONE == rGrf.GetType() )
333 [ # # ]: 0 : rGrf.SetDefaultType();
334 : :
335 : :
336 [ # # ][ # # ]: 0 : if( !pDownLoadData->aGrf.GetContext() )
337 : : {
338 [ # # ][ # # ]: 0 : delete pDownLoadData, pDownLoadData = 0;
339 : 0 : bDataReady = sal_True;
340 : 0 : bWaitForData = sal_False;
341 : : }
342 : : else if( sal_False )
343 : : {
344 : : // Set up Timer, to return back
345 : : pDownLoadData->aTimer.Start();
346 : : }
347 : : }
348 : : }
349 : :
350 [ - + ][ # # ]: 16 : if( pStream && ERRCODE_IO_PENDING == pStream->GetError() )
[ - + ]
351 [ # # ]: 0 : pStream->ResetError();
352 : :
353 : : #ifdef DBG_UTIL
354 : : if( nRes )
355 : : {
356 : : if( xMed.Is() && !pStream )
357 : : {
358 : : DBG_WARNING3( "Graphic error [%d] - [%s] URL[%s]",
359 : : nRes,
360 : : xMed->GetPhysicalName().getStr(),
361 : : sFileNm.GetBuffer() );
362 : : }
363 : : else
364 : : {
365 : : DBG_WARNING2( "Graphic error [%d] - [%s]",
366 : : nRes, sFileNm.GetBuffer() );
367 : : }
368 : : }
369 : : #endif
370 : :
371 [ + - ]: 16 : return GRFILTER_OK == nRes;
372 : : }
373 : :
374 : : /** detect the filter of the given file
375 : :
376 : : @param _rURL
377 : : specifies the URL of the file which filter is to detected.<br/>
378 : : If the URL doesn't denote a valid (existent and accessible) file, the
379 : : request is silently dropped.
380 : : */
381 : 0 : String impl_getFilter( const String& _rURL )
382 : : {
383 : 0 : String sFilter;
384 [ # # ]: 0 : if ( _rURL.Len() == 0 )
385 : 0 : return sFilter;
386 : :
387 : : try
388 : : {
389 : : css::uno::Reference< ::com::sun::star::document::XTypeDetection > xTypeDetection(
390 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory()->createInstance(
391 : 0 : ::rtl::OUString("com.sun.star.document.TypeDetection") ),
392 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY );
393 [ # # ]: 0 : if ( xTypeDetection.is() )
394 : : {
395 [ # # ]: 0 : ::comphelper::MediaDescriptor aDescr;
396 [ # # ][ # # ]: 0 : aDescr[ ::comphelper::MediaDescriptor::PROP_URL() ] <<= ::rtl::OUString( _rURL );
[ # # ][ # # ]
397 : : css::uno::Sequence< css::beans::PropertyValue > aDescrList =
398 [ # # ]: 0 : aDescr.getAsConstPropertyValueList();
399 [ # # ][ # # ]: 0 : ::rtl::OUString sType = xTypeDetection->queryTypeByDescriptor( aDescrList, sal_True );
400 [ # # ]: 0 : if ( !sType.isEmpty() )
401 : : {
402 : : css::uno::Reference< css::container::XNameAccess > xTypeCont( xTypeDetection,
403 [ # # ]: 0 : css::uno::UNO_QUERY );
404 [ # # ]: 0 : if ( xTypeCont.is() )
405 : : {
406 [ # # ][ # # ]: 0 : ::comphelper::SequenceAsHashMap lTypeProps( xTypeCont->getByName( sType ) );
[ # # ]
407 : : sFilter = lTypeProps.getUnpackedValueOrDefault(
408 [ # # ][ # # ]: 0 : ::rtl::OUString("PreferredFilter"), ::rtl::OUString() );
[ # # ]
409 : 0 : }
410 [ # # ][ # # ]: 0 : }
411 [ # # ]: 0 : }
412 : : }
413 [ # # ]: 0 : catch( const css::uno::Exception& )
414 : : {
415 : : }
416 : :
417 : 0 : return sFilter;
418 : : }
419 : :
420 : 0 : void SvFileObject::Edit( Window* pParent, sfx2::SvBaseLink* pLink, const Link& rEndEditHdl )
421 : : {
422 : 0 : aEndEditLink = rEndEditHdl;
423 [ # # ][ # # ]: 0 : String sFile, sRange, sTmpFilter;
[ # # ]
424 [ # # ][ # # ]: 0 : if( pLink && pLink->GetLinkManager() )
[ # # ][ # # ]
425 : : {
426 [ # # ][ # # ]: 0 : pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sFile, &sRange, &sTmpFilter );
427 : :
428 [ # # # # ]: 0 : switch( pLink->GetObjType() )
429 : : {
430 : : case OBJECT_CLIENT_GRF:
431 : : {
432 : 0 : nType = FILETYPE_GRF; // If not set already
433 : :
434 [ # # ][ # # ]: 0 : SvxOpenGraphicDialog aDlg(SfxResId(RID_SVXSTR_EDITGRFLINK).toString());
[ # # ][ # # ]
[ # # ]
435 [ # # ]: 0 : aDlg.EnableLink(sal_False);
436 [ # # ]: 0 : aDlg.SetPath( sFile, sal_True );
437 [ # # ]: 0 : aDlg.SetCurrentFilter( sTmpFilter );
438 : :
439 [ # # ][ # # ]: 0 : if( !aDlg.Execute() )
440 : : {
441 [ # # ][ # # ]: 0 : sFile = aDlg.GetPath();
[ # # ]
442 [ # # ]: 0 : sFile += ::sfx2::cTokenSeperator;
443 [ # # ]: 0 : sFile += ::sfx2::cTokenSeperator;
444 [ # # ][ # # ]: 0 : sFile += aDlg.GetCurrentFilter();
[ # # ]
445 : :
446 [ # # ][ # # ]: 0 : if ( aEndEditLink.IsSet() )
447 [ # # ]: 0 : aEndEditLink.Call( &sFile );
448 : : }
449 : : else
450 [ # # ][ # # ]: 0 : sFile.Erase();
451 : : }
452 : 0 : break;
453 : :
454 : : case OBJECT_CLIENT_OLE:
455 : : {
456 : 0 : nType = FILETYPE_OBJECT; // if not set already
457 [ # # ]: 0 : pOldParent = Application::GetDefDialogParent();
458 [ # # ]: 0 : Application::SetDefDialogParent( pParent );
459 : :
460 : : ::sfx2::FileDialogHelper & rFileDlg =
461 [ # # ][ # # ]: 0 : pLink->GetInsertFileDialog( String() );
[ # # ]
462 : : rFileDlg.StartExecuteModal(
463 [ # # ][ # # ]: 0 : LINK( this, SvFileObject, DialogClosedHdl ) );
464 : : }
465 : 0 : break;
466 : :
467 : : case OBJECT_CLIENT_FILE:
468 : : {
469 : 0 : nType = FILETYPE_TEXT; // if not set already
470 [ # # ]: 0 : pOldParent = Application::GetDefDialogParent();
471 [ # # ]: 0 : Application::SetDefDialogParent( pParent );
472 : :
473 [ # # ]: 0 : String sFactory;
474 [ # # ]: 0 : SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist();
475 [ # # ]: 0 : if ( pShell )
476 [ # # ][ # # ]: 0 : sFactory = pShell->GetFactory().GetFactoryName();
[ # # ][ # # ]
477 : :
478 : : ::sfx2::FileDialogHelper & rFileDlg =
479 [ # # ]: 0 : pLink->GetInsertFileDialog(sFactory);
480 : : rFileDlg.StartExecuteModal(
481 [ # # ][ # # ]: 0 : LINK( this, SvFileObject, DialogClosedHdl ) );
[ # # ]
482 : : }
483 : 0 : break;
484 : :
485 : : default:
486 [ # # ]: 0 : sFile.Erase();
487 : : }
488 [ # # ][ # # ]: 0 : }
[ # # ]
489 : 0 : }
490 : :
491 : 15 : IMPL_STATIC_LINK( SvFileObject, LoadGrfReady_Impl, void*, EMPTYARG )
492 : : {
493 : : // When we come form here there it can not be an error no more.
494 : 15 : pThis->bLoadError = sal_False;
495 : 15 : pThis->bWaitForData = sal_False;
496 : 15 : pThis->bInCallDownLoad = sal_False;
497 : :
498 [ + - ][ + + ]: 15 : if( !pThis->bInNewData && !pThis->bDataReady )
499 : : {
500 : : // Graphic is finished, also send DataChanged from Status change
501 : 12 : pThis->bDataReady = sal_True;
502 : 12 : pThis->SendStateChg_Impl( sfx2::LinkManager::STATE_LOAD_OK );
503 : :
504 : : // and then send the data again
505 : 12 : pThis->NotifyDataChanged();
506 : : }
507 : :
508 [ + - ]: 15 : if( pThis->bDataReady )
509 : : {
510 : 15 : pThis->bLoadAgain = sal_True;
511 [ - + ]: 15 : if( pThis->xMed.Is() )
512 : : {
513 [ # # ]: 0 : pThis->xMed->SetDoneLink( Link() );
514 : :
515 : : Application::PostUserEvent(
516 : : STATIC_LINK( pThis, SvFileObject, DelMedium_Impl ),
517 [ # # ]: 0 : new SfxMediumRef( pThis->xMed ));
518 : 0 : pThis->xMed.Clear();
519 : : }
520 [ - + ]: 15 : if( pThis->pDownLoadData )
521 [ # # ]: 0 : delete pThis->pDownLoadData, pThis->pDownLoadData = 0;
522 : : }
523 : :
524 : 15 : return 0;
525 : : }
526 : :
527 : 0 : IMPL_STATIC_LINK( SvFileObject, DelMedium_Impl, SfxMediumRef*, pDelMed )
528 : : {
529 : : (void)pThis;
530 [ # # ]: 0 : delete pDelMed;
531 : 0 : return 0;
532 : : }
533 : :
534 : 0 : IMPL_LINK( SvFileObject, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
535 : : {
536 [ # # ]: 0 : String sFile;
537 [ # # ]: 0 : Application::SetDefDialogParent( pOldParent );
538 : :
539 [ # # ][ # # ]: 0 : if ( FILETYPE_TEXT == nType || FILETYPE_OBJECT == nType )
540 : : {
541 [ # # ][ # # ]: 0 : if ( _pFileDlg && _pFileDlg->GetError() == ERRCODE_NONE )
[ # # ]
542 : : {
543 [ # # ]: 0 : String sURL( _pFileDlg->GetPath() );
544 [ # # ]: 0 : sFile = sURL;
545 [ # # ]: 0 : sFile += ::sfx2::cTokenSeperator;
546 [ # # ]: 0 : sFile += ::sfx2::cTokenSeperator;
547 [ # # ][ # # ]: 0 : sFile += impl_getFilter( sURL );
[ # # ][ # # ]
548 : 0 : }
549 : : }
550 : : else
551 : : {
552 : : SAL_WARN( "sfx2.appl", "SvFileObject::DialogClosedHdl(): wrong file type" );
553 : : }
554 : :
555 [ # # ][ # # ]: 0 : if ( aEndEditLink.IsSet() )
556 [ # # ]: 0 : aEndEditLink.Call( &sFile );
557 [ # # ]: 0 : return 0;
558 : : }
559 : :
560 : : /* [Description]
561 : :
562 : : The method determines whether the data-object can be read from a DDE.
563 : :
564 : : The following can be returned:
565 : : ERRCODE_NONE if it has been completely read
566 : : ERRCODE_SO_PENDING if it has not been completely read
567 : : ERRCODE_SO_FALSE otherwise
568 : : */
569 : 28 : sal_Bool SvFileObject::IsPending() const
570 : : {
571 : 28 : return FILETYPE_GRF == nType && !bLoadError &&
572 [ + - ][ + + ]: 28 : ( pDownLoadData || bWaitForData );
[ + - ][ + - ]
573 : : }
574 : 62 : sal_Bool SvFileObject::IsDataComplete() const
575 : : {
576 : 62 : sal_Bool bRet = sal_False;
577 [ - + ]: 62 : if( FILETYPE_GRF != nType )
578 : 0 : bRet = sal_True;
579 [ + + ][ - + ]: 62 : else if( !bLoadError && ( !bWaitForData && !pDownLoadData ))
[ # # ]
580 : : {
581 : 0 : SvFileObject* pThis = (SvFileObject*)this;
582 [ # # ][ # # : 0 : if( bDataReady ||
# # # # ]
[ # # ]
583 : 0 : ( bSynchron && pThis->LoadFile_Impl() && xMed.Is() ) )
584 : 0 : bRet = sal_True;
585 : : else
586 : : {
587 [ # # ][ # # ]: 0 : INetURLObject aUrl( sFileNm );
588 [ # # ]: 0 : if( aUrl.HasError() ||
[ # # # # ]
589 : 0 : INET_PROT_NOT_VALID == aUrl.GetProtocol() )
590 [ # # ]: 0 : bRet = sal_True;
591 : : }
592 : : }
593 : 62 : return bRet;
594 : : }
595 : :
596 : :
597 : :
598 : 8 : void SvFileObject::CancelTransfers()
599 : : {
600 : : // unsubscribe from the cache if in the middle of loading
601 [ + + ]: 8 : if( !bDataReady )
602 : : {
603 : : // Do not set-up again
604 : 2 : bLoadAgain = sal_False;
605 : 2 : bDataReady = bLoadError = bWaitForData = sal_True;
606 : 2 : SendStateChg_Impl( sfx2::LinkManager::STATE_LOAD_ABORT );
607 : : }
608 : 8 : }
609 : :
610 : :
611 : 14 : void SvFileObject::SendStateChg_Impl( sfx2::LinkManager::LinkState nState )
612 : : {
613 [ + - ][ + - ]: 14 : if( !bStateChangeCalled && HasDataLinks() )
[ + - ]
614 : : {
615 : 14 : css::uno::Any aAny;
616 [ + - ]: 14 : aAny <<= rtl::OUString::valueOf( (sal_Int32)nState );
617 : : DataChanged( SotExchange::GetFormatName(
618 [ + - ][ + - ]: 14 : sfx2::LinkManager::RegisterStatusInfoId()), aAny );
[ + - ][ + - ]
619 : 14 : bStateChangeCalled = sal_True;
620 : : }
621 : 14 : }
622 : :
623 : :
624 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|