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 : #include <sfx2/sfxsids.hrc>
21 : #include <sfx2/app.hxx>
22 : #include <svl/itemset.hxx>
23 : #include <svl/stritem.hxx>
24 : #include <sfx2/docfile.hxx>
25 : #include <sfx2/docfilt.hxx>
26 : #include <sfx2/fcontnr.hxx>
27 : #include <sfx2/linkmgr.hxx>
28 : #include <tools/urlobj.hxx>
29 : #include <unotools/transliterationwrapper.hxx>
30 :
31 : #include "tablink.hxx"
32 :
33 : #include "scextopt.hxx"
34 : #include "table.hxx"
35 : #include "document.hxx"
36 : #include "docsh.hxx"
37 : #include "globstr.hrc"
38 : #include "undoblk.hxx"
39 : #include "undotab.hxx"
40 : #include "global.hxx"
41 : #include "hints.hxx"
42 : #include "dociter.hxx"
43 : #include "formula/opcode.hxx"
44 : #include "formulacell.hxx"
45 : #include "formulaiter.hxx"
46 : #include "tokenarray.hxx"
47 :
48 : struct TableLink_Impl
49 : {
50 : ScDocShell* m_pDocSh;
51 : Window* m_pOldParent;
52 : Link m_aEndEditLink;
53 :
54 2 : TableLink_Impl() : m_pDocSh( NULL ), m_pOldParent( NULL ) {}
55 : };
56 :
57 26 : TYPEINIT1(ScTableLink, ::sfx2::SvBaseLink);
58 :
59 : //------------------------------------------------------------------------
60 :
61 2 : ScTableLink::ScTableLink(ScDocShell* pDocSh, const String& rFile,
62 : const String& rFilter, const String& rOpt,
63 : sal_uLong nRefresh ):
64 : ::sfx2::SvBaseLink(sfx2::LINKUPDATE_ONCALL,FORMAT_FILE),
65 : ScRefreshTimer( nRefresh ),
66 2 : pImpl( new TableLink_Impl ),
67 : aFileName(rFile),
68 : aFilterName(rFilter),
69 : aOptions(rOpt),
70 : bInCreate( false ),
71 : bInEdit( false ),
72 : bAddUndo( true ),
73 4 : bDoPaint( true )
74 : {
75 2 : pImpl->m_pDocSh = pDocSh;
76 2 : }
77 :
78 0 : ScTableLink::ScTableLink(SfxObjectShell* pShell, const String& rFile,
79 : const String& rFilter, const String& rOpt,
80 : sal_uLong nRefresh ):
81 : ::sfx2::SvBaseLink(sfx2::LINKUPDATE_ONCALL,FORMAT_FILE),
82 : ScRefreshTimer( nRefresh ),
83 0 : pImpl( new TableLink_Impl ),
84 : aFileName(rFile),
85 : aFilterName(rFilter),
86 : aOptions(rOpt),
87 : bInCreate( false ),
88 : bInEdit( false ),
89 : bAddUndo( true ),
90 0 : bDoPaint( true )
91 : {
92 0 : pImpl->m_pDocSh = static_cast< ScDocShell* >( pShell );
93 0 : SetRefreshHandler( LINK( this, ScTableLink, RefreshHdl ) );
94 0 : SetRefreshControl( pImpl->m_pDocSh->GetDocument()->GetRefreshTimerControlAddress() );
95 0 : }
96 :
97 6 : ScTableLink::~ScTableLink()
98 : {
99 : // Verbindung aufheben
100 :
101 2 : StopRefreshTimer();
102 2 : String aEmpty;
103 2 : ScDocument* pDoc = pImpl->m_pDocSh->GetDocument();
104 2 : SCTAB nCount = pDoc->GetTableCount();
105 4 : for (SCTAB nTab=0; nTab<nCount; nTab++)
106 2 : if (pDoc->IsLinked(nTab) && aFileName.equals(pDoc->GetLinkDoc(nTab)))
107 2 : pDoc->SetLink( nTab, SC_LINK_NONE, aEmpty, aEmpty, aEmpty, aEmpty, 0 );
108 2 : delete pImpl;
109 4 : }
110 :
111 0 : void ScTableLink::Edit( Window* pParent, const Link& rEndEditHdl )
112 : {
113 : // DefModalDialogParent setzen, weil evtl. aus der DocShell beim ConvertFrom
114 : // ein Optionen-Dialog kommt...
115 :
116 0 : pImpl->m_aEndEditLink = rEndEditHdl;
117 0 : pImpl->m_pOldParent = Application::GetDefDialogParent();
118 0 : if (pParent)
119 0 : Application::SetDefDialogParent(pParent);
120 :
121 0 : bInEdit = true;
122 0 : SvBaseLink::Edit( pParent, LINK( this, ScTableLink, TableEndEditHdl ) );
123 0 : }
124 :
125 4 : ::sfx2::SvBaseLink::UpdateResult ScTableLink::DataChanged(
126 : const String&, const ::com::sun::star::uno::Any& )
127 : {
128 4 : sfx2::LinkManager* pLinkManager=pImpl->m_pDocSh->GetDocument()->GetLinkManager();
129 4 : if (pLinkManager!=NULL)
130 : {
131 8 : OUString aFile, aFilter;
132 4 : pLinkManager->GetDisplayNames(this, 0, &aFile, NULL, &aFilter);
133 :
134 : // the file dialog returns the filter name with the application prefix
135 : // -> remove prefix
136 4 : ScDocumentLoader::RemoveAppPrefix( aFilter );
137 :
138 4 : if (!bInCreate)
139 6 : Refresh( aFile, aFilter, NULL, GetRefreshDelay() ); // don't load twice
140 : }
141 4 : return SUCCESS;
142 : }
143 :
144 0 : void ScTableLink::Closed()
145 : {
146 : // Verknuepfung loeschen: Undo
147 0 : ScDocument* pDoc = pImpl->m_pDocSh->GetDocument();
148 0 : sal_Bool bUndo (pDoc->IsUndoEnabled());
149 :
150 0 : if (bAddUndo && bUndo)
151 : {
152 0 : pImpl->m_pDocSh->GetUndoManager()->AddUndoAction(
153 0 : new ScUndoRemoveLink( pImpl->m_pDocSh, aFileName ) );
154 :
155 0 : bAddUndo = false; // nur einmal
156 : }
157 :
158 : // Verbindung wird im dtor aufgehoben
159 :
160 0 : SvBaseLink::Closed();
161 0 : }
162 :
163 0 : sal_Bool ScTableLink::IsUsed() const
164 : {
165 0 : return pImpl->m_pDocSh->GetDocument()->HasLink( aFileName, aFilterName, aOptions );
166 : }
167 :
168 2 : sal_Bool ScTableLink::Refresh(const String& rNewFile, const String& rNewFilter,
169 : const String* pNewOptions, sal_uLong nNewRefresh )
170 : {
171 : // Dokument laden
172 :
173 2 : if (!rNewFile.Len() || !rNewFilter.Len())
174 0 : return false;
175 :
176 2 : OUString aNewUrl = ScGlobal::GetAbsDocName(rNewFile, pImpl->m_pDocSh);
177 2 : bool bNewUrlName = !aFileName.equals(aNewUrl);
178 :
179 2 : const SfxFilter* pFilter = pImpl->m_pDocSh->GetFactory().GetFilterContainer()->GetFilter4FilterName(rNewFilter);
180 2 : if (!pFilter)
181 0 : return false;
182 :
183 2 : ScDocument* pDoc = pImpl->m_pDocSh->GetDocument();
184 2 : pDoc->SetInLinkUpdate( true );
185 :
186 2 : sal_Bool bUndo(pDoc->IsUndoEnabled());
187 :
188 : // wenn neuer Filter ausgewaehlt wurde, Optionen vergessen
189 2 : if (!aFilterName.equals(rNewFilter))
190 0 : aOptions = OUString();
191 2 : if ( pNewOptions ) // Optionen hart angegeben?
192 0 : aOptions = *pNewOptions;
193 :
194 : // ItemSet immer anlegen, damit die DocShell die Optionen setzen kann
195 2 : SfxItemSet* pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
196 2 : if (!aOptions.isEmpty())
197 0 : pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
198 :
199 2 : SfxMedium* pMed = new SfxMedium(aNewUrl, STREAM_STD_READ, pFilter, pSet);
200 :
201 2 : if ( bInEdit ) // only if using the edit dialog,
202 0 : pMed->UseInteractionHandler(true); // enable the filter options dialog
203 :
204 : // aRef->DoClose() will be called explicitly, but it is still more safe to use SfxObjectShellLock here
205 2 : ScDocShell* pSrcShell = new ScDocShell(SFX_CREATE_MODE_INTERNAL);
206 4 : SfxObjectShellLock aRef = pSrcShell;
207 2 : pSrcShell->DoLoad(pMed);
208 :
209 : // Optionen koennten gesetzt worden sein
210 4 : String aNewOpt = ScDocumentLoader::GetOptions(*pMed);
211 2 : if (!aNewOpt.Len())
212 2 : aNewOpt = aOptions;
213 :
214 : // Undo...
215 :
216 2 : ScDocument* pUndoDoc = NULL;
217 2 : sal_Bool bFirst = true;
218 2 : if (bAddUndo && bUndo)
219 2 : pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
220 :
221 : // Tabellen kopieren
222 :
223 4 : ScDocShellModificator aModificator( *pImpl->m_pDocSh );
224 :
225 2 : sal_Bool bNotFound = false;
226 2 : ScDocument* pSrcDoc = pSrcShell->GetDocument();
227 :
228 : // from text filters that don't set the table name,
229 : // use the one table regardless of link table name
230 2 : sal_Bool bAutoTab = (pSrcDoc->GetTableCount() == 1) &&
231 2 : ScDocShell::HasAutomaticTableName( rNewFilter );
232 :
233 2 : SCTAB nCount = pDoc->GetTableCount();
234 4 : for (SCTAB nTab=0; nTab<nCount; nTab++)
235 : {
236 2 : sal_uInt8 nMode = pDoc->GetLinkMode(nTab);
237 2 : if (nMode && aFileName.equals(pDoc->GetLinkDoc(nTab)))
238 : {
239 2 : String aTabName = pDoc->GetLinkTab(nTab);
240 :
241 : // Undo
242 :
243 2 : if (bAddUndo && bUndo)
244 : {
245 2 : if (bFirst)
246 2 : pUndoDoc->InitUndo( pDoc, nTab, nTab, true, true );
247 : else
248 0 : pUndoDoc->AddUndoTab( nTab, nTab, true, true );
249 2 : bFirst = false;
250 2 : ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
251 2 : pDoc->CopyToDocument(aRange, IDF_ALL, false, pUndoDoc);
252 2 : pUndoDoc->TransferDrawPage( pDoc, nTab, nTab );
253 : pUndoDoc->SetLink( nTab, nMode, aFileName, aFilterName,
254 2 : aOptions, aTabName, GetRefreshDelay() );
255 2 : pUndoDoc->SetTabBgColor( nTab, pDoc->GetTabBgColor(nTab) );
256 : }
257 :
258 : // Tabellenname einer ExtDocRef anpassen
259 :
260 2 : if ( bNewUrlName && nMode == SC_LINK_VALUE )
261 : {
262 0 : OUString aName;
263 0 : pDoc->GetName( nTab, aName );
264 0 : if ( ScGlobal::GetpTransliteration()->isEqual(
265 0 : ScGlobal::GetDocTabName( aFileName, aTabName ), aName ) )
266 : {
267 : pDoc->RenameTab( nTab,
268 : ScGlobal::GetDocTabName( aNewUrl, aTabName ),
269 0 : false, true ); // kein RefUpdate, kein ValidTabName
270 0 : }
271 : }
272 :
273 : // kopieren
274 :
275 2 : SCTAB nSrcTab = 0;
276 2 : bool bFound = false;
277 : /* #i71497# check if external document is loaded successfully,
278 : otherwise we may find the empty default sheet "Sheet1" in
279 : pSrcDoc, even if the document does not exist. */
280 2 : if( pMed->GetError() == 0 )
281 : {
282 : // no sheet name -> use first sheet
283 2 : if ( aTabName.Len() && !bAutoTab )
284 2 : bFound = pSrcDoc->GetTable( aTabName, nSrcTab );
285 : else
286 0 : bFound = true;
287 : }
288 :
289 2 : if (bFound)
290 : pDoc->TransferTab( pSrcDoc, nSrcTab, nTab, false, // nicht neu einfuegen
291 2 : (nMode == SC_LINK_VALUE) ); // nur Werte?
292 : else
293 : {
294 0 : pDoc->DeleteAreaTab( 0,0,MAXCOL,MAXROW, nTab, IDF_ALL );
295 :
296 0 : bool bShowError = true;
297 0 : if ( nMode == SC_LINK_VALUE )
298 : {
299 : // Value link (used with external references in formulas):
300 : // Look for formulas that reference the sheet, and put errors in the referenced cells.
301 :
302 0 : ScRangeList aErrorCells; // cells on the linked sheets that need error values
303 :
304 0 : ScCellIterator aIter(pDoc, ScRange(0,0,0,MAXCOL,MAXROW,MAXTAB)); // all sheets
305 0 : for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
306 : {
307 0 : if (aIter.getType() != CELLTYPE_FORMULA)
308 0 : continue;
309 :
310 0 : ScFormulaCell* pCell = aIter.getFormulaCell();
311 0 : ScDetectiveRefIter aRefIter(pCell);
312 0 : ScRange aRefRange;
313 0 : while ( aRefIter.GetNextRef( aRefRange ) )
314 : {
315 0 : if ( aRefRange.aStart.Tab() <= nTab && aRefRange.aEnd.Tab() >= nTab )
316 : {
317 : // use first cell of range references (don't fill potentially large ranges)
318 :
319 0 : aErrorCells.Join( ScRange( aRefRange.aStart ) );
320 : }
321 : }
322 : }
323 :
324 0 : size_t nRanges = aErrorCells.size();
325 0 : if ( nRanges ) // found any?
326 : {
327 0 : ScTokenArray aTokenArr;
328 0 : aTokenArr.AddOpCode( ocNotAvail );
329 0 : aTokenArr.AddOpCode( ocOpen );
330 0 : aTokenArr.AddOpCode( ocClose );
331 0 : aTokenArr.AddOpCode( ocStop );
332 :
333 0 : for (size_t nPos=0; nPos < nRanges; nPos++)
334 : {
335 0 : const ScRange* pRange = aErrorCells[ nPos ];
336 0 : SCCOL nStartCol = pRange->aStart.Col();
337 0 : SCROW nStartRow = pRange->aStart.Row();
338 0 : SCCOL nEndCol = pRange->aEnd.Col();
339 0 : SCROW nEndRow = pRange->aEnd.Row();
340 0 : for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
341 0 : for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
342 : {
343 0 : ScAddress aDestPos( nCol, nRow, nTab );
344 0 : pDoc->SetFormula(aDestPos, aTokenArr);
345 : }
346 : }
347 :
348 0 : bShowError = false;
349 0 : }
350 : // if no references were found, insert error message (don't leave the sheet empty)
351 : }
352 :
353 0 : if ( bShowError )
354 : {
355 : // Normal link or no references: put error message on sheet.
356 :
357 0 : pDoc->SetString( 0,0,nTab, ScGlobal::GetRscString(STR_LINKERROR) );
358 0 : pDoc->SetString( 0,1,nTab, ScGlobal::GetRscString(STR_LINKERRORFILE) );
359 0 : pDoc->SetString( 1,1,nTab, aNewUrl );
360 0 : pDoc->SetString( 0,2,nTab, ScGlobal::GetRscString(STR_LINKERRORTAB) );
361 0 : pDoc->SetString( 1,2,nTab, aTabName );
362 : }
363 :
364 0 : bNotFound = true;
365 : }
366 :
367 10 : if ( bNewUrlName || !aFilterName.equals(rNewFilter) ||
368 12 : !aOptions.equals(aNewOpt) || pNewOptions ||
369 2 : nNewRefresh != GetRefreshDelay() )
370 : pDoc->SetLink( nTab, nMode, aNewUrl, rNewFilter, aNewOpt,
371 0 : aTabName, nNewRefresh );
372 : }
373 : }
374 :
375 : // neue Einstellungen merken
376 :
377 2 : if ( bNewUrlName )
378 0 : aFileName = aNewUrl;
379 2 : if (!aFilterName.equals(rNewFilter))
380 0 : aFilterName = rNewFilter;
381 2 : if (!aOptions.equals(aNewOpt))
382 0 : aOptions = aNewOpt;
383 :
384 : // aufraeumen
385 :
386 2 : aRef->DoClose();
387 :
388 : // Undo
389 :
390 2 : if (bAddUndo && bUndo)
391 2 : pImpl->m_pDocSh->GetUndoManager()->AddUndoAction(
392 2 : new ScUndoRefreshLink( pImpl->m_pDocSh, pUndoDoc ) );
393 :
394 : // Paint (koennen mehrere Tabellen sein)
395 :
396 2 : if (bDoPaint)
397 : {
398 : pImpl->m_pDocSh->PostPaint( ScRange(0,0,0,MAXCOL,MAXROW,MAXTAB),
399 2 : PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
400 2 : aModificator.SetDocumentModified();
401 : }
402 :
403 : if (bNotFound)
404 : {
405 : //! Fehler ausgeben ?
406 : }
407 :
408 2 : pDoc->SetInLinkUpdate( false );
409 :
410 : // notify Uno objects (for XRefreshListener)
411 : //! also notify Uno objects if file name was changed!
412 4 : ScLinkRefreshedHint aHint;
413 2 : aHint.SetSheetLink( aFileName );
414 2 : pDoc->BroadcastUno( aHint );
415 :
416 4 : return true;
417 : }
418 :
419 0 : IMPL_LINK_NOARG(ScTableLink, RefreshHdl)
420 : {
421 0 : long nRes = Refresh( aFileName, aFilterName, NULL, GetRefreshDelay() ) != 0;
422 0 : return nRes;
423 : }
424 :
425 0 : IMPL_LINK( ScTableLink, TableEndEditHdl, ::sfx2::SvBaseLink*, pLink )
426 : {
427 0 : if ( pImpl->m_aEndEditLink.IsSet() )
428 0 : pImpl->m_aEndEditLink.Call( pLink );
429 0 : bInEdit = false;
430 0 : Application::SetDefDialogParent( pImpl->m_pOldParent );
431 0 : return 0;
432 : }
433 :
434 : // === ScDocumentLoader ==================================================
435 :
436 6 : OUString ScDocumentLoader::GetOptions( SfxMedium& rMedium )
437 : {
438 6 : SfxItemSet* pSet = rMedium.GetItemSet();
439 : const SfxPoolItem* pItem;
440 6 : if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
441 0 : return ((const SfxStringItem*)pItem)->GetValue();
442 :
443 6 : return EMPTY_STRING;
444 : }
445 :
446 7 : bool ScDocumentLoader::GetFilterName( const String& rFileName,
447 : String& rFilter, String& rOptions,
448 : bool bWithContent, bool bWithInteraction )
449 : {
450 7 : TypeId aScType = TYPE(ScDocShell);
451 7 : SfxObjectShell* pDocSh = SfxObjectShell::GetFirst( &aScType );
452 19 : while ( pDocSh )
453 : {
454 5 : if ( pDocSh->HasName() )
455 : {
456 0 : SfxMedium* pMed = pDocSh->GetMedium();
457 0 : if ( pMed->GetName().equals(rFileName) )
458 : {
459 0 : rFilter = pMed->GetFilter()->GetFilterName();
460 0 : rOptions = GetOptions(*pMed);
461 0 : return true;
462 : }
463 : }
464 5 : pDocSh = SfxObjectShell::GetNext( *pDocSh, &aScType );
465 : }
466 :
467 7 : INetURLObject aUrl( rFileName );
468 7 : INetProtocol eProt = aUrl.GetProtocol();
469 7 : if ( eProt == INET_PROT_NOT_VALID ) // invalid URL?
470 0 : return false; // abort without creating a medium
471 :
472 : // Filter-Detection
473 :
474 7 : const SfxFilter* pSfxFilter = NULL;
475 7 : SfxMedium* pMedium = new SfxMedium( rFileName, STREAM_STD_READ );
476 7 : if ( pMedium->GetError() == ERRCODE_NONE )
477 : {
478 7 : if ( bWithInteraction )
479 0 : pMedium->UseInteractionHandler(true); // #i73992# no longer called from GuessFilter
480 :
481 7 : SfxFilterMatcher aMatcher("scalc");
482 7 : if( bWithContent )
483 7 : aMatcher.GuessFilter( *pMedium, &pSfxFilter );
484 : else
485 0 : aMatcher.GuessFilterIgnoringContent( *pMedium, &pSfxFilter );
486 : }
487 :
488 7 : sal_Bool bOK = false;
489 7 : if ( pMedium->GetError() == ERRCODE_NONE )
490 : {
491 7 : if ( pSfxFilter )
492 5 : rFilter = pSfxFilter->GetFilterName();
493 : else
494 2 : rFilter = ScDocShell::GetOwnFilterName(); // sonst Calc-Datei
495 7 : bOK = (rFilter.Len()>0);
496 : }
497 :
498 7 : delete pMedium;
499 7 : return bOK;
500 : }
501 :
502 7 : bool ScDocumentLoader::GetFilterName(
503 : const OUString& rFilterName, OUString& rFilter, OUString& rOptions,
504 : bool bWithContent, bool bWithInteraction)
505 : {
506 14 : String aTmp1, aTmp2;
507 7 : bool bRet = GetFilterName(rFilterName, aTmp1, aTmp2, bWithContent, bWithInteraction);
508 7 : rFilter = aTmp1;
509 7 : rOptions = aTmp2;
510 14 : return bRet;
511 : }
512 :
513 38 : void ScDocumentLoader::RemoveAppPrefix( OUString& rFilterName )
514 : {
515 38 : OUStringBuffer aAppPrefix;
516 38 : aAppPrefix.appendAscii(STRING_SCAPP);
517 38 : aAppPrefix.appendAscii(": ");
518 38 : sal_Int32 nPreLen = aAppPrefix.getLength();
519 38 : if (rFilterName.copy(0, nPreLen).equals(aAppPrefix.makeStringAndClear()))
520 0 : rFilterName = rFilterName.copy(nPreLen);
521 38 : }
522 :
523 0 : ScDocumentLoader::ScDocumentLoader( const OUString& rFileName,
524 : OUString& rFilterName, OUString& rOptions,
525 : sal_uInt32 nRekCnt, bool bWithInteraction ) :
526 : pDocShell(0),
527 0 : pMedium(0)
528 : {
529 0 : if ( rFilterName.isEmpty() )
530 0 : GetFilterName( rFileName, rFilterName, rOptions, true, bWithInteraction );
531 :
532 0 : const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( rFilterName );
533 :
534 : // ItemSet immer anlegen, damit die DocShell die Optionen setzen kann
535 0 : SfxItemSet* pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
536 0 : if ( !rOptions.isEmpty() )
537 0 : pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, rOptions ) );
538 :
539 0 : pMedium = new SfxMedium( rFileName, STREAM_STD_READ, pFilter, pSet );
540 0 : if ( pMedium->GetError() != ERRCODE_NONE )
541 0 : return ;
542 :
543 0 : if ( bWithInteraction )
544 0 : pMedium->UseInteractionHandler( true ); // to enable the filter options dialog
545 :
546 0 : pDocShell = new ScDocShell( SFX_CREATE_MODE_INTERNAL );
547 0 : aRef = pDocShell;
548 :
549 0 : ScDocument* pDoc = pDocShell->GetDocument();
550 0 : if( pDoc )
551 : {
552 0 : ScExtDocOptions* pExtDocOpt = pDoc->GetExtDocOptions();
553 0 : if( !pExtDocOpt )
554 : {
555 0 : pExtDocOpt = new ScExtDocOptions;
556 0 : pDoc->SetExtDocOptions( pExtDocOpt );
557 : }
558 0 : pExtDocOpt->GetDocSettings().mnLinkCnt = nRekCnt;
559 : }
560 :
561 0 : pDocShell->DoLoad( pMedium );
562 :
563 0 : OUString aNew = GetOptions(*pMedium); // Optionen werden beim Laden per Dialog gesetzt
564 0 : if (!aNew.isEmpty() && aNew != rOptions)
565 0 : rOptions = aNew;
566 : }
567 :
568 0 : ScDocumentLoader::~ScDocumentLoader()
569 : {
570 0 : if ( aRef.Is() )
571 0 : aRef->DoClose();
572 0 : else if ( pMedium )
573 0 : delete pMedium;
574 0 : }
575 :
576 0 : void ScDocumentLoader::ReleaseDocRef()
577 : {
578 0 : if ( aRef.Is() )
579 : {
580 : // release reference without calling DoClose - caller must
581 : // have another reference to the doc and call DoClose later
582 :
583 0 : pDocShell = NULL;
584 0 : pMedium = NULL;
585 0 : aRef.Clear();
586 : }
587 0 : }
588 :
589 0 : ScDocument* ScDocumentLoader::GetDocument()
590 : {
591 0 : return pDocShell ? pDocShell->GetDocument() : 0;
592 : }
593 :
594 0 : bool ScDocumentLoader::IsError() const
595 : {
596 0 : if ( pDocShell && pMedium )
597 0 : return pMedium->GetError() != ERRCODE_NONE;
598 : else
599 0 : return true;
600 : }
601 :
602 0 : OUString ScDocumentLoader::GetTitle() const
603 : {
604 0 : if ( pDocShell )
605 0 : return pDocShell->GetTitle();
606 : else
607 0 : return EMPTY_STRING;
608 93 : }
609 :
610 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|