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