LibreOffice Module sc (master)  1
docsh.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <docsh.hxx>
21 
22 #include <config_features.h>
23 #include <scitems.hxx>
24 #include <sc.hrc>
25 #include <vcl/errinf.hxx>
26 #include <editeng/justifyitem.hxx>
27 #include <comphelper/fileformat.h>
28 #include <comphelper/classids.hxx>
29 #include <formula/errorcodes.hxx>
30 #include <vcl/stdtext.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/virdev.hxx>
33 #include <vcl/weld.hxx>
34 #include <rtl/bootstrap.hxx>
35 #include <rtl/tencinfo.h>
36 #include <sal/log.hxx>
37 #include <svl/PasswordHelper.hxx>
38 #include <sfx2/app.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/dinfdlg.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/event.hxx>
43 #include <sfx2/docfilt.hxx>
44 #include <sfx2/objface.hxx>
45 #include <sfx2/viewfrm.hxx>
46 #include <svl/documentlockfile.hxx>
47 #include <svl/sharecontrolfile.hxx>
48 #include <svl/urihelper.hxx>
49 #include <osl/file.hxx>
50 #include <chgtrack.hxx>
51 #include <chgviset.hxx>
52 #include <com/sun/star/awt/Key.hpp>
53 #include <com/sun/star/awt/KeyModifier.hpp>
54 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
55 #include <com/sun/star/document/UpdateDocMode.hpp>
56 #include <com/sun/star/script/vba/VBAEventId.hpp>
57 #include <com/sun/star/script/vba/VBAScriptEventId.hpp>
58 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
59 #include <com/sun/star/script/vba/XVBAScriptListener.hpp>
60 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
61 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
62 #include <com/sun/star/task/XJob.hpp>
63 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
64 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
65 #include <com/sun/star/util/VetoException.hpp>
66 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
67 #include <ooo/vba/excel/XWorkbook.hpp>
68 #include <tools/diagnose_ex.h>
69 
70 #include <config_folders.h>
71 
72 #include <scabstdlg.hxx>
73 #include <sot/formats.hxx>
74 #include <svx/dialogs.hrc>
75 
76 #include <formulacell.hxx>
77 #include <global.hxx>
78 #include <filter.hxx>
79 #include <scmod.hxx>
80 #include <tabvwsh.hxx>
81 #include <docfunc.hxx>
82 #include <imoptdlg.hxx>
83 #include <impex.hxx>
84 #include <scresid.hxx>
85 #include <strings.hrc>
86 #include <globstr.hrc>
87 #include <scerrors.hxx>
88 #include <brdcst.hxx>
89 #include <stlpool.hxx>
90 #include <autostyl.hxx>
91 #include <attrib.hxx>
92 #include <asciiopt.hxx>
93 #include <progress.hxx>
94 #include <pntlock.hxx>
95 #include <docuno.hxx>
96 #include <appoptio.hxx>
97 #include <formulaopt.hxx>
98 #include <scdll.hxx>
99 #include <detdata.hxx>
100 #include <printfun.hxx>
101 #include <dociter.hxx>
102 #include <cellform.hxx>
103 #include <chartlis.hxx>
104 #include <hints.hxx>
105 #include <xmlwrap.hxx>
106 #include <drwlayer.hxx>
107 #include <dbdata.hxx>
108 #include <scextopt.hxx>
109 #include <compiler.hxx>
110 #include <warnpassword.hxx>
111 #include <optsolver.hxx>
112 #include <sheetdata.hxx>
113 #include <tabprotection.hxx>
114 #include <docparam.hxx>
115 #include "docshimp.hxx"
116 #include <sizedev.hxx>
117 #include <refreshtimerprotector.hxx>
118 
119 #include <officecfg/Office/Calc.hxx>
121 #include <comphelper/string.hxx>
122 #include <unotools/configmgr.hxx>
123 #include <uiitems.hxx>
124 #include <dpobject.hxx>
125 #include <markdata.hxx>
126 #include <docoptio.hxx>
127 #include <orcusfilters.hxx>
128 #include <datastream.hxx>
129 #include <documentlinkmgr.hxx>
130 #include <refupdatecontext.hxx>
131 
132 #include <memory>
133 #include <vector>
134 
135 using namespace com::sun::star;
136 using ::com::sun::star::uno::Reference;
137 using ::com::sun::star::lang::XMultiServiceFactory;
138 using std::shared_ptr;
139 using ::std::vector;
140 
141 // Filter names (like in sclib.cxx)
142 
143 constexpr OUStringLiteral pFilterSc50 = u"StarCalc 5.0";
144 const char pFilterXML[] = "StarOffice XML (Calc)";
145 constexpr OUStringLiteral pFilterAscii = u"" SC_TEXT_CSV_FILTER_NAME;
146 constexpr OUStringLiteral pFilterLotus = u"Lotus";
147 const char pFilterQPro6[] = "Quattro Pro 6.0";
148 const char16_t pFilterExcel4[] = u"MS Excel 4.0";
149 const char16_t pFilterEx4Temp[] = u"MS Excel 4.0 Vorlage/Template";
150 const char pFilterExcel5[] = "MS Excel 5.0/95";
151 const char pFilterEx5Temp[] = "MS Excel 5.0/95 Vorlage/Template";
152 const char pFilterExcel95[] = "MS Excel 95";
153 const char pFilterEx95Temp[] = "MS Excel 95 Vorlage/Template";
154 const char pFilterExcel97[] = "MS Excel 97";
155 const char pFilterEx97Temp[] = "MS Excel 97 Vorlage/Template";
156 constexpr OUStringLiteral pFilterDBase = u"dBase";
157 constexpr OUStringLiteral pFilterDif = u"DIF";
158 const char16_t pFilterSylk[] = u"SYLK";
159 constexpr OUStringLiteral pFilterHtml = u"HTML (StarCalc)";
160 constexpr OUStringLiteral pFilterHtmlWebQ = u"calc_HTML_WebQuery";
161 const char16_t pFilterRtf[] = u"Rich Text Format (StarCalc)";
162 
163 #define ShellClass_ScDocShell
164 #include <scslots.hxx>
165 
167 
168 void ScDocShell::InitInterface_Impl()
169 {
170 }
171 
172 // GlobalName of the current version:
173 SFX_IMPL_OBJECTFACTORY( ScDocShell, SvGlobalName(SO3_SC_CLASSID), "scalc" )
174 
175 
176 void ScDocShell::FillClass( SvGlobalName* pClassName,
177  SotClipboardFormatId* pFormat,
178  OUString* pFullTypeName,
179  sal_Int32 nFileFormat,
180  bool bTemplate /* = false */) const
181 {
182  if ( nFileFormat == SOFFICE_FILEFORMAT_60 )
183  {
184  *pClassName = SvGlobalName( SO3_SC_CLASSID_60 );
185  *pFormat = SotClipboardFormatId::STARCALC_60;
186  *pFullTypeName = ScResId( SCSTR_LONG_SCDOC_NAME_60 );
187  }
188  else if ( nFileFormat == SOFFICE_FILEFORMAT_8 )
189  {
190  *pClassName = SvGlobalName( SO3_SC_CLASSID_60 );
191  *pFormat = bTemplate ? SotClipboardFormatId::STARCALC_8_TEMPLATE : SotClipboardFormatId::STARCALC_8;
192  *pFullTypeName = ScResId( SCSTR_LONG_SCDOC_NAME_80 );
193  }
194  else
195  {
196  OSL_FAIL("Which version?");
197  }
198 }
199 
200 std::set<Color> ScDocShell::GetDocColors()
201 {
202  return m_aDocument.GetDocColors();
203 }
204 
206 {
208  if (pViewSh && pViewSh->GetViewData().GetDocShell() == this)
209  SC_MOD()->InputEnterHandler();
210 }
211 
213 {
214  SCTAB nTab = 0;
215  ScTabViewShell* pSh = GetBestViewShell();
216  if (pSh)
217  {
218  const ScMarkData& rMark = pSh->GetViewData().GetMarkData();
219  nTab = rMark.GetFirstSelected();
220  }
221  return nTab;
222 }
223 
225 {
226  // get global state like HiddenInformation::DOCUMENTVERSIONS
228 
229  if ( nStates & HiddenInformation::RECORDEDCHANGES )
230  {
231  if ( m_aDocument.GetChangeTrack() && m_aDocument.GetChangeTrack()->GetFirst() )
232  nState |= HiddenInformation::RECORDEDCHANGES;
233  }
234  if ( nStates & HiddenInformation::NOTES )
235  {
236  SCTAB nTableCount = m_aDocument.GetTableCount();
237  bool bFound = false;
238  for (SCTAB nTab = 0; nTab < nTableCount && !bFound; ++nTab)
239  {
240  if (m_aDocument.HasTabNotes(nTab)) //TODO:
241  bFound = true;
242  }
243 
244  if (bFound)
245  nState |= HiddenInformation::NOTES;
246  }
247 
248  return nState;
249 }
250 
252 {
253  m_aDocument.EnableIdle(false);
254 
255  // prevent unnecessary broadcasts and updates
256  OSL_ENSURE(m_pModificator == nullptr, "The Modificator should not exist");
257  m_pModificator.reset( new ScDocShellModificator( *this ) );
258 
259  m_aDocument.SetImportingXML( true );
260  m_aDocument.EnableExecuteLink( false ); // #i101304# to be safe, prevent nested loading from external references
261  m_aDocument.EnableUndo( false );
262  // prevent unnecessary broadcasts and "half way listeners"
263  m_aDocument.SetInsertingFromOtherDoc( true );
264 }
265 
267 {
268  if (GetCreateMode() != SfxObjectCreateMode::ORGANIZER)
269  {
270  UpdateLinks();
271  // don't prevent establishing of listeners anymore
272  m_aDocument.SetInsertingFromOtherDoc( false );
273  if ( bRet )
274  {
275  ScChartListenerCollection* pChartListener = m_aDocument.GetChartListenerCollection();
276  if (pChartListener)
277  pChartListener->UpdateDirtyCharts();
278 
279  // #95582#; set the table names of linked tables to the new path
280  SCTAB nTabCount = m_aDocument.GetTableCount();
281  for (SCTAB i = 0; i < nTabCount; ++i)
282  {
283  if (m_aDocument.IsLinked( i ))
284  {
285  OUString aName;
286  m_aDocument.GetName(i, aName);
287  OUString aLinkTabName = m_aDocument.GetLinkTab(i);
288  sal_Int32 nLinkTabNameLength = aLinkTabName.getLength();
289  sal_Int32 nNameLength = aName.getLength();
290  if (nLinkTabNameLength < nNameLength)
291  {
292 
293  // remove the quotes on begin and end of the docname and restore the escaped quotes
294  const sal_Unicode* pNameBuffer = aName.getStr();
295  if ( *pNameBuffer == '\'' && // all docnames have to have a ' character on the first pos
297  {
298  OUStringBuffer aDocURLBuffer;
299  bool bQuote = true; // Document name is always quoted
300  ++pNameBuffer;
301  while ( bQuote && *pNameBuffer )
302  {
303  if ( *pNameBuffer == '\'' && *(pNameBuffer-1) != '\\' )
304  bQuote = false;
305  else if( *pNameBuffer != '\\' || *(pNameBuffer+1) != '\'' )
306  aDocURLBuffer.append(*pNameBuffer); // If escaped quote: only quote in the name
307  ++pNameBuffer;
308  }
309 
310  if( *pNameBuffer == SC_COMPILER_FILE_TAB_SEP ) // after the last quote of the docname should be the # char
311  {
312  sal_Int32 nIndex = nNameLength - nLinkTabNameLength;
313  INetURLObject aINetURLObject(aDocURLBuffer.makeStringAndClear());
314  if(aName.match( aLinkTabName, nIndex) &&
315  (aName[nIndex - 1] == '#') && // before the table name should be the # char
316  !aINetURLObject.HasError()) // the docname should be a valid URL
317  {
318  aName = ScGlobal::GetDocTabName( m_aDocument.GetLinkDoc( i ), m_aDocument.GetLinkTab( i ) );
319  m_aDocument.RenameTab(i, aName, true/*bExternalDocument*/);
320  }
321  // else; nothing has to happen, because it is a user given name
322  }
323  // else; nothing has to happen, because it is a user given name
324  }
325  // else; nothing has to happen, because it is a user given name
326  }
327  // else; nothing has to happen, because it is a user given name
328  }
329  }
330 
331  // #i94570# DataPilot table names have to be unique, or the tables can't be accessed by API.
332  // If no name (or an invalid name, skipped in ScXMLDataPilotTableContext::EndElement) was set, create a new name.
333  ScDPCollection* pDPCollection = m_aDocument.GetDPCollection();
334  if ( pDPCollection )
335  {
336  size_t nDPCount = pDPCollection->GetCount();
337  for (size_t nDP=0; nDP<nDPCount; ++nDP)
338  {
339  ScDPObject& rDPObj = (*pDPCollection)[nDP];
340  if (rDPObj.GetName().isEmpty())
341  rDPObj.SetName( pDPCollection->CreateNewName() );
342  }
343  }
344  }
345  }
346  else
347  m_aDocument.SetInsertingFromOtherDoc( false );
348 
349  m_aDocument.SetImportingXML( false );
350  m_aDocument.EnableExecuteLink( true );
351  m_aDocument.EnableUndo( true );
352  m_bIsEmpty = false;
353 
354  if (m_pModificator)
355  {
356  ScDocument::HardRecalcState eRecalcState = m_aDocument.GetHardRecalcState();
357  // Temporarily set hard-recalc to prevent calling
358  // ScFormulaCell::Notify() during destruction of the Modificator which
359  // will set the cells dirty.
360  if (eRecalcState == ScDocument::HardRecalcState::OFF)
361  m_aDocument.SetHardRecalcState(ScDocument::HardRecalcState::TEMPORARY);
362  m_pModificator.reset();
363  m_aDocument.SetHardRecalcState(eRecalcState);
364  }
365  else
366  {
367  OSL_FAIL("The Modificator should exist");
368  }
369 
370  m_aDocument.EnableIdle(true);
371 }
372 
373 namespace {
374 
375 class LoadMediumGuard
376 {
377 public:
378  explicit LoadMediumGuard(ScDocument* pDoc) :
379  mpDoc(pDoc)
380  {
381  mpDoc->SetLoadingMedium(true);
382  }
383 
384  ~LoadMediumGuard()
385  {
386  mpDoc->SetLoadingMedium(false);
387  }
388 private:
389  ScDocument* mpDoc;
390 };
391 
392 void processDataStream( ScDocShell& rShell, const sc::ImportPostProcessData& rData )
393 {
394  if (!rData.mpDataStream)
395  return;
396 
398  if (!r.maRange.IsValid())
399  return;
400 
401  // Break the streamed range into the top range and the height limit. A
402  // height limit of 0 means unlimited i.e. the streamed data will go all
403  // the way to the last row.
404 
405  ScRange aTopRange = r.maRange;
406  aTopRange.aEnd.SetRow(aTopRange.aStart.Row());
407  sal_Int32 nLimit = r.maRange.aEnd.Row() - r.maRange.aStart.Row() + 1;
408  if (r.maRange.aEnd.Row() == rShell.GetDocument().MaxRow())
409  // Unlimited range.
410  nLimit = 0;
411 
415 
416  sc::DataStream* pStrm = new sc::DataStream(&rShell, r.maURL, aTopRange, nLimit, eMove, 0);
419  rMgr.setDataStream(pStrm);
420 }
421 
422 class MessageWithCheck : public weld::MessageDialogController
423 {
424 private:
425  std::unique_ptr<weld::CheckButton> m_xWarningOnBox;
426 public:
427  MessageWithCheck(weld::Window *pParent, const OUString& rUIFile, const OString& rDialogId)
428  : MessageDialogController(pParent, rUIFile, rDialogId, "ask")
429  , m_xWarningOnBox(m_xBuilder->weld_check_button("ask"))
430  {
431  }
432  bool get_active() const { return m_xWarningOnBox->get_active(); }
433  void hide_ask() const { m_xWarningOnBox->set_visible(false); };
434 };
435 
436 
437 class VBAScriptListener : public ::cppu::WeakImplHelper< css::script::vba::XVBAScriptListener >
438 {
439 private:
440  ScDocShell* m_pDocSh;
441 public:
442  VBAScriptListener(ScDocShell* pDocSh) : m_pDocSh(pDocSh)
443  {
444  }
445 
446  // XVBAScriptListener
447  virtual void SAL_CALL notifyVBAScriptEvent( const ::css::script::vba::VBAScriptEvent& aEvent ) override
448  {
449  if (aEvent.Identifier == script::vba::VBAScriptEventId::SCRIPT_STOPPED &&
450  m_pDocSh->GetClipData().is())
451  {
452  m_pDocSh->SetClipData(uno::Reference<datatransfer::XTransferable2>());
453  }
454  }
455 
456  // XEventListener
457  virtual void SAL_CALL disposing( const ::css::lang::EventObject& /*Source*/ ) override
458  {
459  }
460 };
461 
462 }
463 
464 bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const css::uno::Reference< css::embed::XStorage >& xStor )
465 {
466  LoadMediumGuard aLoadGuard(&m_aDocument);
467 
468  // MacroCallMode is no longer needed, state is kept in SfxObjectShell now
469 
470  // no Seek(0) here - always loading from storage, GetInStream must not be called
471 
472  BeforeXMLLoading();
473 
474  ScXMLImportWrapper aImport(*this, pLoadMedium, xStor);
475 
476  bool bRet = false;
477  ErrCode nError = ERRCODE_NONE;
478  m_aDocument.LockAdjustHeight();
479  if (GetCreateMode() == SfxObjectCreateMode::ORGANIZER)
480  bRet = aImport.Import(ImportFlags::Styles, nError);
481  else
482  bRet = aImport.Import(ImportFlags::All, nError);
483 
484  if ( nError )
485  pLoadMedium->SetError(nError);
486 
487  processDataStream(*this, aImport.GetImportPostProcessData());
488 
489  //if the document was not generated by LibreOffice, do hard recalc in case some other document
490  //generator saved cached formula results that differ from LibreOffice's calculated results or
491  //did not use cached formula results.
492  uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW);
493  uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
494 
496  ScRecalcOptions nRecalcMode =
497  static_cast<ScRecalcOptions>(officecfg::Office::Calc::Formula::Load::ODFRecalcMode::get(xContext));
498 
499  bool bHardRecalc = false;
500  if (nRecalcMode == RECALC_ASK)
501  {
502  OUString sProductName(utl::ConfigManager::getProductName());
503  if (m_aDocument.IsUserInteractionEnabled() && xDocProps->getGenerator().indexOf(sProductName) == -1)
504  {
505  // Generator is not LibreOffice. Ask if the user wants to perform
506  // full re-calculation.
507  MessageWithCheck aQueryBox(GetActiveDialogParent(),
508  "modules/scalc/ui/recalcquerydialog.ui", "RecalcQueryDialog");
509  aQueryBox.set_primary_text(ScResId(STR_QUERY_FORMULA_RECALC_ONLOAD_ODS));
510  aQueryBox.set_default_response(RET_YES);
511 
512  if ( officecfg::Office::Calc::Formula::Load::OOXMLRecalcMode::isReadOnly() )
513  aQueryBox.hide_ask();
514 
515  bHardRecalc = aQueryBox.run() == RET_YES;
516 
517  if (aQueryBox.get_active())
518  {
519  // Always perform selected action in the future.
520  std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
521  officecfg::Office::Calc::Formula::Load::ODFRecalcMode::set(sal_Int32(0), batch);
522  ScFormulaOptions aOpt = SC_MOD()->GetFormulaOptions();
523  aOpt.SetODFRecalcOptions(bHardRecalc ? RECALC_ALWAYS : RECALC_NEVER);
524  /* XXX is this really supposed to set the ScModule options?
525  * Not the ScDocShell options? */
526  SC_MOD()->SetFormulaOptions(aOpt);
527 
528  batch->commit();
529  }
530  }
531  }
532  else if (nRecalcMode == RECALC_ALWAYS)
533  bHardRecalc = true;
534 
535  if (bHardRecalc)
536  DoHardRecalc();
537  else
538  {
539  // still need to recalc volatile formula cells.
540  m_aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
541  }
542 
543  AfterXMLLoading(bRet);
544 
545  m_aDocument.UnlockAdjustHeight();
546  return bRet;
547 }
548 
549 bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const css::uno::Reference< css::embed::XStorage >& xStor )
550 {
551  m_aDocument.EnableIdle(false);
552 
553  ScXMLImportWrapper aImport(*this, pSaveMedium, xStor);
554  bool bRet(false);
555  if (GetCreateMode() != SfxObjectCreateMode::ORGANIZER)
556  bRet = aImport.Export(false);
557  else
558  bRet = aImport.Export(true);
559 
560  m_aDocument.EnableIdle(true);
561 
562  return bRet;
563 }
564 
565 bool ScDocShell::Load( SfxMedium& rMedium )
566 {
567  LoadMediumGuard aLoadGuard(&m_aDocument);
568  ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );
569 
570  // only the latin script language is loaded
571  // -> initialize the others from options (before loading)
572  InitOptions(true);
573 
574  // If this is an ODF file being loaded, then by default, use legacy processing
575  // for tdf#99729 (if required, it will be overridden in *::ReadUserDataSequence())
576  if (IsOwnStorageFormat(rMedium))
577  {
578  if (m_aDocument.GetDrawLayer())
579  m_aDocument.GetDrawLayer()->SetAnchoredTextOverflowLegacy(true);
580  }
581 
582  GetUndoManager()->Clear();
583 
584  bool bRet = SfxObjectShell::Load(rMedium);
585  if (bRet)
586  {
587  if (GetMedium())
588  {
589  const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
590  m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
591  }
592 
593  // GetLinkUpdateModeState() evaluates m_nCanUpdate so that must have
594  // been set first. Do not override an already forbidden LinkUpdate (the
595  // default is allow).
596  comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
597  if (rEmbeddedObjectContainer.getUserAllowsLinkUpdate())
598  {
599  // For anything else than LM_ALWAYS we need user confirmation.
600  rEmbeddedObjectContainer.setUserAllowsLinkUpdate( GetLinkUpdateModeState() == LM_ALWAYS);
601  }
602 
603  {
604  // prepare a valid document for XML filter
605  // (for ConvertFrom, InitNew is called before)
606  m_aDocument.MakeTable(0);
607  m_aDocument.GetStyleSheetPool()->CreateStandardStyles();
608  m_aDocument.UpdStlShtPtrsFrmNms();
609 
610  if (!m_bUcalcTest)
611  {
612  /* Create styles that are imported through Orcus */
613 
614  OUString aURL("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/calc/styles.xml");
615  rtl::Bootstrap::expandMacros(aURL);
616 
617  OUString aPath;
618  osl::FileBase::getSystemPathFromFileURL(aURL, aPath);
619 
621 
622  if (pOrcus)
623  {
624  pOrcus->importODS_Styles(m_aDocument, aPath);
625  m_aDocument.GetStyleSheetPool()->setAllParaStandard();
626  }
627  }
628 
629  bRet = LoadXML( &rMedium, nullptr );
630  }
631  }
632 
633  if (!bRet && !rMedium.GetError())
635 
636  if (rMedium.GetError())
637  SetError(rMedium.GetError());
638 
639  InitItems();
640  CalcOutputFactor();
641 
642  // invalidate eventually temporary table areas
643  if ( bRet )
644  m_aDocument.InvalidateTableArea();
645 
646  m_bIsEmpty = false;
647  FinishedLoading();
648  return bRet;
649 }
650 
652 {
653  const ScTablesHint* pScHint = dynamic_cast< const ScTablesHint* >( &rHint );
654  if (pScHint)
655  {
656  if (pScHint->GetTablesHintId() == SC_TAB_INSERTED)
657  {
658  uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = m_aDocument.GetVbaEventProcessor();
659  if ( xVbaEvents.is() ) try
660  {
661  uno::Sequence< uno::Any > aArgs( 1 );
662  aArgs[0] <<= pScHint->GetTab1();
663  xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_NEWSHEET, aArgs );
664  }
665  catch( uno::Exception& )
666  {
667  }
668  }
669  }
670 
671  if ( auto pStyleSheetHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint) ) // Template changed
672  NotifyStyle( *pStyleSheetHint );
673  else if ( auto pStlHint = dynamic_cast<const ScAutoStyleHint*>(&rHint) )
674  {
676 
677  // this is called synchronously from ScInterpreter::ScStyle,
678  // modifying the document must be asynchronous
679  // (handled by AddInitial)
680 
681  const ScRange& aRange = pStlHint->GetRange();
682  const OUString& aName1 = pStlHint->GetStyle1();
683  const OUString& aName2 = pStlHint->GetStyle2();
684  sal_uInt32 nTimeout = pStlHint->GetTimeout();
685 
686  if (!m_pAutoStyleList)
687  m_pAutoStyleList.reset( new ScAutoStyleList(this) );
688  m_pAutoStyleList->AddInitial( aRange, aName1, nTimeout, aName2 );
689  }
690  else if ( auto pEventHint = dynamic_cast<const SfxEventHint*>(&rHint) )
691  {
692  SfxEventHintId nEventId = pEventHint->GetEventId();
693 
694  switch ( nEventId )
695  {
696  case SfxEventHintId::LoadFinished:
697  {
698 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
699  // the readonly documents should not be opened in shared mode
700  if ( HasSharedXMLFlagSet() && !SC_MOD()->IsInSharedDocLoading() && !IsReadOnly() )
701  {
702  if ( SwitchToShared( true, false ) )
703  {
704  ScViewData* pViewData = GetViewData();
705  ScTabView* pTabView = ( pViewData ? pViewData->GetView() : nullptr );
706  if ( pTabView )
707  {
708  pTabView->UpdateLayerLocks();
709  }
710  }
711  else
712  {
713  // switching to shared mode has failed, the document should be opened readonly
714  // TODO/LATER: And error message should be shown here probably
715  SetReadOnlyUI();
716  }
717  }
718 #endif
719  }
720  break;
721  case SfxEventHintId::ViewCreated:
722  {
723  #if HAVE_FEATURE_SCRIPTING
724  uno::Reference<script::vba::XVBACompatibility> xVBACompat(GetBasicContainer(), uno::UNO_QUERY);
725  if ( !m_xVBAListener.is() && xVBACompat.is() )
726  {
727  m_xVBAListener.set(new VBAScriptListener(this));
728  xVBACompat->addVBAScriptListener(m_xVBAListener);
729  }
730 #endif
731 
732 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
733  if ( IsDocShared() && !SC_MOD()->IsInSharedDocLoading() )
734  {
735  ScAppOptions aAppOptions = SC_MOD()->GetAppOptions();
736  if ( aAppOptions.GetShowSharedDocumentWarning() )
737  {
738  MessageWithCheck aWarningBox(ScDocShell::GetActiveDialogParent(),
739  "modules/scalc/ui/sharedwarningdialog.ui", "SharedWarningDialog");
740  aWarningBox.run();
741 
742  bool bChecked = aWarningBox.get_active();
743  if (bChecked)
744  {
745  aAppOptions.SetShowSharedDocumentWarning(false);
746  SC_MOD()->SetAppOptions( aAppOptions );
747  }
748  }
749  }
750 #endif
751  try
752  {
753  uno::Reference< uno::XComponentContext > xContext(
755  uno::Reference< lang::XMultiServiceFactory > xServiceManager(
756  xContext->getServiceManager(),
757  uno::UNO_QUERY_THROW );
758  uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xServiceManager, uno::UNO_QUERY_THROW );
759  uno::Reference< container::XEnumeration> xEnum = xEnumAccess->createContentEnumeration(
760  "com.sun.star.sheet.SpreadsheetDocumentJob" );
761  if ( xEnum.is() )
762  {
763  while ( xEnum->hasMoreElements() )
764  {
765  uno::Any aAny = xEnum->nextElement();
766  uno::Reference< lang::XSingleComponentFactory > xFactory;
767  aAny >>= xFactory;
768  if ( xFactory.is() )
769  {
770  uno::Reference< task::XJob > xJob( xFactory->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
771  ScViewData* pViewData = GetViewData();
772  SfxViewShell* pViewShell = ( pViewData ? pViewData->GetViewShell() : nullptr );
773  SfxViewFrame* pViewFrame = ( pViewShell ? pViewShell->GetViewFrame() : nullptr );
774  SfxFrame* pFrame = ( pViewFrame ? &pViewFrame->GetFrame() : nullptr );
775  uno::Reference< frame::XController > xController = ( pFrame ? pFrame->GetController() : nullptr );
776  uno::Reference< sheet::XSpreadsheetView > xSpreadsheetView( xController, uno::UNO_QUERY_THROW );
777  uno::Sequence< beans::NamedValue > aArgsForJob { { "SpreadsheetView", uno::makeAny( xSpreadsheetView ) } };
778  xJob->execute( aArgsForJob );
779  }
780  }
781  }
782  }
783  catch ( uno::Exception & )
784  {
785  }
786  }
787  break;
788  case SfxEventHintId::SaveDoc:
789  {
790 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
791  if ( IsDocShared() && !SC_MOD()->IsInSharedDocSaving() )
792  {
793  bool bSuccess = false;
794  bool bRetry = true;
795  while ( bRetry )
796  {
797  bRetry = false;
798  uno::Reference< frame::XModel > xModel;
799  try
800  {
801  // load shared file
802  xModel.set( LoadSharedDocument(), uno::UNO_SET_THROW );
803  uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
804 
805  // check if shared flag is set in shared file
806  bool bShared = false;
807  ScModelObj* pDocObj = comphelper::getUnoTunnelImplementation<ScModelObj>( xModel );
808  ScDocShell* pSharedDocShell = ( pDocObj ? dynamic_cast< ScDocShell* >( pDocObj->GetObjectShell() ) : nullptr );
809  if ( pSharedDocShell )
810  {
811  bShared = pSharedDocShell->HasSharedXMLFlagSet();
812  }
813 
814  // #i87870# check if shared status was disabled and enabled again
815  bool bOwnEntry = false;
816  bool bEntriesNotAccessible = false;
817  try
818  {
819  ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
820  bOwnEntry = aControlFile.HasOwnEntry();
821  }
822  catch ( uno::Exception& )
823  {
824  bEntriesNotAccessible = true;
825  }
826 
827  if ( bShared && bOwnEntry )
828  {
829  uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
830 
831  if ( xStorable->isReadonly() )
832  {
833  xCloseable->close( true );
834 
835  OUString aUserName( ScResId( STR_UNKNOWN_USER ) );
836  bool bNoLockAccess = false;
837  try
838  {
839  ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
840  LockFileEntry aData = aLockFile.GetLockData();
841  if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
842  {
843  aUserName = aData[LockFileComponent::OOOUSERNAME];
844  }
845  else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() )
846  {
847  aUserName = aData[LockFileComponent::SYSUSERNAME];
848  }
849  }
850  catch ( uno::Exception& )
851  {
852  bNoLockAccess = true;
853  }
854 
855  if ( bNoLockAccess )
856  {
857  // TODO/LATER: in future an error regarding impossibility to open file for writing could be shown
859  }
860  else
861  {
862  OUString aMessage( ScResId( STR_FILE_LOCKED_SAVE_LATER ) );
863  aMessage = aMessage.replaceFirst( "%1", aUserName );
864 
865  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(),
866  VclMessageType::Warning, VclButtonsType::NONE,
867  aMessage));
868  xWarn->add_button(GetStandardText(StandardButtonType::Retry), RET_RETRY);
869  xWarn->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
870  xWarn->set_default_response(RET_RETRY);
871  if (xWarn->run() == RET_RETRY)
872  {
873  bRetry = true;
874  }
875  }
876  }
877  else
878  {
879  // merge changes from shared file into temp file
880  bool bSaveToShared = false;
881  if ( pSharedDocShell )
882  {
883  bSaveToShared = MergeSharedDocument( pSharedDocShell );
884  }
885 
886  // close shared file
887  xCloseable->close( true );
888 
889  // TODO: keep file lock on shared file
890 
891  // store to shared file
892  if ( bSaveToShared )
893  {
894  bool bChangedViewSettings = false;
895  ScChangeViewSettings* pChangeViewSet = m_aDocument.GetChangeViewSettings();
896  if ( pChangeViewSet && pChangeViewSet->ShowChanges() )
897  {
898  pChangeViewSet->SetShowChanges( false );
899  pChangeViewSet->SetShowAccepted( false );
900  m_aDocument.SetChangeViewSettings( *pChangeViewSet );
901  bChangedViewSettings = true;
902  }
903 
904  uno::Reference< frame::XStorable > xStor( GetModel(), uno::UNO_QUERY_THROW );
905  // TODO/LATER: More entries from the MediaDescriptor might be interesting for the merge
906  uno::Sequence< beans::PropertyValue > aValues(1);
907  aValues[0].Name = "FilterName";
908  aValues[0].Value <<= GetMedium()->GetFilter()->GetFilterName();
909 
910  const SfxStringItem* pPasswordItem = SfxItemSet::GetItem<SfxStringItem>(GetMedium()->GetItemSet(), SID_PASSWORD, false);
911  if ( pPasswordItem && !pPasswordItem->GetValue().isEmpty() )
912  {
913  aValues.realloc( 2 );
914  aValues[1].Name = "Password";
915  aValues[1].Value <<= pPasswordItem->GetValue();
916  }
917 
918  SC_MOD()->SetInSharedDocSaving( true );
919  xStor->storeToURL( GetSharedFileURL(), aValues );
920  SC_MOD()->SetInSharedDocSaving( false );
921 
922  if ( bChangedViewSettings )
923  {
924  pChangeViewSet->SetShowChanges( true );
925  pChangeViewSet->SetShowAccepted( true );
926  m_aDocument.SetChangeViewSettings( *pChangeViewSet );
927  }
928  }
929 
930  bSuccess = true;
931  GetUndoManager()->Clear();
932  }
933  }
934  else
935  {
936  xCloseable->close( true );
937 
938  if ( bEntriesNotAccessible )
939  {
940  // TODO/LATER: in future an error regarding impossibility to write to share control file could be shown
942  }
943  else
944  {
945  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(),
946  VclMessageType::Warning, VclButtonsType::Ok,
947  ScResId(STR_DOC_NOLONGERSHARED)));
948  xWarn->run();
949 
950  SfxBindings* pBindings = GetViewBindings();
951  if ( pBindings )
952  {
953  pBindings->ExecuteSynchron( SID_SAVEASDOC );
954  }
955  }
956  }
957  }
958  catch ( uno::Exception& )
959  {
960  TOOLS_WARN_EXCEPTION( "sc", "SfxEventHintId::SaveDoc" );
961  SC_MOD()->SetInSharedDocSaving( false );
962 
963  try
964  {
965  uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
966  xClose->close( true );
967  }
968  catch ( uno::Exception& )
969  {
970  }
971  }
972  }
973 
974  if ( !bSuccess )
975  SetError(ERRCODE_IO_ABORT); // this error code will produce no error message, but will break the further saving process
976  }
977 #endif
978 
979  if (m_pSheetSaveData)
980  m_pSheetSaveData->SetInSupportedSave(true);
981  }
982  break;
983  case SfxEventHintId::SaveAsDoc:
984  {
985  if ( GetDocument().GetExternalRefManager()->containsUnsavedReferences() )
986  {
987  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(),
988  VclMessageType::Warning, VclButtonsType::YesNo,
989  ScResId(STR_UNSAVED_EXT_REF)));
990  if (RET_NO == xWarn->run())
991  {
992  SetError(ERRCODE_IO_ABORT); // this error code will produce no error message, but will break the further saving process
993  }
994  }
995  [[fallthrough]];
996  }
997  case SfxEventHintId::SaveToDoc:
998  // #i108978# If no event is sent before saving, there will also be no "...DONE" event,
999  // and SAVE/SAVEAS can't be distinguished from SAVETO. So stream copying is only enabled
1000  // if there is a SAVE/SAVEAS/SAVETO event first.
1001  if (m_pSheetSaveData)
1002  m_pSheetSaveData->SetInSupportedSave(true);
1003  break;
1004  case SfxEventHintId::SaveDocDone:
1005  case SfxEventHintId::SaveAsDocDone:
1006  {
1007  // new positions are used after "save" and "save as", but not "save to"
1008  UseSheetSaveEntries(); // use positions from saved file for next saving
1009  [[fallthrough]];
1010  }
1011  case SfxEventHintId::SaveToDocDone:
1012  // only reset the flag, don't use the new positions
1013  if (m_pSheetSaveData)
1014  m_pSheetSaveData->SetInSupportedSave(false);
1015  break;
1016  default:
1017  {
1018  }
1019  break;
1020  }
1021  }
1022  else if (rHint.GetId() == SfxHintId::TitleChanged) // Without parameter
1023  {
1024  m_aDocument.SetName( SfxShell::GetName() );
1025  // RegisterNewTargetNames doesn't exist any longer
1026  SfxGetpApp()->Broadcast(SfxHint( SfxHintId::ScDocNameChanged )); // Navigator
1027  }
1028  else if (rHint.GetId() == SfxHintId::Deinitializing)
1029  {
1030 
1031 #if HAVE_FEATURE_SCRIPTING
1032  uno::Reference<script::vba::XVBACompatibility> xVBACompat(GetBasicContainer(), uno::UNO_QUERY);
1033  if (m_xVBAListener.is() && xVBACompat.is())
1034  {
1035  xVBACompat->removeVBAScriptListener(m_xVBAListener);
1036  }
1037 #endif
1038 
1039  if (m_aDocument.IsClipboardSource())
1040  {
1041  // Notes copied to the clipboard have a raw SdrCaptionObj pointer
1042  // copied from this document, forget it as it references this
1043  // document's drawing layer pages and what not, which otherwise when
1044  // pasting to another document after this document was destructed would
1045  // attempt to access non-existing data. Preserve the text data though.
1046  ScDocument* pClipDoc = ScModule::GetClipDoc();
1047  if (pClipDoc)
1048  pClipDoc->ClosingClipboardSource();
1049  }
1050  }
1051 
1052  const SfxEventHint* pSfxEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
1053  if (!pSfxEventHint)
1054  return;
1055 
1056  switch( pSfxEventHint->GetEventId() )
1057  {
1058  case SfxEventHintId::CreateDoc:
1059  {
1060  uno::Any aWorkbook;
1061  aWorkbook <<= mxAutomationWorkbookObject;
1062  uno::Sequence< uno::Any > aArgs(1);
1063  aArgs[0] = aWorkbook;
1064  SC_MOD()->CallAutomationApplicationEventSinks( "NewWorkbook", aArgs );
1065  }
1066  break;
1067  case SfxEventHintId::OpenDoc:
1068  {
1069  uno::Any aWorkbook;
1070  aWorkbook <<= mxAutomationWorkbookObject;
1071  uno::Sequence< uno::Any > aArgs(1);
1072  aArgs[0] = aWorkbook;
1073  SC_MOD()->CallAutomationApplicationEventSinks( "WorkbookOpen", aArgs );
1074  }
1075  break;
1076  default:
1077  break;
1078  }
1079 }
1080 
1081 // Load contents for organizer
1083 {
1084  LoadMediumGuard aLoadGuard(&m_aDocument);
1085  ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );
1086 
1087  weld::WaitObject aWait( GetActiveDialogParent() );
1088 
1089  bool bRet = false;
1090 
1091  if (GetMedium())
1092  {
1093  const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
1094  m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
1095  }
1096 
1097  // until loading/saving only the styles in XML is implemented,
1098  // load the whole file
1099  bRet = LoadXML( &rMedium, nullptr );
1100  InitItems();
1101 
1102  SfxObjectShell::LoadFrom( rMedium );
1103 
1104  return bRet;
1105 }
1106 
1107 static void lcl_parseHtmlFilterOption(const OUString& rOption, LanguageType& rLang, bool& rDateConvert)
1108 {
1109  OUStringBuffer aBuf;
1110  std::vector< OUString > aTokens;
1111  sal_Int32 n = rOption.getLength();
1112  const sal_Unicode* p = rOption.getStr();
1113  for (sal_Int32 i = 0; i < n; ++i)
1114  {
1115  const sal_Unicode c = p[i];
1116  if (c == ' ')
1117  {
1118  if (!aBuf.isEmpty())
1119  aTokens.push_back( aBuf.makeStringAndClear() );
1120  }
1121  else
1122  aBuf.append(c);
1123  }
1124 
1125  if (!aBuf.isEmpty())
1126  aTokens.push_back( aBuf.makeStringAndClear() );
1127 
1128  rLang = LanguageType( 0 );
1129  rDateConvert = false;
1130 
1131  if (!aTokens.empty())
1132  rLang = static_cast<LanguageType>(aTokens[0].toInt32());
1133  if (aTokens.size() > 1)
1134  rDateConvert = static_cast<bool>(aTokens[1].toInt32());
1135 }
1136 
1138 {
1139  LoadMediumGuard aLoadGuard(&m_aDocument);
1140 
1141  bool bRet = false; // sal_False means user quit!
1142  // On error: Set error at stream
1143 
1144  ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );
1145 
1146  GetUndoManager()->Clear();
1147 
1148  // Set optimal col width after import?
1149  bool bSetColWidths = false;
1150  bool bSetSimpleTextColWidths = false;
1151  std::map<SCCOL, ScColWidthParam> aColWidthParam;
1152  ScRange aColWidthRange;
1153  // Set optimal row height after import?
1154  bool bSetRowHeights = false;
1155 
1156  vector<ScDocRowHeightUpdater::TabRanges> aRecalcRowRangesArray;
1157 
1158  // All filters need the complete file in one piece (not asynchronously)
1159  // So make sure that we transfer the whole file with CreateFileStream
1160  rMedium.GetPhysicalName();
1161 
1162  const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
1163  m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
1164 
1165  std::shared_ptr<const SfxFilter> pFilter = rMedium.GetFilter();
1166  if (pFilter)
1167  {
1168  OUString aFltName = pFilter->GetFilterName();
1169 
1170  bool bCalc3 = aFltName == "StarCalc 3.0";
1171  bool bCalc4 = aFltName == "StarCalc 4.0";
1172  if (!bCalc3 && !bCalc4)
1173  m_aDocument.SetInsertingFromOtherDoc( true );
1174 
1175  if (aFltName == pFilterXML)
1176  bRet = LoadXML( &rMedium, nullptr );
1177  else if (aFltName == pFilterLotus)
1178  {
1179  OUString sItStr;
1180  SfxItemSet* pSet = rMedium.GetItemSet();
1181  const SfxPoolItem* pItem;
1182  if ( pSet && SfxItemState::SET ==
1183  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
1184  {
1185  sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
1186  }
1187 
1188  if (sItStr.isEmpty())
1189  {
1190  // default for lotus import (from API without options):
1191  // IBM_437 encoding
1192  sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_437 );
1193  }
1194 
1195  ErrCode eError = ScFormatFilter::Get().ScImportLotus123( rMedium, m_aDocument,
1196  ScGlobal::GetCharsetValue(sItStr));
1197  if (eError != ERRCODE_NONE)
1198  {
1199  if (!GetError())
1200  SetError(eError);
1201 
1202  if( eError.IsWarning() )
1203  bRet = true;
1204  }
1205  else
1206  bRet = true;
1207  bSetColWidths = true;
1208  bSetRowHeights = true;
1209  }
1210  else if ( aFltName == pFilterExcel4 || aFltName == pFilterExcel5 ||
1211  aFltName == pFilterExcel95 || aFltName == pFilterExcel97 ||
1212  aFltName == pFilterEx4Temp || aFltName == pFilterEx5Temp ||
1213  aFltName == pFilterEx95Temp || aFltName == pFilterEx97Temp )
1214  {
1215  EXCIMPFORMAT eFormat = EIF_AUTO;
1216  if ( aFltName == pFilterExcel4 || aFltName == pFilterEx4Temp )
1217  eFormat = EIF_BIFF_LE4;
1218  else if ( aFltName == pFilterExcel5 || aFltName == pFilterExcel95 ||
1219  aFltName == pFilterEx5Temp || aFltName == pFilterEx95Temp )
1220  eFormat = EIF_BIFF5;
1221  else if ( aFltName == pFilterExcel97 || aFltName == pFilterEx97Temp )
1222  eFormat = EIF_BIFF8;
1223 
1224  MakeDrawLayer();
1225  CalcOutputFactor(); // prepare update of row height
1226  ErrCode eError = ScFormatFilter::Get().ScImportExcel( rMedium, &m_aDocument, eFormat );
1227  m_aDocument.UpdateFontCharSet();
1228  if ( m_aDocument.IsChartListenerCollectionNeedsUpdate() )
1229  m_aDocument.UpdateChartListenerCollection();
1230 
1231  // all graphics objects must have names
1232  m_aDocument.EnsureGraphicNames();
1233 
1234  if (eError == SCWARN_IMPORT_RANGE_OVERFLOW)
1235  {
1236  if (!GetError())
1237  SetError(eError);
1238  bRet = true;
1239  }
1240  else if (eError != ERRCODE_NONE)
1241  {
1242  if (!GetError())
1243  SetError(eError);
1244  }
1245  else
1246  bRet = true;
1247  }
1248  else if (aFltName == "Gnumeric Spreadsheet")
1249  {
1251  if (!pOrcus)
1252  return false;
1253 
1254  bRet = pOrcus->importGnumeric(m_aDocument, rMedium);
1255  }
1256  else if (aFltName == "MS Excel 2003 XML Orcus")
1257  {
1259  if (!pOrcus)
1260  return false;
1261 
1262  bRet = pOrcus->importExcel2003XML(m_aDocument, rMedium);
1263  }
1264  else if (aFltName == pFilterAscii)
1265  {
1266  SfxItemSet* pSet = rMedium.GetItemSet();
1267  const SfxPoolItem* pItem;
1268  ScAsciiOptions aOptions;
1269  bool bOptInit = false;
1270 
1271  if ( pSet && SfxItemState::SET ==
1272  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
1273  {
1274  aOptions.ReadFromString( static_cast<const SfxStringItem*>(pItem)->GetValue() );
1275  bOptInit = true;
1276  }
1277 
1278  if ( !bOptInit )
1279  {
1280  // default for ascii import (from API without options):
1281  // ISO8859-1/MS_1252 encoding, comma, double quotes
1282 
1283  aOptions.SetCharSet( RTL_TEXTENCODING_MS_1252 );
1284  aOptions.SetFieldSeps( OUString(',') );
1285  aOptions.SetTextSep( '"' );
1286  }
1287 
1288  ErrCode eError = ERRCODE_NONE;
1289  bool bOverflowRow, bOverflowCol, bOverflowCell;
1290  bOverflowRow = bOverflowCol = bOverflowCell = false;
1291 
1292  if( ! rMedium.IsStorage() )
1293  {
1294  ScImportExport aImpEx( m_aDocument );
1295  aImpEx.SetExtOptions( aOptions );
1296 
1297  SvStream* pInStream = rMedium.GetInStream();
1298  if (pInStream)
1299  {
1300  pInStream->SetStreamCharSet( aOptions.GetCharSet() );
1301  pInStream->Seek( 0 );
1302  bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL(), SotClipboardFormatId::STRING );
1303  eError = bRet ? ERRCODE_NONE : SCERR_IMPORT_CONNECT;
1304  m_aDocument.StartAllListeners();
1306  m_aDocument.SetAllFormulasDirty(aCxt);
1307 
1308  // The same resulting name has to be handled in
1309  // ScExternalRefCache::initializeDoc() and related, hence
1310  // pass 'true' for RenameTab()'s bExternalDocument for a
1311  // composed name so ValidTabName() will not be checked,
1312  // which could veto the rename in case it contained
1313  // characters that Excel does not handle. If we wanted to
1314  // change that then it needed to be handled in all
1315  // corresponding places of the external references
1316  // manager/cache. Likely then we'd also need a method to
1317  // compose a name excluding such characters.
1318  m_aDocument.RenameTab( 0, INetURLObject( rMedium.GetName()).GetBase(), true/*bExternalDocument*/);
1319 
1320  bOverflowRow = aImpEx.IsOverflowRow();
1321  bOverflowCol = aImpEx.IsOverflowCol();
1322  bOverflowCell = aImpEx.IsOverflowCell();
1323  }
1324  else
1325  {
1326  OSL_FAIL( "No Stream" );
1327  }
1328  }
1329 
1330  if (eError != ERRCODE_NONE)
1331  {
1332  if (!GetError())
1333  SetError(eError);
1334  }
1335  else if (!GetError() && (bOverflowRow || bOverflowCol || bOverflowCell))
1336  {
1337  // precedence: row, column, cell
1338  ErrCode nWarn = (bOverflowRow ? SCWARN_IMPORT_ROW_OVERFLOW :
1339  (bOverflowCol ? SCWARN_IMPORT_COLUMN_OVERFLOW :
1341  SetError(nWarn);
1342  }
1343  bSetColWidths = true;
1344  bSetSimpleTextColWidths = true;
1345  }
1346  else if (aFltName == pFilterDBase)
1347  {
1348  OUString sItStr;
1349  SfxItemSet* pSet = rMedium.GetItemSet();
1350  const SfxPoolItem* pItem;
1351  if ( pSet && SfxItemState::SET ==
1352  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
1353  {
1354  sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
1355  }
1356 
1357  if (sItStr.isEmpty())
1358  {
1359  // default for dBase import (from API without options):
1360  // IBM_850 encoding
1361 
1362  sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 );
1363  }
1364 
1365  ScDocRowHeightUpdater::TabRanges aRecalcRanges(0, m_aDocument.MaxRow());
1366  ErrCode eError = DBaseImport( rMedium.GetPhysicalName(),
1367  ScGlobal::GetCharsetValue(sItStr), aColWidthParam, aRecalcRanges.maRanges );
1368  aRecalcRowRangesArray.push_back(aRecalcRanges);
1369 
1370  if (eError != ERRCODE_NONE)
1371  {
1372  if (!GetError())
1373  SetError(eError);
1374  bRet = ( eError == SCWARN_IMPORT_RANGE_OVERFLOW );
1375  }
1376  else
1377  bRet = true;
1378 
1379  aColWidthRange.aStart.SetRow( 1 ); // Except for the column header
1380  bSetColWidths = true;
1381  bSetSimpleTextColWidths = true;
1382  }
1383  else if (aFltName == pFilterDif)
1384  {
1385  SvStream* pStream = rMedium.GetInStream();
1386  if (pStream)
1387  {
1388  ErrCode eError;
1389  OUString sItStr;
1390  SfxItemSet* pSet = rMedium.GetItemSet();
1391  const SfxPoolItem* pItem;
1392  if ( pSet && SfxItemState::SET ==
1393  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
1394  {
1395  sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
1396  }
1397 
1398  if (sItStr.isEmpty())
1399  {
1400  // default for DIF import (from API without options):
1401  // ISO8859-1/MS_1252 encoding
1402 
1403  sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 );
1404  }
1405 
1406  eError = ScFormatFilter::Get().ScImportDif( *pStream, &m_aDocument, ScAddress(0,0,0),
1407  ScGlobal::GetCharsetValue(sItStr));
1408  if (eError != ERRCODE_NONE)
1409  {
1410  if (!GetError())
1411  SetError(eError);
1412 
1413  if( eError.IsWarning() )
1414  bRet = true;
1415  }
1416  else
1417  bRet = true;
1418  }
1419  bSetColWidths = true;
1420  bSetSimpleTextColWidths = true;
1421  bSetRowHeights = true;
1422  }
1423  else if (aFltName == pFilterSylk)
1424  {
1425  ErrCode eError = SCERR_IMPORT_UNKNOWN;
1426  bool bOverflowRow, bOverflowCol, bOverflowCell;
1427  bOverflowRow = bOverflowCol = bOverflowCell = false;
1428  if( !rMedium.IsStorage() )
1429  {
1430  ScImportExport aImpEx( m_aDocument );
1431 
1432  SvStream* pInStream = rMedium.GetInStream();
1433  if (pInStream)
1434  {
1435  pInStream->Seek( 0 );
1436  bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL(), SotClipboardFormatId::SYLK );
1437  eError = bRet ? ERRCODE_NONE : SCERR_IMPORT_UNKNOWN;
1438  m_aDocument.StartAllListeners();
1440  m_aDocument.SetAllFormulasDirty(aCxt);
1441 
1442  bOverflowRow = aImpEx.IsOverflowRow();
1443  bOverflowCol = aImpEx.IsOverflowCol();
1444  bOverflowCell = aImpEx.IsOverflowCell();
1445  }
1446  else
1447  {
1448  OSL_FAIL( "No Stream" );
1449  }
1450  }
1451 
1452  if ( eError != ERRCODE_NONE && !GetError() )
1453  SetError(eError);
1454  else if (!GetError() && (bOverflowRow || bOverflowCol || bOverflowCell))
1455  {
1456  // precedence: row, column, cell
1457  ErrCode nWarn = (bOverflowRow ? SCWARN_IMPORT_ROW_OVERFLOW :
1458  (bOverflowCol ? SCWARN_IMPORT_COLUMN_OVERFLOW :
1460  SetError(nWarn);
1461  }
1462  bSetColWidths = true;
1463  bSetSimpleTextColWidths = true;
1464  bSetRowHeights = true;
1465  }
1466  else if (aFltName == pFilterQPro6)
1467  {
1468  ErrCode eError = ScFormatFilter::Get().ScImportQuattroPro(rMedium.GetInStream(), m_aDocument);
1469  if (eError != ERRCODE_NONE)
1470  {
1471  if (!GetError())
1472  SetError(eError);
1473  if( eError.IsWarning() )
1474  bRet = true;
1475  }
1476  else
1477  bRet = true;
1478  // TODO: Filter should set column widths. Not doing it here, it may
1479  // result in very narrow or wide columns, depending on content.
1480  // Setting row heights makes cells with font size attribution or
1481  // wrapping enabled look nicer...
1482  bSetRowHeights = true;
1483  }
1484  else if (aFltName == pFilterRtf)
1485  {
1486  ErrCode eError = SCERR_IMPORT_UNKNOWN;
1487  if( !rMedium.IsStorage() )
1488  {
1489  SvStream* pInStream = rMedium.GetInStream();
1490  if (pInStream)
1491  {
1492  pInStream->Seek( 0 );
1493  ScRange aRange;
1494  eError = ScFormatFilter::Get().ScImportRTF( *pInStream, rMedium.GetBaseURL(), &m_aDocument, aRange );
1495  if (eError != ERRCODE_NONE)
1496  {
1497  if (!GetError())
1498  SetError(eError);
1499 
1500  if( eError.IsWarning() )
1501  bRet = true;
1502  }
1503  else
1504  bRet = true;
1505  m_aDocument.StartAllListeners();
1507  m_aDocument.SetAllFormulasDirty(aCxt);
1508  bSetColWidths = true;
1509  bSetRowHeights = true;
1510  }
1511  else
1512  {
1513  OSL_FAIL( "No Stream" );
1514  }
1515  }
1516 
1517  if ( eError != ERRCODE_NONE && !GetError() )
1518  SetError(eError);
1519  }
1520  else if (aFltName == pFilterHtml || aFltName == pFilterHtmlWebQ)
1521  {
1522  ErrCode eError = SCERR_IMPORT_UNKNOWN;
1523  bool bWebQuery = aFltName == pFilterHtmlWebQ;
1524  if( !rMedium.IsStorage() )
1525  {
1526  SvStream* pInStream = rMedium.GetInStream();
1527  if (pInStream)
1528  {
1529  LanguageType eLang = LANGUAGE_SYSTEM;
1530  bool bDateConvert = false;
1531  SfxItemSet* pSet = rMedium.GetItemSet();
1532  const SfxPoolItem* pItem;
1533  if ( pSet && SfxItemState::SET ==
1534  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
1535  {
1536  OUString aFilterOption = static_cast<const SfxStringItem*>(pItem)->GetValue();
1537  lcl_parseHtmlFilterOption(aFilterOption, eLang, bDateConvert);
1538  }
1539 
1540  pInStream->Seek( 0 );
1541  ScRange aRange;
1542  // HTML does its own ColWidth/RowHeight
1543  CalcOutputFactor();
1545  eError = ScFormatFilter::Get().ScImportHTML( *pInStream, rMedium.GetBaseURL(), &m_aDocument, aRange,
1546  GetOutputFactor(), !bWebQuery, &aNumFormatter, bDateConvert );
1547  if (eError != ERRCODE_NONE)
1548  {
1549  if (!GetError())
1550  SetError(eError);
1551 
1552  if( eError.IsWarning() )
1553  bRet = true;
1554  }
1555  else
1556  bRet = true;
1557  m_aDocument.StartAllListeners();
1558 
1560  m_aDocument.SetAllFormulasDirty(aCxt);
1561  }
1562  else
1563  {
1564  OSL_FAIL( "No Stream" );
1565  }
1566  }
1567 
1568  if ( eError != ERRCODE_NONE && !GetError() )
1569  SetError(eError);
1570  }
1571  else
1572  {
1573  if (!GetError())
1574  {
1575  SAL_WARN("sc.filter", "No match for filter '" << aFltName << "' in ConvertFrom");
1577  }
1578  }
1579 
1580  if (!bCalc3)
1581  m_aDocument.SetInsertingFromOtherDoc( false );
1582  }
1583  else
1584  {
1585  OSL_FAIL("No Filter in ConvertFrom");
1586  }
1587 
1588  InitItems();
1589  CalcOutputFactor();
1590  if ( bRet && (bSetColWidths || bSetRowHeights) )
1591  { // Adjust column width/row height; base 100% zoom
1592  Fraction aZoom( 1, 1 );
1593  double nPPTX = ScGlobal::nScreenPPTX * static_cast<double>(aZoom) / GetOutputFactor(); // Factor is printer display ratio
1594  double nPPTY = ScGlobal::nScreenPPTY * static_cast<double>(aZoom);
1596  // all sheets (for Excel import)
1597  SCTAB nTabCount = m_aDocument.GetTableCount();
1598  for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1599  {
1600  SCCOL nEndCol;
1601  SCROW nEndRow;
1602  m_aDocument.GetCellArea( nTab, nEndCol, nEndRow );
1603  aColWidthRange.aEnd.SetCol( nEndCol );
1604  aColWidthRange.aEnd.SetRow( nEndRow );
1605  ScMarkData aMark(m_aDocument.GetSheetLimits());
1606  aMark.SetMarkArea( aColWidthRange );
1607  aMark.MarkToMulti();
1608 
1609  // Order is important: First width, then height
1610  if ( bSetColWidths )
1611  {
1612  for ( SCCOL nCol=0; nCol <= nEndCol; nCol++ )
1613  {
1614  if (!bSetSimpleTextColWidths)
1615  aColWidthParam[nCol].mbSimpleText = false;
1616 
1617  sal_uInt16 nWidth = m_aDocument.GetOptimalColWidth(
1618  nCol, nTab, pVirtDev, nPPTX, nPPTY, aZoom, aZoom, false, &aMark,
1619  &aColWidthParam[nCol] );
1620  m_aDocument.SetColWidth( nCol, nTab,
1621  nWidth + static_cast<sal_uInt16>(ScGlobal::nLastColWidthExtra) );
1622  }
1623  }
1624  }
1625 
1626  if (bSetRowHeights)
1627  {
1628  // Update all rows in all tables.
1629  ScSizeDeviceProvider aProv(this);
1630  ScDocRowHeightUpdater aUpdater(m_aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), nullptr);
1631  aUpdater.update();
1632  }
1633  else if (!aRecalcRowRangesArray.empty())
1634  {
1635  // Update only specified row ranges for better performance.
1636  ScSizeDeviceProvider aProv(this);
1637  ScDocRowHeightUpdater aUpdater(m_aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), &aRecalcRowRangesArray);
1638  aUpdater.update();
1639  }
1640  }
1641  FinishedLoading();
1642 
1643  // invalidate eventually temporary table areas
1644  if ( bRet )
1645  m_aDocument.InvalidateTableArea();
1646 
1647  m_bIsEmpty = false;
1648 
1649  return bRet;
1650 }
1651 
1653 {
1654  std::shared_ptr<const SfxFilter> pFilter = rMed.GetFilter();
1655  if (!pFilter)
1656  return false;
1657 
1658  if (pFilter->GetProviderName() == "orcus")
1659  {
1661  if (!pOrcus)
1662  return false;
1663 
1664  const OUString& rFilterName = pFilter->GetName();
1665  if (rFilterName == "gnumeric")
1666  {
1667  if (!pOrcus->importGnumeric(m_aDocument, rMed))
1668  return false;
1669  }
1670  else if (rFilterName == "csv")
1671  {
1672  if (!pOrcus->importCSV(m_aDocument, rMed))
1673  return false;
1674  }
1675  else if (rFilterName == "xlsx")
1676  {
1677  if (!pOrcus->importXLSX(m_aDocument, rMed))
1678  return false;
1679  }
1680  else if (rFilterName == "ods")
1681  {
1682  if (!pOrcus->importODS(m_aDocument, rMed))
1683  return false;
1684  }
1685 
1686  FinishedLoading();
1687  return true;
1688  }
1689 
1690  return false;
1691 }
1692 
1694  : mrDocShell( rDocShell)
1695 {
1696  // DoEnterHandler not here (because of AutoSave), is in ExecuteSave.
1697 
1699  if (pCharts)
1700  pCharts->UpdateDirtyCharts(); // Charts to be updated.
1703  mrDocShell.m_pAutoStyleList->ExecuteAllNow(); // Execute template timeouts now.
1705  {
1707  if (pRefMgr && pRefMgr->hasExternalData())
1708  {
1709  pRefMgr->setAllCacheTableReferencedStati( false);
1710  mrDocShell.m_aDocument.MarkUsedExternalReferences(); // Mark tables of external references to be written.
1711  }
1712  }
1713  if (mrDocShell.GetCreateMode()== SfxObjectCreateMode::STANDARD)
1714  mrDocShell.SfxObjectShell::SetVisArea( tools::Rectangle() ); // "Normally" worked on => no VisArea.
1715 }
1716 
1718 {
1719  if (mrDocShell.m_aDocument.HasExternalRefManager())
1720  {
1721  ScExternalRefManager* pRefMgr = mrDocShell.m_aDocument.GetExternalRefManager();
1722  if (pRefMgr && pRefMgr->hasExternalData())
1723  {
1724  // Prevent accidental data loss due to lack of knowledge.
1725  pRefMgr->setAllCacheTableReferencedStati( true);
1726  }
1727  }
1728 }
1729 
1731 {
1733 
1734  PrepareSaveGuard aPrepareGuard( *this);
1735 
1736  if (const auto pFrame1 = SfxViewFrame::GetFirst(this))
1737  {
1738  if (auto pSysWin = pFrame1->GetWindow().GetSystemWindow())
1739  {
1740  pSysWin->SetAccessibleName(OUString());
1741  }
1742  }
1743  // wait cursor is handled with progress bar
1744  bool bRet = SfxObjectShell::Save();
1745  if( bRet )
1746  bRet = SaveXML( GetMedium(), nullptr );
1747  return bRet;
1748 }
1749 
1750 namespace {
1751 
1755 void popFileName(OUString& rPath)
1756 {
1757  if (!rPath.isEmpty())
1758  {
1759  INetURLObject aURLObj(rPath);
1760  aURLObj.removeSegment();
1761  rPath = aURLObj.GetMainURL(INetURLObject::DecodeMechanism::NONE);
1762  }
1763 }
1764 
1765 }
1766 
1768 {
1769  // Commit any cell changes before saving.
1770  SC_MOD()->InputEnterHandler();
1771 }
1772 
1774 {
1775  OUString aCurPath; // empty for new document that hasn't been saved.
1776  const SfxMedium* pCurMedium = GetMedium();
1777  if (pCurMedium)
1778  {
1779  aCurPath = pCurMedium->GetName();
1780  popFileName(aCurPath);
1781  }
1782 
1783  if (!aCurPath.isEmpty())
1784  {
1785  // current document has a path -> not a brand-new document.
1786  OUString aNewPath = rMedium.GetName();
1787  popFileName(aNewPath);
1788  OUString aRel = URIHelper::simpleNormalizedMakeRelative(aCurPath, aNewPath);
1789  if (!aRel.isEmpty())
1790  {
1791  // Directory path will change before and after the save.
1793  }
1794  }
1795 
1796  ScTabViewShell* pViewShell = GetBestViewShell();
1798  if (bNeedsRehash)
1799  // legacy xls hash double-hashed by SHA1 is also supported.
1801  if (bNeedsRehash)
1802  { // SHA256 explicitly supported in ODF 1.2, implicitly in ODF 1.1
1804  }
1805 
1806  if (pViewShell && bNeedsRehash)
1807  {
1808  if (!pViewShell->ExecuteRetypePassDlg(PASSHASH_SHA1))
1809  // password re-type cancelled. Don't save the document.
1810  return false;
1811  }
1812 
1814 
1815  PrepareSaveGuard aPrepareGuard( *this);
1816 
1817  // wait cursor is handled with progress bar
1818  bool bRet = SfxObjectShell::SaveAs( rMedium );
1819  if (bRet)
1820  bRet = SaveXML( &rMedium, nullptr );
1821 
1822  return bRet;
1823 }
1824 
1825 namespace {
1826 
1827 // Xcl-like column width measured in characters of standard font.
1828 sal_Int32 lcl_ScDocShell_GetColWidthInChars( sal_uInt16 nWidth )
1829 {
1830  double f = nWidth;
1831  f *= 1328.0 / 25.0;
1832  f += 90.0;
1833  f *= 1.0 / 23.0;
1834  f /= 256.0;
1835 
1836  return sal_Int32( f );
1837 }
1838 
1839 void lcl_ScDocShell_GetFixedWidthString( OUString& rStr, const ScDocument& rDoc,
1840  SCTAB nTab, SCCOL nCol, bool bValue, SvxCellHorJustify eHorJust )
1841 {
1842  OUString aString = rStr;
1843  sal_Int32 nLen = lcl_ScDocShell_GetColWidthInChars(
1844  rDoc.GetColWidth( nCol, nTab ) );
1845  //If the text won't fit in the column
1846  if ( nLen < aString.getLength() )
1847  {
1848  OUStringBuffer aReplacement;
1849  if (bValue)
1850  aReplacement.append("###");
1851  else
1852  aReplacement.append(aString);
1853  //truncate to the number of characters that should fit, even in the
1854  //bValue case nLen might be < len ###
1855  aString = comphelper::string::truncateToLength(aReplacement, nLen).makeStringAndClear();
1856  }
1857  if ( nLen > aString.getLength() )
1858  {
1859  if ( bValue && eHorJust == SvxCellHorJustify::Standard )
1860  eHorJust = SvxCellHorJustify::Right;
1861  sal_Int32 nBlanks = nLen - aString.getLength();
1862  switch ( eHorJust )
1863  {
1864  case SvxCellHorJustify::Right:
1865  {
1866  OUStringBuffer aTmp;
1867  comphelper::string::padToLength( aTmp, nBlanks, ' ' );
1868  aString = aTmp.append(aString).makeStringAndClear();
1869  }
1870  break;
1871  case SvxCellHorJustify::Center:
1872  {
1873  sal_Int32 nLeftPad = nBlanks / 2;
1874  OUStringBuffer aTmp;
1875  comphelper::string::padToLength( aTmp, nLeftPad, ' ' );
1876  aTmp.append(aString);
1877  comphelper::string::padToLength( aTmp, nLen, ' ' );
1878  aString = aTmp.makeStringAndClear();
1879  }
1880  break;
1881  default:
1882  {
1883  OUStringBuffer aTmp(aString);
1884  comphelper::string::padToLength( aTmp, nLen, ' ' );
1885  aString = aTmp.makeStringAndClear();
1886  }
1887  }
1888  }
1889  rStr = aString;
1890 }
1891 
1892 void lcl_ScDocShell_WriteEmptyFixedWidthString( SvStream& rStream,
1893  const ScDocument& rDoc, SCTAB nTab, SCCOL nCol )
1894 {
1895  OUString aString;
1896  lcl_ScDocShell_GetFixedWidthString( aString, rDoc, nTab, nCol, false,
1897  SvxCellHorJustify::Standard );
1898  rStream.WriteUnicodeOrByteText( aString );
1899 }
1900 
1901 template<typename StrT, typename SepCharT>
1902 sal_Int32 getTextSepPos(
1903  const StrT& rStr, const ScImportOptions& rAsciiOpt, const SepCharT& rTextSep, const SepCharT& rFieldSep, bool& rNeedQuotes)
1904 {
1905  // #i116636# quotes are needed if text delimiter (quote), field delimiter,
1906  // or LF or CR is in the cell text.
1907  sal_Int32 nPos = rStr.indexOf(rTextSep);
1908  rNeedQuotes = rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
1909  (rStr.indexOf(rFieldSep) >= 0) ||
1910  (rStr.indexOf('\n') >= 0) ||
1911  (rStr.indexOf('\r') >= 0);
1912  return nPos;
1913 }
1914 
1915 template<typename StrT, typename StrBufT>
1916 void escapeTextSep(sal_Int32 nPos, const StrT& rStrDelim, StrT& rStr)
1917 {
1918  while (nPos >= 0)
1919  {
1920  StrBufT aBuf(rStr);
1921  aBuf.insert(nPos, rStrDelim);
1922  rStr = aBuf.makeStringAndClear();
1923  nPos = rStr.indexOf(rStrDelim, nPos+1+rStrDelim.getLength());
1924  }
1925 }
1926 
1927 }
1928 
1929 void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt )
1930 {
1931  sal_Unicode cDelim = rAsciiOpt.nFieldSepCode;
1932  sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
1933  rtl_TextEncoding eCharSet = rAsciiOpt.eCharSet;
1934  bool bFixedWidth = rAsciiOpt.bFixedWidth;
1935  bool bSaveNumberAsSuch = rAsciiOpt.bSaveNumberAsSuch;
1936  bool bSaveAsShown = rAsciiOpt.bSaveAsShown;
1937  bool bShowFormulas = rAsciiOpt.bSaveFormulas;
1938 
1939  rtl_TextEncoding eOldCharSet = rStream.GetStreamCharSet();
1940  rStream.SetStreamCharSet( eCharSet );
1941  SvStreamEndian nOldNumberFormatInt = rStream.GetEndian();
1942  OString aStrDelimEncoded; // only used if not Unicode
1943  OUString aStrDelimDecoded; // only used if context encoding
1944  OString aDelimEncoded;
1945  OUString aDelimDecoded;
1946  bool bContextOrNotAsciiEncoding;
1947  if ( eCharSet == RTL_TEXTENCODING_UNICODE )
1948  {
1949  rStream.StartWritingUnicodeText();
1950  bContextOrNotAsciiEncoding = false;
1951  }
1952  else
1953  {
1954  aStrDelimEncoded = OString(&cStrDelim, 1, eCharSet);
1955  aDelimEncoded = OString(&cDelim, 1, eCharSet);
1956  rtl_TextEncodingInfo aInfo;
1957  aInfo.StructSize = sizeof(aInfo);
1958  if ( rtl_getTextEncodingInfo( eCharSet, &aInfo ) )
1959  {
1960  bContextOrNotAsciiEncoding =
1961  (((aInfo.Flags & RTL_TEXTENCODING_INFO_CONTEXT) != 0) ||
1962  ((aInfo.Flags & RTL_TEXTENCODING_INFO_ASCII) == 0));
1963  if ( bContextOrNotAsciiEncoding )
1964  {
1965  aStrDelimDecoded = OStringToOUString(aStrDelimEncoded, eCharSet);
1966  aDelimDecoded = OStringToOUString(aDelimEncoded, eCharSet);
1967  }
1968  }
1969  else
1970  bContextOrNotAsciiEncoding = false;
1971  }
1972 
1973  SCCOL nStartCol = 0;
1974  SCROW nStartRow = 0;
1975  SCTAB nTab = GetSaveTab();
1976  SCCOL nEndCol;
1977  SCROW nEndRow;
1978  m_aDocument.GetCellArea( nTab, nEndCol, nEndRow );
1979 
1980  ScProgress aProgress( this, ScResId( STR_SAVE_DOC ), nEndRow, true );
1981 
1982  OUString aString;
1983 
1984  bool bTabProtect = m_aDocument.IsTabProtected( nTab );
1985 
1986  SCCOL nCol;
1987  SCROW nRow;
1988  SCCOL nNextCol = nStartCol;
1989  SCROW nNextRow = nStartRow;
1990  SCCOL nEmptyCol;
1991  SCROW nEmptyRow;
1992  SvNumberFormatter& rFormatter = *m_aDocument.GetFormatTable();
1993 
1994  ScHorizontalCellIterator aIter( m_aDocument, nTab, nStartCol, nStartRow,
1995  nEndCol, nEndRow );
1996  ScRefCellValue* pCell;
1997  while ( ( pCell = aIter.GetNext( nCol, nRow ) ) != nullptr )
1998  {
1999  bool bProgress = false; // only upon line change
2000  if ( nNextRow < nRow )
2001  { // empty rows or/and empty columns up to end of row
2002  bProgress = true;
2003  for ( nEmptyCol = nNextCol; nEmptyCol < nEndCol; nEmptyCol++ )
2004  { // remaining columns of last row
2005  if ( bFixedWidth )
2006  lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2007  m_aDocument, nTab, nEmptyCol );
2008  else if ( cDelim != 0 )
2009  rStream.WriteUniOrByteChar( cDelim );
2010  }
2011  endlub( rStream );
2012  nNextRow++;
2013  for ( nEmptyRow = nNextRow; nEmptyRow < nRow; nEmptyRow++ )
2014  { // completely empty rows
2015  for ( nEmptyCol = nStartCol; nEmptyCol < nEndCol; nEmptyCol++ )
2016  {
2017  if ( bFixedWidth )
2018  lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2019  m_aDocument, nTab, nEmptyCol );
2020  else if ( cDelim != 0 )
2021  rStream.WriteUniOrByteChar( cDelim );
2022  }
2023  endlub( rStream );
2024  }
2025  for ( nEmptyCol = nStartCol; nEmptyCol < nCol; nEmptyCol++ )
2026  { // empty columns at beginning of row
2027  if ( bFixedWidth )
2028  lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2029  m_aDocument, nTab, nEmptyCol );
2030  else if ( cDelim != 0 )
2031  rStream.WriteUniOrByteChar( cDelim );
2032  }
2033  nNextRow = nRow;
2034  }
2035  else if ( nNextCol < nCol )
2036  { // empty columns in same row
2037  for ( nEmptyCol = nNextCol; nEmptyCol < nCol; nEmptyCol++ )
2038  { // columns in between
2039  if ( bFixedWidth )
2040  lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2041  m_aDocument, nTab, nEmptyCol );
2042  else if ( cDelim != 0 )
2043  rStream.WriteUniOrByteChar( cDelim );
2044  }
2045  }
2046  if ( nCol == nEndCol )
2047  {
2048  bProgress = true;
2049  nNextCol = nStartCol;
2050  nNextRow = nRow + 1;
2051  }
2052  else
2053  nNextCol = nCol + 1;
2054 
2055  CellType eType = pCell->meType;
2056  ScAddress aPos(nCol, nRow, nTab);
2057  if ( bTabProtect )
2058  {
2059  const ScProtectionAttr* pProtAttr =
2060  m_aDocument.GetAttr( nCol, nRow, nTab, ATTR_PROTECTION );
2061  if ( pProtAttr->GetHideCell() ||
2062  ( eType == CELLTYPE_FORMULA && bShowFormulas &&
2063  pProtAttr->GetHideFormula() ) )
2064  eType = CELLTYPE_NONE; // hide
2065  }
2066  bool bForceQuotes = false;
2067  bool bString;
2068  switch ( eType )
2069  {
2070  case CELLTYPE_NONE:
2071  aString.clear();
2072  bString = false;
2073  break;
2074  case CELLTYPE_FORMULA :
2075  {
2076  FormulaError nErrCode;
2077  if ( bShowFormulas )
2078  {
2079  pCell->mpFormula->GetFormula(aString);
2080  bString = true;
2081  }
2082  else if ((nErrCode = pCell->mpFormula->GetErrCode()) != FormulaError::NONE)
2083  {
2084  aString = ScGlobal::GetErrorString( nErrCode );
2085  bString = true;
2086  }
2087  else if (pCell->mpFormula->IsValue())
2088  {
2089  sal_uInt32 nFormat = m_aDocument.GetNumberFormat(aPos);
2090  if ( bFixedWidth || bSaveAsShown )
2091  {
2092  const Color* pDummy;
2093  ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, m_aDocument);
2094  bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
2095  }
2096  else
2097  {
2098  ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, m_aDocument);
2099  bString = bForceQuotes = !bSaveNumberAsSuch;
2100  }
2101  }
2102  else
2103  {
2104  if ( bSaveAsShown )
2105  {
2106  sal_uInt32 nFormat = m_aDocument.GetNumberFormat(aPos);
2107  const Color* pDummy;
2108  ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, m_aDocument);
2109  }
2110  else
2111  aString = pCell->mpFormula->GetString().getString();
2112  bString = true;
2113  }
2114  }
2115  break;
2116  case CELLTYPE_STRING :
2117  if ( bSaveAsShown )
2118  {
2119  sal_uInt32 nFormat = m_aDocument.GetNumberFormat(aPos);
2120  const Color* pDummy;
2121  ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, m_aDocument);
2122  }
2123  else
2124  aString = pCell->mpString->getString();
2125  bString = true;
2126  break;
2127  case CELLTYPE_EDIT :
2128  {
2129  const EditTextObject* pObj = pCell->mpEditText;
2130  EditEngine& rEngine = m_aDocument.GetEditEngine();
2131  rEngine.SetText( *pObj);
2132  aString = rEngine.GetText(); // including LF
2133  bString = true;
2134  }
2135  break;
2136  case CELLTYPE_VALUE :
2137  {
2138  sal_uInt32 nFormat;
2139  m_aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
2140  if ( bFixedWidth || bSaveAsShown )
2141  {
2142  const Color* pDummy;
2143  ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, m_aDocument);
2144  bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
2145  }
2146  else
2147  {
2148  ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, m_aDocument);
2149  bString = bForceQuotes = !bSaveNumberAsSuch;
2150  }
2151  }
2152  break;
2153  default:
2154  OSL_FAIL( "ScDocShell::AsciiSave: unknown CellType" );
2155  aString.clear();
2156  bString = false;
2157  }
2158 
2159  if ( bFixedWidth )
2160  {
2161  SvxCellHorJustify eHorJust =
2162  m_aDocument.GetAttr( nCol, nRow, nTab, ATTR_HOR_JUSTIFY )->GetValue();
2163  lcl_ScDocShell_GetFixedWidthString( aString, m_aDocument, nTab, nCol,
2164  !bString, eHorJust );
2165  rStream.WriteUnicodeOrByteText( aString );
2166  }
2167  else
2168  {
2169  OUString aUniString = aString;// TODO: remove that later
2170  if (!bString && cStrDelim != 0 && !aUniString.isEmpty())
2171  {
2172  sal_Unicode c = aUniString[0];
2173  bString = (c == cStrDelim || c == ' ' ||
2174  aUniString.endsWith(" ") ||
2175  aUniString.indexOf(cStrDelim) >= 0);
2176  if (!bString && cDelim != 0)
2177  bString = (aUniString.indexOf(cDelim) >= 0);
2178  }
2179  if ( bString )
2180  {
2181  if ( cStrDelim != 0 ) //@ BugId 55355
2182  {
2183  if ( eCharSet == RTL_TEXTENCODING_UNICODE )
2184  {
2185  bool bNeedQuotes = false;
2186  sal_Int32 nPos = getTextSepPos(
2187  aUniString, rAsciiOpt, cStrDelim, cDelim, bNeedQuotes);
2188 
2189  escapeTextSep<OUString, OUStringBuffer>(
2190  nPos, OUString(cStrDelim), aUniString);
2191 
2192  if ( bNeedQuotes || bForceQuotes )
2193  rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
2194  write_uInt16s_FromOUString(rStream, aUniString);
2195  if ( bNeedQuotes || bForceQuotes )
2196  rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
2197  }
2198  else
2199  {
2200  // This is nasty. The Unicode to byte encoding
2201  // may convert typographical quotation marks to ASCII
2202  // quotation marks, which may interfere with the delimiter,
2203  // so we have to escape delimiters after the string has
2204  // been encoded. Since this may happen also with UTF-8
2205  // encoded typographical quotation marks if such was
2206  // specified as a delimiter we have to check for the full
2207  // encoded delimiter string, not just one character.
2208  // Now for RTL_TEXTENCODING_ISO_2022_... and similar brain
2209  // dead encodings where one code point (and especially a
2210  // low ASCII value) may represent different characters, we
2211  // have to convert forth and back and forth again. Same for
2212  // UTF-7 since it is a context sensitive encoding too.
2213 
2214  if ( bContextOrNotAsciiEncoding )
2215  {
2216  // to byte encoding
2217  OString aStrEnc = OUStringToOString(aUniString, eCharSet);
2218  // back to Unicode
2219  OUString aStrDec = OStringToOUString(aStrEnc, eCharSet);
2220 
2221  // search on re-decoded string
2222  bool bNeedQuotes = false;
2223  sal_Int32 nPos = getTextSepPos(
2224  aStrDec, rAsciiOpt, aStrDelimDecoded, aDelimDecoded, bNeedQuotes);
2225 
2226  escapeTextSep<OUString, OUStringBuffer>(
2227  nPos, aStrDelimDecoded, aStrDec);
2228 
2229  // write byte re-encoded
2230  if ( bNeedQuotes || bForceQuotes )
2231  rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
2232  rStream.WriteUnicodeOrByteText( aStrDec, eCharSet );
2233  if ( bNeedQuotes || bForceQuotes )
2234  rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
2235  }
2236  else
2237  {
2238  OString aStrEnc = OUStringToOString(aUniString, eCharSet);
2239 
2240  // search on encoded string
2241  bool bNeedQuotes = false;
2242  sal_Int32 nPos = getTextSepPos(
2243  aStrEnc, rAsciiOpt, aStrDelimEncoded, aDelimEncoded, bNeedQuotes);
2244 
2245  escapeTextSep<OString, OStringBuffer>(
2246  nPos, aStrDelimEncoded, aStrEnc);
2247 
2248  // write byte encoded
2249  if ( bNeedQuotes || bForceQuotes )
2250  rStream.WriteBytes(
2251  aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
2252  rStream.WriteBytes(aStrEnc.getStr(), aStrEnc.getLength());
2253  if ( bNeedQuotes || bForceQuotes )
2254  rStream.WriteBytes(
2255  aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
2256  }
2257  }
2258  }
2259  else
2260  rStream.WriteUnicodeOrByteText( aUniString );
2261  }
2262  else
2263  rStream.WriteUnicodeOrByteText( aUniString );
2264  }
2265 
2266  if( nCol < nEndCol )
2267  {
2268  if(cDelim!=0) //@ BugId 55355
2269  rStream.WriteUniOrByteChar( cDelim );
2270  }
2271  else
2272  endlub( rStream );
2273 
2274  if ( bProgress )
2275  aProgress.SetStateOnPercent( nRow );
2276  }
2277 
2278  // write out empty if requested
2279  if ( nNextRow <= nEndRow )
2280  {
2281  for ( nEmptyCol = nNextCol; nEmptyCol < nEndCol; nEmptyCol++ )
2282  { // remaining empty columns of last row
2283  if ( bFixedWidth )
2284  lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2285  m_aDocument, nTab, nEmptyCol );
2286  else if ( cDelim != 0 )
2287  rStream.WriteUniOrByteChar( cDelim );
2288  }
2289  endlub( rStream );
2290  nNextRow++;
2291  }
2292  for ( nEmptyRow = nNextRow; nEmptyRow <= nEndRow; nEmptyRow++ )
2293  { // entire empty rows
2294  for ( nEmptyCol = nStartCol; nEmptyCol < nEndCol; nEmptyCol++ )
2295  {
2296  if ( bFixedWidth )
2297  lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
2298  m_aDocument, nTab, nEmptyCol );
2299  else if ( cDelim != 0 )
2300  rStream.WriteUniOrByteChar( cDelim );
2301  }
2302  endlub( rStream );
2303  }
2304 
2305  rStream.SetStreamCharSet( eOldCharSet );
2306  rStream.SetEndian( nOldNumberFormatInt );
2307 }
2308 
2310 {
2312 
2313  // #i6500# don't call DoEnterHandler here (doesn't work with AutoSave),
2314  // it's already in ExecuteSave (as for Save and SaveAs)
2315 
2316  if (m_pAutoStyleList)
2317  m_pAutoStyleList->ExecuteAllNow(); // Execute template timeouts now
2318  if (GetCreateMode()== SfxObjectCreateMode::STANDARD)
2319  SfxObjectShell::SetVisArea( tools::Rectangle() ); // Edited normally -> no VisArea
2320 
2321  OSL_ENSURE( rMed.GetFilter(), "Filter == 0" );
2322 
2323  bool bRet = false;
2324  OUString aFltName = rMed.GetFilter()->GetFilterName();
2325 
2326  if (aFltName == pFilterXML)
2327  {
2328  //TODO/LATER: this shouldn't happen!
2329  OSL_FAIL("XML filter in ConvertFrom?!");
2330  bRet = SaveXML( &rMed, nullptr );
2331  }
2332  else if (aFltName == pFilterExcel5 || aFltName == pFilterExcel95 ||
2333  aFltName == pFilterExcel97 || aFltName == pFilterEx5Temp ||
2334  aFltName == pFilterEx95Temp || aFltName == pFilterEx97Temp)
2335  {
2337 
2338  bool bDoSave = true;
2339  if( ScTabViewShell* pViewShell = GetBestViewShell() )
2340  {
2342  if( !pExtDocOpt )
2343  {
2344  m_aDocument.SetExtDocOptions( std::make_unique<ScExtDocOptions>() );
2345  pExtDocOpt = m_aDocument.GetExtDocOptions();
2346  }
2347  pViewShell->GetViewData().WriteExtOptions( *pExtDocOpt );
2348 
2349  /* #i104990# If the imported document contains a medium
2350  password, determine if we can save it, otherwise ask the users
2351  whether they want to save without it. */
2352  if( (rMed.GetFilter()->GetFilterFlags() & SfxFilterFlags::ENCRYPTION) == SfxFilterFlags::NONE )
2353  {
2354  SfxItemSet* pItemSet = rMed.GetItemSet();
2355  const SfxPoolItem* pItem = nullptr;
2356  if( pItemSet && pItemSet->GetItemState( SID_PASSWORD, true, &pItem ) == SfxItemState::SET )
2357  {
2358  bDoSave = ScWarnPassword::WarningOnPassword( rMed );
2359  // #i42858# remove password from medium (warn only one time)
2360  if( bDoSave )
2361  pItemSet->ClearItem( SID_PASSWORD );
2362  }
2363  }
2364 
2365  if( bDoSave )
2366  {
2367  bool bNeedRetypePassDlg = ScPassHashHelper::needsPassHashRegen( m_aDocument, PASSHASH_XL );
2368  bDoSave = !bNeedRetypePassDlg || pViewShell->ExecuteRetypePassDlg( PASSHASH_XL );
2369  }
2370  }
2371 
2372  if( bDoSave )
2373  {
2374  ExportFormatExcel eFormat = ExpBiff5;
2375  if( aFltName == pFilterExcel97 || aFltName == pFilterEx97Temp )
2376  eFormat = ExpBiff8;
2377  ErrCode eError = ScFormatFilter::Get().ScExportExcel5( rMed, &m_aDocument, eFormat, RTL_TEXTENCODING_MS_1252 );
2378 
2379  if( eError && !GetError() )
2380  SetError(eError);
2381 
2382  // don't return false for warnings
2383  bRet = eError.IsWarning() || (eError == ERRCODE_NONE);
2384  }
2385  else
2386  {
2387  // export aborted, i.e. "Save without password" warning
2389  }
2390  }
2391  else if (aFltName == pFilterAscii)
2392  {
2393  SvStream* pStream = rMed.GetOutStream();
2394  if (pStream)
2395  {
2396  OUString sItStr;
2397  SfxItemSet* pSet = rMed.GetItemSet();
2398  const SfxPoolItem* pItem;
2399  if ( pSet && SfxItemState::SET ==
2400  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
2401  {
2402  sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
2403  }
2404 
2405  if ( sItStr.isEmpty() )
2406  {
2407  // default for ascii export (from API without options):
2408  // ISO8859-1/MS_1252 encoding, comma, double quotes
2409 
2410  ScImportOptions aDefOptions( ',', '"', RTL_TEXTENCODING_MS_1252 );
2411  sItStr = aDefOptions.BuildString();
2412  }
2413 
2415  ScImportOptions aOptions( sItStr );
2416  AsciiSave( *pStream, aOptions );
2417  bRet = true;
2418 
2419  if (m_aDocument.GetTableCount() > 1)
2420  if (!rMed.GetError())
2422  }
2423  }
2424  else if (aFltName == pFilterDBase)
2425  {
2426  OUString sCharSet;
2427  SfxItemSet* pSet = rMed.GetItemSet();
2428  const SfxPoolItem* pItem;
2429  if ( pSet && SfxItemState::SET ==
2430  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
2431  {
2432  sCharSet = static_cast<const SfxStringItem*>(pItem)->GetValue();
2433  }
2434 
2435  if (sCharSet.isEmpty())
2436  {
2437  // default for dBase export (from API without options):
2438  // IBM_850 encoding
2439 
2440  sCharSet = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 );
2441  }
2442 
2444  // Hack so that Sba can overwrite the opened TempFile.
2445  rMed.CloseOutStream();
2446  bool bHasMemo = false;
2447 
2448  ErrCode eError = DBaseExport(
2449  rMed.GetPhysicalName(), ScGlobal::GetCharsetValue(sCharSet), bHasMemo);
2450 
2451  INetURLObject aTmpFile( rMed.GetPhysicalName(), INetProtocol::File );
2452  if ( bHasMemo )
2453  aTmpFile.setExtension("dbt");
2454  if ( eError != ERRCODE_NONE && !eError.IsWarning() )
2455  {
2456  if (!GetError())
2457  SetError(eError);
2458  if ( bHasMemo && IsDocument( aTmpFile ) )
2459  KillFile( aTmpFile );
2460  }
2461  else
2462  {
2463  bRet = true;
2464  if ( bHasMemo )
2465  {
2466  const SfxStringItem* pNameItem = rMed.GetItemSet()->GetItem<SfxStringItem>( SID_FILE_NAME );
2467  INetURLObject aDbtFile( pNameItem->GetValue(), INetProtocol::File );
2468  aDbtFile.setExtension("dbt");
2469 
2470  // tdf#40713: don't lose dbt file
2471  // if aDbtFile corresponds exactly to aTmpFile, we just have to return
2472  if (aDbtFile.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ) ==
2473  aTmpFile.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ))
2474  {
2475  if (eError != ERRCODE_NONE && !GetError())
2476  SetError(eError);
2477  return bRet;
2478  }
2479 
2480  if ( IsDocument( aDbtFile ) && !KillFile( aDbtFile ) )
2481  bRet = false;
2482  if ( bRet && !MoveFile( aTmpFile, aDbtFile ) )
2483  bRet = false;
2484  if ( !bRet )
2485  {
2486  KillFile( aTmpFile );
2487  if (eError == ERRCODE_NONE || eError.IsWarning())
2488  eError = SCERR_EXPORT_DATA;
2489  }
2490  }
2491  if (eError != ERRCODE_NONE && !GetError())
2492  SetError(eError);
2493  }
2494  }
2495  else if (aFltName == pFilterDif)
2496  {
2497  SvStream* pStream = rMed.GetOutStream();
2498  if (pStream)
2499  {
2500  OUString sItStr;
2501  SfxItemSet* pSet = rMed.GetItemSet();
2502  const SfxPoolItem* pItem;
2503  if ( pSet && SfxItemState::SET ==
2504  pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
2505  {
2506  sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
2507  }
2508 
2509  if (sItStr.isEmpty())
2510  {
2511  // default for DIF export (from API without options):
2512  // ISO8859-1/MS_1252 encoding
2513 
2514  sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 );
2515  }
2516 
2518  ScFormatFilter::Get().ScExportDif( *pStream, &m_aDocument, ScAddress(0,0,0),
2519  ScGlobal::GetCharsetValue(sItStr) );
2520  bRet = true;
2521 
2522  if (m_aDocument.GetTableCount() > 1)
2523  if (!rMed.GetError())
2525  }
2526  }
2527  else if (aFltName == pFilterSylk)
2528  {
2529  SvStream* pStream = rMed.GetOutStream();
2530  if ( pStream )
2531  {
2533 
2534  SCCOL nEndCol;
2535  SCROW nEndRow;
2536  m_aDocument.GetCellArea( 0, nEndCol, nEndRow );
2537  ScRange aRange( 0,0,0, nEndCol,nEndRow,0 );
2538 
2539  ScImportExport aImExport( m_aDocument, aRange );
2540  aImExport.SetFormulas( true );
2541  bRet = aImExport.ExportStream( *pStream, rMed.GetBaseURL( true ), SotClipboardFormatId::SYLK );
2542  }
2543  }
2544  else if (aFltName == pFilterHtml)
2545  {
2546  SvStream* pStream = rMed.GetOutStream();
2547  if ( pStream )
2548  {
2549  SfxItemSet* pSet = rMed.GetItemSet();
2550  const SfxPoolItem* pItem;
2551  OUString sFilterOptions;
2552 
2553  if (pSet->GetItemState(SID_FILE_FILTEROPTIONS, true, &pItem) == SfxItemState::SET)
2554  sFilterOptions = static_cast<const SfxStringItem*>(pItem)->GetValue();
2555 
2557  ScImportExport aImExport(m_aDocument);
2558  aImExport.SetStreamPath(rMed.GetName());
2559  aImExport.SetFilterOptions(sFilterOptions);
2560  bRet = aImExport.ExportStream(*pStream, rMed.GetBaseURL(true), SotClipboardFormatId::HTML);
2561  if (bRet && !aImExport.GetNonConvertibleChars().isEmpty())
2562  {
2565  aImExport.GetNonConvertibleChars(),
2566  DialogMask::ButtonsOk | DialogMask::MessageInfo));
2567  }
2568  }
2569  }
2570  else
2571  {
2572  if (GetError())
2574  }
2575  return bRet;
2576 }
2577 
2578 bool ScDocShell::DoSaveCompleted( SfxMedium * pNewStor, bool bRegisterRecent )
2579 {
2580  bool bRet = SfxObjectShell::DoSaveCompleted( pNewStor, bRegisterRecent );
2581 
2582  // SfxHintId::ScDocSaved for change ReadOnly -> Read/Write
2583  Broadcast( SfxHint( SfxHintId::ScDocSaved ) );
2584  return bRet;
2585 }
2586 
2587 bool ScDocShell::QuerySlotExecutable( sal_uInt16 nSlotId )
2588 {
2589  // #i112634# ask VBA event handlers whether to save or print the document
2590 
2591  using namespace ::com::sun::star::script::vba;
2592 
2593  sal_Int32 nVbaEventId = VBAEventId::NO_EVENT;
2594  uno::Sequence< uno::Any > aArgs;
2595  switch( nSlotId )
2596  {
2597  case SID_SAVEDOC:
2598  case SID_SAVEASDOC:
2599  nVbaEventId = VBAEventId::WORKBOOK_BEFORESAVE;
2600  aArgs.realloc( 1 );
2601  aArgs[ 0 ] <<= (nSlotId == SID_SAVEASDOC);
2602  break;
2603  case SID_PRINTDOC:
2604  case SID_PRINTDOCDIRECT:
2605  nVbaEventId = VBAEventId::WORKBOOK_BEFOREPRINT;
2606  break;
2607  }
2608 
2609  bool bSlotExecutable = true;
2610  if( nVbaEventId != VBAEventId::NO_EVENT ) try
2611  {
2612  uno::Reference< XVBAEventProcessor > xEventProcessor( m_aDocument.GetVbaEventProcessor(), uno::UNO_SET_THROW );
2613  xEventProcessor->processVbaEvent( nVbaEventId, aArgs );
2614  }
2615  catch( util::VetoException& )
2616  {
2617  bSlotExecutable = false;
2618  }
2619  catch( uno::Exception& )
2620  {
2621  }
2622  return bSlotExecutable;
2623 }
2624 
2626 {
2627  if(SC_MOD()->GetCurRefDlgId()>0)
2628  {
2629  SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
2630  if( pFrame )
2631  {
2632  SfxViewShell* p = pFrame->GetViewShell();
2633  ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( p );
2634  if(pViewSh!=nullptr)
2635  {
2636  vcl::Window *pWin=pViewSh->GetWindow();
2637  if(pWin!=nullptr) pWin->GrabFocus();
2638  }
2639  }
2640 
2641  return false;
2642  }
2644  {
2645  ErrorMessage(STR_CLOSE_ERROR_LINK);
2646  return false;
2647  }
2648 
2649  DoEnterHandler();
2650 
2651  // start 'Workbook_BeforeClose' VBA event handler for possible veto
2652  if( !IsInPrepareClose() )
2653  {
2654  try
2655  {
2656  uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( m_aDocument.GetVbaEventProcessor(), uno::UNO_SET_THROW );
2657  uno::Sequence< uno::Any > aArgs;
2658  xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_BEFORECLOSE, aArgs );
2659  }
2660  catch( util::VetoException& )
2661  {
2662  // if event processor throws VetoException, macro has vetoed close
2663  return false;
2664  }
2665  catch( uno::Exception& )
2666  {
2667  }
2668  }
2669  // end handler code
2670 
2671  bool bRet = SfxObjectShell::PrepareClose( bUI );
2672  if (bRet) // true == close
2673  m_aDocument.EnableIdle(false); // Do not mess around with it anymore!
2674 
2675  return bRet;
2676 }
2677 
2679 {
2680  return pFilterSc50;
2681 }
2682 
2684 {
2685  return pFilterHtml;
2686 }
2687 
2689 {
2690  return pFilterHtmlWebQ;
2691 }
2692 
2694 {
2695  return pFilterAscii;
2696 }
2697 
2699 {
2700  return pFilterLotus;
2701 }
2702 
2704 {
2705  return pFilterDBase;
2706 }
2707 
2709 {
2710  return pFilterDif;
2711 }
2712 
2713 bool ScDocShell::HasAutomaticTableName( std::u16string_view rFilter )
2714 {
2715  // sal_True for those filters that keep the default table name
2716  // (which is language specific)
2717 
2718  return rFilter == pFilterAscii
2719  || rFilter == pFilterLotus
2720  || rFilter == pFilterExcel4
2721  || rFilter == pFilterEx4Temp
2722  || rFilter == pFilterDBase
2723  || rFilter == pFilterDif
2724  || rFilter == pFilterSylk
2725  || rFilter == pFilterHtml
2726  || rFilter == pFilterRtf;
2727 }
2728 
2729 std::unique_ptr<ScDocFunc> ScDocShell::CreateDocFunc()
2730 {
2731  return std::make_unique<ScDocFuncDirect>( *this );
2732 }
2733 
2734 ScDocShell::ScDocShell( const SfxModelFlags i_nSfxCreationFlags ) :
2735  SfxObjectShell( i_nSfxCreationFlags ),
2736  m_aDocument ( SCDOCMODE_DOCUMENT, this ),
2737  m_aDdeTextFmt(OUString("TEXT")),
2738  m_nPrtToScreenFactor( 1.0 ),
2739  m_pImpl ( new DocShell_Impl ),
2740  m_bHeaderOn ( true ),
2741  m_bFooterOn ( true ),
2742  m_bIsEmpty ( true ),
2743  m_bIsInUndo ( false ),
2744  m_bDocumentModifiedPending( false ),
2745  m_bUpdateEnabled ( true ),
2746  m_bUcalcTest ( false ),
2748  m_nDocumentLock ( 0 ),
2749  m_nCanUpdate (css::document::UpdateDocMode::ACCORDING_TO_CONFIG)
2750 {
2751  SetPool( &SC_MOD()->GetPool() );
2752 
2753  m_bIsInplace = (GetCreateMode() == SfxObjectCreateMode::EMBEDDED);
2754  // Will be reset if not in place
2755 
2757 
2758  // SetBaseModel needs exception handling
2759  ScModelObj::CreateAndSet( this );
2760 
2761  StartListening(*this);
2763  if (pStlPool)
2764  StartListening(*pStlPool);
2765 
2767  LINK( this, ScDocShell, RefreshDBDataHdl ) );
2768 
2769  // InitItems and CalcOutputFactor are called now in Load/ConvertFrom/InitNew
2770 }
2771 
2773 {
2774  ResetDrawObjectShell(); // If the Drawing Layer still tries to access it, access it
2775 
2777  if (pStlPool)
2778  EndListening(*pStlPool);
2779  EndListening(*this);
2780 
2781  m_pAutoStyleList.reset();
2782 
2783  SfxApplication *pSfxApp = SfxGetpApp();
2784  if ( pSfxApp->GetDdeService() ) // Delete DDE for Document
2785  pSfxApp->RemoveDdeTopic( this );
2786 
2787  m_pDocFunc.reset();
2788  delete m_aDocument.mpUndoManager;
2789  m_aDocument.mpUndoManager = nullptr;
2790  m_pImpl.reset();
2791 
2792  m_pPaintLockData.reset();
2793 
2794  m_pSolverSaveData.reset();
2795  m_pSheetSaveData.reset();
2796  m_pFormatSaveData.reset();
2797  m_pOldAutoDBRange.reset();
2798 
2799  if (m_pModificator)
2800  {
2801  OSL_FAIL("The Modificator should not exist");
2802  m_pModificator.reset();
2803  }
2804 }
2805 
2807 {
2808  return m_aDocument.GetUndoManager();
2809 }
2810 
2811 void ScDocShell::SetModified( bool bModified )
2812 {
2814  {
2815  SfxObjectShell::SetModified( bModified );
2816  Broadcast( SfxHint( SfxHintId::DocChanged ) );
2817  }
2818 }
2819 
2821 {
2822  // BroadcastUno must also happen right away with pPaintLockData
2823  // FIXME: Also for SetDrawModified, if Drawing is connected
2824  // FIXME: Then own Hint?
2825 
2826  if ( m_pPaintLockData )
2827  {
2828  // #i115009# broadcast BCA_BRDCST_ALWAYS, so a component can read recalculated results
2829  // of RecalcModeAlways formulas (like OFFSET) after modifying cells
2830  m_aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
2831  m_aDocument.InvalidateTableArea(); // #i105279# needed here
2832  m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
2833 
2834  m_pPaintLockData->SetModified(); // Later on ...
2835  return;
2836  }
2837 
2838  SetDrawModified();
2839 
2842  else
2843  {
2844  SetDocumentModifiedPending( false );
2848  m_aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
2850  m_aDocument.CalcFormulaTree( true );
2852  PostDataChanged();
2853 
2854  // Detective AutoUpdate:
2855  // Update if formulas were modified (DetectiveDirty) or the list contains
2856  // "Trace Error" entries (Trace Error can look completely different
2857  // after changes to non-formula cells).
2858 
2860  if ( pList && ( m_aDocument.IsDetectiveDirty() || pList->HasAddError() ) &&
2861  pList->Count() && !IsInUndo() && SC_MOD()->GetAppOptions().GetDetectiveAuto() )
2862  {
2863  GetDocFunc().DetectiveRefresh(true); // sal_True = caused by automatic update
2864  }
2865  m_aDocument.SetDetectiveDirty(false); // always reset, also if not refreshed
2866  }
2867 
2869  {
2871  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged));
2872  }
2873 
2874  // notify UNO objects after BCA_BRDCST_ALWAYS etc.
2875  m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
2876 }
2877 
2885 {
2886  bool bUpdate = !IsModified();
2887 
2888  SetModified();
2889 
2890  SfxBindings* pBindings = GetViewBindings();
2891  if (bUpdate && pBindings)
2892  {
2893  pBindings->Invalidate( SID_SAVEDOC );
2894  pBindings->Invalidate( SID_DOC_MODIFIED );
2895  }
2896 
2897  if (pBindings)
2898  {
2899  // #i105960# Undo etc used to be volatile.
2900  // They always have to be invalidated, including drawing layer or row height changes
2901  // (but not while pPaintLockData is set).
2902  pBindings->Invalidate( SID_UNDO );
2903  pBindings->Invalidate( SID_REDO );
2904  pBindings->Invalidate( SID_REPEAT );
2905  }
2906 
2908  {
2910  SfxGetpApp()->Broadcast(SfxHint( SfxHintId::ScDrawChanged )); // Navigator
2911  }
2912  SC_MOD()->AnythingChanged();
2913 }
2914 
2915 void ScDocShell::SetInUndo(bool bSet)
2916 {
2917  m_bIsInUndo = bSet;
2918 }
2919 
2921 {
2922  SfxPrinter* pPrinter = GetPrinter();
2923 
2924  m_aDocument.GetDocStat( rDocStat );
2925  rDocStat.nPageCount = 0;
2926 
2927  if ( pPrinter )
2928  for ( SCTAB i=0; i<rDocStat.nTableCount; i++ )
2929  rDocStat.nPageCount = sal::static_int_cast<sal_uInt16>( rDocStat.nPageCount +
2930  static_cast<sal_uInt16>(ScPrintFunc( this, pPrinter, i ).GetTotalPages()) );
2931 }
2932 
2933 std::shared_ptr<SfxDocumentInfoDialog> ScDocShell::CreateDocumentInfoDialog(weld::Window* pParent, const SfxItemSet &rSet)
2934 {
2935  std::shared_ptr<SfxDocumentInfoDialog> xDlg = std::make_shared<SfxDocumentInfoDialog>(pParent, rSet);
2936  ScDocShell* pDocSh = dynamic_cast< ScDocShell *>( SfxObjectShell::Current() );
2937 
2938  // Only for statistics, if this Doc is shown; not from the Doc Manager
2939  if( pDocSh == this )
2940  {
2942  ::CreateTabPage ScDocStatPageCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_STAT);
2943  OSL_ENSURE(ScDocStatPageCreate, "Tabpage create fail!");
2944  xDlg->AddFontTabPage();
2945  xDlg->AddTabPage("calcstats", ScResId(STR_DOC_STAT), ScDocStatPageCreate);
2946  }
2947  return xDlg;
2948 }
2949 
2951 {
2953  if ( pViewSh )
2954  return pViewSh->GetDialogParent();
2956  return pRet ? pRet->GetFrameWeld() : nullptr;
2957 }
2958 
2959 void ScDocShell::SetSolverSaveData( std::unique_ptr<ScOptSolverSave> pData )
2960 {
2961  m_pSolverSaveData = std::move(pData);
2962 }
2963 
2965 {
2966  if (!m_pSheetSaveData)
2967  m_pSheetSaveData.reset( new ScSheetSaveData );
2968 
2969  return m_pSheetSaveData.get();
2970 }
2971 
2973 {
2974  if (!m_pFormatSaveData)
2975  m_pFormatSaveData.reset( new ScFormatSaveData );
2976 
2977  return m_pFormatSaveData.get();
2978 }
2979 
2980 namespace {
2981 
2982 void removeKeysIfExists(const Reference<ui::XAcceleratorConfiguration>& xScAccel, const vector<const awt::KeyEvent*>& rKeys)
2983 {
2984  for (const awt::KeyEvent* p : rKeys)
2985  {
2986  if (!p)
2987  continue;
2988 
2989  try
2990  {
2991  xScAccel->removeKeyEvent(*p);
2992  }
2993  catch (const container::NoSuchElementException&) {}
2994  }
2995 }
2996 
2997 }
2998 
3000 {
3001  using namespace ::com::sun::star::ui;
3002 
3003  Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
3004  if (!xContext.is())
3005  return;
3006 
3007  Reference<XModuleUIConfigurationManagerSupplier> xModuleCfgSupplier(
3008  theModuleUIConfigurationManagerSupplier::get(xContext) );
3009 
3010  // Grab the Calc configuration.
3011  Reference<XUIConfigurationManager> xConfigMgr =
3012  xModuleCfgSupplier->getUIConfigurationManager(
3013  "com.sun.star.sheet.SpreadsheetDocument");
3014 
3015  if (!xConfigMgr.is())
3016  return;
3017 
3018  // shortcut manager
3019  Reference<XAcceleratorConfiguration> xScAccel = xConfigMgr->getShortCutManager();
3020 
3021  if (!xScAccel.is())
3022  return;
3023 
3024  vector<const awt::KeyEvent*> aKeys;
3025  aKeys.reserve(9);
3026 
3027  // Backspace key
3028  awt::KeyEvent aBackspace;
3029  aBackspace.KeyCode = awt::Key::BACKSPACE;
3030  aBackspace.Modifiers = 0;
3031  aKeys.push_back(&aBackspace);
3032 
3033  // Delete key
3034  awt::KeyEvent aDelete;
3035  aDelete.KeyCode = awt::Key::DELETE;
3036  aDelete.Modifiers = 0;
3037  aKeys.push_back(&aDelete);
3038 
3039  // Ctrl-D
3040  awt::KeyEvent aCtrlD;
3041  aCtrlD.KeyCode = awt::Key::D;
3042  aCtrlD.Modifiers = awt::KeyModifier::MOD1;
3043  aKeys.push_back(&aCtrlD);
3044 
3045  // Alt-Down
3046  awt::KeyEvent aAltDown;
3047  aAltDown.KeyCode = awt::Key::DOWN;
3048  aAltDown.Modifiers = awt::KeyModifier::MOD2;
3049  aKeys.push_back(&aAltDown);
3050 
3051  // Ctrl-Space
3052  awt::KeyEvent aCtrlSpace;
3053  aCtrlSpace.KeyCode = awt::Key::SPACE;
3054  aCtrlSpace.Modifiers = awt::KeyModifier::MOD1;
3055  aKeys.push_back(&aCtrlSpace);
3056 
3057  // Ctrl-Shift-Space
3058  awt::KeyEvent aCtrlShiftSpace;
3059  aCtrlShiftSpace.KeyCode = awt::Key::SPACE;
3060  aCtrlShiftSpace.Modifiers = awt::KeyModifier::MOD1 | awt::KeyModifier::SHIFT;
3061  aKeys.push_back(&aCtrlShiftSpace);
3062 
3063  // F4
3064  awt::KeyEvent aF4;
3065  aF4.KeyCode = awt::Key::F4;
3066  aF4.Modifiers = 0;
3067  aKeys.push_back(&aF4);
3068 
3069  // CTRL+SHIFT+F4
3070  awt::KeyEvent aCtrlShiftF4;
3071  aCtrlShiftF4.KeyCode = awt::Key::F4;
3072  aCtrlShiftF4.Modifiers = awt::KeyModifier::MOD1 | awt::KeyModifier::SHIFT;
3073  aKeys.push_back(&aCtrlShiftF4);
3074 
3075  // SHIFT+F4
3076  awt::KeyEvent aShiftF4;
3077  aShiftF4.KeyCode = awt::Key::F4;
3078  aShiftF4.Modifiers = awt::KeyModifier::SHIFT;
3079  aKeys.push_back(&aShiftF4);
3080 
3081  // Remove all involved keys first, because swapping commands don't work
3082  // well without doing this.
3083  removeKeysIfExists(xScAccel, aKeys);
3084  xScAccel->store();
3085 
3086  switch (eType)
3087  {
3089  xScAccel->setKeyEvent(aDelete, ".uno:ClearContents");
3090  xScAccel->setKeyEvent(aBackspace, ".uno:Delete");
3091  xScAccel->setKeyEvent(aCtrlD, ".uno:FillDown");
3092  xScAccel->setKeyEvent(aAltDown, ".uno:DataSelect");
3093  xScAccel->setKeyEvent(aCtrlSpace, ".uno:SelectColumn");
3094  xScAccel->setKeyEvent(aCtrlShiftSpace, ".uno:SelectAll");
3095  xScAccel->setKeyEvent(aF4, ".uno:ToggleRelative");
3096  xScAccel->setKeyEvent(aCtrlShiftF4, ".uno:ViewDataSourceBrowser");
3097  break;
3099  xScAccel->setKeyEvent(aDelete, ".uno:Delete");
3100  xScAccel->setKeyEvent(aBackspace, ".uno:ClearContents");
3101  xScAccel->setKeyEvent(aCtrlD, ".uno:DataSelect");
3102  xScAccel->setKeyEvent(aCtrlShiftSpace, ".uno:SelectColumn");
3103  xScAccel->setKeyEvent(aF4, ".uno:ViewDataSourceBrowser");
3104  xScAccel->setKeyEvent(aShiftF4, ".uno:ToggleRelative");
3105  break;
3106  default:
3107  ;
3108  }
3109 
3110  xScAccel->store();
3111 }
3112 
3114 {
3115  if (!m_pSheetSaveData)
3116  return;
3117 
3118  m_pSheetSaveData->UseSaveEntries(); // use positions from saved file for next saving
3119 
3120  bool bHasEntries = false;
3121  SCTAB nTabCount = m_aDocument.GetTableCount();
3122  SCTAB nTab;
3123  for (nTab = 0; nTab < nTabCount; ++nTab)
3124  if (m_pSheetSaveData->HasStreamPos(nTab))
3125  bHasEntries = true;
3126 
3127  if (!bHasEntries)
3128  {
3129  // if no positions were set (for example, export to other format),
3130  // reset all "valid" flags
3131  for (nTab = 0; nTab < nTabCount; ++nTab)
3132  m_aDocument.SetStreamValid(nTab, false);
3133  }
3134 }
3135 
3136 // --- ScDocShellModificator ------------------------------------------
3137 
3139  :
3140  rDocShell( rDS ),
3141  mpProtector(new ScRefreshTimerProtector(rDS.GetDocument().GetRefreshTimerControlAddress()))
3142 {
3143  ScDocument& rDoc = rDocShell.GetDocument();
3145  bIdleEnabled = rDoc.IsIdleEnabled();
3146  rDoc.SetAutoCalcShellDisabled( true );
3147  rDoc.EnableIdle(false);
3148 }
3149 
3151 {
3152  ScDocument& rDoc = rDocShell.GetDocument();
3155  rDocShell.SetDocumentModified(); // last one shuts off the lights
3156  rDoc.EnableIdle(bIdleEnabled);
3157 }
3158 
3160 {
3161  ScDocument& rDoc = rDocShell.GetDocument();
3162  rDoc.PrepareFormulaCalc();
3163  if ( !rDoc.IsImportingXML() )
3164  {
3165  // temporarily restore AutoCalcShellDisabled
3166  bool bDisabled = rDoc.IsAutoCalcShellDisabled();
3169  rDoc.SetAutoCalcShellDisabled( bDisabled );
3170  }
3171  else
3172  {
3173  // uno broadcast is necessary for api to work
3174  // -> must also be done during xml import
3175  rDoc.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
3176  }
3177 }
3178 
3180 {
3181  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
3182  return pChangeTrack != nullptr;
3183 }
3184 
3186 {
3187  bool bRes = false;
3188  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
3189  if (pChangeTrack)
3190  bRes = pChangeTrack->IsProtected();
3191  return bRes;
3192 }
3193 
3194 void ScDocShell::SetChangeRecording( bool bActivate, bool /*bLockAllViews*/ )
3195 {
3196  bool bOldChangeRecording = IsChangeRecording();
3197 
3198  if (bActivate)
3199  {
3201  ScChangeViewSettings aChangeViewSet;
3202  aChangeViewSet.SetShowChanges(true);
3203  m_aDocument.SetChangeViewSettings(aChangeViewSet);
3204  }
3205  else
3206  {
3208  PostPaintGridAll();
3209  }
3210 
3211  if (bOldChangeRecording != IsChangeRecording())
3212  {
3214  // invalidate slots
3215  SfxBindings* pBindings = GetViewBindings();
3216  if (pBindings)
3217  pBindings->InvalidateAll(false);
3218  }
3219 }
3220 
3221 void ScDocShell::SetProtectionPassword( const OUString &rNewPassword )
3222 {
3223  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
3224  if (!pChangeTrack)
3225  return;
3226 
3227  bool bProtected = pChangeTrack->IsProtected();
3228 
3229  if (!rNewPassword.isEmpty())
3230  {
3231  // when password protection is applied change tracking must always be active
3232  SetChangeRecording( true );
3233 
3234  css::uno::Sequence< sal_Int8 > aProtectionHash;
3235  SvPasswordHelper::GetHashPassword( aProtectionHash, rNewPassword );
3236  pChangeTrack->SetProtection( aProtectionHash );
3237  }
3238  else
3239  {
3240  pChangeTrack->SetProtection( css::uno::Sequence< sal_Int8 >() );
3241  }
3242 
3243  if ( bProtected != pChangeTrack->IsProtected() )
3244  {
3247  }
3248 }
3249 
3250 bool ScDocShell::GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash )
3251 {
3252  bool bRes = false;
3253  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
3254  if (pChangeTrack && pChangeTrack->IsProtected())
3255  {
3256  rPasswordHash = pChangeTrack->GetProtection();
3257  bRes = true;
3258  }
3259  return bRes;
3260 }
3261 
3263 {
3264  m_bUcalcTest = true;
3265 }
3266 
3267 void ScDocShell::RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const& xWorkbook)
3268 {
3269  mxAutomationWorkbookObject = xWorkbook;
3270 }
3271 
3272 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportSLK(SvStream &rStream)
3273 {
3274  ScDLL::Init();
3276  ScDocOptions aDocOpt = aDocument.GetDocOptions();
3277  aDocOpt.SetLookUpColRowNames(false);
3278  aDocument.SetDocOptions(aDocOpt);
3279  aDocument.MakeTable(0);
3280  aDocument.EnableExecuteLink(false);
3281  aDocument.SetInsertingFromOtherDoc(true);
3282  aDocument.SetImportingXML(true);
3283 
3284  ScImportExport aImpEx(aDocument);
3285  return aImpEx.ImportStream(rStream, OUString(), SotClipboardFormatId::SYLK);
3286 }
3287 
3288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3047
sal_Unicode nFieldSepCode
Definition: imoptdlg.hxx:43
Data stream data needs to be post-processed because it requires ScDocShell instance which is not avai...
SfxViewFrame * GetViewFrame() const
bool bSaveFormulas
Definition: imoptdlg.hxx:51
bool m_bUcalcTest
Definition: docsh.hxx:95
constexpr double nPPTY
virtual void SetVisArea(const tools::Rectangle &rVisArea)
void EnableIdle(bool bDo)
Definition: document.hxx:2121
SvxCellHorJustify
OUString GetText(LineEnd eEnd=LINEEND_LF) const
bool HasExternalRefManager() const
Definition: document.hxx:1001
URL aURL
virtual HiddenInformation GetHiddenInformationState(HiddenInformation nStates) override
Definition: docsh.cxx:224
static OUString GetOwnFilterName()
Definition: docsh.cxx:2678
std::size_t write_uInt16s_FromOUString(SvStream &rStrm, const OUString &rStr, std::size_t nUnits)
sal_Int32 nIndex
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:813
OUString getString() const
double GetPPTY() const
Definition: sizedev.hxx:42
ScAddress aStart
Definition: address.hxx:499
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
void EndChangeTracking()
Definition: documen2.cxx:269
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1906
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
void SetExtOptions(const ScAsciiOptions &rOpt)
Definition: impex.cxx:204
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: docsh3.cxx:450
const sc::ImportPostProcessData & GetImportPostProcessData() const
Definition: xmlwrap.hxx:91
static void GetInputString(const ScRefCellValue &rCell, sal_uInt32 nFormat, OUString &rString, SvNumberFormatter &rFormatter, const ScDocument &rDoc, bool bFiltering=false)
Definition: cellform.cxx:118
ScRefCellValue * GetNext(SCCOL &rCol, SCROW &rRow)
Definition: dociter.cxx:2134
#define SFX_IMPL_INTERFACE(Class, SuperClass)
virtual bool DoSaveCompleted(SfxMedium *pNewStor=nullptr, bool bRegisterRecent=true)
bool IsInInterpreter() const
Definition: document.hxx:2313
SC_DLLPUBLIC size_t GetCount() const
Definition: dpobject.cxx:3676
Collection of orcus filter wrappers.
ScriptDocument aDocument
SCROW Row() const
Definition: address.hxx:261
#define SCWARN_EXPORT_NONCONVERTIBLE_CHARS
Definition: scerrors.hxx:69
std::unique_ptr< ScDBData > m_pOldAutoDBRange
Definition: docsh.hxx:100
virtual ErrCode ScImportRTF(SvStream &, const OUString &rBaseURL, ScDocument *, ScRange &rRange)=0
void PostPaintGridAll()
Definition: docsh3.cxx:182
#define ERRCODE_IO_ABORT
std::unique_ptr< ScRefreshTimerControl > const & GetRefreshTimerControlAddress() const
Definition: document.hxx:2421
SC_DLLPUBLIC void SetChangeViewSettings(const ScChangeViewSettings &rNew)
Definition: documen2.cxx:1111
virtual bool Load(SfxMedium &rMedium)
bool HasSharedXMLFlagSet() const
void RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const &xWorkbook)
Definition: docsh.cxx:3267
SfxObjectShell * GetObjectShell() const
bool HasAddError() const
Definition: detdata.hxx:81
ScFormatSaveData * GetFormatSaveData()
Definition: docsh.cxx:2972
std::string GetValue
const css::uno::Reference< css::script::vba::XVBAEventProcessor > & GetVbaEventProcessor() const
Definition: document.hxx:2438
static weld::Window * GetActiveDialogParent()
Definition: docsh.cxx:2950
SAL_DLLPUBLIC_EXPORT bool TestImportSLK(SvStream &rStream)
Definition: docsh.cxx:3272
int SetError()
SfxBindings * GetViewBindings()
Definition: docsh4.cxx:2584
OUString GetStandardText(StandardButtonType eButton)
double m_nPrtToScreenFactor
Definition: docsh.hxx:84
bool Import(ImportFlags nMode, ErrCode &rError)
Definition: xmlwrap.cxx:285
void SetProtection(const css::uno::Sequence< sal_Int8 > &rPass)
Definition: chgtrack.hxx:1128
static vcl::Window * GetDefDialogParent()
RET_RETRY
virtual void SetModified(bool bModified=true)
void GetFormula(OUString &rFormula, const formula::FormulaGrammar::Grammar=formula::FormulaGrammar::GRAM_DEFAULT, const ScInterpreterContext *pContext=nullptr) const
ScDetOpList * GetDetOpList() const
Definition: document.hxx:1767
css::uno::Reference< css::datatransfer::XTransferable2 > const & GetClipData() const
Definition: docsh.hxx:220
virtual ErrCode ScImportExcel(SfxMedium &, ScDocument *, const EXCIMPFORMAT)=0
const OUString & GetName() const
Do things that need to be done before saving to our own format and necessary clean ups in dtor...
Definition: docsh.hxx:123
static OUString GetAsciiFilterName()
Definition: docsh.cxx:2693
sal_Int32 toInt32(OUString const &rStr)
sal_Int64 n
virtual std::shared_ptr< SfxDocumentInfoDialog > CreateDocumentInfoDialog(weld::Window *pParent, const SfxItemSet &rSet) override
Definition: docsh.cxx:2933
ScDocShell & rDocShell
Definition: docsh.hxx:453
void SetStateOnPercent(sal_uLong nVal)
Definition: progress.hxx:96
void setAllCacheTableReferencedStati(bool bReferenced)
ScDocShell(const ScDocShell &rDocShell)=delete
virtual bool importODS(ScDocument &rDoc, SfxMedium &rMedium) const =0
normal calculation of dependencies
sal_uInt16 GetValue() const
aBuf
static SVL_DLLPUBLIC void GetHashPassword(css::uno::Sequence< sal_Int8 > &rPassHash, const char *pPass, sal_uInt32 nLen)
const char pFilterEx5Temp[]
Definition: docsh.cxx:151
void SetDocumentModified()
Definition: docsh.cxx:2820
Stores data imported from the file that need to be processed at the end of the import process...
constexpr OUStringLiteral pFilterDBase
Definition: docsh.cxx:156
#define SCWARN_IMPORT_RANGE_OVERFLOW
Definition: scerrors.hxx:61
void SetSolverSaveData(std::unique_ptr< ScOptSolverSave > pData)
Definition: docsh.cxx:2959
bool m_bUpdateEnabled
Definition: docsh.hxx:94
sal_uInt64 Seek(sal_uInt64 nPos)
bool ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
Definition: tabvwshh.cxx:247
static SC_DLLPUBLIC ScFormatFilterPlugin & Get()
Definition: impex.cxx:2398
SAL_DLLPRIVATE void DoEnterHandler()
Definition: docsh.cxx:205
SC_DLLPUBLIC void GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt32 &rFormat) const
Definition: document.cxx:3633
virtual bool SaveAs(SfxMedium &rMedium)
static OUString GetHtmlFilterName()
Definition: docsh.cxx:2683
ScAddress aEnd
Definition: address.hxx:500
Extended options held by an ScDocument containing additional settings for filters.
Definition: scextopt.hxx:76
virtual std::set< Color > GetDocColors() override
Definition: docsh.cxx:200
static SfxObjectShell * Current()
bool m_bAreasChangedNeedBroadcast
Definition: docsh.hxx:96
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
#define SC_TAB_INSERTED
Definition: uiitems.hxx:75
const char pFilterQPro6[]
Definition: docsh.cxx:147
const char pFilterXML[]
Definition: docsh.cxx:144
static OUString GetCharsetString(rtl_TextEncoding eVal)
Definition: global.cxx:581
void Invalidate(sal_uInt16 nId)
sc::DocumentLinkManager & GetDocLinkManager()
Definition: documen2.cxx:227
SC_DLLPUBLIC SfxUndoManager * GetUndoManager()
Definition: document.cxx:6363
virtual bool importODS_Styles(ScDocument &rDoc, OUString &aFileName) const =0
Used to import just the styles from an xml file.
bool IsInPrepareClose() const
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
static OUString GetWebQueryFilterName()
Definition: docsh.cxx:2688
RET_CANCEL
bool ImportStream(SvStream &, const OUString &rBaseURL, SotClipboardFormatId)
Definition: impex.cxx:382
SfxHintId GetId() const
ErrCode GetError() const
bool bSaveNumberAsSuch
Definition: imoptdlg.hxx:50
~PrepareSaveGuard() COVERITY_NOEXCEPT_FALSE
Definition: docsh.cxx:1717
~ScDocShellModificator() COVERITY_NOEXCEPT_FALSE
Definition: docsh.cxx:3150
virtual bool ConvertTo(SfxMedium &rMedium) override
Definition: docsh.cxx:2309
SfxApplication * SfxGetpApp()
virtual ScOrcusFilters * GetOrcusFilters()=0
virtual bool HasChangeRecordProtection() const override
Definition: docsh.cxx:3185
const char pFilterEx95Temp[]
Definition: docsh.cxx:153
PrepareSaveGuard(ScDocShell &rDocShell)
Definition: docsh.cxx:1693
constexpr OUStringLiteral pFilterHtmlWebQ
Definition: docsh.cxx:160
size_t Count() const
Definition: detdata.hxx:82
void InvalidateTableArea()
Definition: documen4.cxx:577
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2806
RET_NO
OUString CreateNewName() const
Create a new name that's not yet used by any existing data pilot objects.
Definition: dpobject.cxx:3702
virtual bool PrepareClose(bool bUI=true)
void SetCharSet(rtl_TextEncoding eNew)
Definition: asciiopt.hxx:70
weld::Window * GetFrameWeld() const
SC_DLLPUBLIC void SetImportingXML(bool bVal)
Definition: documen9.cxx:592
bool IsStorage()
sal_uInt16 sal_Unicode
constexpr OUStringLiteral pFilterHtml
Definition: docsh.cxx:159
bool ShowChanges() const
Definition: chgviset.hxx:77
void SetRefreshOnEmptyLine(bool bVal)
Definition: datastream.cxx:403
virtual void ScExportDif(SvStream &, ScDocument *, const ScAddress &rOutPos, const rtl_TextEncoding eDest)=0
Reference< XController > xController
RET_YES
const EditTextObject * mpEditText
Definition: cellvalue.hxx:109
static void ResetKeyBindings(ScOptionsUtil::KeyBindingType eType)
Definition: docsh.cxx:2999
void SetText(const OUString &rStr)
bool setExtension(OUString const &rTheExtension, sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void InvalidateStyleSheetUsage()
Definition: document.hxx:2432
virtual ~ScDocShell() override
Definition: docsh.cxx:2772
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:871
virtual bool Save()
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:313
FormulaError GetErrCode()
SfxFrame & GetFrame() const
virtual bool SaveAs(SfxMedium &rMedium) override
Definition: docsh.cxx:1773
std::unique_ptr< ScPaintLockData > m_pPaintLockData
Definition: docsh.hxx:103
virtual ErrCode ScImportLotus123(SfxMedium &, ScDocument &, rtl_TextEncoding eSrc)=0
bool IsOverflowCol() const
Definition: impex.hxx:149
void SetLookUpColRowNames(bool bVal)
Definition: docoptio.hxx:52
const OUString & GetPhysicalName() const
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
Definition: documen3.cxx:623
bool IsAutoCalcShellDisabled() const
Definition: document.hxx:1361
SvStream * GetOutStream()
UpdateLinks
std::unique_ptr< ScDocFunc > m_pDocFunc
Definition: docsh.hxx:86
const SfxPoolItem * ExecuteSynchron(sal_uInt16 nSlot, const SfxPoolItem **pArgs=nullptr)
const char16_t pFilterExcel4[]
Definition: docsh.cxx:148
bool DetectiveRefresh(bool bAutomatic=false)
Definition: docfunc.cxx:463
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:110
void SetRow(SCROW nRowP)
Definition: address.hxx:274
SAL_DLLPRIVATE void UseSheetSaveEntries()
Definition: docsh.cxx:3113
static std::shared_ptr< ConfigurationChanges > create(css::uno::Reference< css::uno::XComponentContext > const &context=comphelper::getProcessComponentContext())
std::unique_ptr< DataStream > mpDataStream
static void lcl_parseHtmlFilterOption(const OUString &rOption, LanguageType &rLang, bool &rDateConvert)
Definition: docsh.cxx:1107
SotClipboardFormatId
virtual bool Load(SfxMedium &rMedium) override
Definition: docsh.cxx:565
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
const OUString & GetName() const
void SetRefreshHandler(const Link< Timer *, void > &rLink)
Definition: dbdata.hxx:335
SfxObjectCreateMode GetCreateMode() const
#define SO3_SC_CLASSID_60
void PrepareFormulaCalc()
Call this before any operations that might trigger one or more formula cells to get calculated...
Definition: document.cxx:2440
void SetClipData(const css::uno::Reference< css::datatransfer::XTransferable2 > &xTransferable)
Definition: docsh.hxx:221
const sal_Unicode cDelim
Definition: unitconv.cxx:29
void SetCol(SCCOL nColP)
Definition: address.hxx:278
virtual bool LoadFrom(SfxMedium &rMedium) override
Definition: docsh.cxx:1082
SfxUndoManager * mpUndoManager
Definition: document.hxx:364
void MarkUsedExternalReferences()
Definition: documen3.cxx:637
virtual bool importExcel2003XML(ScDocument &rDoc, SfxMedium &rMedium) const =0
ScViewData & GetViewData()
Definition: tabview.hxx:333
static ScDocument * GetClipDoc()
Definition: scmod.cxx:617
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2395
#define SCWARN_EXPORT_ASCII
Definition: scerrors.hxx:71
bool m_bIsInUndo
Definition: docsh.hxx:92
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4706
bool IsDocumentModifiedPending() const
Definition: docsh.hxx:376
const css::uno::Sequence< sal_Int8 > & GetProtection() const
Definition: chgtrack.hxx:1130
SfxItemPool & GetPool() const
void SetInsertingFromOtherDoc(bool bVal)
Definition: document.hxx:2136
#define SCWARN_IMPORT_CELL_OVERFLOW
Definition: scerrors.hxx:65
void SetError(ErrCode nError)
bool IsProtected() const
Definition: chgtrack.hxx:1132
OutputDevice * GetDevice() const
Definition: sizedev.hxx:40
void SetIsInUcalc()
Definition: docsh.cxx:3262
SC_DLLPUBLIC bool GetCellArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow) const
Definition: document.cxx:1009
constexpr OUStringLiteral aData
virtual bool DoSaveCompleted(SfxMedium *pNewStor=nullptr, bool bRegisterRecent=true) override
Definition: docsh.cxx:2578
void SetName(const OUString &rNew)
Definition: dpobject.cxx:489
DocumentType eType
ScSheetSaveData * GetSheetSaveData()
Definition: docsh.cxx:2964
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1939
static bool HasAutomaticTableName(std::u16string_view rFilter)
Definition: docsh.cxx:2713
constexpr double nPPTX
bool GetHideCell() const
Definition: attrib.hxx:147
bool IsModified() const
#define SCERR_IMPORT_NI
Definition: scerrors.hxx:35
void InvalidateStreamOnSave()
Definition: document.cxx:494
sal_Unicode nTextSepCode
Definition: imoptdlg.hxx:44
void SetMarkArea(const ScRange &rRange)
Definition: markdata.cxx:97
bool m_bIsEmpty
Definition: docsh.hxx:91
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:440
#define SOFFICE_FILEFORMAT_60
std::unique_ptr< ScAutoStyleList > m_pAutoStyleList
Definition: docsh.hxx:102
bool IsChartListenerCollectionNeedsUpdate() const
Definition: document.hxx:2152
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
#define TOOLS_WARN_EXCEPTION(area, stream)
SC_DLLPUBLIC void CalcFormulaTree(bool bOnlyForced=false, bool bProgressBar=true, bool bSetAllDirty=true)
Calculate formula cells that are on the formula tree either partially, or in full.
Definition: documen7.cxx:326
bool IsImportingXML() const
Definition: document.hxx:2140
void EnableExecuteLink(bool bVal)
Definition: document.hxx:1541
void CloseOutStream()
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define ERRCODE_IO_GENERAL
static SAL_DLLPRIVATE bool MoveFile(const INetURLObject &rSource, const INetURLObject &rDest)
Definition: docsh8.cxx:140
virtual bool importGnumeric(ScDocument &rDoc, SfxMedium &rMedium) const =0
void SetFormulas(bool b)
Definition: impex.hxx:132
int i
static OUString getProductName()
OUStringBuffer & truncateToLength(OUStringBuffer &rBuffer, sal_Int32 nLength)
static SAL_DLLPRIVATE bool KillFile(const INetURLObject &rURL)
Definition: docsh8.cxx:184
#define LANGUAGE_SYSTEM
const svl::SharedString * mpString
Definition: cellvalue.hxx:108
static OUString GetLotusFilterName()
Definition: docsh.cxx:2698
std::unique_ptr< ScDocShellModificator, o3tl::default_delete< ScDocShellModificator > > m_pModificator
Definition: docsh.hxx:108
sal_Int16 SCCOL
Definition: types.hxx:21
SAL_DLLPRIVATE SCTAB GetSaveTab()
Definition: docsh.cxx:212
static SC_DLLPUBLIC void Init()
DLL-init/exit-code must be linked to the DLL only.
Definition: scdll.cxx:99
SAL_DLLPRIVATE void ResetDrawObjectShell()
Definition: docsh2.cxx:162
constexpr OUStringLiteral pFilterLotus
Definition: docsh.cxx:146
static SC_DLLPUBLIC double nScreenPPTY
Vertical pixel per twips factor.
Definition: global.hxx:578
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
sal_uInt16 m_nDocumentLock
Definition: docsh.hxx:97
#define SC_MOD()
Definition: scmod.hxx:249
bool IsTextFormat(sal_uInt32 nFIndex) const
bool GetHideFormula() const
Definition: attrib.hxx:145
bool IsForcedFormulaPending() const
Definition: document.hxx:1364
virtual bool LoadFrom(SfxMedium &rMedium)
const OUString & GetValue() const
void RemoveDdeTopic(SfxObjectShell const *)
::tools::Long nLastColWidthExtra
Definition: global.hxx:586
const OUString & GetName() const
Definition: dpobject.hxx:166
const char pFilterExcel95[]
Definition: docsh.cxx:152
#define SCERR_EXPORT_DATA
Definition: scerrors.hxx:53
void SetPool(SfxItemPool *pNewPool)
std::size_t WriteBytes(const void *pData, std::size_t nSize)
virtual bool PrepareClose(bool bUI=true) override
Definition: docsh.cxx:2625
bool hasExternalData() const
float u
bool IsDetectiveDirty() const
Definition: document.hxx:2123
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
virtual bool Save() override
Definition: docsh.cxx:1730
OUString GetBaseURL(bool bForSaving=false)
#define BCA_BRDCST_ALWAYS
Definition: address.hxx:950
std::unique_ptr< weld::CheckButton > m_xWarningOnBox
constexpr OUStringLiteral pFilterDif
Definition: docsh.cxx:157
void StartWritingUnicodeText()
virtual ErrCode ScExportExcel5(SfxMedium &, ScDocument *, ExportFormatExcel eFormat, rtl_TextEncoding eDest)=0
virtual ErrCode ScImportQuattroPro(SvStream *pStream, ScDocument &rDoc)=0
SfxItemSet * GetItemSet() const
void BroadcastUno(const SfxHint &rHint)
Definition: documen3.cxx:949
SCTAB nTableCount
Definition: document.hxx:277
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
virtual bool LoadExternal(SfxMedium &rMedium) override
Definition: docsh.cxx:1652
sal_Int16 m_nCanUpdate
Definition: docsh.hxx:98
SvStream & endlub(SvStream &rStrm)
SAL_DLLPRIVATE ErrCode DBaseExport(const OUString &rFullFileName, rtl_TextEncoding eCharSet, bool &bHasMemo)
Definition: docsh8.cxx:729
bool GetShowSharedDocumentWarning() const
Definition: appoptio.hxx:76
virtual ErrCode ScImportHTML(SvStream &, const OUString &rBaseURL, ScDocument *, ScRange &rRange, double nOutputFactor, bool bCalcWidthHeight, SvNumberFormatter *pFormatter, bool bConvertDate)=0
virtual HiddenInformation GetHiddenInformationState(HiddenInformation nStates)
bool ExportStream(SvStream &, const OUString &rBaseURL, SotClipboardFormatId)
Definition: impex.cxx:422
const char pFilterEx97Temp[]
Definition: docsh.cxx:155
bool IsValid() const
Definition: address.hxx:546
void Broadcast(const ScHint &rHint)
Broadcast wrapper, calls rHint.GetCell()->Broadcast() and AreaBroadcast() and TrackFormulas() Preferr...
Definition: documen7.cxx:117
void SetShowSharedDocumentWarning(bool bNew)
Definition: appoptio.hxx:75
void GrabFocus()
void SetFieldSeps(const OUString &rStr)
Definition: asciiopt.hxx:73
const std::shared_ptr< const SfxFilter > & GetFilter() const
void PostDataChanged()
Definition: docsh3.cxx:92
bool m_bFooterOn
Definition: docsh.hxx:89
SfxViewShell * GetViewShell() const
#define SCERR_IMPORT_UNKNOWN
Definition: scerrors.hxx:27
sal_uInt16 nPageCount
Definition: document.hxx:280
SAL_DLLPRIVATE std::unique_ptr< ScDocFunc > CreateDocFunc()
Definition: docsh.cxx:2729
virtual bool IsChangeRecording() const override
Definition: docsh.cxx:3179
const svl::SharedString & GetString()
virtual void TerminateEditing() override
Definition: docsh.cxx:1767
FormulaError
ScDBFunc * GetView() const
Definition: viewdata.cxx:853
virtual bool GetProtectionHash(css::uno::Sequence< sal_Int8 > &rPasswordHash) override
Definition: docsh.cxx:3250
ExportFormatExcel
Definition: filter.hxx:42
const char pFilterExcel5[]
Definition: docsh.cxx:150
const char16_t pFilterRtf[]
Definition: docsh.cxx:161
CellType meType
Definition: cellvalue.hxx:105
SvStreamEndian GetEndian() const
void SetShowAccepted(bool bVal)
Definition: chgviset.hxx:113
constexpr OUStringLiteral pFilterSc50
Definition: docsh.cxx:143
std::unique_ptr< ScOptSolverSave > m_pSolverSaveData
Definition: docsh.hxx:104
void SetInUndo(bool bSet)
Definition: docsh.cxx:2915
SvStream * GetInStream()
sal_Int32 SCROW
Definition: types.hxx:17
void StopTemporaryChartLock()
Definition: documen3.cxx:406
const OUString & GetNonConvertibleChars() const
Definition: impex.hxx:153
std::unique_ptr< ScSheetSaveData > m_pSheetSaveData
Definition: docsh.hxx:105
void SetStreamValid(SCTAB nTab, bool bSet, bool bIgnoreLock=false)
Definition: document.cxx:924
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1945
SFX_IMPL_OBJECTFACTORY(DrawDocShell, SvGlobalName(SO3_SIMPRESS_CLASSID),"simpress") void DrawDocShell
static ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1038
sal_uInt16 GetTablesHintId() const
Definition: uiitems.hxx:93
bool IsOverflowRow() const
Definition: impex.hxx:148
exports com.sun.star. document
virtual bool ConvertFrom(SfxMedium &rMedium) override
Definition: docsh.cxx:1137
Any makeAny(Color const &value)
SfxEventHintId GetEventId() const
std::unique_ptr< ScFormatSaveData > m_pFormatSaveData
Definition: docsh.hxx:106
static SC_DLLPUBLIC OUString GetDocTabName(std::u16string_view rFileName, std::u16string_view rTabName)
Definition: global2.cxx:321
static SAL_DLLPRIVATE bool IsDocument(const INetURLObject &rURL)
Definition: docsh8.cxx:203
#define ERRCODE_NONE
void ReadFromString(const OUString &rString)
Definition: asciiopt.cxx:85
void AsciiSave(SvStream &rStream, const ScImportOptions &rOpt)
Definition: docsh.cxx:1929
bool bQuoteAllText
Definition: imoptdlg.hxx:49
bool IsOverflowCell() const
Definition: impex.hxx:150
void SetStreamPath(const OUString &rPath)
Definition: impex.hxx:135
CellType
Definition: global.hxx:280
void ErrorMessage(const char *pGlobStrId)
Definition: docsh5.cxx:70
EXCIMPFORMAT
Definition: filter.hxx:39
#define SCERR_IMPORT_CONNECT
Definition: scerrors.hxx:25
void AfterXMLLoading(bool bRet)
Definition: docsh.cxx:266
#define SCWARN_IMPORT_ROW_OVERFLOW
Definition: scerrors.hxx:62
void SetEndian(SvStreamEndian SvStreamEndian)
css::uno::Reference< css::frame::XController > GetController() const
OUString aName
SCTAB GetFirstSelected() const
Definition: markdata.cxx:200
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
SfxEventHintId
SfxModelFlags
virtual LockFileEntry GetLockData() override
int GetError()
ScExtDocOptions * GetExtDocOptions()
Definition: document.hxx:630
bool m_bHeaderOn
Definition: docsh.hxx:88
void UpdateAcceptChangesDialog()
Definition: docsh4.cxx:1351
#define SC_TEXT_CSV_FILTER_NAME
Definition: global.hxx:60
void SetDetectiveDirty(bool bSet)
Definition: document.hxx:2124
void SetStreamCharSet(rtl_TextEncoding eCharSet)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
#define SVSTREAM_FILEFORMAT_ERROR
SAL_DLLPRIVATE bool SaveXML(SfxMedium *pMedium, const css::uno::Reference< css::embed::XStorage > &)
Definition: docsh.cxx:549
void InvalidateLastTableOpParams()
Definition: document.hxx:2354
rtl_TextEncoding GetCharSet() const
Definition: asciiopt.hxx:55
rtl_TextEncoding GetStreamCharSet() const
const char16_t pFilterSylk[]
Definition: docsh.cxx:158
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
virtual CreateTabPage GetTabPageCreatorFunc(sal_uInt16 nId)=0
bool IsWarning() const
static OUString GetDBaseFilterName()
Definition: docsh.cxx:2703
std::unique_ptr< DocShell_Impl > m_pImpl
Definition: docsh.hxx:85
void * p
Reference< XComponentContext > getProcessComponentContext()
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2146
static SC_DLLPUBLIC double nScreenPPTX
Horizontal pixel per twips factor.
Definition: global.hxx:576
bool needsPassHashRegen(const ScDocument &rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED)
Check for the compatibility of all password hashes.
void SetAutoCalcShellDisabled(bool bNew)
Definition: document.hxx:1360
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
ScRecalcOptions
Definition: calcconfig.hxx:23
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:570
css::uno::Reference< ooo::vba::excel::XWorkbook > mxAutomationWorkbookObject
Definition: docsh.hxx:110
vcl::Window * GetWindow() const
#define SCWARN_IMPORT_COLUMN_OVERFLOW
Definition: scerrors.hxx:63
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6053
static rtl_TextEncoding GetCharsetValue(const OUString &rCharSet)
Definition: global.cxx:553
virtual void SetProtectionPassword(const OUString &rPassword) override
Definition: docsh.cxx:3221
ScDocShellModificator(const ScDocShellModificator &)=delete
void ClosingClipboardSource()
To be called at the clipboard document when closing a document that is the current clipboard source t...
Definition: documen2.cxx:318
SAL_DLLPRIVATE bool LoadXML(SfxMedium *pMedium, const css::uno::Reference< css::embed::XStorage > &)
Definition: docsh.cxx:464
static const sal_Unicode * UnicodeStrChr(const sal_Unicode *pStr, sal_Unicode c)
strchr() functionality on unicode, as long as we need it for FormulaToken etc.
Definition: global.cxx:640
bool IsEnableSetModified() const
void SetDocumentModified()
Definition: docsh.cxx:3159
bool IsInUndo() const
Definition: docsh.hxx:349
virtual ErrCode ScImportDif(SvStream &, ScDocument *, const ScAddress &rInsPos, const rtl_TextEncoding eSrc)=0
ScDocument m_aDocument
Definition: docsh.hxx:80
#define SC_COMPILER_FILE_TAB_SEP
Definition: compiler.hxx:82
ErrCode GetError() const
bool IsInLinkUpdate() const
Definition: documen8.cxx:784
static void CreateAndSet(ScDocShell *pDocSh)
create ScModelObj and set at pDocSh (SetBaseModel)
Definition: docuno.cxx:371
#define ERRCODE_ABORT
virtual bool QuerySlotExecutable(sal_uInt16 nSlotId) override
Definition: docsh.cxx:2587
OUString BuildString() const
Definition: imoptdlg.cxx:83
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
virtual void SetModified(bool=true) override
Definition: docsh.cxx:2811
void GetDocStat(ScDocStat &rDocStat)
Definition: docsh.cxx:2920
void InvalidateAll(bool bWithMsg)
virtual bool importXLSX(ScDocument &rDoc, SfxMedium &rMedium) const =0
bool m_bDocumentModifiedPending
Definition: docsh.hxx:93
#define SAL_WARN(area, stream)
Reference< XSingleServiceFactory > xFactory
OUString m_aDdeTextFmt
Definition: docsh.hxx:82
rtl_TextEncoding eCharSet
Definition: imoptdlg.hxx:46
Reference< XModel > xModel
SvStreamEndian
void(* f)(TrueTypeTable *)
void SetDrawModified()
SetDrawModified - without Formula update.
Definition: docsh.cxx:2884
void setDataStream(DataStream *p)
static void GetString(const ScRefCellValue &rCell, sal_uInt32 nFormat, OUString &rString, const Color **ppColor, SvNumberFormatter &rFormatter, const ScDocument &rDoc, bool bNullVals=true, bool bFormula=false, bool bUseStarFormat=false)
Definition: cellform.cxx:31
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:218
constexpr OUStringLiteral pFilterAscii
Definition: docsh.cxx:145
SC_DLLPUBLIC void MakeTable(SCTAB nTab, bool _bNeedsNameCheck=true)
Definition: document.cxx:167
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
Definition: docsh4.cxx:2565
bool m_bIsInplace
Definition: docsh.hxx:90
bool WriteUnicodeOrByteText(const OUString &rStr, rtl_TextEncoding eDestCharSet)
void StartChangeTracking()
Definition: documen2.cxx:263
void SetDocumentModifiedPending(bool bVal)
Definition: docsh.hxx:374
SC_DLLPUBLIC void SetExtDocOptions(std::unique_ptr< ScExtDocOptions > pNewOptions)
Definition: documen3.cxx:2021
void SetFilterOptions(const OUString &rFilterOptions)
Definition: impex.cxx:217
void UpdateLayerLocks()
Definition: tabview5.cxx:347
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4112
virtual void SetChangeRecording(bool bActivate, bool bLockAllViews=false) override
Definition: docsh.cxx:3194
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
bool Export(bool bStylesOnly)
Definition: xmlwrap.cxx:718
HiddenInformation
const DdeService * GetDdeService() const
bool IsIdleEnabled() const
Definition: document.hxx:2120
bool WriteUniOrByteChar(sal_Unicode ch, rtl_TextEncoding eDestCharSet)
static bool WarningOnPassword(SfxMedium &rMedium)
Opens a query warning dialog.
const char16_t pFilterEx4Temp[]
Definition: docsh.cxx:149
sal_Int32 nState
void RefreshDirtyTableColumnNames()
Definition: documen3.cxx:354
double GetPPTX() const
Definition: sizedev.hxx:41
void GetDocStat(ScDocStat &rDocStat)
Definition: document.cxx:6229
virtual bool importCSV(ScDocument &rDoc, SfxMedium &rMedium) const =0
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: docsh.cxx:651
void SetTextSep(sal_Unicode c)
Definition: asciiopt.hxx:79
weld::Window * GetDialogParent()
parent window for dialogs Problem: OLE Server!
Definition: tabvwshd.cxx:31
void SetError(ErrCode rErr)
static OUString GetErrorString(FormulaError nErrNumber)
Definition: global.cxx:301
SC_DLLPUBLIC ScFieldEditEngine & GetEditEngine()
Definition: documen2.cxx:456
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:451
const char pFilterExcel97[]
Definition: docsh.cxx:154
#define SOFFICE_FILEFORMAT_8
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:22
void SetODFRecalcOptions(ScRecalcOptions eOpt)
Definition: formulaopt.hxx:64
bool bAutoCalcShellDisabled
Definition: docsh.hxx:455
SC_DLLPUBLIC bool GetAutoCalc() const
Definition: document.hxx:1358
static OUString GetDifFilterName()
Definition: docsh.cxx:2708
SCTAB GetTab1() const
Definition: uiitems.hxx:94
void SetShowChanges(bool bFlag)
Definition: chgviset.hxx:78
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill= '\0')
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
SfxMedium * GetMedium() const
void BeforeXMLLoading()
Definition: docsh.cxx:251