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 : : #include "scitems.hxx"
30 : : #include <editeng/justifyitem.hxx>
31 : : #include <sot/clsids.hxx>
32 : : #include <vcl/msgbox.hxx>
33 : : #include <vcl/virdev.hxx>
34 : : #include <vcl/waitobj.hxx>
35 : : #include <svl/PasswordHelper.hxx>
36 : : #include <sfx2/app.hxx>
37 : : #include <sfx2/bindings.hxx>
38 : : #include <sfx2/dinfdlg.hxx>
39 : : #include <sfx2/docfile.hxx>
40 : : #include <sfx2/fcontnr.hxx>
41 : : #include <sfx2/objface.hxx>
42 : : #include <svl/documentlockfile.hxx>
43 : : #include <svl/sharecontrolfile.hxx>
44 : : #include "chgtrack.hxx"
45 : : #include "chgviset.hxx"
46 : : #include <com/sun/star/awt/Key.hpp>
47 : : #include <com/sun/star/awt/KeyModifier.hpp>
48 : : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
49 : : #include <com/sun/star/document/UpdateDocMode.hpp>
50 : : #include <com/sun/star/script/vba/VBAEventId.hpp>
51 : : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
52 : : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
53 : : #include <com/sun/star/task/XJob.hpp>
54 : : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
55 : : #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
56 : :
57 : : #include "scabstdlg.hxx"
58 : : #include <sot/formats.hxx>
59 : :
60 : : #include "cell.hxx"
61 : : #include "column.hxx"
62 : : #include "postit.hxx"
63 : : #include "global.hxx"
64 : : #include "filter.hxx"
65 : : #include "scmod.hxx"
66 : : #include "tabvwsh.hxx"
67 : : #include "docfunc.hxx"
68 : : #include "imoptdlg.hxx"
69 : : #include "impex.hxx"
70 : : #include "scresid.hxx"
71 : : #include "sc.hrc"
72 : : #include "globstr.hrc"
73 : : #include "scerrors.hxx"
74 : : #include "brdcst.hxx"
75 : : #include "stlpool.hxx"
76 : : #include "autostyl.hxx"
77 : : #include "attrib.hxx"
78 : : #include "asciiopt.hxx"
79 : : #include "waitoff.hxx"
80 : : #include "docpool.hxx" // LoadCompleted
81 : : #include "progress.hxx"
82 : : #include "pntlock.hxx"
83 : : #include "docuno.hxx"
84 : : #include "appoptio.hxx"
85 : : #include "detdata.hxx"
86 : : #include "printfun.hxx"
87 : : #include "dociter.hxx"
88 : : #include "cellform.hxx"
89 : : #include "chartlis.hxx"
90 : : #include "hints.hxx"
91 : : #include "xmlwrap.hxx"
92 : : #include "drwlayer.hxx"
93 : : #include "refreshtimer.hxx"
94 : : #include "dbdata.hxx"
95 : : #include "scextopt.hxx"
96 : : #include "compiler.hxx"
97 : : #include "cfgids.hxx"
98 : : #include "warnpassword.hxx"
99 : : #include "optsolver.hxx"
100 : : #include "sheetdata.hxx"
101 : : #include "tabprotection.hxx"
102 : : #include "docparam.hxx"
103 : :
104 : : #include "docsh.hxx"
105 : : #include "docshimp.hxx"
106 : : #include "sizedev.hxx"
107 : : #include <rtl/logfile.hxx>
108 : :
109 : : #include <comphelper/processfactory.hxx>
110 : : #include <comphelper/string.hxx>
111 : : #include "uiitems.hxx"
112 : : #include "cellsuno.hxx"
113 : : #include "dpobject.hxx"
114 : : #include "markdata.hxx"
115 : : #ifdef ENABLE_TELEPATHY
116 : : #include "sccollaboration.hxx"
117 : : #endif
118 : :
119 : : #include <vector>
120 : : #include <boost/shared_ptr.hpp>
121 : :
122 : : #define SC_LIBO_PROD_NAME "LibreOffice"
123 : :
124 : : using namespace com::sun::star;
125 : : using ::com::sun::star::uno::Reference;
126 : : using ::com::sun::star::uno::UNO_QUERY;
127 : : using ::com::sun::star::lang::XMultiServiceFactory;
128 : : using ::rtl::OUString;
129 : : using ::rtl::OUStringBuffer;
130 : : using ::boost::shared_ptr;
131 : : using ::std::vector;
132 : :
133 : : // STATIC DATA -----------------------------------------------------------
134 : :
135 : : // Stream-Namen im Storage
136 : :
137 : : const sal_Char ScDocShell::pStarCalcDoc[] = STRING_SCSTREAM; // "StarCalcDocument"
138 : : const sal_Char ScDocShell::pStyleName[] = "SfxStyleSheets";
139 : :
140 : : // Filter-Namen (wie in sclib.cxx)
141 : :
142 : : static const sal_Char pFilterSc50[] = "StarCalc 5.0";
143 : : static const sal_Char pFilterSc40[] = "StarCalc 4.0";
144 : : static const sal_Char pFilterSc30[] = "StarCalc 3.0";
145 : : static const sal_Char pFilterSc10[] = "StarCalc 1.0";
146 : : static const sal_Char pFilterXML[] = "StarOffice XML (Calc)";
147 : : static const sal_Char pFilterAscii[] = "Text - txt - csv (StarCalc)";
148 : : static const sal_Char pFilterLotus[] = "Lotus";
149 : : static const sal_Char pFilterQPro6[] = "Quattro Pro 6.0";
150 : : static const sal_Char pFilterExcel4[] = "MS Excel 4.0";
151 : : static const sal_Char pFilterEx4Temp[] = "MS Excel 4.0 Vorlage/Template";
152 : : static const sal_Char pFilterExcel5[] = "MS Excel 5.0/95";
153 : : static const sal_Char pFilterEx5Temp[] = "MS Excel 5.0/95 Vorlage/Template";
154 : : static const sal_Char pFilterExcel95[] = "MS Excel 95";
155 : : static const sal_Char pFilterEx95Temp[] = "MS Excel 95 Vorlage/Template";
156 : : static const sal_Char pFilterExcel97[] = "MS Excel 97";
157 : : static const sal_Char pFilterEx97Temp[] = "MS Excel 97 Vorlage/Template";
158 : : static const sal_Char pFilterDBase[] = "dBase";
159 : : static const sal_Char pFilterDif[] = "DIF";
160 : : static const sal_Char pFilterSylk[] = "SYLK";
161 : : static const sal_Char pFilterHtml[] = "HTML (StarCalc)";
162 : : static const sal_Char pFilterHtmlWebQ[] = "calc_HTML_WebQuery";
163 : : static const sal_Char pFilterRtf[] = "Rich Text Format (StarCalc)";
164 : :
165 : : //----------------------------------------------------------------------
166 : :
167 : : #define ScDocShell
168 : : #include "scslots.hxx"
169 : :
170 : :
171 [ + + ][ + - ]: 21510 : SFX_IMPL_INTERFACE(ScDocShell,SfxObjectShell, ScResId(SCSTR_DOCSHELL))
[ + - ][ + - ]
172 : : {
173 : 51 : }
174 : :
175 : : // GlobalName der aktuellen Version:
176 [ + + ][ + - ]: 108314 : SFX_IMPL_OBJECTFACTORY( ScDocShell, SvGlobalName(SO3_SC_CLASSID), SFXOBJECTSHELL_STD_NORMAL, "scalc" )
[ + - ][ + - ]
[ + - ][ # # ]
177 : :
178 [ + + ][ + + ]: 43056 : TYPEINIT1( ScDocShell, SfxObjectShell ); // SfxInPlaceObject: kein Type-Info ?
179 : :
180 : : //------------------------------------------------------------------
181 : :
182 : 311 : void ScDocShell::FillClass( SvGlobalName* pClassName,
183 : : sal_uInt32* pFormat,
184 : : String* /* pAppName */,
185 : : String* pFullTypeName,
186 : : String* pShortTypeName,
187 : : sal_Int32 nFileFormat,
188 : : sal_Bool bTemplate /* = sal_False */) const
189 : : {
190 [ + + ]: 311 : if ( nFileFormat == SOFFICE_FILEFORMAT_60 )
191 : : {
192 [ + - ]: 2 : *pClassName = SvGlobalName( SO3_SC_CLASSID_60 );
193 : 2 : *pFormat = SOT_FORMATSTR_ID_STARCALC_60;
194 [ + - ][ + - ]: 2 : *pFullTypeName = String( ScResId( SCSTR_LONG_SCDOC_NAME ) );
[ + - ]
195 [ + - ][ + - ]: 2 : *pShortTypeName = String( ScResId( SCSTR_SHORT_SCDOC_NAME ) );
[ + - ]
196 : : }
197 [ + - ]: 309 : else if ( nFileFormat == SOFFICE_FILEFORMAT_8 )
198 : : {
199 [ + - ]: 309 : *pClassName = SvGlobalName( SO3_SC_CLASSID_60 );
200 [ - + ]: 309 : *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARCALC_8_TEMPLATE : SOT_FORMATSTR_ID_STARCALC_8;
201 [ + - ]: 309 : *pFullTypeName = rtl::OUString("calc8");
202 [ + - ][ + - ]: 309 : *pShortTypeName = ScResId(SCSTR_SHORT_SCDOC_NAME).toString();
203 : : }
204 : : else
205 : : {
206 : : OSL_FAIL("wat fuer ne Version?");
207 : : }
208 : 311 : }
209 : :
210 : : //------------------------------------------------------------------
211 : :
212 : 0 : void ScDocShell::DoEnterHandler()
213 : : {
214 : 0 : ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
215 [ # # ]: 0 : if (pViewSh)
216 [ # # ]: 0 : if (pViewSh->GetViewData()->GetDocShell() == this)
217 : 0 : SC_MOD()->InputEnterHandler();
218 : 0 : }
219 : :
220 : : //------------------------------------------------------------------
221 : :
222 : 0 : SCTAB ScDocShell::GetSaveTab()
223 : : {
224 : 0 : SCTAB nTab = 0;
225 : 0 : ScTabViewShell* pSh = GetBestViewShell();
226 [ # # ]: 0 : if (pSh)
227 : : {
228 : 0 : const ScMarkData& rMark = pSh->GetViewData()->GetMarkData();
229 : 0 : nTab = rMark.GetFirstSelected();
230 : : }
231 : 0 : return nTab;
232 : : }
233 : :
234 : 0 : sal_uInt16 ScDocShell::GetHiddenInformationState( sal_uInt16 nStates )
235 : : {
236 : : // get global state like HIDDENINFORMATION_DOCUMENTVERSIONS
237 : 0 : sal_uInt16 nState = SfxObjectShell::GetHiddenInformationState( nStates );
238 : :
239 [ # # ]: 0 : if ( nStates & HIDDENINFORMATION_RECORDEDCHANGES )
240 : : {
241 [ # # ][ # # ]: 0 : if ( aDocument.GetChangeTrack() && aDocument.GetChangeTrack()->GetFirst() )
[ # # ]
242 : 0 : nState |= HIDDENINFORMATION_RECORDEDCHANGES;
243 : : }
244 [ # # ]: 0 : if ( nStates & HIDDENINFORMATION_NOTES )
245 : : {
246 : 0 : SCTAB nTableCount = aDocument.GetTableCount();
247 : 0 : bool bFound = false;
248 [ # # ][ # # ]: 0 : for (SCTAB nTab = 0; nTab < nTableCount && !bFound; ++nTab)
[ # # ]
249 : : {
250 [ # # ]: 0 : if (!aDocument.GetNotes(nTab)->empty())
251 : 0 : bFound = true;
252 : : }
253 : :
254 [ # # ]: 0 : if (bFound)
255 : 0 : nState |= HIDDENINFORMATION_NOTES;
256 : : }
257 : :
258 : 0 : return nState;
259 : : }
260 : :
261 : 94 : void ScDocShell::BeforeXMLLoading()
262 : : {
263 : 94 : aDocument.DisableIdle( sal_True );
264 : :
265 : : // prevent unnecessary broadcasts and updates
266 : : OSL_ENSURE(pModificator == NULL, "The Modificator should not exist");
267 [ + - ]: 94 : pModificator = new ScDocShellModificator( *this );
268 : :
269 : 94 : aDocument.SetImportingXML( sal_True );
270 : 94 : aDocument.EnableExecuteLink( false ); // #i101304# to be safe, prevent nested loading from external references
271 : 94 : aDocument.EnableUndo( false );
272 : : // prevent unnecessary broadcasts and "half way listeners"
273 : 94 : aDocument.SetInsertingFromOtherDoc( sal_True );
274 : :
275 [ + - ]: 94 : if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
276 : 94 : ScColumn::bDoubleAlloc = sal_True;
277 : 94 : }
278 : :
279 : 94 : void ScDocShell::AfterXMLLoading(sal_Bool bRet)
280 : : {
281 [ + - ]: 94 : if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
282 : : {
283 : 94 : UpdateLinks();
284 : : // don't prevent establishing of listeners anymore
285 : 94 : aDocument.SetInsertingFromOtherDoc( false );
286 [ + - ]: 94 : if ( bRet )
287 : : {
288 : 94 : ScChartListenerCollection* pChartListener = aDocument.GetChartListenerCollection();
289 [ + - ]: 94 : if (pChartListener)
290 : 94 : pChartListener->UpdateDirtyCharts();
291 : :
292 : : // #95582#; set the table names of linked tables to the new path
293 : 94 : SCTAB nTabCount = aDocument.GetTableCount();
294 [ + + ]: 319 : for (SCTAB i = 0; i < nTabCount; ++i)
295 : : {
296 [ - + ]: 225 : if (aDocument.IsLinked( i ))
297 : : {
298 : 0 : rtl::OUString aName;
299 [ # # ]: 0 : aDocument.GetName(i, aName);
300 [ # # ]: 0 : rtl::OUString aLinkTabName = aDocument.GetLinkTab(i);
301 : 0 : sal_Int32 nLinkTabNameLength = aLinkTabName.getLength();
302 : 0 : sal_Int32 nNameLength = aName.getLength();
303 [ # # ]: 0 : if (nLinkTabNameLength < nNameLength)
304 : : {
305 : :
306 : : // remove the quottes on begin and end of the docname and restore the escaped quotes
307 : 0 : const sal_Unicode* pNameBuffer = aName.getStr();
308 [ # # ][ # # ]: 0 : if ( *pNameBuffer == '\'' && // all docnames have to have a ' character on the first pos
[ # # ]
309 [ # # ]: 0 : ScGlobal::UnicodeStrChr( pNameBuffer, SC_COMPILER_FILE_TAB_SEP ) )
310 : : {
311 : 0 : rtl::OUStringBuffer aDocURLBuffer;
312 : 0 : sal_Bool bQuote = sal_True; // Dokumentenname ist immer quoted
313 : 0 : ++pNameBuffer;
314 [ # # ][ # # ]: 0 : while ( bQuote && *pNameBuffer )
[ # # ]
315 : : {
316 [ # # ][ # # ]: 0 : if ( *pNameBuffer == '\'' && *(pNameBuffer-1) != '\\' )
317 : 0 : bQuote = false;
318 [ # # ][ # # ]: 0 : else if( !(*pNameBuffer == '\\' && *(pNameBuffer+1) == '\'') )
319 [ # # ]: 0 : aDocURLBuffer.append(*pNameBuffer); // falls escaped Quote: nur Quote in den Namen
320 : 0 : ++pNameBuffer;
321 : : }
322 : :
323 : :
324 [ # # ]: 0 : if( *pNameBuffer == SC_COMPILER_FILE_TAB_SEP ) // after the last quote of the docname should be the # char
325 : : {
326 : 0 : xub_StrLen nIndex = nNameLength - nLinkTabNameLength;
327 [ # # ][ # # ]: 0 : INetURLObject aINetURLObject(aDocURLBuffer.makeStringAndClear());
328 [ # # ][ # # ]: 0 : if( String(aName).Equals(String(aLinkTabName), nIndex, nLinkTabNameLength) &&
[ # # # #
# # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
[ # # ]
329 : 0 : (aName[nIndex - 1] == '#') && // before the table name should be the # char
330 : 0 : !aINetURLObject.HasError()) // the docname should be a valid URL
331 : : {
332 [ # # ][ # # ]: 0 : aName = ScGlobal::GetDocTabName( aDocument.GetLinkDoc( i ), aDocument.GetLinkTab( i ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
333 [ # # ]: 0 : aDocument.RenameTab(i, aName, sal_True, sal_True);
334 [ # # ]: 0 : }
335 : : // else; nothing has to happen, because it is a user given name
336 : 0 : }
337 : : // else; nothing has to happen, because it is a user given name
338 : : }
339 : : // else; nothing has to happen, because it is a user given name
340 : 0 : }
341 : : // else; nothing has to happen, because it is a user given name
342 : : }
343 : : }
344 : :
345 : : // #i94570# DataPilot table names have to be unique, or the tables can't be accessed by API.
346 : : // If no name (or an invalid name, skipped in ScXMLDataPilotTableContext::EndElement) was set, create a new name.
347 : 94 : ScDPCollection* pDPCollection = aDocument.GetDPCollection();
348 [ + - ]: 94 : if ( pDPCollection )
349 : : {
350 : 94 : size_t nDPCount = pDPCollection->GetCount();
351 [ + + ]: 100 : for (size_t nDP=0; nDP<nDPCount; ++nDP)
352 : : {
353 : 6 : ScDPObject* pDPObj = (*pDPCollection)[nDP];
354 [ - + ]: 6 : if (pDPObj->GetName().isEmpty())
355 [ # # ]: 0 : pDPObj->SetName( pDPCollection->CreateNewName() );
356 : : }
357 : : }
358 : : }
359 : 94 : ScColumn::bDoubleAlloc = false;
360 : : }
361 : : else
362 : 0 : aDocument.SetInsertingFromOtherDoc( false );
363 : :
364 : 94 : aDocument.SetImportingXML( false );
365 : 94 : aDocument.EnableExecuteLink( true );
366 : 94 : aDocument.EnableUndo( sal_True );
367 : 94 : bIsEmpty = false;
368 : :
369 [ + - ]: 94 : if (pModificator)
370 : : {
371 : 94 : bool bRecalcState = aDocument.GetHardRecalcState();
372 : : //temporarily set hard-recalc to prevent calling ScFormulaCell::Notify()
373 : : //which will set the cells dirty.
374 : 94 : aDocument.SetHardRecalcState(true);
375 [ + - ]: 94 : delete pModificator;
376 : 94 : aDocument.SetHardRecalcState(bRecalcState);
377 : 94 : pModificator = NULL;
378 : : }
379 : : else
380 : : {
381 : : OSL_FAIL("The Modificator should exist");
382 : : }
383 : :
384 : 94 : aDocument.DisableIdle( false );
385 : 94 : }
386 : :
387 : : namespace {
388 : :
389 : : class LoadMediumGuard
390 : : {
391 : : public:
392 : 274 : explicit LoadMediumGuard(ScDocument* pDoc) :
393 : 274 : mpDoc(pDoc)
394 : : {
395 : 274 : mpDoc->SetLoadingMedium(true);
396 : 274 : }
397 : :
398 : 274 : ~LoadMediumGuard()
399 : : {
400 : 274 : mpDoc->SetLoadingMedium(false);
401 : 274 : }
402 : : private:
403 : : ScDocument* mpDoc;
404 : : };
405 : :
406 : : }
407 : :
408 : 93 : sal_Bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStor )
409 : : {
410 [ + - ]: 93 : LoadMediumGuard aLoadGuard(&aDocument);
411 : :
412 : : // MacroCallMode is no longer needed, state is kept in SfxObjectShell now
413 : :
414 : : // no Seek(0) here - always loading from storage, GetInStream must not be called
415 : :
416 [ + - ]: 93 : BeforeXMLLoading();
417 : :
418 : : // #i62677# BeforeXMLLoading is also called from ScXMLImport::startDocument when invoked
419 : : // from an external component. The XMLFromWrapper flag is only set here, when called
420 : : // through ScDocShell.
421 [ + - ]: 93 : aDocument.SetXMLFromWrapper( sal_True );
422 : :
423 [ + - ]: 93 : ScXMLImportWrapper aImport( aDocument, pLoadMedium, xStor );
424 : :
425 : 93 : sal_Bool bRet(false);
426 : 93 : ErrCode nError = ERRCODE_NONE;
427 [ + - ]: 93 : if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
428 [ + - ]: 93 : bRet = aImport.Import(false, nError);
429 : : else
430 [ # # ]: 0 : bRet = aImport.Import(sal_True, nError);
431 : :
432 [ - + ]: 93 : if ( nError )
433 [ # # ][ # # ]: 0 : pLoadMedium->SetError( nError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
434 : :
435 : : //if the document was not generated by LibreOffice, do hard recalc in case some other document
436 : : //generator saved cached formula results that differ from LibreOffice's calculated results or
437 : : //did not use cached formula results.
438 [ + - ][ + - ]: 93 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW);
439 [ + - ][ + - ]: 93 : uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
440 [ + - ][ + - ]: 93 : rtl::OUString sGenerator(xDocProps->getGenerator());
441 [ + + ]: 93 : if(sGenerator.indexOf(SC_LIBO_PROD_NAME) == -1)
442 [ + - ]: 9 : DoHardRecalc(false);
443 : : else //still need to recalc volatile formula cells
444 [ + - ]: 84 : DoRecalc(false);
445 : :
446 : 93 : aDocument.EnableAdjustHeight(false);
447 : :
448 [ + - ]: 93 : aDocument.SetXMLFromWrapper( false );
449 [ + - ]: 93 : AfterXMLLoading(bRet);
450 : :
451 [ + - ][ + - ]: 93 : return bRet;
452 : : }
453 : :
454 : 4 : sal_Bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStor )
455 : : {
456 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "sb99857", "ScDocShell::SaveXML" );
457 : :
458 : 4 : aDocument.DisableIdle( sal_True );
459 : :
460 [ + - ]: 4 : ScXMLImportWrapper aImport( aDocument, pSaveMedium, xStor );
461 : 4 : sal_Bool bRet(false);
462 [ + - ]: 4 : if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
463 [ + - ]: 4 : bRet = aImport.Export(false);
464 : : else
465 [ # # ]: 0 : bRet = aImport.Export(sal_True);
466 : :
467 : 4 : aDocument.DisableIdle( false );
468 : :
469 [ + - ]: 4 : return bRet;
470 : : }
471 : :
472 : 93 : sal_Bool ScDocShell::Load( SfxMedium& rMedium )
473 : : {
474 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::Load" );
475 [ + - ]: 93 : LoadMediumGuard aLoadGuard(&aDocument);
476 [ + - ]: 93 : ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
477 : :
478 : : // only the latin script language is loaded
479 : : // -> initialize the others from options (before loading)
480 [ + - ]: 93 : InitOptions(true);
481 : :
482 [ + - ][ + - ]: 93 : GetUndoManager()->Clear();
483 : :
484 [ + - ]: 93 : sal_Bool bRet = SfxObjectShell::Load( rMedium );
485 [ + - ]: 93 : if( bRet )
486 : : {
487 [ + - ]: 93 : if (GetMedium())
488 : : {
489 [ + - ][ + - ]: 93 : SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, false);
[ + - ]
490 [ + + ]: 93 : nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : com::sun::star::document::UpdateDocMode::NO_UPDATE;
491 : : }
492 : :
493 : : {
494 : : // prepare a valid document for XML filter
495 : : // (for ConvertFrom, InitNew is called before)
496 [ + - ]: 93 : aDocument.MakeTable(0);
497 [ + - ][ + - ]: 93 : aDocument.GetStyleSheetPool()->CreateStandardStyles();
498 [ + - ]: 93 : aDocument.UpdStlShtPtrsFrmNms();
499 : :
500 [ + - ][ + - ]: 93 : bRet = LoadXML( &rMedium, NULL );
501 : : }
502 : : }
503 : :
504 [ - + ][ # # ]: 93 : if (!bRet && !rMedium.GetError())
[ # # ][ - + ]
505 [ # # ][ # # ]: 0 : rMedium.SetError( SVSTREAM_FILEFORMAT_ERROR, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
506 : :
507 [ + - ][ - + ]: 93 : if (rMedium.GetError())
508 [ # # ][ # # ]: 0 : SetError( rMedium.GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
[ # # ]
509 : :
510 [ + - ]: 93 : InitItems();
511 [ + - ]: 93 : CalcOutputFactor();
512 : :
513 : : // invalidate eventually temporary table areas
514 [ + - ]: 93 : if ( bRet )
515 [ + - ]: 93 : aDocument.InvalidateTableArea();
516 : :
517 : 93 : bIsEmpty = false;
518 [ + - ]: 93 : FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
519 [ + - ]: 93 : return bRet;
520 : : }
521 : :
522 : 35455 : void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
523 : : {
524 [ + - ]: 35455 : uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = aDocument.GetVbaEventProcessor();
525 [ + + ]: 35455 : if ( xVbaEvents.is() ) try
526 : : {
527 : : using namespace ::com::sun::star::script::vba::VBAEventId;
528 [ + - ][ + - ]: 187 : if (rHint.ISA(ScTablesHint) )
[ - + ]
529 : : {
530 : 0 : const ScTablesHint& rScHint = static_cast< const ScTablesHint& >( rHint );
531 [ # # ]: 0 : if (rScHint.GetId() == SC_TAB_INSERTED)
532 : : {
533 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 1 );
534 [ # # ][ # # ]: 0 : aArgs[0] <<= rScHint.GetTab1();
535 [ # # ][ # # ]: 0 : xVbaEvents->processVbaEvent( WORKBOOK_NEWSHEET, aArgs );
[ # # ]
536 : : }
537 [ # # ]: 0 : else if (rScHint.GetId() == SC_TABS_INSERTED)
538 : : {
539 [ # # ]: 0 : for (SCTAB i = 0; i < rScHint.GetTab2(); ++i)
540 : : {
541 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 1 );
542 [ # # ][ # # ]: 0 : aArgs[0] <<= static_cast<sal_Int16>(rScHint.GetTab1() + i);
543 [ # # ][ # # ]: 0 : xVbaEvents->processVbaEvent( WORKBOOK_NEWSHEET, aArgs );
544 [ # # ]: 0 : }
545 : : }
546 : : }
547 [ + - ][ + - ]: 187 : else if ( rHint.ISA( SfxEventHint ) )
[ + + ]
548 : : {
549 : 33 : sal_uLong nEventId = static_cast< const SfxEventHint& >( rHint ).GetEventId();
550 [ + - + - : 33 : switch ( nEventId )
- + + ]
551 : : {
552 : : case SFX_EVENT_ACTIVATEDOC:
553 : : {
554 [ + - ]: 4 : uno::Sequence< uno::Any > aArgs;
555 [ + - ][ + - ]: 4 : xVbaEvents->processVbaEvent( WORKBOOK_ACTIVATE, aArgs );
[ + - ]
556 : : }
557 : 4 : break;
558 : : case SFX_EVENT_DEACTIVATEDOC:
559 : : {
560 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs;
561 [ # # ][ # # ]: 0 : xVbaEvents->processVbaEvent( WORKBOOK_DEACTIVATE, aArgs );
[ # # ]
562 : : }
563 : 0 : break;
564 : : case SFX_EVENT_OPENDOC:
565 : : {
566 [ + - ]: 4 : uno::Sequence< uno::Any > aArgs;
567 [ + - ][ + - ]: 4 : xVbaEvents->processVbaEvent( WORKBOOK_OPEN, aArgs );
[ + - ]
568 : : }
569 : 4 : break;
570 : : case SFX_EVENT_SAVEDOCDONE:
571 : : case SFX_EVENT_SAVEASDOCDONE:
572 : : case SFX_EVENT_SAVETODOCDONE:
573 : : {
574 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 1 );
575 [ # # ][ # # ]: 0 : aArgs[ 0 ] <<= true;
576 [ # # ][ # # ]: 0 : xVbaEvents->processVbaEvent( WORKBOOK_AFTERSAVE, aArgs );
[ # # ]
577 : : }
578 : 0 : break;
579 : : case SFX_EVENT_SAVEASDOCFAILED:
580 : : case SFX_EVENT_SAVEDOCFAILED:
581 : : case SFX_EVENT_SAVETODOCFAILED:
582 : : {
583 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 1 );
584 [ # # ][ # # ]: 0 : aArgs[ 0 ] <<= false;
585 [ # # ][ # # ]: 0 : xVbaEvents->processVbaEvent( WORKBOOK_AFTERSAVE, aArgs );
[ # # ]
586 : : }
587 : 0 : break;
588 : : case SFX_EVENT_CLOSEDOC:
589 : : {
590 : : // #163655# prevent event processing after model is disposed
591 [ + - ]: 5 : aDocument.SetVbaEventProcessor( uno::Reference< script::vba::XVBAEventProcessor >() );
592 [ + - ][ + - ]: 5 : uno::Reference< lang::XEventListener >( xVbaEvents, uno::UNO_QUERY_THROW )->disposing( lang::EventObject() );
[ + - ][ + - ]
[ # # ][ + - ]
593 : : }
594 : 33 : break;
595 : : }
596 : : }
597 : : }
598 [ # # ]: 0 : catch( uno::Exception& )
599 : : {
600 : : }
601 : :
602 [ + - ][ + - ]: 35455 : if (rHint.ISA(SfxSimpleHint)) // ohne Parameter
[ + + ]
603 : : {
604 : 11468 : sal_uLong nSlot = ((const SfxSimpleHint&)rHint).GetId();
605 [ + + ]: 11468 : switch ( nSlot )
606 : : {
607 : : case SFX_HINT_TITLECHANGED:
608 [ + - ][ + - ]: 954 : aDocument.SetName( SfxShell::GetName() );
609 : : // RegisterNewTargetNames gibts nicht mehr
610 [ + - ][ + - ]: 954 : SFX_APP()->Broadcast(SfxSimpleHint( SC_HINT_DOCNAME_CHANGED )); // Navigator
[ + - ][ + - ]
611 : 11468 : break;
612 : : }
613 : : }
614 [ + - ][ + - ]: 23987 : else if (rHint.ISA(SfxStyleSheetHint)) // Vorlagen geaendert
[ + + ]
615 [ + - ]: 7120 : NotifyStyle((const SfxStyleSheetHint&) rHint);
616 [ + - ][ + - ]: 16867 : else if (rHint.ISA(ScAutoStyleHint))
[ - + ]
617 : : {
618 : : //! direct call for AutoStyles
619 : :
620 : : // this is called synchronously from ScInterpreter::ScStyle,
621 : : // modifying the document must be asynchronous
622 : : // (handled by AddInitial)
623 : :
624 : 0 : ScAutoStyleHint& rStlHint = (ScAutoStyleHint&)rHint;
625 : 0 : ScRange aRange = rStlHint.GetRange();
626 [ # # ]: 0 : String aName1 = rStlHint.GetStyle1();
627 [ # # ]: 0 : String aName2 = rStlHint.GetStyle2();
628 : 0 : sal_uInt32 nTimeout = rStlHint.GetTimeout();
629 : :
630 [ # # ]: 0 : if (!pAutoStyleList)
631 [ # # ][ # # ]: 0 : pAutoStyleList = new ScAutoStyleList(this);
632 [ # # ][ # # ]: 0 : pAutoStyleList->AddInitial( aRange, aName1, nTimeout, aName2 );
[ # # ]
633 : : }
634 [ + - ][ + - ]: 16867 : else if ( rHint.ISA( SfxEventHint ) )
[ + + ]
635 : : {
636 : 2305 : sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
637 [ + + - + : 2305 : switch ( nEventId )
- + - + ]
638 : : {
639 : : case SFX_EVENT_LOADFINISHED:
640 : : {
641 : : // the readonly documents should not be opened in shared mode
642 [ + - ][ - + ]: 205 : if ( HasSharedXMLFlagSet() && !SC_MOD()->IsInSharedDocLoading() && !IsReadOnly() )
[ # # ][ # # ]
[ # # ][ # # ]
[ - + ]
643 : : {
644 [ # # ][ # # ]: 0 : if ( SwitchToShared( sal_True, false ) )
645 : : {
646 [ # # ]: 0 : ScViewData* pViewData = GetViewData();
647 [ # # ][ # # ]: 0 : ScTabView* pTabView = ( pViewData ? dynamic_cast< ScTabView* >( pViewData->GetView() ) : NULL );
648 [ # # ]: 0 : if ( pTabView )
649 : : {
650 [ # # ]: 0 : pTabView->UpdateLayerLocks();
651 : : }
652 : : }
653 : : else
654 : : {
655 : : // switching to shared mode has failed, the document should be opened readonly
656 : : // TODO/LATER: And error message should be shown here probably
657 [ # # ]: 0 : SetReadOnlyUI( sal_True );
658 : : }
659 : : }
660 : : }
661 : 205 : break;
662 : : case SFX_EVENT_VIEWCREATED:
663 : : {
664 [ + - ][ - + ]: 245 : if ( IsDocShared() && !SC_MOD()->IsInSharedDocLoading() )
[ # # ][ # # ]
[ - + ]
665 : : {
666 [ # # ][ # # ]: 0 : ScAppOptions aAppOptions = SC_MOD()->GetAppOptions();
[ # # ]
667 [ # # ]: 0 : if ( aAppOptions.GetShowSharedDocumentWarning() )
668 : : {
669 : : WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ),
670 [ # # ][ # # ]: 0 : ScGlobal::GetRscString( STR_SHARED_DOC_WARNING ) );
[ # # ]
671 [ # # ]: 0 : aBox.SetDefaultCheckBoxText();
672 [ # # ]: 0 : aBox.Execute();
673 [ # # ]: 0 : sal_Bool bChecked = aBox.GetCheckBoxState();
674 [ # # ]: 0 : if ( bChecked )
675 : : {
676 : 0 : aAppOptions.SetShowSharedDocumentWarning( !bChecked );
677 [ # # ][ # # ]: 0 : SC_MOD()->SetAppOptions( aAppOptions );
678 [ # # ]: 0 : }
679 [ # # ]: 0 : }
680 : : }
681 : :
682 : : try
683 : : {
684 : 245 : uno::Reference< uno::XComponentContext > xContext;
685 [ + - ]: 245 : uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
686 [ + - ]: 245 : uno::Reference< beans::XPropertySet > xProp( xServiceManager, uno::UNO_QUERY_THROW );
687 [ + - ][ + - ]: 245 : xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ) >>= xContext;
[ + - ][ + - ]
688 [ + - ]: 245 : if ( xContext.is() )
689 : : {
690 [ + - ]: 245 : uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xServiceManager, uno::UNO_QUERY_THROW );
691 [ + - ]: 245 : uno::Reference< container::XEnumeration> xEnum = xEnumAccess->createContentEnumeration(
692 [ + - ][ + - ]: 245 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocumentJob" ) ) );
693 [ + - ]: 245 : if ( xEnum.is() )
694 : : {
695 [ + - ][ + - ]: 245 : while ( xEnum->hasMoreElements() )
[ - + ]
696 : : {
697 [ # # ][ # # ]: 0 : uno::Any aAny = xEnum->nextElement();
698 : 0 : uno::Reference< lang::XSingleComponentFactory > xFactory;
699 [ # # ]: 0 : aAny >>= xFactory;
700 [ # # ]: 0 : if ( xFactory.is() )
701 : : {
702 [ # # ][ # # ]: 0 : uno::Reference< task::XJob > xJob( xFactory->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
[ # # ]
703 [ # # ]: 0 : uno::Sequence< beans::NamedValue > aArgsForJob(1);
704 [ # # ]: 0 : ScViewData* pViewData = GetViewData();
705 [ # # ]: 0 : SfxViewShell* pViewShell = ( pViewData ? pViewData->GetViewShell() : NULL );
706 [ # # ]: 0 : SfxViewFrame* pViewFrame = ( pViewShell ? pViewShell->GetViewFrame() : NULL );
707 [ # # ][ # # ]: 0 : SfxFrame* pFrame = ( pViewFrame ? &pViewFrame->GetFrame() : NULL );
708 [ # # ][ # # ]: 0 : uno::Reference< frame::XController > xController = ( pFrame ? pFrame->GetController() : 0 );
[ # # ]
709 [ # # ]: 0 : uno::Reference< sheet::XSpreadsheetView > xSpreadsheetView( xController, uno::UNO_QUERY_THROW );
710 [ # # ]: 0 : aArgsForJob[0] = beans::NamedValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "SpreadsheetView" )),
711 [ # # ][ # # ]: 0 : uno::makeAny( xSpreadsheetView ) );
712 [ # # ][ # # ]: 0 : xJob->execute( aArgsForJob );
[ # # ]
713 : : }
714 : 0 : }
715 : 245 : }
716 [ # # ]: 245 : }
717 : : }
718 [ # # ]: 0 : catch ( uno::Exception & )
719 : : {
720 : : }
721 : : }
722 : 245 : break;
723 : : case SFX_EVENT_SAVEDOC:
724 : : {
725 [ # # ][ # # ]: 0 : if ( IsDocShared() && !SC_MOD()->IsInSharedDocSaving() )
[ # # ][ # # ]
[ # # ]
726 : : {
727 : 0 : bool bSuccess = false;
728 : 0 : bool bRetry = true;
729 [ # # ]: 0 : while ( bRetry )
730 : : {
731 : 0 : bRetry = false;
732 : 0 : uno::Reference< frame::XModel > xModel;
733 : : try
734 : : {
735 : : // load shared file
736 [ # # ][ # # ]: 0 : xModel.set( LoadSharedDocument(), uno::UNO_QUERY_THROW );
737 [ # # ]: 0 : uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
738 : :
739 : : // check if shared flag is set in shared file
740 : 0 : bool bShared = false;
741 [ # # ]: 0 : ScModelObj* pDocObj = ScModelObj::getImplementation( xModel );
742 [ # # ][ # # ]: 0 : ScDocShell* pSharedDocShell = ( pDocObj ? dynamic_cast< ScDocShell* >( pDocObj->GetObjectShell() ) : NULL );
[ # # ]
743 [ # # ]: 0 : if ( pSharedDocShell )
744 : : {
745 [ # # ]: 0 : bShared = pSharedDocShell->HasSharedXMLFlagSet();
746 : : }
747 : :
748 : : // #i87870# check if shared status was disabled and enabled again
749 : 0 : bool bOwnEntry = false;
750 : 0 : bool bEntriesNotAccessible = false;
751 : : try
752 : : {
753 [ # # ][ # # ]: 0 : ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
754 [ # # ][ # # ]: 0 : bOwnEntry = aControlFile.HasOwnEntry();
[ # # ]
755 : : }
756 [ # # ]: 0 : catch ( uno::Exception& )
757 : : {
758 : 0 : bEntriesNotAccessible = true;
759 : : }
760 : :
761 [ # # ][ # # ]: 0 : if ( bShared && bOwnEntry )
762 : : {
763 [ # # ]: 0 : uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
764 : :
765 [ # # ][ # # ]: 0 : if ( xStorable->isReadonly() )
[ # # ]
766 : : {
767 [ # # ][ # # ]: 0 : xCloseable->close( sal_True );
768 : :
769 [ # # ][ # # ]: 0 : String aUserName( ScGlobal::GetRscString( STR_UNKNOWN_USER ) );
770 : 0 : bool bNoLockAccess = false;
771 : : try
772 : : {
773 [ # # ][ # # ]: 0 : ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
774 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aData = aLockFile.GetLockData();
775 [ # # ]: 0 : if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
776 : : {
777 [ # # ][ # # ]: 0 : if ( !aData[LOCKFILE_OOOUSERNAME_ID].isEmpty() )
778 : : {
779 [ # # ][ # # ]: 0 : aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
780 : : }
781 [ # # ][ # # ]: 0 : else if ( !aData[LOCKFILE_SYSUSERNAME_ID].isEmpty() )
782 : : {
783 [ # # ][ # # ]: 0 : aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
784 : : }
785 [ # # ][ # # ]: 0 : }
[ # # ]
786 : : }
787 [ # # ]: 0 : catch ( uno::Exception& )
788 : : {
789 : 0 : bNoLockAccess = true;
790 : : }
791 : :
792 [ # # ]: 0 : if ( bNoLockAccess )
793 : : {
794 : : // TODO/LATER: in future an error regarding impossibility to open file for writing could be shown
795 [ # # ]: 0 : ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
796 : : }
797 : : else
798 : : {
799 [ # # ][ # # ]: 0 : String aMessage( ScGlobal::GetRscString( STR_FILE_LOCKED_SAVE_LATER ) );
800 [ # # ]: 0 : aMessage.SearchAndReplaceAscii( "%1", aUserName );
801 : :
802 [ # # ][ # # ]: 0 : WarningBox aBox( GetActiveDialogParent(), WinBits( WB_RETRY_CANCEL | WB_DEF_RETRY ), aMessage );
803 [ # # ][ # # ]: 0 : if ( aBox.Execute() == RET_RETRY )
804 : : {
805 : 0 : bRetry = true;
806 [ # # ][ # # ]: 0 : }
807 [ # # ]: 0 : }
808 : : }
809 : : else
810 : : {
811 : : // merge changes from shared file into temp file
812 : 0 : bool bSaveToShared = false;
813 [ # # ]: 0 : if ( pSharedDocShell )
814 : : {
815 [ # # ]: 0 : bSaveToShared = MergeSharedDocument( pSharedDocShell );
816 : : }
817 : :
818 : : // close shared file
819 [ # # ][ # # ]: 0 : xCloseable->close( sal_True );
820 : :
821 : : // TODO: keep file lock on shared file
822 : :
823 : : // store to shared file
824 [ # # ]: 0 : if ( bSaveToShared )
825 : : {
826 : 0 : bool bChangedViewSettings = false;
827 : 0 : ScChangeViewSettings* pChangeViewSet = aDocument.GetChangeViewSettings();
828 [ # # ][ # # ]: 0 : if ( pChangeViewSet && pChangeViewSet->ShowChanges() )
[ # # ]
829 : : {
830 : 0 : pChangeViewSet->SetShowChanges( false );
831 : 0 : pChangeViewSet->SetShowAccepted( false );
832 [ # # ]: 0 : aDocument.SetChangeViewSettings( *pChangeViewSet );
833 : 0 : bChangedViewSettings = true;
834 : : }
835 : :
836 [ # # ][ # # ]: 0 : uno::Reference< frame::XStorable > xStor( GetModel(), uno::UNO_QUERY_THROW );
837 : : // TODO/LATER: More entries from the MediaDescriptor might be interesting for the merge
838 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aValues(1);
839 [ # # ][ # # ]: 0 : aValues[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "FilterName"));
840 [ # # ][ # # ]: 0 : aValues[0].Value <<= ::rtl::OUString( GetMedium()->GetFilter()->GetFilterName() );
[ # # ][ # # ]
841 : :
842 [ # # ][ # # ]: 0 : SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, false);
[ # # ]
843 [ # # ][ # # ]: 0 : if ( pPasswordItem && pPasswordItem->GetValue().Len() )
[ # # ]
844 : : {
845 [ # # ]: 0 : aValues.realloc( 2 );
846 [ # # ][ # # ]: 0 : aValues[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Password") );
847 [ # # ][ # # ]: 0 : aValues[1].Value <<= ::rtl::OUString( pPasswordItem->GetValue() );
[ # # ]
848 : : }
849 : :
850 [ # # ]: 0 : SC_MOD()->SetInSharedDocSaving( true );
851 [ # # ][ # # ]: 0 : xStor->storeToURL( GetSharedFileURL(), aValues );
[ # # ]
852 [ # # ]: 0 : SC_MOD()->SetInSharedDocSaving( false );
853 : :
854 [ # # ]: 0 : if ( bChangedViewSettings )
855 : : {
856 : 0 : pChangeViewSet->SetShowChanges( sal_True );
857 : 0 : pChangeViewSet->SetShowAccepted( sal_True );
858 [ # # ]: 0 : aDocument.SetChangeViewSettings( *pChangeViewSet );
859 [ # # ]: 0 : }
860 : : }
861 : :
862 : 0 : bSuccess = true;
863 [ # # ][ # # ]: 0 : GetUndoManager()->Clear();
864 : 0 : }
865 : : }
866 : : else
867 : : {
868 [ # # ][ # # ]: 0 : xCloseable->close( sal_True );
869 : :
870 [ # # ]: 0 : if ( bEntriesNotAccessible )
871 : : {
872 : : // TODO/LATER: in future an error regarding impossibility to write to share control file could be shown
873 [ # # ]: 0 : ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
874 : : }
875 : : else
876 : : {
877 : : WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ),
878 [ # # ][ # # ]: 0 : ScGlobal::GetRscString( STR_DOC_NOLONGERSHARED ) );
[ # # ]
879 [ # # ]: 0 : aBox.Execute();
880 : :
881 [ # # ]: 0 : SfxBindings* pBindings = GetViewBindings();
882 [ # # ]: 0 : if ( pBindings )
883 : : {
884 [ # # ]: 0 : pBindings->ExecuteSynchron( SID_SAVEASDOC );
885 [ # # ]: 0 : }
886 : : }
887 : 0 : }
888 : : }
889 [ # # # # ]: 0 : catch ( uno::Exception& )
890 : : {
891 : : OSL_FAIL( "SFX_EVENT_SAVEDOC: caught exception\n" );
892 [ # # ]: 0 : SC_MOD()->SetInSharedDocSaving( false );
893 : :
894 : : try
895 : : {
896 [ # # ]: 0 : uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
897 [ # # # # : 0 : xClose->close( sal_True );
# # ]
898 : : }
899 [ # # ]: 0 : catch ( uno::Exception& )
900 : : {
901 : : }
902 : : }
903 : 0 : }
904 : :
905 [ # # ]: 0 : if ( !bSuccess )
906 [ # # ][ # # ]: 0 : SetError( ERRCODE_IO_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // this error code will produce no error message, but will break the further saving process
907 : : }
908 : :
909 : :
910 [ # # ]: 0 : if (pSheetSaveData)
911 [ # # ]: 0 : pSheetSaveData->SetInSupportedSave(true);
912 : : }
913 : 0 : break;
914 : : case SFX_EVENT_SAVEASDOC:
915 : : {
916 [ + - ][ + - ]: 4 : if ( GetDocument()->GetExternalRefManager()->containsUnsavedReferences() )
[ - + ]
917 : : {
918 : : WarningBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO ),
919 [ # # ][ # # ]: 0 : ScGlobal::GetRscString( STR_UNSAVED_EXT_REF ) );
[ # # ]
920 : :
921 [ # # ][ # # ]: 0 : if( RET_NO == aBox.Execute())
922 : : {
923 [ # # ][ # # ]: 0 : SetError( ERRCODE_IO_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // this error code will produce no error message, but will break the further saving process
924 [ # # ]: 0 : }
925 : : }
926 : : } // fall through
927 : : case SFX_EVENT_SAVETODOC:
928 : : // #i108978# If no event is sent before saving, there will also be no "...DONE" event,
929 : : // and SAVE/SAVEAS can't be distinguished from SAVETO. So stream copying is only enabled
930 : : // if there is a SAVE/SAVEAS/SAVETO event first.
931 [ + + ]: 4 : if (pSheetSaveData)
932 [ + - ]: 2 : pSheetSaveData->SetInSupportedSave(true);
933 : 4 : break;
934 : : case SFX_EVENT_SAVEDOCDONE:
935 : : case SFX_EVENT_SAVEASDOCDONE:
936 : : {
937 : : // new positions are used after "save" and "save as", but not "save to"
938 [ + - ]: 4 : UseSheetSaveEntries(); // use positions from saved file for next saving
939 : : } // fall through
940 : : case SFX_EVENT_SAVETODOCDONE:
941 : : // only reset the flag, don't use the new positions
942 [ + - ]: 4 : if (pSheetSaveData)
943 [ + - ]: 4 : pSheetSaveData->SetInSupportedSave(false);
944 : 4 : break;
945 : : default:
946 : : {
947 : : }
948 : 2305 : break;
949 : : }
950 : 35455 : }
951 : 35455 : }
952 : :
953 : : // Inhalte fuer Organizer laden
954 : :
955 : :
956 : 0 : sal_Bool ScDocShell::LoadFrom( SfxMedium& rMedium )
957 : : {
958 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::LoadFrom" );
959 [ # # ]: 0 : LoadMediumGuard aLoadGuard(&aDocument);
960 [ # # ]: 0 : ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
961 : :
962 [ # # ][ # # ]: 0 : WaitObject aWait( GetActiveDialogParent() );
963 : :
964 : 0 : sal_Bool bRet = false;
965 : :
966 [ # # ]: 0 : if (GetMedium())
967 : : {
968 [ # # ][ # # ]: 0 : SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, false);
[ # # ]
969 [ # # ]: 0 : nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : com::sun::star::document::UpdateDocMode::NO_UPDATE;
970 : : }
971 : :
972 : : // until loading/saving only the styles in XML is implemented,
973 : : // load the whole file
974 [ # # ][ # # ]: 0 : bRet = LoadXML( &rMedium, NULL );
975 [ # # ]: 0 : InitItems();
976 : :
977 [ # # ]: 0 : SfxObjectShell::LoadFrom( rMedium );
978 : :
979 [ # # ][ # # ]: 0 : return bRet;
980 : : }
981 : :
982 : 0 : static void lcl_parseHtmlFilterOption(const OUString& rOption, LanguageType& rLang, bool& rDateConvert)
983 : : {
984 : 0 : OUStringBuffer aBuf;
985 [ # # ]: 0 : OUString aTokens[2];
986 : 0 : sal_Int32 n = rOption.getLength();
987 : 0 : const sal_Unicode* p = rOption.getStr();
988 : 0 : sal_Int32 nTokenId = 0;
989 [ # # ]: 0 : for (sal_Int32 i = 0; i < n; ++i)
990 : : {
991 : 0 : const sal_Unicode c = p[i];
992 [ # # ]: 0 : if (c == sal_Unicode(' '))
993 : : {
994 [ # # ]: 0 : if (aBuf.getLength())
995 [ # # ]: 0 : aTokens[nTokenId++] = aBuf.makeStringAndClear();
996 : : }
997 : : else
998 [ # # ]: 0 : aBuf.append(c);
999 : :
1000 [ # # ]: 0 : if (nTokenId >= 2)
1001 : 0 : break;
1002 : : }
1003 : :
1004 [ # # ]: 0 : if (aBuf.getLength())
1005 [ # # ]: 0 : aTokens[nTokenId] = aBuf.makeStringAndClear();
1006 : :
1007 : 0 : rLang = static_cast<LanguageType>(aTokens[0].toInt32());
1008 [ # # ][ # # ]: 0 : rDateConvert = static_cast<bool>(aTokens[1].toInt32());
1009 : 0 : }
1010 : :
1011 : 88 : sal_Bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
1012 : : {
1013 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ConvertFrom" );
1014 : :
1015 [ + - ]: 88 : LoadMediumGuard aLoadGuard(&aDocument);
1016 : :
1017 : 88 : sal_Bool bRet = false; // sal_False heisst Benutzerabbruch !!
1018 : : // bei Fehler: Fehler am Stream setzen!!
1019 : :
1020 [ + - ]: 88 : ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
1021 : :
1022 [ + - ][ + - ]: 88 : GetUndoManager()->Clear();
1023 : :
1024 : : // ob nach dem Import optimale Spaltenbreiten gesetzt werden sollen
1025 : 88 : sal_Bool bSetColWidths = false;
1026 : 88 : sal_Bool bSetSimpleTextColWidths = false;
1027 [ + - ][ + + ]: 90200 : ScColWidthParam aColWidthParam[MAXCOLCOUNT];
1028 : 88 : ScRange aColWidthRange;
1029 : : // ob nach dem Import optimale Zeilenhoehen gesetzt werden sollen
1030 : 88 : sal_Bool bSetRowHeights = false;
1031 : :
1032 [ + - ]: 88 : vector<ScDocRowHeightUpdater::TabRanges> aRecalcRowRangesArray;
1033 : :
1034 : : // Alle Filter brauchen die komplette Datei am Stueck (nicht asynchron),
1035 : : // darum vorher per CreateFileStream dafuer sorgen, dass die komplette
1036 : : // Datei uebertragen wird.
1037 [ + - ]: 88 : rMedium.GetPhysicalName(); //! CreateFileStream direkt rufen, wenn verfuegbar
1038 : :
1039 [ + - ][ + - ]: 88 : SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, false);
[ + - ]
1040 [ + + ]: 88 : nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : com::sun::star::document::UpdateDocMode::NO_UPDATE;
1041 : :
1042 [ + - ]: 88 : const SfxFilter* pFilter = rMedium.GetFilter();
1043 [ + - ]: 88 : if (pFilter)
1044 : : {
1045 [ + - ]: 88 : String aFltName = pFilter->GetFilterName();
1046 : :
1047 [ + - ]: 88 : sal_Bool bCalc3 = ( aFltName.EqualsAscii(pFilterSc30) );
1048 [ + - ]: 88 : sal_Bool bCalc4 = ( aFltName.EqualsAscii(pFilterSc40) );
1049 [ + - ][ + - ]: 88 : if (!bCalc3 && !bCalc4)
1050 : 88 : aDocument.SetInsertingFromOtherDoc( sal_True );
1051 : :
1052 [ + - ][ - + ]: 88 : if (aFltName.EqualsAscii(pFilterXML))
1053 [ # # ][ # # ]: 0 : bRet = LoadXML( &rMedium, NULL );
1054 [ + - ][ - + ]: 88 : else if (aFltName.EqualsAscii(pFilterSc10))
1055 : : {
1056 [ # # ]: 0 : SvStream* pStream = rMedium.GetInStream();
1057 [ # # ]: 0 : if (pStream)
1058 : : {
1059 [ # # ][ # # ]: 0 : FltError eError = ScFormatFilter::Get().ScImportStarCalc10( *pStream, &aDocument );
1060 [ # # ]: 0 : if (eError != eERR_OK)
1061 : : {
1062 [ # # ][ # # ]: 0 : if (!GetError())
1063 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1064 : : }
1065 : : else
1066 : 0 : bRet = sal_True;
1067 : : }
1068 : : }
1069 [ + - ][ - + ]: 88 : else if (aFltName.EqualsAscii(pFilterLotus))
1070 : : {
1071 [ # # ]: 0 : String sItStr;
1072 [ # # ]: 0 : SfxItemSet* pSet = rMedium.GetItemSet();
1073 : : const SfxPoolItem* pItem;
1074 [ # # ][ # # ]: 0 : if ( pSet && SFX_ITEM_SET ==
[ # # ]
1075 [ # # ]: 0 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1076 : : {
1077 [ # # ]: 0 : sItStr = ((const SfxStringItem*)pItem)->GetValue();
1078 : : }
1079 : :
1080 [ # # ]: 0 : if (sItStr.Len() == 0)
1081 : : {
1082 : : // default for lotus import (from API without options):
1083 : : // IBM_437 encoding
1084 [ # # ][ # # ]: 0 : sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_437 );
[ # # ]
1085 : : }
1086 : :
1087 : 0 : ScColumn::bDoubleAlloc = sal_True;
1088 [ # # ]: 0 : FltError eError = ScFormatFilter::Get().ScImportLotus123( rMedium, &aDocument,
1089 [ # # ][ # # ]: 0 : ScGlobal::GetCharsetValue(sItStr));
1090 : 0 : ScColumn::bDoubleAlloc = false;
1091 [ # # ]: 0 : if (eError != eERR_OK)
1092 : : {
1093 [ # # ][ # # ]: 0 : if (!GetError())
1094 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1095 : :
1096 [ # # ]: 0 : if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1097 : 0 : bRet = sal_True;
1098 : : }
1099 : : else
1100 : 0 : bRet = sal_True;
1101 : 0 : bSetColWidths = sal_True;
1102 [ # # ]: 0 : bSetRowHeights = sal_True;
1103 : : }
1104 [ + - ][ + - ]: 384 : else if ( aFltName.EqualsAscii(pFilterExcel4) || aFltName.EqualsAscii(pFilterExcel5) ||
[ + - ][ + - ]
[ + - ][ + + ]
[ + - ][ + - ]
[ + - ][ - + ]
[ + + ]
1105 [ + - ][ + - ]: 176 : aFltName.EqualsAscii(pFilterExcel95) || aFltName.EqualsAscii(pFilterExcel97) ||
1106 [ + - ][ + - ]: 60 : aFltName.EqualsAscii(pFilterEx4Temp) || aFltName.EqualsAscii(pFilterEx5Temp) ||
1107 [ + - ][ + - ]: 60 : aFltName.EqualsAscii(pFilterEx95Temp) || aFltName.EqualsAscii(pFilterEx97Temp) )
1108 : : {
1109 : 58 : EXCIMPFORMAT eFormat = EIF_AUTO;
1110 [ + - ][ + - ]: 58 : if ( aFltName.EqualsAscii(pFilterExcel4) || aFltName.EqualsAscii(pFilterEx4Temp) )
[ + - ][ - + ]
[ - + ]
1111 : 0 : eFormat = EIF_BIFF_LE4;
1112 [ + - ][ + - ]: 174 : else if ( aFltName.EqualsAscii(pFilterExcel5) || aFltName.EqualsAscii(pFilterExcel95) ||
[ + - ][ + - ]
[ + - ][ - + ]
[ - + ]
1113 [ + - ][ + - ]: 116 : aFltName.EqualsAscii(pFilterEx5Temp) || aFltName.EqualsAscii(pFilterEx95Temp) )
1114 : 0 : eFormat = EIF_BIFF5;
1115 [ + - ][ - + ]: 58 : else if ( aFltName.EqualsAscii(pFilterExcel97) || aFltName.EqualsAscii(pFilterEx97Temp) )
[ # # ][ # # ]
[ + - ]
1116 : 58 : eFormat = EIF_BIFF8;
1117 : :
1118 [ + - ]: 58 : MakeDrawLayer(); //! im Filter
1119 [ + - ]: 58 : CalcOutputFactor(); // prepare update of row height
1120 : 58 : ScColumn::bDoubleAlloc = true;
1121 [ + - ][ + - ]: 58 : FltError eError = ScFormatFilter::Get().ScImportExcel( rMedium, &aDocument, eFormat );
1122 : 58 : ScColumn::bDoubleAlloc = false;
1123 [ + - ]: 58 : aDocument.UpdateFontCharSet();
1124 [ + - ]: 58 : if ( aDocument.IsChartListenerCollectionNeedsUpdate() )
1125 [ + - ]: 58 : aDocument.UpdateChartListenerCollection(); //! fuer alle Importe?
1126 : :
1127 : : // all graphics objects must have names
1128 [ + - ]: 58 : aDocument.EnsureGraphicNames();
1129 : :
1130 [ - + ]: 58 : if (eError == SCWARN_IMPORT_RANGE_OVERFLOW)
1131 : : {
1132 [ # # ][ # # ]: 0 : if (!GetError())
1133 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1134 : 0 : bRet = sal_True;
1135 : : }
1136 [ + + ]: 58 : else if (eError != eERR_OK)
1137 : : {
1138 [ + - ][ + - ]: 3 : if (!GetError())
1139 [ + - ][ + - ]: 3 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1140 : : }
1141 : : else
1142 : 55 : bRet = true;
1143 : : }
1144 [ + - ][ + + ]: 30 : else if (aFltName.EqualsAscii(pFilterAscii))
1145 : : {
1146 [ + - ]: 6 : SfxItemSet* pSet = rMedium.GetItemSet();
1147 : : const SfxPoolItem* pItem;
1148 [ + - ]: 6 : ScAsciiOptions aOptions;
1149 : 6 : sal_Bool bOptInit = false;
1150 : :
1151 [ + - ][ - + ]: 12 : if ( pSet && SFX_ITEM_SET ==
[ - + ]
1152 [ + - ]: 6 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1153 : : {
1154 [ # # ]: 0 : aOptions.ReadFromString( ((const SfxStringItem*)pItem)->GetValue() );
1155 : 0 : bOptInit = sal_True;
1156 : : }
1157 : :
1158 [ + - ]: 6 : if ( !bOptInit )
1159 : : {
1160 : : // default for ascii import (from API without options):
1161 : : // ISO8859-1/MS_1252 encoding, comma, double quotes
1162 : :
1163 : 6 : aOptions.SetCharSet( RTL_TEXTENCODING_MS_1252 );
1164 [ + - ][ + - ]: 6 : aOptions.SetFieldSeps( rtl::OUString(',') );
[ + - ]
1165 : 6 : aOptions.SetTextSep( '"' );
1166 : : }
1167 : :
1168 : 6 : FltError eError = eERR_OK;
1169 : : bool bOverflowRow, bOverflowCol, bOverflowCell;
1170 : 6 : bOverflowRow = bOverflowCol = bOverflowCell = false;
1171 : :
1172 [ + - ][ + - ]: 6 : if( ! rMedium.IsStorage() )
1173 : : {
1174 [ + - ]: 6 : ScImportExport aImpEx( &aDocument );
1175 [ + - ]: 6 : aImpEx.SetExtOptions( aOptions );
1176 : :
1177 [ + - ]: 6 : SvStream* pInStream = rMedium.GetInStream();
1178 [ + - ]: 6 : if (pInStream)
1179 : : {
1180 : 6 : pInStream->SetStreamCharSet( aOptions.GetCharSet() );
1181 [ + - ]: 6 : pInStream->Seek( 0 );
1182 [ + - ][ + - ]: 6 : bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL() );
[ + - ][ + - ]
1183 [ + - ]: 6 : eError = bRet ? eERR_OK : SCERR_IMPORT_CONNECT;
1184 [ + - ]: 6 : aDocument.StartAllListeners();
1185 [ + - ]: 6 : aDocument.SetDirty();
1186 : 6 : bOverflowRow = aImpEx.IsOverflowRow();
1187 : 6 : bOverflowCol = aImpEx.IsOverflowCol();
1188 : 6 : bOverflowCell = aImpEx.IsOverflowCell();
1189 : : }
1190 : : else
1191 : : {
1192 : : OSL_FAIL( "No Stream" );
1193 [ + - ]: 6 : }
1194 : : }
1195 : :
1196 [ - + ]: 6 : if (eError != eERR_OK)
1197 : : {
1198 [ # # ][ # # ]: 0 : if (!GetError())
1199 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1200 : : }
1201 [ + - ][ + - ]: 6 : else if (!GetError() && (bOverflowRow || bOverflowCol || bOverflowCell))
[ + - ][ + - ]
[ - + ][ - + ]
1202 : : {
1203 : : // precedence: row, column, cell
1204 : : FltError nWarn = (bOverflowRow ? SCWARN_IMPORT_ROW_OVERFLOW :
1205 : : (bOverflowCol ? SCWARN_IMPORT_COLUMN_OVERFLOW :
1206 [ # # ][ # # ]: 0 : SCWARN_IMPORT_CELL_OVERFLOW));
1207 [ # # ][ # # ]: 0 : SetError( nWarn, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1208 : : }
1209 : 6 : bSetColWidths = sal_True;
1210 [ + - ]: 6 : bSetSimpleTextColWidths = sal_True;
1211 : : }
1212 [ + - ][ - + ]: 24 : else if (aFltName.EqualsAscii(pFilterDBase))
1213 : : {
1214 [ # # ]: 0 : String sItStr;
1215 [ # # ]: 0 : SfxItemSet* pSet = rMedium.GetItemSet();
1216 : : const SfxPoolItem* pItem;
1217 [ # # ][ # # ]: 0 : if ( pSet && SFX_ITEM_SET ==
[ # # ]
1218 [ # # ]: 0 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1219 : : {
1220 [ # # ]: 0 : sItStr = ((const SfxStringItem*)pItem)->GetValue();
1221 : : }
1222 : :
1223 [ # # ]: 0 : if (sItStr.Len() == 0)
1224 : : {
1225 : : // default for dBase import (from API without options):
1226 : : // IBM_850 encoding
1227 : :
1228 [ # # ][ # # ]: 0 : sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 );
[ # # ]
1229 : : }
1230 : :
1231 [ # # ]: 0 : ScDocRowHeightUpdater::TabRanges aRecalcRanges(0);
1232 [ # # ]: 0 : sal_uLong eError = DBaseImport( rMedium.GetPhysicalName(),
1233 [ # # ][ # # ]: 0 : ScGlobal::GetCharsetValue(sItStr), aColWidthParam, *aRecalcRanges.mpRanges );
[ # # ][ # # ]
1234 [ # # ]: 0 : aRecalcRowRangesArray.push_back(aRecalcRanges);
1235 : :
1236 [ # # ]: 0 : if (eError != eERR_OK)
1237 : : {
1238 [ # # ][ # # ]: 0 : if (!GetError())
1239 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1240 : 0 : bRet = ( eError == SCWARN_IMPORT_RANGE_OVERFLOW );
1241 : : }
1242 : : else
1243 : 0 : bRet = sal_True;
1244 : :
1245 : 0 : aColWidthRange.aStart.SetRow( 1 ); // Spaltenheader nicht
1246 : 0 : bSetColWidths = true;
1247 [ # # ][ # # ]: 0 : bSetSimpleTextColWidths = true;
1248 : : }
1249 [ + - ][ - + ]: 24 : else if (aFltName.EqualsAscii(pFilterDif))
1250 : : {
1251 [ # # ]: 0 : SvStream* pStream = rMedium.GetInStream();
1252 [ # # ]: 0 : if (pStream)
1253 : : {
1254 : : FltError eError;
1255 [ # # ]: 0 : String sItStr;
1256 [ # # ]: 0 : SfxItemSet* pSet = rMedium.GetItemSet();
1257 : : const SfxPoolItem* pItem;
1258 [ # # ][ # # ]: 0 : if ( pSet && SFX_ITEM_SET ==
[ # # ]
1259 [ # # ]: 0 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1260 : : {
1261 [ # # ]: 0 : sItStr = ((const SfxStringItem*)pItem)->GetValue();
1262 : : }
1263 : :
1264 [ # # ]: 0 : if (sItStr.Len() == 0)
1265 : : {
1266 : : // default for DIF import (from API without options):
1267 : : // ISO8859-1/MS_1252 encoding
1268 : :
1269 [ # # ][ # # ]: 0 : sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 );
[ # # ]
1270 : : }
1271 : :
1272 [ # # ]: 0 : eError = ScFormatFilter::Get().ScImportDif( *pStream, &aDocument, ScAddress(0,0,0),
1273 [ # # ][ # # ]: 0 : ScGlobal::GetCharsetValue(sItStr));
1274 [ # # ]: 0 : if (eError != eERR_OK)
1275 : : {
1276 [ # # ][ # # ]: 0 : if (!GetError())
1277 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1278 : :
1279 [ # # ]: 0 : if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1280 : 0 : bRet = sal_True;
1281 : : }
1282 : : else
1283 [ # # ]: 0 : bRet = sal_True;
1284 : : }
1285 : 0 : bSetColWidths = sal_True;
1286 : 0 : bSetSimpleTextColWidths = sal_True;
1287 : 0 : bSetRowHeights = sal_True;
1288 : : }
1289 [ + - ][ + + ]: 24 : else if (aFltName.EqualsAscii(pFilterSylk))
1290 : : {
1291 : 12 : FltError eError = SCERR_IMPORT_UNKNOWN;
1292 [ + - ][ + - ]: 12 : if( !rMedium.IsStorage() )
1293 : : {
1294 [ + - ]: 12 : ScImportExport aImpEx( &aDocument );
1295 : :
1296 [ + - ]: 12 : SvStream* pInStream = rMedium.GetInStream();
1297 [ + - ]: 12 : if (pInStream)
1298 : : {
1299 [ + - ]: 12 : pInStream->Seek( 0 );
1300 [ + - ][ + - ]: 12 : bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL(), SOT_FORMATSTR_ID_SYLK );
[ + - ][ + - ]
1301 [ + - ]: 12 : eError = bRet ? eERR_OK : SCERR_IMPORT_UNKNOWN;
1302 [ + - ]: 12 : aDocument.StartAllListeners();
1303 [ + - ]: 12 : aDocument.SetDirty();
1304 : : }
1305 : : else
1306 : : {
1307 : : OSL_FAIL( "No Stream" );
1308 [ + - ]: 12 : }
1309 : : }
1310 : :
1311 [ - + ][ # # ]: 12 : if ( eError != eERR_OK && !GetError() )
[ # # ][ - + ]
1312 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1313 : 12 : bSetColWidths = sal_True;
1314 : 12 : bSetSimpleTextColWidths = sal_True;
1315 : 12 : bSetRowHeights = sal_True;
1316 : : }
1317 [ + - ][ + + ]: 12 : else if (aFltName.EqualsAscii(pFilterQPro6))
1318 : : {
1319 : 9 : ScColumn::bDoubleAlloc = sal_True;
1320 [ + - ][ + - ]: 9 : FltError eError = ScFormatFilter::Get().ScImportQuattroPro( rMedium, &aDocument);
1321 : 9 : ScColumn::bDoubleAlloc = false;
1322 [ + + ]: 9 : if (eError != eERR_OK)
1323 : : {
1324 [ + - ][ + - ]: 3 : if (!GetError())
1325 [ + - ][ + - ]: 3 : SetError( eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1326 [ - + ]: 3 : if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1327 : 0 : bRet = sal_True;
1328 : : }
1329 : : else
1330 : 6 : bRet = sal_True;
1331 : : // TODO: Filter should set column widths. Not doing it here, it may
1332 : : // result in very narrow or wide columns, depending on content.
1333 : : // Setting row heights makes cells with font size attribution or
1334 : : // wrapping enabled look nicer..
1335 : 9 : bSetRowHeights = sal_True;
1336 : : }
1337 [ + - ][ - + ]: 3 : else if (aFltName.EqualsAscii(pFilterRtf))
1338 : : {
1339 : 0 : FltError eError = SCERR_IMPORT_UNKNOWN;
1340 [ # # ][ # # ]: 0 : if( !rMedium.IsStorage() )
1341 : : {
1342 [ # # ]: 0 : SvStream* pInStream = rMedium.GetInStream();
1343 [ # # ]: 0 : if (pInStream)
1344 : : {
1345 [ # # ]: 0 : pInStream->Seek( 0 );
1346 : 0 : ScRange aRange;
1347 [ # # ][ # # ]: 0 : eError = ScFormatFilter::Get().ScImportRTF( *pInStream, rMedium.GetBaseURL(), &aDocument, aRange );
[ # # ][ # # ]
[ # # ]
1348 [ # # ]: 0 : if (eError != eERR_OK)
1349 : : {
1350 [ # # ][ # # ]: 0 : if (!GetError())
1351 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1352 : :
1353 [ # # ]: 0 : if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1354 : 0 : bRet = sal_True;
1355 : : }
1356 : : else
1357 : 0 : bRet = sal_True;
1358 [ # # ]: 0 : aDocument.StartAllListeners();
1359 [ # # ]: 0 : aDocument.SetDirty();
1360 : 0 : bSetColWidths = sal_True;
1361 : 0 : bSetRowHeights = sal_True;
1362 : : }
1363 : : else
1364 : : {
1365 : : OSL_FAIL( "No Stream" );
1366 : : }
1367 : : }
1368 : :
1369 [ # # ][ # # ]: 0 : if ( eError != eERR_OK && !GetError() )
[ # # ][ # # ]
1370 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1371 : : }
1372 [ + - ][ + - ]: 3 : else if (aFltName.EqualsAscii(pFilterHtml) || aFltName.EqualsAscii(pFilterHtmlWebQ))
[ + - ][ + - ]
[ + - ]
1373 : : {
1374 : 3 : FltError eError = SCERR_IMPORT_UNKNOWN;
1375 [ + - ]: 3 : sal_Bool bWebQuery = aFltName.EqualsAscii(pFilterHtmlWebQ);
1376 [ + - ][ + - ]: 3 : if( !rMedium.IsStorage() )
1377 : : {
1378 [ + - ]: 3 : SvStream* pInStream = rMedium.GetInStream();
1379 [ + - ]: 3 : if (pInStream)
1380 : : {
1381 : 3 : LanguageType eLang = LANGUAGE_SYSTEM;
1382 : 3 : bool bDateConvert = false;
1383 [ + - ]: 3 : SfxItemSet* pSet = rMedium.GetItemSet();
1384 : : const SfxPoolItem* pItem;
1385 [ + - ][ - + ]: 6 : if ( pSet && SFX_ITEM_SET ==
[ - + ]
1386 [ + - ]: 3 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1387 : : {
1388 [ # # ]: 0 : String aFilterOption = (static_cast<const SfxStringItem*>(pItem))->GetValue();
1389 [ # # ][ # # ]: 0 : lcl_parseHtmlFilterOption(aFilterOption, eLang, bDateConvert);
[ # # ]
1390 : : }
1391 : :
1392 [ + - ]: 3 : pInStream->Seek( 0 );
1393 : 3 : ScRange aRange;
1394 : : // HTML macht eigenes ColWidth/RowHeight
1395 [ + - ]: 3 : CalcOutputFactor();
1396 [ + - ][ + - ]: 3 : SvNumberFormatter aNumFormatter(aDocument.GetServiceManager(), eLang);
1397 [ + - ]: 3 : eError = ScFormatFilter::Get().ScImportHTML( *pInStream, rMedium.GetBaseURL(), &aDocument, aRange,
1398 [ + - ][ + - ]: 3 : GetOutputFactor(), !bWebQuery, &aNumFormatter, bDateConvert );
[ + - ][ + - ]
[ + - ]
1399 [ - + ]: 3 : if (eError != eERR_OK)
1400 : : {
1401 [ # # ][ # # ]: 0 : if (!GetError())
1402 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1403 : :
1404 [ # # ]: 0 : if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1405 : 0 : bRet = sal_True;
1406 : : }
1407 : : else
1408 : 3 : bRet = sal_True;
1409 [ + - ]: 3 : aDocument.StartAllListeners();
1410 [ + - ][ + - ]: 3 : aDocument.SetDirty();
1411 : : }
1412 : : else
1413 : : {
1414 : : OSL_FAIL( "No Stream" );
1415 : : }
1416 : : }
1417 : :
1418 [ - + ][ # # ]: 3 : if ( eError != eERR_OK && !GetError() )
[ # # ][ - + ]
1419 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1420 : : }
1421 : : else
1422 : : {
1423 [ # # ][ # # ]: 0 : if (!GetError())
1424 [ # # ][ # # ]: 0 : SetError(SCERR_IMPORT_NI, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1425 : : }
1426 : :
1427 [ + - ]: 88 : if (!bCalc3)
1428 [ + - ]: 88 : aDocument.SetInsertingFromOtherDoc( false );
1429 : : }
1430 : : else
1431 : : {
1432 : : OSL_FAIL("Kein Filter bei ConvertFrom");
1433 : : }
1434 : :
1435 [ + - ]: 88 : InitItems();
1436 [ + - ]: 88 : CalcOutputFactor();
1437 [ + + ][ + + ]: 88 : if ( bRet && (bSetColWidths || bSetRowHeights) )
[ + + ]
1438 : : { // Spaltenbreiten/Zeilenhoehen anpassen, Basis 100% Zoom
1439 [ + - ]: 24 : Fraction aZoom( 1, 1 );
1440 [ + - ]: 24 : double nPPTX = ScGlobal::nScreenPPTX * (double) aZoom
1441 [ + - ]: 24 : / GetOutputFactor(); // Faktor ist Drucker zu Bildschirm
1442 [ + - ]: 24 : double nPPTY = ScGlobal::nScreenPPTY * (double) aZoom;
1443 [ + - ]: 24 : VirtualDevice aVirtDev;
1444 : : // all sheets (for Excel import)
1445 [ + - ]: 24 : SCTAB nTabCount = aDocument.GetTableCount();
1446 [ + + ]: 48 : for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1447 : : {
1448 : : SCCOL nEndCol;
1449 : : SCROW nEndRow;
1450 [ + - ]: 24 : aDocument.GetCellArea( nTab, nEndCol, nEndRow );
1451 : 24 : aColWidthRange.aEnd.SetCol( nEndCol );
1452 : 24 : aColWidthRange.aEnd.SetRow( nEndRow );
1453 [ + - ]: 24 : ScMarkData aMark;
1454 [ + - ]: 24 : aMark.SetMarkArea( aColWidthRange );
1455 [ + - ]: 24 : aMark.MarkToMulti();
1456 : : // Reihenfolge erst Breite dann Hoehe ist wichtig (vergl. hund.rtf)
1457 [ + + ]: 24 : if ( bSetColWidths )
1458 : : {
1459 [ + + ]: 228 : for ( SCCOL nCol=0; nCol <= nEndCol; nCol++ )
1460 : : {
1461 [ - + ]: 210 : if (!bSetSimpleTextColWidths)
1462 : 0 : aColWidthParam[nCol].mbSimpleText = false;
1463 : :
1464 : : sal_uInt16 nWidth = aDocument.GetOptimalColWidth(
1465 : : nCol, nTab, &aVirtDev, nPPTX, nPPTY, aZoom, aZoom, false, &aMark,
1466 [ + - ]: 210 : &aColWidthParam[nCol] );
1467 : : aDocument.SetColWidth( nCol, nTab,
1468 [ + - ]: 210 : nWidth + (sal_uInt16)ScGlobal::nLastColWidthExtra );
1469 : : }
1470 : : }
1471 [ + - ]: 24 : }
1472 : :
1473 [ + + ]: 24 : if (bSetRowHeights)
1474 : : {
1475 : : // Update all rows in all tables.
1476 [ + - ]: 18 : ScSizeDeviceProvider aProv(this);
1477 [ + - ]: 18 : ScDocRowHeightUpdater aUpdater(aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), NULL);
1478 [ + - ][ + - ]: 18 : aUpdater.update();
1479 : : }
1480 [ - + ]: 6 : else if (!aRecalcRowRangesArray.empty())
1481 : : {
1482 : : // Update only specified row ranges for better performance.
1483 [ # # ]: 0 : ScSizeDeviceProvider aProv(this);
1484 [ # # ]: 0 : ScDocRowHeightUpdater aUpdater(aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), &aRecalcRowRangesArray);
1485 [ # # ][ # # ]: 0 : aUpdater.update();
1486 [ + - ]: 24 : }
1487 : : }
1488 [ + - ]: 88 : FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
1489 : :
1490 : :
1491 : : // invalidate eventually temporary table areas
1492 [ + + ]: 88 : if ( bRet )
1493 [ + - ]: 82 : aDocument.InvalidateTableArea();
1494 : :
1495 : 88 : bIsEmpty = false;
1496 : :
1497 [ + - ]: 88 : return bRet;
1498 : : }
1499 : :
1500 : :
1501 : 4 : ScDocShell::PrepareSaveGuard::PrepareSaveGuard( ScDocShell& rDocShell )
1502 : 4 : : mrDocShell( rDocShell)
1503 : : {
1504 : : // DoEnterHandler not here (because of AutoSave), is in ExecuteSave.
1505 : :
1506 : 4 : ScChartListenerCollection* pCharts = mrDocShell.aDocument.GetChartListenerCollection();
1507 [ + - ]: 4 : if (pCharts)
1508 : 4 : pCharts->UpdateDirtyCharts(); // Charts to be updated.
1509 : 4 : mrDocShell.aDocument.StopTemporaryChartLock();
1510 [ - + ]: 4 : if (mrDocShell.pAutoStyleList)
1511 : 0 : mrDocShell.pAutoStyleList->ExecuteAllNow(); // Execute template timeouts now.
1512 [ + - ]: 4 : if (mrDocShell.aDocument.HasExternalRefManager())
1513 : : {
1514 : 4 : ScExternalRefManager* pRefMgr = mrDocShell.aDocument.GetExternalRefManager();
1515 [ - + ][ - + ]: 4 : if (pRefMgr && pRefMgr->hasExternalData())
[ + - ]
1516 : : {
1517 : 0 : pRefMgr->setAllCacheTableReferencedStati( false);
1518 : 0 : mrDocShell.aDocument.MarkUsedExternalReferences(); // Mark tables of external references to be written.
1519 : : }
1520 : : }
1521 [ + - ]: 4 : if (mrDocShell.GetCreateMode()== SFX_CREATE_MODE_STANDARD)
1522 [ + - ]: 4 : mrDocShell.SfxObjectShell::SetVisArea( Rectangle() ); // "Normally" worked on => no VisArea.
1523 : 4 : }
1524 : :
1525 : 4 : ScDocShell::PrepareSaveGuard::~PrepareSaveGuard()
1526 : : {
1527 [ + - ]: 4 : if (mrDocShell.aDocument.HasExternalRefManager())
1528 : : {
1529 : 4 : ScExternalRefManager* pRefMgr = mrDocShell.aDocument.GetExternalRefManager();
1530 [ - + ][ - + ]: 4 : if (pRefMgr && pRefMgr->hasExternalData())
[ + - ]
1531 : : {
1532 : : // Prevent accidental data loss due to lack of knowledge.
1533 : 0 : pRefMgr->setAllCacheTableReferencedStati( true);
1534 : : }
1535 : : }
1536 : 4 : }
1537 : :
1538 : :
1539 : 0 : sal_Bool ScDocShell::Save()
1540 : : {
1541 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::Save" );
1542 : :
1543 [ # # ]: 0 : ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
1544 : :
1545 [ # # ]: 0 : PrepareSaveGuard aPrepareGuard( *this);
1546 : :
1547 : : // wait cursor is handled with progress bar
1548 [ # # ]: 0 : sal_Bool bRet = SfxObjectShell::Save();
1549 [ # # ]: 0 : if( bRet )
1550 [ # # ][ # # ]: 0 : bRet = SaveXML( GetMedium(), NULL );
1551 [ # # ]: 0 : return bRet;
1552 : : }
1553 : :
1554 : :
1555 : 4 : sal_Bool ScDocShell::SaveAs( SfxMedium& rMedium )
1556 : : {
1557 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::SaveAs" );
1558 : :
1559 [ + - ]: 4 : ScTabViewShell* pViewShell = GetBestViewShell();
1560 [ + - ]: 4 : bool bNeedsRehash = ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_SHA1);
1561 [ - + ]: 4 : if (bNeedsRehash)
1562 : : // legacy xls hash double-hashed by SHA1 is also supported.
1563 [ # # ]: 0 : bNeedsRehash = ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_XL, PASSHASH_SHA1);
1564 : :
1565 [ + - ][ - + ]: 4 : if (pViewShell && bNeedsRehash)
1566 : : {
1567 [ # # ][ # # ]: 0 : if (!pViewShell->ExecuteRetypePassDlg(PASSHASH_SHA1))
1568 : : // password re-type cancelled. Don't save the document.
1569 : 0 : return false;
1570 : : }
1571 : :
1572 : :
1573 [ + - ]: 4 : ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
1574 : :
1575 [ + - ]: 4 : PrepareSaveGuard aPrepareGuard( *this);
1576 : :
1577 : : // wait cursor is handled with progress bar
1578 [ + - ]: 4 : sal_Bool bRet = SfxObjectShell::SaveAs( rMedium );
1579 [ + - ]: 4 : if( bRet )
1580 [ + - ][ + - ]: 4 : bRet = SaveXML( &rMedium, NULL );
1581 : :
1582 [ + - ]: 4 : return bRet;
1583 : : }
1584 : :
1585 : :
1586 : 0 : sal_Bool ScDocShell::IsInformationLost()
1587 : : {
1588 : : //!!! bei Gelegenheit ein korrekte eigene Behandlung einbauen
1589 : :
1590 : 0 : return SfxObjectShell::IsInformationLost();
1591 : : }
1592 : :
1593 : : namespace {
1594 : :
1595 : : // Xcl-like column width measured in characters of standard font.
1596 : 0 : sal_Int32 lcl_ScDocShell_GetColWidthInChars( sal_uInt16 nWidth )
1597 : : {
1598 : 0 : double f = nWidth;
1599 : 0 : f *= 1328.0 / 25.0;
1600 : 0 : f += 90.0;
1601 : 0 : f *= 1.0 / 23.0;
1602 : 0 : f /= 256.0;
1603 : :
1604 : 0 : return sal_Int32( f );
1605 : : }
1606 : :
1607 : :
1608 : 0 : void lcl_ScDocShell_GetFixedWidthString( rtl::OUString& rStr, const ScDocument& rDoc,
1609 : : SCTAB nTab, SCCOL nCol, sal_Bool bValue, SvxCellHorJustify eHorJust )
1610 : : {
1611 : 0 : rtl::OUString aString = rStr;
1612 : : sal_Int32 nLen = lcl_ScDocShell_GetColWidthInChars(
1613 [ # # ]: 0 : rDoc.GetColWidth( nCol, nTab ) );
1614 : : //If the text won't fit in the column
1615 [ # # ]: 0 : if ( nLen < aString.getLength() )
1616 : : {
1617 : 0 : rtl::OUStringBuffer aReplacement;
1618 [ # # ]: 0 : if (bValue)
1619 [ # # ]: 0 : aReplacement.appendAscii(RTL_CONSTASCII_STRINGPARAM("###"));
1620 : : else
1621 [ # # ]: 0 : aReplacement.append(aString);
1622 : : //truncate to the number of characters that should fit, even in the
1623 : : //bValue case nLen might be < len ###
1624 [ # # ][ # # ]: 0 : aString = comphelper::string::truncateToLength(aReplacement, nLen).makeStringAndClear();
1625 : : }
1626 [ # # ]: 0 : if ( nLen > aString.getLength() )
1627 : : {
1628 [ # # ][ # # ]: 0 : if ( bValue && eHorJust == SVX_HOR_JUSTIFY_STANDARD )
1629 : 0 : eHorJust = SVX_HOR_JUSTIFY_RIGHT;
1630 : 0 : sal_Int32 nBlanks = nLen - aString.getLength();
1631 [ # # # ]: 0 : switch ( eHorJust )
1632 : : {
1633 : : case SVX_HOR_JUSTIFY_RIGHT:
1634 : : {
1635 : 0 : rtl::OUStringBuffer aTmp;
1636 [ # # ][ # # ]: 0 : aTmp = comphelper::string::padToLength( aTmp, nBlanks, ' ' );
1637 [ # # ][ # # ]: 0 : aString = aTmp.append(aString).makeStringAndClear();
1638 : : }
1639 : 0 : break;
1640 : : case SVX_HOR_JUSTIFY_CENTER:
1641 : : {
1642 : 0 : sal_Int32 nLeftPad = nBlanks / 2;
1643 : 0 : rtl::OUStringBuffer aTmp;
1644 [ # # ]: 0 : comphelper::string::padToLength( aTmp, nLeftPad, ' ' );
1645 [ # # ]: 0 : aTmp.append(aString);
1646 [ # # ]: 0 : comphelper::string::padToLength( aTmp, nLen, ' ' );
1647 [ # # ]: 0 : aString = aTmp.makeStringAndClear();
1648 : : }
1649 : 0 : break;
1650 : : default:
1651 : : {
1652 [ # # ]: 0 : rtl::OUStringBuffer aTmp(aString);
1653 [ # # ]: 0 : comphelper::string::padToLength( aTmp, nLen, ' ' );
1654 [ # # ]: 0 : aString = aTmp.makeStringAndClear();
1655 : : }
1656 : : }
1657 : : }
1658 : 0 : rStr = aString;
1659 : 0 : }
1660 : :
1661 : :
1662 : 0 : void lcl_ScDocShell_WriteEmptyFixedWidthString( SvStream& rStream,
1663 : : const ScDocument& rDoc, SCTAB nTab, SCCOL nCol )
1664 : : {
1665 : 0 : rtl::OUString aString;
1666 : : lcl_ScDocShell_GetFixedWidthString( aString, rDoc, nTab, nCol, false,
1667 [ # # ]: 0 : SVX_HOR_JUSTIFY_STANDARD );
1668 [ # # ][ # # ]: 0 : rStream.WriteUnicodeOrByteText( aString );
[ # # ]
1669 : 0 : }
1670 : :
1671 : : template<typename StrT, typename SepCharT>
1672 : 0 : sal_Int32 getTextSepPos(
1673 : : const StrT& rStr, const ScImportOptions& rAsciiOpt, const SepCharT& rTextSep, const SepCharT& rFieldSep, bool& rNeedQuotes)
1674 : : {
1675 : : // #i116636# quotes are needed if text delimiter (quote), field delimiter,
1676 : : // or LF is in the cell text.
1677 : 0 : sal_Int32 nPos = rStr.indexOf(rTextSep);
1678 [ # # ][ # # ]: 0 : rNeedQuotes = rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1679 : : (rStr.indexOf(rFieldSep) >= 0) ||
1680 : : (rStr.indexOf(sal_Unicode(_LF)) >= 0);
1681 : 0 : return nPos;
1682 : : }
1683 : :
1684 : : template<typename StrT, typename StrBufT>
1685 : 0 : void escapeTextSep(sal_Int32 nPos, const StrT& rStrDelim, StrT& rStr)
1686 : : {
1687 [ # # ][ # # ]: 0 : while (nPos >= 0)
1688 : : {
1689 [ # # ][ # # ]: 0 : StrBufT aBuf(rStr);
1690 [ # # # # ]: 0 : aBuf.insert(nPos, rStrDelim);
1691 [ # # ]: 0 : rStr = aBuf.makeStringAndClear();
1692 : 0 : nPos = rStr.indexOf(rStrDelim, nPos+1+rStrDelim.getLength());
1693 : : }
1694 : 0 : }
1695 : :
1696 : : }
1697 : :
1698 : 0 : void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt )
1699 : : {
1700 : 0 : sal_Unicode cDelim = rAsciiOpt.nFieldSepCode;
1701 : 0 : sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
1702 : 0 : CharSet eCharSet = rAsciiOpt.eCharSet;
1703 : 0 : bool bFixedWidth = rAsciiOpt.bFixedWidth;
1704 : 0 : bool bSaveAsShown = rAsciiOpt.bSaveAsShown;
1705 : 0 : bool bShowFormulas = rAsciiOpt.bSaveFormulas;
1706 : :
1707 : 0 : CharSet eOldCharSet = rStream.GetStreamCharSet();
1708 : 0 : rStream.SetStreamCharSet( eCharSet );
1709 : 0 : sal_uInt16 nOldNumberFormatInt = rStream.GetNumberFormatInt();
1710 : 0 : rtl::OString aStrDelimEncoded; // only used if not Unicode
1711 : 0 : rtl::OUString aStrDelimDecoded; // only used if context encoding
1712 : 0 : rtl::OString aDelimEncoded;
1713 : 0 : rtl::OUString aDelimDecoded;
1714 : : bool bContextOrNotAsciiEncoding;
1715 [ # # ]: 0 : if ( eCharSet == RTL_TEXTENCODING_UNICODE )
1716 : : {
1717 [ # # ]: 0 : rStream.StartWritingUnicodeText();
1718 : 0 : bContextOrNotAsciiEncoding = false;
1719 : : }
1720 : : else
1721 : : {
1722 [ # # ]: 0 : aStrDelimEncoded = rtl::OString(&cStrDelim, 1, eCharSet);
1723 [ # # ]: 0 : aDelimEncoded = rtl::OString(&cDelim, 1, eCharSet);
1724 : : rtl_TextEncodingInfo aInfo;
1725 : 0 : aInfo.StructSize = sizeof(aInfo);
1726 [ # # ][ # # ]: 0 : if ( rtl_getTextEncodingInfo( eCharSet, &aInfo ) )
1727 : : {
1728 : : bContextOrNotAsciiEncoding =
1729 : : (((aInfo.Flags & RTL_TEXTENCODING_INFO_CONTEXT) != 0) ||
1730 [ # # ][ # # ]: 0 : ((aInfo.Flags & RTL_TEXTENCODING_INFO_ASCII) == 0));
1731 [ # # ]: 0 : if ( bContextOrNotAsciiEncoding )
1732 : : {
1733 [ # # ]: 0 : aStrDelimDecoded = rtl::OStringToOUString(aStrDelimEncoded, eCharSet);
1734 [ # # ]: 0 : aDelimDecoded = rtl::OStringToOUString(aDelimEncoded, eCharSet);
1735 : : }
1736 : : }
1737 : : else
1738 : 0 : bContextOrNotAsciiEncoding = false;
1739 : : }
1740 : :
1741 : 0 : SCCOL nStartCol = 0;
1742 : 0 : SCROW nStartRow = 0;
1743 [ # # ]: 0 : SCTAB nTab = GetSaveTab();
1744 : : SCCOL nEndCol;
1745 : : SCROW nEndRow;
1746 [ # # ]: 0 : aDocument.GetCellArea( nTab, nEndCol, nEndRow );
1747 : :
1748 [ # # ][ # # ]: 0 : ScProgress aProgress( this, ScGlobal::GetRscString( STR_SAVE_DOC ), nEndRow );
1749 : :
1750 : 0 : rtl::OUString aString;
1751 : :
1752 [ # # ]: 0 : bool bTabProtect = aDocument.IsTabProtected( nTab );
1753 : :
1754 : : SCCOL nCol;
1755 : : SCROW nRow;
1756 : 0 : SCCOL nNextCol = nStartCol;
1757 : 0 : SCROW nNextRow = nStartRow;
1758 : : SCCOL nEmptyCol;
1759 : : SCROW nEmptyRow;
1760 [ # # ]: 0 : SvNumberFormatter& rFormatter = *aDocument.GetFormatTable();
1761 : :
1762 : : ScHorizontalCellIterator aIter( &aDocument, nTab, nStartCol, nStartRow,
1763 [ # # ]: 0 : nEndCol, nEndRow );
1764 : : ScBaseCell* pCell;
1765 [ # # ][ # # ]: 0 : while ( ( pCell = aIter.GetNext( nCol, nRow ) ) != NULL )
1766 : : {
1767 : 0 : bool bProgress = false; // only upon line change
1768 [ # # ]: 0 : if ( nNextRow < nRow )
1769 : : { // empty rows or/and empty columns up to end of row
1770 : 0 : bProgress = true;
1771 [ # # ]: 0 : for ( nEmptyCol = nNextCol; nEmptyCol < nEndCol; nEmptyCol++ )
1772 : : { // remaining columns of last row
1773 [ # # ]: 0 : if ( bFixedWidth )
1774 : : lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1775 [ # # ]: 0 : aDocument, nTab, nEmptyCol );
1776 [ # # ]: 0 : else if ( cDelim != 0 )
1777 [ # # ]: 0 : rStream.WriteUniOrByteChar( cDelim );
1778 : : }
1779 [ # # ]: 0 : endlub( rStream );
1780 : 0 : nNextRow++;
1781 [ # # ]: 0 : for ( nEmptyRow = nNextRow; nEmptyRow < nRow; nEmptyRow++ )
1782 : : { // completely empty rows
1783 [ # # ]: 0 : for ( nEmptyCol = nStartCol; nEmptyCol < nEndCol; nEmptyCol++ )
1784 : : {
1785 [ # # ]: 0 : if ( bFixedWidth )
1786 : : lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1787 [ # # ]: 0 : aDocument, nTab, nEmptyCol );
1788 [ # # ]: 0 : else if ( cDelim != 0 )
1789 [ # # ]: 0 : rStream.WriteUniOrByteChar( cDelim );
1790 : : }
1791 [ # # ]: 0 : endlub( rStream );
1792 : : }
1793 [ # # ]: 0 : for ( nEmptyCol = nStartCol; nEmptyCol < nCol; nEmptyCol++ )
1794 : : { // empty columns at beginning of row
1795 [ # # ]: 0 : if ( bFixedWidth )
1796 : : lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1797 [ # # ]: 0 : aDocument, nTab, nEmptyCol );
1798 [ # # ]: 0 : else if ( cDelim != 0 )
1799 [ # # ]: 0 : rStream.WriteUniOrByteChar( cDelim );
1800 : : }
1801 : 0 : nNextRow = nRow;
1802 : : }
1803 [ # # ]: 0 : else if ( nNextCol < nCol )
1804 : : { // empty columns in same row
1805 [ # # ]: 0 : for ( nEmptyCol = nNextCol; nEmptyCol < nCol; nEmptyCol++ )
1806 : : { // columns in between
1807 [ # # ]: 0 : if ( bFixedWidth )
1808 : : lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1809 [ # # ]: 0 : aDocument, nTab, nEmptyCol );
1810 [ # # ]: 0 : else if ( cDelim != 0 )
1811 [ # # ]: 0 : rStream.WriteUniOrByteChar( cDelim );
1812 : : }
1813 : : }
1814 [ # # ]: 0 : if ( nCol == nEndCol )
1815 : : {
1816 : 0 : bProgress = true;
1817 : 0 : nNextCol = nStartCol;
1818 : 0 : nNextRow = nRow + 1;
1819 : : }
1820 : : else
1821 : 0 : nNextCol = nCol + 1;
1822 : :
1823 : 0 : CellType eType = pCell->GetCellType();
1824 [ # # ]: 0 : if ( bTabProtect )
1825 : : {
1826 : : const ScProtectionAttr* pProtAttr =
1827 : : (const ScProtectionAttr*) aDocument.GetAttr(
1828 [ # # ]: 0 : nCol, nRow, nTab, ATTR_PROTECTION );
1829 [ # # ][ # # ]: 0 : if ( pProtAttr->GetHideCell() ||
[ # # # # ]
[ # # ]
1830 : : ( eType == CELLTYPE_FORMULA && bShowFormulas &&
1831 : 0 : pProtAttr->GetHideFormula() ) )
1832 : 0 : eType = CELLTYPE_NONE; // hide
1833 : : }
1834 : : bool bString;
1835 [ # # # # : 0 : switch ( eType )
# # ]
1836 : : {
1837 : : case CELLTYPE_NOTE:
1838 : : case CELLTYPE_NONE:
1839 : 0 : aString = rtl::OUString();
1840 : 0 : bString = false;
1841 : 0 : break;
1842 : : case CELLTYPE_FORMULA :
1843 : : {
1844 : : sal_uInt16 nErrCode;
1845 [ # # ]: 0 : if ( bShowFormulas )
1846 : : {
1847 [ # # ][ # # ]: 0 : ((ScFormulaCell*)pCell)->GetFormula( aString );
1848 : 0 : bString = true;
1849 : : }
1850 [ # # ][ # # ]: 0 : else if ( ( nErrCode = ((ScFormulaCell*)pCell)->GetErrCode() ) != 0 )
[ # # ]
1851 : : {
1852 [ # # ][ # # ]: 0 : aString = ScGlobal::GetErrorString( nErrCode );
[ # # ]
1853 : 0 : bString = true;
1854 : : }
1855 [ # # ][ # # ]: 0 : else if ( ((ScFormulaCell*)pCell)->IsValue() )
[ # # ]
1856 : : {
1857 : : sal_uInt32 nFormat;
1858 [ # # ]: 0 : aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1859 [ # # ][ # # ]: 0 : if ( bFixedWidth || bSaveAsShown )
1860 : : {
1861 : : Color* pDummy;
1862 [ # # ]: 0 : ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1863 [ # # ][ # # ]: 0 : bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
[ # # ]
1864 : : }
1865 : : else
1866 : : {
1867 [ # # ]: 0 : ScCellFormat::GetInputString( pCell, nFormat, aString, rFormatter );
1868 : 0 : bString = false;
1869 : : }
1870 : : }
1871 : : else
1872 : : {
1873 [ # # ]: 0 : if ( bSaveAsShown )
1874 : : {
1875 : : sal_uInt32 nFormat;
1876 [ # # ]: 0 : aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1877 : : Color* pDummy;
1878 [ # # ]: 0 : ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1879 : : }
1880 : : else
1881 [ # # ][ # # ]: 0 : aString = ((ScFormulaCell*)pCell)->GetString();
1882 : 0 : bString = true;
1883 : : }
1884 : : }
1885 : 0 : break;
1886 : : case CELLTYPE_STRING :
1887 [ # # ]: 0 : if ( bSaveAsShown )
1888 : : {
1889 : : sal_uInt32 nFormat;
1890 [ # # ]: 0 : aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1891 : : Color* pDummy;
1892 [ # # ]: 0 : ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1893 : : }
1894 : : else
1895 : 0 : aString = ((ScStringCell*)pCell)->GetString();
1896 : 0 : bString = true;
1897 : 0 : break;
1898 : : case CELLTYPE_EDIT :
1899 : : {
1900 : : const EditTextObject* pObj;
1901 [ # # ]: 0 : static_cast<const ScEditCell*>(pCell)->GetData( pObj);
1902 [ # # ]: 0 : EditEngine& rEngine = aDocument.GetEditEngine();
1903 [ # # ]: 0 : rEngine.SetText( *pObj);
1904 [ # # ][ # # ]: 0 : aString = rEngine.GetText(); // including LF
[ # # ]
1905 : 0 : bString = true;
1906 : : }
1907 : 0 : break;
1908 : : case CELLTYPE_VALUE :
1909 : : {
1910 : : sal_uInt32 nFormat;
1911 [ # # ]: 0 : aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1912 [ # # ][ # # ]: 0 : if ( bFixedWidth || bSaveAsShown )
1913 : : {
1914 : : Color* pDummy;
1915 [ # # ]: 0 : ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1916 [ # # ][ # # ]: 0 : bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
[ # # ]
1917 : : }
1918 : : else
1919 : : {
1920 [ # # ]: 0 : ScCellFormat::GetInputString( pCell, nFormat, aString, rFormatter );
1921 : 0 : bString = false;
1922 : : }
1923 : : }
1924 : 0 : break;
1925 : : default:
1926 : : OSL_FAIL( "ScDocShell::AsciiSave: unknown CellType" );
1927 : 0 : aString = rtl::OUString();
1928 : 0 : bString = false;
1929 : : }
1930 : :
1931 [ # # ]: 0 : if ( bFixedWidth )
1932 : : {
1933 : : SvxCellHorJustify eHorJust = (SvxCellHorJustify)
1934 : : ((const SvxHorJustifyItem*) aDocument.GetAttr( nCol, nRow,
1935 [ # # ]: 0 : nTab, ATTR_HOR_JUSTIFY ))->GetValue();
1936 : : lcl_ScDocShell_GetFixedWidthString( aString, aDocument, nTab, nCol,
1937 [ # # ]: 0 : !bString, eHorJust );
1938 [ # # ][ # # ]: 0 : rStream.WriteUnicodeOrByteText( aString );
[ # # ]
1939 : : }
1940 : : else
1941 : : {
1942 : 0 : rtl::OUString aUniString = aString;//remove that later
1943 [ # # ][ # # ]: 0 : if (!bString && cStrDelim != 0 && !aUniString.isEmpty())
[ # # ][ # # ]
1944 : : {
1945 : 0 : sal_Unicode c = aUniString[0];
1946 : : bString = (c == cStrDelim || c == ' ' ||
1947 : 0 : aUniString[aUniString.getLength()-1] == ' ' ||
1948 [ # # # # ]: 0 : aUniString.indexOf(cStrDelim) >= 0);
[ # # ][ # # ]
1949 [ # # ][ # # ]: 0 : if (!bString && cDelim != 0)
1950 : 0 : bString = (aUniString.indexOf(cDelim) >= 0);
1951 : : }
1952 [ # # ]: 0 : if ( bString )
1953 : : {
1954 [ # # ]: 0 : if ( cStrDelim != 0 ) //@ BugId 55355
1955 : : {
1956 [ # # ]: 0 : if ( eCharSet == RTL_TEXTENCODING_UNICODE )
1957 : : {
1958 : 0 : bool bNeedQuotes = false;
1959 : : sal_Int32 nPos = getTextSepPos(
1960 : 0 : aUniString, rAsciiOpt, cStrDelim, cDelim, bNeedQuotes);
1961 : :
1962 : : escapeTextSep<rtl::OUString, rtl::OUStringBuffer>(
1963 [ # # ]: 0 : nPos, rtl::OUString(cStrDelim), aUniString);
1964 : :
1965 [ # # ]: 0 : if ( bNeedQuotes )
1966 [ # # ]: 0 : rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
1967 [ # # ]: 0 : write_uInt16s_FromOUString(rStream, aUniString);
1968 [ # # ]: 0 : if ( bNeedQuotes )
1969 [ # # ]: 0 : rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
1970 : : }
1971 : : else
1972 : : {
1973 : : // This is nasty. The Unicode to byte encoding
1974 : : // may convert typographical quotation marks to ASCII
1975 : : // quotation marks, which may interfer with the delimiter,
1976 : : // so we have to escape delimiters after the string has
1977 : : // been encoded. Since this may happen also with UTF-8
1978 : : // encoded typographical quotation marks if such was
1979 : : // specified as a delimiter we have to check for the full
1980 : : // encoded delimiter string, not just one character.
1981 : : // Now for RTL_TEXTENCODING_ISO_2022_... and similar brain
1982 : : // dead encodings where one code point (and especially a
1983 : : // low ASCII value) may represent different characters, we
1984 : : // have to convert forth and back and forth again. Same for
1985 : : // UTF-7 since it is a context sensitive encoding too.
1986 : :
1987 [ # # ]: 0 : if ( bContextOrNotAsciiEncoding )
1988 : : {
1989 : : // to byte encoding
1990 [ # # ]: 0 : rtl::OString aStrEnc = rtl::OUStringToOString(aUniString, eCharSet);
1991 : : // back to Unicode
1992 [ # # ]: 0 : rtl::OUString aStrDec = rtl::OStringToOUString(aStrEnc, eCharSet);
1993 : :
1994 : : // search on re-decoded string
1995 : 0 : bool bNeedQuotes = false;
1996 : : sal_Int32 nPos = getTextSepPos(
1997 : 0 : aStrDec, rAsciiOpt, aStrDelimDecoded, aDelimDecoded, bNeedQuotes);
1998 : :
1999 : : escapeTextSep<rtl::OUString, rtl::OUStringBuffer>(
2000 [ # # ]: 0 : nPos, aStrDelimDecoded, aStrDec);
2001 : :
2002 : : // write byte re-encoded
2003 [ # # ]: 0 : if ( bNeedQuotes )
2004 [ # # ]: 0 : rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
2005 [ # # ][ # # ]: 0 : rStream.WriteUnicodeOrByteText( aStrDec, eCharSet );
[ # # ]
2006 [ # # ]: 0 : if ( bNeedQuotes )
2007 [ # # ]: 0 : rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
2008 : : }
2009 : : else
2010 : : {
2011 [ # # ]: 0 : rtl::OString aStrEnc = rtl::OUStringToOString(aUniString, eCharSet);
2012 : :
2013 : : // search on encoded string
2014 : 0 : bool bNeedQuotes = false;
2015 : : sal_Int32 nPos = getTextSepPos(
2016 : 0 : aStrEnc, rAsciiOpt, aStrDelimEncoded, aDelimEncoded, bNeedQuotes);
2017 : :
2018 : : escapeTextSep<rtl::OString, rtl::OStringBuffer>(
2019 [ # # ]: 0 : nPos, aStrDelimEncoded, aStrEnc);
2020 : :
2021 : : // write byte encoded
2022 [ # # ]: 0 : if ( bNeedQuotes )
2023 : : rStream.Write(
2024 [ # # ]: 0 : aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
2025 [ # # ]: 0 : rStream.Write(aStrEnc.getStr(), aStrEnc.getLength());
2026 [ # # ]: 0 : if ( bNeedQuotes )
2027 : : rStream.Write(
2028 [ # # ]: 0 : aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
2029 : : }
2030 : : }
2031 : : }
2032 : : else
2033 [ # # ][ # # ]: 0 : rStream.WriteUnicodeOrByteText( aUniString );
[ # # ]
2034 : : }
2035 : : else
2036 [ # # ][ # # ]: 0 : rStream.WriteUnicodeOrByteText( aUniString );
[ # # ]
2037 : : }
2038 : :
2039 [ # # ]: 0 : if( nCol < nEndCol )
2040 : : {
2041 [ # # ]: 0 : if(cDelim!=0) //@ BugId 55355
2042 [ # # ]: 0 : rStream.WriteUniOrByteChar( cDelim );
2043 : : }
2044 : : else
2045 [ # # ]: 0 : endlub( rStream );
2046 : :
2047 [ # # ]: 0 : if ( bProgress )
2048 [ # # ]: 0 : aProgress.SetStateOnPercent( nRow );
2049 : : }
2050 : :
2051 : : // write out empty if requested
2052 [ # # ]: 0 : if ( nNextRow <= nEndRow )
2053 : : {
2054 [ # # ]: 0 : for ( nEmptyCol = nNextCol; nEmptyCol < nEndCol; nEmptyCol++ )
2055 : : { // remaining empty columns of last row
2056 [ # # ]: 0 : if ( bFixedWidth )
2057 : : lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2058 [ # # ]: 0 : aDocument, nTab, nEmptyCol );
2059 [ # # ]: 0 : else if ( cDelim != 0 )
2060 [ # # ]: 0 : rStream.WriteUniOrByteChar( cDelim );
2061 : : }
2062 [ # # ]: 0 : endlub( rStream );
2063 : 0 : nNextRow++;
2064 : : }
2065 [ # # ]: 0 : for ( nEmptyRow = nNextRow; nEmptyRow <= nEndRow; nEmptyRow++ )
2066 : : { // entire empty rows
2067 [ # # ]: 0 : for ( nEmptyCol = nStartCol; nEmptyCol < nEndCol; nEmptyCol++ )
2068 : : {
2069 [ # # ]: 0 : if ( bFixedWidth )
2070 : : lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2071 [ # # ]: 0 : aDocument, nTab, nEmptyCol );
2072 [ # # ]: 0 : else if ( cDelim != 0 )
2073 [ # # ]: 0 : rStream.WriteUniOrByteChar( cDelim );
2074 : : }
2075 [ # # ]: 0 : endlub( rStream );
2076 : : }
2077 : :
2078 : 0 : rStream.SetStreamCharSet( eOldCharSet );
2079 [ # # ][ # # ]: 0 : rStream.SetNumberFormatInt( nOldNumberFormatInt );
[ # # ]
2080 : 0 : }
2081 : :
2082 : 0 : sal_Bool ScDocShell::ConvertTo( SfxMedium &rMed )
2083 : : {
2084 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ConvertTo" );
2085 : :
2086 [ # # ]: 0 : ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
2087 : :
2088 : : // #i6500# don't call DoEnterHandler here (doesn't work with AutoSave),
2089 : : // it's already in ExecuteSave (as for Save and SaveAs)
2090 : :
2091 [ # # ]: 0 : if (pAutoStyleList)
2092 [ # # ]: 0 : pAutoStyleList->ExecuteAllNow(); // Vorlagen-Timeouts jetzt ausfuehren
2093 [ # # ]: 0 : if (GetCreateMode()== SFX_CREATE_MODE_STANDARD)
2094 [ # # ][ # # ]: 0 : SfxObjectShell::SetVisArea( Rectangle() ); // normal bearbeitet -> keine VisArea
2095 : :
2096 : : OSL_ENSURE( rMed.GetFilter(), "Filter == 0" );
2097 : :
2098 : 0 : sal_Bool bRet = false;
2099 [ # # ][ # # ]: 0 : String aFltName = rMed.GetFilter()->GetFilterName();
2100 : :
2101 [ # # ][ # # ]: 0 : if (aFltName.EqualsAscii(pFilterXML))
2102 : : {
2103 : : //TODO/LATER: this shouldn't happen!
2104 : : OSL_FAIL("XML filter in ConvertFrom?!");
2105 [ # # ][ # # ]: 0 : bRet = SaveXML( &rMed, NULL );
2106 : : }
2107 [ # # ][ # # ]: 0 : else if (aFltName.EqualsAscii(pFilterExcel5) || aFltName.EqualsAscii(pFilterExcel95) ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2108 [ # # ][ # # ]: 0 : aFltName.EqualsAscii(pFilterExcel97) || aFltName.EqualsAscii(pFilterEx5Temp) ||
2109 [ # # ][ # # ]: 0 : aFltName.EqualsAscii(pFilterEx95Temp) || aFltName.EqualsAscii(pFilterEx97Temp))
2110 : : {
2111 [ # # ][ # # ]: 0 : WaitObject aWait( GetActiveDialogParent() );
2112 : :
2113 : 0 : bool bDoSave = true;
2114 [ # # ][ # # ]: 0 : if( ScTabViewShell* pViewShell = GetBestViewShell() )
2115 : : {
2116 : 0 : ScExtDocOptions* pExtDocOpt = aDocument.GetExtDocOptions();
2117 [ # # ]: 0 : if( !pExtDocOpt )
2118 [ # # ][ # # ]: 0 : aDocument.SetExtDocOptions( pExtDocOpt = new ScExtDocOptions );
[ # # ]
2119 [ # # ]: 0 : pViewShell->GetViewData()->WriteExtOptions( *pExtDocOpt );
2120 : :
2121 : : /* #i104990# If the imported document contains a medium
2122 : : password, determine if we can save it, otherwise ask the users
2123 : : whether they want to save without it. */
2124 [ # # ][ # # ]: 0 : if( (rMed.GetFilter()->GetFilterFlags() & SFX_FILTER_ENCRYPTION) == 0 )
2125 : : {
2126 [ # # ]: 0 : SfxItemSet* pItemSet = rMed.GetItemSet();
2127 : 0 : const SfxPoolItem* pItem = 0;
2128 [ # # ][ # # ]: 0 : if( pItemSet && pItemSet->GetItemState( SID_PASSWORD, sal_True, &pItem ) == SFX_ITEM_SET )
[ # # ][ # # ]
2129 : : {
2130 [ # # ]: 0 : bDoSave = ScWarnPassword::WarningOnPassword( rMed );
2131 : : // #i42858# remove password from medium (warn only one time)
2132 [ # # ]: 0 : if( bDoSave )
2133 [ # # ]: 0 : pItemSet->ClearItem( SID_PASSWORD );
2134 : : }
2135 : : }
2136 : :
2137 [ # # ]: 0 : if( bDoSave )
2138 : : {
2139 [ # # ]: 0 : bool bNeedRetypePassDlg = ScPassHashHelper::needsPassHashRegen( aDocument, PASSHASH_XL );
2140 [ # # ][ # # ]: 0 : bDoSave = !bNeedRetypePassDlg || pViewShell->ExecuteRetypePassDlg( PASSHASH_XL );
[ # # ]
2141 : : }
2142 : : }
2143 : :
2144 [ # # ]: 0 : if( bDoSave )
2145 : : {
2146 : 0 : ExportFormatExcel eFormat = ExpBiff5;
2147 [ # # ][ # # ]: 0 : if( aFltName.EqualsAscii( pFilterExcel97 ) || aFltName.EqualsAscii( pFilterEx97Temp ) )
[ # # ][ # # ]
[ # # ]
2148 : 0 : eFormat = ExpBiff8;
2149 [ # # ][ # # ]: 0 : FltError eError = ScFormatFilter::Get().ScExportExcel5( rMed, &aDocument, eFormat, RTL_TEXTENCODING_MS_1252 );
2150 : :
2151 [ # # ][ # # ]: 0 : if( eError && !GetError() )
[ # # ][ # # ]
2152 [ # # ][ # # ]: 0 : SetError( eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2153 : :
2154 : : // don't return false for warnings
2155 [ # # ][ # # ]: 0 : bRet = ((eError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK) || (eError == eERR_OK);
2156 : : }
2157 : : else
2158 : : {
2159 : : // export aborted, i.e. "Save without password" warning
2160 [ # # ][ # # ]: 0 : SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2161 [ # # ]: 0 : }
2162 : : }
2163 [ # # ][ # # ]: 0 : else if (aFltName.EqualsAscii(pFilterAscii))
2164 : : {
2165 [ # # ]: 0 : SvStream* pStream = rMed.GetOutStream();
2166 [ # # ]: 0 : if (pStream)
2167 : : {
2168 [ # # ]: 0 : String sItStr;
2169 [ # # ]: 0 : SfxItemSet* pSet = rMed.GetItemSet();
2170 : : const SfxPoolItem* pItem;
2171 [ # # ][ # # ]: 0 : if ( pSet && SFX_ITEM_SET ==
[ # # ]
2172 [ # # ]: 0 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
2173 : : {
2174 [ # # ]: 0 : sItStr = ((const SfxStringItem*)pItem)->GetValue();
2175 : : }
2176 : :
2177 [ # # ]: 0 : if ( sItStr.Len() == 0 )
2178 : : {
2179 : : // default for ascii export (from API without options):
2180 : : // ISO8859-1/MS_1252 encoding, comma, double quotes
2181 : :
2182 [ # # ]: 0 : ScImportOptions aDefOptions( ',', '"', RTL_TEXTENCODING_MS_1252 );
2183 [ # # ][ # # ]: 0 : sItStr = aDefOptions.BuildString();
[ # # ][ # # ]
2184 : : }
2185 : :
2186 [ # # ][ # # ]: 0 : WaitObject aWait( GetActiveDialogParent() );
2187 [ # # ]: 0 : ScImportOptions aOptions( sItStr );
2188 [ # # ]: 0 : AsciiSave( *pStream, aOptions );
2189 : 0 : bRet = sal_True;
2190 : :
2191 [ # # ][ # # ]: 0 : if (aDocument.GetTableCount() > 1)
2192 [ # # ][ # # ]: 0 : if (!rMed.GetError())
2193 [ # # ][ # # ]: 0 : rMed.SetError(SCWARN_EXPORT_ASCII, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
[ # # ][ # # ]
[ # # ]
2194 : : }
2195 : : }
2196 [ # # ][ # # ]: 0 : else if (aFltName.EqualsAscii(pFilterDBase))
2197 : : {
2198 [ # # ]: 0 : String sCharSet;
2199 [ # # ]: 0 : SfxItemSet* pSet = rMed.GetItemSet();
2200 : : const SfxPoolItem* pItem;
2201 [ # # ][ # # ]: 0 : if ( pSet && SFX_ITEM_SET ==
[ # # ]
2202 [ # # ]: 0 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
2203 : : {
2204 [ # # ]: 0 : sCharSet = ((const SfxStringItem*)pItem)->GetValue();
2205 : : }
2206 : :
2207 [ # # ]: 0 : if (sCharSet.Len() == 0)
2208 : : {
2209 : : // default for dBase export (from API without options):
2210 : : // IBM_850 encoding
2211 : :
2212 [ # # ][ # # ]: 0 : sCharSet = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 );
[ # # ]
2213 : : }
2214 : :
2215 [ # # ][ # # ]: 0 : WaitObject aWait( GetActiveDialogParent() );
2216 : : // HACK damit Sba geoffnetes TempFile ueberschreiben kann
2217 [ # # ]: 0 : rMed.CloseOutStream();
2218 : 0 : bool bHasMemo = false;
2219 : :
2220 : : sal_uLong eError = DBaseExport(
2221 [ # # ][ # # ]: 0 : rMed.GetPhysicalName(), ScGlobal::GetCharsetValue(sCharSet), bHasMemo);
[ # # ]
2222 : :
2223 [ # # ][ # # ]: 0 : if ( eError != eERR_OK && (eError & ERRCODE_WARNING_MASK) )
2224 : : {
2225 : 0 : eError = eERR_OK;
2226 : : }
2227 : :
2228 [ # # ][ # # ]: 0 : INetURLObject aTmpFile( rMed.GetPhysicalName(), INET_PROT_FILE );
2229 [ # # ]: 0 : if ( bHasMemo )
2230 [ # # ]: 0 : aTmpFile.setExtension(rtl::OUString("dbt"));
2231 [ # # ]: 0 : if ( eError != eERR_OK )
2232 : : {
2233 [ # # ][ # # ]: 0 : if (!GetError())
2234 [ # # ][ # # ]: 0 : SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
2235 [ # # ][ # # ]: 0 : if ( bHasMemo && IsDocument( aTmpFile ) )
[ # # ][ # # ]
2236 [ # # ]: 0 : KillFile( aTmpFile );
2237 : : }
2238 : : else
2239 : : {
2240 : 0 : bRet = sal_True;
2241 [ # # ]: 0 : if ( bHasMemo )
2242 : : {
2243 : : SfxStringItem* pNameItem =
2244 [ # # ][ # # ]: 0 : (SfxStringItem*) rMed.GetItemSet()->GetItem( SID_FILE_NAME );
2245 [ # # ][ # # ]: 0 : INetURLObject aDbtFile( pNameItem->GetValue(), INET_PROT_FILE );
2246 [ # # ]: 0 : aDbtFile.setExtension(rtl::OUString("dbt"));
2247 [ # # ][ # # ]: 0 : if ( IsDocument( aDbtFile ) && !KillFile( aDbtFile ) )
[ # # ][ # # ]
[ # # ]
2248 : 0 : bRet = false;
2249 [ # # ][ # # ]: 0 : if ( bRet && !MoveFile( aTmpFile, aDbtFile ) )
[ # # ][ # # ]
2250 : 0 : bRet = false;
2251 [ # # ]: 0 : if ( !bRet )
2252 : : {
2253 [ # # ]: 0 : KillFile( aTmpFile );
2254 [ # # ][ # # ]: 0 : if ( !GetError() )
2255 [ # # ][ # # ]: 0 : SetError( SCERR_EXPORT_DATA, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2256 [ # # ]: 0 : }
2257 : : }
2258 [ # # ][ # # ]: 0 : }
[ # # ]
2259 : : }
2260 [ # # ][ # # ]: 0 : else if (aFltName.EqualsAscii(pFilterDif))
2261 : : {
2262 [ # # ]: 0 : SvStream* pStream = rMed.GetOutStream();
2263 [ # # ]: 0 : if (pStream)
2264 : : {
2265 [ # # ]: 0 : String sItStr;
2266 [ # # ]: 0 : SfxItemSet* pSet = rMed.GetItemSet();
2267 : : const SfxPoolItem* pItem;
2268 [ # # ][ # # ]: 0 : if ( pSet && SFX_ITEM_SET ==
[ # # ]
2269 [ # # ]: 0 : pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
2270 : : {
2271 [ # # ]: 0 : sItStr = ((const SfxStringItem*)pItem)->GetValue();
2272 : : }
2273 : :
2274 [ # # ]: 0 : if (sItStr.Len() == 0)
2275 : : {
2276 : : // default for DIF export (from API without options):
2277 : : // ISO8859-1/MS_1252 encoding
2278 : :
2279 [ # # ][ # # ]: 0 : sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 );
[ # # ]
2280 : : }
2281 : :
2282 [ # # ][ # # ]: 0 : WaitObject aWait( GetActiveDialogParent() );
2283 [ # # ]: 0 : ScFormatFilter::Get().ScExportDif( *pStream, &aDocument, ScAddress(0,0,0),
2284 [ # # ][ # # ]: 0 : ScGlobal::GetCharsetValue(sItStr) );
2285 : 0 : bRet = sal_True;
2286 : :
2287 [ # # ][ # # ]: 0 : if (aDocument.GetTableCount() > 1)
2288 [ # # ][ # # ]: 0 : if (!rMed.GetError())
2289 [ # # ][ # # ]: 0 : rMed.SetError(SCWARN_EXPORT_ASCII, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
[ # # ][ # # ]
2290 : : }
2291 : : }
2292 [ # # ][ # # ]: 0 : else if (aFltName.EqualsAscii(pFilterSylk))
2293 : : {
2294 [ # # ]: 0 : SvStream* pStream = rMed.GetOutStream();
2295 [ # # ]: 0 : if ( pStream )
2296 : : {
2297 [ # # ][ # # ]: 0 : WaitObject aWait( GetActiveDialogParent() );
2298 : :
2299 : : SCCOL nEndCol;
2300 : : SCROW nEndRow;
2301 [ # # ]: 0 : aDocument.GetCellArea( 0, nEndCol, nEndRow );
2302 : 0 : ScRange aRange( 0,0,0, nEndCol,nEndRow,0 );
2303 : :
2304 [ # # ]: 0 : ScImportExport aImExport( &aDocument, aRange );
2305 : 0 : aImExport.SetFormulas( sal_True );
2306 [ # # ][ # # ]: 0 : bRet = aImExport.ExportStream( *pStream, rMed.GetBaseURL( true ), SOT_FORMATSTR_ID_SYLK );
[ # # ][ # # ]
[ # # ][ # # ]
2307 : : }
2308 : : }
2309 [ # # ][ # # ]: 0 : else if (aFltName.EqualsAscii(pFilterHtml))
2310 : : {
2311 [ # # ]: 0 : SvStream* pStream = rMed.GetOutStream();
2312 [ # # ]: 0 : if ( pStream )
2313 : : {
2314 [ # # ][ # # ]: 0 : WaitObject aWait( GetActiveDialogParent() );
2315 [ # # ]: 0 : ScImportExport aImExport( &aDocument );
2316 [ # # ][ # # ]: 0 : aImExport.SetStreamPath( rMed.GetName() );
[ # # ][ # # ]
2317 [ # # ][ # # ]: 0 : bRet = aImExport.ExportStream( *pStream, rMed.GetBaseURL( true ), SOT_FORMATSTR_ID_HTML );
[ # # ][ # # ]
2318 [ # # ][ # # ]: 0 : if ( bRet && aImExport.GetNonConvertibleChars().Len() )
[ # # ]
2319 : : SetError( *new StringErrorInfo(
2320 : : SCWARN_EXPORT_NONCONVERTIBLE_CHARS,
2321 : : aImExport.GetNonConvertibleChars(),
2322 [ # # ][ # # ]: 0 : ERRCODE_BUTTON_OK | ERRCODE_MSG_INFO ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2323 : : }
2324 : : }
2325 : : else
2326 : : {
2327 [ # # ][ # # ]: 0 : if (GetError())
2328 [ # # ][ # # ]: 0 : SetError(SCERR_IMPORT_NI, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2329 : : }
2330 [ # # ]: 0 : return bRet;
2331 : : }
2332 : :
2333 : :
2334 : 4 : sal_Bool ScDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor )
2335 : : {
2336 : 4 : return SfxObjectShell::SaveCompleted( xStor );
2337 : : }
2338 : :
2339 : :
2340 : 4 : sal_Bool ScDocShell::DoSaveCompleted( SfxMedium * pNewStor )
2341 : : {
2342 : 4 : sal_Bool bRet = SfxObjectShell::DoSaveCompleted( pNewStor );
2343 : :
2344 : : // SC_HINT_DOC_SAVED fuer Wechsel ReadOnly -> Read/Write
2345 [ + - ]: 4 : Broadcast( SfxSimpleHint( SC_HINT_DOC_SAVED ) );
2346 : 4 : return bRet;
2347 : : }
2348 : :
2349 : :
2350 : 0 : sal_Bool ScDocShell::QuerySlotExecutable( sal_uInt16 nSlotId )
2351 : : {
2352 : : // #i112634# ask VBA event handlers whether to save or print the document
2353 : :
2354 : : using namespace ::com::sun::star::script::vba;
2355 : :
2356 : 0 : sal_Int32 nVbaEventId = VBAEventId::NO_EVENT;
2357 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs;
2358 [ # # # ]: 0 : switch( nSlotId )
2359 : : {
2360 : : case SID_SAVEDOC:
2361 : : case SID_SAVEASDOC:
2362 : 0 : nVbaEventId = VBAEventId::WORKBOOK_BEFORESAVE;
2363 [ # # ]: 0 : aArgs.realloc( 1 );
2364 [ # # ][ # # ]: 0 : aArgs[ 0 ] <<= (nSlotId == SID_SAVEASDOC);
2365 : 0 : break;
2366 : : case SID_PRINTDOC:
2367 : : case SID_PRINTDOCDIRECT:
2368 : 0 : nVbaEventId = VBAEventId::WORKBOOK_BEFOREPRINT;
2369 : 0 : break;
2370 : : }
2371 : :
2372 : 0 : sal_Bool bSlotExecutable = sal_True;
2373 [ # # ]: 0 : if( nVbaEventId != VBAEventId::NO_EVENT ) try
2374 : : {
2375 [ # # ][ # # ]: 0 : uno::Reference< XVBAEventProcessor > xEventProcessor( aDocument.GetVbaEventProcessor(), uno::UNO_QUERY_THROW );
2376 [ # # ]: 0 : xEventProcessor->processVbaEvent( nVbaEventId, aArgs );
[ # # # ]
[ # # ]
2377 : : }
2378 [ # # ]: 0 : catch( util::VetoException& )
2379 : : {
2380 : 0 : bSlotExecutable = false;
2381 : : }
2382 [ # # ]: 0 : catch( uno::Exception& )
2383 : : {
2384 : : }
2385 [ # # ]: 0 : return bSlotExecutable;
2386 : : }
2387 : :
2388 : :
2389 : 0 : sal_uInt16 ScDocShell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
2390 : : {
2391 [ # # ]: 0 : if(SC_MOD()->GetCurRefDlgId()>0)
2392 : : {
2393 : 0 : SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
2394 [ # # ]: 0 : if( pFrame )
2395 : : {
2396 : 0 : SfxViewShell* p = pFrame->GetViewShell();
2397 [ # # ][ # # ]: 0 : ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
2398 [ # # ]: 0 : if(pViewSh!=NULL)
2399 : : {
2400 : 0 : Window *pWin=pViewSh->GetWindow();
2401 [ # # ]: 0 : if(pWin!=NULL) pWin->GrabFocus();
2402 : : }
2403 : : }
2404 : :
2405 : 0 : return false;
2406 : : }
2407 [ # # ][ # # ]: 0 : if ( aDocument.IsInLinkUpdate() || aDocument.IsInInterpreter() )
[ # # ]
2408 : : {
2409 : 0 : ErrorMessage(STR_CLOSE_ERROR_LINK);
2410 : 0 : return false;
2411 : : }
2412 : :
2413 : 0 : DoEnterHandler();
2414 : :
2415 : : // start 'Workbook_BeforeClose' VBA event handler for possible veto
2416 [ # # ]: 0 : if( !IsInPrepareClose() )
2417 : : {
2418 : : try
2419 : : {
2420 [ # # ][ # # ]: 0 : uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( aDocument.GetVbaEventProcessor(), uno::UNO_SET_THROW );
2421 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs;
2422 [ # # ][ # # ]: 0 : xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_BEFORECLOSE, aArgs );
[ # # ]
[ # # # ]
2423 : : }
2424 : 0 : catch( util::VetoException& )
2425 : : {
2426 : : // if event processor throws VetoException, macro has vetoed close
2427 : 0 : return false;
2428 : : }
2429 : 0 : catch( uno::Exception& )
2430 : : {
2431 : : }
2432 : : }
2433 : : // end handler code
2434 : :
2435 : 0 : sal_uInt16 nRet = SfxObjectShell::PrepareClose( bUI, bForBrowsing );
2436 [ # # ]: 0 : if (nRet == sal_True) // sal_True = schliessen
2437 : 0 : aDocument.DisableIdle(sal_True); // nicht mehr drin rumpfuschen !!!
2438 : :
2439 : 0 : return nRet;
2440 : : }
2441 : :
2442 : 0 : void ScDocShell::PrepareReload()
2443 : : {
2444 : 0 : SfxObjectShell::PrepareReload(); // tut nichts?
2445 : :
2446 : : // Das Disconnect von DDE-Links kann Reschedule ausloesen.
2447 : : // Wenn die DDE-Links erst im Dokument-dtor geloescht werden, kann beim Reload
2448 : : // aus diesem Reschedule das DDE-Link-Update fuer das neue Dokument ausgeloest
2449 : : // werden. Dabei verklemmt sicht dann irgendwas.
2450 : : // -> Beim Reload die DDE-Links des alten Dokuments vorher disconnecten
2451 : :
2452 : 0 : aDocument.DisconnectDdeLinks();
2453 : 0 : }
2454 : :
2455 : :
2456 : 6 : String ScDocShell::GetOwnFilterName()
2457 : : {
2458 [ + - ]: 6 : return rtl::OUString(pFilterSc50);
2459 : : }
2460 : :
2461 : 0 : String ScDocShell::GetHtmlFilterName()
2462 : : {
2463 [ # # ]: 0 : return rtl::OUString(pFilterHtml);
2464 : : }
2465 : :
2466 : 4 : String ScDocShell::GetWebQueryFilterName()
2467 : : {
2468 [ + - ]: 4 : return rtl::OUString(pFilterHtmlWebQ);
2469 : : }
2470 : :
2471 : 0 : String ScDocShell::GetAsciiFilterName()
2472 : : {
2473 [ # # ]: 0 : return rtl::OUString(pFilterAscii);
2474 : : }
2475 : :
2476 : 0 : String ScDocShell::GetLotusFilterName()
2477 : : {
2478 [ # # ]: 0 : return rtl::OUString(pFilterLotus);
2479 : : }
2480 : :
2481 : 0 : String ScDocShell::GetDBaseFilterName()
2482 : : {
2483 [ # # ]: 0 : return rtl::OUString(pFilterDBase);
2484 : : }
2485 : :
2486 : 0 : String ScDocShell::GetDifFilterName()
2487 : : {
2488 [ # # ]: 0 : return rtl::OUString(pFilterDif);
2489 : : }
2490 : :
2491 : 0 : sal_Bool ScDocShell::HasAutomaticTableName( const String& rFilter )
2492 : : {
2493 : : // sal_True for those filters that keep the default table name
2494 : : // (which is language specific)
2495 : :
2496 : 0 : return rFilter.EqualsAscii( pFilterAscii )
2497 : 0 : || rFilter.EqualsAscii( pFilterLotus )
2498 : 0 : || rFilter.EqualsAscii( pFilterExcel4 )
2499 : 0 : || rFilter.EqualsAscii( pFilterEx4Temp )
2500 : 0 : || rFilter.EqualsAscii( pFilterDBase )
2501 : 0 : || rFilter.EqualsAscii( pFilterDif )
2502 : 0 : || rFilter.EqualsAscii( pFilterSylk )
2503 : 0 : || rFilter.EqualsAscii( pFilterHtml )
2504 [ # # ][ # # : 0 : || rFilter.EqualsAscii( pFilterRtf );
# # # # #
# # # # #
# # # # ]
2505 : : }
2506 : :
2507 : : #ifndef ENABLE_TELEPATHY
2508 : 846 : ScDocFunc *ScDocShell::CreateDocFunc()
2509 : : {
2510 : 846 : return new ScDocFuncDirect( *this );
2511 : : }
2512 : : #else
2513 : : ScCollaboration* ScDocShell::GetCollaboration()
2514 : : {
2515 : : return mpCollaboration;
2516 : : }
2517 : : #endif
2518 : :
2519 : 0 : ScDocShell::ScDocShell( const ScDocShell& rShell ) :
2520 : : SvRefBase(),
2521 : : SotObject(),
2522 : : SfxObjectShell( rShell.GetCreateMode() ),
2523 : : SfxListener(),
2524 : : aDocument ( SCDOCMODE_DOCUMENT, this ),
2525 : : aDdeTextFmt(rtl::OUString("TEXT")),
2526 : : nPrtToScreenFactor( 1.0 ),
2527 : 0 : pImpl ( new DocShell_Impl ),
2528 : : bHeaderOn ( true ),
2529 : : bFooterOn ( true ),
2530 : : bIsEmpty ( true ),
2531 : : bIsInUndo ( false ),
2532 : : bDocumentModifiedPending( false ),
2533 : : bUpdateEnabled ( true ),
2534 : : nDocumentLock ( 0 ),
2535 : : nCanUpdate (com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG),
2536 : : pOldAutoDBRange ( NULL ),
2537 : : pDocHelper ( NULL ),
2538 : : pAutoStyleList ( NULL ),
2539 : : pPaintLockData ( NULL ),
2540 : : pSolverSaveData ( NULL ),
2541 : : pSheetSaveData ( NULL ),
2542 [ # # ][ # # ]: 0 : pModificator ( NULL )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2543 : : #ifdef ENABLE_TELEPATHY
2544 : : , mpCollaboration( new ScCollaboration( this ) )
2545 : : #endif
2546 : : {
2547 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ScDocShell" );
2548 : :
2549 [ # # ][ # # ]: 0 : SetPool( &SC_MOD()->GetPool() );
2550 : :
2551 : 0 : bIsInplace = rShell.bIsInplace;
2552 : :
2553 [ # # # # ]: 0 : pDocFunc = CreateDocFunc();
2554 : :
2555 : : // SetBaseModel needs exception handling
2556 [ # # ][ # # ]: 0 : ScModelObj::CreateAndSet( this );
2557 : :
2558 [ # # ][ # # ]: 0 : StartListening(*this);
2559 [ # # ][ # # ]: 0 : SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
2560 [ # # ][ # # ]: 0 : if (pStlPool)
2561 [ # # ][ # # ]: 0 : StartListening(*pStlPool);
2562 : :
2563 [ # # ][ # # ]: 0 : GetPageOnFromPageStyleSet( NULL, 0, bHeaderOn, bFooterOn );
2564 [ # # ][ # # ]: 0 : SetHelpId( HID_SCSHELL_DOCSH );
2565 : :
2566 : : // InitItems und CalcOutputFactor werden jetzt nach bei Load/ConvertFrom/InitNew gerufen
2567 : 0 : }
2568 : :
2569 : : //------------------------------------------------------------------
2570 : :
2571 : 846 : ScDocShell::ScDocShell( const sal_uInt64 i_nSfxCreationFlags ) :
2572 : : SfxObjectShell( i_nSfxCreationFlags ),
2573 : : aDocument ( SCDOCMODE_DOCUMENT, this ),
2574 : : aDdeTextFmt(rtl::OUString("TEXT")),
2575 : : nPrtToScreenFactor( 1.0 ),
2576 : 846 : pImpl ( new DocShell_Impl ),
2577 : : bHeaderOn ( true ),
2578 : : bFooterOn ( true ),
2579 : : bIsEmpty ( true ),
2580 : : bIsInUndo ( false ),
2581 : : bDocumentModifiedPending( false ),
2582 : : bUpdateEnabled ( true ),
2583 : : nDocumentLock ( 0 ),
2584 : : nCanUpdate (com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG),
2585 : : pOldAutoDBRange ( NULL ),
2586 : : pDocHelper ( NULL ),
2587 : : pAutoStyleList ( NULL ),
2588 : : pPaintLockData ( NULL ),
2589 : : pSolverSaveData ( NULL ),
2590 : : pSheetSaveData ( NULL ),
2591 [ + - ][ + - ]: 846 : pModificator ( NULL )
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2592 : : #ifdef ENABLE_TELEPATHY
2593 : : , mpCollaboration( new ScCollaboration( this ) )
2594 : : #endif
2595 : : {
2596 : : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ScDocShell" );
2597 : :
2598 [ # # ][ + - ]: 846 : SetPool( &SC_MOD()->GetPool() );
2599 : :
2600 : 846 : bIsInplace = (GetCreateMode() == SFX_CREATE_MODE_EMBEDDED);
2601 : : // wird zurueckgesetzt, wenn nicht inplace
2602 : :
2603 [ + - # # ]: 846 : pDocFunc = CreateDocFunc();
2604 : :
2605 : : // SetBaseModel needs exception handling
2606 [ + - ][ # # ]: 846 : ScModelObj::CreateAndSet( this );
2607 : :
2608 [ + - ][ # # ]: 846 : StartListening(*this);
2609 [ + - ][ # # ]: 846 : SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
2610 [ + - ][ # # ]: 846 : if (pStlPool)
2611 [ + - ][ # # ]: 846 : StartListening(*pStlPool);
2612 [ + - ][ # # ]: 846 : SetHelpId( HID_SCSHELL_DOCSH );
2613 : :
2614 : : aDocument.GetDBCollection()->SetRefreshHandler(
2615 [ + - ][ + - ]: 846 : LINK( this, ScDocShell, RefreshDBDataHdl ) );
[ # # ][ # # ]
2616 : :
2617 : : // InitItems und CalcOutputFactor werden jetzt nach bei Load/ConvertFrom/InitNew gerufen
2618 : 846 : }
2619 : :
2620 : : //------------------------------------------------------------------
2621 : :
2622 [ + - ][ + - ]: 2085 : ScDocShell::~ScDocShell()
[ + - ][ + - ]
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2623 : : {
2624 [ + - ][ # # ]: 695 : ResetDrawObjectShell(); // falls der Drawing-Layer noch versucht, darauf zuzugreifen
2625 : :
2626 [ + - ][ # # ]: 695 : SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
2627 [ + - ][ # # ]: 695 : if (pStlPool)
2628 [ + - ][ # # ]: 695 : EndListening(*pStlPool);
2629 [ + - ][ # # ]: 695 : EndListening(*this);
2630 : :
2631 [ - + ][ # # ]: 695 : delete pAutoStyleList;
[ # # ][ # # ]
2632 : :
2633 [ + - ][ # # ]: 695 : SfxApplication *pSfxApp = SFX_APP();
2634 [ + - ][ - + ]: 695 : if ( pSfxApp->GetDdeService() ) // DDE vor Dokument loeschen
[ # # ][ # # ]
2635 [ # # ][ # # ]: 0 : pSfxApp->RemoveDdeTopic( this );
2636 : :
2637 [ + - ][ + - ]: 695 : delete pDocFunc;
[ # # ][ # # ]
2638 [ + + ][ + - ]: 695 : delete aDocument.mpUndoManager;
[ # # ][ # # ]
2639 : 695 : aDocument.mpUndoManager = 0;
2640 [ + - ][ + - ]: 695 : delete pImpl;
[ # # ][ # # ]
2641 : :
2642 [ + + ][ + - ]: 695 : delete pPaintLockData;
[ # # ][ # # ]
2643 : :
2644 [ - + ][ # # ]: 695 : delete pSolverSaveData;
[ # # ][ # # ]
2645 [ + + ][ + - ]: 695 : delete pSheetSaveData;
[ # # ][ # # ]
2646 [ + + ][ + - ]: 695 : delete pOldAutoDBRange;
[ # # ][ # # ]
2647 : :
2648 [ - + ][ # # ]: 695 : if (pModificator)
2649 : : {
2650 : : OSL_FAIL("The Modificator should not exist");
2651 [ # # ][ # # ]: 0 : delete pModificator;
[ # # ][ # # ]
2652 : : }
2653 : : #ifdef ENABLE_TELEPATHY
2654 : : delete mpCollaboration;
2655 : : #endif
2656 [ + - ][ + - ]: 2780 : }
[ - + ]
[ # # # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
2657 : :
2658 : : //------------------------------------------------------------------
2659 : :
2660 : 4520 : ::svl::IUndoManager* ScDocShell::GetUndoManager()
2661 : : {
2662 : 4520 : return aDocument.GetUndoManager();
2663 : : }
2664 : :
2665 : 5297 : void ScDocShell::SetModified( sal_Bool bModified )
2666 : : {
2667 [ + + ]: 5297 : if ( SfxObjectShell::IsEnableSetModified() )
2668 : : {
2669 : 4719 : SfxObjectShell::SetModified( bModified );
2670 [ + - ]: 4719 : Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
2671 : : }
2672 : 5297 : }
2673 : :
2674 : :
2675 : 10136 : void ScDocShell::SetDocumentModified( sal_Bool bIsModified /* = sal_True */ )
2676 : : {
2677 : : // BroadcastUno muss auch mit pPaintLockData sofort passieren
2678 : : //! auch bei SetDrawModified, wenn Drawing angebunden ist
2679 : : //! dann eigener Hint???
2680 : :
2681 [ + + ][ + - ]: 10136 : if ( pPaintLockData && bIsModified )
2682 : : {
2683 : : // #i115009# broadcast BCA_BRDCST_ALWAYS, so a component can read recalculated results
2684 : : // of RecalcModeAlways formulas (like OFFSET) after modifying cells
2685 [ + - ]: 6038 : aDocument.Broadcast( SC_HINT_DATACHANGED, BCA_BRDCST_ALWAYS, NULL );
2686 : 6038 : aDocument.InvalidateTableArea(); // #i105279# needed here
2687 [ + - ]: 6038 : aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
2688 : :
2689 : 6038 : pPaintLockData->SetModified(); // spaeter...
2690 : 10136 : return;
2691 : : }
2692 : :
2693 : 4098 : SetDrawModified( bIsModified );
2694 : :
2695 [ + - ]: 4098 : if ( bIsModified )
2696 : : {
2697 [ + + ]: 4098 : if ( aDocument.IsAutoCalcShellDisabled() )
2698 : 113 : SetDocumentModifiedPending( sal_True );
2699 : : else
2700 : : {
2701 : 3985 : SetDocumentModifiedPending( false );
2702 : 3985 : aDocument.InvalidateStyleSheetUsage();
2703 : 3985 : aDocument.InvalidateTableArea();
2704 : 3985 : aDocument.InvalidateLastTableOpParams();
2705 [ + - ]: 3985 : aDocument.Broadcast( SC_HINT_DATACHANGED, BCA_BRDCST_ALWAYS, NULL );
2706 [ - + ][ # # ]: 3985 : if ( aDocument.IsForcedFormulaPending() && aDocument.GetAutoCalc() )
[ - + ]
2707 : 0 : aDocument.CalcFormulaTree( sal_True );
2708 : 3985 : PostDataChanged();
2709 : :
2710 : : // Detective AutoUpdate:
2711 : : // Update if formulas were modified (DetectiveDirty) or the list contains
2712 : : // "Trace Error" entries (Trace Error can look completely different
2713 : : // after changes to non-formula cells).
2714 : :
2715 : 3985 : ScDetOpList* pList = aDocument.GetDetOpList();
2716 [ + + ][ - + : 3994 : if ( pList && ( aDocument.IsDetectiveDirty() || pList->HasAddError() ) &&
+ - + - +
+ ][ + + ]
[ + + ]
2717 : 9 : pList->Count() && !IsInUndo() && SC_MOD()->GetAppOptions().GetDetectiveAuto() )
2718 : : {
2719 : 2 : GetDocFunc().DetectiveRefresh(sal_True); // sal_True = caused by automatic update
2720 : : }
2721 : 3985 : aDocument.SetDetectiveDirty(false); // always reset, also if not refreshed
2722 : : }
2723 : :
2724 : : // notify UNO objects after BCA_BRDCST_ALWAYS etc.
2725 [ + - ]: 4098 : aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
2726 : : }
2727 : : }
2728 : :
2729 : : // SetDrawModified - ohne Formel-Update
2730 : : // (Drawing muss auch beim normalen SetDocumentModified upgedated werden,
2731 : : // z.B. bei Tabelle loeschen etc.)
2732 : :
2733 : 4168 : void ScDocShell::SetDrawModified( sal_Bool bIsModified /* = sal_True */ )
2734 : : {
2735 : 4168 : sal_Bool bUpdate = ( bIsModified != IsModified() );
2736 : :
2737 : 4168 : SetModified( bIsModified );
2738 : :
2739 : 4168 : SfxBindings* pBindings = GetViewBindings();
2740 [ + + ]: 4168 : if (bUpdate)
2741 : : {
2742 [ + + ]: 474 : if (pBindings)
2743 : : {
2744 : 180 : pBindings->Invalidate( SID_SAVEDOC );
2745 : 180 : pBindings->Invalidate( SID_DOC_MODIFIED );
2746 : : }
2747 : : }
2748 : :
2749 [ + - ]: 4168 : if (bIsModified)
2750 : : {
2751 [ + + ]: 4168 : if (pBindings)
2752 : : {
2753 : : // #i105960# Undo etc used to be volatile.
2754 : : // They always have to be invalidated, including drawing layer or row height changes
2755 : : // (but not while pPaintLockData is set).
2756 : 3866 : pBindings->Invalidate( SID_UNDO );
2757 : 3866 : pBindings->Invalidate( SID_REDO );
2758 : 3866 : pBindings->Invalidate( SID_REPEAT );
2759 : : }
2760 : :
2761 [ + + ]: 4168 : if ( aDocument.IsChartListenerCollectionNeedsUpdate() )
2762 : : {
2763 : 445 : aDocument.UpdateChartListenerCollection();
2764 [ + - ][ + - ]: 445 : SFX_APP()->Broadcast(SfxSimpleHint( SC_HINT_DRAW_CHANGED )); // Navigator
2765 : : }
2766 : 4168 : SC_MOD()->AnythingChanged();
2767 : : }
2768 : 4168 : }
2769 : :
2770 : 12 : void ScDocShell::SetInUndo(bool bSet)
2771 : : {
2772 : 12 : bIsInUndo = bSet;
2773 : 12 : }
2774 : :
2775 : :
2776 : 0 : void ScDocShell::GetDocStat( ScDocStat& rDocStat )
2777 : : {
2778 : 0 : SfxPrinter* pPrinter = GetPrinter();
2779 : :
2780 : 0 : aDocument.GetDocStat( rDocStat );
2781 : 0 : rDocStat.nPageCount = 0;
2782 : :
2783 [ # # ]: 0 : if ( pPrinter )
2784 [ # # ]: 0 : for ( SCTAB i=0; i<rDocStat.nTableCount; i++ )
2785 : : rDocStat.nPageCount = sal::static_int_cast<sal_uInt16>( rDocStat.nPageCount +
2786 : 0 : (sal_uInt16) ScPrintFunc( this, pPrinter, i ).GetTotalPages() );
2787 : 0 : }
2788 : :
2789 : :
2790 : 0 : SfxDocumentInfoDialog* ScDocShell::CreateDocumentInfoDialog(
2791 : : Window *pParent, const SfxItemSet &rSet )
2792 : : {
2793 [ # # ]: 0 : SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog( pParent, rSet );
2794 [ # # ][ # # ]: 0 : ScDocShell* pDocSh = PTR_CAST(ScDocShell,SfxObjectShell::Current());
2795 : :
2796 : : //nur mit Statistik, wenn dieses Doc auch angezeigt wird, nicht
2797 : : //aus dem Doc-Manager
2798 : :
2799 [ # # ]: 0 : if( pDocSh == this )
2800 : : {
2801 : 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2802 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2803 : 0 : ::CreateTabPage ScDocStatPageCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_STAT );
2804 : : OSL_ENSURE(ScDocStatPageCreate, "Tabpage create fail!");
2805 : : pDlg->AddTabPage( 42,
2806 : 0 : ScGlobal::GetRscString( STR_DOC_STAT ),
2807 : : ScDocStatPageCreate,
2808 : 0 : NULL);
2809 : : }
2810 : 0 : return pDlg;
2811 : : }
2812 : :
2813 : 467 : Window* ScDocShell::GetActiveDialogParent()
2814 : : {
2815 : 467 : ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
2816 [ + + ]: 467 : if ( pViewSh )
2817 : 255 : return pViewSh->GetDialogParent();
2818 : : else
2819 : 467 : return Application::GetDefDialogParent();
2820 : : }
2821 : :
2822 : 0 : void ScDocShell::SetSolverSaveData( const ScOptSolverSave& rData )
2823 : : {
2824 [ # # ]: 0 : delete pSolverSaveData;
2825 [ # # ]: 0 : pSolverSaveData = new ScOptSolverSave( rData );
2826 : 0 : }
2827 : :
2828 : 2047 : ScSheetSaveData* ScDocShell::GetSheetSaveData()
2829 : : {
2830 [ + + ]: 2047 : if (!pSheetSaveData)
2831 [ + - ]: 95 : pSheetSaveData = new ScSheetSaveData;
2832 : :
2833 : 2047 : return pSheetSaveData;
2834 : : }
2835 : :
2836 : : namespace {
2837 : :
2838 : 0 : void removeKeysIfExists(Reference<ui::XAcceleratorConfiguration>& xScAccel, const vector<const awt::KeyEvent*>& rKeys)
2839 : : {
2840 : 0 : vector<const awt::KeyEvent*>::const_iterator itr = rKeys.begin(), itrEnd = rKeys.end();
2841 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
2842 : : {
2843 : 0 : const awt::KeyEvent* p = *itr;
2844 [ # # ]: 0 : if (!p)
2845 : 0 : continue;
2846 : :
2847 : : try
2848 : : {
2849 [ # # ][ # # ]: 0 : xScAccel->removeKeyEvent(*p);
2850 : : }
2851 [ # # ]: 0 : catch (const container::NoSuchElementException&) {}
2852 : : }
2853 [ # # ]: 0 : }
2854 : :
2855 : : }
2856 : :
2857 : 0 : void ScDocShell::ResetKeyBindings( ScOptionsUtil::KeyBindingType eType )
2858 : : {
2859 : : using namespace ::com::sun::star::ui;
2860 : :
2861 [ # # ]: 0 : Reference<XMultiServiceFactory> xServiceManager = ::comphelper::getProcessServiceFactory();
2862 [ # # ]: 0 : if (!xServiceManager.is())
2863 : : return;
2864 : :
2865 : : Reference<XModuleUIConfigurationManagerSupplier> xModuleCfgSupplier(
2866 [ # # ]: 0 : xServiceManager->createInstance(
2867 [ # # ][ # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.ModuleUIConfigurationManagerSupplier"))), UNO_QUERY);
[ # # ]
2868 : :
2869 [ # # ]: 0 : if (!xModuleCfgSupplier.is())
2870 : : return;
2871 : :
2872 : : // Grab the Calc configuration.
2873 : : Reference<XUIConfigurationManager> xConfigMgr =
2874 [ # # ]: 0 : xModuleCfgSupplier->getUIConfigurationManager(
2875 [ # # ][ # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument")));
2876 : :
2877 [ # # ]: 0 : if (!xConfigMgr.is())
2878 : : return;
2879 : :
2880 : : // shortcut manager
2881 : : Reference<XAcceleratorConfiguration> xScAccel(
2882 [ # # ][ # # ]: 0 : xConfigMgr->getShortCutManager(), UNO_QUERY);
[ # # ]
2883 : :
2884 [ # # ]: 0 : if (!xScAccel.is())
2885 : : return;
2886 : :
2887 [ # # ]: 0 : vector<const awt::KeyEvent*> aKeys;
2888 [ # # ]: 0 : aKeys.reserve(4);
2889 : :
2890 : : // Backsapce key
2891 [ # # ]: 0 : awt::KeyEvent aBackspace;
2892 : 0 : aBackspace.KeyCode = awt::Key::BACKSPACE;
2893 : 0 : aBackspace.Modifiers = 0;
2894 [ # # ]: 0 : aKeys.push_back(&aBackspace);
2895 : :
2896 : : // Delete key
2897 [ # # ]: 0 : awt::KeyEvent aDelete;
2898 : 0 : aDelete.KeyCode = awt::Key::DELETE;
2899 : 0 : aDelete.Modifiers = 0;
2900 [ # # ]: 0 : aKeys.push_back(&aDelete);
2901 : :
2902 : : // Ctrl-D
2903 [ # # ]: 0 : awt::KeyEvent aCtrlD;
2904 : 0 : aCtrlD.KeyCode = awt::Key::D;
2905 : 0 : aCtrlD.Modifiers = awt::KeyModifier::MOD1;
2906 [ # # ]: 0 : aKeys.push_back(&aCtrlD);
2907 : :
2908 : : // Alt-Down
2909 [ # # ]: 0 : awt::KeyEvent aAltDown;
2910 : 0 : aAltDown.KeyCode = awt::Key::DOWN;
2911 : 0 : aAltDown.Modifiers = awt::KeyModifier::MOD2;
2912 [ # # ]: 0 : aKeys.push_back(&aAltDown);
2913 : :
2914 : : // Remove all involved keys first, because swapping commands don't work
2915 : : // well without doing this.
2916 [ # # ]: 0 : removeKeysIfExists(xScAccel, aKeys);
2917 [ # # ][ # # ]: 0 : xScAccel->store();
2918 : :
2919 [ # # # ]: 0 : switch (eType)
2920 : : {
2921 : : case ScOptionsUtil::KEY_DEFAULT:
2922 [ # # ][ # # ]: 0 : xScAccel->setKeyEvent(aDelete, OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:ClearContents")));
[ # # ]
2923 [ # # ][ # # ]: 0 : xScAccel->setKeyEvent(aBackspace, OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Delete")));
[ # # ]
2924 [ # # ][ # # ]: 0 : xScAccel->setKeyEvent(aCtrlD, OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillDown")));
[ # # ]
2925 [ # # ][ # # ]: 0 : xScAccel->setKeyEvent(aAltDown, OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DataSelect")));
[ # # ]
2926 : 0 : break;
2927 : : case ScOptionsUtil::KEY_OOO_LEGACY:
2928 [ # # ][ # # ]: 0 : xScAccel->setKeyEvent(aDelete, OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Delete")));
[ # # ]
2929 [ # # ][ # # ]: 0 : xScAccel->setKeyEvent(aBackspace, OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:ClearContents")));
[ # # ]
2930 [ # # ][ # # ]: 0 : xScAccel->setKeyEvent(aCtrlD, OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DataSelect")));
[ # # ]
2931 : 0 : break;
2932 : : default:
2933 : : ;
2934 : : }
2935 : :
2936 [ # # ][ # # ]: 0 : xScAccel->store();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2937 : : }
2938 : :
2939 : 4 : void ScDocShell::UseSheetSaveEntries()
2940 : : {
2941 [ + - ]: 4 : if (pSheetSaveData)
2942 : : {
2943 : 4 : pSheetSaveData->UseSaveEntries(); // use positions from saved file for next saving
2944 : :
2945 : 4 : bool bHasEntries = false;
2946 : 4 : SCTAB nTabCount = aDocument.GetTableCount();
2947 : : SCTAB nTab;
2948 [ + + ]: 8 : for (nTab = 0; nTab < nTabCount; ++nTab)
2949 [ - + ]: 4 : if (pSheetSaveData->HasStreamPos(nTab))
2950 : 0 : bHasEntries = true;
2951 : :
2952 [ + - ]: 4 : if (!bHasEntries)
2953 : : {
2954 : : // if no positions were set (for example, export to other format),
2955 : : // reset all "valid" flags
2956 : :
2957 [ + + ]: 8 : for (nTab = 0; nTab < nTabCount; ++nTab)
2958 [ - + ]: 4 : if (aDocument.IsStreamValid(nTab))
2959 : 0 : aDocument.SetStreamValid(nTab, false);
2960 : : }
2961 : : }
2962 : 4 : }
2963 : :
2964 : : // --- ScDocShellModificator ------------------------------------------
2965 : :
2966 : 15482 : ScDocShellModificator::ScDocShellModificator( ScDocShell& rDS )
2967 : : :
2968 : : rDocShell( rDS ),
2969 : 15482 : aProtector( rDS.GetDocument()->GetRefreshTimerControlAddress() )
2970 : : {
2971 : 15482 : ScDocument* pDoc = rDocShell.GetDocument();
2972 : 15482 : bAutoCalcShellDisabled = pDoc->IsAutoCalcShellDisabled();
2973 : 15482 : bIdleDisabled = pDoc->IsIdleDisabled();
2974 : 15482 : pDoc->SetAutoCalcShellDisabled( sal_True );
2975 : 15482 : pDoc->DisableIdle( sal_True );
2976 : 15482 : }
2977 : :
2978 : :
2979 : 15482 : ScDocShellModificator::~ScDocShellModificator()
2980 : : {
2981 : 15482 : ScDocument* pDoc = rDocShell.GetDocument();
2982 : 15482 : pDoc->SetAutoCalcShellDisabled( bAutoCalcShellDisabled );
2983 [ + + ][ + + ]: 15482 : if ( !bAutoCalcShellDisabled && rDocShell.IsDocumentModifiedPending() )
[ + + ]
2984 [ + - ]: 94 : rDocShell.SetDocumentModified(); // last one shuts off the lights
2985 : 15482 : pDoc->DisableIdle( bIdleDisabled );
2986 : 15482 : }
2987 : :
2988 : :
2989 : 12949 : void ScDocShellModificator::SetDocumentModified()
2990 : : {
2991 : 12949 : ScDocument* pDoc = rDocShell.GetDocument();
2992 [ + + ]: 12949 : if ( !pDoc->IsImportingXML() )
2993 : : {
2994 : : // AutoCalcShellDisabled temporaer restaurieren
2995 : 5628 : sal_Bool bDisabled = pDoc->IsAutoCalcShellDisabled();
2996 : 5628 : pDoc->SetAutoCalcShellDisabled( bAutoCalcShellDisabled );
2997 : 5628 : rDocShell.SetDocumentModified();
2998 : 5628 : pDoc->SetAutoCalcShellDisabled( bDisabled );
2999 : : }
3000 : : else
3001 : : {
3002 : : // uno broadcast is necessary for api to work
3003 : : // -> must also be done during xml import
3004 [ + - ]: 7321 : pDoc->BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
3005 : : }
3006 : 12949 : }
3007 : :
3008 : 0 : bool ScDocShell::IsChangeRecording() const
3009 : : {
3010 : 0 : ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
3011 : 0 : return pChangeTrack != NULL;
3012 : : }
3013 : :
3014 : :
3015 : 0 : bool ScDocShell::HasChangeRecordProtection() const
3016 : : {
3017 : 0 : bool bRes = false;
3018 : 0 : ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
3019 [ # # ]: 0 : if (pChangeTrack)
3020 : 0 : bRes = pChangeTrack->IsProtected();
3021 : 0 : return bRes;
3022 : : }
3023 : :
3024 : :
3025 : 0 : void ScDocShell::SetChangeRecording( bool bActivate )
3026 : : {
3027 : 0 : bool bOldChangeRecording = IsChangeRecording();
3028 : :
3029 [ # # ]: 0 : if (bActivate)
3030 : : {
3031 [ # # ]: 0 : aDocument.StartChangeTracking();
3032 [ # # ]: 0 : ScChangeViewSettings aChangeViewSet;
3033 : 0 : aChangeViewSet.SetShowChanges(sal_True);
3034 [ # # ][ # # ]: 0 : aDocument.SetChangeViewSettings(aChangeViewSet);
3035 : : }
3036 : : else
3037 : : {
3038 : 0 : aDocument.EndChangeTracking();
3039 : 0 : PostPaintGridAll();
3040 : : }
3041 : :
3042 [ # # ]: 0 : if (bOldChangeRecording != IsChangeRecording())
3043 : : {
3044 : 0 : UpdateAcceptChangesDialog();
3045 : : // Slots invalidieren
3046 : 0 : SfxBindings* pBindings = GetViewBindings();
3047 [ # # ]: 0 : if (pBindings)
3048 : 0 : pBindings->InvalidateAll(false);
3049 : : }
3050 : 0 : }
3051 : :
3052 : :
3053 : 0 : bool ScDocShell::SetProtectionPassword( const String &rNewPassword )
3054 : : {
3055 : 0 : bool bRes = false;
3056 : 0 : ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
3057 [ # # ]: 0 : if (pChangeTrack)
3058 : : {
3059 : 0 : bool bProtected = pChangeTrack->IsProtected();
3060 : :
3061 [ # # ]: 0 : if (rNewPassword.Len())
3062 : : {
3063 : : // when password protection is applied change tracking must always be active
3064 [ # # ]: 0 : SetChangeRecording( true );
3065 : :
3066 [ # # ]: 0 : ::com::sun::star::uno::Sequence< sal_Int8 > aProtectionHash;
3067 [ # # ]: 0 : SvPasswordHelper::GetHashPassword( aProtectionHash, rNewPassword );
3068 [ # # ][ # # ]: 0 : pChangeTrack->SetProtection( aProtectionHash );
3069 : : }
3070 : : else
3071 : : {
3072 [ # # ]: 0 : pChangeTrack->SetProtection( ::com::sun::star::uno::Sequence< sal_Int8 >() );
3073 : : }
3074 : 0 : bRes = true;
3075 : :
3076 [ # # ]: 0 : if ( bProtected != pChangeTrack->IsProtected() )
3077 : : {
3078 : 0 : UpdateAcceptChangesDialog();
3079 : 0 : SetDocumentModified();
3080 : : }
3081 : : }
3082 : :
3083 : 0 : return bRes;
3084 : : }
3085 : :
3086 : :
3087 : 0 : bool ScDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash )
3088 : : {
3089 : 0 : bool bRes = false;
3090 : 0 : ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
3091 [ # # ][ # # ]: 0 : if (pChangeTrack && pChangeTrack->IsProtected())
[ # # ]
3092 : : {
3093 [ # # ]: 0 : rPasswordHash = pChangeTrack->GetProtection();
3094 : 0 : bRes = true;
3095 : : }
3096 : 0 : return bRes;
3097 : : }
3098 : :
3099 : :
3100 : :
3101 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|