LibreOffice Module sc (master)  1
docsh4.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 <config_features.h>
21 
22 #include <boost/property_tree/json_parser.hpp>
23 
24 #include <com/sun/star/frame/Desktop.hpp>
25 
26 using namespace ::com::sun::star;
27 
28 #include <scitems.hxx>
29 #include <editeng/flstitem.hxx>
30 #include <sfx2/fcontnr.hxx>
31 #include <sfx2/infobar.hxx>
32 #include <sfx2/objface.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <sfx2/docfilt.hxx>
35 #include <svtools/ehdl.hxx>
36 #include <svtools/langtab.hxx>
37 #include <basic/sbxcore.hxx>
38 #include <basic/sberrors.hxx>
39 #include <svtools/sfxecode.hxx>
40 #include <svx/ofaitem.hxx>
41 #include <svl/stritem.hxx>
42 #include <svl/whiter.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/weld.hxx>
46 #include <svx/drawitem.hxx>
47 #include <svx/fmshell.hxx>
48 #include <sfx2/passwd.hxx>
49 #include <sfx2/filedlghelper.hxx>
50 #include <sfx2/dispatch.hxx>
51 #include <sfx2/sfxdlg.hxx>
52 #include <svl/PasswordHelper.hxx>
53 #include <svl/documentlockfile.hxx>
54 #include <svl/sharecontrolfile.hxx>
56 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
57 #include <sal/log.hxx>
58 #include <unotools/charclass.hxx>
59 #include <tools/diagnose_ex.h>
60 
61 #include <comphelper/lok.hxx>
63 #include <docuno.hxx>
64 
65 #include <docsh.hxx>
66 #include "docshimp.hxx"
67 #include <docfunc.hxx>
68 #include <scres.hrc>
69 #include <strings.hrc>
70 #include <stlsheet.hxx>
71 #include <stlpool.hxx>
72 #include <appoptio.hxx>
73 #include <globstr.hrc>
74 #include <global.hxx>
75 #include <dbdocfun.hxx>
76 #include <printfun.hxx>
77 #include <viewdata.hxx>
78 #include <tabvwsh.hxx>
79 #include <impex.hxx>
80 #include <undodat.hxx>
81 #include <undocell.hxx>
82 #include <inputhdl.hxx>
83 #include <dbdata.hxx>
84 #include <servobj.hxx>
85 #include <rangenam.hxx>
86 #include <scmod.hxx>
87 #include <chgviset.hxx>
88 #include <reffact.hxx>
89 #include <chartlis.hxx>
90 #include <chartpos.hxx>
91 #include <tablink.hxx>
92 #include <drwlayer.hxx>
93 #include <docoptio.hxx>
94 #include <undostyl.hxx>
95 #include <rangeseq.hxx>
96 #include <chgtrack.hxx>
97 #include <com/sun/star/document/UpdateDocMode.hpp>
98 #include <scresid.hxx>
99 #include <scabstdlg.hxx>
100 #include <sharedocdlg.hxx>
101 #include <conditio.hxx>
102 #include <sheetevents.hxx>
103 #include <formulacell.hxx>
104 #include <documentlinkmgr.hxx>
105 #include <memory>
107 #include <helpids.h>
108 #include <editeng/eeitem.hxx>
109 #include <editeng/langitem.hxx>
110 
111 #include <svx/xdef.hxx>
112 
114 {
117 }
118 
120 {
121  AllowLinkUpdate();
122 
123  ReloadTabLinks();
124  weld::Window *pDialogParent = GetActiveDialogParent();
125  m_aDocument.UpdateExternalRefLinks(pDialogParent);
126 
127  bool bAnyDde = m_aDocument.GetDocLinkManager().updateDdeOrOleOrWebServiceLinks(pDialogParent);
128 
129  if (bAnyDde)
130  {
131  // calculate formulas and paint like in the TrackTimeHdl
133  Broadcast(SfxHint(SfxHintId::ScDataChanged));
134 
135  // Should FID_DATACHANGED become asynchronous some time
136  // (e.g., with Invalidate at Window), an update needs to be forced here.
137  }
138 
140 }
141 
142 IMPL_LINK_NOARG( ScDocShell, ReloadAllLinksHdl, weld::Button&, void )
143 {
144  ReloadAllLinks();
145 
146  ScTabViewShell* pViewSh = GetBestViewShell();
147  SfxViewFrame* pViewFrame = pViewSh ? pViewSh->GetFrame() : nullptr;
148  if (pViewFrame)
149  pViewFrame->RemoveInfoBar(u"enablecontent");
150  SAL_WARN_IF(!pViewFrame, "sc", "expected there to be a ViewFrame");
151 }
152 
154 {
155  const ScDocument& rDoc = GetDocument();
156 
157  ScLkUpdMode nSet = rDoc.GetLinkMode();
158 
159  if (nSet == LM_UNKNOWN)
160  {
161  ScAppOptions aAppOptions = SC_MOD()->GetAppOptions();
162  nSet = aAppOptions.GetLinkMode();
163  }
164 
165  if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
166  nSet = LM_NEVER;
167  else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
168  nSet = LM_ALWAYS;
169 
170  if (nSet == LM_ALWAYS
171  && !(SvtSecurityOptions().isTrustedLocationUriForUpdatingLinks(
172  GetMedium() == nullptr ? OUString() : GetMedium()->GetName())
173  || (IsDocShared()
174  && SvtSecurityOptions().isTrustedLocationUriForUpdatingLinks(
175  GetSharedFileURL()))))
176  {
177  nSet = LM_ON_DEMAND;
178  }
179  if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
180  && nSet == LM_ON_DEMAND)
181  {
182  nSet = LM_NEVER;
183  }
184 
185  return nSet;
186 }
187 
189 {
190  const SfxItemSet* pReqArgs = rReq.GetArgs();
191  SfxBindings* pBindings = GetViewBindings();
192  bool bUndo (m_aDocument.IsUndoEnabled());
193 
194  sal_uInt16 nSlot = rReq.GetSlot();
195  switch ( nSlot )
196  {
197  case SID_SC_SETTEXT:
198  {
199  const SfxPoolItem* pColItem;
200  const SfxPoolItem* pRowItem;
201  const SfxPoolItem* pTabItem;
202  const SfxPoolItem* pTextItem;
203  if( pReqArgs && pReqArgs->HasItem( FN_PARAM_1, &pColItem ) &&
204  pReqArgs->HasItem( FN_PARAM_2, &pRowItem ) &&
205  pReqArgs->HasItem( FN_PARAM_3, &pTabItem ) &&
206  pReqArgs->HasItem( SID_SC_SETTEXT, &pTextItem ) )
207  {
208  // parameters are 1-based !!!
209  SCCOL nCol = static_cast<const SfxInt16Item*>(pColItem)->GetValue() - 1;
210  SCROW nRow = static_cast<const SfxInt32Item*>(pRowItem)->GetValue() - 1;
211  SCTAB nTab = static_cast<const SfxInt16Item*>(pTabItem)->GetValue() - 1;
212 
213  SCTAB nTabCount = m_aDocument.GetTableCount();
214  if ( m_aDocument.ValidCol(nCol) && m_aDocument.ValidRow(nRow) && ValidTab(nTab,nTabCount) )
215  {
216  if ( m_aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) )
217  {
218  OUString aVal = static_cast<const SfxStringItem*>(pTextItem)->GetValue();
219  m_aDocument.SetString( nCol, nRow, nTab, aVal );
220 
221  PostPaintCell( nCol, nRow, nTab );
223 
224  rReq.Done();
225  break;
226  }
227  else // protected cell
228  {
229 #if HAVE_FEATURE_SCRIPTING
231 #endif
232  break;
233  }
234  }
235  }
236 #if HAVE_FEATURE_SCRIPTING
238 #endif
239  }
240  break;
241 
242  case SID_SBA_IMPORT:
243  {
244  if (pReqArgs)
245  {
246  const SfxPoolItem* pItem;
248  if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
249  {
250  uno::Any aAny = static_cast<const SfxUnoAnyItem*>(pItem)->GetValue();
251  uno::Sequence<beans::PropertyValue> aProperties;
252  if ( aAny >>= aProperties )
253  aDesc.initializeFrom( aProperties );
254  }
255 
256  OUString sTarget;
257  if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET )
258  sTarget = static_cast<const SfxStringItem*>(pItem)->GetValue();
259 
260  bool bIsNewArea = true; // Default sal_True (no inquiry)
261  if ( pReqArgs->GetItemState( FN_PARAM_2, true, &pItem ) == SfxItemState::SET )
262  bIsNewArea = static_cast<const SfxBoolItem*>(pItem)->GetValue();
263 
264  // if necessary, create new database area
265  bool bMakeArea = false;
266  if (bIsNewArea)
267  {
269  if ( !pDBColl || !pDBColl->getNamedDBs().findByUpperName(ScGlobal::getCharClassPtr()->uppercase(sTarget)) )
270  {
271  ScAddress aPos;
273  {
274  bMakeArea = true;
275  if (bUndo)
276  {
277  OUString aStrImport = ScResId( STR_UNDO_IMPORTDATA );
278  ViewShellId nViewShellId(-1);
280  nViewShellId = pViewSh->GetViewShellId();
281  GetUndoManager()->EnterListAction( aStrImport, aStrImport, 0, nViewShellId );
282  }
283 
285  OSL_ENSURE(pDBData, "Cannot create DB data");
286  sTarget = pDBData->GetName();
287  }
288  }
289  }
290 
291  // inquire, before old DB range gets overwritten
292  bool bDo = true;
293  if (!bIsNewArea)
294  {
295  OUString aTemplate = ScResId( STR_IMPORT_REPLACE );
296  OUString aMessage = aTemplate.getToken( 0, '#' )
297  + sTarget
298  + aTemplate.getToken( 1, '#' );
299 
300  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(nullptr,
301  VclMessageType::Question, VclButtonsType::YesNo,
302  aMessage));
303  xQueryBox->set_default_response(RET_YES);
304  bDo = xQueryBox->run() == RET_YES;
305  }
306 
307  if (bDo)
308  {
309  ScDBDocFunc(*this).UpdateImport( sTarget, aDesc );
310  rReq.Done();
311 
312  // UpdateImport also updates the internal operations
313  }
314  else
315  rReq.Ignore();
316 
317  if ( bMakeArea && bUndo)
319  }
320  else
321  {
322  OSL_FAIL( "arguments expected" );
323  }
324  }
325  break;
326 
327  case SID_CHART_SOURCE:
328  case SID_CHART_ADDSOURCE:
329  if (pReqArgs)
330  {
331  ScDocument& rDoc = GetDocument();
332  const SfxPoolItem* pItem;
333  OUString aChartName, aRangeName;
334 
335  ScRange aSingleRange;
336  ScRangeListRef aRangeListRef;
337  bool bMultiRange = false;
338 
339  bool bColHeaders = true;
340  bool bRowHeaders = true;
341  bool bColInit = false;
342  bool bRowInit = false;
343  bool bAddRange = (nSlot == SID_CHART_ADDSOURCE);
344 
345  if( pReqArgs->HasItem( SID_CHART_NAME, &pItem ) )
346  aChartName = static_cast<const SfxStringItem*>(pItem)->GetValue();
347 
348  if( pReqArgs->HasItem( SID_CHART_SOURCE, &pItem ) )
349  aRangeName = static_cast<const SfxStringItem*>(pItem)->GetValue();
350 
351  if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
352  {
353  bColHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue();
354  bColInit = true;
355  }
356  if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
357  {
358  bRowHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue();
359  bRowInit = true;
360  }
361 
362  ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0);
363  bool bValid = (aSingleRange.ParseAny(aRangeName, rDoc, aDetails) & ScRefFlags::VALID) == ScRefFlags::ZERO;
364  if (!bValid)
365  {
366  aRangeListRef = new ScRangeList;
367  aRangeListRef->Parse( aRangeName, rDoc );
368  if ( !aRangeListRef->empty() )
369  {
370  bMultiRange = true;
371  aSingleRange = aRangeListRef->front(); // for header
372  bValid = true;
373  }
374  else
375  aRangeListRef.clear();
376  }
377 
379  if (pViewSh && bValid && !aChartName.isEmpty() )
380  {
381  weld::Window* pParent = pViewSh->GetFrameWeld();
382 
383  SCCOL nCol1 = aSingleRange.aStart.Col();
384  SCROW nRow1 = aSingleRange.aStart.Row();
385  SCCOL nCol2 = aSingleRange.aEnd.Col();
386  SCROW nRow2 = aSingleRange.aEnd.Row();
387  SCTAB nTab = aSingleRange.aStart.Tab();
388 
390  if (!bMultiRange)
391  m_aDocument.LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );
392 
393  // Dialog for column/row headers
394  bool bOk = true;
395  if ( !bAddRange && ( !bColInit || !bRowInit ) )
396  {
397  ScChartPositioner aChartPositioner( m_aDocument, nTab, nCol1,nRow1, nCol2,nRow2 );
398  if (!bColInit)
399  bColHeaders = aChartPositioner.HasColHeaders();
400  if (!bRowInit)
401  bRowHeaders = aChartPositioner.HasRowHeaders();
402 
404 
405  ScopedVclPtr<AbstractScColRowLabelDlg> pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders));
406  if ( pDlg->Execute() == RET_OK )
407  {
408  bColHeaders = pDlg->IsRow();
409  bRowHeaders = pDlg->IsCol();
410 
411  rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders));
412  rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders));
413  }
414  else
415  bOk = false;
416  }
417 
418  if (bOk) // execute
419  {
420  if (bMultiRange)
421  {
422  if (bUndo)
423  {
425  std::make_unique<ScUndoChartData>( this, aChartName, aRangeListRef,
426  bColHeaders, bRowHeaders, bAddRange ) );
427  }
428  m_aDocument.UpdateChartArea( aChartName, aRangeListRef,
429  bColHeaders, bRowHeaders, bAddRange );
430  }
431  else
432  {
433  ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
434  if (bUndo)
435  {
437  std::make_unique<ScUndoChartData>( this, aChartName, aNewRange,
438  bColHeaders, bRowHeaders, bAddRange ) );
439  }
440  m_aDocument.UpdateChartArea( aChartName, aNewRange,
441  bColHeaders, bRowHeaders, bAddRange );
442  }
443  }
444  }
445  else
446  {
447  OSL_FAIL("UpdateChartArea: no ViewShell or wrong data");
448  }
449  rReq.Done();
450  }
451  else
452  {
453  OSL_FAIL("SID_CHART_SOURCE without arguments");
454  }
455  break;
456 
457  case FID_AUTO_CALC:
458  {
459  bool bNewVal;
460  const SfxPoolItem* pItem;
461  if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) )
462  bNewVal = static_cast<const SfxBoolItem*>(pItem)->GetValue();
463  else
464  bNewVal = !m_aDocument.GetAutoCalc(); // Toggle for menu
465  m_aDocument.SetAutoCalc( bNewVal );
467  if (pBindings)
468  {
469  pBindings->Invalidate( FID_AUTO_CALC );
470  }
471  rReq.AppendItem( SfxBoolItem( FID_AUTO_CALC, bNewVal ) );
472  rReq.Done();
473  }
474  break;
475  case FID_RECALC:
476  DoRecalc( rReq.IsAPI() );
477  rReq.Done();
478  break;
479  case FID_HARD_RECALC:
480  DoHardRecalc();
481  rReq.Done();
482  break;
483  case SID_UPDATETABLINKS:
484  {
486 
487  if (nSet == LM_ALWAYS)
488  {
489  ReloadAllLinks();
490  rReq.Done();
491  }
492  else if (nSet == LM_NEVER)
493  {
495  rReq.Ignore();
496  }
497  else if (nSet == LM_ON_DEMAND)
498  {
499  ScTabViewShell* pViewSh = GetBestViewShell();
500  SfxViewFrame* pViewFrame = pViewSh ? pViewSh->GetFrame() : nullptr;
501  if (pViewFrame)
502  {
503  pViewFrame->RemoveInfoBar(u"enablecontent");
504  auto pInfoBar = pViewFrame->AppendInfoBar("enablecontent", "", ScResId(STR_RELOAD_TABLES), InfobarType::WARNING);
505  if (pInfoBar)
506  {
507  weld::Button& rBtn = pInfoBar->addButton();
508  rBtn.set_label(ScResId(STR_ENABLE_CONTENT));
509  rBtn.connect_clicked(LINK(this, ScDocShell, ReloadAllLinksHdl));
510  }
511  }
512  rReq.Done();
513  }
514  }
515  break;
516 
517  case SID_REIMPORT_AFTER_LOAD:
518  {
519  // Is called after loading if there are DB areas with omitted data
520 
521  bool bDone = false;
523 
524  if ((m_nCanUpdate != css::document::UpdateDocMode::NO_UPDATE) &&
525  (m_nCanUpdate != css::document::UpdateDocMode::QUIET_UPDATE))
526  {
527  ScRange aRange;
528  ScTabViewShell* pViewSh = GetBestViewShell();
529  OSL_ENSURE(pViewSh,"SID_REIMPORT_AFTER_LOAD: no View");
530  if (pViewSh && pDBColl)
531  {
532  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetActiveDialogParent(),
533  VclMessageType::Question, VclButtonsType::YesNo,
534  ScResId(STR_REIMPORT_AFTER_LOAD)));
535  xQueryBox->set_default_response(RET_YES);
536  if (xQueryBox->run() == RET_YES)
537  {
538  ScDBCollection::NamedDBs& rDBs = pDBColl->getNamedDBs();
539  for (const auto& rxDB : rDBs)
540  {
541  ScDBData& rDBData = *rxDB;
542  if ( rDBData.IsStripData() &&
543  rDBData.HasImportParam() && !rDBData.HasImportSelection() )
544  {
545  rDBData.GetArea(aRange);
546  pViewSh->MarkRange(aRange);
547 
548  // Import and internal operations like SID_REFRESH_DBAREA
549  // (inquiry for import not needed here)
550 
551  ScImportParam aImportParam;
552  rDBData.GetImportParam( aImportParam );
553  bool bContinue = pViewSh->ImportData( aImportParam );
554  rDBData.SetImportParam( aImportParam );
555 
556  // mark (size may have changed)
557  rDBData.GetArea(aRange);
558  pViewSh->MarkRange(aRange);
559 
560  if ( bContinue ) // error at import -> abort
561  {
562  // internal operations, if some where saved
563 
564  if ( rDBData.HasQueryParam() || rDBData.HasSortParam() ||
565  rDBData.HasSubTotalParam() )
566  pViewSh->RepeatDB();
567 
568  // pivot tables, which have the range as source data
569 
570  RefreshPivotTables(aRange);
571  }
572  }
573  }
574  bDone = true;
575  }
576  }
577  }
578 
579  if ( !bDone && pDBColl )
580  {
581  // if not, but then update the dependent formulas
583 
584  m_aDocument.CalcAll();
585  PostDataChanged();
586  }
587 
588  if (bDone)
589  rReq.Done();
590  else
591  rReq.Ignore();
592  }
593  break;
594 
595  case SID_AUTO_STYLE:
596  OSL_FAIL("use ScAutoStyleHint instead of SID_AUTO_STYLE");
597  break;
598 
599  case SID_GET_COLORLIST:
600  {
601  const SvxColorListItem* pColItem = GetItem(SID_COLOR_TABLE);
602  const XColorListRef& pList = pColItem->GetColorList();
603  rReq.SetReturnValue(OfaRefItem<XColorList>(SID_GET_COLORLIST, pList));
604  }
605  break;
606 
607  case FID_CHG_RECORD:
608  {
609  ScDocument& rDoc = GetDocument();
610  // get argument (recorded macro)
611  const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(FID_CHG_RECORD);
612  bool bDo = true;
613 
614  // desired state
615  ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
616  bool bActivateTracking = (pChangeTrack == nullptr); // toggle
617  if ( pItem )
618  bActivateTracking = pItem->GetValue(); // from argument
619 
620  if ( !bActivateTracking )
621  {
622  if ( !pItem )
623  {
624  // no dialog on playing the macro
625  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(),
626  VclMessageType::Warning, VclButtonsType::YesNo,
627  ScResId(STR_END_REDLINING)));
628  xWarn->set_default_response(RET_NO);
629  bDo = (xWarn->run() == RET_YES );
630  }
631 
632  if ( bDo )
633  {
634  if (pChangeTrack)
635  {
636  if ( pChangeTrack->IsProtected() )
638  }
639  if ( bDo )
640  {
641  rDoc.EndChangeTracking();
643  }
644  }
645  }
646  else
647  {
648  rDoc.StartChangeTracking();
649  ScChangeViewSettings aChangeViewSet;
650  aChangeViewSet.SetShowChanges(true);
651  rDoc.SetChangeViewSettings(aChangeViewSet);
652  }
653 
654  if ( bDo )
655  {
657 
658  // invalidate slots
659  if (pBindings)
660  pBindings->InvalidateAll(false);
661  if ( !pItem )
662  rReq.AppendItem( SfxBoolItem( FID_CHG_RECORD, bActivateTracking ) );
663  rReq.Done();
664  }
665  else
666  rReq.Ignore();
667  }
668  break;
669 
670  case SID_CHG_PROTECT :
671  {
673  {
674  rReq.Done();
676  }
677  else
678  rReq.Ignore();
679  }
680  break;
681 
682  case SID_DOCUMENT_MERGE:
683  case SID_DOCUMENT_COMPARE:
684  {
685  bool bDo = true;
686  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
687  if ( pChangeTrack && !m_pImpl->bIgnoreLostRedliningWarning )
688  {
689  if ( nSlot == SID_DOCUMENT_COMPARE )
690  {
691  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(),
692  VclMessageType::Warning, VclButtonsType::YesNo,
693  ScResId(STR_END_REDLINING)));
694  xWarn->set_default_response(RET_NO);
695  if (xWarn->run() == RET_YES)
696  bDo = ExecuteChangeProtectionDialog( true );
697  else
698  bDo = false;
699  }
700  else // merge might reject some actions
701  bDo = ExecuteChangeProtectionDialog( true );
702  }
703  if ( !bDo )
704  {
705  rReq.Ignore();
706  break;
707  }
708  SfxApplication* pApp = SfxGetpApp();
709  const SfxPoolItem* pItem;
710  const SfxStringItem* pStringItem(nullptr);
711  SfxMedium* pMed = nullptr;
712  if (pReqArgs && pReqArgs->GetItemState(SID_FILE_NAME, true, &pItem) == SfxItemState::SET)
713  {
714  pStringItem = dynamic_cast<const SfxStringItem*>(pItem);
715  }
716  if (pStringItem)
717  {
718  OUString aFileName = pStringItem->GetValue();
719 
720  OUString aFilterName;
721  pStringItem = nullptr;
722  if (pReqArgs->GetItemState(SID_FILTER_NAME, true, &pItem) == SfxItemState::SET)
723  pStringItem = dynamic_cast<const SfxStringItem*>(pItem);
724  if (pStringItem)
725  {
726  aFilterName = pStringItem->GetValue();
727  }
728  OUString aOptions;
729  pStringItem = nullptr;
730  if (pReqArgs->GetItemState(SID_FILE_FILTEROPTIONS, true, &pItem) == SfxItemState::SET)
731  pStringItem = dynamic_cast<const SfxStringItem*>(pItem);
732  if (pStringItem)
733  {
734  aOptions = pStringItem->GetValue();
735  }
736  short nVersion = 0;
737  const SfxInt16Item* pInt16Item(nullptr);
738  if (pReqArgs->GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET)
739  pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem);
740  if (pInt16Item)
741  {
742  nVersion = pInt16Item->GetValue();
743  }
744 
745  // no filter specified -> detection
746  if (aFilterName.isEmpty())
747  ScDocumentLoader::GetFilterName( aFileName, aFilterName, aOptions, true, false );
748 
749  // filter name from dialog contains application prefix,
750  // GetFilter needs name without the prefix.
751  ScDocumentLoader::RemoveAppPrefix( aFilterName );
752 
753  std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
754  auto pSet = std::make_shared<SfxAllItemSet>( pApp->GetPool() );
755  if (!aOptions.isEmpty())
756  pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
757  if ( nVersion != 0 )
758  pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) );
759  pMed = new SfxMedium( aFileName, StreamMode::STD_READ, pFilter, std::move(pSet) );
760  }
761  else
762  {
763  const sfx2::DocumentInserter::Mode mode { nSlot==SID_DOCUMENT_COMPARE
766  // start file dialog asynchronous
767  m_pImpl->bIgnoreLostRedliningWarning = true;
768  m_pImpl->pRequest.reset(new SfxRequest( rReq ));
769  m_pImpl->pDocInserter.reset();
770 
772  weld::Window* pParent = pViewSh ? pViewSh->GetFrameWeld() : nullptr;
773  m_pImpl->pDocInserter.reset( new ::sfx2::DocumentInserter(pParent,
774  ScDocShell::Factory().GetFactoryName(), mode ) );
775  m_pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) );
776  return ;
777  }
778 
779  // now execute in earnest...
781 
782  // pOtherDocSh->DoClose() will be called explicitly later, but it is still more safe to use SfxObjectShellLock here
783  ScDocShell* pOtherDocSh = new ScDocShell;
784  SfxObjectShellLock aDocShTablesRef = pOtherDocSh;
785  pOtherDocSh->DoLoad( pMed );
786  ErrCode nErr = pOtherDocSh->GetErrorCode();
787  if (nErr)
788  ErrorHandler::HandleError( nErr ); // also warnings
789 
790  if ( !pOtherDocSh->GetError() ) // only errors
791  {
792  bool bHadTrack = ( m_aDocument.GetChangeTrack() != nullptr );
793 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
794  sal_uLong nStart = 0;
795  if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack )
796  {
797  nStart = pChangeTrack->GetActionMax() + 1;
798  }
799 #endif
800  if ( nSlot == SID_DOCUMENT_COMPARE )
801  CompareDocument( pOtherDocSh->GetDocument() );
802  else
803  MergeDocument( pOtherDocSh->GetDocument() );
804 
805  // show "accept changes" dialog
807  if ( !IsDocShared() )
808  {
809  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
810  if ( pViewFrm )
811  {
812  pViewFrm->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId() ); //@51669
813  }
814  if ( pBindings )
815  {
816  pBindings->Invalidate( FID_CHG_ACCEPT );
817  }
818  }
819 
820  rReq.SetReturnValue( SfxInt32Item( nSlot, 0 ) );
821  rReq.Done();
822 
823  if (!bHadTrack) // newly turned on -> show as well
824  {
826  if ( !pOldSet || !pOldSet->ShowChanges() )
827  {
828  ScChangeViewSettings aChangeViewSet;
829  aChangeViewSet.SetShowChanges(true);
830  m_aDocument.SetChangeViewSettings(aChangeViewSet);
831  }
832  }
833 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
834  else if ( nSlot == SID_DOCUMENT_MERGE && IsDocShared() && pChangeTrack )
835  {
836  sal_uLong nEnd = pChangeTrack->GetActionMax();
837  if ( nEnd >= nStart )
838  {
839  // only show changes from merged document
840  ScChangeViewSettings aChangeViewSet;
841  aChangeViewSet.SetShowChanges( true );
842  aChangeViewSet.SetShowAccepted( true );
843  aChangeViewSet.SetHasActionRange();
844  aChangeViewSet.SetTheActionRange( nStart, nEnd );
845  m_aDocument.SetChangeViewSettings( aChangeViewSet );
846 
847  // update view
848  PostPaintExtras();
850  }
851  }
852 #endif
853  }
854  pOtherDocSh->DoClose(); // delete happens with the Ref
855  }
856  break;
857 
858  case SID_DELETE_SCENARIO:
859  if (pReqArgs)
860  {
861  const SfxPoolItem* pItem;
862  if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
863  {
864  if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
865  {
866  const OUString& aName = pStringItem->GetValue();
867  SCTAB nTab;
868  if (m_aDocument.GetTable( aName, nTab ))
869  {
870  // move DeleteTable from viewfunc to docfunc!
871 
873  if ( pSh )
874  {
876  SCTAB nDispTab = pSh->GetViewData().GetTabNo();
877  pSh->DeleteTable( nTab );
878  pSh->SetTabNo(nDispTab);
879  rReq.Done();
880  }
881  }
882  }
883  }
884  }
885  break;
886 
887  case SID_EDIT_SCENARIO:
888  {
889  const SfxPoolItem* pItem;
890  if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
891  {
892  if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
893  {
894  OUString aName = pStringItem->GetValue();
895  SCTAB nTab;
896  if (m_aDocument.GetTable( aName, nTab ))
897  {
898  if (m_aDocument.IsScenario(nTab))
899  {
900  OUString aComment;
901  Color aColor;
902  ScScenarioFlags nFlags;
903  m_aDocument.GetScenarioData( nTab, aComment, aColor, nFlags );
904 
905  // Determine if the Sheet that the Scenario was created on
906  // is protected. But first we need to find that Sheet.
907  // Rewind back to the actual sheet.
908  SCTAB nActualTab = nTab;
909  do
910  {
911  nActualTab--;
912  }
913  while(m_aDocument.IsScenario(nActualTab));
914  bool bSheetProtected = m_aDocument.IsTabProtected(nActualTab);
915 
917 
918  ScopedVclPtr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(GetActiveDialogParent(), aName, true, bSheetProtected));
919  pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags );
920  if ( pNewDlg->Execute() == RET_OK )
921  {
922  pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
923  ModifyScenario( nTab, aName, aComment, aColor, nFlags );
924  rReq.Done();
925  }
926  }
927  }
928  }
929  }
930  }
931  break;
932 
933  case SID_ATTR_YEAR2000 :
934  {
935  const SfxPoolItem* pItem;
936  if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
937  {
938  if (const SfxUInt16Item* pInt16Item = dynamic_cast<const SfxUInt16Item*>(pItem))
939  {
940  sal_uInt16 nY2k = pInt16Item->GetValue();
941  // set always to DocOptions, so that it is also saved for S050
942  // (and all inquiries run up until now on it as well).
943  // SetDocOptions propagates that to the NumberFormatter
945  aDocOpt.SetYear2000( nY2k );
946  m_aDocument.SetDocOptions( aDocOpt );
947  // the FormShell shall notice it as well
949  if ( pSh )
950  {
951  FmFormShell* pFSh = pSh->GetFormShell();
952  if ( pFSh )
953  pFSh->SetY2KState( nY2k );
954  }
955  }
956  }
957  }
958  break;
959 
960 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
961  case SID_SHARE_DOC:
962  {
963  ScViewData* pViewData = GetViewData();
964  if ( !pViewData )
965  {
966  rReq.Ignore();
967  break;
968  }
969 
971  ScShareDocumentDlg aDlg(pWin, pViewData);
972  if (aDlg.run() == RET_OK)
973  {
974  bool bSetShared = aDlg.IsShareDocumentChecked();
975  if ( bSetShared != IsDocShared() )
976  {
977  if ( bSetShared )
978  {
979  bool bContinue = true;
980  if ( HasName() )
981  {
982  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pWin,
983  VclMessageType::Question, VclButtonsType::YesNo,
984  ScResId(STR_DOC_WILLBESAVED)));
985  xQueryBox->set_default_response(RET_YES);
986  if (xQueryBox->run() == RET_NO)
987  {
988  bContinue = false;
989  }
990  }
991  if ( bContinue )
992  {
993  EnableSharedSettings( true );
994 
995  SC_MOD()->SetInSharedDocSaving( true );
996  if ( !SwitchToShared( true, true ) )
997  {
998  // TODO/LATER: what should be done in case the switch has failed?
999  // for example in case the user has cancelled the saveAs operation
1000  }
1001 
1002  SC_MOD()->SetInSharedDocSaving( false );
1003 
1004  InvalidateName();
1005  GetUndoManager()->Clear();
1006 
1007  ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
1008  if ( pTabView )
1009  {
1010  pTabView->UpdateLayerLocks();
1011  }
1012  }
1013  }
1014  else
1015  {
1016  uno::Reference< frame::XModel > xModel;
1017  try
1018  {
1019  // load shared file
1020  xModel.set( LoadSharedDocument(), uno::UNO_SET_THROW );
1021  uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
1022 
1023  // check if shared flag is set in shared file
1024  bool bShared = false;
1025  ScModelObj* pDocObj = comphelper::getUnoTunnelImplementation<ScModelObj>( xModel );
1026  if ( pDocObj )
1027  {
1028  ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pDocObj->GetEmbeddedObject() );
1029  if ( pDocShell )
1030  {
1031  bShared = pDocShell->HasSharedXMLFlagSet();
1032  }
1033  }
1034 
1035  // #i87870# check if shared status was disabled and enabled again
1036  bool bOwnEntry = false;
1037  try
1038  {
1039  ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
1040  bOwnEntry = aControlFile.HasOwnEntry();
1041  }
1042  catch ( uno::Exception& )
1043  {
1044  }
1045 
1046  if ( bShared && bOwnEntry )
1047  {
1048  uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
1049  if ( xStorable->isReadonly() )
1050  {
1051  xCloseable->close( true );
1052 
1053  OUString aUserName( ScResId( STR_UNKNOWN_USER ) );
1054  try
1055  {
1057  LockFileEntry aData = aLockFile.GetLockData();
1058  if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
1059  {
1060  aUserName = aData[LockFileComponent::OOOUSERNAME];
1061  }
1062  else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() )
1063  {
1064  aUserName = aData[LockFileComponent::SYSUSERNAME];
1065  }
1066  }
1067  catch ( uno::Exception& )
1068  {
1069  }
1070  OUString aMessage( ScResId( STR_FILE_LOCKED_TRY_LATER ) );
1071  aMessage = aMessage.replaceFirst( "%1", aUserName );
1072 
1073  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin,
1074  VclMessageType::Warning, VclButtonsType::Ok,
1075  aMessage));
1076  xWarn->run();
1077  }
1078  else
1079  {
1080  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin,
1081  VclMessageType::Warning, VclButtonsType::YesNo,
1082  ScResId(STR_DOC_DISABLESHARED)));
1083  xWarn->set_default_response(RET_YES);
1084 
1085  if (xWarn->run() == RET_YES)
1086  {
1087  xCloseable->close( true );
1088 
1089  if ( !SwitchToShared( false, true ) )
1090  {
1091  // TODO/LATER: what should be done in case the switch has failed?
1092  // for example in case the user has cancelled the saveAs operation
1093  }
1094 
1095  EnableSharedSettings( false );
1096 
1097  if ( pBindings )
1098  {
1099  pBindings->ExecuteSynchron( SID_SAVEDOC );
1100  }
1101 
1102  ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
1103  if ( pTabView )
1104  {
1105  pTabView->UpdateLayerLocks();
1106  }
1107  }
1108  else
1109  {
1110  xCloseable->close( true );
1111  }
1112  }
1113  }
1114  else
1115  {
1116  xCloseable->close( true );
1117  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin,
1118  VclMessageType::Warning, VclButtonsType::Ok,
1119  ScResId(STR_DOC_NOLONGERSHARED)));
1120  xWarn->run();
1121  }
1122  }
1123  catch ( uno::Exception& )
1124  {
1125  TOOLS_WARN_EXCEPTION( "sc", "SID_SHARE_DOC" );
1126  SC_MOD()->SetInSharedDocSaving( false );
1127 
1128  try
1129  {
1130  uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
1131  xClose->close( true );
1132  }
1133  catch ( uno::Exception& )
1134  {
1135  }
1136  }
1137  }
1138  }
1139  }
1140  rReq.Done();
1141  }
1142  break;
1143 #endif
1144  case SID_OPEN_CALC:
1145  {
1146  SfxStringItem aApp(SID_DOC_SERVICE, "com.sun.star.sheet.SpreadsheetDocument");
1147  SfxStringItem aTarget(SID_TARGETNAME, "_blank");
1149  SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON,
1150  { &aApp, &aTarget });
1151  }
1152  break;
1153  case SID_NOTEBOOKBAR:
1154  {
1155  const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>( SID_NOTEBOOKBAR );
1156 
1157  if ( pBindings && sfx2::SfxNotebookBar::IsActive() )
1158  sfx2::SfxNotebookBar::ExecMethod(*pBindings, pFile ? pFile->GetValue() : "");
1159  else if ( pBindings )
1161  }
1162  break;
1163  case SID_LANGUAGE_STATUS:
1164  {
1165  OUString aLangText;
1166  const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1167  if ( pItem )
1168  aLangText = pItem->GetValue();
1169 
1170  if ( !aLangText.isEmpty() )
1171  {
1172  LanguageType eLang, eLatin, eCjk, eCtl;
1173  const OUString aSelectionLangPrefix("Current_");
1174  const OUString aParagraphLangPrefix("Paragraph_");
1175  const OUString aDocLangPrefix("Default_");
1176 
1177  bool bSelection = false;
1178  bool bParagraph = false;
1179 
1180  ScDocument& rDoc = GetDocument();
1181  rDoc.GetLanguage( eLatin, eCjk, eCtl );
1182 
1183  sal_Int32 nPos = 0;
1184  if ( aLangText == "*" )
1185  {
1188  ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclDialog(pSh ? pSh->GetDialogParent() : nullptr, SID_LANGUAGE_OPTIONS));
1189  pDlg->Execute();
1190 
1191  rDoc.GetLanguage( eLang, eCjk, eCtl );
1192  }
1193  else if ( (nPos = aLangText.indexOf(aDocLangPrefix)) != -1 )
1194  {
1195  aLangText = aLangText.replaceAt(nPos, aDocLangPrefix.getLength(), "");
1196 
1197  if ( aLangText == "LANGUAGE_NONE" )
1198  {
1199  eLang = LANGUAGE_NONE;
1200  rDoc.SetLanguage( eLang, eCjk, eCtl );
1201  }
1202  else if ( aLangText == "RESET_LANGUAGES" )
1203  {
1204  bool bAutoSpell;
1205 
1206  ScModule::GetSpellSettings(eLang, eCjk, eCtl, bAutoSpell);
1207  rDoc.SetLanguage(eLang, eCjk, eCtl);
1208  }
1209  else
1210  {
1211  eLang = SvtLanguageTable::GetLanguageType( aLangText );
1212  if ( eLang != LANGUAGE_DONTKNOW && SvtLanguageOptions::GetScriptTypeOfLanguage(eLang) == SvtScriptType::LATIN )
1213  {
1214  rDoc.SetLanguage( eLang, eCjk, eCtl );
1215  }
1216  else
1217  {
1218  eLang = eLatin;
1219  }
1220  }
1221  }
1222  else if (-1 != (nPos = aLangText.indexOf( aSelectionLangPrefix )))
1223  {
1224  bSelection = true;
1225  aLangText = aLangText.replaceAt( nPos, aSelectionLangPrefix.getLength(), "" );
1226  }
1227  else if (-1 != (nPos = aLangText.indexOf( aParagraphLangPrefix )))
1228  {
1229  bParagraph = true;
1230  aLangText = aLangText.replaceAt( nPos, aParagraphLangPrefix.getLength(), "" );
1231  }
1232 
1233  if (bSelection || bParagraph)
1234  {
1235  ScViewData* pViewData = GetViewData();
1236  if (!pViewData)
1237  return;
1238 
1239  EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart());
1240  if (!pEditView)
1241  return;
1242 
1243  const LanguageType nLangToUse = SvtLanguageTable::GetLanguageType( aLangText );
1244  SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse );
1245 
1246  SfxItemSet aAttrs = pEditView->GetEditEngine()->GetEmptyItemSet();
1247  if (nScriptType == SvtScriptType::LATIN)
1248  aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE ) );
1249  if (nScriptType == SvtScriptType::COMPLEX)
1250  aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CTL ) );
1251  if (nScriptType == SvtScriptType::ASIAN)
1252  aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CJK ) );
1253  ESelection aOldSel;
1254  if (bParagraph)
1255  {
1256  ESelection aSel = pEditView->GetSelection();
1257  aOldSel = aSel;
1258  aSel.nStartPos = 0;
1259  aSel.nEndPos = EE_TEXTPOS_ALL;
1260  pEditView->SetSelection( aSel );
1261  }
1262 
1263  pEditView->SetAttribs( aAttrs );
1264  if (bParagraph)
1265  pEditView->SetSelection( aOldSel );
1266  }
1267  else if ( eLang != eLatin )
1268  {
1270  {
1271  ScInputHandler* pInputHandler = SC_MOD()->GetInputHdl(pViewSh);
1272  if ( pInputHandler )
1273  pInputHandler->UpdateSpellSettings();
1274 
1275  pViewSh->UpdateDrawTextOutliner();
1276  }
1277 
1279  Broadcast(SfxHint(SfxHintId::LanguageChanged));
1280  PostPaintGridAll();
1281  }
1282  }
1283  }
1284  break;
1285  case SID_SPELLCHECK_IGNORE_ALL:
1286  {
1287  ScViewData* pViewData = GetViewData();
1288  if (!pViewData)
1289  return;
1290 
1291  EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart());
1292  if (!pEditView)
1293  return;
1294 
1295  OUString sIgnoreText;
1296  const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
1297  if (pItem2)
1298  sIgnoreText = pItem2->GetValue();
1299 
1300  if(sIgnoreText == "Spelling")
1301  {
1302  ESelection aOldSel = pEditView->GetSelection();
1303  pEditView->SpellIgnoreWord();
1304  pEditView->SetSelection( aOldSel );
1305  }
1306  }
1307  break;
1308  case SID_SPELLCHECK_APPLY_SUGGESTION:
1309  {
1310  ScViewData* pViewData = GetViewData();
1311  if (!pViewData)
1312  return;
1313 
1314  EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart());
1315  if (!pEditView)
1316  return;
1317 
1318  OUString sApplyText;
1319  const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
1320  if (pItem2)
1321  sApplyText = pItem2->GetValue();
1322 
1323  const OUString sSpellingRule("Spelling_");
1324  sal_Int32 nPos = 0;
1325  if(-1 != (nPos = sApplyText.indexOf( sSpellingRule )))
1326  {
1327  sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), "");
1328  pEditView->InsertText( sApplyText );
1329  }
1330  }
1331  break;
1332  default:
1333  {
1334  // small (?) hack -> forwarding of the slots to TabViewShell
1336  if ( pSh )
1337  pSh->Execute( rReq );
1338 #if HAVE_FEATURE_SCRIPTING
1339  else
1341 #endif
1342  }
1343  }
1344 }
1345 
1347 {
1348  // update "accept changes" dialog
1350  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1351  if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) )
1352  {
1353  SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT );
1354  if ( pChild )
1355  static_cast<ScAcceptChgDlgWrapper*>(pChild)->ReInitDlg();
1356  }
1357 }
1358 
1359 bool ScDocShell::ExecuteChangeProtectionDialog( bool bJustQueryIfProtected )
1360 {
1361  bool bDone = false;
1362  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
1363  if ( pChangeTrack )
1364  {
1365  bool bProtected = pChangeTrack->IsProtected();
1366  if ( bJustQueryIfProtected && !bProtected )
1367  return true;
1368 
1369  OUString aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) );
1370  OUString aText( ScResId( SCSTR_PASSWORD ) );
1371  OUString aPassword;
1372 
1374  SfxPasswordDialog aDlg(pWin, &aText);
1375  aDlg.set_title(aTitle);
1376  aDlg.SetMinLen(1);
1377  aDlg.set_help_id(GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand());
1379  if ( !bProtected )
1380  aDlg.ShowExtras(SfxShowExtras::CONFIRM);
1381  if (aDlg.run() == RET_OK)
1382  aPassword = aDlg.GetPassword();
1383 
1384  if (!aPassword.isEmpty())
1385  {
1386  if ( bProtected )
1387  {
1388  if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) )
1389  {
1390  if ( bJustQueryIfProtected )
1391  bDone = true;
1392  else
1393  pChangeTrack->SetProtection(
1394  css::uno::Sequence< sal_Int8 > (0) );
1395  }
1396  else
1397  {
1398  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin,
1399  VclMessageType::Info, VclButtonsType::Ok,
1400  ScResId(SCSTR_WRONGPASSWORD)));
1401  xInfoBox->run();
1402  }
1403  }
1404  else
1405  {
1406  css::uno::Sequence< sal_Int8 > aPass;
1407  SvPasswordHelper::GetHashPassword( aPass, aPassword );
1408  pChangeTrack->SetProtection( aPass );
1409  }
1410  if ( bProtected != pChangeTrack->IsProtected() )
1411  {
1413  bDone = true;
1414  }
1415  }
1416  }
1417  else if ( bJustQueryIfProtected )
1418  bDone = true;
1419  return bDone;
1420 }
1421 
1422 void ScDocShell::DoRecalc( bool bApi )
1423 {
1425  bool bDone = false;
1427  ScInputHandler* pHdl = ( pSh ? SC_MOD()->GetInputHdl( pSh ) : nullptr );
1428  if ( pSh )
1429  {
1430  if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi )
1431  {
1432  pHdl->FormulaPreview(); // partial result as QuickHelp
1433  bDone = true;
1434  }
1435  else
1436  {
1437  ScTabView::UpdateInputLine(); // InputEnterHandler
1438  pSh->UpdateInputHandler();
1439  }
1440  }
1441  if (bDone) // otherwise re-calculate document
1442  return;
1443 
1445  if ( pHdl )
1446  {
1447  // tdf97897 set current cell to Dirty to force recalculation of cell
1449  if (pFC)
1450  pFC->SetDirty();
1451  }
1453  if ( pSh )
1454  pSh->UpdateCharts(true);
1455 
1456  m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
1457 
1458  // If there are charts, then paint everything, so that PostDataChanged
1459  // and the charts do not come one after the other and parts are painted twice.
1460 
1462  if ( pCharts && pCharts->hasListeners() )
1463  PostPaintGridAll();
1464  else
1465  PostDataChanged();
1466 }
1467 
1469 {
1470  auto start = std::chrono::steady_clock::now();
1474  if ( pSh )
1475  {
1476  ScTabView::UpdateInputLine(); // InputEnterHandler
1477  pSh->UpdateInputHandler();
1478  }
1479  m_aDocument.CalcAll();
1480  GetDocFunc().DetectiveRefresh(); // creates own Undo
1481  if ( pSh )
1482  pSh->UpdateCharts(true);
1483 
1484  // set notification flags for "calculate" event (used in SfxHintId::DataChanged broadcast)
1485  // (might check for the presence of any formulas on each sheet)
1486  SCTAB nTabCount = m_aDocument.GetTableCount();
1487  if (m_aDocument.HasAnySheetEventScript( ScSheetEventId::CALCULATE, true )) // search also for VBA handler
1488  for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1490 
1491  // CalcAll doesn't broadcast value changes, so SfxHintId::ScCalcAll is broadcasted globally
1492  // in addition to SfxHintId::DataChanged.
1493  m_aDocument.BroadcastUno( SfxHint( SfxHintId::ScCalcAll ) );
1494  m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
1495 
1496  // use hard recalc also to disable stream-copying of all sheets
1497  // (somewhat consistent with charts)
1498  for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1499  m_aDocument.SetStreamValid(nTab, false);
1500 
1501  PostPaintGridAll();
1502  auto end = std::chrono::steady_clock::now();
1503  SAL_INFO("sc.timing", "ScDocShell::DoHardRecalc(): took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms");
1504 }
1505 
1506 void ScDocShell::DoAutoStyle( const ScRange& rRange, const OUString& rStyle )
1507 {
1509  ScStyleSheet* pStyleSheet =
1510  pStylePool->FindCaseIns( rStyle, SfxStyleFamily::Para );
1511  if (!pStyleSheet)
1512  pStyleSheet = static_cast<ScStyleSheet*>(
1513  pStylePool->Find( ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Para ));
1514  if (!pStyleSheet)
1515  return;
1516 
1517  OSL_ENSURE(rRange.aStart.Tab() == rRange.aEnd.Tab(),
1518  "DoAutoStyle with several tables");
1519  SCTAB nTab = rRange.aStart.Tab();
1520  SCCOL nStartCol = rRange.aStart.Col();
1521  SCROW nStartRow = rRange.aStart.Row();
1522  SCCOL nEndCol = rRange.aEnd.Col();
1523  SCROW nEndRow = rRange.aEnd.Row();
1524  m_aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
1525  m_aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
1526  PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PaintPartFlags::Grid );
1527 }
1528 
1530 {
1531  SfxHintId nId = rHint.GetId();
1532  const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet();
1533  if (!pStyle)
1534  return;
1535 
1536  if ( pStyle->GetFamily() == SfxStyleFamily::Page )
1537  {
1538  if ( nId == SfxHintId::StyleSheetModified )
1539  {
1540  ScDocShellModificator aModificator( *this );
1541 
1542  const OUString& aNewName = pStyle->GetName();
1543  OUString aOldName = aNewName;
1544  const SfxStyleSheetModifiedHint* pExtendedHint = dynamic_cast<const SfxStyleSheetModifiedHint*>(&rHint); // name changed?
1545  if (pExtendedHint)
1546  aOldName = pExtendedHint->GetOldName();
1547 
1548  if ( aNewName != aOldName )
1549  m_aDocument.RenamePageStyleInUse( aOldName, aNewName );
1550 
1551  SCTAB nTabCount = m_aDocument.GetTableCount();
1552  for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1553  if (m_aDocument.GetPageStyle(nTab) == aNewName) // already adjusted to new
1554  {
1555  m_aDocument.PageStyleModified( nTab, aNewName );
1556  ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1557  aPrintFunc.UpdatePages();
1558  }
1559 
1560  aModificator.SetDocumentModified();
1561 
1562  if (pExtendedHint)
1563  {
1564  SfxBindings* pBindings = GetViewBindings();
1565  if (pBindings)
1566  {
1567  pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1568  pBindings->Invalidate( SID_STYLE_FAMILY4 );
1569  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1570  pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1571  pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1572  }
1573  }
1574  }
1575  }
1576  else if ( pStyle->GetFamily() == SfxStyleFamily::Para )
1577  {
1578  if ( nId == SfxHintId::StyleSheetModified)
1579  {
1580  const OUString& aNewName = pStyle->GetName();
1581  OUString aOldName = aNewName;
1582  const SfxStyleSheetModifiedHint* pExtendedHint = dynamic_cast<const SfxStyleSheetModifiedHint*>(&rHint);
1583  if (pExtendedHint)
1584  aOldName = pExtendedHint->GetOldName();
1585  if ( aNewName != aOldName )
1586  {
1587  for(SCTAB i = 0; i < m_aDocument.GetTableCount(); ++i)
1588  {
1590  if (pList)
1591  pList->RenameCellStyle( aOldName,aNewName );
1592  }
1593  }
1594  }
1595  }
1596 
1597  // everything else goes via slots...
1598 }
1599 
1600 // like in printfun.cxx
1601 #define ZOOM_MIN 10
1602 
1603 void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages )
1604 {
1605  OUString aStyleName = m_aDocument.GetPageStyle( nTab );
1607  SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
1608  OSL_ENSURE( pStyleSheet, "PageStyle not found" );
1609  if ( !pStyleSheet )
1610  return;
1611 
1612  ScDocShellModificator aModificator( *this );
1613 
1614  SfxItemSet& rSet = pStyleSheet->GetItemSet();
1615  const bool bUndo(m_aDocument.IsUndoEnabled());
1616  if (bUndo)
1617  {
1618  sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
1619  sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
1620  GetUndoManager()->AddUndoAction( std::make_unique<ScUndoPrintZoom>(
1621  this, nTab, nOldScale, nOldPages, nScale, nPages ) );
1622  }
1623 
1624  rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
1625  rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
1626 
1627  ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1628  aPrintFunc.UpdatePages();
1629  aModificator.SetDocumentModified();
1630 
1631  SfxBindings* pBindings = GetViewBindings();
1632  if (pBindings)
1633  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1634 }
1635 
1637 {
1638  bool bChange = false;
1639  SCTAB nTab = rRange.aStart.Tab();
1640 
1641  OUString aStyleName = m_aDocument.GetPageStyle( nTab );
1643  SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
1644  OSL_ENSURE( pStyleSheet, "PageStyle not found" );
1645  if ( pStyleSheet )
1646  {
1647  SfxItemSet& rSet = pStyleSheet->GetItemSet();
1648  bool bHeaders = rSet.Get(ATTR_PAGE_HEADERS).GetValue();
1649  sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
1650  sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
1651  const ScRange* pRepeatCol = m_aDocument.GetRepeatColRange( nTab );
1652  const ScRange* pRepeatRow = m_aDocument.GetRepeatRowRange( nTab );
1653 
1654  // calculate needed scaling for selection
1655 
1656  sal_uInt16 nNewScale = nOldScale;
1657 
1658  tools::Long nBlkTwipsX = 0;
1659  if (bHeaders)
1660  nBlkTwipsX += tools::Long(PRINT_HEADER_WIDTH);
1661  SCCOL nStartCol = rRange.aStart.Col();
1662  SCCOL nEndCol = rRange.aEnd.Col();
1663  if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
1664  {
1665  for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ )
1666  nBlkTwipsX += m_aDocument.GetColWidth( i, nTab );
1667  if ( nStartCol <= pRepeatCol->aEnd.Col() )
1668  nStartCol = pRepeatCol->aEnd.Col() + 1;
1669  }
1670  // legacy compilers' own scope for i
1671  {
1672  for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
1673  nBlkTwipsX += m_aDocument.GetColWidth( i, nTab );
1674  }
1675 
1676  tools::Long nBlkTwipsY = 0;
1677  if (bHeaders)
1678  nBlkTwipsY += tools::Long(PRINT_HEADER_HEIGHT);
1679  SCROW nStartRow = rRange.aStart.Row();
1680  SCROW nEndRow = rRange.aEnd.Row();
1681  if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
1682  {
1683  nBlkTwipsY += m_aDocument.GetRowHeight( pRepeatRow->aStart.Row(),
1684  pRepeatRow->aEnd.Row(), nTab );
1685  if ( nStartRow <= pRepeatRow->aEnd.Row() )
1686  nStartRow = pRepeatRow->aEnd.Row() + 1;
1687  }
1688  nBlkTwipsY += m_aDocument.GetRowHeight( nStartRow, nEndRow, nTab );
1689 
1690  Size aPhysPage;
1691  tools::Long nHdr, nFtr;
1692  ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab );
1693  aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
1694  nBlkTwipsY += nHdr + nFtr;
1695 
1696  if ( nBlkTwipsX == 0 ) // hidden columns/rows may lead to 0
1697  nBlkTwipsX = 1;
1698  if ( nBlkTwipsY == 0 )
1699  nBlkTwipsY = 1;
1700 
1701  tools::Long nNeeded = std::min( aPhysPage.Width() * 100 / nBlkTwipsX,
1702  aPhysPage.Height() * 100 / nBlkTwipsY );
1703  if ( nNeeded < ZOOM_MIN )
1704  nNeeded = ZOOM_MIN; // boundary
1705  if ( nNeeded < static_cast<tools::Long>(nNewScale) )
1706  nNewScale = static_cast<sal_uInt16>(nNeeded);
1707 
1708  bChange = ( nNewScale != nOldScale || nOldPages != 0 );
1709  if ( bChange )
1710  SetPrintZoom( nTab, nNewScale, 0 );
1711  }
1712  return bChange;
1713 }
1714 
1715 void ScDocShell::PageStyleModified( std::u16string_view rStyleName, bool bApi )
1716 {
1717  ScDocShellModificator aModificator( *this );
1718 
1719  SCTAB nTabCount = m_aDocument.GetTableCount();
1720  SCTAB nUseTab = MAXTAB+1;
1721  for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
1722  if ( m_aDocument.GetPageStyle(nTab) == rStyleName &&
1723  ( !bApi || m_aDocument.GetPageSize(nTab).Width() ) )
1724  nUseTab = nTab;
1725  // at bApi only if breaks already shown
1726 
1727  if (ValidTab(nUseTab)) // not used -> nothing to do
1728  {
1729  bool bWarn = false;
1730 
1731  ScPrintFunc aPrintFunc( this, GetPrinter(), nUseTab );
1732  if (!aPrintFunc.UpdatePages()) // sets breaks on all tabs
1733  bWarn = true;
1734 
1735  if (bWarn && !bApi)
1736  {
1738  weld::WaitObject aWaitOff(pWin);
1739  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin,
1740  VclMessageType::Info, VclButtonsType::Ok,
1741  ScResId(STR_PRINT_INVALID_AREA)));
1742  xInfoBox->run();
1743  }
1744  }
1745 
1746  aModificator.SetDocumentModified();
1747 
1748  SfxBindings* pBindings = GetViewBindings();
1749  if (pBindings)
1750  {
1751  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1752  pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1753  pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1754  }
1755 }
1756 
1758  SfxRequest& rReq,
1759  SCTAB nCurTab )
1760 {
1761  const SfxItemSet* pReqArgs = rReq.GetArgs();
1762 
1763  switch ( rReq.GetSlot() )
1764  {
1765  case SID_STATUS_PAGESTYLE: // click on StatusBar control
1766  case SID_FORMATPAGE:
1767  {
1768  if ( pReqArgs == nullptr )
1769  {
1770  OUString aOldName = m_aDocument.GetPageStyle( nCurTab );
1772  SfxStyleSheetBase* pStyleSheet
1773  = pStylePool->Find( aOldName, SfxStyleFamily::Page );
1774 
1775  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
1776 
1777  if ( pStyleSheet )
1778  {
1779  ScStyleSaveData aOldData;
1780  const bool bUndo(m_aDocument.IsUndoEnabled());
1781  if (bUndo)
1782  aOldData.InitFromStyle( pStyleSheet );
1783 
1784  SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1786 
1788 
1789  VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScStyleDlg(GetActiveDialogParent(), *pStyleSheet, true));
1790 
1791  auto pRequest = std::make_shared<SfxRequest>(rReq);
1792  rReq.Ignore(); // the 'old' request is not relevant any more
1793  pDlg->StartExecuteAsync([this, pDlg, pRequest, pStyleSheet, aOldData, aOldName, &rStyleSet, nCurTab, &rCaller, bUndo](sal_Int32 nResult){
1794  if ( nResult == RET_OK )
1795  {
1796  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1797 
1799 
1800  OUString aNewName = pStyleSheet->GetName();
1801  if ( aNewName != aOldName &&
1802  m_aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
1803  {
1804  SfxBindings* pBindings = GetViewBindings();
1805  if (pBindings)
1806  {
1807  pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1808  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1809  }
1810  }
1811 
1812  if ( pOutSet )
1813  m_aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1814 
1815  // memorizing for GetState():
1816  GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );
1817  rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT );
1818 
1819  ScStyleSaveData aNewData;
1820  aNewData.InitFromStyle( pStyleSheet );
1821  if (bUndo)
1822  {
1824  std::make_unique<ScUndoModifyStyle>( this, SfxStyleFamily::Page,
1825  aOldData, aNewData ) );
1826  }
1827 
1828  PageStyleModified( aNewName, false );
1829  pRequest->Done();
1830  }
1831  pDlg->disposeOnce();
1832  });
1833  }
1834  }
1835  }
1836  break;
1837 
1838  case SID_HFEDIT:
1839  {
1840  if ( pReqArgs == nullptr )
1841  {
1842  OUString aStr( m_aDocument.GetPageStyle( nCurTab ) );
1843 
1844  ScStyleSheetPool* pStylePool
1846 
1847  SfxStyleSheetBase* pStyleSheet
1848  = pStylePool->Find( aStr, SfxStyleFamily::Page );
1849 
1850  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
1851 
1852  if ( pStyleSheet )
1853  {
1854  SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1855 
1856  SvxPageUsage eUsage = rStyleSet.Get( ATTR_PAGE ).GetPageUsage();
1857  bool bShareHeader = rStyleSet
1859  .GetItemSet()
1860  .Get(ATTR_PAGE_SHARED)
1861  .GetValue();
1862  bool bShareFooter = rStyleSet
1864  .GetItemSet()
1865  .Get(ATTR_PAGE_SHARED)
1866  .GetValue();
1867  sal_uInt16 nResId = 0;
1868 
1869  switch ( eUsage )
1870  {
1871  case SvxPageUsage::Left:
1872  case SvxPageUsage::Right:
1873  {
1874  if ( m_bHeaderOn && m_bFooterOn )
1875  nResId = RID_SCDLG_HFEDIT;
1876  else if ( SvxPageUsage::Right == eUsage )
1877  {
1878  if ( !m_bHeaderOn && m_bFooterOn )
1879  nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1880  else if ( m_bHeaderOn && !m_bFooterOn )
1881  nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1882  }
1883  else
1884  {
1885  // #69193a# respect "shared" setting
1886  if ( !m_bHeaderOn && m_bFooterOn )
1887  nResId = bShareFooter ?
1888  RID_SCDLG_HFEDIT_RIGHTFOOTER :
1889  RID_SCDLG_HFEDIT_LEFTFOOTER;
1890  else if ( m_bHeaderOn && !m_bFooterOn )
1891  nResId = bShareHeader ?
1892  RID_SCDLG_HFEDIT_RIGHTHEADER :
1893  RID_SCDLG_HFEDIT_LEFTHEADER;
1894  }
1895  }
1896  break;
1897 
1898  case SvxPageUsage::Mirror:
1899  case SvxPageUsage::All:
1900  default:
1901  {
1902  if ( !bShareHeader && !bShareFooter )
1903  {
1904  if ( m_bHeaderOn && m_bFooterOn )
1905  nResId = RID_SCDLG_HFEDIT_ALL;
1906  else if ( !m_bHeaderOn && m_bFooterOn )
1907  nResId = RID_SCDLG_HFEDIT_FOOTER;
1908  else if ( m_bHeaderOn && !m_bFooterOn )
1909  nResId = RID_SCDLG_HFEDIT_HEADER;
1910  }
1911  else if ( bShareHeader && bShareFooter )
1912  {
1913  if ( m_bHeaderOn && m_bFooterOn )
1914  nResId = RID_SCDLG_HFEDIT;
1915  else
1916  {
1917  if ( !m_bHeaderOn && m_bFooterOn )
1918  nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1919  else if ( m_bHeaderOn && !m_bFooterOn )
1920  nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1921  }
1922  }
1923  else if ( !bShareHeader && bShareFooter )
1924  {
1925  if ( m_bHeaderOn && m_bFooterOn )
1926  nResId = RID_SCDLG_HFEDIT_SFTR;
1927  else if ( !m_bHeaderOn && m_bFooterOn )
1928  nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1929  else if ( m_bHeaderOn && !m_bFooterOn )
1930  nResId = RID_SCDLG_HFEDIT_HEADER;
1931  }
1932  else if ( bShareHeader && !bShareFooter )
1933  {
1934  if ( m_bHeaderOn && m_bFooterOn )
1935  nResId = RID_SCDLG_HFEDIT_SHDR;
1936  else if ( !m_bHeaderOn && m_bFooterOn )
1937  nResId = RID_SCDLG_HFEDIT_FOOTER;
1938  else if ( m_bHeaderOn && !m_bFooterOn )
1939  nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1940  }
1941  }
1942  }
1943 
1945 
1948  rStyleSet,
1949  aStr,
1950  nResId));
1951  auto xRequest = std::make_shared<SfxRequest>(rReq);
1952  rReq.Ignore(); // the 'old' request is not relevant any more
1953  pDlg->StartExecuteAsync([this, pDlg, pStyleSheet, xRequest](sal_Int32 nResult){
1954  if ( nResult == RET_OK )
1955  {
1956  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1957 
1958  if ( pOutSet )
1959  m_aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1960 
1962  xRequest->Done();
1963  }
1964  pDlg->disposeOnce();
1965  });
1966  }
1967  }
1968  }
1969  break;
1970 
1971  default:
1972  break;
1973  }
1974 }
1975 
1977  SCTAB nCurTab )
1978 {
1979  SfxWhichIter aIter(rSet);
1980  sal_uInt16 nWhich = aIter.FirstWhich();
1981  while ( nWhich )
1982  {
1983  switch (nWhich)
1984  {
1985  case SID_STATUS_PAGESTYLE:
1986  rSet.Put( SfxStringItem( nWhich, m_aDocument.GetPageStyle( nCurTab ) ) );
1987  break;
1988 
1989  case SID_HFEDIT:
1990  {
1991  OUString aStr = m_aDocument.GetPageStyle( nCurTab );
1993  SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStr, SfxStyleFamily::Page );
1994 
1995  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
1996 
1997  if ( pStyleSheet )
1998  {
1999  SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
2000  GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );
2001 
2002  if ( !m_bHeaderOn && !m_bFooterOn )
2003  rSet.DisableItem( nWhich );
2004  }
2005  }
2006  break;
2007  }
2008 
2009  nWhich = aIter.NextWhich();
2010  }
2011 }
2012 
2014 {
2015  bool bTabView = GetBestViewShell() != nullptr;
2016 
2017  SfxWhichIter aIter(rSet);
2018  for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
2019  {
2020  if (!bTabView)
2021  {
2022  rSet.DisableItem(nWhich);
2023  continue;
2024  }
2025 
2026  switch (nWhich)
2027  {
2028  case FID_AUTO_CALC:
2030  rSet.DisableItem( nWhich );
2031  else
2032  rSet.Put( SfxBoolItem( nWhich, m_aDocument.GetAutoCalc() ) );
2033  break;
2034 
2035  case FID_CHG_RECORD:
2036  if ( IsDocShared() )
2037  rSet.DisableItem( nWhich );
2038  else
2039  rSet.Put( SfxBoolItem( nWhich,
2040  m_aDocument.GetChangeTrack() != nullptr ) );
2041  break;
2042 
2043  case SID_CHG_PROTECT:
2044  {
2045  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
2046  if ( pChangeTrack && !IsDocShared() )
2047  rSet.Put( SfxBoolItem( nWhich,
2048  pChangeTrack->IsProtected() ) );
2049  else
2050  rSet.DisableItem( nWhich );
2051  }
2052  break;
2053 
2054  case SID_DOCUMENT_COMPARE:
2055  {
2056  if ( IsDocShared() )
2057  {
2058  rSet.DisableItem( nWhich );
2059  }
2060  }
2061  break;
2062 
2063  // When a formula is edited, FID_RECALC must be enabled in any case. Recalc for
2064  // the doc was disabled once because of a bug if AutoCalc was on, but is now
2065  // always enabled because of another bug.
2066 
2067  case SID_TABLES_COUNT:
2068  rSet.Put( SfxInt16Item( nWhich, m_aDocument.GetTableCount() ) );
2069  break;
2070 
2071  case SID_ATTR_YEAR2000 :
2072  rSet.Put( SfxUInt16Item( nWhich,
2074  break;
2075 
2076  case SID_SHARE_DOC:
2077  {
2078  if ( IsReadOnly() || GetObjectShell()->isExportLocked() )
2079  {
2080  rSet.DisableItem( nWhich );
2081  }
2082  }
2083  break;
2084 
2085  case SID_ATTR_CHAR_FONTLIST:
2086  rSet.Put( SvxFontListItem( m_pImpl->pFontList.get(), nWhich ) );
2087  break;
2088 
2089  case SID_NOTEBOOKBAR:
2090  {
2091  if (GetViewBindings())
2092  {
2094  u"modules/scalc/ui/");
2095  rSet.Put( SfxBoolItem( SID_NOTEBOOKBAR, bVisible ) );
2096  }
2097  }
2098  break;
2099 
2100  case SID_LANGUAGE_STATUS:
2101  {
2102  LanguageType eLatin, eCjk, eCtl;
2103 
2104  GetDocument().GetLanguage( eLatin, eCjk, eCtl );
2105  OUString sLanguage = SvtLanguageTable::GetLanguageString(eLatin);
2107  if (eLatin == LANGUAGE_NONE)
2108  sLanguage += ";-";
2109  else
2110  sLanguage += ";" + LanguageTag(eLatin).getBcp47(false);
2111  }
2112  rSet.Put(SfxStringItem(nWhich, sLanguage));
2113  }
2114  break;
2115 
2116  default:
2117  {
2118  }
2119  break;
2120  }
2121  }
2122 }
2123 
2124 void ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect )
2125 {
2126 
2127  SCTAB nVisTab = m_aDocument.GetVisibleTab();
2128  if (!m_aDocument.HasTable(nVisTab))
2129  return;
2130 
2131  ComplexTextLayoutFlags nOldLayoutMode = pDev->GetLayoutMode();
2132  pDev->SetLayoutMode( ComplexTextLayoutFlags::Default ); // even if it's the same, to get the metafile action
2133 
2134  if ( nAspect == ASPECT_THUMBNAIL )
2135  {
2137  ScViewData aTmpData( *this, nullptr );
2138  aTmpData.SetTabNo(nVisTab);
2139  SnapVisArea( aBoundRect );
2140  aTmpData.SetScreen( aBoundRect );
2141  ScPrintFunc::DrawToDev( m_aDocument, pDev, 1.0, aBoundRect, &aTmpData, true );
2142  }
2143  else
2144  {
2146  tools::Rectangle aNewArea = aOldArea;
2147  ScViewData aTmpData( *this, nullptr );
2148  aTmpData.SetTabNo(nVisTab);
2149  SnapVisArea( aNewArea );
2150  if ( aNewArea != aOldArea && (m_aDocument.GetPosLeft() > 0 || m_aDocument.GetPosTop() > 0) )
2151  SfxObjectShell::SetVisArea( aNewArea );
2152  aTmpData.SetScreen( aNewArea );
2153  ScPrintFunc::DrawToDev( m_aDocument, pDev, 1.0, aNewArea, &aTmpData, true );
2154  }
2155 
2156  pDev->SetLayoutMode( nOldLayoutMode );
2157 }
2158 
2159 tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
2160 {
2161  SfxObjectCreateMode eShellMode = GetCreateMode();
2162  if ( eShellMode == SfxObjectCreateMode::ORGANIZER )
2163  {
2164  // without contents we also don't know how large are the contents;
2165  // return empty rectangle, it will then be calculated after the loading
2166  return tools::Rectangle();
2167  }
2168 
2169  if( nAspect == ASPECT_THUMBNAIL )
2170  {
2171  SCTAB nVisTab = m_aDocument.GetVisibleTab();
2172  if (!m_aDocument.HasTable(nVisTab))
2173  {
2174  nVisTab = 0;
2175  const_cast<ScDocShell*>(this)->m_aDocument.SetVisibleTab(nVisTab);
2176  }
2177  Size aSize = m_aDocument.GetPageSize(nVisTab);
2178  const tools::Long SC_PREVIEW_SIZE_X = 10000;
2179  const tools::Long SC_PREVIEW_SIZE_Y = 12400;
2180  tools::Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X, SC_PREVIEW_SIZE_Y);
2181  if (aSize.Width() > aSize.Height())
2182  {
2183  aArea.SetRight( SC_PREVIEW_SIZE_Y );
2184  aArea.SetBottom( SC_PREVIEW_SIZE_X );
2185  }
2186 
2187  bool bNegativePage = m_aDocument.IsNegativePage( m_aDocument.GetVisibleTab() );
2188  if ( bNegativePage )
2189  ScDrawLayer::MirrorRectRTL( aArea );
2190  SnapVisArea( aArea );
2191  return aArea;
2192  }
2193  else if( nAspect == ASPECT_CONTENT && eShellMode != SfxObjectCreateMode::EMBEDDED )
2194  {
2195  // fetch visarea like after loading
2196 
2197  SCTAB nVisTab = m_aDocument.GetVisibleTab();
2198  if (!m_aDocument.HasTable(nVisTab))
2199  {
2200  nVisTab = 0;
2201  const_cast<ScDocShell*>(this)->m_aDocument.SetVisibleTab(nVisTab);
2202  }
2203  SCCOL nStartCol;
2204  SCROW nStartRow;
2205  m_aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
2206  SCCOL nEndCol;
2207  SCROW nEndRow;
2208  m_aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
2209  if (nStartCol>nEndCol)
2210  nStartCol = nEndCol;
2211  if (nStartRow>nEndRow)
2212  nStartRow = nEndRow;
2213  tools::Rectangle aNewArea = m_aDocument
2214  .GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
2215  return aNewArea;
2216  }
2217  else
2218  return SfxObjectShell::GetVisArea( nAspect );
2219 }
2220 
2221 namespace {
2222 
2223 [[nodiscard]]
2224 tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCCOL& rStartCol )
2225 {
2226  SCCOL nCol = 0;
2227  tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS);
2228  tools::Long nSnap = 0;
2229  while ( nCol<rDoc.MaxCol() )
2230  {
2231  tools::Long nAdd = rDoc.GetColWidth(nCol, nTab);
2232  if ( nSnap + nAdd/2 < nTwips || nCol < rStartCol )
2233  {
2234  nSnap += nAdd;
2235  ++nCol;
2236  }
2237  else
2238  break;
2239  }
2240  nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS );
2241  rStartCol = nCol;
2242  return nVal;
2243 }
2244 
2245 [[nodiscard]]
2246 tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCROW& rStartRow )
2247 {
2248  SCROW nRow = 0;
2249  tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS);
2250  tools::Long nSnap = 0;
2251 
2252  bool bFound = false;
2253  for (SCROW i = nRow; i <= rDoc.MaxRow(); ++i)
2254  {
2255  SCROW nLastRow;
2256  if (rDoc.RowHidden(i, nTab, nullptr, &nLastRow))
2257  {
2258  i = nLastRow;
2259  continue;
2260  }
2261 
2262  nRow = i;
2263  tools::Long nAdd = rDoc.GetRowHeight(i, nTab);
2264  if ( nSnap + nAdd/2 < nTwips || nRow < rStartRow )
2265  {
2266  nSnap += nAdd;
2267  ++nRow;
2268  }
2269  else
2270  {
2271  bFound = true;
2272  break;
2273  }
2274  }
2275  if (!bFound)
2276  nRow = rDoc.MaxRow(); // all hidden down to the bottom
2277 
2278  nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS );
2279  rStartRow = nRow;
2280  return nVal;
2281 }
2282 
2283 }
2284 
2286 {
2287  SCTAB nTab = m_aDocument.GetVisibleTab();
2288  tools::Long nOrigTop = rRect.Top();
2289  tools::Long nOrigLeft = rRect.Left();
2290  bool bNegativePage = m_aDocument.IsNegativePage( nTab );
2291  if ( bNegativePage )
2292  ScDrawLayer::MirrorRectRTL( rRect ); // calculate with positive (LTR) values
2293 
2294  SCCOL nCol = m_aDocument.GetPosLeft();
2295  tools::Long nSetLeft = SnapHorizontal( m_aDocument, nTab, rRect.Left(), nCol );
2296  rRect.SetLeft( nSetLeft );
2297  ++nCol; // at least one column
2298  tools::Long nCorrectionLeft = (nOrigLeft == 0 && nCol > 0) ? nSetLeft : 0; // initial correction
2299  rRect.SetRight( SnapHorizontal( m_aDocument, nTab, rRect.Right() + nCorrectionLeft, nCol ));
2300 
2301  SCROW nRow = m_aDocument.GetPosTop();
2302  tools::Long nSetTop = SnapVertical( m_aDocument, nTab, rRect.Top(), nRow );
2303  rRect.SetTop( nSetTop );
2304  ++nRow; // at least one row
2305  tools::Long nCorrectionTop = (nOrigTop == 0 && nRow > 0) ? nSetTop : 0; // initial correction
2306  rRect.SetBottom( SnapVertical( m_aDocument, nTab, rRect.Bottom() + nCorrectionTop, nRow ));
2307 
2308  if ( bNegativePage )
2309  ScDrawLayer::MirrorRectRTL( rRect ); // back to real rectangle
2310 }
2311 
2313  SCTAB nCurTab,
2314  bool& rbHeader,
2315  bool& rbFooter )
2316 {
2317  if ( !pStyleSet )
2318  {
2320  SfxStyleSheetBase* pStyleSheet = pStylePool->
2321  Find( m_aDocument.GetPageStyle( nCurTab ),
2322  SfxStyleFamily::Page );
2323 
2324  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
2325 
2326  if ( pStyleSheet )
2327  pStyleSet = &pStyleSheet->GetItemSet();
2328  else
2329  rbHeader = rbFooter = false;
2330  }
2331 
2332  OSL_ENSURE( pStyleSet, "PageStyle-Set not found! :-(" );
2333  if (!pStyleSet)
2334  return;
2335 
2336  const SvxSetItem* pSetItem = nullptr;
2337  const SfxItemSet* pSet = nullptr;
2338 
2339  pSetItem = &pStyleSet->Get( ATTR_PAGE_HEADERSET );
2340  pSet = &pSetItem->GetItemSet();
2341  rbHeader = pSet->Get(ATTR_PAGE_ON).GetValue();
2342 
2343  pSetItem = &pStyleSet->Get( ATTR_PAGE_FOOTERSET );
2344  pSet = &pSetItem->GetItemSet();
2345  rbFooter = pSet->Get(ATTR_PAGE_ON).GetValue();
2346 }
2347 
2348 #if defined(_WIN32)
2349 bool ScDocShell::DdeGetData( const OUString& rItem,
2350  const OUString& rMimeType,
2351  css::uno::Any & rValue )
2352 {
2354  if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId)
2355  {
2356  if( rItem.equalsIgnoreAsciiCase( "Format" ) )
2357  {
2358  OString aFmtByte(OUStringToOString(m_aDdeTextFmt,
2359  osl_getThreadTextEncoding()));
2360  rValue <<= css::uno::Sequence< sal_Int8 >(
2361  reinterpret_cast<const sal_Int8*>(aFmtByte.getStr()),
2362  aFmtByte.getLength() + 1 );
2363  return true;
2364  }
2365  ScImportExport aObj( m_aDocument, rItem );
2366  if ( !aObj.IsRef() )
2367  return false; // invalid range
2368 
2369  if( m_aDdeTextFmt[0] == 'F' )
2370  aObj.SetFormulas( true );
2371  if( m_aDdeTextFmt == "SYLK" ||
2372  m_aDdeTextFmt == "FSYLK" )
2373  {
2374  OString aData;
2375  if( aObj.ExportByteString( aData, osl_getThreadTextEncoding(),
2376  SotClipboardFormatId::SYLK ) )
2377  {
2378  rValue <<= css::uno::Sequence< sal_Int8 >(
2379  reinterpret_cast<const sal_Int8*>(aData.getStr()),
2380  aData.getLength() + 1 );
2381  return true;
2382  }
2383  else
2384  return false;
2385  }
2386  if( m_aDdeTextFmt == "CSV" ||
2387  m_aDdeTextFmt == "FCSV" )
2388  aObj.SetSeparator( ',' );
2389  aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2390  return aObj.ExportData( rMimeType, rValue );
2391  }
2392 
2393  ScImportExport aObj( m_aDocument, rItem );
2394  aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2395  return aObj.IsRef() && aObj.ExportData( rMimeType, rValue );
2396 }
2397 
2398 bool ScDocShell::DdeSetData( const OUString& rItem,
2399  const OUString& rMimeType,
2400  const css::uno::Any & rValue )
2401 {
2403  if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId)
2404  {
2405  if( rItem.equalsIgnoreAsciiCase( "Format" ) )
2406  {
2407  if ( ScByteSequenceToString::GetString( m_aDdeTextFmt, rValue, osl_getThreadTextEncoding() ) )
2408  {
2409  m_aDdeTextFmt = m_aDdeTextFmt.toAsciiUpperCase();
2410  return true;
2411  }
2412  return false;
2413  }
2414  ScImportExport aObj( m_aDocument, rItem );
2415  if( m_aDdeTextFmt[0] == 'F' )
2416  aObj.SetFormulas( true );
2417  if( m_aDdeTextFmt == "SYLK" ||
2418  m_aDdeTextFmt == "FSYLK" )
2419  {
2420  OUString aData;
2421  if ( ScByteSequenceToString::GetString( aData, rValue, osl_getThreadTextEncoding() ) )
2422  {
2423  return aObj.ImportString( aData, SotClipboardFormatId::SYLK );
2424  }
2425  return false;
2426  }
2427  if( m_aDdeTextFmt == "CSV" ||
2428  m_aDdeTextFmt == "FCSV" )
2429  aObj.SetSeparator( ',' );
2430  OSL_ENSURE( false, "Implementation is missing" );
2431  return false;
2432  }
2433  /*ScImportExport aObj( aDocument, rItem );
2434  return aObj.IsRef() && ScImportExport::ImportData( rMimeType, rValue );*/
2435  OSL_ENSURE( false, "Implementation is missing" );
2436  return false;
2437 }
2438 #endif
2439 
2441 {
2442  // only check for valid item string - range is parsed again in ScServerObject ctor
2443 
2444  // named range?
2445  OUString aPos = rItem;
2446  ScRangeName* pRange = m_aDocument.GetRangeName();
2447  if( pRange )
2448  {
2449  const ScRangeData* pData = pRange->findByUpperName(ScGlobal::getCharClassPtr()->uppercase(aPos));
2450  if (pData)
2451  {
2452  if( pData->HasType( ScRangeData::Type::RefArea )
2453  || pData->HasType( ScRangeData::Type::AbsArea )
2454  || pData->HasType( ScRangeData::Type::AbsPos ) )
2455  pData->GetSymbol( aPos ); // continue with the name's contents
2456  }
2457  }
2458 
2459  // Address in DDE function must be always parsed as CONV_OOO so that it
2460  // would always work regardless of current address conversion. We do this
2461  // because the address item in a DDE entry is *not* normalized when saved
2462  // into ODF.
2463  ScRange aRange;
2464  bool bValid = ( (aRange.Parse(aPos, m_aDocument, formula::FormulaGrammar::CONV_OOO ) & ScRefFlags::VALID) ||
2466 
2467  ScServerObject* pObj = nullptr; // NULL = error
2468  if ( bValid )
2469  pObj = new ScServerObject( this, rItem );
2470 
2471  // GetLinkManager()->InsertServer() is in the ScServerObject ctor
2472 
2473  return pObj;
2474 }
2475 
2477 {
2478  if ( !pDocument->IsDocVisible() || // don't want callbacks until document load
2481  return;
2482 
2483  boost::property_tree::ptree aAnnotation;
2484  aAnnotation.put("action", (nType == LOKCommentNotificationType::Add ? "Add" :
2485  (nType == LOKCommentNotificationType::Remove ? "Remove" :
2486  (nType == LOKCommentNotificationType::Modify ? "Modify" : "???"))));
2487 
2488  assert(pNote);
2489  aAnnotation.put("id", pNote->GetId());
2490  aAnnotation.put("tab", rPos.Tab());
2491 
2493  {
2494  aAnnotation.put("author", pNote->GetAuthor());
2495  aAnnotation.put("dateTime", pNote->GetDate());
2496  aAnnotation.put("text", pNote->GetText());
2497 
2498  // Calculating the cell cursor position
2499  ScViewData* pViewData = GetViewData();
2500  if (pViewData && pViewData->GetActiveWin())
2501  {
2502  bool bInPrintTwips = comphelper::LibreOfficeKit::isCompatFlagSet(
2503  comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
2504  OString aRectString;
2505  if (bInPrintTwips)
2506  {
2507  Point aTopLeft = pViewData->GetPrintTwipsPos(rPos.Col(), rPos.Row());
2508  tools::Long nSizeX, nSizeY;
2509  pViewData->GetMergeSizePrintTwips(rPos.Col(), rPos.Row(), nSizeX, nSizeY);
2510  aRectString = tools::Rectangle(aTopLeft, Size(nSizeX - 1, nSizeY - 1)).toString();
2511  }
2512  else
2513  {
2514  Point aTopLeft = pViewData->GetScrPos(rPos.Col(), rPos.Row(),
2515  pViewData->GetActivePart(), true);
2516  tools::Long nSizeXPix, nSizeYPix;
2517  pViewData->GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeXPix, nSizeYPix);
2518  const double fPPTX = pViewData->GetPPTX();
2519  const double fPPTY = pViewData->GetPPTY();
2520  aRectString = tools::Rectangle(Point(aTopLeft.getX() / fPPTX, aTopLeft.getY() / fPPTY),
2521  Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY)).toString();
2522  }
2523  aAnnotation.put("cellPos", aRectString);
2524  }
2525  }
2526 
2527  boost::property_tree::ptree aTree;
2528  aTree.add_child("comment", aAnnotation);
2529  std::stringstream aStream;
2530  boost::property_tree::write_json(aStream, aTree);
2531  std::string aPayload = aStream.str();
2532 
2533  ScViewData* pViewData = GetViewData();
2534  SfxViewShell* pThisViewShell = ( pViewData ? pViewData->GetViewShell() : nullptr );
2535  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
2536  while (pViewShell)
2537  {
2538  if (pThisViewShell == nullptr || pViewShell->GetDocId() == pThisViewShell->GetDocId())
2539  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
2540  pViewShell = SfxViewShell::GetNext(*pViewShell);
2541  }
2542 }
2543 
2545 {
2547  ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( pCur );
2548  return pViewSh ? &pViewSh->GetViewData() : nullptr;
2549 }
2550 
2552 {
2554 
2555  ScViewData* pViewData = GetViewData();
2556 
2557  return pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0);
2558 }
2559 
2561 {
2563  // wrong Doc?
2564  if( pViewSh && pViewSh->GetViewData().GetDocShell() != this )
2565  pViewSh = nullptr;
2566  if( !pViewSh )
2567  {
2568  // 1. find ViewShell
2569  SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, bOnlyVisible );
2570  if( pFrame )
2571  {
2572  SfxViewShell* p = pFrame->GetViewShell();
2573  pViewSh = dynamic_cast< ScTabViewShell *>( p );
2574  }
2575  }
2576  return pViewSh;
2577 }
2578 
2580 {
2581  // used to invalidate slots after changes to this document
2582 
2583  SfxViewShell* pViewSh = GetBestViewShell();
2584  if (pViewSh)
2585  return &pViewSh->GetViewFrame()->GetBindings();
2586  else
2587  return nullptr;
2588 }
2589 
2590 ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo ) // static
2591 {
2592  ScDocShell* pFound = nullptr;
2594  sal_uInt16 nShellCnt = 0;
2595 
2596  while ( pShell && !pFound )
2597  {
2598  if ( auto pDocSh = dynamic_cast<ScDocShell*>(pShell) )
2599  {
2600  if ( nShellCnt == nDocNo )
2601  pFound = pDocSh;
2602  else
2603  ++nShellCnt;
2604  }
2605  pShell = SfxObjectShell::GetNext( *pShell );
2606  }
2607 
2608  return pFound;
2609 }
2610 
2611 IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void )
2612 {
2613  OSL_ENSURE( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" );
2614  OSL_ENSURE( m_pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2615 
2616  if ( ERRCODE_NONE == _pFileDlg->GetError() )
2617  {
2618  sal_uInt16 nSlot = m_pImpl->pRequest->GetSlot();
2619  std::unique_ptr<SfxMedium> pMed = m_pImpl->pDocInserter->CreateMedium();
2620  // #i87094# If a .odt was selected pMed is NULL.
2621  if (pMed)
2622  {
2623  m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
2624  if ( SID_DOCUMENT_COMPARE == nSlot )
2625  {
2626  if ( pMed->GetFilter() )
2627  m_pImpl->pRequest->AppendItem(
2628  SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
2629  OUString sOptions = ScDocumentLoader::GetOptions( *pMed );
2630  if ( !sOptions.isEmpty() )
2631  m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2632  }
2633  const SfxPoolItem* pItem = nullptr;
2634  const SfxInt16Item* pInt16Item(nullptr);
2635  SfxItemSet* pSet = pMed->GetItemSet();
2636  if (pSet && pSet->GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET)
2637  {
2638  pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem);
2639  }
2640  if (pInt16Item)
2641  {
2642  m_pImpl->pRequest->AppendItem( *pItem );
2643  }
2644 
2645  Execute( *(m_pImpl->pRequest) );
2646  }
2647  }
2648 
2649  m_pImpl->bIgnoreLostRedliningWarning = false;
2650 }
2651 
2652 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
2653 
2654 void ScDocShell::EnableSharedSettings( bool bEnable )
2655 {
2657 
2658  if ( bEnable )
2659  {
2662 
2663  // hide accept or reject changes dialog
2664  sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
2665  SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2666  if ( pViewFrame && pViewFrame->HasChildWindow( nId ) )
2667  {
2668  pViewFrame->ToggleChildWindow( nId );
2669  SfxBindings* pBindings = GetViewBindings();
2670  if ( pBindings )
2671  {
2672  pBindings->Invalidate( FID_CHG_ACCEPT );
2673  }
2674  }
2675  }
2676  else
2677  {
2679  }
2680 
2681  ScChangeViewSettings aChangeViewSet;
2682  aChangeViewSet.SetShowChanges( false );
2683  m_aDocument.SetChangeViewSettings( aChangeViewSet );
2684 }
2685 
2686 uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
2687 {
2688  uno::Reference< frame::XModel > xModel;
2689  try
2690  {
2691  SC_MOD()->SetInSharedDocLoading( true );
2692  uno::Reference< frame::XDesktop2 > xLoader = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
2693  uno::Sequence < beans::PropertyValue > aArgs( 1 );
2694  aArgs[0].Name = "Hidden";
2695  aArgs[0].Value <<= true;
2696 
2697  if ( GetMedium() )
2698  {
2699  const SfxStringItem* pPasswordItem = SfxItemSet::GetItem<SfxStringItem>(GetMedium()->GetItemSet(), SID_PASSWORD, false);
2700  if ( pPasswordItem && !pPasswordItem->GetValue().isEmpty() )
2701  {
2702  aArgs.realloc( 2 );
2703  aArgs[1].Name = "Password";
2704  aArgs[1].Value <<= pPasswordItem->GetValue();
2705  }
2706  const SfxUnoAnyItem* pEncryptionItem = SfxItemSet::GetItem<SfxUnoAnyItem>(GetMedium()->GetItemSet(), SID_ENCRYPTIONDATA, false);
2707  if (pEncryptionItem)
2708  {
2709  aArgs.realloc(aArgs.getLength() + 1);
2710  aArgs[aArgs.getLength() - 1].Name = "EncryptionData";
2711  aArgs[aArgs.getLength() - 1].Value = pEncryptionItem->GetValue();
2712  }
2713  }
2714 
2715  xModel.set(
2716  xLoader->loadComponentFromURL( GetSharedFileURL(), "_blank", 0, aArgs ),
2717  uno::UNO_QUERY_THROW );
2718  SC_MOD()->SetInSharedDocLoading( false );
2719  }
2720  catch ( uno::Exception& )
2721  {
2722  OSL_FAIL( "ScDocShell::LoadSharedDocument(): caught exception" );
2723  SC_MOD()->SetInSharedDocLoading( false );
2724  try
2725  {
2726  uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
2727  xClose->close( true );
2728  return uno::Reference< frame::XModel >();
2729  }
2730  catch ( uno::Exception& )
2731  {
2732  return uno::Reference< frame::XModel >();
2733  }
2734  }
2735  return xModel;
2736 }
2737 
2738 #endif
2739 
2740 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1775
SC_DLLPUBLIC bool GetPrintArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bNotes=true) const
Definition: documen2.cxx:572
void SetEditHelpId(const OString &rId)
SfxViewFrame * GetViewFrame() const
bool GetValue() const
bool IsBlockEditable(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool *pOnlyNotBecauseOfMatrix=nullptr, bool bNoMatrixAtAll=false) const
Definition: document.cxx:5320
virtual void SetVisArea(const tools::Rectangle &rVisArea)
#define LANGUAGE_NONE
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
virtual void set_label(const OUString &rText)=0
const size_t count(pCandidateA->getBorderLines().size())
SfxHintId
void GetScaleData(Size &rPhysSize, tools::Long &rDocHdr, tools::Long &rDocFtr)
Definition: printfun.cxx:1101
SC_DLLPUBLIC void ApplyStyleAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScStyleSheet &rStyle)
Definition: document.cxx:4849
SC_DLLPUBLIC const ScRange * GetRepeatColRange(SCTAB nTab)
Definition: document.cxx:6280
SC_DLLPUBLIC bool HasQueryParam() const
Definition: dbdata.cxx:509
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:813
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScAddress aStart
Definition: address.hxx:500
void EndChangeTracking()
Definition: documen2.cxx:266
bool bVisible
SC_DLLPUBLIC bool GetDataStart(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow) const
Definition: documen2.cxx:640
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1889
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: docsh3.cxx:449
SfxChildWindow * GetChildWindow(sal_uInt16)
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
Definition: documen3.cxx:498
static SfxInterface * GetStaticInterface()
void ExecutePageStyle(const SfxViewShell &rCaller, SfxRequest &rReq, SCTAB nCurTab)
Definition: docsh4.cxx:1757
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:1000
virtual const FmFormShell * GetFormShell() const override
Definition: tabvwsh.hxx:335
SfxViewFrame * GetFrame() const
VclPtr< SfxInfoBarWindow > AppendInfoBar(const OUString &sId, const OUString &sPrimaryMessage, const OUString &sSecondaryMessage, InfobarType aInfobarType, bool bShowCloseButton=true)
SCROW Row() const
Definition: address.hxx:262
IMPL_LINK_NOARG(ScDocShell, ReloadAllLinksHdl, weld::Button &, void)
Definition: docsh4.cxx:142
static SfxAbstractDialogFactory * Create()
void PostPaintGridAll()
Definition: docsh3.cxx:180
ScLkUpdMode GetLinkMode() const
Definition: appoptio.hxx:68
#define PRINT_HEADER_WIDTH
Definition: printfun.hxx:45
SC_DLLPUBLIC void SetChangeViewSettings(const ScChangeViewSettings &rNew)
Definition: documen2.cxx:1108
bool HasSharedXMLFlagSet() const
static void GetSpellSettings(LanguageType &rDefLang, LanguageType &rCjkLang, LanguageType &rCtlLang, bool &rAutoSpell)
Definition: scmod.cxx:2176
const SfxItemSet & GetEmptyItemSet() const
std::unique_ptr< ContentProperties > pData
std::string GetValue
static weld::Window * GetActiveDialogParent()
Definition: docsh.cxx:2950
static void DrawToDev(ScDocument &rDoc, OutputDevice *pDev, double nPrintFactor, const tools::Rectangle &rBound, ScViewData *pViewData, bool bMetaFile)
Definition: printfun.cxx:446
SfxBindings * GetViewBindings()
Definition: docsh4.cxx:2579
virtual VclPtr< AbstractScColRowLabelDlg > CreateScColRowLabelDlg(weld::Window *pParent, bool bCol, bool bRow)=0
bool IsFormulaMode() const
Definition: inputhdl.hxx:262
signed char sal_Int8
void SetProtection(const css::uno::Sequence< sal_Int8 > &rPass)
Definition: chgtrack.hxx:1129
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1683
void PostPaintCell(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: docsh3.cxx:185
SC_DLLPUBLIC const ScFormulaCell * GetFormulaCell(const ScAddress &rPos) const
Definition: document.cxx:3721
ScScenarioFlags
Definition: global.hxx:238
bool IsInputMode() const
Definition: inputhdl.hxx:185
Point GetPrintTwipsPos(SCCOL nCol, SCROW nRow) const
returns the position (top-left corner) of the requested cell in print twips coordinates.
Definition: viewdata.cxx:2465
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:214
static void RemoveAppPrefix(OUString &rFilterName)
Definition: tablink.cxx:486
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALETOPAGES(175)
const OUString & GetName() const
sal_uIntPtr sal_uLong
long Long
void GetPageOnFromPageStyleSet(const SfxItemSet *pStyleSet, SCTAB nCurTab, bool &rbHeader, bool &rbFooter)
Definition: docsh4.cxx:2312
These options control how multi-line cells are converted during export in certain lossy formats (such...
Definition: impex.hxx:36
#define ZOOM_MIN
Definition: docsh4.cxx:1601
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:167
SAL_DLLPRIVATE css::uno::Reference< css::frame::XModel > LoadSharedDocument()
bool updateDdeOrOleOrWebServiceLinks(weld::Window *pWin)
void initializeFrom(const css::uno::Sequence< css::beans::PropertyValue > &_rValues)
const OUString & getBcp47(bool bResolveSystem=true) const
ViewShellDocId GetDocId() const override
ScDocShell(const ScDocShell &rDocShell)=delete
void RefreshPivotTables(const ScRange &rSource)
Definition: docsh5.cxx:472
void ModifyStyleSheet(SfxStyleSheetBase &rPageStyle, const SfxItemSet &rChanges)
Definition: documen8.cxx:208
void DeleteTable(SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2414
static SVL_DLLPUBLIC void GetHashPassword(css::uno::Sequence< sal_Int8 > &rPassHash, const char *pPass, sal_uInt32 nLen)
void SetDocumentModified()
Definition: docsh.cxx:2820
sal_Int16 nId
sal_uInt16 FirstWhich()
double GetPPTX() const
Definition: viewdata.hxx:468
void PostPaintExtras()
Definition: docsh3.cxx:195
ComplexTextLayoutFlags GetLayoutMode() const
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScStyleSheet * FindCaseIns(const OUString &rName, SfxStyleFamily eFam)
Definition: stlpool.cxx:412
bool ImportData(const ScImportParam &rParam)
Definition: dbfunc.cxx:432
void MergeDocument(ScDocument &rOtherDoc, bool bShared=false, bool bCheckDuplicates=false, sal_uLong nOffset=0, ScChangeActionMergeMap *pMergeMap=nullptr, bool bInverseMap=false)
Definition: docsh3.cxx:768
void SetLayoutMode(ComplexTextLayoutFlags nTextLayoutMode)
ScAddress aEnd
Definition: address.hxx:501
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
static void UpdateInputLine()
Definition: tabview3.cxx:3001
create "Importx" (if necessary)
Definition: global.hxx:396
void Done(bool bRemove=false)
virtual short run() override
virtual SfxItemSet & GetItemSet()
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
bool HasSubTotalParam() const
Definition: dbdata.cxx:527
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
ScDBData * GetDBData(const ScRange &rMarked, ScGetDBMode eMode, ScGetDBSelection eSel)
Definition: docsh5.cxx:114
sc::DocumentLinkManager & GetDocLinkManager()
Definition: documen2.cxx:224
bool ExecuteChangeProtectionDialog(bool bJustQueryIfProtected=false)
Protect/unprotect ChangeTrack and return if protection was successfully changed.
Definition: docsh4.cxx:1359
SfxStyleFamily GetFamily() const
virtual short Execute()=0
sal_uLong GetActionMax() const
Definition: chgtrack.hxx:961
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:488
void UpdateChartArea(const OUString &rChartName, const ScRange &rNewArea, bool bColHeaders, bool bRowHeaders, bool bAdd)
Definition: documen5.cxx:129
SfxHintId GetId() const
void SetRight(tools::Long v)
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4159
sal_uInt16 NextWhich()
virtual ::sfx2::SvLinkSource * DdeCreateLinkSource(const OUString &rItem) override
Definition: docsh4.cxx:2440
SfxApplication * SfxGetpApp()
OUString GetSharedFileURL() const
bool HasAnySheetEventScript(ScSheetEventId nEvent, bool bWithVbaEvents=false) const
Definition: documen3.cxx:690
void DoRecalc(bool bApi)
Definition: docsh4.cxx:1422
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2806
void ToggleChildWindow(sal_uInt16)
RET_NO
SfxStyleSheetBase * GetStyleSheet() const
Keep selection as is, expand to used data area if no selection.
bool AdjustPrintZoom(const ScRange &rRange)
Definition: docsh4.cxx:1636
void MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo)
SC_DLLPUBLIC ScConditionalFormatList * GetCondFormList(SCTAB nTab) const
Definition: documen4.cxx:857
bool ShowChanges() const
Definition: chgviset.hxx:78
RET_YES
void ReloadAllLinks()
Definition: docsh4.cxx:119
void SetImportParam(const ScImportParam &rImportParam)
Definition: dbdata.cxx:475
const OUString & GetName() const
PropertiesInfo aProperties
tools::Long Left() const
void SetLeft(tools::Long v)
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:870
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:312
Additional class containing cell annotation data.
Definition: postit.hxx:160
static void LOKCommentNotify(LOKCommentNotificationType nType, const ScDocument *pDocument, const ScAddress &rPos, const ScPostIt *pNote)
Definition: docsh4.cxx:2476
static LanguageType GetLanguageType(std::u16string_view rStr)
ScLkUpdMode
Definition: global.hxx:420
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
tools::Long Bottom() const
static SfxViewShell * Current()
bool isCompatFlagSet(Compat flag)
void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
Definition: document.cxx:258
SC_DLLPUBLIC bool IsDocVisible() const
Definition: document.hxx:1549
void UpdateCharts(bool bAllCharts)
Definition: dbfunc2.cxx:24
bool IsDocShared() const
const SfxPoolItem * ExecuteSynchron(sal_uInt16 nSlot, const SfxPoolItem **pArgs=nullptr)
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:189
bool DetectiveRefresh(bool bAutomatic=false)
Definition: docfunc.cxx:461
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:653
#define HMM_PER_TWIPS
Definition: global.hxx:93
SCTAB Tab() const
Definition: address.hxx:271
const css::uno::Any & GetValue() const
void Execute(SfxRequest &rReq)
Definition: docsh4.cxx:188
SotClipboardFormatId
void NotifyStyle(const SfxStyleSheetHint &rHint)
Definition: docsh4.cxx:1529
static SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
const OUString & GetName() const
static OUString GetOptions(const SfxMedium &rMedium)
Definition: tablink.cxx:422
sal_Int32 nEndPos
void SetTheActionRange(sal_uLong nFirst, sal_uLong nLast)
Definition: chgviset.hxx:127
constexpr TypedWhichId< SfxBoolItem > ATTR_PAGE_HEADERS(169)
SfxObjectCreateMode GetCreateMode() const
void PageStyleModified(SCTAB nTab, const OUString &rNewName)
Definition: document.cxx:6167
bool HasRowHeaders() const
Definition: chartpos.hxx:134
bool GetMergeSizePrintTwips(SCCOL nX, SCROW nY, tools::Long &rSizeXTwips, tools::Long &rSizeYTwips) const
Definition: viewdata.cxx:2678
ScViewData & GetViewData()
Definition: tabview.hxx:334
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2389
void UpdateSpellSettings(bool bFromStartTab=false)
Definition: inputhdl.cxx:900
void DoHardRecalc()
Definition: docsh4.cxx:1468
void SetDirty(bool bDirtyFlag=true)
static void SetError(ErrCode)
const css::uno::Sequence< sal_Int8 > & GetProtection() const
Definition: chgtrack.hxx:1131
SfxItemPool & GetPool() const
bool IsProtected() const
Definition: chgtrack.hxx:1133
bool empty() const
Definition: rangelst.hxx:89
constexpr OUStringLiteral aData
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1922
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
void InitFromStyle(const SfxStyleSheetBase *pSource)
Definition: undostyl.cxx:59
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2254
SC_DLLPUBLIC void SetVisibleTab(SCTAB nTab)
Definition: document.hxx:857
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: document.cxx:3361
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:679
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:869
void connect_clicked(const Link< Button &, void > &rLink)
void RepeatDB(bool bRecord=true)
Definition: dbfunc3.cxx:2113
bool UpdatePages()
Definition: printfun.cxx:2400
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
SvtScriptType
#define TOOLS_WARN_EXCEPTION(area, stream)
void DoAutoStyle(const ScRange &rRange, const OUString &rStyle)
Definition: docsh4.cxx:1506
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:325
virtual void Draw(OutputDevice *, const JobSetup &rSetup, sal_uInt16 nAspect) override
Definition: docsh4.cxx:2124
sal_Int16 GetValue() const
#define ERRCTX_SFX_OPENDOC
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
bool SwitchToShared(bool bShared, bool bSave)
SC_DLLPUBLIC void GetSymbol(OUString &rSymbol, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: rangenam.cxx:243
int i
SfxObjectCreateMode
Point GetScrPos(SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich, bool bAllowNeg=false, SCTAB nForTab=-1) const
Definition: viewdata.cxx:2313
constexpr TypedWhichId< SvxSetItem > ATTR_PAGE_FOOTERSET(182)
virtual SfxObjectShell * GetObjectShell() override
ComplexTextLayoutFlags
void SetAttribs(const SfxItemSet &rSet)
sal_Int16 SCCOL
Definition: types.hxx:22
bool ValidCol(SCCOL nCol) const
Definition: document.hxx:872
EditEngine * GetEditEngine() const
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
SC_DLLPUBLIC void SetAutoCalc(bool bNewAutoCalc)
Definition: documen7.cxx:601
#define SC_MOD()
Definition: scmod.hxx:250
bool HasSortParam() const
Definition: dbdata.cxx:520
void LimitChartArea(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow)
Definition: document.cxx:1113
SfxBindings & GetBindings()
SfxObjectShell * GetEmbeddedObject() const
Definition: docuno.cxx:453
void PageStyleModified(std::u16string_view rStyleName, bool bApi)
Definition: docsh4.cxx:1715
#define ERRCODE_BASIC_NO_OBJECT
virtual void Clear()
const OUString & GetValue() const
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1794
const T * GetArg(sal_uInt16 nSlotId) const
void ShowExtras(SfxShowExtras nExtras)
constexpr sal_uInt16 XATTR_FILL_FIRST(XATTRSET_LINE+1)
tools::Long Width() const
ScRefFlags Parse(const OUString &, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, SCTAB nDefaultTab=0, sal_Unicode cDelimiter=0)
Definition: rangelst.cxx:104
void ModifyScenario(SCTAB nTab, const OUString &rName, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: docsh5.cxx:754
void SetPrintZoom(SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages)
Definition: docsh4.cxx:1603
bool RenamePageStyleInUse(std::u16string_view rOld, const OUString &rNew)
Definition: documen8.cxx:339
void SetLinkFormulaNeedingCheck(bool bSet)
Definition: document.hxx:2121
float u
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
void SetYear2000(sal_uInt16 nVal)
Definition: docoptio.hxx:85
const OUString & GetName() const
Definition: dbdata.hxx:122
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:913
void GetImportParam(ScImportParam &rImportParam) const
Definition: dbdata.cxx:465
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3062
void AllowLinkUpdate()
Definition: docsh4.cxx:113
#define LANGUAGE_DONTKNOW
HardRecalcState GetHardRecalcState() const
Definition: document.hxx:2297
#define HID_CHG_PROTECT
Definition: helpids.h:52
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6179
void TrackFormulas(SfxHintId nHintId=SfxHintId::ScDataChanged)
Definition: documen7.cxx:526
SfxItemSet * GetItemSet() const
void BroadcastUno(const SfxHint &rHint)
Definition: documen3.cxx:943
virtual comphelper::EmbeddedObjectContainer & getEmbeddedObjectContainer() const override
static bool IsActive()
void SetTop(tools::Long v)
bool HasName() const
void SetBottom(tools::Long v)
void InsertText(const OUString &rNew, bool bSelect=false)
SC_DLLPUBLIC tools::Rectangle GetMMRect(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: documen3.cxx:1971
const XColorListRef & GetColorList() const
sal_Int16 m_nCanUpdate
Definition: docsh.hxx:99
#define ERRCODE_BASIC_NO_ACTIVE_OBJECT
sal_Int16 nVersion
OUString SpellIgnoreWord()
const tools::Rectangle & GetVisArea() const
const SCTAB MAXTAB
Definition: address.hxx:71
tools::Long Top() const
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
static ScViewData * GetViewData()
Definition: docsh4.cxx:2544
#define ASPECT_CONTENT
void ReloadTabLinks()
Definition: docsh6.cxx:387
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:98
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:300
SC_DLLPUBLIC bool ExtendMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, SCTAB nTab, bool bRefresh=false)
Definition: document.cxx:5561
bool HasType(Type nType) const
Definition: rangenam.hxx:177
bool IsStripData() const
Definition: dbdata.hxx:140
void GetStatePageStyle(SfxItemSet &rSet, SCTAB nCurTab)
Definition: docsh4.cxx:1976
void PostDataChanged()
Definition: docsh3.cxx:90
bool m_bFooterOn
Definition: docsh.hxx:90
SfxViewShell * GetViewShell() const
virtual VclPtr< AbstractScNewScenarioDlg > CreateScNewScenarioDlg(weld::Window *pParent, const OUString &rName, bool bEdit, bool bSheetProtected)=0
enumrange< T >::Iterator end(enumrange< T >)
SCCOL Col() const
Definition: address.hxx:267
bool IsReadOnly() const
bool IsShareDocumentChecked() const
Definition: sharedocdlg.cxx:91
void RemoveInfoBar(std::u16string_view sId)
size_t LeaveListAction()
ScDBData * findByUpperName(const OUString &rName)
Definition: dbdata.cxx:1144
void SetCalcNotification(SCTAB nTab)
Definition: documen3.cxx:715
ScDBFunc * GetView() const
Definition: viewdata.cxx:852
SvxPageUsage
void SetMinLen(sal_uInt16 Len)
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2590
ConversionMode mode
SC_DLLPUBLIC void GetScenarioData(SCTAB nTab, OUString &rComment, Color &rColor, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:462
void SetReturnValue(const SfxPoolItem &)
#define ERRCODE_BASIC_BAD_PARAMETER
bool isExportLocked() const
static bool StateMethod(SfxBindings &rBindings, std::u16string_view rUIFile, bool bReloadNotebookbar=false)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CTL(EE_CHAR_START+16)
static bool GetString(OUString &rString, const css::uno::Any &rAny, sal_uInt16 nEncoding)
Definition: rangeseq.cxx:432
Stores global named database ranges.
Definition: dbdata.hxx:235
SCCOL GetPosLeft() const
Definition: document.hxx:858
void SetShowAccepted(bool bVal)
Definition: chgviset.hxx:114
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:18
sal_uInt16 GetSlot() const
void UpdateExternalRefLinks(weld::Window *pWin)
Definition: documen8.cxx:788
double GetPPTY() const
Definition: viewdata.hxx:469
bool HasChildWindow(sal_uInt16)
virtual VclPtr< SfxAbstractTabDialog > CreateScStyleDlg(weld::Window *pParent, SfxStyleSheetBase &rStyleBase, bool bPage)=0
static SfxViewFrame * Current()
bool ValidRow(SCROW nRow) const
Definition: document.hxx:873
void SetStreamValid(SCTAB nTab, bool bSet, bool bIgnoreLock=false)
Definition: document.cxx:923
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1928
static ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1020
void DisableItem(sal_uInt16 nWhich)
weld::Window * GetFrameWeld() const
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:426
SC_DLLPUBLIC void CalcAll()
Definition: document.cxx:3931
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SC_DLLPUBLIC const ScRange * GetRepeatRowRange(SCTAB nTab)
Definition: document.cxx:6288
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
const ScAddress & GetCursorPos() const
Definition: inputhdl.hxx:193
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
#define PRINT_HEADER_HEIGHT
Definition: printfun.hxx:46
IMPL_LINK(ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper *, _pFileDlg, void)
Definition: docsh4.cxx:2611
static SotClipboardFormatId GetFormatIdFromMimeType(const OUString &rMimeType)
void CompareDocument(ScDocument &rOtherDoc)
Definition: docsh3.cxx:659
#define SAL_INFO(area, stream)
OUString aName
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
virtual VclPtr< SfxAbstractTabDialog > CreateScHFEditDlg(weld::Window *pParent, const SfxItemSet &rCoreSet, const OUString &rPageStyle, sal_uInt16 nResId)=0
virtual LockFileEntry GetLockData() override
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3040
RET_OK
ScChangeViewSettings * GetChangeViewSettings() const
Definition: document.hxx:2150
static void MirrorRectRTL(tools::Rectangle &rRect)
Definition: drwlayer.cxx:1991
bool m_bHeaderOn
Definition: docsh.hxx:89
void UpdateAcceptChangesDialog()
Definition: docsh4.cxx:1346
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, ScAddress::ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, const OUString *pErrRef=nullptr)
Definition: address.cxx:1742
sal_uInt32 GetId() const
Returns the note id.
Definition: postit.hxx:203
static void ExecMethod(SfxBindings &rBindings, const OUString &rUIName)
void InvalidateName()
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
tools::Long Height() const
OUString GetPassword() const
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
virtual short run()
LOKCommentNotificationType
Definition: docsh.hxx:72
static SC_DLLPUBLIC const CharClass * getCharClassPtr()
Definition: global.cxx:1009
std::unique_ptr< DocShell_Impl > m_pImpl
Definition: docsh.hxx:86
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:209
void * p
Reference< XComponentContext > getProcessComponentContext()
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2140
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
void SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl)
Definition: documen3.cxx:1955
constexpr TypedWhichId< SvxPageItem > ATTR_PAGE(159)
const ScDocument & GetDocument() const
Definition: docsh.hxx:217
void RenameCellStyle(std::u16string_view rOld, const OUString &rNew)
Definition: conditio.cxx:2159
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
sal_uInt16 GetYear2000() const
Definition: docoptio.hxx:86
bool GetMergeSizePixel(SCCOL nX, SCROW nY, tools::Long &rSizeXPix, tools::Long &rSizeYPix) const
Definition: viewdata.cxx:2641
bool HasImportSelection() const
Definition: dbdata.hxx:201
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6059
void ShowChildWindow(sal_uInt16, bool bVisible=true)
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
static OUString GetLanguageString(const LanguageType eType)
SC_DLLPUBLIC bool RowHidden(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: document.cxx:4427
void SetSelection(const ESelection &rNewSel)
void SetDocumentModified()
Definition: docsh.cxx:3159
ScDocument m_aDocument
Definition: docsh.hxx:81
void UpdateImport(const OUString &rTarget, const svx::ODataAccessDescriptor &rDescriptor)
Definition: dbdocfun.cxx:1668
static bool GetFilterName(const OUString &rFileName, OUString &rFilter, OUString &rOptions, bool bWithContent, bool bWithInteraction)
Returns the filter name and options from a file name.
Definition: tablink.cxx:432
static SVL_DLLPUBLIC bool CompareHashPassword(const css::uno::Sequence< sal_Int8 > &rOldPassHash, const OUString &sNewPass)
void Execute(SfxRequest &rReq)
Definition: tabvwsh3.cxx:164
bool hasListeners() const
Definition: chartlis.cxx:414
ScRange & front()
Definition: rangelst.hxx:93
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
void InvalidateAll(bool bWithMsg)
bool HasColHeaders() const
Definition: chartpos.hxx:133
void AppendItem(const SfxPoolItem &)
constexpr TypedWhichId< SvxSetItem > ATTR_PAGE_HEADERSET(181)
OUString m_aDdeTextFmt
Definition: docsh.hxx:83
bool IsUndoEnabled() const
Definition: document.hxx:1528
Reference< XModel > xModel
static SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLBACKGROUND)
ESelection GetSelection() const
bool IsAPI() const
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
Definition: address.cxx:1548
Size GetPageSize(SCTAB nTab) const
Definition: document.cxx:6193
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:219
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
Definition: docsh4.cxx:2560
void UpdateAreaLinks()
Definition: documen8.cxx:1048
void FormulaPreview()
Definition: inputhdl.cxx:1773
bool DoLoad(SfxMedium *pMedium)
void StartChangeTracking()
Definition: documen2.cxx:260
void SetScreen(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: viewdata.cxx:2933
constexpr TypedWhichId< SfxBoolItem > ATTR_PAGE_ON(164)
SC_DLLPUBLIC void GetLanguage(LanguageType &rLatin, LanguageType &rCjk, LanguageType &rCtl) const
Definition: documen3.cxx:1948
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALE(174)
void UpdateLayerLocks()
Definition: tabview5.cxx:346
SCTAB GetVisibleTab() const
Definition: document.hxx:856
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4118
rtl::OString toString() const
SAL_DLLPRIVATE void EnableSharedSettings(bool bEnable)
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
void Ignore()
static SCTAB GetCurTab()
Definition: docsh4.cxx:2551
void SnapVisArea(tools::Rectangle &rRect) const
Definition: docsh4.cxx:2285
#define EE_TEXTPOS_ALL
SCROW GetPosTop() const
Definition: document.hxx:860
ScLkUpdMode GetLinkUpdateModeState() const
Definition: docsh4.cxx:153
void SetY2KState(sal_uInt16 n)
aStr
bool ValidTab(SCTAB nTab)
Definition: address.hxx:105
#define ASPECT_THUMBNAIL
weld::Window * GetDialogParent()
parent window for dialogs Problem: OLE Server!
Definition: tabvwshd.cxx:31
tools::Long Right() const
bool HasImportParam() const
Definition: dbdata.cxx:504
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:452
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2219
constexpr TypedWhichId< SfxBoolItem > ATTR_PAGE_SHARED(166)
sal_uInt16 nPos
static void CloseMethod(SfxBindings &rBindings)
sal_Int16 SCTAB
Definition: types.hxx:23
void GetState(SfxItemSet &rSet)
Definition: docsh4.cxx:2013
OUString toString(OptionInfo const *info)
SC_DLLPUBLIC bool GetAutoCalc() const
Definition: document.hxx:1357
sal_Int32 nStartPos
void SetShowChanges(bool bFlag)
Definition: chgviset.hxx:79
SfxMedium * GetMedium() const