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
172  GetMedium() == nullptr ? OUString() : GetMedium()->GetName())
173  || (IsDocShared()
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 = 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 = 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  static const OUStringLiteral aSelectionLangPrefix(u"Current_");
1174  static const OUStringLiteral aParagraphLangPrefix(u"Paragraph_");
1175  static const OUStringLiteral aDocLangPrefix(u"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  static const OUStringLiteral sSpellingRule(u"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  case SID_REFRESH_VIEW:
1333  {
1334  PostPaintGridAll();
1335  }
1336  break;
1337  default:
1338  {
1339  // small (?) hack -> forwarding of the slots to TabViewShell
1341  if ( pSh )
1342  pSh->Execute( rReq );
1343 #if HAVE_FEATURE_SCRIPTING
1344  else
1346 #endif
1347  }
1348  }
1349 }
1350 
1352 {
1353  // update "accept changes" dialog
1355  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1356  if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) )
1357  {
1358  SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT );
1359  if ( pChild )
1360  static_cast<ScAcceptChgDlgWrapper*>(pChild)->ReInitDlg();
1361  }
1362 }
1363 
1364 bool ScDocShell::ExecuteChangeProtectionDialog( bool bJustQueryIfProtected )
1365 {
1366  bool bDone = false;
1367  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
1368  if ( pChangeTrack )
1369  {
1370  bool bProtected = pChangeTrack->IsProtected();
1371  if ( bJustQueryIfProtected && !bProtected )
1372  return true;
1373 
1374  OUString aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) );
1375  OUString aText( ScResId( SCSTR_PASSWORD ) );
1376  OUString aPassword;
1377 
1379  SfxPasswordDialog aDlg(pWin, &aText);
1380  aDlg.set_title(aTitle);
1381  aDlg.SetMinLen(1);
1382  aDlg.set_help_id(GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand());
1384  if ( !bProtected )
1385  aDlg.ShowExtras(SfxShowExtras::CONFIRM);
1386  if (aDlg.run() == RET_OK)
1387  aPassword = aDlg.GetPassword();
1388 
1389  if (!aPassword.isEmpty())
1390  {
1391  if ( bProtected )
1392  {
1393  if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) )
1394  {
1395  if ( bJustQueryIfProtected )
1396  bDone = true;
1397  else
1398  pChangeTrack->SetProtection( {} );
1399  }
1400  else
1401  {
1402  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin,
1403  VclMessageType::Info, VclButtonsType::Ok,
1404  ScResId(SCSTR_WRONGPASSWORD)));
1405  xInfoBox->run();
1406  }
1407  }
1408  else
1409  {
1410  css::uno::Sequence< sal_Int8 > aPass;
1411  SvPasswordHelper::GetHashPassword( aPass, aPassword );
1412  pChangeTrack->SetProtection( aPass );
1413  }
1414  if ( bProtected != pChangeTrack->IsProtected() )
1415  {
1417  bDone = true;
1418  }
1419  }
1420  }
1421  else if ( bJustQueryIfProtected )
1422  bDone = true;
1423  return bDone;
1424 }
1425 
1426 void ScDocShell::DoRecalc( bool bApi )
1427 {
1429  {
1430  SAL_WARN("sc","ScDocShell::DoRecalc tries re-entering while in Recalc; probably Forms->BASIC->Dispatcher.");
1431  return;
1432  }
1434  bool bDone = false;
1436  ScInputHandler* pHdl = ( pSh ? SC_MOD()->GetInputHdl( pSh ) : nullptr );
1437  if ( pSh )
1438  {
1439  if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi )
1440  {
1441  pHdl->FormulaPreview(); // partial result as QuickHelp
1442  bDone = true;
1443  }
1444  else
1445  {
1446  ScTabView::UpdateInputLine(); // InputEnterHandler
1447  pSh->UpdateInputHandler();
1448  }
1449  }
1450  if (bDone) // otherwise re-calculate document
1451  return;
1452 
1454  if ( pHdl )
1455  {
1456  // tdf97897 set current cell to Dirty to force recalculation of cell
1458  if (pFC)
1459  pFC->SetDirty();
1460  }
1462  if ( pSh )
1463  pSh->UpdateCharts(true);
1464 
1465  m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
1466 
1467  // If there are charts, then paint everything, so that PostDataChanged
1468  // and the charts do not come one after the other and parts are painted twice.
1469 
1471  if ( pCharts && pCharts->hasListeners() )
1472  PostPaintGridAll();
1473  else
1474  PostDataChanged();
1475 }
1476 
1478 {
1480  {
1481  SAL_WARN("sc","ScDocShell::DoHardRecalc tries re-entering while in Recalc; probably Forms->BASIC->Dispatcher.");
1482  return;
1483  }
1484  auto start = std::chrono::steady_clock::now();
1488  if ( pSh )
1489  {
1490  ScTabView::UpdateInputLine(); // InputEnterHandler
1491  pSh->UpdateInputHandler();
1492  }
1493  m_aDocument.CalcAll();
1494  GetDocFunc().DetectiveRefresh(); // creates own Undo
1495  if ( pSh )
1496  pSh->UpdateCharts(true);
1497 
1498  // set notification flags for "calculate" event (used in SfxHintId::DataChanged broadcast)
1499  // (might check for the presence of any formulas on each sheet)
1500  SCTAB nTabCount = m_aDocument.GetTableCount();
1501  if (m_aDocument.HasAnySheetEventScript( ScSheetEventId::CALCULATE, true )) // search also for VBA handler
1502  for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1504 
1505  // CalcAll doesn't broadcast value changes, so SfxHintId::ScCalcAll is broadcasted globally
1506  // in addition to SfxHintId::DataChanged.
1507  m_aDocument.BroadcastUno( SfxHint( SfxHintId::ScCalcAll ) );
1508  m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
1509 
1510  // use hard recalc also to disable stream-copying of all sheets
1511  // (somewhat consistent with charts)
1512  for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1513  m_aDocument.SetStreamValid(nTab, false);
1514 
1515  PostPaintGridAll();
1516  auto end = std::chrono::steady_clock::now();
1517  SAL_INFO("sc.timing", "ScDocShell::DoHardRecalc(): took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms");
1518 }
1519 
1520 void ScDocShell::DoAutoStyle( const ScRange& rRange, const OUString& rStyle )
1521 {
1523  ScStyleSheet* pStyleSheet =
1524  pStylePool->FindCaseIns( rStyle, SfxStyleFamily::Para );
1525  if (!pStyleSheet)
1526  pStyleSheet = static_cast<ScStyleSheet*>(
1527  pStylePool->Find( ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Para ));
1528  if (!pStyleSheet)
1529  return;
1530 
1531  OSL_ENSURE(rRange.aStart.Tab() == rRange.aEnd.Tab(),
1532  "DoAutoStyle with several tables");
1533  SCTAB nTab = rRange.aStart.Tab();
1534  SCCOL nStartCol = rRange.aStart.Col();
1535  SCROW nStartRow = rRange.aStart.Row();
1536  SCCOL nEndCol = rRange.aEnd.Col();
1537  SCROW nEndRow = rRange.aEnd.Row();
1538  m_aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
1539  m_aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
1540  PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PaintPartFlags::Grid );
1541 }
1542 
1544 {
1545  SfxHintId nId = rHint.GetId();
1546  const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet();
1547  if (!pStyle)
1548  return;
1549 
1550  if ( pStyle->GetFamily() == SfxStyleFamily::Page )
1551  {
1552  if ( nId == SfxHintId::StyleSheetModified )
1553  {
1554  ScDocShellModificator aModificator( *this );
1555 
1556  const OUString& aNewName = pStyle->GetName();
1557  OUString aOldName = aNewName;
1558  const SfxStyleSheetModifiedHint* pExtendedHint = dynamic_cast<const SfxStyleSheetModifiedHint*>(&rHint); // name changed?
1559  if (pExtendedHint)
1560  aOldName = pExtendedHint->GetOldName();
1561 
1562  if ( aNewName != aOldName )
1563  m_aDocument.RenamePageStyleInUse( aOldName, aNewName );
1564 
1565  SCTAB nTabCount = m_aDocument.GetTableCount();
1566  for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1567  if (m_aDocument.GetPageStyle(nTab) == aNewName) // already adjusted to new
1568  {
1569  m_aDocument.PageStyleModified( nTab, aNewName );
1570  ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1571  aPrintFunc.UpdatePages();
1572  }
1573 
1574  aModificator.SetDocumentModified();
1575 
1576  if (pExtendedHint)
1577  {
1578  SfxBindings* pBindings = GetViewBindings();
1579  if (pBindings)
1580  {
1581  pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1582  pBindings->Invalidate( SID_STYLE_FAMILY4 );
1583  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1584  pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1585  pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1586  }
1587  }
1588  }
1589  }
1590  else if ( pStyle->GetFamily() == SfxStyleFamily::Para )
1591  {
1592  if ( nId == SfxHintId::StyleSheetModified)
1593  {
1594  const OUString& aNewName = pStyle->GetName();
1595  OUString aOldName = aNewName;
1596  const SfxStyleSheetModifiedHint* pExtendedHint = dynamic_cast<const SfxStyleSheetModifiedHint*>(&rHint);
1597  if (pExtendedHint)
1598  aOldName = pExtendedHint->GetOldName();
1599  if ( aNewName != aOldName )
1600  {
1601  for(SCTAB i = 0; i < m_aDocument.GetTableCount(); ++i)
1602  {
1604  if (pList)
1605  pList->RenameCellStyle( aOldName,aNewName );
1606  }
1607  }
1608  }
1609  }
1610 
1611  // everything else goes via slots...
1612 }
1613 
1614 // like in printfun.cxx
1615 #define ZOOM_MIN 10
1616 
1617 void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages )
1618 {
1619  OUString aStyleName = m_aDocument.GetPageStyle( nTab );
1621  SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
1622  OSL_ENSURE( pStyleSheet, "PageStyle not found" );
1623  if ( !pStyleSheet )
1624  return;
1625 
1626  ScDocShellModificator aModificator( *this );
1627 
1628  SfxItemSet& rSet = pStyleSheet->GetItemSet();
1629  const bool bUndo(m_aDocument.IsUndoEnabled());
1630  if (bUndo)
1631  {
1632  sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
1633  sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
1634  GetUndoManager()->AddUndoAction( std::make_unique<ScUndoPrintZoom>(
1635  this, nTab, nOldScale, nOldPages, nScale, nPages ) );
1636  }
1637 
1638  rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
1639  rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
1640 
1641  ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1642  aPrintFunc.UpdatePages();
1643  aModificator.SetDocumentModified();
1644 
1645  SfxBindings* pBindings = GetViewBindings();
1646  if (pBindings)
1647  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1648 }
1649 
1651 {
1652  bool bChange = false;
1653  SCTAB nTab = rRange.aStart.Tab();
1654 
1655  OUString aStyleName = m_aDocument.GetPageStyle( nTab );
1657  SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
1658  OSL_ENSURE( pStyleSheet, "PageStyle not found" );
1659  if ( pStyleSheet )
1660  {
1661  SfxItemSet& rSet = pStyleSheet->GetItemSet();
1662  bool bHeaders = rSet.Get(ATTR_PAGE_HEADERS).GetValue();
1663  sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
1664  sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
1665  const ScRange* pRepeatCol = m_aDocument.GetRepeatColRange( nTab );
1666  const ScRange* pRepeatRow = m_aDocument.GetRepeatRowRange( nTab );
1667 
1668  // calculate needed scaling for selection
1669 
1670  sal_uInt16 nNewScale = nOldScale;
1671 
1672  tools::Long nBlkTwipsX = 0;
1673  if (bHeaders)
1674  nBlkTwipsX += tools::Long(PRINT_HEADER_WIDTH);
1675  SCCOL nStartCol = rRange.aStart.Col();
1676  SCCOL nEndCol = rRange.aEnd.Col();
1677  if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
1678  {
1679  for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ )
1680  nBlkTwipsX += m_aDocument.GetColWidth( i, nTab );
1681  if ( nStartCol <= pRepeatCol->aEnd.Col() )
1682  nStartCol = pRepeatCol->aEnd.Col() + 1;
1683  }
1684  // legacy compilers' own scope for i
1685  {
1686  for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
1687  nBlkTwipsX += m_aDocument.GetColWidth( i, nTab );
1688  }
1689 
1690  tools::Long nBlkTwipsY = 0;
1691  if (bHeaders)
1692  nBlkTwipsY += tools::Long(PRINT_HEADER_HEIGHT);
1693  SCROW nStartRow = rRange.aStart.Row();
1694  SCROW nEndRow = rRange.aEnd.Row();
1695  if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
1696  {
1697  nBlkTwipsY += m_aDocument.GetRowHeight( pRepeatRow->aStart.Row(),
1698  pRepeatRow->aEnd.Row(), nTab );
1699  if ( nStartRow <= pRepeatRow->aEnd.Row() )
1700  nStartRow = pRepeatRow->aEnd.Row() + 1;
1701  }
1702  nBlkTwipsY += m_aDocument.GetRowHeight( nStartRow, nEndRow, nTab );
1703 
1704  Size aPhysPage;
1705  tools::Long nHdr, nFtr;
1706  ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab );
1707  aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
1708  nBlkTwipsY += nHdr + nFtr;
1709 
1710  if ( nBlkTwipsX == 0 ) // hidden columns/rows may lead to 0
1711  nBlkTwipsX = 1;
1712  if ( nBlkTwipsY == 0 )
1713  nBlkTwipsY = 1;
1714 
1715  tools::Long nNeeded = std::min( aPhysPage.Width() * 100 / nBlkTwipsX,
1716  aPhysPage.Height() * 100 / nBlkTwipsY );
1717  if ( nNeeded < ZOOM_MIN )
1718  nNeeded = ZOOM_MIN; // boundary
1719  if ( nNeeded < static_cast<tools::Long>(nNewScale) )
1720  nNewScale = static_cast<sal_uInt16>(nNeeded);
1721 
1722  bChange = ( nNewScale != nOldScale || nOldPages != 0 );
1723  if ( bChange )
1724  SetPrintZoom( nTab, nNewScale, 0 );
1725  }
1726  return bChange;
1727 }
1728 
1729 void ScDocShell::PageStyleModified( std::u16string_view rStyleName, bool bApi )
1730 {
1731  ScDocShellModificator aModificator( *this );
1732 
1733  SCTAB nTabCount = m_aDocument.GetTableCount();
1734  SCTAB nUseTab = MAXTAB+1;
1735  for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
1736  if ( m_aDocument.GetPageStyle(nTab) == rStyleName &&
1737  ( !bApi || m_aDocument.GetPageSize(nTab).Width() ) )
1738  nUseTab = nTab;
1739  // at bApi only if breaks already shown
1740 
1741  if (ValidTab(nUseTab)) // not used -> nothing to do
1742  {
1743  bool bWarn = false;
1744 
1745  ScPrintFunc aPrintFunc( this, GetPrinter(), nUseTab );
1746  if (!aPrintFunc.UpdatePages()) // sets breaks on all tabs
1747  bWarn = true;
1748 
1749  if (bWarn && !bApi)
1750  {
1752  weld::WaitObject aWaitOff(pWin);
1753  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin,
1754  VclMessageType::Info, VclButtonsType::Ok,
1755  ScResId(STR_PRINT_INVALID_AREA)));
1756  xInfoBox->run();
1757  }
1758  }
1759 
1760  aModificator.SetDocumentModified();
1761 
1762  SfxBindings* pBindings = GetViewBindings();
1763  if (pBindings)
1764  {
1765  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1766  pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1767  pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1768  }
1769 }
1770 
1772  SfxRequest& rReq,
1773  SCTAB nCurTab )
1774 {
1775  const SfxItemSet* pReqArgs = rReq.GetArgs();
1776 
1777  switch ( rReq.GetSlot() )
1778  {
1779  case SID_STATUS_PAGESTYLE: // click on StatusBar control
1780  case SID_FORMATPAGE:
1781  {
1782  if ( pReqArgs == nullptr )
1783  {
1784  OUString aOldName = m_aDocument.GetPageStyle( nCurTab );
1786  SfxStyleSheetBase* pStyleSheet
1787  = pStylePool->Find( aOldName, SfxStyleFamily::Page );
1788 
1789  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
1790 
1791  if ( pStyleSheet )
1792  {
1793  ScStyleSaveData aOldData;
1794  const bool bUndo(m_aDocument.IsUndoEnabled());
1795  if (bUndo)
1796  aOldData.InitFromStyle( pStyleSheet );
1797 
1798  SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1800 
1802 
1803  VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScStyleDlg(GetActiveDialogParent(), *pStyleSheet, true));
1804 
1805  auto pRequest = std::make_shared<SfxRequest>(rReq);
1806  rReq.Ignore(); // the 'old' request is not relevant any more
1807  pDlg->StartExecuteAsync([this, pDlg, pRequest, pStyleSheet, aOldData, aOldName, &rStyleSet, nCurTab, &rCaller, bUndo](sal_Int32 nResult){
1808  if ( nResult == RET_OK )
1809  {
1810  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1811 
1813 
1814  OUString aNewName = pStyleSheet->GetName();
1815  if ( aNewName != aOldName &&
1816  m_aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
1817  {
1818  SfxBindings* pBindings = GetViewBindings();
1819  if (pBindings)
1820  {
1821  pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1822  pBindings->Invalidate( FID_RESET_PRINTZOOM );
1823  }
1824  }
1825 
1826  if ( pOutSet )
1827  m_aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1828 
1829  // memorizing for GetState():
1830  GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );
1831  rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT );
1832 
1833  ScStyleSaveData aNewData;
1834  aNewData.InitFromStyle( pStyleSheet );
1835  if (bUndo)
1836  {
1838  std::make_unique<ScUndoModifyStyle>( this, SfxStyleFamily::Page,
1839  aOldData, aNewData ) );
1840  }
1841 
1842  PageStyleModified( aNewName, false );
1843  pRequest->Done();
1844  }
1845  pDlg->disposeOnce();
1846  });
1847  }
1848  }
1849  }
1850  break;
1851 
1852  case SID_HFEDIT:
1853  {
1854  if ( pReqArgs == nullptr )
1855  {
1856  OUString aStr( m_aDocument.GetPageStyle( nCurTab ) );
1857 
1858  ScStyleSheetPool* pStylePool
1860 
1861  SfxStyleSheetBase* pStyleSheet
1862  = pStylePool->Find( aStr, SfxStyleFamily::Page );
1863 
1864  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
1865 
1866  if ( pStyleSheet )
1867  {
1868  SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1869 
1870  SvxPageUsage eUsage = rStyleSet.Get( ATTR_PAGE ).GetPageUsage();
1871  bool bShareHeader = rStyleSet
1873  .GetItemSet()
1874  .Get(ATTR_PAGE_SHARED)
1875  .GetValue();
1876  bool bShareFooter = rStyleSet
1878  .GetItemSet()
1879  .Get(ATTR_PAGE_SHARED)
1880  .GetValue();
1881  sal_uInt16 nResId = 0;
1882 
1883  switch ( eUsage )
1884  {
1885  case SvxPageUsage::Left:
1886  case SvxPageUsage::Right:
1887  {
1888  if ( m_bHeaderOn && m_bFooterOn )
1889  nResId = RID_SCDLG_HFEDIT;
1890  else if ( SvxPageUsage::Right == eUsage )
1891  {
1892  if ( !m_bHeaderOn && m_bFooterOn )
1893  nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1894  else if ( m_bHeaderOn && !m_bFooterOn )
1895  nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1896  }
1897  else
1898  {
1899  // #69193a# respect "shared" setting
1900  if ( !m_bHeaderOn && m_bFooterOn )
1901  nResId = bShareFooter ?
1902  RID_SCDLG_HFEDIT_RIGHTFOOTER :
1903  RID_SCDLG_HFEDIT_LEFTFOOTER;
1904  else if ( m_bHeaderOn && !m_bFooterOn )
1905  nResId = bShareHeader ?
1906  RID_SCDLG_HFEDIT_RIGHTHEADER :
1907  RID_SCDLG_HFEDIT_LEFTHEADER;
1908  }
1909  }
1910  break;
1911 
1912  case SvxPageUsage::Mirror:
1913  case SvxPageUsage::All:
1914  default:
1915  {
1916  if ( !bShareHeader && !bShareFooter )
1917  {
1918  if ( m_bHeaderOn && m_bFooterOn )
1919  nResId = RID_SCDLG_HFEDIT_ALL;
1920  else if ( !m_bHeaderOn && m_bFooterOn )
1921  nResId = RID_SCDLG_HFEDIT_FOOTER;
1922  else if ( m_bHeaderOn && !m_bFooterOn )
1923  nResId = RID_SCDLG_HFEDIT_HEADER;
1924  }
1925  else if ( bShareHeader && bShareFooter )
1926  {
1927  if ( m_bHeaderOn && m_bFooterOn )
1928  nResId = RID_SCDLG_HFEDIT;
1929  else
1930  {
1931  if ( !m_bHeaderOn && m_bFooterOn )
1932  nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1933  else if ( m_bHeaderOn && !m_bFooterOn )
1934  nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1935  }
1936  }
1937  else if ( !bShareHeader && bShareFooter )
1938  {
1939  if ( m_bHeaderOn && m_bFooterOn )
1940  nResId = RID_SCDLG_HFEDIT_SFTR;
1941  else if ( !m_bHeaderOn && m_bFooterOn )
1942  nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1943  else if ( m_bHeaderOn && !m_bFooterOn )
1944  nResId = RID_SCDLG_HFEDIT_HEADER;
1945  }
1946  else if ( bShareHeader && !bShareFooter )
1947  {
1948  if ( m_bHeaderOn && m_bFooterOn )
1949  nResId = RID_SCDLG_HFEDIT_SHDR;
1950  else if ( !m_bHeaderOn && m_bFooterOn )
1951  nResId = RID_SCDLG_HFEDIT_FOOTER;
1952  else if ( m_bHeaderOn && !m_bFooterOn )
1953  nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1954  }
1955  }
1956  }
1957 
1959 
1962  rStyleSet,
1963  aStr,
1964  nResId));
1965  auto xRequest = std::make_shared<SfxRequest>(rReq);
1966  rReq.Ignore(); // the 'old' request is not relevant any more
1967  pDlg->StartExecuteAsync([this, pDlg, pStyleSheet, xRequest](sal_Int32 nResult){
1968  if ( nResult == RET_OK )
1969  {
1970  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1971 
1972  if ( pOutSet )
1973  m_aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1974 
1976  xRequest->Done();
1977  }
1978  pDlg->disposeOnce();
1979  });
1980  }
1981  }
1982  }
1983  break;
1984 
1985  default:
1986  break;
1987  }
1988 }
1989 
1991  SCTAB nCurTab )
1992 {
1993  SfxWhichIter aIter(rSet);
1994  sal_uInt16 nWhich = aIter.FirstWhich();
1995  while ( nWhich )
1996  {
1997  switch (nWhich)
1998  {
1999  case SID_STATUS_PAGESTYLE:
2000  rSet.Put( SfxStringItem( nWhich, m_aDocument.GetPageStyle( nCurTab ) ) );
2001  break;
2002 
2003  case SID_HFEDIT:
2004  {
2005  OUString aStr = m_aDocument.GetPageStyle( nCurTab );
2007  SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStr, SfxStyleFamily::Page );
2008 
2009  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
2010 
2011  if ( pStyleSheet )
2012  {
2013  SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
2014  GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );
2015 
2016  if ( !m_bHeaderOn && !m_bFooterOn )
2017  rSet.DisableItem( nWhich );
2018  }
2019  }
2020  break;
2021  }
2022 
2023  nWhich = aIter.NextWhich();
2024  }
2025 }
2026 
2028 {
2029  bool bTabView = GetBestViewShell() != nullptr;
2030 
2031  SfxWhichIter aIter(rSet);
2032  for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
2033  {
2034  if (!bTabView)
2035  {
2036  rSet.DisableItem(nWhich);
2037  continue;
2038  }
2039 
2040  switch (nWhich)
2041  {
2042  case FID_AUTO_CALC:
2044  rSet.DisableItem( nWhich );
2045  else
2046  rSet.Put( SfxBoolItem( nWhich, m_aDocument.GetAutoCalc() ) );
2047  break;
2048 
2049  case FID_CHG_RECORD:
2050  if ( IsDocShared() )
2051  rSet.DisableItem( nWhich );
2052  else
2053  rSet.Put( SfxBoolItem( nWhich,
2054  m_aDocument.GetChangeTrack() != nullptr ) );
2055  break;
2056 
2057  case SID_CHG_PROTECT:
2058  {
2059  ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
2060  if ( pChangeTrack && !IsDocShared() )
2061  rSet.Put( SfxBoolItem( nWhich,
2062  pChangeTrack->IsProtected() ) );
2063  else
2064  rSet.DisableItem( nWhich );
2065  }
2066  break;
2067 
2068  case SID_DOCUMENT_COMPARE:
2069  {
2070  if ( IsDocShared() )
2071  {
2072  rSet.DisableItem( nWhich );
2073  }
2074  }
2075  break;
2076 
2077  // When a formula is edited, FID_RECALC must be enabled in any case. Recalc for
2078  // the doc was disabled once because of a bug if AutoCalc was on, but is now
2079  // always enabled because of another bug.
2080 
2081  case SID_TABLES_COUNT:
2082  rSet.Put( SfxInt16Item( nWhich, m_aDocument.GetTableCount() ) );
2083  break;
2084 
2085  case SID_ATTR_YEAR2000 :
2086  rSet.Put( SfxUInt16Item( nWhich,
2088  break;
2089 
2090  case SID_SHARE_DOC:
2091  {
2092  if ( IsReadOnly() || GetObjectShell()->isExportLocked() )
2093  {
2094  rSet.DisableItem( nWhich );
2095  }
2096  }
2097  break;
2098 
2099  case SID_ATTR_CHAR_FONTLIST:
2100  rSet.Put( SvxFontListItem( m_pImpl->pFontList.get(), nWhich ) );
2101  break;
2102 
2103  case SID_NOTEBOOKBAR:
2104  {
2105  if (GetViewBindings())
2106  {
2108  u"modules/scalc/ui/");
2109  rSet.Put( SfxBoolItem( SID_NOTEBOOKBAR, bVisible ) );
2110  }
2111  }
2112  break;
2113 
2114  case SID_LANGUAGE_STATUS:
2115  {
2116  LanguageType eLatin, eCjk, eCtl;
2117 
2118  GetDocument().GetLanguage( eLatin, eCjk, eCtl );
2119  OUString sLanguage = SvtLanguageTable::GetLanguageString(eLatin);
2121  if (eLatin == LANGUAGE_NONE)
2122  sLanguage += ";-";
2123  else
2124  sLanguage += ";" + LanguageTag(eLatin).getBcp47(false);
2125  }
2126  rSet.Put(SfxStringItem(nWhich, sLanguage));
2127  }
2128  break;
2129 
2130  default:
2131  {
2132  }
2133  break;
2134  }
2135  }
2136 }
2137 
2138 void ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect )
2139 {
2140 
2141  SCTAB nVisTab = m_aDocument.GetVisibleTab();
2142  if (!m_aDocument.HasTable(nVisTab))
2143  return;
2144 
2145  ComplexTextLayoutFlags nOldLayoutMode = pDev->GetLayoutMode();
2146  pDev->SetLayoutMode( ComplexTextLayoutFlags::Default ); // even if it's the same, to get the metafile action
2147 
2148  if ( nAspect == ASPECT_THUMBNAIL )
2149  {
2151  ScViewData aTmpData( *this, nullptr );
2152  aTmpData.SetTabNo(nVisTab);
2153  SnapVisArea( aBoundRect );
2154  aTmpData.SetScreen( aBoundRect );
2155  ScPrintFunc::DrawToDev( m_aDocument, pDev, 1.0, aBoundRect, &aTmpData, true );
2156  }
2157  else
2158  {
2160  tools::Rectangle aNewArea = aOldArea;
2161  ScViewData aTmpData( *this, nullptr );
2162  aTmpData.SetTabNo(nVisTab);
2163  SnapVisArea( aNewArea );
2164  if ( aNewArea != aOldArea && (m_aDocument.GetPosLeft() > 0 || m_aDocument.GetPosTop() > 0) )
2165  SfxObjectShell::SetVisArea( aNewArea );
2166  aTmpData.SetScreen( aNewArea );
2167  ScPrintFunc::DrawToDev( m_aDocument, pDev, 1.0, aNewArea, &aTmpData, true );
2168  }
2169 
2170  pDev->SetLayoutMode( nOldLayoutMode );
2171 }
2172 
2173 tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
2174 {
2175  SfxObjectCreateMode eShellMode = GetCreateMode();
2176  if ( eShellMode == SfxObjectCreateMode::ORGANIZER )
2177  {
2178  // without contents we also don't know how large are the contents;
2179  // return empty rectangle, it will then be calculated after the loading
2180  return tools::Rectangle();
2181  }
2182 
2183  if( nAspect == ASPECT_THUMBNAIL )
2184  {
2185  SCTAB nVisTab = m_aDocument.GetVisibleTab();
2186  if (!m_aDocument.HasTable(nVisTab))
2187  {
2188  nVisTab = 0;
2189  const_cast<ScDocShell*>(this)->m_aDocument.SetVisibleTab(nVisTab);
2190  }
2191  Size aSize = m_aDocument.GetPageSize(nVisTab);
2192  const tools::Long SC_PREVIEW_SIZE_X = 10000;
2193  const tools::Long SC_PREVIEW_SIZE_Y = 12400;
2194  tools::Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X, SC_PREVIEW_SIZE_Y);
2195  if (aSize.Width() > aSize.Height())
2196  {
2197  aArea.SetRight( SC_PREVIEW_SIZE_Y );
2198  aArea.SetBottom( SC_PREVIEW_SIZE_X );
2199  }
2200 
2201  bool bNegativePage = m_aDocument.IsNegativePage( m_aDocument.GetVisibleTab() );
2202  if ( bNegativePage )
2203  ScDrawLayer::MirrorRectRTL( aArea );
2204  SnapVisArea( aArea );
2205  return aArea;
2206  }
2207  else if( nAspect == ASPECT_CONTENT && eShellMode != SfxObjectCreateMode::EMBEDDED )
2208  {
2209  // fetch visarea like after loading
2210 
2211  SCTAB nVisTab = m_aDocument.GetVisibleTab();
2212  if (!m_aDocument.HasTable(nVisTab))
2213  {
2214  nVisTab = 0;
2215  const_cast<ScDocShell*>(this)->m_aDocument.SetVisibleTab(nVisTab);
2216  }
2217  SCCOL nStartCol;
2218  SCROW nStartRow;
2219  m_aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
2220  SCCOL nEndCol;
2221  SCROW nEndRow;
2222  m_aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
2223  if (nStartCol>nEndCol)
2224  nStartCol = nEndCol;
2225  if (nStartRow>nEndRow)
2226  nStartRow = nEndRow;
2227  tools::Rectangle aNewArea = m_aDocument
2228  .GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
2229  return aNewArea;
2230  }
2231  else
2232  return SfxObjectShell::GetVisArea( nAspect );
2233 }
2234 
2235 namespace {
2236 
2237 [[nodiscard]]
2238 tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCCOL& rStartCol )
2239 {
2240  SCCOL nCol = 0;
2241  tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS);
2242  tools::Long nSnap = 0;
2243  while ( nCol<rDoc.MaxCol() )
2244  {
2245  tools::Long nAdd = rDoc.GetColWidth(nCol, nTab);
2246  if ( nSnap + nAdd/2 < nTwips || nCol < rStartCol )
2247  {
2248  nSnap += nAdd;
2249  ++nCol;
2250  }
2251  else
2252  break;
2253  }
2254  nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS );
2255  rStartCol = nCol;
2256  return nVal;
2257 }
2258 
2259 [[nodiscard]]
2260 tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCROW& rStartRow )
2261 {
2262  SCROW nRow = 0;
2263  tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS);
2264  tools::Long nSnap = 0;
2265 
2266  bool bFound = false;
2267  for (SCROW i = nRow; i <= rDoc.MaxRow(); ++i)
2268  {
2269  SCROW nLastRow;
2270  if (rDoc.RowHidden(i, nTab, nullptr, &nLastRow))
2271  {
2272  i = nLastRow;
2273  continue;
2274  }
2275 
2276  nRow = i;
2277  tools::Long nAdd = rDoc.GetRowHeight(i, nTab);
2278  if ( nSnap + nAdd/2 < nTwips || nRow < rStartRow )
2279  {
2280  nSnap += nAdd;
2281  ++nRow;
2282  }
2283  else
2284  {
2285  bFound = true;
2286  break;
2287  }
2288  }
2289  if (!bFound)
2290  nRow = rDoc.MaxRow(); // all hidden down to the bottom
2291 
2292  nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS );
2293  rStartRow = nRow;
2294  return nVal;
2295 }
2296 
2297 }
2298 
2300 {
2301  SCTAB nTab = m_aDocument.GetVisibleTab();
2302  tools::Long nOrigTop = rRect.Top();
2303  tools::Long nOrigLeft = rRect.Left();
2304  bool bNegativePage = m_aDocument.IsNegativePage( nTab );
2305  if ( bNegativePage )
2306  ScDrawLayer::MirrorRectRTL( rRect ); // calculate with positive (LTR) values
2307 
2308  SCCOL nCol = m_aDocument.GetPosLeft();
2309  tools::Long nSetLeft = SnapHorizontal( m_aDocument, nTab, rRect.Left(), nCol );
2310  rRect.SetLeft( nSetLeft );
2311  ++nCol; // at least one column
2312  tools::Long nCorrectionLeft = (nOrigLeft == 0 && nCol > 0) ? nSetLeft : 0; // initial correction
2313  rRect.SetRight( SnapHorizontal( m_aDocument, nTab, rRect.Right() + nCorrectionLeft, nCol ));
2314 
2315  SCROW nRow = m_aDocument.GetPosTop();
2316  tools::Long nSetTop = SnapVertical( m_aDocument, nTab, rRect.Top(), nRow );
2317  rRect.SetTop( nSetTop );
2318  ++nRow; // at least one row
2319  tools::Long nCorrectionTop = (nOrigTop == 0 && nRow > 0) ? nSetTop : 0; // initial correction
2320  rRect.SetBottom( SnapVertical( m_aDocument, nTab, rRect.Bottom() + nCorrectionTop, nRow ));
2321 
2322  if ( bNegativePage )
2323  ScDrawLayer::MirrorRectRTL( rRect ); // back to real rectangle
2324 }
2325 
2327  SCTAB nCurTab,
2328  bool& rbHeader,
2329  bool& rbFooter )
2330 {
2331  if ( !pStyleSet )
2332  {
2334  SfxStyleSheetBase* pStyleSheet = pStylePool->
2335  Find( m_aDocument.GetPageStyle( nCurTab ),
2336  SfxStyleFamily::Page );
2337 
2338  OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
2339 
2340  if ( pStyleSheet )
2341  pStyleSet = &pStyleSheet->GetItemSet();
2342  else
2343  rbHeader = rbFooter = false;
2344  }
2345 
2346  OSL_ENSURE( pStyleSet, "PageStyle-Set not found! :-(" );
2347  if (!pStyleSet)
2348  return;
2349 
2350  const SvxSetItem* pSetItem = nullptr;
2351  const SfxItemSet* pSet = nullptr;
2352 
2353  pSetItem = &pStyleSet->Get( ATTR_PAGE_HEADERSET );
2354  pSet = &pSetItem->GetItemSet();
2355  rbHeader = pSet->Get(ATTR_PAGE_ON).GetValue();
2356 
2357  pSetItem = &pStyleSet->Get( ATTR_PAGE_FOOTERSET );
2358  pSet = &pSetItem->GetItemSet();
2359  rbFooter = pSet->Get(ATTR_PAGE_ON).GetValue();
2360 }
2361 
2362 #if defined(_WIN32)
2363 bool ScDocShell::DdeGetData( const OUString& rItem,
2364  const OUString& rMimeType,
2365  css::uno::Any & rValue )
2366 {
2368  if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId)
2369  {
2370  if( rItem.equalsIgnoreAsciiCase( "Format" ) )
2371  {
2372  OString aFmtByte(OUStringToOString(m_aDdeTextFmt,
2373  osl_getThreadTextEncoding()));
2374  rValue <<= css::uno::Sequence< sal_Int8 >(
2375  reinterpret_cast<const sal_Int8*>(aFmtByte.getStr()),
2376  aFmtByte.getLength() + 1 );
2377  return true;
2378  }
2379  ScImportExport aObj( m_aDocument, rItem );
2380  if ( !aObj.IsRef() )
2381  return false; // invalid range
2382 
2383  if( m_aDdeTextFmt[0] == 'F' )
2384  aObj.SetFormulas( true );
2385  if( m_aDdeTextFmt == "SYLK" ||
2386  m_aDdeTextFmt == "FSYLK" )
2387  {
2388  OString aData;
2389  if( aObj.ExportByteString( aData, osl_getThreadTextEncoding(),
2390  SotClipboardFormatId::SYLK ) )
2391  {
2392  rValue <<= css::uno::Sequence< sal_Int8 >(
2393  reinterpret_cast<const sal_Int8*>(aData.getStr()),
2394  aData.getLength() + 1 );
2395  return true;
2396  }
2397  else
2398  return false;
2399  }
2400  if( m_aDdeTextFmt == "CSV" ||
2401  m_aDdeTextFmt == "FCSV" )
2402  aObj.SetSeparator( ',' );
2403  aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2404  return aObj.ExportData( rMimeType, rValue );
2405  }
2406 
2407  ScImportExport aObj( m_aDocument, rItem );
2408  aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2409  return aObj.IsRef() && aObj.ExportData( rMimeType, rValue );
2410 }
2411 
2412 bool ScDocShell::DdeSetData( const OUString& rItem,
2413  const OUString& rMimeType,
2414  const css::uno::Any & rValue )
2415 {
2417  if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId)
2418  {
2419  if( rItem.equalsIgnoreAsciiCase( "Format" ) )
2420  {
2421  if ( ScByteSequenceToString::GetString( m_aDdeTextFmt, rValue, osl_getThreadTextEncoding() ) )
2422  {
2423  m_aDdeTextFmt = m_aDdeTextFmt.toAsciiUpperCase();
2424  return true;
2425  }
2426  return false;
2427  }
2428  ScImportExport aObj( m_aDocument, rItem );
2429  if( m_aDdeTextFmt[0] == 'F' )
2430  aObj.SetFormulas( true );
2431  if( m_aDdeTextFmt == "SYLK" ||
2432  m_aDdeTextFmt == "FSYLK" )
2433  {
2434  OUString aData;
2435  if ( ScByteSequenceToString::GetString( aData, rValue, osl_getThreadTextEncoding() ) )
2436  {
2437  return aObj.ImportString( aData, SotClipboardFormatId::SYLK );
2438  }
2439  return false;
2440  }
2441  if( m_aDdeTextFmt == "CSV" ||
2442  m_aDdeTextFmt == "FCSV" )
2443  aObj.SetSeparator( ',' );
2444  OSL_ENSURE( false, "Implementation is missing" );
2445  return false;
2446  }
2447  /*ScImportExport aObj( aDocument, rItem );
2448  return aObj.IsRef() && ScImportExport::ImportData( rMimeType, rValue );*/
2449  OSL_ENSURE( false, "Implementation is missing" );
2450  return false;
2451 }
2452 #endif
2453 
2455 {
2456  // only check for valid item string - range is parsed again in ScServerObject ctor
2457 
2458  // named range?
2459  OUString aPos = rItem;
2460  ScRangeName* pRange = m_aDocument.GetRangeName();
2461  if( pRange )
2462  {
2463  const ScRangeData* pData = pRange->findByUpperName(ScGlobal::getCharClassPtr()->uppercase(aPos));
2464  if (pData)
2465  {
2466  if( pData->HasType( ScRangeData::Type::RefArea )
2467  || pData->HasType( ScRangeData::Type::AbsArea )
2468  || pData->HasType( ScRangeData::Type::AbsPos ) )
2469  pData->GetSymbol( aPos ); // continue with the name's contents
2470  }
2471  }
2472 
2473  // Address in DDE function must be always parsed as CONV_OOO so that it
2474  // would always work regardless of current address conversion. We do this
2475  // because the address item in a DDE entry is *not* normalized when saved
2476  // into ODF.
2477  ScRange aRange;
2478  bool bValid = ( (aRange.Parse(aPos, m_aDocument, formula::FormulaGrammar::CONV_OOO ) & ScRefFlags::VALID) ||
2480 
2481  ScServerObject* pObj = nullptr; // NULL = error
2482  if ( bValid )
2483  pObj = new ScServerObject( this, rItem );
2484 
2485  // GetLinkManager()->InsertServer() is in the ScServerObject ctor
2486 
2487  return pObj;
2488 }
2489 
2491 {
2492  if ( !pDocument->IsDocVisible() || // don't want callbacks until document load
2495  return;
2496 
2497  boost::property_tree::ptree aAnnotation;
2498  aAnnotation.put("action", (nType == LOKCommentNotificationType::Add ? "Add" :
2499  (nType == LOKCommentNotificationType::Remove ? "Remove" :
2500  (nType == LOKCommentNotificationType::Modify ? "Modify" : "???"))));
2501 
2502  assert(pNote);
2503  aAnnotation.put("id", pNote->GetId());
2504  aAnnotation.put("tab", rPos.Tab());
2505 
2507  {
2508  aAnnotation.put("author", pNote->GetAuthor());
2509  aAnnotation.put("dateTime", pNote->GetDate());
2510  aAnnotation.put("text", pNote->GetText());
2511 
2512  // Calculating the cell cursor position
2513  ScViewData* pViewData = GetViewData();
2514  if (pViewData && pViewData->GetActiveWin())
2515  {
2516  bool bInPrintTwips = comphelper::LibreOfficeKit::isCompatFlagSet(
2517  comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
2518  OString aRectString;
2519  if (bInPrintTwips)
2520  {
2521  Point aTopLeft = pViewData->GetPrintTwipsPos(rPos.Col(), rPos.Row());
2522  tools::Long nSizeX, nSizeY;
2523  pViewData->GetMergeSizePrintTwips(rPos.Col(), rPos.Row(), nSizeX, nSizeY);
2524  aRectString = tools::Rectangle(aTopLeft, Size(nSizeX - 1, nSizeY - 1)).toString();
2525  }
2526  else
2527  {
2528  Point aTopLeft = pViewData->GetScrPos(rPos.Col(), rPos.Row(),
2529  pViewData->GetActivePart(), true);
2530  tools::Long nSizeXPix, nSizeYPix;
2531  pViewData->GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeXPix, nSizeYPix);
2532  const double fPPTX = pViewData->GetPPTX();
2533  const double fPPTY = pViewData->GetPPTY();
2534  aRectString = tools::Rectangle(Point(aTopLeft.getX() / fPPTX, aTopLeft.getY() / fPPTY),
2535  Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY)).toString();
2536  }
2537  aAnnotation.put("cellPos", aRectString);
2538  }
2539  }
2540 
2541  boost::property_tree::ptree aTree;
2542  aTree.add_child("comment", aAnnotation);
2543  std::stringstream aStream;
2544  boost::property_tree::write_json(aStream, aTree);
2545  std::string aPayload = aStream.str();
2546 
2547  ScViewData* pViewData = GetViewData();
2548  SfxViewShell* pThisViewShell = ( pViewData ? pViewData->GetViewShell() : nullptr );
2549  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
2550  while (pViewShell)
2551  {
2552  if (pThisViewShell == nullptr || pViewShell->GetDocId() == pThisViewShell->GetDocId())
2553  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
2554  pViewShell = SfxViewShell::GetNext(*pViewShell);
2555  }
2556 }
2557 
2559 {
2561  ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( pCur );
2562  return pViewSh ? &pViewSh->GetViewData() : nullptr;
2563 }
2564 
2566 {
2568 
2569  ScViewData* pViewData = GetViewData();
2570 
2571  return pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0);
2572 }
2573 
2575 {
2577  // wrong Doc?
2578  if( pViewSh && pViewSh->GetViewData().GetDocShell() != this )
2579  pViewSh = nullptr;
2580  if( !pViewSh )
2581  {
2582  // 1. find ViewShell
2583  SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, bOnlyVisible );
2584  if( pFrame )
2585  {
2586  SfxViewShell* p = pFrame->GetViewShell();
2587  pViewSh = dynamic_cast< ScTabViewShell *>( p );
2588  }
2589  }
2590  return pViewSh;
2591 }
2592 
2594 {
2595  // used to invalidate slots after changes to this document
2596 
2597  SfxViewShell* pViewSh = GetBestViewShell();
2598  if (pViewSh)
2599  return &pViewSh->GetViewFrame()->GetBindings();
2600  else
2601  return nullptr;
2602 }
2603 
2604 ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo ) // static
2605 {
2606  ScDocShell* pFound = nullptr;
2608  sal_uInt16 nShellCnt = 0;
2609 
2610  while ( pShell && !pFound )
2611  {
2612  if ( auto pDocSh = dynamic_cast<ScDocShell*>(pShell) )
2613  {
2614  if ( nShellCnt == nDocNo )
2615  pFound = pDocSh;
2616  else
2617  ++nShellCnt;
2618  }
2619  pShell = SfxObjectShell::GetNext( *pShell );
2620  }
2621 
2622  return pFound;
2623 }
2624 
2625 IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void )
2626 {
2627  OSL_ENSURE( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" );
2628  OSL_ENSURE( m_pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2629 
2630  if ( ERRCODE_NONE == _pFileDlg->GetError() )
2631  {
2632  sal_uInt16 nSlot = m_pImpl->pRequest->GetSlot();
2633  std::unique_ptr<SfxMedium> pMed = m_pImpl->pDocInserter->CreateMedium();
2634  // #i87094# If a .odt was selected pMed is NULL.
2635  if (pMed)
2636  {
2637  m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
2638  if ( SID_DOCUMENT_COMPARE == nSlot )
2639  {
2640  if ( pMed->GetFilter() )
2641  m_pImpl->pRequest->AppendItem(
2642  SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
2643  OUString sOptions = ScDocumentLoader::GetOptions( *pMed );
2644  if ( !sOptions.isEmpty() )
2645  m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2646  }
2647  const SfxPoolItem* pItem = nullptr;
2648  const SfxInt16Item* pInt16Item(nullptr);
2649  SfxItemSet* pSet = pMed->GetItemSet();
2650  if (pSet && pSet->GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET)
2651  {
2652  pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem);
2653  }
2654  if (pInt16Item)
2655  {
2656  m_pImpl->pRequest->AppendItem( *pItem );
2657  }
2658 
2659  Execute( *(m_pImpl->pRequest) );
2660  }
2661  }
2662 
2663  m_pImpl->bIgnoreLostRedliningWarning = false;
2664 }
2665 
2666 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
2667 
2668 void ScDocShell::EnableSharedSettings( bool bEnable )
2669 {
2671 
2672  if ( bEnable )
2673  {
2676 
2677  // hide accept or reject changes dialog
2678  sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
2679  SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2680  if ( pViewFrame && pViewFrame->HasChildWindow( nId ) )
2681  {
2682  pViewFrame->ToggleChildWindow( nId );
2683  SfxBindings* pBindings = GetViewBindings();
2684  if ( pBindings )
2685  {
2686  pBindings->Invalidate( FID_CHG_ACCEPT );
2687  }
2688  }
2689  }
2690  else
2691  {
2693  }
2694 
2695  ScChangeViewSettings aChangeViewSet;
2696  aChangeViewSet.SetShowChanges( false );
2697  m_aDocument.SetChangeViewSettings( aChangeViewSet );
2698 }
2699 
2700 uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
2701 {
2702  uno::Reference< frame::XModel > xModel;
2703  try
2704  {
2705  SC_MOD()->SetInSharedDocLoading( true );
2706  uno::Reference< frame::XDesktop2 > xLoader = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
2707  uno::Sequence < beans::PropertyValue > aArgs( 1 );
2708  aArgs[0].Name = "Hidden";
2709  aArgs[0].Value <<= true;
2710 
2711  if ( GetMedium() )
2712  {
2713  const SfxStringItem* pPasswordItem = SfxItemSet::GetItem<SfxStringItem>(GetMedium()->GetItemSet(), SID_PASSWORD, false);
2714  if ( pPasswordItem && !pPasswordItem->GetValue().isEmpty() )
2715  {
2716  aArgs.realloc( 2 );
2717  aArgs[1].Name = "Password";
2718  aArgs[1].Value <<= pPasswordItem->GetValue();
2719  }
2720  const SfxUnoAnyItem* pEncryptionItem = SfxItemSet::GetItem<SfxUnoAnyItem>(GetMedium()->GetItemSet(), SID_ENCRYPTIONDATA, false);
2721  if (pEncryptionItem)
2722  {
2723  aArgs.realloc(aArgs.getLength() + 1);
2724  aArgs[aArgs.getLength() - 1].Name = "EncryptionData";
2725  aArgs[aArgs.getLength() - 1].Value = pEncryptionItem->GetValue();
2726  }
2727  }
2728 
2729  xModel.set(
2730  xLoader->loadComponentFromURL( GetSharedFileURL(), "_blank", 0, aArgs ),
2731  uno::UNO_QUERY_THROW );
2732  SC_MOD()->SetInSharedDocLoading( false );
2733  }
2734  catch ( uno::Exception& )
2735  {
2736  OSL_FAIL( "ScDocShell::LoadSharedDocument(): caught exception" );
2737  SC_MOD()->SetInSharedDocLoading( false );
2738  try
2739  {
2740  uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
2741  xClose->close( true );
2742  return uno::Reference< frame::XModel >();
2743  }
2744  catch ( uno::Exception& )
2745  {
2746  return uno::Reference< frame::XModel >();
2747  }
2748  }
2749  return xModel;
2750 }
2751 
2752 #endif
2753 
2754 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:575
void SetEditHelpId(const OString &rId)
SfxViewFrame * GetViewFrame() const
bool GetValue() const
bool IsInDocShellRecalc() const
Definition: document.hxx:2539
bool IsBlockEditable(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool *pOnlyNotBecauseOfMatrix=nullptr, bool bNoMatrixAtAll=false) const
Definition: document.cxx:5353
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
SfxHintId
void GetScaleData(Size &rPhysSize, tools::Long &rDocHdr, tools::Long &rDocFtr)
Definition: printfun.cxx:1129
SC_DLLPUBLIC void ApplyStyleAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScStyleSheet &rStyle)
Definition: document.cxx:4882
SC_DLLPUBLIC const ScRange * GetRepeatColRange(SCTAB nTab)
Definition: document.cxx:6313
SC_DLLPUBLIC bool HasQueryParam() const
Definition: dbdata.cxx:524
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:814
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
ScAddress aStart
Definition: address.hxx:499
void EndChangeTracking()
Definition: documen2.cxx:269
bool bVisible
SC_DLLPUBLIC bool GetDataStart(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow) const
Definition: documen2.cxx:643
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1906
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: docsh3.cxx:450
SfxChildWindow * GetChildWindow(sal_uInt16)
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
Definition: documen3.cxx:504
static SfxInterface * GetStaticInterface()
void ExecutePageStyle(const SfxViewShell &rCaller, SfxRequest &rReq, SCTAB nCurTab)
Definition: docsh4.cxx:1771
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:993
virtual const FmFormShell * GetFormShell() const override
Definition: tabvwsh.hxx:334
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:261
IMPL_LINK_NOARG(ScDocShell, ReloadAllLinksHdl, weld::Button &, void)
Definition: docsh4.cxx:142
static SfxAbstractDialogFactory * Create()
void PostPaintGridAll()
Definition: docsh3.cxx:182
ScLkUpdMode GetLinkMode() const
Definition: appoptio.hxx:67
#define PRINT_HEADER_WIDTH
Definition: printfun.hxx:45
SC_DLLPUBLIC void SetChangeViewSettings(const ScChangeViewSettings &rNew)
Definition: documen2.cxx:1111
bool HasSharedXMLFlagSet() const
static void GetSpellSettings(LanguageType &rDefLang, LanguageType &rCjkLang, LanguageType &rCtlLang, bool &rAutoSpell)
Definition: scmod.cxx:2175
const SfxItemSet & GetEmptyItemSet() const
std::unique_ptr< ContentProperties > pData
std::string GetValue
static weld::Window * GetActiveDialogParent()
Definition: docsh.cxx:3045
static void DrawToDev(ScDocument &rDoc, OutputDevice *pDev, double nPrintFactor, const tools::Rectangle &rBound, ScViewData *pViewData, bool bMetaFile)
Definition: printfun.cxx:465
SfxBindings * GetViewBindings()
Definition: docsh4.cxx:2593
virtual VclPtr< AbstractScColRowLabelDlg > CreateScColRowLabelDlg(weld::Window *pParent, bool bCol, bool bRow)=0
bool IsFormulaMode() const
Definition: inputhdl.hxx:261
signed char sal_Int8
void SetProtection(const css::uno::Sequence< sal_Int8 > &rPass)
Definition: chgtrack.hxx:1128
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1687
void PostPaintCell(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: docsh3.cxx:187
SC_DLLPUBLIC const ScFormulaCell * GetFormulaCell(const ScAddress &rPos) const
Definition: document.cxx:3754
ScScenarioFlags
Definition: global.hxx:235
bool IsInputMode() const
Definition: inputhdl.hxx:184
Point GetPrintTwipsPos(SCCOL nCol, SCROW nRow) const
returns the position (top-left corner) of the requested cell in print twips coordinates.
Definition: viewdata.cxx:2520
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALE(175)
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:213
static void RemoveAppPrefix(OUString &rFilterName)
Definition: tablink.cxx:486
const OUString & GetName() const
sal_uIntPtr sal_uLong
long Long
void GetPageOnFromPageStyleSet(const SfxItemSet *pStyleSet, SCTAB nCurTab, bool &rbHeader, bool &rbFooter)
Definition: docsh4.cxx:2326
These options control how multi-line cells are converted during export in certain lossy formats (such...
Definition: impex.hxx:35
#define ZOOM_MIN
Definition: docsh4.cxx:1615
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
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:210
void DeleteTable(SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2413
static SVL_DLLPUBLIC void GetHashPassword(css::uno::Sequence< sal_Int8 > &rPassHash, const char *pPass, sal_uInt32 nLen)
void SetDocumentModified()
Definition: docsh.cxx:2915
sal_Int16 nId
sal_uInt16 FirstWhich()
double GetPPTX() const
Definition: viewdata.hxx:467
void PostPaintExtras()
Definition: docsh3.cxx:197
ComplexTextLayoutFlags GetLayoutMode() const
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
ScStyleSheet * FindCaseIns(const OUString &rName, SfxStyleFamily eFam)
Definition: stlpool.cxx:409
bool ImportData(const ScImportParam &rParam)
Definition: dbfunc.cxx:433
void MergeDocument(ScDocument &rOtherDoc, bool bShared=false, bool bCheckDuplicates=false, sal_uLong nOffset=0, ScChangeActionMergeMap *pMergeMap=nullptr, bool bInverseMap=false)
Definition: docsh3.cxx:769
void SetLayoutMode(ComplexTextLayoutFlags nTextLayoutMode)
ScAddress aEnd
Definition: address.hxx:500
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:397
static void UpdateInputLine()
Definition: tabview3.cxx:3031
create "Importx" (if necessary)
Definition: global.hxx:394
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:542
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:227
bool ExecuteChangeProtectionDialog(bool bJustQueryIfProtected=false)
Protect/unprotect ChangeTrack and return if protection was successfully changed.
Definition: docsh4.cxx:1364
SfxStyleFamily GetFamily() const
virtual short Execute()=0
sal_uLong GetActionMax() const
Definition: chgtrack.hxx:960
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
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:4192
sal_uInt16 NextWhich()
virtual ::sfx2::SvLinkSource * DdeCreateLinkSource(const OUString &rItem) override
Definition: docsh4.cxx:2454
SfxApplication * SfxGetpApp()
OUString GetSharedFileURL() const
bool HasAnySheetEventScript(ScSheetEventId nEvent, bool bWithVbaEvents=false) const
Definition: documen3.cxx:696
void DoRecalc(bool bApi)
Definition: docsh4.cxx:1426
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2901
void ToggleChildWindow(sal_uInt16)
RET_NO
constexpr tools::Long Width() const
SfxStyleSheetBase * GetStyleSheet() const
Keep selection as is, expand to used data area if no selection.
bool AdjustPrintZoom(const ScRange &rRange)
Definition: docsh4.cxx:1650
void MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo)
SC_DLLPUBLIC ScConditionalFormatList * GetCondFormList(SCTAB nTab) const
Definition: documen4.cxx:858
bool ShowChanges() const
Definition: chgviset.hxx:77
RET_YES
void ReloadAllLinks()
Definition: docsh4.cxx:119
void SetImportParam(const ScImportParam &rImportParam)
Definition: dbdata.cxx:490
const OUString & GetName() const
PropertiesInfo aProperties
tools::Long Left() const
void SetLeft(tools::Long v)
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:313
Additional class containing cell annotation data.
Definition: postit.hxx:159
static void LOKCommentNotify(LOKCommentNotificationType nType, const ScDocument *pDocument, const ScAddress &rPos, const ScPostIt *pNote)
Definition: docsh4.cxx:2490
static LanguageType GetLanguageType(std::u16string_view rStr)
ScLkUpdMode
Definition: global.hxx:418
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:259
SC_DLLPUBLIC bool IsDocVisible() const
Definition: document.hxx:1556
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:190
bool DetectiveRefresh(bool bAutomatic=false)
Definition: docfunc.cxx:464
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:653
#define HMM_PER_TWIPS
Definition: global.hxx:92
SCTAB Tab() const
Definition: address.hxx:270
const css::uno::Any & GetValue() const
void Execute(SfxRequest &rReq)
Definition: docsh4.cxx:188
SotClipboardFormatId
void NotifyStyle(const SfxStyleSheetHint &rHint)
Definition: docsh4.cxx:1543
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:126
SfxObjectCreateMode GetCreateMode() const
void PageStyleModified(SCTAB nTab, const OUString &rNewName)
Definition: document.cxx:6200
bool HasRowHeaders() const
Definition: chartpos.hxx:133
bool GetMergeSizePrintTwips(SCCOL nX, SCROW nY, tools::Long &rSizeXTwips, tools::Long &rSizeYTwips) const
Definition: viewdata.cxx:2733
ScViewData & GetViewData()
Definition: tabview.hxx:333
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2404
void UpdateSpellSettings(bool bFromStartTab=false)
Definition: inputhdl.cxx:911
void DoHardRecalc()
Definition: docsh4.cxx:1477
void SetDirty(bool bDirtyFlag=true)
static void SetError(ErrCode)
const css::uno::Sequence< sal_Int8 > & GetProtection() const
Definition: chgtrack.hxx:1130
SfxItemPool & GetPool() const
bool IsProtected() const
Definition: chgtrack.hxx:1132
bool empty() const
Definition: rangelst.hxx:88
constexpr OUStringLiteral aData
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1939
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:356
void InitFromStyle(const SfxStyleSheetBase *pSource)
Definition: undostyl.cxx:59
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2307
SC_DLLPUBLIC void SetVisibleTab(SCTAB nTab)
Definition: document.hxx:859
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:3394
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:681
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
void connect_clicked(const Link< Button &, void > &rLink)
void RepeatDB(bool bRecord=true)
Definition: dbfunc3.cxx:2114
bool UpdatePages()
Definition: printfun.cxx:2429
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:1520
SC_DLLPUBLIC void CalcFormulaTree(bool bOnlyForced=false, bool bProgressBar=true, bool bSetAllDirty=true)
Calculate formula cells that are on the formula tree either partially, or in full.
Definition: documen7.cxx:326
virtual void Draw(OutputDevice *, const JobSetup &rSetup, sal_uInt16 nAspect) override
Definition: docsh4.cxx:2138
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:2368
constexpr TypedWhichId< SvxSetItem > ATTR_PAGE_HEADERSET(184)
virtual SfxObjectShell * GetObjectShell() override
ComplexTextLayoutFlags
void SetAttribs(const SfxItemSet &rSet)
sal_Int16 SCCOL
Definition: types.hxx:21
bool ValidCol(SCCOL nCol) const
Definition: document.hxx:874
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:602
#define SC_MOD()
Definition: scmod.hxx:250
bool HasSortParam() const
Definition: dbdata.cxx:535
void LimitChartArea(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow)
Definition: document.cxx:1107
SfxBindings & GetBindings()
SfxObjectShell * GetEmbeddedObject() const
Definition: docuno.cxx:451
void PageStyleModified(std::u16string_view rStyleName, bool bApi)
Definition: docsh4.cxx:1729
#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:1798
const T * GetArg(sal_uInt16 nSlotId) const
void ShowExtras(SfxShowExtras nExtras)
constexpr sal_uInt16 XATTR_FILL_FIRST(XATTRSET_LINE+1)
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:1617
bool RenamePageStyleInUse(std::u16string_view rOld, const OUString &rNew)
Definition: documen8.cxx:341
void SetLinkFormulaNeedingCheck(bool bSet)
Definition: document.hxx:2136
float u
void SetYear2000(sal_uInt16 nVal)
Definition: docoptio.hxx:84
const OUString & GetName() const
Definition: dbdata.hxx:121
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:914
void GetImportParam(ScImportParam &rImportParam) const
Definition: dbdata.cxx:480
SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3117
void AllowLinkUpdate()
Definition: docsh4.cxx:113
#define LANGUAGE_DONTKNOW
HardRecalcState GetHardRecalcState() const
Definition: document.hxx:2312
#define HID_CHG_PROTECT
Definition: helpids.h:51
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6212
void TrackFormulas(SfxHintId nHintId=SfxHintId::ScDataChanged)
Definition: documen7.cxx:527
SfxItemSet * GetItemSet() const
void BroadcastUno(const SfxHint &rHint)
Definition: documen3.cxx:949
virtual comphelper::EmbeddedObjectContainer & getEmbeddedObjectContainer() const override
static bool IsActive()
void SetTop(tools::Long v)
bool HasName() const
void SetBottom(tools::Long v)
SC_DLLPUBLIC tools::Rectangle GetMMRect(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: documen3.cxx:1988
const ::avmedia::MediaItem * Execute(SdrMarkView *pSdrView, SfxRequest const &rReq)
const XColorListRef & GetColorList() const
sal_Int16 m_nCanUpdate
Definition: docsh.hxx:98
#define ERRCODE_BASIC_NO_ACTIVE_OBJECT
sal_Int16 nVersion
OUString SpellIgnoreWord()
const tools::Rectangle & GetVisArea() const
const SCTAB MAXTAB
Definition: address.hxx:70
tools::Long Top() const
constexpr TypedWhichId< SfxBoolItem > ATTR_PAGE_HEADERS(170)
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
static ScViewData * GetViewData()
Definition: docsh4.cxx:2558
#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:100
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:5594
bool HasType(Type nType) const
Definition: rangenam.hxx:176
bool IsStripData() const
Definition: dbdata.hxx:140
void GetStatePageStyle(SfxItemSet &rSet, SCTAB nCurTab)
Definition: docsh4.cxx:1990
void PostDataChanged()
Definition: docsh3.cxx:92
bool m_bFooterOn
Definition: docsh.hxx:89
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:266
bool IsReadOnly() const
bool IsShareDocumentChecked() const
Definition: sharedocdlg.cxx:91
void RemoveInfoBar(std::u16string_view sId)
size_t LeaveListAction()
void InsertText(const OUString &rNew, bool bSelect=false, bool bLOKShowSelect=true)
ScDBData * findByUpperName(const OUString &rName)
Definition: dbdata.cxx:1167
void SetCalcNotification(SCTAB nTab)
Definition: documen3.cxx:721
ScDBFunc * GetView() const
Definition: viewdata.cxx:855
SvxPageUsage
void SetMinLen(sal_uInt16 Len)
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2604
ConversionMode mode
SC_DLLPUBLIC void GetScenarioData(SCTAB nTab, OUString &rComment, Color &rColor, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:468
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:860
void SetShowAccepted(bool bVal)
Definition: chgviset.hxx:113
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:17
sal_uInt16 GetSlot() const
void UpdateExternalRefLinks(weld::Window *pWin)
Definition: documen8.cxx:790
double GetPPTY() const
Definition: viewdata.hxx:468
bool HasChildWindow(sal_uInt16)
virtual VclPtr< SfxAbstractTabDialog > CreateScStyleDlg(weld::Window *pParent, SfxStyleSheetBase &rStyleBase, bool bPage)=0
static SfxViewFrame * Current()
OUString ScResId(std::string_view aId)
Definition: scdll.cxx:89
bool ValidRow(SCROW nRow) const
Definition: document.hxx:875
void SetStreamValid(SCTAB nTab, bool bSet, bool bIgnoreLock=false)
Definition: document.cxx:924
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1945
static ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1038
void DisableItem(sal_uInt16 nWhich)
weld::Window * GetFrameWeld() const
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
SC_DLLPUBLIC void CalcAll()
Definition: document.cxx:3964
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SC_DLLPUBLIC const ScRange * GetRepeatRowRange(SCTAB nTab)
Definition: document.cxx:6321
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
const ScAddress & GetCursorPos() const
Definition: inputhdl.hxx:192
constexpr tools::Long Height() const
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:2625
static SotClipboardFormatId GetFormatIdFromMimeType(const OUString &rMimeType)
void CompareDocument(ScDocument &rOtherDoc)
Definition: docsh3.cxx:660
#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:3095
RET_OK
ScChangeViewSettings * GetChangeViewSettings() const
Definition: document.hxx:2165
static void MirrorRectRTL(tools::Rectangle &rRect)
Definition: drwlayer.cxx:2086
bool m_bHeaderOn
Definition: docsh.hxx:88
void UpdateAcceptChangesDialog()
Definition: docsh4.cxx:1351
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:202
static void ExecMethod(SfxBindings &rBindings, const OUString &rUIName)
void InvalidateName()
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) 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:71
static SC_DLLPUBLIC const CharClass * getCharClassPtr()
Definition: global.cxx:1009
std::unique_ptr< DocShell_Impl > m_pImpl
Definition: docsh.hxx:85
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:208
void * p
Reference< XComponentContext > getProcessComponentContext()
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2155
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
void SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl)
Definition: documen3.cxx:1972
constexpr TypedWhichId< SvxPageItem > ATTR_PAGE(159)
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
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:85
bool GetMergeSizePixel(SCCOL nX, SCROW nY, tools::Long &rSizeXPix, tools::Long &rSizeYPix) const
Definition: viewdata.cxx:2696
bool HasImportSelection() const
Definition: dbdata.hxx:201
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6092
void ShowChildWindow(sal_uInt16, bool bVisible=true)
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALETOPAGES(176)
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:4460
void SetSelection(const ESelection &rNewSel)
void SetDocumentModified()
Definition: docsh.cxx:3254
ScDocument m_aDocument
Definition: docsh.hxx:80
void UpdateImport(const OUString &rTarget, const svx::ODataAccessDescriptor &rDescriptor)
Definition: dbdocfun.cxx:1696
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:92
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
void InvalidateAll(bool bWithMsg)
bool HasColHeaders() const
Definition: chartpos.hxx:132
void AppendItem(const SfxPoolItem &)
#define SAL_WARN(area, stream)
OUString m_aDdeTextFmt
Definition: docsh.hxx:82
bool IsUndoEnabled() const
Definition: document.hxx:1535
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:6226
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:218
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
Definition: docsh4.cxx:2574
void UpdateAreaLinks()
Definition: documen8.cxx:1050
void FormulaPreview()
Definition: inputhdl.cxx:1794
bool DoLoad(SfxMedium *pMedium)
void StartChangeTracking()
Definition: documen2.cxx:263
void SetScreen(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: viewdata.cxx:2988
constexpr TypedWhichId< SfxBoolItem > ATTR_PAGE_ON(164)
SC_DLLPUBLIC void GetLanguage(LanguageType &rLatin, LanguageType &rCjk, LanguageType &rCtl) const
Definition: documen3.cxx:1965
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
void UpdateLayerLocks()
Definition: tabview5.cxx:354
SCTAB GetVisibleTab() const
Definition: document.hxx:858
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4151
rtl::OString toString() const
SAL_DLLPRIVATE void EnableSharedSettings(bool bEnable)
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
constexpr TypedWhichId< SvxSetItem > ATTR_PAGE_FOOTERSET(185)
void Ignore()
static SCTAB GetCurTab()
Definition: docsh4.cxx:2565
void SnapVisArea(tools::Rectangle &rRect) const
Definition: docsh4.cxx:2299
#define EE_TEXTPOS_ALL
SCROW GetPosTop() const
Definition: document.hxx:862
ScLkUpdMode GetLinkUpdateModeState() const
Definition: docsh4.cxx:153
void SetY2KState(sal_uInt16 n)
aStr
bool ValidTab(SCTAB nTab)
Definition: address.hxx:104
#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:519
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:451
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2272
bool isTrustedLocationUriForUpdatingLinks(OUString const &uri)
constexpr TypedWhichId< SfxBoolItem > ATTR_PAGE_SHARED(166)
sal_uInt16 nPos
static void CloseMethod(SfxBindings &rBindings)
sal_Int16 SCTAB
Definition: types.hxx:22
void GetState(SfxItemSet &rSet)
Definition: docsh4.cxx:2027
OUString toString(OptionInfo const *info)
SC_DLLPUBLIC bool GetAutoCalc() const
Definition: document.hxx:1360
sal_Int32 nStartPos
void SetShowChanges(bool bFlag)
Definition: chgviset.hxx:78
SfxMedium * GetMedium() const