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