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