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