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