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