LibreOffice Module sc (master)  1
viewfun2.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 eCode 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 <scitems.hxx>
21 
22 #include <sfx2/app.hxx>
23 #include <editeng/borderline.hxx>
24 #include <editeng/boxitem.hxx>
25 #include <editeng/fontitem.hxx>
26 #include <editeng/lineitem.hxx>
28 #include <svl/srchitem.hxx>
29 #include <sfx2/linkmgr.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/docfilt.hxx>
32 #include <sfx2/docfile.hxx>
33 #include <sfx2/objitem.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <svl/numformat.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/zforlist.hxx>
38 #include <svx/srchdlg.hxx>
39 #include <svx/svdview.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/weld.hxx>
42 #include <osl/diagnose.h>
43 
44 #include <viewfunc.hxx>
45 #include <vcl/uitest/logger.hxx>
47 
48 #include <sc.hrc>
49 #include <globstr.hrc>
50 #include <scresid.hxx>
51 
52 #include <attrib.hxx>
53 #include <autoform.hxx>
54 #include <formulacell.hxx>
55 #include <cellmergeoption.hxx>
56 #include <compiler.hxx>
57 #include <docfunc.hxx>
58 #include <docpool.hxx>
59 #include <docsh.hxx>
60 #include <docoptio.hxx>
61 #include <global.hxx>
62 #include <patattr.hxx>
63 #include <printfun.hxx>
64 #include <refundo.hxx>
65 #include <table.hxx>
66 #include <tablink.hxx>
67 #include <tabvwsh.hxx>
68 #include <uiitems.hxx>
69 #include <undoblk.hxx>
70 #include <undotab.hxx>
71 #include <sizedev.hxx>
72 #include <editable.hxx>
73 #include <docuno.hxx>
74 #include <charthelper.hxx>
75 #include <tabbgcolor.hxx>
76 #include <clipparam.hxx>
77 #include <prnsave.hxx>
78 #include <searchresults.hxx>
79 #include <tokenarray.hxx>
80 #include <rowheightcontext.hxx>
81 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
82 #include <comphelper/lok.hxx>
83 #include <mergecellsdialog.hxx>
84 #include <sheetevents.hxx>
85 #include <columnspanset.hxx>
86 
87 #include <vector>
88 #include <memory>
89 #include <boost/property_tree/json_parser.hpp>
90 
91 #include <officecfg/Office/Calc.hxx>
92 
93 using namespace com::sun::star;
94 using ::editeng::SvxBorderLine;
95 
96 namespace {
97 
98 void collectUIInformation(std::map<OUString, OUString>&& aParameters, const OUString& rAction)
99 {
100  EventDescription aDescription;
101  aDescription.aID = "grid_window";
102  aDescription.aAction = rAction;
103  aDescription.aParameters = std::move(aParameters);
104  aDescription.aParent = "MainWindow";
105  aDescription.aKeyWord = "ScGridWinUIObject";
106 
107  UITestLogger::getInstance().logEvent(aDescription);
108 }
109 }
110 
111 using ::std::vector;
112 using ::std::unique_ptr;
113 
114 bool ScViewFunc::AdjustBlockHeight( bool bPaint, ScMarkData* pMarkData )
115 {
116  ScDocShell* pDocSh = GetViewData().GetDocShell();
117  if (!pMarkData)
118  pMarkData = &GetViewData().GetMarkData();
119 
120  ScDocument& rDoc = pDocSh->GetDocument();
121  std::vector<sc::ColRowSpan> aMarkedRows = pMarkData->GetMarkedRowSpans();
122 
123  if (aMarkedRows.empty())
124  {
125  SCROW nCurRow = GetViewData().GetCurY();
126  aMarkedRows.emplace_back(nCurRow, nCurRow);
127  }
128 
130  {
131  SCCOLROW nStart = aMarkedRows[0].mnStart;
132  OnLOKSetWidthOrHeight(nStart, /*width: */ false);
133  }
134 
135  double nPPTX = GetViewData().GetPPTX();
136  double nPPTY = GetViewData().GetPPTY();
137  Fraction aZoomX = GetViewData().GetZoomX();
138  Fraction aZoomY = GetViewData().GetZoomY();
139 
140  ScSizeDeviceProvider aProv(pDocSh);
141  if (aProv.IsPrinter())
142  {
143  nPPTX = aProv.GetPPTX();
144  nPPTY = aProv.GetPPTY();
145  aZoomX = aZoomY = Fraction( 1, 1 );
146  }
147 
148  sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice());
149  bool bAnyChanged = false;
150  for (const SCTAB& nTab : *pMarkData)
151  {
152  bool bChanged = false;
153  SCROW nPaintY = 0;
154  for (const auto& rRow : aMarkedRows)
155  {
156  SCROW nStartNo = rRow.mnStart;
157  SCROW nEndNo = rRow.mnEnd;
158  ScAddress aTopLeft(0, nStartNo, nTab);
159  rDoc.UpdateScriptTypes(aTopLeft, rDoc.GetSheetLimits().GetMaxColCount(), nEndNo-nStartNo+1);
160  if (rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, true))
161  {
162  if (!bChanged)
163  nPaintY = nStartNo;
164  bAnyChanged = bChanged = true;
165  }
166  }
167  // tdf#76183: recalculate objects' positions
168  if (bChanged)
169  rDoc.SetDrawPageSize(nTab);
170  if ( bPaint && bChanged )
171  pDocSh->PostPaint( 0, nPaintY, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab,
173  }
174 
175  if ( bPaint && bAnyChanged )
176  pDocSh->UpdateOle(GetViewData());
177 
179  {
180  SCTAB nTab = GetViewData().GetTabNo();
182  GetViewData().GetViewShell(),
183  false /* bColumns */, true /* bRows */,
184  true /* bSizes*/, false /* bHidden */, false /* bFiltered */,
185  false /* bGroups */, nTab);
186  ScTabViewShell::notifyAllViewsHeaderInvalidation(GetViewData().GetViewShell(), ROW_HEADER, nTab);
187  }
188 
189  return bAnyChanged;
190 }
191 
192 bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, bool bApi )
193 {
195  {
196  OnLOKSetWidthOrHeight(nStartRow, /*width: */ false);
197  }
198 
199  ScDocShell* pDocSh = GetViewData().GetDocShell();
200  ScDocument& rDoc = pDocSh->GetDocument();
201  SCTAB nTab = GetViewData().GetTabNo();
202  double nPPTX = GetViewData().GetPPTX();
203  double nPPTY = GetViewData().GetPPTY();
204  Fraction aZoomX = GetViewData().GetZoomX();
205  Fraction aZoomY = GetViewData().GetZoomY();
206  sal_uInt16 nOldPixel = 0;
207  if (nStartRow == nEndRow)
208  nOldPixel = static_cast<sal_uInt16>(rDoc.GetRowHeight(nStartRow,nTab) * nPPTY);
209 
210  ScSizeDeviceProvider aProv(pDocSh);
211  if (aProv.IsPrinter())
212  {
213  nPPTX = aProv.GetPPTX();
214  nPPTY = aProv.GetPPTY();
215  aZoomX = aZoomY = Fraction( 1, 1 );
216  }
217  sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice());
218  bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab, bApi);
219 
220  // tdf#76183: recalculate objects' positions
221  if (bChanged)
222  rDoc.SetDrawPageSize(nTab);
223 
224  if (bChanged && ( nStartRow == nEndRow ))
225  {
226  sal_uInt16 nNewPixel = static_cast<sal_uInt16>(rDoc.GetRowHeight(nStartRow,nTab) * nPPTY);
227  if ( nNewPixel == nOldPixel )
228  bChanged = false;
229  }
230 
231  if ( bChanged )
232  pDocSh->PostPaint( 0, nStartRow, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab,
234 
236  {
238  GetViewData().GetViewShell(),
239  false /* bColumns */, true /* bRows */,
240  true /* bSizes*/, false /* bHidden */, false /* bFiltered */,
241  false /* bGroups */, nTab);
242  ScTabViewShell::notifyAllViewsHeaderInvalidation(GetViewData().GetViewShell(), ROW_HEADER, GetViewData().GetTabNo());
243  }
244 
245  return bChanged;
246 }
247 
248 namespace {
249 
251 {
252  ScAutoSumNone = 0,
253  ScAutoSumData,
254  ScAutoSumSum,
255  ScAutoSumAverage,
256  ScAutoSumMax,
257  ScAutoSumMin,
258  ScAutoSumCount,
259  ScAutoSumCountA,
260  ScAutoSumProduct,
261  ScAutoSumStDev,
262  ScAutoSumStDevP,
263  ScAutoSumVar,
264  ScAutoSumVarP,
265  ScAutoSumEnd
266 };
267 
268 }
269 
271  SCTAB nTab, ScDirection eDir, SCCOLROW& nExtend )
272 {
273  ScRefCellValue aCell(rDoc, ScAddress(nCol, nRow, nTab));
274  if (aCell.hasNumeric())
275  {
276  if (aCell.meType == CELLTYPE_FORMULA)
277  {
278  ScAutoSum val = ScAutoSumNone;
279  ScTokenArray* pCode = aCell.mpFormula->GetCode();
280  if ( pCode )
281  {
282  switch( pCode->GetOuterFuncOpCode() )
283  {
284  case ocSum : val = ScAutoSumSum;
285  break;
286  case ocAverage : val = ScAutoSumAverage;
287  break;
288  case ocMax : val = ScAutoSumMax;
289  break;
290  case ocMin : val = ScAutoSumMin;
291  break;
292  case ocCount : val = ScAutoSumCount;
293  break;
294  case ocCount2 : val = ScAutoSumCountA;
295  break;
296  case ocProduct : val = ScAutoSumProduct;
297  break;
298  case ocStDev : val = ScAutoSumStDev;
299  break;
300  case ocStDevP : val = ScAutoSumStDevP;
301  break;
302  case ocVar : val = ScAutoSumVar;
303  break;
304  case ocVarP : val = ScAutoSumVarP;
305  break;
306  default :
307  break;
308  }
309  if ( pCode->GetAdjacentExtendOfOuterFuncRefs( nExtend,
310  ScAddress( nCol, nRow, nTab ), eDir ) )
311  return val;
312  }
313  }
314  return ScAutoSumData;
315  }
316  return ScAutoSumNone;
317 }
318 
319 #define SC_AUTOSUM_MAXCOUNT 20
320 
321 static ScAutoSum lcl_SeekAutoSumData( ScDocument& rDoc, SCCOL& nCol, SCROW& nRow,
322  SCTAB nTab, ScDirection eDir, SCCOLROW& nExtend )
323 {
324  sal_uInt16 nCount = 0;
325  while (nCount < SC_AUTOSUM_MAXCOUNT)
326  {
327  if ( eDir == DIR_TOP )
328  {
329  if (nRow > 0)
330  --nRow;
331  else
332  return ScAutoSumNone;
333  }
334  else
335  {
336  if (nCol > 0)
337  --nCol;
338  else
339  return ScAutoSumNone;
340  }
341  ScAutoSum eSum;
342  if ( (eSum = lcl_IsAutoSumData(
343  rDoc, nCol, nRow, nTab, eDir, nExtend )) != ScAutoSumNone )
344  return eSum;
345  ++nCount;
346  }
347  return ScAutoSumNone;
348 }
349 
350 #undef SC_AUTOSUM_MAXCOUNT
351 
352 static bool lcl_FindNextSumEntryInColumn( ScDocument& rDoc, SCCOL nCol, SCROW& nRow,
353  SCTAB nTab, SCCOLROW& nExtend, SCROW nMinRow )
354 {
355  const SCROW nTmp = nRow;
356  ScAutoSum eSkip = ScAutoSumNone;
357  for (;;)
358  {
359  eSkip = lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_TOP, nExtend );
360  if (eSkip != ScAutoSumData || nRow <= nMinRow )
361  break;
362  --nRow;
363  }
364  return eSkip >= ScAutoSumSum && nRow < nTmp;
365 }
366 
367 static bool lcl_FindNextSumEntryInRow( ScDocument& rDoc, SCCOL& nCol, SCROW nRow,
368  SCTAB nTab, SCCOLROW& nExtend, SCCOL nMinCol )
369 {
370  const SCCOL nTmp = nCol;
371  ScAutoSum eSkip = ScAutoSumNone;
372  for (;;)
373  {
374  eSkip = lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_LEFT, nExtend );
375  if (eSkip != ScAutoSumData || nCol <= nMinCol )
376  break;
377  --nCol;
378  }
379  return eSkip >= ScAutoSumSum && nCol < nTmp;
380 }
381 
382 static ScAutoSum lcl_GetAutoSumForColumnRange( ScDocument& rDoc, ScRangeList& rRangeList, const ScRange& rRange )
383 {
384  const ScAddress aStart = rRange.aStart;
385  const ScAddress aEnd = rRange.aEnd;
386  if ( aStart.Col() != aEnd.Col() )
387  {
388  return ScAutoSumNone;
389  }
390 
391  const SCTAB nTab = aEnd.Tab();
392  const SCCOL nCol = aEnd.Col();
393  SCROW nEndRow = aEnd.Row();
394  SCROW nStartRow = nEndRow;
395  SCCOLROW nExtend = 0;
396  ScAutoSum eSum = lcl_IsAutoSumData( rDoc, nCol, nEndRow, nTab, DIR_TOP, nExtend /*out*/ );
397 
398  if ( eSum >= ScAutoSumSum )
399  {
400  bool bContinue = false;
401  do
402  {
403  rRangeList.push_back( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab ) );
404  nEndRow = static_cast< SCROW >( nExtend );
405  bContinue = lcl_FindNextSumEntryInColumn( rDoc, nCol, nEndRow /*inout*/, nTab, nExtend /*out*/, aStart.Row() );
406  if ( bContinue )
407  {
408  nStartRow = nEndRow;
409  }
410  } while ( bContinue );
411  }
412  else
413  {
414  while ( nStartRow > aStart.Row() )
415  {
416  eSum = lcl_IsAutoSumData( rDoc, nCol, nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ );
417  if (eSum >= ScAutoSumSum )
418  break;
419  --nStartRow;
420  }
421  rRangeList.push_back( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab ) );
422  if (eSum == ScAutoSumNone)
423  eSum = ScAutoSumData;
424  }
425 
426  return eSum;
427 }
428 
429 static ScAutoSum lcl_GetAutoSumForRowRange( ScDocument& rDoc, ScRangeList& rRangeList, const ScRange& rRange )
430 {
431  const ScAddress aStart = rRange.aStart;
432  const ScAddress aEnd = rRange.aEnd;
433  if ( aStart.Row() != aEnd.Row() )
434  {
435  return ScAutoSumNone;
436  }
437 
438  const SCTAB nTab = aEnd.Tab();
439  const SCROW nRow = aEnd.Row();
440  SCCOL nEndCol = aEnd.Col();
441  SCCOL nStartCol = nEndCol;
442  SCCOLROW nExtend = 0;
443  ScAutoSum eSum = lcl_IsAutoSumData( rDoc, nEndCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ );
444 
445  if ( eSum >= ScAutoSumSum )
446  {
447  bool bContinue = false;
448  do
449  {
450  rRangeList.push_back( ScRange( nStartCol, nRow, nTab, nEndCol, nRow, nTab ) );
451  nEndCol = static_cast< SCCOL >( nExtend );
452  bContinue = lcl_FindNextSumEntryInRow( rDoc, nEndCol /*inout*/, nRow, nTab, nExtend /*out*/, aStart.Col() );
453  if ( bContinue )
454  {
455  nStartCol = nEndCol;
456  }
457  } while ( bContinue );
458  }
459  else
460  {
461  while ( nStartCol > aStart.Col() )
462  {
463  eSum = lcl_IsAutoSumData( rDoc, nStartCol-1, nRow, nTab, DIR_LEFT, nExtend /*out*/ );
464  if (eSum >= ScAutoSumSum )
465  break;
466  --nStartCol;
467  }
468  rRangeList.push_back( ScRange( nStartCol, nRow, nTab, nEndCol, nRow, nTab ) );
469  if (eSum == ScAutoSumNone)
470  eSum = ScAutoSumData;
471  }
472 
473  return eSum;
474 }
475 
476 static sal_Int8 GetSubTotal( const OpCode eCode )
477 {
478  sal_Int8 val;
479  switch ( eCode )
480  {
481  case ocSum : val = 9;
482  break;
483  case ocAverage : val = 1;
484  break;
485  case ocMax : val = 4;
486  break;
487  case ocMin : val = 5;
488  break;
489  case ocCount : val = 2;
490  break;
491  case ocCount2 : val = 3;
492  break;
493  case ocProduct : val = 6;
494  break;
495  case ocStDev : val = 7;
496  break;
497  case ocStDevP : val = 8;
498  break;
499  case ocVar : val = 10;
500  break;
501  case ocVarP : val = 11;
502  break;
503  default : val = 9;
504  }
505 
506  return val;
507 }
508 
510 {
511  ScDocument& rDoc = GetViewData().GetDocument();
512  SCTAB nTab = GetViewData().GetTabNo();
513 
514  SCCOL nCol = GetViewData().GetCurX();
515  SCROW nRow = GetViewData().GetCurY();
516 
517  SCCOL nStartCol = nCol;
518  SCROW nStartRow = nRow;
519  SCCOL nEndCol = nCol;
520  SCROW nEndRow = nRow;
521  SCCOL nSeekCol = nCol;
522  SCROW nSeekRow = nRow;
523  SCCOLROW nExtend; // will become valid via reference for ScAutoSumSum
524 
525  bool bCol = false;
526  bool bRow = false;
527 
528  ScAutoSum eSum;
529  if ( nRow != 0
530  && ((eSum = lcl_IsAutoSumData( rDoc, nCol, nRow-1, nTab,
531  DIR_TOP, nExtend /*out*/ )) == ScAutoSumData )
532  && ((eSum = lcl_IsAutoSumData( rDoc, nCol, nRow-1, nTab,
533  DIR_LEFT, nExtend /*out*/ )) == ScAutoSumData )
534  )
535  {
536  bRow = true;
537  nSeekRow = nRow - 1;
538  }
539  else if ( nCol != 0 && (eSum = lcl_IsAutoSumData( rDoc, nCol-1, nRow, nTab,
540  DIR_LEFT, nExtend /*out*/ )) == ScAutoSumData )
541  {
542  bCol = true;
543  nSeekCol = nCol - 1;
544  }
545  else if ( (eSum = lcl_SeekAutoSumData( rDoc, nCol, nSeekRow, nTab, DIR_TOP, nExtend /*out*/ )) != ScAutoSumNone )
546  bRow = true;
547  else if (( eSum = lcl_SeekAutoSumData( rDoc, nSeekCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ )) != ScAutoSumNone )
548  bCol = true;
549 
550  if ( bCol || bRow )
551  {
552  if ( bRow )
553  {
554  nStartRow = nSeekRow; // nSeekRow might be adjusted via reference
555  if ( eSum >= ScAutoSumSum && eSum < ScAutoSumEnd )
556  nEndRow = nStartRow; // only sum sums
557  else
558  nEndRow = nRow - 1; // maybe extend data area at bottom
559  }
560  else
561  {
562  nStartCol = nSeekCol; // nSeekCol might be adjusted via reference
563  if ( eSum >= ScAutoSumSum )
564  nEndCol = nStartCol; // only sum sums
565  else
566  nEndCol = nCol - 1; // maybe extend data area to the right
567  }
568  bool bContinue = false;
569  do
570  {
571  if ( eSum == ScAutoSumData )
572  {
573  if ( bRow )
574  {
575  while ( nStartRow != 0 && lcl_IsAutoSumData( rDoc, nCol,
576  nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ ) == eSum )
577  --nStartRow;
578  }
579  else
580  {
581  while ( nStartCol != 0 && lcl_IsAutoSumData( rDoc, nStartCol-1,
582  nRow, nTab, DIR_LEFT, nExtend /*out*/ ) == eSum )
583  --nStartCol;
584  }
585  }
586  rRangeList.push_back(
587  ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab ) );
588  if ( eSum >= ScAutoSumSum )
589  {
590  if ( bRow )
591  {
592  nEndRow = static_cast< SCROW >( nExtend );
593  bContinue = lcl_FindNextSumEntryInColumn( rDoc, nCol, nEndRow /*inout*/, nTab, nExtend /*out*/, 0 );
594  if ( bContinue )
595  {
596  nStartRow = nEndRow;
597  }
598  }
599  else
600  {
601  nEndCol = static_cast< SCCOL >( nExtend );
602  bContinue = lcl_FindNextSumEntryInRow( rDoc, nEndCol /*inout*/, nRow, nTab, nExtend /*out*/, 0 );
603  if ( bContinue )
604  {
605  nStartCol = nEndCol;
606  }
607  }
608  }
609  } while ( bContinue );
610  return true;
611  }
612  return false;
613 }
614 
615 void ScViewFunc::EnterAutoSum(const ScRangeList& rRangeList, bool bSubTotal, const ScAddress& rAddr, const OpCode eCode)
616 {
617  OUString aFormula = GetAutoSumFormula( rRangeList, bSubTotal, rAddr , eCode);
618  EnterBlock( aFormula, nullptr );
619 }
620 
621 bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor, bool bContinue , const OpCode eCode)
622 {
623  ScDocument& rDoc = GetViewData().GetDocument();
624  const SCTAB nTab = rRange.aStart.Tab();
625  SCCOL nStartCol = rRange.aStart.Col();
626  SCROW nStartRow = rRange.aStart.Row();
627  const SCCOL nEndCol = rRange.aEnd.Col();
628  const SCROW nEndRow = rRange.aEnd.Row();
629  SCCOLROW nExtend = 0; // out parameter for lcl_IsAutoSumData
630 
631  // ignore rows at the top of the given range which don't contain autosum data
632  bool bRowData = false;
633  for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
634  {
635  for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
636  {
637  if ( lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_TOP, nExtend ) != ScAutoSumNone )
638  {
639  bRowData = true;
640  break;
641  }
642  }
643  if ( bRowData )
644  {
645  nStartRow = nRow;
646  break;
647  }
648  }
649  if ( !bRowData )
650  {
651  return false;
652  }
653 
654  // ignore columns at the left of the given range which don't contain autosum data
655  bool bColData = false;
656  for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
657  {
658  for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
659  {
660  if ( lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_LEFT, nExtend ) != ScAutoSumNone )
661  {
662  bColData = true;
663  break;
664  }
665  }
666  if ( bColData )
667  {
668  nStartCol = nCol;
669  break;
670  }
671  }
672  if ( !bColData )
673  {
674  return false;
675  }
676 
677  const bool bEndRowEmpty = rDoc.IsBlockEmpty( nTab, nStartCol, nEndRow, nEndCol, nEndRow );
678  const bool bEndColEmpty = rDoc.IsBlockEmpty( nTab, nEndCol, nStartRow, nEndCol, nEndRow );
679  bool bRow = ( nStartRow != nEndRow ) && ( bEndRowEmpty || !bEndColEmpty );
680  bool bCol = ( nStartCol != nEndCol ) && ( bEndColEmpty || nStartRow == nEndRow );
681 
682  // find an empty row for entering the result
683  SCROW nInsRow = nEndRow;
684  if ( bRow && !bEndRowEmpty )
685  {
686  if ( nInsRow < rDoc.MaxRow() )
687  {
688  ++nInsRow;
689  while ( !rDoc.IsBlockEmpty( nTab, nStartCol, nInsRow, nEndCol, nInsRow ) )
690  {
691  if ( nInsRow < rDoc.MaxRow() )
692  {
693  ++nInsRow;
694  }
695  else
696  {
697  bRow = false;
698  break;
699  }
700  }
701  }
702  else
703  {
704  bRow = false;
705  }
706  }
707 
708  // find an empty column for entering the result
709  SCCOL nInsCol = nEndCol;
710  if ( bCol && !bEndColEmpty )
711  {
712  if ( nInsCol < rDoc.MaxCol() )
713  {
714  ++nInsCol;
715  while ( !rDoc.IsBlockEmpty( nTab, nInsCol, nStartRow, nInsCol, nEndRow ) )
716  {
717  if ( nInsCol < rDoc.MaxCol() )
718  {
719  ++nInsCol;
720  }
721  else
722  {
723  bCol = false;
724  break;
725  }
726  }
727  }
728  else
729  {
730  bCol = false;
731  }
732  }
733 
734  if ( !bRow && !bCol )
735  {
736  return false;
737  }
738 
739  SCCOL nMarkEndCol = nEndCol;
740  SCROW nMarkEndRow = nEndRow;
741  ScAutoSum eSum = ScAutoSumNone;
742  SCROW nColSums = 0;
743  SCCOL nRowSums = 0;
744  SCROW nColSumsStartRow = 0;
745  SCCOL nRowSumsStartCol = 0;
746 
747  if ( bRow )
748  {
749  // calculate the row sums for all columns of the given range
750 
751  SCROW nSumEndRow = nEndRow;
752 
753  if ( bEndRowEmpty )
754  {
755  // the last row of the given range is empty;
756  // don't take into account for calculating the autosum
757  --nSumEndRow;
758  }
759  else
760  {
761  // increase mark range
762  ++nMarkEndRow;
763  }
764 
765  for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
766  {
767  if ( !rDoc.IsBlockEmpty( nTab, nCol, nStartRow, nCol, nSumEndRow ) )
768  {
769  ScRangeList aRangeList;
770  // Include the originally selected start row.
771  const ScRange aRange( nCol, rRange.aStart.Row(), nTab, nCol, nSumEndRow, nTab );
772  if ( (eSum = lcl_GetAutoSumForColumnRange( rDoc, aRangeList, aRange )) != ScAutoSumNone )
773  {
774  if (++nRowSums == 1)
775  nRowSumsStartCol = aRangeList[0].aStart.Col();
776  const OUString aFormula = GetAutoSumFormula(
777  aRangeList, bSubTotal, ScAddress(nCol, nInsRow, nTab), eCode);
778  EnterData( nCol, nInsRow, nTab, aFormula );
779  }
780  }
781  }
782  }
783 
784  if ( bCol )
785  {
786  // calculate the column sums for all rows of the given range
787 
788  SCCOL nSumEndCol = nEndCol;
789 
790  if ( bEndColEmpty )
791  {
792  // the last column of the given range is empty;
793  // don't take into account for calculating the autosum
794  --nSumEndCol;
795  }
796  else
797  {
798  // increase mark range
799  ++nMarkEndCol;
800  }
801 
802  for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
803  {
804  if ( !rDoc.IsBlockEmpty( nTab, nStartCol, nRow, nSumEndCol, nRow ) )
805  {
806  ScRangeList aRangeList;
807  // Include the originally selected start column.
808  const ScRange aRange( rRange.aStart.Col(), nRow, nTab, nSumEndCol, nRow, nTab );
809  if ( (eSum = lcl_GetAutoSumForRowRange( rDoc, aRangeList, aRange )) != ScAutoSumNone )
810  {
811  if (++nColSums == 1)
812  nColSumsStartRow = aRangeList[0].aStart.Row();
813  const OUString aFormula = GetAutoSumFormula( aRangeList, bSubTotal, ScAddress(nInsCol, nRow, nTab), eCode );
814  EnterData( nInsCol, nRow, nTab, aFormula );
815  }
816  }
817  }
818  }
819 
820  // Set new mark range and cursor position.
821  // For sum of sums (and data until sum) mark the actual resulting range if
822  // there is only one, or the data range if more than one. Otherwise use the
823  // original selection. All extended by end column/row where the sum is put.
824  const ScRange aMarkRange(
825  (eSum >= ScAutoSumSum ?
826  (nRowSums == 1 ? nRowSumsStartCol : nStartCol) :
827  rRange.aStart.Col()),
828  (eSum >= ScAutoSumSum ?
829  (nColSums == 1 ? nColSumsStartRow : nStartRow) :
830  rRange.aStart.Row()),
831  nTab, nMarkEndCol, nMarkEndRow, nTab );
832  MarkRange( aMarkRange, false, bContinue );
833  if ( bSetCursor )
834  {
835  SetCursor( nMarkEndCol, nMarkEndRow );
836  }
837 
838  return true;
839 }
840 
841 OUString ScViewFunc::GetAutoSumFormula( const ScRangeList& rRangeList, bool bSubTotal, const ScAddress& rAddr , const OpCode eCode)
842 {
843  ScViewData& rViewData = GetViewData();
844  ScDocument& rDoc = rViewData.GetDocument();
845  ScTokenArray aArray(rDoc);
846 
847  aArray.AddOpCode(bSubTotal ? ocSubTotal : eCode);
848  aArray.AddOpCode(ocOpen);
849 
850  if (bSubTotal)
851  {
852  aArray.AddDouble( GetSubTotal( eCode ) );
853  aArray.AddOpCode(ocSep);
854  }
855 
856  if(!rRangeList.empty())
857  {
858  ScRangeList aRangeList = rRangeList;
859  size_t ListSize = aRangeList.size();
860  for ( size_t i = 0; i < ListSize; ++i )
861  {
862  const ScRange & r = aRangeList[i];
863  if (i != 0)
864  aArray.AddOpCode(ocSep);
865  ScComplexRefData aRef;
866  aRef.InitRangeRel(rDoc, r, rAddr);
867  aArray.AddDoubleReference(aRef);
868  }
869  }
870 
871  aArray.AddOpCode(ocClose);
872 
873  ScCompiler aComp(rDoc, rAddr, aArray, rDoc.GetGrammar());
874  OUStringBuffer aBuf;
875  aComp.CreateStringFromTokenArray(aBuf);
876  OUString aFormula = aBuf.makeStringAndClear();
877  aBuf.append('=');
878  aBuf.append(aFormula);
879  return aBuf.makeStringAndClear();
880 }
881 
882 void ScViewFunc::EnterBlock( const OUString& rString, const EditTextObject* pData )
883 {
884  // test for multi selection
885 
886  SCCOL nCol = GetViewData().GetCurX();
887  SCROW nRow = GetViewData().GetCurY();
888  SCTAB nTab = GetViewData().GetTabNo();
889  ScMarkData& rMark = GetViewData().GetMarkData();
890  if ( rMark.IsMultiMarked() )
891  {
892  rMark.MarkToSimple();
893  if ( rMark.IsMultiMarked() )
894  { // "Insert into multi selection not possible"
895  ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
896 
897  // insert into single cell
898  if ( pData )
899  EnterData(nCol, nRow, nTab, *pData);
900  else
901  EnterData( nCol, nRow, nTab, rString );
902  return;
903  }
904  }
905 
906  if (GetViewData().SelectionForbidsCellFill())
907  {
908  PaintArea(nCol, nRow, nCol, nRow); // possibly the edit-engine is still painted there
909  return;
910  }
911 
912  ScDocument& rDoc = GetViewData().GetDocument();
913  OUString aNewStr = rString;
914  if ( pData )
915  {
916  const ScPatternAttr* pOldPattern = rDoc.GetPattern( nCol, nRow, nTab );
917  ScTabEditEngine aEngine( *pOldPattern, rDoc.GetEnginePool(), &rDoc );
918  aEngine.SetTextCurrentDefaults(*pData);
919 
920  ScEditAttrTester aTester( &aEngine );
921  if (!aTester.NeedsObject())
922  {
923  aNewStr = aEngine.GetText();
924  pData = nullptr;
925  }
926  }
927 
928  // Insert via PasteFromClip
929  weld::WaitObject aWait(GetViewData().GetDialogParent());
930 
931  ScAddress aPos( nCol, nRow, nTab );
932 
934  pInsDoc->ResetClip( &rDoc, nTab );
935 
936  if (aNewStr[0] == '=') // Formula ?
937  {
938  // SetString not possible, because in Clipboard-Documents nothing will be compiled!
939  pInsDoc->SetFormulaCell(aPos, new ScFormulaCell(rDoc, aPos, aNewStr));
940  }
941  else if ( pData )
942  {
943  // A copy of pData will be stored.
944  pInsDoc->SetEditText(aPos, *pData, rDoc.GetEditPool());
945  }
946  else
947  pInsDoc->SetString( nCol, nRow, nTab, aNewStr );
948 
949  pInsDoc->SetClipArea( ScRange(aPos) );
950  // insert Block, with Undo etc.
951  if ( !PasteFromClip( InsertDeleteFlags::CONTENTS, pInsDoc.get(), ScPasteFunc::NONE, false, false,
953  return;
954 
955  const SfxUInt32Item* pItem = pInsDoc->GetAttr(
956  nCol, nRow, nTab, ATTR_VALUE_FORMAT );
957  if ( pItem )
958  { // set number format if incompatible
959  // MarkData was already MarkToSimple'ed in PasteFromClip
960  ScRange aRange;
961  rMark.GetMarkArea( aRange );
962  ScPatternAttr aPattern( rDoc.GetPool() );
963  aPattern.GetItemSet().Put( *pItem );
964  SvNumFormatType nNewType = rDoc.GetFormatTable()->GetType( pItem->GetValue() );
965  rDoc.ApplyPatternIfNumberformatIncompatible( aRange, rMark,
966  aPattern, nNewType );
967  }
968 }
969 
970 // manual page break
971 
972 void ScViewFunc::InsertPageBreak( bool bColumn, bool bRecord, const ScAddress* pPos,
973  bool bSetModified )
974 {
975  SCTAB nTab = GetViewData().GetTabNo();
976  ScAddress aCursor;
977  if (pPos)
978  aCursor = *pPos;
979  else
980  aCursor = ScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
981 
982  bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
983  InsertPageBreak( bColumn, aCursor, bRecord, bSetModified );
984 
985  if ( bSuccess && bSetModified )
986  UpdatePageBreakData( true ); // for PageBreak-Mode
987 }
988 
989 void ScViewFunc::DeletePageBreak( bool bColumn, bool bRecord, const ScAddress* pPos,
990  bool bSetModified )
991 {
992  SCTAB nTab = GetViewData().GetTabNo();
993  ScAddress aCursor;
994  if (pPos)
995  aCursor = *pPos;
996  else
997  aCursor = ScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
998 
999  bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
1000  RemovePageBreak( bColumn, aCursor, bRecord, bSetModified );
1001 
1002  if ( bSuccess && bSetModified )
1003  UpdatePageBreakData( true ); // for PageBreak-Mode
1004 }
1005 
1007 {
1008  ScDocShell* pDocSh = GetViewData().GetDocShell();
1009  ScDocument& rDoc = pDocSh->GetDocument();
1010  SCTAB nTab = GetViewData().GetTabNo();
1011  bool bUndo(rDoc.IsUndoEnabled());
1012 
1013  if (bUndo)
1014  {
1016  pUndoDoc->InitUndo( rDoc, nTab, nTab, true, true );
1017  rDoc.CopyToDocument( 0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc );
1018  pDocSh->GetUndoManager()->AddUndoAction(
1019  std::make_unique<ScUndoRemoveBreaks>( pDocSh, nTab, std::move(pUndoDoc) ) );
1020  }
1021 
1022  rDoc.RemoveManualBreaks(nTab);
1023  rDoc.UpdatePageBreaks(nTab);
1024 
1025  UpdatePageBreakData( true );
1026  pDocSh->SetDocumentModified();
1027  pDocSh->PostPaint( 0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, PaintPartFlags::Grid );
1028 }
1029 
1030 void ScViewFunc::SetPrintZoom(sal_uInt16 nScale)
1031 {
1032  ScDocShell* pDocSh = GetViewData().GetDocShell();
1033  SCTAB nTab = GetViewData().GetTabNo();
1034  pDocSh->SetPrintZoom( nTab, nScale, 0/*nPages*/ );
1035 }
1036 
1038 {
1039  ScRange aRange;
1040  if ( GetViewData().GetSimpleArea( aRange ) != SC_MARK_SIMPLE )
1041  GetViewData().GetMarkData().GetMultiMarkArea( aRange );
1042  GetViewData().GetDocShell()->AdjustPrintZoom( aRange );
1043 }
1044 
1045 void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint,
1046  const OUString* pRepCol, const OUString* pRepRow,
1047  bool bAddPrint )
1048 {
1049  // on all selected tables
1050 
1051  ScDocShell* pDocSh = GetViewData().GetDocShell();
1052  ScDocument& rDoc = pDocSh->GetDocument();
1053  ScMarkData& rMark = GetViewData().GetMarkData();
1054  bool bUndo (rDoc.IsUndoEnabled());
1055 
1056  std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
1057 
1058  ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0);
1059 
1060  for (const SCTAB& nTab : rMark)
1061  {
1062  ScRange aRange( 0,0,nTab );
1063 
1064  // print ranges
1065 
1066  if( !bAddPrint )
1067  rDoc.ClearPrintRanges( nTab );
1068 
1069  if( bEntireSheet )
1070  {
1071  rDoc.SetPrintEntireSheet( nTab );
1072  }
1073  else if ( pPrint )
1074  {
1075  if ( !pPrint->isEmpty() )
1076  {
1078  sal_Int32 nPos = 0;
1079  do
1080  {
1081  const OUString aToken = pPrint->getToken(0, sep, nPos);
1082  if ( aRange.ParseAny( aToken, rDoc, aDetails ) & ScRefFlags::VALID )
1083  rDoc.AddPrintRange( nTab, aRange );
1084  }
1085  while (nPos >= 0);
1086  }
1087  }
1088  else // NULL = use selection (print range is always set), use empty string to delete all ranges
1089  {
1090  if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
1091  {
1092  rDoc.AddPrintRange( nTab, aRange );
1093  }
1094  else if ( rMark.IsMultiMarked() )
1095  {
1096  rMark.MarkToMulti();
1097  ScRangeListRef pList( new ScRangeList );
1098  rMark.FillRangeListWithMarks( pList.get(), false );
1099  for (size_t i = 0, n = pList->size(); i < n; ++i)
1100  {
1101  const ScRange & rR = (*pList)[i];
1102  rDoc.AddPrintRange(nTab, rR);
1103  }
1104  }
1105  }
1106 
1107  // repeat columns
1108 
1109  if ( pRepCol )
1110  {
1111  if ( pRepCol->isEmpty() )
1112  rDoc.SetRepeatColRange( nTab, nullptr );
1113  else
1114  if ( aRange.ParseAny( *pRepCol, rDoc, aDetails ) & ScRefFlags::VALID )
1115  rDoc.SetRepeatColRange( nTab, std::unique_ptr<ScRange>(new ScRange(aRange)) );
1116  }
1117 
1118  // repeat rows
1119 
1120  if ( pRepRow )
1121  {
1122  if ( pRepRow->isEmpty() )
1123  rDoc.SetRepeatRowRange( nTab, nullptr );
1124  else
1125  if ( aRange.ParseAny( *pRepRow, rDoc, aDetails ) & ScRefFlags::VALID )
1126  rDoc.SetRepeatRowRange( nTab, std::unique_ptr<ScRange>(new ScRange(aRange)) );
1127  }
1128  }
1129 
1130  // undo (for all tables)
1131  if (bUndo)
1132  {
1133  SCTAB nCurTab = GetViewData().GetTabNo();
1134  std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver();
1135  pDocSh->GetUndoManager()->AddUndoAction(
1136  std::make_unique<ScUndoPrintRange>( pDocSh, nCurTab, std::move(pOldRanges), std::move(pNewRanges) ) );
1137  }
1138  else
1139  pOldRanges.reset();
1140 
1141  // update page breaks
1142 
1143  for (const auto& rTab : rMark)
1144  ScPrintFunc( pDocSh, pDocSh->GetPrinter(), rTab ).UpdatePages();
1145 
1146  SfxBindings& rBindings = GetViewData().GetBindings();
1147  rBindings.Invalidate( SID_DELETE_PRINTAREA );
1148 
1149  pDocSh->SetDocumentModified();
1150 }
1151 
1152 // Merge cells
1153 
1154 bool ScViewFunc::TestMergeCells() // pre-test (for menu)
1155 {
1156  // simple test: true if there's a selection but no multi selection and not filtered
1157 
1158  const ScMarkData& rMark = GetViewData().GetMarkData();
1159  if ( rMark.IsMarked() || rMark.IsMultiMarked() )
1160  {
1161  ScRange aRange;
1162  bool bMergeable = ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE );
1163  bMergeable = bMergeable && ( aRange.aStart.Col() != aRange.aEnd.Col() ||
1164  aRange.aStart.Row() != aRange.aEnd.Row() );
1165  return bMergeable;
1166  }
1167  else
1168  return false;
1169 }
1170 
1171 bool ScViewFunc::MergeCells( bool bApi, bool& rDoContents, bool bCenter )
1172 {
1173  // Editable- and Being-Nested- test must be at the beginning (in DocFunc too),
1174  // so that the Contents-QueryBox won't appear
1175  ScEditableTester aTester( this );
1176  if (!aTester.IsEditable())
1177  {
1178  ErrorMessage(aTester.GetMessageId());
1179  return false;
1180  }
1181 
1182  ScMarkData& rMark = GetViewData().GetMarkData();
1183  rMark.MarkToSimple();
1184  if (!rMark.IsMarked())
1185  {
1186  ErrorMessage(STR_NOMULTISELECT);
1187  return false;
1188  }
1189 
1190  ScDocShell* pDocSh = GetViewData().GetDocShell();
1191  ScDocument& rDoc = pDocSh->GetDocument();
1192 
1193  ScRange aMarkRange;
1194  rMark.GetMarkArea( aMarkRange );
1195  SCCOL nStartCol = aMarkRange.aStart.Col();
1196  SCROW nStartRow = aMarkRange.aStart.Row();
1197  SCTAB nStartTab = aMarkRange.aStart.Tab();
1198  SCCOL nEndCol = aMarkRange.aEnd.Col();
1199  SCROW nEndRow = aMarkRange.aEnd.Row();
1200  SCTAB nEndTab = aMarkRange.aEnd.Tab();
1201  if ( nStartCol == nEndCol && nStartRow == nEndRow )
1202  {
1203  // nothing to do
1204  return true;
1205  }
1206 
1207  if ( rDoc.HasAttrib( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
1209  { // "Don't nest merging !"
1210  ErrorMessage(STR_MSSG_MERGECELLS_0);
1211  return false;
1212  }
1213 
1214  // Check for the contents of all selected tables.
1215  bool bAskDialog = false;
1216  ScCellMergeOption aMergeOption(nStartCol, nStartRow, nEndCol, nEndRow, bCenter);
1217  for (const SCTAB& i : rMark)
1218  {
1219  aMergeOption.maTabs.insert(i);
1220 
1221  sc::MultiDataCellState aState = rDoc.HasMultipleDataCells(aMergeOption.getSingleRange(i));
1222  switch (aState.meState)
1223  {
1225  {
1226  // this range contains multiple data cells.
1227  bAskDialog = true;
1228  break;
1229  }
1231  {
1232  // this range contains only one data cell.
1233  if (nStartCol != aState.mnCol1 || nStartRow != aState.mnRow1)
1234  rDoContents = true; // move the value to the top-left.
1235  break;
1236  }
1237  default:
1238  ;
1239  }
1240  }
1241 
1242  bool bOk = true;
1243  bool bEmptyMergedCells = officecfg::Office::Calc::Compatibility::MergeCells::EmptyMergedCells::get();
1244 
1245  if (bAskDialog)
1246  {
1247  bool bShowDialog = officecfg::Office::Calc::Compatibility::MergeCells::ShowDialog::get();
1248  if (!bApi && bShowDialog)
1249  {
1250  ScMergeCellsDialog aBox(GetViewData().GetDialogParent());
1251  sal_uInt16 nRetVal = aBox.run();
1252 
1253  if ( nRetVal == RET_OK )
1254  {
1255  switch (aBox.GetMergeCellsOption())
1256  {
1258  rDoContents = true;
1259  break;
1261  bEmptyMergedCells = false;
1262  break;
1264  bEmptyMergedCells = true;
1265  break;
1266  default:
1267  assert(!"Unknown option for merge cells.");
1268  break;
1269  }
1270  }
1271  else if ( nRetVal == RET_CANCEL )
1272  bOk = false;
1273  }
1274  }
1275 
1276  if (bOk)
1277  {
1278  bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, true/*bRecord*/, bApi, bEmptyMergedCells );
1279 
1280  if (bOk)
1281  {
1282  SetCursor( nStartCol, nStartRow );
1283  //DoneBlockMode( sal_False);
1284  Unmark();
1285 
1286  pDocSh->UpdateOle(GetViewData());
1287  UpdateInputLine();
1288 
1289  OUString aStartAddress = aMarkRange.aStart.GetColRowString();
1290  OUString aEndAddress = aMarkRange.aEnd.GetColRowString();
1291 
1292  collectUIInformation({{"RANGE", aStartAddress + ":" + aEndAddress}}, "MERGE_CELLS");
1293  }
1294  }
1295 
1296  return bOk;
1297 }
1298 
1300 {
1301  bool bMerged = false;
1302  ScRange aRange;
1303  if (GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1304  {
1305  ScDocument& rDoc = GetViewData().GetDocument();
1306  if ( rDoc.HasAttrib( aRange, HasAttrFlags::Merged ) )
1307  bMerged = true;
1308  }
1309  return bMerged;
1310 }
1311 
1312 static bool lcl_extendMergeRange(ScCellMergeOption& rOption, const ScRange& rRange)
1313 {
1314  bool bExtended = false;
1315  if (rOption.mnStartCol > rRange.aStart.Col())
1316  {
1317  rOption.mnStartCol = rRange.aStart.Col();
1318  bExtended = true;
1319  }
1320  if (rOption.mnStartRow > rRange.aStart.Row())
1321  {
1322  rOption.mnStartRow = rRange.aStart.Row();
1323  bExtended = true;
1324  }
1325  if (rOption.mnEndCol < rRange.aEnd.Col())
1326  {
1327  rOption.mnEndCol = rRange.aEnd.Col();
1328  bExtended = true;
1329  }
1330  if (rOption.mnEndRow < rRange.aEnd.Row())
1331  {
1332  rOption.mnEndRow = rRange.aEnd.Row();
1333  bExtended = true;
1334  }
1335  return bExtended;
1336 }
1337 
1339 {
1340  ScRange aRange;
1341  ScEditableTester aTester( this );
1342  if (!aTester.IsEditable())
1343  {
1344  ErrorMessage(aTester.GetMessageId());
1345  return false;
1346  }
1347  else if (GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1348  {
1349  ScDocument& rDoc = GetViewData().GetDocument();
1350  ScRange aExtended( aRange );
1351  rDoc.ExtendMerge( aExtended );
1352  ScDocShell* pDocSh = GetViewData().GetDocShell();
1353  const ScMarkData& rMark = GetViewData().GetMarkData();
1354  ScCellMergeOption aOption(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row());
1355  bool bExtended = false;
1356  do
1357  {
1358  bExtended = false;
1359  for (const SCTAB& i : rMark)
1360  {
1361  aOption.maTabs.insert(i);
1362  aExtended.aStart.SetTab(i);
1363  aExtended.aEnd.SetTab(i);
1364  rDoc.ExtendMerge(aExtended);
1365  rDoc.ExtendOverlapped(aExtended);
1366 
1367  // Expand the current range to be inclusive of all merged
1368  // areas on all sheets.
1369  bExtended = lcl_extendMergeRange(aOption, aExtended);
1370  }
1371  }
1372  while (bExtended);
1373 
1374  bool bOk = pDocSh->GetDocFunc().UnmergeCells(aOption, true/*bRecord*/, nullptr);
1375  aExtended = aOption.getFirstSingleRange();
1376  MarkRange( aExtended );
1377 
1378  if (bOk)
1379  pDocSh->UpdateOle(GetViewData());
1380  }
1381 
1382  OUString aCellLocation = aRange.aStart.GetColRowString();
1383  collectUIInformation({{"CELL", aCellLocation}}, "UNMERGE_CELL");
1384 
1385  return true;
1386 }
1387 
1389 {
1390  ScRange aRange;
1391  if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1392  {
1393  ScDocShell* pDocSh = GetViewData().GetDocShell();
1394  const ScMarkData& rMark = GetViewData().GetMarkData();
1395  bool bSuccess = pDocSh->GetDocFunc().FillSimple( aRange, &rMark, eDir, false );
1396  if (bSuccess)
1397  {
1398  pDocSh->UpdateOle(GetViewData());
1399  UpdateScrollBars();
1400 
1401  auto& rDoc = pDocSh->GetDocument();
1402  bool bDoAutoSpell = rDoc.GetDocOptions().IsAutoSpell();
1403  if ( bDoAutoSpell )
1404  {
1405  // Copy AutoSpellData from above(left/right/below) if no selection.
1406  switch (eDir)
1407  {
1408  case FILL_TO_BOTTOM:
1409  if (aRange.aStart.Row() > 0 && aRange.aStart.Row() == aRange.aEnd.Row())
1410  aRange.aStart.IncRow(-1);
1411  break;
1412  case FILL_TO_TOP:
1413  if (aRange.aEnd.Row() < rDoc.MaxRow() && aRange.aStart.Row() == aRange.aEnd.Row())
1414  aRange.aEnd.IncRow(1);
1415  break;
1416  case FILL_TO_RIGHT:
1417  if (aRange.aStart.Col() > 0 && aRange.aStart.Col() == aRange.aEnd.Col())
1418  aRange.aStart.IncCol(-1);
1419  break;
1420  case FILL_TO_LEFT:
1421  if (aRange.aEnd.Col() < rDoc.MaxCol() && aRange.aStart.Col() == aRange.aEnd.Col())
1422  aRange.aEnd.IncCol(1);
1423  break;
1424  }
1425  CopyAutoSpellData(eDir, aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(),
1426  ::std::numeric_limits<sal_uLong>::max());
1427  }
1428 
1429  // Invalidate cell slots and update input line with new content.
1430  CellContentChanged();
1431  }
1432  }
1433  else
1434  ErrorMessage(STR_NOMULTISELECT);
1435 }
1436 
1438  double fStart, double fStep, double fMax )
1439 {
1440  ScRange aRange;
1441  if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1442  {
1443  ScDocShell* pDocSh = GetViewData().GetDocShell();
1444  const ScMarkData& rMark = GetViewData().GetMarkData();
1445  bool bSuccess = pDocSh->GetDocFunc().
1446  FillSeries( aRange, &rMark, eDir, eCmd, eDateCmd,
1447  fStart, fStep, fMax, false );
1448  if (bSuccess)
1449  {
1450  pDocSh->UpdateOle(GetViewData());
1451  UpdateScrollBars();
1452 
1454  }
1455  }
1456  else
1457  ErrorMessage(STR_NOMULTISELECT);
1458 }
1459 
1460 void ScViewFunc::FillAuto( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
1461  SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount )
1462 {
1463  SCTAB nTab = GetViewData().GetTabNo();
1464  ScRange aRange( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab );
1465  ScRange aSourceRange( aRange );
1466  ScDocShell* pDocSh = GetViewData().GetDocShell();
1467  const ScMarkData& rMark = GetViewData().GetMarkData();
1468  bool bSuccess = pDocSh->GetDocFunc().
1469  FillAuto( aRange, &rMark, eDir, nCount, false );
1470  if (!bSuccess)
1471  return;
1472 
1473  MarkRange( aRange, false ); // aRange was modified in FillAuto
1474  pDocSh->UpdateOle(GetViewData());
1475  UpdateScrollBars();
1476 
1477  bool bDoAutoSpell = pDocSh->GetDocument().GetDocOptions().IsAutoSpell();
1478  if ( bDoAutoSpell )
1479  CopyAutoSpellData(eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount);
1480 
1482  if (!pModelObj)
1483  return;
1484 
1485  ScRangeList aChangeRanges;
1486  ScRange aChangeRange( aRange );
1487  switch (eDir)
1488  {
1489  case FILL_TO_BOTTOM:
1490  aChangeRange.aStart.SetRow( aSourceRange.aEnd.Row() + 1 );
1491  break;
1492  case FILL_TO_TOP:
1493  aChangeRange.aEnd.SetRow( aSourceRange.aStart.Row() - 1 );
1494  break;
1495  case FILL_TO_RIGHT:
1496  aChangeRange.aStart.SetCol( aSourceRange.aEnd.Col() + 1 );
1497  break;
1498  case FILL_TO_LEFT:
1499  aChangeRange.aEnd.SetCol( aSourceRange.aStart.Col() - 1 );
1500  break;
1501  default:
1502  break;
1503  }
1504  aChangeRanges.push_back( aChangeRange );
1505  HelperNotifyChanges::Notify(*pModelObj, aChangeRanges);
1506 }
1507 
1508 void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
1509  SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount )
1510 {
1511  const ScDocument* pDoc = &GetViewData().GetDocument();
1512  SCTAB nTab = GetViewData().GetTabNo();
1513  CellType eCellType;
1514 
1515  ScGridWindow* pWin = GetActiveWin();
1516  if ( pWin->InsideVisibleRange(nStartCol, nStartRow) && pWin->InsideVisibleRange(nEndCol, nEndRow) )
1517  {
1518  if ( nCount == ::std::numeric_limits<sal_uLong>::max() )
1519  {
1520  switch( eDir )
1521  {
1522  case FILL_TO_BOTTOM:
1523  for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1524  {
1525  eCellType = pDoc->GetCellType(nColItr, nStartRow, nTab); // We need this optimization only for EditTextObject source cells
1526  if (eCellType != CELLTYPE_EDIT)
1527  continue;
1528 
1529  const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nColItr, nStartRow);
1530  if ( !pRanges )
1531  continue;
1532  for ( SCROW nRowItr = nStartRow + 1; nRowItr <= nEndRow; ++nRowItr )
1533  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1534  }
1535  break;
1536  case FILL_TO_TOP:
1537  for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1538  {
1539  eCellType = pDoc->GetCellType(nColItr, nEndRow, nTab); // We need this optimization only for EditTextObject source cells
1540  if (eCellType != CELLTYPE_EDIT)
1541  continue;
1542 
1543  const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nColItr, nEndRow);
1544  if ( !pRanges )
1545  continue;
1546  for ( SCROW nRowItr = nEndRow - 1; nRowItr >= nStartRow; --nRowItr )
1547  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1548  }
1549  break;
1550  case FILL_TO_RIGHT:
1551  for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1552  {
1553  eCellType = pDoc->GetCellType(nStartCol, nRowItr, nTab); // We need this optimization only for EditTextObject source cells
1554  if (eCellType != CELLTYPE_EDIT)
1555  continue;
1556 
1557  const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nStartCol, nRowItr);
1558  if ( !pRanges )
1559  continue;
1560  for ( SCCOL nColItr = nStartCol + 1; nColItr <= nEndCol; ++nColItr )
1561  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1562  }
1563  break;
1564  case FILL_TO_LEFT:
1565  for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1566  {
1567  eCellType = pDoc->GetCellType(nEndCol, nRowItr, nTab); // We need this optimization only for EditTextObject source cells
1568  if (eCellType != CELLTYPE_EDIT)
1569  continue;
1570 
1571  const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nEndCol, nRowItr);
1572  if ( !pRanges )
1573  continue;
1574  for ( SCCOL nColItr = nEndCol - 1; nColItr >= nStartCol; --nColItr )
1575  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1576  }
1577  break;
1578  }
1579  return;
1580  }
1581 
1582  typedef const std::vector<editeng::MisspellRanges>* MisspellRangesType;
1583  SCROW nRowRepeatSize = nEndRow - nStartRow + 1;
1584  SCCOL nColRepeatSize = nEndCol - nStartCol + 1;
1585  SCROW nTillRow = 0;
1586  SCCOL nTillCol = 0;
1587  std::vector<std::vector<MisspellRangesType>> aSourceSpellRanges(nRowRepeatSize, std::vector<MisspellRangesType>(nColRepeatSize, nullptr));
1588 
1589  for ( SCROW nRowIdx = 0; nRowIdx < nRowRepeatSize; ++nRowIdx )
1590  {
1591  for ( SCCOL nColIdx = 0; nColIdx < nColRepeatSize; ++nColIdx )
1592  {
1593  eCellType = pDoc->GetCellType(nStartCol + nColIdx, nStartRow + nRowIdx, nTab); // We need this optimization only for EditTextObject source cells
1594  if (eCellType != CELLTYPE_EDIT)
1595  continue;
1596 
1597  aSourceSpellRanges[nRowIdx][nColIdx] = pWin->GetAutoSpellData( nStartCol + nColIdx, nStartRow + nRowIdx );
1598  }
1599  }
1600 
1601  switch( eDir )
1602  {
1603  case FILL_TO_BOTTOM:
1604  nTillRow = nEndRow + nCount;
1605  for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1606  {
1607  for ( SCROW nRowItr = nEndRow + 1; nRowItr <= nTillRow; ++nRowItr )
1608  {
1609  size_t nSourceRowIdx = ( nRowItr - nEndRow - 1 ) % nRowRepeatSize;
1610  MisspellRangesType pRanges = aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
1611  if ( !pRanges )
1612  continue;
1613  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1614  }
1615  }
1616  break;
1617 
1618  case FILL_TO_TOP:
1619  nTillRow = nStartRow - nCount;
1620  for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1621  {
1622  for ( SCROW nRowItr = nStartRow - 1; nRowItr >= nTillRow; --nRowItr )
1623  {
1624  size_t nSourceRowIdx = nRowRepeatSize - 1 - ( ( nStartRow - 1 - nRowItr ) % nRowRepeatSize );
1625  MisspellRangesType pRanges = aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
1626  if ( !pRanges )
1627  continue;
1628  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1629  }
1630  }
1631  break;
1632 
1633  case FILL_TO_RIGHT:
1634  nTillCol = nEndCol + nCount;
1635  for ( SCCOL nColItr = nEndCol + 1; nColItr <= nTillCol; ++nColItr )
1636  {
1637  size_t nSourceColIdx = ( nColItr - nEndCol - 1 ) % nColRepeatSize;
1638  for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1639  {
1640  MisspellRangesType pRanges = aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
1641  if ( !pRanges )
1642  continue;
1643  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1644  }
1645  }
1646  break;
1647 
1648  case FILL_TO_LEFT:
1649  nTillCol = nStartCol - nCount;
1650  for ( SCCOL nColItr = nStartCol - 1; nColItr >= nTillCol; --nColItr )
1651  {
1652  size_t nSourceColIdx = nColRepeatSize - 1 - ( ( nStartCol - 1 - nColItr ) % nColRepeatSize );
1653  for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1654  {
1655  MisspellRangesType pRanges = aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
1656  if ( !pRanges )
1657  continue;
1658  pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1659  }
1660  }
1661  break;
1662  }
1663  }
1664  else
1666 
1667 }
1668 
1669 void ScViewFunc::FillTab( InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink )
1670 {
1672  ScEditableTester aTester( this );
1673  if (!aTester.IsEditable())
1674  {
1675  ErrorMessage(aTester.GetMessageId());
1676  return;
1677  }
1678 
1679  ScDocShell* pDocSh = GetViewData().GetDocShell();
1680  ScDocument& rDoc = pDocSh->GetDocument();
1681  ScMarkData& rMark = GetViewData().GetMarkData();
1682  SCTAB nTab = GetViewData().GetTabNo();
1683  bool bUndo(rDoc.IsUndoEnabled());
1684 
1685  ScRange aMarkRange;
1686  rMark.MarkToSimple();
1687  bool bMulti = rMark.IsMultiMarked();
1688  if (bMulti)
1689  rMark.GetMultiMarkArea( aMarkRange );
1690  else if (rMark.IsMarked())
1691  rMark.GetMarkArea( aMarkRange );
1692  else
1693  aMarkRange = ScRange( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
1694 
1695  ScDocumentUniquePtr pUndoDoc;
1696 
1697  if (bUndo)
1698  {
1699  pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
1700  pUndoDoc->InitUndo( rDoc, nTab, nTab );
1701 
1702  for (const SCTAB& i : rMark)
1703  if (i != nTab )
1704  {
1705  pUndoDoc->AddUndoTab( i, i );
1706  aMarkRange.aStart.SetTab( i );
1707  aMarkRange.aEnd.SetTab( i );
1708  rDoc.CopyToDocument( aMarkRange, InsertDeleteFlags::ALL, bMulti, *pUndoDoc );
1709  }
1710  }
1711 
1712  if (bMulti)
1713  rDoc.FillTabMarked( nTab, rMark, nFlags, nFunction, bSkipEmpty, bAsLink );
1714  else
1715  {
1716  aMarkRange.aStart.SetTab( nTab );
1717  aMarkRange.aEnd.SetTab( nTab );
1718  rDoc.FillTab( aMarkRange, rMark, nFlags, nFunction, bSkipEmpty, bAsLink );
1719  }
1720 
1721  if (bUndo)
1722  {
1723  pDocSh->GetUndoManager()->AddUndoAction(
1724  std::make_unique<ScUndoFillTable>( pDocSh, rMark,
1725  aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), nTab,
1726  aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab,
1727  std::move(pUndoDoc), bMulti, nTab, nFlags, nFunction, bSkipEmpty, bAsLink ) );
1728  }
1729 
1730  pDocSh->PostPaintGridAll();
1731  pDocSh->PostDataChanged();
1732 }
1733 
1750 {
1751  ScRange aRange;
1752  GetViewData().GetSimpleArea( aRange );
1753  aRange.PutInOrder();
1754 
1755  SCTAB nTab = GetViewData().GetCurPos().Tab();
1756  SCCOL nStartX = aRange.aStart.Col();
1757  SCROW nStartY = aRange.aStart.Row();
1758  SCCOL nEndX = aRange.aEnd.Col();
1759  SCROW nEndY = aRange.aEnd.Row();
1760 
1761  ScDocument& rDoc = GetViewData().GetDocument();
1762 
1763  if (nEndY >= rDoc.MaxRow())
1764  // Nothing to fill.
1765  return;
1766 
1767  // Make sure the selection is not empty
1768  if ( rDoc.IsBlockEmpty( nTab, nStartX, nStartY, nEndX, nEndY ) )
1769  return;
1770 
1771  // If there is data in all columns immediately below the selection then
1772  // switch to overwriting fill.
1773  SCROW nOverWriteEndRow = rDoc.MaxRow();
1774  for (SCCOL nCol = nStartX; nCol <= nEndX; ++nCol)
1775  {
1776  if (rDoc.HasData( nCol, nEndY + 1, nTab))
1777  {
1778  // Determine the shortest data column to end the fill.
1779  SCROW nY = nEndY + 1;
1780  // FindAreaPos() returns the start row of the next data block if
1781  // the current row is the last row of a data block and an empty
1782  // cell follows. Somewhat unexpected behaviour...
1783  // So check beforehand if there is one non-empty cell following.
1784  if (rDoc.HasData( nCol, nY + 1, nTab))
1785  {
1786  rDoc.FindAreaPos( nCol, nY, nTab, SC_MOVE_DOWN);
1787  if (nOverWriteEndRow > nY)
1788  nOverWriteEndRow = nY;
1789  }
1790  else
1791  {
1792  nOverWriteEndRow = nY;
1793  }
1794  }
1795  else
1796  {
1797  nOverWriteEndRow = 0;
1798  break; // for
1799  }
1800  }
1801 
1802  if (nOverWriteEndRow > nEndY)
1803  {
1804  FillAuto( FILL_TO_BOTTOM, nStartX, nStartY, nEndX, nEndY, nOverWriteEndRow - nEndY);
1805  return;
1806  }
1807 
1808  // Non-overwriting fill follows.
1809 
1810  const bool bDataLeft = (nStartX > 0);
1811  if (!bDataLeft && nEndX >= rDoc.MaxCol())
1812  // Absolutely no data left or right of selection.
1813  return;
1814 
1815  // Check that there is
1816  // 1) data immediately left (preferred) or right of start (row) of selection
1817  // 2) data there below
1818  // 3) no data immediately below selection
1819 
1820  SCCOL nMovX = (bDataLeft ? nStartX - 1 : nEndX + 1);
1821  SCROW nMovY = nStartY;
1822  bool bDataFound = (rDoc.HasData( nMovX, nStartY, nTab) && rDoc.HasData( nMovX, nStartY + 1, nTab));
1823  if (!bDataFound && bDataLeft && nEndX < rDoc.MaxCol())
1824  {
1825  nMovX = nEndX + 1; // check right
1826  bDataFound = (rDoc.HasData( nMovX, nStartY, nTab) && rDoc.HasData( nMovX, nStartY + 1, nTab));
1827  }
1828 
1829  if (!(bDataFound && rDoc.IsBlockEmpty( nTab, nStartX, nEndY + 1, nEndX, nEndY + 1, true)))
1830  return;
1831 
1832  // Get end of data left or right.
1833  rDoc.FindAreaPos( nMovX, nMovY, nTab, SC_MOVE_DOWN);
1834  // Find minimum end row of below empty area and data right.
1835  for (SCCOL nX = nStartX; nX <= nEndX; ++nX)
1836  {
1837  SCROW nY = nEndY + 1;
1838  // Get next row with data in this column.
1839  rDoc.FindAreaPos( nX, nY, nTab, SC_MOVE_DOWN);
1840  if (nMovY == rDoc.MaxRow() && nY == rDoc.MaxRow())
1841  {
1842  // FindAreaPos() returns MAXROW also if there is no data at all
1843  // from the start, so check if that contains data if the nearby
1844  // (left or right) data ends there and increment if no data
1845  // here, pretending the next data would be thereafter so nMovY
1846  // will not be decremented.
1847  if (!rDoc.HasData( nX, nY, nTab))
1848  ++nY;
1849  }
1850  if (nMovY > nY - 1)
1851  nMovY = nY - 1;
1852  }
1853 
1854  if (nMovY > nEndY)
1855  {
1856  FillAuto( FILL_TO_BOTTOM, nStartX, nStartY, nEndX, nEndY, nMovY - nEndY);
1857  }
1858 }
1859 
1861 {
1862  ScRange aRange;
1863  GetViewData().GetSimpleArea(aRange);
1864  aRange.PutInOrder();
1865 
1866  ScDocShell* pDocSh = GetViewData().GetDocShell();
1867  pDocSh->GetDocFunc().ConvertFormulaToValue(aRange, true);
1868  pDocSh->PostPaint(aRange, PaintPartFlags::Grid);
1869 }
1870 
1872 {
1873  ScMarkData aFuncMark = GetViewData().GetMarkData();
1874  if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
1875  {
1876  // no selection -> use cursor position
1877 
1878  ScAddress aCursor( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
1879  aFuncMark.SetMarkArea( ScRange( aCursor ) );
1880  }
1881 
1882  bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
1883  TransliterateText( aFuncMark, nType, false );
1884  if (bSuccess)
1885  {
1886  GetViewData().GetViewShell()->UpdateInputHandler();
1887  }
1888 }
1889 
1890 // AutoFormat
1891 
1893 {
1894  ScAutoFormatData* pData = nullptr;
1895  SCCOL nStartCol;
1896  SCROW nStartRow;
1897  SCTAB nStartTab;
1898  SCCOL nEndCol;
1899  SCROW nEndRow;
1900  SCTAB nEndTab;
1901  if (GetViewData().GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
1902  {
1903  if ( nEndCol-nStartCol >= 3 && nEndRow-nStartRow >= 3 )
1904  {
1905  ScDocument& rDoc = GetViewData().GetDocument();
1906  pData = new ScAutoFormatData;
1907  rDoc.GetAutoFormatData( nStartTab, nStartCol,nStartRow,nEndCol,nEndRow, *pData );
1908  }
1909  }
1910  return pData;
1911 }
1912 
1913 void ScViewFunc::AutoFormat( sal_uInt16 nFormatNo )
1914 {
1915  ScRange aRange;
1916  if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1917  {
1918  ScDocShell* pDocSh = GetViewData().GetDocShell();
1919  ScMarkData& rMark = GetViewData().GetMarkData();
1920 
1921  bool bSuccess = pDocSh->GetDocFunc().AutoFormat( aRange, &rMark, nFormatNo, false );
1922  if (bSuccess)
1923  pDocSh->UpdateOle(GetViewData());
1924  }
1925  else
1926  ErrorMessage(STR_NOMULTISELECT);
1927 }
1928 
1929 // Search & Replace
1930 
1932  bool bAddUndo, bool bIsApi )
1933 {
1934  SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty);
1935  ScDocShell* pDocSh = GetViewData().GetDocShell();
1936  ScDocument& rDoc = pDocSh->GetDocument();
1937  ScMarkData& rMark = GetViewData().GetMarkData();
1938  if (bAddUndo && !rDoc.IsUndoEnabled())
1939  bAddUndo = false;
1940 
1941  if ( !rMark.IsMarked() && !rMark.IsMultiMarked() && (pSearchItem->HasStartPoint()) )
1942  {
1943  // No selection -> but we have a start point (top left corner of the
1944  // current view), start searching from there, not from the current
1945  // cursor position.
1946  SCCOL nPosX;
1947  SCROW nPosY;
1948 
1949  int nPixelX = pSearchItem->GetStartPointX() * GetViewData().GetPPTX();
1950  int nPixelY = pSearchItem->GetStartPointY() * GetViewData().GetPPTY();
1951 
1952  GetViewData().GetPosFromPixel(nPixelX, nPixelY, GetViewData().GetActivePart(), nPosX, nPosY);
1953 
1954  AlignToCursor( nPosX, nPosY, SC_FOLLOW_JUMP );
1955  SetCursor( nPosX, nPosY, true );
1956  }
1957 
1958  SCCOL nCol, nOldCol;
1959  SCROW nRow, nOldRow;
1960  SCTAB nTab, nOldTab;
1961  nCol = nOldCol = GetViewData().GetCurX();
1962  nRow = nOldRow = GetViewData().GetCurY();
1963  nTab = nOldTab = GetViewData().GetTabNo();
1964 
1965  SvxSearchCmd nCommand = pSearchItem->GetCommand();
1966  bool bAllTables = pSearchItem->IsAllTables();
1967  std::set<SCTAB> aOldSelectedTables;
1968  SCTAB nLastTab = rDoc.GetTableCount() - 1;
1969  SCTAB nStartTab, nEndTab;
1970  if ( bAllTables )
1971  {
1972  nStartTab = 0;
1973  nEndTab = nLastTab;
1974  std::set<SCTAB> aTmp(rMark.begin(), rMark.end());
1975  aOldSelectedTables.swap(aTmp);
1976  }
1977  else
1978  {
1979  nStartTab = rMark.GetFirstSelected();
1980  nEndTab = rMark.GetLastSelected();
1981  }
1982 
1983  if ( nCommand == SvxSearchCmd::FIND
1984  || nCommand == SvxSearchCmd::FIND_ALL)
1985  bAddUndo = false;
1986 
1988 
1989  ScDocumentUniquePtr pUndoDoc;
1990  std::unique_ptr<ScMarkData> pUndoMark;
1991  OUString aUndoStr;
1992  if (bAddUndo)
1993  {
1994  pUndoMark.reset(new ScMarkData(rMark)); // Mark is being modified
1995  if ( nCommand == SvxSearchCmd::REPLACE_ALL )
1996  {
1997  pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
1998  pUndoDoc->InitUndo( rDoc, nStartTab, nEndTab );
1999  }
2000  }
2001 
2002  if ( bAllTables )
2003  {
2004  for ( SCTAB j = nStartTab; j <= nEndTab; j++ )
2005  {
2006  rMark.SelectTable( j, true );
2007  }
2008  }
2009 
2010  DoneBlockMode(true); // don't delete mark
2011  InitOwnBlockMode();
2012 
2013  // If search starts at the beginning don't ask again whether it shall start at the beginning
2014  bool bFirst = true;
2015  if ( nCol == 0 && nRow == 0 && nTab == nStartTab && !pSearchItem->GetBackward() )
2016  bFirst = false;
2017 
2018  bool bFound = false;
2019  while (true)
2020  {
2021  GetFrameWin()->EnterWait();
2022  ScRangeList aMatchedRanges;
2023  if (rDoc.SearchAndReplace(*pSearchItem, nCol, nRow, nTab, rMark, aMatchedRanges, aUndoStr, pUndoDoc.get()))
2024  {
2025  bFound = true;
2026  if (bAddUndo)
2027  {
2028  GetViewData().GetDocShell()->GetUndoManager()->AddUndoAction(
2029  std::make_unique<ScUndoReplace>( GetViewData().GetDocShell(), *pUndoMark,
2030  nCol, nRow, nTab,
2031  aUndoStr, std::move(pUndoDoc), pSearchItem ) );
2032  }
2033 
2034  if (nCommand == SvxSearchCmd::FIND_ALL || nCommand == SvxSearchCmd::REPLACE_ALL)
2035  {
2036  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
2037  bool bShow = GetViewData().GetViewShell()->GetViewData().GetOptions().GetOption( VOPT_SUMMARY );
2038 
2039  if (bShow && pViewFrm && !comphelper::LibreOfficeKit::isActive())
2040  {
2041  pViewFrm->ShowChildWindow(sc::SearchResultsDlgWrapper::GetChildWindowId());
2042  SfxChildWindow* pWnd = pViewFrm->GetChildWindow(sc::SearchResultsDlgWrapper::GetChildWindowId());
2043  if (pWnd)
2044  {
2045  sc::SearchResultsDlg* pDlg = static_cast<sc::SearchResultsDlg*>(pWnd->GetController().get());
2046  if (pDlg)
2047  {
2048  const bool bCellNotes = (pSearchItem->GetCellType() == SvxSearchCellType::NOTE);
2049  // ScCellIterator iterates over cells with content,
2050  // for empty cells iterate over match positions.
2051  const bool bEmptyCells = (!bCellNotes
2052  && ((nCommand == SvxSearchCmd::FIND_ALL
2053  && ScDocument::IsEmptyCellSearch(*pSearchItem))
2054  || (nCommand == SvxSearchCmd::REPLACE_ALL
2055  && pSearchItem->GetReplaceString().isEmpty())));
2056  pDlg->FillResults(rDoc, aMatchedRanges, bCellNotes, bEmptyCells);
2057  }
2058  }
2059  }
2060 
2061  rMark.ResetMark();
2062  for (size_t i = 0, n = aMatchedRanges.size(); i < n; ++i)
2063  {
2064  const ScRange& r = aMatchedRanges[i];
2065  if (r.aStart.Tab() == nTab)
2066  rMark.SetMultiMarkArea(r);
2067  }
2068  }
2069 
2070  break; // break 'while (TRUE)'
2071  }
2072  else if ( bFirst && (nCommand == SvxSearchCmd::FIND ||
2073  nCommand == SvxSearchCmd::REPLACE) )
2074  {
2075  bFirst = false;
2076  GetFrameWin()->LeaveWait();
2077  if (!bIsApi)
2078  {
2079  if ( nStartTab == nEndTab )
2080  SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::EndSheet);
2081  else
2082  SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::End);
2083 
2084  rDoc.GetSearchAndReplaceStart( *pSearchItem, nCol, nRow );
2085  if (pSearchItem->GetBackward())
2086  nTab = nEndTab;
2087  else
2088  nTab = nStartTab;
2089  }
2090  else
2091  {
2092  break; // break 'while (TRUE)'
2093  }
2094  }
2095  else // nothing found
2096  {
2097  if ( nCommand == SvxSearchCmd::FIND_ALL || nCommand == SvxSearchCmd::REPLACE_ALL )
2098  {
2099  pDocSh->PostPaintGridAll(); // Mark
2100  }
2101 
2102  GetFrameWin()->LeaveWait();
2103  if (!bIsApi)
2104  {
2105  GetViewData().GetViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, pSearchItem->GetSearchString().toUtf8().getStr());
2106  SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NotFound);
2107  }
2108 
2109  break; // break 'while (TRUE)'
2110  }
2111  } // of while true
2112 
2113  if (!aOldSelectedTables.empty())
2114  {
2115  // restore originally selected table
2116  for (SCTAB i = 0; i <= nEndTab; ++i)
2117  rMark.SelectTable(i, false);
2118 
2119  for (const auto& rTab : aOldSelectedTables)
2120  rMark.SelectTable(rTab, true);
2121 
2122  if ( bFound )
2123  { // if a table is selected as a "match" it remains selected.
2124  rMark.SelectTable( nTab, true );
2125  // It's a swap if only one table was selected before
2127  if ( aOldSelectedTables.size() == 1 && nTab != nOldTab )
2128  rMark.SelectTable( nOldTab, false );
2129  }
2130  }
2131 
2132  // Avoid LOK selection notifications before we have all the results.
2133  GetViewData().GetViewShell()->setTiledSearching(true);
2134  MarkDataChanged();
2135  GetViewData().GetViewShell()->setTiledSearching(false);
2136 
2137  if ( bFound )
2138  {
2139  if ( nTab != GetViewData().GetTabNo() )
2140  SetTabNo( nTab );
2141 
2142  // if nothing is marked, DoneBlockMode, then marking can start
2143  // directly from this place via Shift-Cursor
2144  if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2145  DoneBlockMode(true);
2146 
2147  AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
2148  SetCursor( nCol, nRow, true );
2149 
2151  {
2152  Point aCurPos = GetViewData().GetScrPos(nCol, nRow, GetViewData().GetActivePart());
2153 
2154  // just update the cell selection
2155  ScGridWindow* pGridWindow = GetViewData().GetActiveWin();
2156  // Don't move cell selection handles for find-all: selection of all but the first result would be lost.
2157  if (pGridWindow && nCommand == SvxSearchCmd::FIND)
2158  {
2159  // move the cell selection handles
2160  pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_RESET, aCurPos.X(), aCurPos.Y());
2161  pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_START, aCurPos.X(), aCurPos.Y());
2162  pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_END, aCurPos.X(), aCurPos.Y());
2163  }
2164 
2165  if (pGridWindow)
2166  {
2167  std::vector<tools::Rectangle> aLogicRects;
2168  pGridWindow->GetCellSelection(aLogicRects);
2169 
2170  boost::property_tree::ptree aTree;
2171  aTree.put("searchString", pSearchItem->GetSearchString().toUtf8().getStr());
2172  aTree.put("highlightAll", nCommand == SvxSearchCmd::FIND_ALL);
2173 
2174  boost::property_tree::ptree aSelections;
2175  for (const tools::Rectangle& rLogicRect : aLogicRects)
2176  {
2177  boost::property_tree::ptree aSelection;
2178  aSelection.put("part", OString::number(nTab).getStr());
2179  aSelection.put("rectangles", rLogicRect.toString().getStr());
2180  aSelections.push_back(std::make_pair("", aSelection));
2181  }
2182  aTree.add_child("searchResultSelection", aSelections);
2183 
2184  std::stringstream aStream;
2185  boost::property_tree::write_json(aStream, aTree);
2186  OString aPayload = aStream.str().c_str();
2187  SfxViewShell* pViewShell = GetViewData().GetViewShell();
2188  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
2189 
2190  // Trigger LOK_CALLBACK_TEXT_SELECTION now.
2191  MarkDataChanged();
2192  }
2193  }
2194 
2195  if ( nCommand == SvxSearchCmd::REPLACE
2196  || nCommand == SvxSearchCmd::REPLACE_ALL )
2197  {
2198  if ( nCommand == SvxSearchCmd::REPLACE )
2199  {
2200  pDocSh->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PaintPartFlags::Grid );
2201 
2202  // jump to next cell if we replaced everything in the cell
2203  // where the cursor was positioned (but avoid switching tabs)
2204  if ( nCol == nOldCol && nRow == nOldRow && nTab == nOldTab )
2205  {
2206  SvxSearchItem aSearchItem = ScGlobal::GetSearchItem();
2207  aSearchItem.SetCommand(SvxSearchCmd::FIND);
2208  aSearchItem.SetWhich(SID_SEARCH_ITEM);
2209 
2210  ScRangeList aMatchedRanges;
2211  ScTable::UpdateSearchItemAddressForReplace( aSearchItem, nCol, nRow );
2212  if ( rDoc.SearchAndReplace( aSearchItem, nCol, nRow, nTab, rMark, aMatchedRanges, aUndoStr ) &&
2213  ( nTab == nOldTab ) &&
2214  ( nCol != nOldCol || nRow != nOldRow ) )
2215  {
2216  AlignToCursor(nCol, nRow, SC_FOLLOW_JUMP);
2217  SetCursor( nCol, nRow, true );
2218  }
2219  }
2220  }
2221  else
2222  pDocSh->PostPaintGridAll();
2223  pDocSh->SetDocumentModified();
2224  }
2225  else if ( nCommand == SvxSearchCmd::FIND_ALL )
2226  pDocSh->PostPaintGridAll(); // mark
2227  GetFrameWin()->LeaveWait();
2228  }
2229  return bFound;
2230 }
2231 
2232 // Goal Seek
2233 
2234 void ScViewFunc::Solve( const ScSolveParam& rParam )
2235 {
2236  ScDocument& rDoc = GetViewData().GetDocument();
2237 
2238  SCCOL nDestCol = rParam.aRefVariableCell.Col();
2239  SCROW nDestRow = rParam.aRefVariableCell.Row();
2240  SCTAB nDestTab = rParam.aRefVariableCell.Tab();
2241 
2242  ScEditableTester aTester( rDoc, nDestTab, nDestCol,nDestRow, nDestCol,nDestRow );
2243  if (!aTester.IsEditable())
2244  {
2245  ErrorMessage(aTester.GetMessageId());
2246  return;
2247  }
2248 
2249  OUString aTargetValStr;
2250  if ( rParam.pStrTargetVal )
2251  aTargetValStr = *rParam.pStrTargetVal;
2252 
2253  OUString aMsgStr;
2254  OUString aResStr;
2255  double nSolveResult;
2256 
2257  GetFrameWin()->EnterWait();
2258 
2259  bool bExact =
2260  rDoc.Solver(
2261  rParam.aRefFormulaCell.Col(),
2262  rParam.aRefFormulaCell.Row(),
2263  rParam.aRefFormulaCell.Tab(),
2264  nDestCol, nDestRow, nDestTab,
2265  aTargetValStr,
2266  nSolveResult );
2267 
2268  GetFrameWin()->LeaveWait();
2269 
2270  SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
2271  sal_uLong nFormat = 0;
2272  const ScPatternAttr* pPattern = rDoc.GetPattern( nDestCol, nDestRow, nDestTab );
2273  if ( pPattern )
2274  nFormat = pPattern->GetNumberFormat( pFormatter );
2275  const Color* p;
2276  pFormatter->GetOutputString( nSolveResult, nFormat, aResStr, &p );
2277 
2278  if ( bExact )
2279  {
2280  aMsgStr += ScResId( STR_MSSG_SOLVE_0 ) +
2281  aResStr +
2282  ScResId( STR_MSSG_SOLVE_1 );
2283  }
2284  else
2285  {
2286  aMsgStr = ScResId( STR_MSSG_SOLVE_2 ) +
2287  ScResId( STR_MSSG_SOLVE_3 ) +
2288  aResStr +
2289  ScResId( STR_MSSG_SOLVE_4 );
2290  }
2291 
2292  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetViewData().GetDialogParent(),
2293  VclMessageType::Question, VclButtonsType::YesNo, aMsgStr));
2294  xBox->set_title(ScResId(STR_MSSG_DOSUBTOTALS_0));
2295  xBox->set_default_response(RET_NO);
2296  if (xBox->run() == RET_YES)
2297  EnterValue( nDestCol, nDestRow, nDestTab, nSolveResult );
2298 
2299  GetViewData().GetViewShell()->UpdateInputHandler( true );
2300 }
2301 
2302 // multi operation
2303 
2304 void ScViewFunc::TabOp( const ScTabOpParam& rParam, bool bRecord )
2305 {
2306  ScRange aRange;
2307  if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
2308  {
2309  ScDocShell* pDocSh = GetViewData().GetDocShell();
2310  ScMarkData& rMark = GetViewData().GetMarkData();
2311  pDocSh->GetDocFunc().TabOp( aRange, &rMark, rParam, bRecord, false );
2312  }
2313  else
2314  ErrorMessage(STR_NOMULTISELECT);
2315 }
2316 
2317 void ScViewFunc::MakeScenario( const OUString& rName, const OUString& rComment,
2318  const Color& rColor, ScScenarioFlags nFlags )
2319 {
2320  ScDocShell* pDocSh = GetViewData().GetDocShell();
2321  ScMarkData& rMark = GetViewData().GetMarkData();
2322  SCTAB nTab = GetViewData().GetTabNo();
2323 
2324  SCTAB nNewTab = pDocSh->MakeScenario( nTab, rName, rComment, rColor, nFlags, rMark );
2325  if (nFlags & ScScenarioFlags::CopyAll)
2326  SetTabNo( nNewTab, true ); // ScScenarioFlags::CopyAll -> visible
2327  else
2328  {
2329  SfxBindings& rBindings = GetViewData().GetBindings();
2330  rBindings.Invalidate( SID_STATUS_DOCPOS ); // Statusbar
2331  rBindings.Invalidate( SID_ROWCOL_SELCOUNT ); // Statusbar
2332  rBindings.Invalidate( SID_TABLES_COUNT );
2333  rBindings.Invalidate( SID_SELECT_SCENARIO );
2334  rBindings.Invalidate( FID_TABLE_SHOW );
2335  }
2336 }
2337 
2339 {
2340  ScEditableTester aTester( this );
2341  if (!aTester.IsEditable())
2342  {
2343  ErrorMessage(aTester.GetMessageId());
2344  return;
2345  }
2346 
2347  // Undo: apply attributes
2348 
2349  ScDocument& rDoc = GetViewData().GetDocument();
2350  ScPatternAttr aPattern( rDoc.GetPool() );
2351  aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) );
2352  aPattern.GetItemSet().Put( ScProtectionAttr( true ) );
2353  ApplySelectionPattern(aPattern);
2354 }
2355 
2356 void ScViewFunc::UseScenario( const OUString& rName )
2357 {
2358  ScDocShell* pDocSh = GetViewData().GetDocShell();
2359  SCTAB nTab = GetViewData().GetTabNo();
2360 
2361  DoneBlockMode();
2362  InitOwnBlockMode();
2363  pDocSh->UseScenario( nTab, rName );
2364 }
2365 
2366 // Insert table
2367 
2368 bool ScViewFunc::InsertTable( const OUString& rName, SCTAB nTab, bool bRecord )
2369 {
2370  // Order Table/Name is inverted for DocFunc
2371  bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
2372  InsertTable( nTab, rName, bRecord, false );
2373  if (bSuccess)
2374  SetTabNo( nTab, true );
2375 
2376  return bSuccess;
2377 }
2378 
2379 // Insert tables
2380 
2381 void ScViewFunc::InsertTables(std::vector<OUString>& aNames, SCTAB nTab,
2382  SCTAB nCount, bool bRecord )
2383 {
2384  ScDocShell* pDocSh = GetViewData().GetDocShell();
2385  ScDocument& rDoc = pDocSh->GetDocument();
2386  if (bRecord && !rDoc.IsUndoEnabled())
2387  bRecord = false;
2388 
2389  weld::WaitObject aWait(GetViewData().GetDialogParent());
2390 
2391  if (bRecord)
2392  {
2393  rDoc.BeginDrawUndo(); // InsertTab creates a SdrUndoNewPage
2394  }
2395 
2396  bool bFlag=false;
2397 
2398  if(aNames.empty())
2399  {
2400  rDoc.CreateValidTabNames(aNames, nCount);
2401  }
2402  if (rDoc.InsertTabs(nTab, aNames))
2403  {
2404  pDocSh->Broadcast( ScTablesHint( SC_TABS_INSERTED, nTab, nCount ) );
2405  bFlag = true;
2406  }
2407 
2408  if (!bFlag)
2409  return;
2410 
2411  if (bRecord)
2412  pDocSh->GetUndoManager()->AddUndoAction(
2413  std::make_unique<ScUndoInsertTables>( pDocSh, nTab, std::move(aNames)));
2414 
2415  // Update views
2416 
2417  SetTabNo( nTab, true );
2418  pDocSh->PostPaintExtras();
2419  pDocSh->SetDocumentModified();
2420  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2421 }
2422 
2423 bool ScViewFunc::AppendTable( const OUString& rName, bool bRecord )
2424 {
2425  ScDocShell* pDocSh = GetViewData().GetDocShell();
2426  ScDocument& rDoc = pDocSh->GetDocument();
2427  if (bRecord && !rDoc.IsUndoEnabled())
2428  bRecord = false;
2429 
2430  weld::WaitObject aWait(GetViewData().GetDialogParent());
2431 
2432  if (bRecord)
2433  rDoc.BeginDrawUndo(); // InsertTab creates a SdrUndoNewPage
2434 
2435  if (rDoc.InsertTab( SC_TAB_APPEND, rName ))
2436  {
2437  SCTAB nTab = rDoc.GetTableCount()-1;
2438  if (bRecord)
2439  pDocSh->GetUndoManager()->AddUndoAction(
2440  std::make_unique<ScUndoInsertTab>( pDocSh, nTab, true, rName));
2441  GetViewData().InsertTab( nTab );
2442  SetTabNo( nTab, true );
2443  pDocSh->PostPaintExtras();
2444  pDocSh->SetDocumentModified();
2445  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2446  return true;
2447  }
2448  else
2449  {
2450  return false;
2451  }
2452 }
2453 
2454 void ScViewFunc::DeleteTable( SCTAB nTab, bool bRecord )
2455 {
2456  ScDocShell* pDocSh = GetViewData().GetDocShell();
2457  ScDocument& rDoc = pDocSh->GetDocument();
2458 
2459  bool bSuccess = pDocSh->GetDocFunc().DeleteTable( nTab, bRecord );
2460  if (bSuccess)
2461  {
2462  SCTAB nNewTab = nTab;
2463  if ( nNewTab >= rDoc.GetTableCount() )
2464  --nNewTab;
2465  SetTabNo( nNewTab, true );
2466  }
2467 }
2468 
2469 //only use this method for undo for now, all sheets must be connected
2470 //this method doesn't support undo for now, merge it when it with the other method later
2471 void ScViewFunc::DeleteTables( const SCTAB nTab, SCTAB nSheets )
2472 {
2473  ScDocShell* pDocSh = GetViewData().GetDocShell();
2474  ScDocument& rDoc = pDocSh->GetDocument();
2475  bool bVbaEnabled = rDoc.IsInVBAMode();
2476  SCTAB nNewTab = nTab;
2477  weld::WaitObject aWait(GetViewData().GetDialogParent());
2478 
2479  while ( nNewTab > 0 && !rDoc.IsVisible( nNewTab ) )
2480  --nNewTab;
2481 
2482  if (!rDoc.DeleteTabs(nTab, nSheets))
2483  return;
2484 
2485  if( bVbaEnabled )
2486  {
2487  for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
2488  {
2489  OUString sCodeName;
2490  bool bHasCodeName = rDoc.GetCodeName( nTab + aTab, sCodeName );
2491  if ( bHasCodeName )
2492  VBA_DeleteModule( *pDocSh, sCodeName );
2493  }
2494  }
2495 
2496  pDocSh->Broadcast( ScTablesHint( SC_TABS_DELETED, nTab, nSheets ) );
2497  if ( nNewTab >= rDoc.GetTableCount() )
2498  nNewTab = rDoc.GetTableCount() - 1;
2499  SetTabNo( nNewTab, true );
2500 
2501  pDocSh->PostPaintExtras();
2502  pDocSh->SetDocumentModified();
2503 
2504  SfxApplication* pSfxApp = SfxGetpApp(); // Navigator
2505  pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2506  pSfxApp->Broadcast( SfxHint( SfxHintId::ScDbAreasChanged ) );
2507  pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) );
2508 }
2509 
2510 bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, bool bRecord )
2511 {
2512  ScDocShell* pDocSh = GetViewData().GetDocShell();
2513  ScDocument& rDoc = pDocSh->GetDocument();
2514  bool bVbaEnabled = rDoc.IsInVBAMode();
2515  SCTAB nNewTab = TheTabs.front();
2516  weld::WaitObject aWait(GetViewData().GetDialogParent());
2517  if (bRecord && !rDoc.IsUndoEnabled())
2518  bRecord = false;
2519  if ( bVbaEnabled )
2520  bRecord = false;
2521 
2522  while ( nNewTab > 0 && !rDoc.IsVisible( nNewTab ) )
2523  --nNewTab;
2524 
2525  bool bWasLinked = false;
2526  ScDocumentUniquePtr pUndoDoc;
2527  std::unique_ptr<ScRefUndoData> pUndoData;
2528  if (bRecord)
2529  {
2530  pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
2531  SCTAB nCount = rDoc.GetTableCount();
2532 
2533  OUString aOldName;
2534  for(size_t i=0; i<TheTabs.size(); ++i)
2535  {
2536  SCTAB nTab = TheTabs[i];
2537  if (i==0)
2538  pUndoDoc->InitUndo( rDoc, nTab,nTab, true,true ); // incl. column/fow flags
2539  else
2540  pUndoDoc->AddUndoTab( nTab,nTab, true,true ); // incl. column/fow flags
2541 
2542  rDoc.CopyToDocument(0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, InsertDeleteFlags::ALL,false, *pUndoDoc );
2543  rDoc.GetName( nTab, aOldName );
2544  pUndoDoc->RenameTab( nTab, aOldName );
2545  if (rDoc.IsLinked(nTab))
2546  {
2547  bWasLinked = true;
2548  pUndoDoc->SetLink( nTab, rDoc.GetLinkMode(nTab), rDoc.GetLinkDoc(nTab),
2549  rDoc.GetLinkFlt(nTab), rDoc.GetLinkOpt(nTab),
2550  rDoc.GetLinkTab(nTab),
2551  rDoc.GetLinkRefreshDelay(nTab) );
2552  }
2553  if ( rDoc.IsScenario(nTab) )
2554  {
2555  pUndoDoc->SetScenario( nTab, true );
2556  OUString aComment;
2557  Color aColor;
2558  ScScenarioFlags nScenFlags;
2559  rDoc.GetScenarioData( nTab, aComment, aColor, nScenFlags );
2560  pUndoDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
2561  bool bActive = rDoc.IsActiveScenario( nTab );
2562  pUndoDoc->SetActiveScenario( nTab, bActive );
2563  }
2564  pUndoDoc->SetVisible( nTab, rDoc.IsVisible( nTab ) );
2565  pUndoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) );
2566  auto pSheetEvents = rDoc.GetSheetEvents( nTab );
2567  pUndoDoc->SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) );
2568  pUndoDoc->SetLayoutRTL( nTab, rDoc.IsLayoutRTL( nTab ) );
2569 
2570  if ( rDoc.IsTabProtected( nTab ) )
2571  pUndoDoc->SetTabProtection(nTab, rDoc.GetTabProtection(nTab));
2572 
2573  // Drawing-Layer is responsible for its Undo !!!
2574  // pUndoDoc->TransferDrawPage(rDoc, nTab,nTab);
2575  }
2576 
2577  pUndoDoc->AddUndoTab( 0, nCount-1 ); // all Tabs for references
2578 
2579  rDoc.BeginDrawUndo(); // DeleteTab creates a SdrUndoDelPage
2580 
2581  pUndoData.reset(new ScRefUndoData( &rDoc ));
2582  }
2583 
2584  bool bDelDone = false;
2585 
2586  for(int i=TheTabs.size()-1; i>=0; --i)
2587  {
2588  OUString sCodeName;
2589  bool bHasCodeName = rDoc.GetCodeName( TheTabs[i], sCodeName );
2590  if (rDoc.DeleteTab(TheTabs[i]))
2591  {
2592  bDelDone = true;
2593  if( bVbaEnabled && bHasCodeName )
2594  {
2595  VBA_DeleteModule( *pDocSh, sCodeName );
2596  }
2597  pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[i] ) );
2598  }
2599  }
2600  if (bRecord)
2601  {
2602  pDocSh->GetUndoManager()->AddUndoAction(
2603  std::make_unique<ScUndoDeleteTab>( GetViewData().GetDocShell(), TheTabs,
2604  std::move(pUndoDoc), std::move(pUndoData) ));
2605  }
2606 
2607  if (bDelDone)
2608  {
2609  if ( nNewTab >= rDoc.GetTableCount() )
2610  nNewTab = rDoc.GetTableCount() - 1;
2611 
2612  SetTabNo( nNewTab, true );
2613 
2614  if (bWasLinked)
2615  {
2616  pDocSh->UpdateLinks(); // update Link-Manager
2617  GetViewData().GetBindings().Invalidate(SID_LINKS);
2618  }
2619 
2620  pDocSh->PostPaintExtras();
2621  pDocSh->SetDocumentModified();
2622 
2623  SfxApplication* pSfxApp = SfxGetpApp(); // Navigator
2624  pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2625  pSfxApp->Broadcast( SfxHint( SfxHintId::ScDbAreasChanged ) );
2626  pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) );
2627  }
2628  return bDelDone;
2629 }
2630 
2631 bool ScViewFunc::RenameTable( const OUString& rName, SCTAB nTab )
2632 {
2633  // order Table/Name is inverted for DocFunc
2634  bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
2635  RenameTable( nTab, rName, true, false );
2636  if (bSuccess)
2637  {
2638  // the table name might be part of a formula
2639  GetViewData().GetViewShell()->UpdateInputHandler();
2640  }
2641  return bSuccess;
2642 }
2643 
2644 bool ScViewFunc::SetTabBgColor( const Color& rColor, SCTAB nTab )
2645 {
2646  bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().SetTabBgColor( nTab, rColor, true, false );
2647  if (bSuccess)
2648  {
2649  GetViewData().GetViewShell()->UpdateInputHandler();
2650  }
2651  return bSuccess;
2652 }
2653 
2654 bool ScViewFunc::SetTabBgColor( ScUndoTabColorInfo::List& rUndoSetTabBgColorInfoList )
2655 {
2656  bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().SetTabBgColor( rUndoSetTabBgColorInfoList, false );
2657  if (bSuccess)
2658  {
2659  GetViewData().GetViewShell()->UpdateInputHandler();
2660  }
2661  return bSuccess;
2662 }
2663 
2664 void ScViewFunc::InsertAreaLink( const OUString& rFile,
2665  const OUString& rFilter, const OUString& rOptions,
2666  const OUString& rSource )
2667 {
2668  ScDocShell* pDocSh = GetViewData().GetDocShell();
2669  SCCOL nPosX = GetViewData().GetCurX();
2670  SCROW nPosY = GetViewData().GetCurY();
2671  SCTAB nTab = GetViewData().GetTabNo();
2672  ScAddress aPos( nPosX, nPosY, nTab );
2673 
2674  pDocSh->GetDocFunc().InsertAreaLink( rFile, rFilter, rOptions, rSource, aPos, 0/*nRefresh*/, false, false );
2675 }
2676 
2677 void ScViewFunc::InsertTableLink( const OUString& rFile,
2678  const OUString& rFilter, const OUString& rOptions,
2679  std::u16string_view rTabName )
2680 {
2681  OUString aFilterName = rFilter;
2682  OUString aOpt = rOptions;
2683  ScDocumentLoader aLoader( rFile, aFilterName, aOpt );
2684  if (aLoader.IsError())
2685  return;
2686 
2687  ScDocShell* pSrcSh = aLoader.GetDocShell();
2688  ScDocument& rSrcDoc = pSrcSh->GetDocument();
2689  SCTAB nTab = MAXTAB+1;
2690  if (rTabName.empty()) // no name given -> first table
2691  nTab = 0;
2692  else
2693  {
2694  OUString aTemp;
2695  SCTAB nCount = rSrcDoc.GetTableCount();
2696  for (SCTAB i=0; i<nCount; i++)
2697  {
2698  rSrcDoc.GetName( i, aTemp );
2699  if ( aTemp == rTabName )
2700  nTab = i;
2701  }
2702  }
2703 
2704  if ( nTab <= MAXTAB )
2705  ImportTables( pSrcSh, 1, &nTab, true,
2706  GetViewData().GetTabNo() );
2707 }
2708 
2709 // Copy/link tables from another document
2710 
2712  SCTAB nCount, const SCTAB* pSrcTabs, bool bLink,SCTAB nTab )
2713 {
2714  ScDocument& rSrcDoc = pSrcShell->GetDocument();
2715 
2716  ScDocShell* pDocSh = GetViewData().GetDocShell();
2717  ScDocument& rDoc = pDocSh->GetDocument();
2718  bool bUndo(rDoc.IsUndoEnabled());
2719 
2720  bool bError = false;
2721  bool bRefs = false;
2722  bool bName = false;
2723 
2724  if (rSrcDoc.GetDrawLayer())
2725  pDocSh->MakeDrawLayer();
2726 
2727  if (bUndo)
2728  rDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
2729 
2730  SCTAB nInsCount = 0;
2731  SCTAB i;
2732  for( i=0; i<nCount; i++ )
2733  { // insert sheets first and update all references
2734  OUString aName;
2735  rSrcDoc.GetName( pSrcTabs[i], aName );
2736  rDoc.CreateValidTabName( aName );
2737  if ( !rDoc.InsertTab( nTab+i, aName ) )
2738  {
2739  bError = true; // total error
2740  break; // for
2741  }
2742  ++nInsCount;
2743  }
2744  for (i=0; i<nCount && !bError; i++)
2745  {
2746  SCTAB nSrcTab = pSrcTabs[i];
2747  SCTAB nDestTab1=nTab+i;
2748  sal_uLong nErrVal = pDocSh->TransferTab( *pSrcShell, nSrcTab, nDestTab1,
2749  false, false ); // no insert
2750 
2751  switch (nErrVal)
2752  {
2753  case 0: // internal error or full of errors
2754  bError = true;
2755  break;
2756  case 2:
2757  bRefs = true;
2758  break;
2759  case 3:
2760  bName = true;
2761  break;
2762  case 4:
2763  bRefs = bName = true;
2764  break;
2765  }
2766 
2767  }
2768 
2769  if (bLink)
2770  {
2771  sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
2772 
2773  SfxMedium* pMed = pSrcShell->GetMedium();
2774  OUString aFileName = pMed->GetName();
2775  OUString aFilterName;
2776  if (pMed->GetFilter())
2777  aFilterName = pMed->GetFilter()->GetFilterName();
2778  OUString aOptions = ScDocumentLoader::GetOptions(*pMed);
2779 
2780  bool bWasThere = rDoc.HasLink( aFileName, aFilterName, aOptions );
2781 
2782  sal_uLong nRefresh = 0;
2783  OUString aTabStr;
2784  for (i=0; i<nInsCount; i++)
2785  {
2786  rSrcDoc.GetName( pSrcTabs[i], aTabStr );
2787  rDoc.SetLink( nTab+i, ScLinkMode::NORMAL,
2788  aFileName, aFilterName, aOptions, aTabStr, nRefresh );
2789  }
2790 
2791  if (!bWasThere) // Insert link only once per source document
2792  {
2793  ScTableLink* pLink = new ScTableLink( pDocSh, aFileName, aFilterName, aOptions, nRefresh );
2794  pLink->SetInCreate( true );
2795  pLinkManager->InsertFileLink( *pLink, sfx2::SvBaseLinkObjectType::ClientFile, aFileName, &aFilterName );
2796  pLink->Update();
2797  pLink->SetInCreate( false );
2798 
2799  SfxBindings& rBindings = GetViewData().GetBindings();
2800  rBindings.Invalidate( SID_LINKS );
2801  }
2802  }
2803 
2804  if (bUndo)
2805  {
2806  pDocSh->GetUndoManager()->AddUndoAction(
2807  std::make_unique<ScUndoImportTab>( pDocSh, nTab, nCount ) );
2808  }
2809 
2810  for (i=0; i<nInsCount; i++)
2811  GetViewData().InsertTab(nTab);
2812  SetTabNo(nTab,true);
2813  pDocSh->PostPaint( 0,0,0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB,
2815 
2816  SfxApplication* pSfxApp = SfxGetpApp();
2817  pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2818  pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
2819 
2820  pDocSh->PostPaintExtras();
2821  pDocSh->PostPaintGridAll();
2822  pDocSh->SetDocumentModified();
2823 
2824  if (bRefs)
2825  ErrorMessage(STR_ABSREFLOST);
2826  if (bName)
2827  ErrorMessage(STR_NAMECONFLICT);
2828 }
2829 
2830 // Move/Copy table to another document
2831 
2833  sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString* pNewTabName )
2834 {
2835  ScDocument& rDoc = GetViewData().GetDocument();
2836  ScDocShell* pDocShell = GetViewData().GetDocShell();
2837  ScDocShell* pDestShell = nullptr;
2838  ScTabViewShell* pDestViewSh = nullptr;
2839  bool bUndo (rDoc.IsUndoEnabled());
2840  bool bRename = pNewTabName && !pNewTabName->isEmpty();
2841 
2842  bool bNewDoc = (nDestDocNo == SC_DOC_NEW);
2843  if ( bNewDoc )
2844  {
2845  nDestTab = 0; // firstly insert
2846 
2847  // execute without SfxCallMode::RECORD, because already contained in move command
2848 
2849  SfxStringItem aItem( SID_FILE_NAME, "private:factory/" + STRING_SCAPP );
2850  SfxStringItem aTarget( SID_TARGETNAME, "_blank" );
2851 
2852  const SfxPoolItem* pRetItem = GetViewData().GetDispatcher().ExecuteList(
2853  SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON,
2854  { &aItem, &aTarget });
2855  if ( pRetItem )
2856  {
2857  if ( auto pObjectItem = dynamic_cast<const SfxObjectItem*>(pRetItem) )
2858  pDestShell = dynamic_cast<ScDocShell*>( pObjectItem->GetShell() );
2859  else if ( auto pViewFrameItem = dynamic_cast<const SfxViewFrameItem*>( pRetItem) )
2860  {
2861  SfxViewFrame* pFrm = pViewFrameItem->GetFrame();
2862  if (pFrm)
2863  pDestShell = dynamic_cast<ScDocShell*>( pFrm->GetObjectShell() );
2864  }
2865  if (pDestShell)
2866  pDestViewSh = pDestShell->GetBestViewShell();
2867  }
2868  }
2869  else
2870  pDestShell = ScDocShell::GetShellByNum( nDestDocNo );
2871 
2872  if (!pDestShell)
2873  {
2874  OSL_FAIL("Destination document not found !!!");
2875  return;
2876  }
2877 
2878  ScMarkData& rMark = GetViewData().GetMarkData();
2879  if (bRename && rMark.GetSelectCount() != 1)
2880  {
2881  // Custom sheet name is provided, but more than one sheet is selected.
2882  // We don't support this scenario at the moment.
2883  return;
2884  }
2885 
2886  ScDocument& rDestDoc = pDestShell->GetDocument();
2887 
2888  if (&rDestDoc != &rDoc)
2889  {
2890  if (bNewDoc)
2891  {
2892  while (rDestDoc.GetTableCount() > 1)
2893  rDestDoc.DeleteTab(0);
2894  rDestDoc.RenameTab( 0, "______42_____" );
2895  }
2896 
2897  SCTAB nTabCount = rDoc.GetTableCount();
2898  SCTAB nTabSelCount = rMark.GetSelectCount();
2899 
2900  vector<SCTAB> TheTabs;
2901 
2902  for(SCTAB i=0; i<nTabCount; ++i)
2903  {
2904  if(rMark.GetTableSelect(i))
2905  {
2906  OUString aTabName;
2907  rDoc.GetName( i, aTabName);
2908  TheTabs.push_back(i);
2909  for(SCTAB j=i+1;j<nTabCount;j++)
2910  {
2911  if((!rDoc.IsVisible(j)) && rDoc.IsScenario(j))
2912  {
2913  rDoc.GetName( j, aTabName);
2914  TheTabs.push_back(j);
2915  i=j;
2916  }
2917  else break;
2918  }
2919  }
2920  }
2921 
2922  GetFrameWin()->EnterWait();
2923 
2924  if (rDoc.GetDrawLayer())
2925  pDestShell->MakeDrawLayer();
2926 
2927  if (!bNewDoc && bUndo)
2928  rDestDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
2929 
2930  sal_uLong nErrVal =1;
2931  if(nDestTab==SC_TAB_APPEND)
2932  nDestTab=rDestDoc.GetTableCount();
2933  SCTAB nDestTab1=nDestTab;
2934  ScClipParam aParam;
2935  for( size_t j=0; j<TheTabs.size(); ++j, ++nDestTab1 )
2936  { // insert sheets first and update all references
2937  OUString aName;
2938  if (bRename)
2939  aName = *pNewTabName;
2940  else
2941  rDoc.GetName( TheTabs[j], aName );
2942 
2943  rDestDoc.CreateValidTabName( aName );
2944  if ( !rDestDoc.InsertTab( nDestTab1, aName ) )
2945  {
2946  nErrVal = 0; // total error
2947  break; // for
2948  }
2949  ScRange aRange( 0, 0, TheTabs[j], rDoc.MaxCol(), rDoc.MaxRow(), TheTabs[j] );
2950  aParam.maRanges.push_back(aRange);
2951  }
2952  rDoc.SetClipParam(aParam);
2953  if ( nErrVal > 0 )
2954  {
2955  nDestTab1 = nDestTab;
2956  for(SCTAB nTab : TheTabs)
2957  {
2958  nErrVal = pDestShell->TransferTab( *pDocShell, nTab, nDestTab1, false, false );
2959  nDestTab1++;
2960  }
2961  }
2962  if (!bNewDoc && bUndo)
2963  {
2964  OUString sName;
2965  rDestDoc.GetName(nDestTab, sName);
2966  pDestShell->GetUndoManager()->AddUndoAction(
2967  std::make_unique<ScUndoImportTab>( pDestShell, nDestTab,
2968  static_cast<SCTAB>(TheTabs.size())));
2969 
2970  }
2971  else
2972  {
2973  pDestShell->GetUndoManager()->Clear();
2974  }
2975 
2976  GetFrameWin()->LeaveWait();
2977  switch (nErrVal)
2978  {
2979  case 0: // internal error or full of errors
2980  {
2981  ErrorMessage(STR_TABINSERT_ERROR);
2982  return;
2983  }
2984  case 2:
2985  ErrorMessage(STR_ABSREFLOST);
2986  break;
2987  case 3:
2988  ErrorMessage(STR_NAMECONFLICT);
2989  break;
2990  case 4:
2991  {
2992  ErrorMessage(STR_ABSREFLOST);
2993  ErrorMessage(STR_NAMECONFLICT);
2994  }
2995  break;
2996  default:
2997  break;
2998  }
2999 
3000  if (!bCopy)
3001  {
3002  if(nTabCount!=nTabSelCount)
3003  DeleteTables(TheTabs); // incl. Paint & Undo
3004  else
3005  ErrorMessage(STR_TABREMOVE_ERROR);
3006  }
3007 
3008  if (bNewDoc)
3009  {
3010  // ChartListenerCollection must be updated before DeleteTab
3011  if ( rDestDoc.IsChartListenerCollectionNeedsUpdate() )
3012  rDestDoc.UpdateChartListenerCollection();
3013 
3014  SCTAB nNumTabsInserted = static_cast<SCTAB>(TheTabs.size());
3015  pDestShell->Broadcast( ScTablesHint( SC_TABS_INSERTED, 0, nNumTabsInserted ) );
3016 
3017  rDestDoc.DeleteTab( nNumTabsInserted ); // old first table
3018  pDestShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nNumTabsInserted ) );
3019 
3020  if (pDestViewSh)
3021  {
3022  // Make sure to clear the cached page view after sheet
3023  // deletion, which still points to the sdr page belonging to
3024  // the deleted sheet.
3025  SdrView* pSdrView = pDestViewSh->GetScDrawView();
3026  if (pSdrView)
3027  pSdrView->ClearPageView();
3028 
3029  pDestViewSh->TabChanged(); // pages on the drawing layer
3030  }
3031  pDestShell->PostPaint( 0,0,0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB,
3034  // PaintPartFlags::Size for outline
3035  }
3036  else
3037  {
3038  pDestShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, nDestTab ) );
3039  pDestShell->PostPaintExtras();
3040  pDestShell->PostPaintGridAll();
3041  }
3042 
3043  TheTabs.clear();
3044 
3045  pDestShell->SetDocumentModified();
3046  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3047  }
3048  else
3049  {
3050  // Move or copy within the same document.
3051  SCTAB nTabCount = rDoc.GetTableCount();
3052 
3053  unique_ptr< vector<SCTAB> > pSrcTabs(new vector<SCTAB>);
3054  unique_ptr< vector<SCTAB> > pDestTabs(new vector<SCTAB>);
3055  unique_ptr< vector<OUString> > pTabNames(new vector<OUString>);
3056  unique_ptr< vector<OUString> > pDestNames;
3057  pSrcTabs->reserve(nTabCount);
3058  pDestTabs->reserve(nTabCount);
3059  pTabNames->reserve(nTabCount);
3060  OUString aDestName;
3061 
3062  for(SCTAB i=0;i<nTabCount;i++)
3063  {
3064  if(rMark.GetTableSelect(i))
3065  {
3066  OUString aTabName;
3067  rDoc.GetName( i, aTabName);
3068  pTabNames->push_back(aTabName);
3069 
3070  for(SCTAB j=i+1;j<nTabCount;j++)
3071  {
3072  if((!rDoc.IsVisible(j)) && rDoc.IsScenario(j))
3073  {
3074  rDoc.GetName( j, aTabName);
3075  pTabNames->push_back(aTabName);
3076  i=j;
3077  }
3078  else break;
3079  }
3080  }
3081  }
3082 
3083  if (bCopy && bUndo)
3084  rDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
3085 
3086  rDoc.GetName( nDestTab, aDestName);
3087  SCTAB nDestTab1=nDestTab;
3088  SCTAB nMovTab=0;
3089  for (size_t j = 0, n = pTabNames->size(); j < n; ++j)
3090  {
3091  nTabCount = rDoc.GetTableCount();
3092  const OUString& rStr = (*pTabNames)[j];
3093  if(!rDoc.GetTable(rStr,nMovTab))
3094  {
3095  nMovTab=nTabCount;
3096  }
3097  if(!rDoc.GetTable(aDestName,nDestTab1))
3098  {
3099  nDestTab1=nTabCount;
3100  }
3101  pDocShell->MoveTable( nMovTab, nDestTab1, bCopy, false ); // Undo is here
3102 
3103  // tdf#43175 - Adjust chart references on every copied sheet
3104  if (bCopy)
3105  {
3106  // New position of source table after moving
3107  SCTAB nSrcTab = (nDestTab1 <= nMovTab) ? nMovTab + 1 : nMovTab;
3108  //#i29848# adjust references to data on the copied sheet
3110  nDestTab1);
3111  }
3112 
3113  if(bCopy && rDoc.IsScenario(nMovTab))
3114  {
3115  OUString aComment;
3116  Color aColor;
3117  ScScenarioFlags nFlags;
3118 
3119  rDoc.GetScenarioData(nMovTab, aComment,aColor, nFlags);
3120  rDoc.SetScenario(nDestTab1,true);
3121  rDoc.SetScenarioData(nDestTab1,aComment,aColor,nFlags);
3122  bool bActive = rDoc.IsActiveScenario(nMovTab );
3123  rDoc.SetActiveScenario( nDestTab1, bActive );
3124  bool bVisible=rDoc.IsVisible(nMovTab);
3125  rDoc.SetVisible(nDestTab1,bVisible );
3126  }
3127 
3128  pSrcTabs->push_back(nMovTab);
3129 
3130  if(!bCopy)
3131  {
3132  if(!rDoc.GetTable(rStr,nDestTab1))
3133  {
3134  nDestTab1=nTabCount;
3135  }
3136  }
3137 
3138  pDestTabs->push_back(nDestTab1);
3139  }
3140 
3141  // Rename must be done after all sheets have been moved.
3142  if (bRename)
3143  {
3144  pDestNames.reset(new vector<OUString>);
3145  size_t n = pDestTabs->size();
3146  pDestNames->reserve(n);
3147  for (size_t j = 0; j < n; ++j)
3148  {
3149  SCTAB nRenameTab = (*pDestTabs)[j];
3150  OUString aTabName = *pNewTabName;
3151  rDoc.CreateValidTabName( aTabName );
3152  pDestNames->push_back(aTabName);
3153  rDoc.RenameTab(nRenameTab, aTabName);
3154  }
3155  }
3156  else
3157  // No need to keep this around when we are not renaming.
3158  pTabNames.reset();
3159 
3160  SCTAB nTab = GetViewData().GetTabNo();
3161 
3162  if (bUndo)
3163  {
3164  if (bCopy)
3165  {
3166  pDocShell->GetUndoManager()->AddUndoAction(
3167  std::make_unique<ScUndoCopyTab>(
3168  pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pDestNames)));
3169  }
3170  else
3171  {
3172  pDocShell->GetUndoManager()->AddUndoAction(
3173  std::make_unique<ScUndoMoveTab>(
3174  pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pTabNames), std::move(pDestNames)));
3175  }
3176  }
3177 
3178  SCTAB nNewTab = nDestTab;
3179  if (nNewTab == SC_TAB_APPEND)
3180  nNewTab = rDoc.GetTableCount()-1;
3181  else if (!bCopy && nTab<nDestTab)
3182  nNewTab--;
3183 
3184  SetTabNo( nNewTab, true );
3185  }
3186 }
3187 
3188 void ScViewFunc::ShowTable( const std::vector<OUString>& rNames )
3189 {
3190  ScDocShell* pDocSh = GetViewData().GetDocShell();
3191  ScDocument& rDoc = pDocSh->GetDocument();
3192  bool bUndo(rDoc.IsUndoEnabled());
3193 
3194  std::vector<SCTAB> undoTabs;
3195  SCTAB nPos = 0;
3196 
3197  bool bFound(false);
3198 
3199  for (const OUString& aName : rNames)
3200  {
3201  if (rDoc.GetTable(aName, nPos))
3202  {
3203  rDoc.SetVisible( nPos, true );
3204  SetTabNo( nPos, true );
3205  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3206  if (!bFound)
3207  bFound = true;
3208  if (bUndo)
3209  undoTabs.push_back(nPos);
3210  }
3211  }
3212  if (bFound)
3213  {
3214  if (bUndo)
3215  {
3216  pDocSh->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoShowHideTab>( pDocSh, std::move(undoTabs), true ) );
3217  }
3218  pDocSh->PostPaint(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB, PaintPartFlags::Extras);
3219  pDocSh->SetDocumentModified();
3220  }
3221 }
3222 
3223 void ScViewFunc::HideTable( const ScMarkData& rMark, SCTAB nTabToSelect )
3224 {
3225  ScDocShell* pDocSh = GetViewData().GetDocShell();
3226  ScDocument& rDoc = pDocSh->GetDocument();
3227  bool bUndo(rDoc.IsUndoEnabled());
3228  SCTAB nVisible = 0;
3229  SCTAB nTabCount = rDoc.GetTableCount();
3230 
3231  SCTAB nTabSelCount = rMark.GetSelectCount();
3232 
3233  // check to make sure we won't hide all sheets. we need at least one visible at all times.
3234  for ( SCTAB i=0; i < nTabCount && nVisible <= nTabSelCount ; i++ )
3235  if (rDoc.IsVisible(i))
3236  ++nVisible;
3237 
3238  if (nVisible <= nTabSelCount)
3239  return;
3240 
3241  std::vector<SCTAB> undoTabs;
3242 
3243  // need to take a copy of selectedtabs since it is modified in the loop
3244  const ScMarkData::MarkedTabsType selectedTabs = rMark.GetSelectedTabs();
3245  for (const SCTAB& nTab : selectedTabs)
3246  {
3247  if (rDoc.IsVisible( nTab ))
3248  {
3249  rDoc.SetVisible( nTab, false );
3250  // Update views
3251  pDocSh->Broadcast( ScTablesHint( SC_TAB_HIDDEN, nTab ) );
3252  SetTabNo( nTab, true );
3253  // Store for undo
3254  if (bUndo)
3255  undoTabs.push_back(nTab);
3256  }
3257  }
3258 
3259  if (nTabToSelect != -1)
3260  SetTabNo(nTabToSelect);
3261 
3262  if (bUndo)
3263  {
3264  pDocSh->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoShowHideTab>( pDocSh, std::move(undoTabs), false ) );
3265  }
3266 
3267  // Update views
3268  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3269  pDocSh->PostPaint(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB, PaintPartFlags::Extras);
3270  pDocSh->SetDocumentModified();
3271 }
3272 
3273 void ScViewFunc::InsertSpecialChar( const OUString& rStr, const vcl::Font& rFont )
3274 {
3275  ScEditableTester aTester( this );
3276  if (!aTester.IsEditable())
3277  {
3278  ErrorMessage(aTester.GetMessageId());
3279  return;
3280  }
3281 
3282  const sal_Unicode* pChar = rStr.getStr();
3283  ScTabViewShell* pViewShell = GetViewData().GetViewShell();
3284  SvxFontItem aFontItem( rFont.GetFamilyType(),
3285  rFont.GetFamilyName(),
3286  rFont.GetStyleName(),
3287  rFont.GetPitch(),
3288  rFont.GetCharSet(),
3289  ATTR_FONT );
3290 
3291  // if string contains WEAK characters, set all fonts
3292  SvtScriptType nScript;
3293  ScDocument& rDoc = GetViewData().GetDocument();
3294  if ( rDoc.HasStringWeakCharacters( rStr ) )
3295  nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
3296  else
3297  nScript = rDoc.GetStringScriptType( rStr );
3298 
3299  SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, pViewShell->GetPool() );
3300  aSetItem.PutItemForScriptType( nScript, aFontItem );
3301  ApplyUserItemSet( aSetItem.GetItemSet() );
3302 
3303  while ( *pChar )
3304  pViewShell->TabKeyInput( KeyEvent( *(pChar++), vcl::KeyCode() ) );
3305 }
3306 
3307 void ScViewFunc::UpdateLineAttrs( SvxBorderLine& rLine,
3308  const SvxBorderLine* pDestLine,
3309  const SvxBorderLine* pSrcLine,
3310  bool bColor )
3311 {
3312  if ( !(pSrcLine && pDestLine) )
3313  return;
3314 
3315  if ( bColor )
3316  {
3317  rLine.SetColor ( pSrcLine->GetColor() );
3318  rLine.SetBorderLineStyle(pDestLine->GetBorderLineStyle());
3319  rLine.SetWidth ( pDestLine->GetWidth() );
3320  }
3321  else
3322  {
3323  rLine.SetColor ( pDestLine->GetColor() );
3324  rLine.SetBorderLineStyle(pSrcLine->GetBorderLineStyle());
3325  rLine.SetWidth ( pSrcLine->GetWidth() );
3326  }
3327 }
3328 
3329 #define SET_LINE_ATTRIBUTES(LINE,BOXLINE) \
3330  pBoxLine = aBoxItem.Get##LINE(); \
3331  if ( pBoxLine ) \
3332  { \
3333  if ( pLine ) \
3334  { \
3335  UpdateLineAttrs( aLine, pBoxLine, pLine, bColorOnly ); \
3336  aBoxItem.SetLine( &aLine, BOXLINE ); \
3337  } \
3338  else \
3339  aBoxItem.SetLine( nullptr, BOXLINE ); \
3340  }
3341 
3342 void ScViewFunc::SetSelectionFrameLines( const SvxBorderLine* pLine,
3343  bool bColorOnly )
3344 {
3345  // Not editable only due to a matrix? Attribute is ok anyhow.
3346  bool bOnlyNotBecauseOfMatrix;
3347  if ( !SelectionEditable( &bOnlyNotBecauseOfMatrix ) && !bOnlyNotBecauseOfMatrix )
3348  {
3349  ErrorMessage(STR_PROTECTIONERR);
3350  return;
3351  }
3352 
3353  ScDocument& rDoc = GetViewData().GetDocument();
3354  ScMarkData aFuncMark( GetViewData().GetMarkData() ); // local copy for UnmarkFiltered
3355  ScViewUtil::UnmarkFiltered( aFuncMark, rDoc );
3356  ScDocShell* pDocSh = GetViewData().GetDocShell();
3357  const ScPatternAttr* pSelAttrs = GetSelectionPattern();
3358  const SfxItemSet& rSelItemSet = pSelAttrs->GetItemSet();
3359 
3360  const SfxPoolItem* pBorderAttr = nullptr;
3361  SfxItemState eItemState = rSelItemSet.GetItemState( ATTR_BORDER, true, &pBorderAttr );
3362 
3363  const SfxPoolItem* pTLBRItem = nullptr;
3364  SfxItemState eTLBRState = rSelItemSet.GetItemState( ATTR_BORDER_TLBR, true, &pTLBRItem );
3365 
3366  const SfxPoolItem* pBLTRItem = nullptr;
3367  SfxItemState eBLTRState = rSelItemSet.GetItemState( ATTR_BORDER_BLTR, true, &pBLTRItem );
3368 
3369  // any of the lines visible?
3370  if( !((eItemState != SfxItemState::DEFAULT) || (eTLBRState != SfxItemState::DEFAULT) || (eBLTRState != SfxItemState::DEFAULT)) )
3371  return;
3372 
3373  // none of the lines don't care?
3374  if( (eItemState != SfxItemState::DONTCARE) && (eTLBRState != SfxItemState::DONTCARE) && (eBLTRState != SfxItemState::DONTCARE) )
3375  {
3378 
3379  SvxBorderLine aLine;
3380 
3381  if( pBorderAttr )
3382  {
3383  const SvxBorderLine* pBoxLine = nullptr;
3384  SvxBoxItem aBoxItem( *static_cast<const SvxBoxItem*>(pBorderAttr) );
3385  SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
3386 
3387  // here pBoxLine is used
3388  SET_LINE_ATTRIBUTES(Top,SvxBoxItemLine::TOP)
3389  SET_LINE_ATTRIBUTES(Bottom,SvxBoxItemLine::BOTTOM)
3390  SET_LINE_ATTRIBUTES(Left,SvxBoxItemLine::LEFT)
3391  SET_LINE_ATTRIBUTES(Right,SvxBoxItemLine::RIGHT)
3392 
3393  aBoxInfoItem.SetLine( aBoxItem.GetTop(), SvxBoxInfoItemLine::HORI );
3394  aBoxInfoItem.SetLine( aBoxItem.GetLeft(), SvxBoxInfoItemLine::VERT );
3395  aBoxInfoItem.ResetFlags(); // set Lines to Valid
3396 
3397  aOldSet.Put( *pBorderAttr );
3398  aNewSet.Put( aBoxItem );
3399  aNewSet.Put( aBoxInfoItem );
3400  }
3401 
3402  if( pTLBRItem && static_cast<const SvxLineItem*>(pTLBRItem)->GetLine() )
3403  {
3404  SvxLineItem aTLBRItem( *static_cast<const SvxLineItem*>(pTLBRItem) );
3405  UpdateLineAttrs( aLine, aTLBRItem.GetLine(), pLine, bColorOnly );
3406  aTLBRItem.SetLine( &aLine );
3407  aOldSet.Put( *pTLBRItem );
3408  aNewSet.Put( aTLBRItem );
3409  }
3410 
3411  if( pBLTRItem && static_cast<const SvxLineItem*>(pBLTRItem)->GetLine() )
3412  {
3413  SvxLineItem aBLTRItem( *static_cast<const SvxLineItem*>(pBLTRItem) );
3414  UpdateLineAttrs( aLine, aBLTRItem.GetLine(), pLine, bColorOnly );
3415  aBLTRItem.SetLine( &aLine );
3416  aOldSet.Put( *pBLTRItem );
3417  aNewSet.Put( aBLTRItem );
3418  }
3419 
3420  ApplyAttributes( &aNewSet, &aOldSet );
3421  }
3422  else // if ( eItemState == SfxItemState::DONTCARE )
3423  {
3424  aFuncMark.MarkToMulti();
3425  rDoc.ApplySelectionLineStyle( aFuncMark, pLine, bColorOnly );
3426  }
3427 
3428  ScRange aMarkRange;
3429  aFuncMark.GetMultiMarkArea( aMarkRange );
3430  SCCOL nStartCol = aMarkRange.aStart.Col();
3431  SCROW nStartRow = aMarkRange.aStart.Row();
3432  SCTAB nStartTab = aMarkRange.aStart.Tab();
3433  SCCOL nEndCol = aMarkRange.aEnd.Col();
3434  SCROW nEndRow = aMarkRange.aEnd.Row();
3435  SCTAB nEndTab = aMarkRange.aEnd.Tab();
3436  pDocSh->PostPaint( nStartCol, nStartRow, nStartTab,
3437  nEndCol, nEndRow, nEndTab,
3439 
3440  pDocSh->UpdateOle(GetViewData());
3441  pDocSh->SetDocumentModified();
3442 }
3443 
3444 #undef SET_LINE_ATTRIBUTES
3445 
3447 {
3448  ScDocument& rDoc = GetViewData().GetDocument();
3449  sal_uLong nIndex = rDoc.AddValidationEntry(rNew); // for it there is no Undo
3450  SfxUInt32Item aItem( ATTR_VALIDDATA, nIndex );
3451 
3452  ApplyAttr( aItem ); // with Paint and Undo...
3453 }
3454 
3455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC OUString GetLinkDoc(SCTAB nTab) const
Definition: documen3.cxx:511
void FillTabMarked(SCTAB nSrcTab, const ScMarkData &rMark, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: document.cxx:3332
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1767
std::shared_ptr< SfxDialogController > & GetController()
static ScAutoSum lcl_GetAutoSumForColumnRange(ScDocument &rDoc, ScRangeList &rRangeList, const ScRange &rRange)
Definition: viewfun2.cxx:382
SC_DLLPUBLIC void InsertPageBreak(bool bColumn, bool bRecord=true, const ScAddress *pPos=nullptr, bool bSetModified=true)
Definition: viewfun2.cxx:972
OUString GetLinkOpt(SCTAB nTab) const
Definition: documen3.cxx:525
#define SC_PF_TESTMERGE
Definition: docsh.hxx:77
void BeginDrawUndo()
Definition: documen9.cxx:60
formula::FormulaToken * AddDoubleReference(const ScComplexRefData &rRef)
Definition: token.cxx:2281
ocStDevP
void UpdateLinks() override
Definition: docsh6.cxx:319
constexpr double nPPTY
void UpdatePageBreaks(SCTAB nTab, const ScRange *pUserArea=nullptr)
Definition: document.cxx:6235
bool InsertTable(const OUString &rName, SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2368
OUString GetColRowString() const
Create a human-readable string representation of the cell address.
Definition: address.cxx:2489
void FillResults(ScDocument &rDoc, const ScRangeList &rMatchedRanges, bool bCellNotes, bool bEmptyCells)
void MarkToSimple()
Definition: markdata.cxx:236
const std::vector< editeng::MisspellRanges > * GetAutoSpellData(SCCOL nPosX, SCROW nPosY)
Definition: gridwin.cxx:5914
bool HasLink(std::u16string_view rDoc, std::u16string_view rFilter, std::u16string_view rOptions) const
Definition: documen3.cxx:554
sal_Int32 nIndex
double GetPPTY() const
Definition: sizedev.hxx:42
void MoveTable(sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString *pNewTabName=nullptr)
Definition: viewfun2.cxx:2832
OpCode GetOuterFuncOpCode() const
ScAddress aStart
Definition: address.hxx:499
SC_DLLPUBLIC void ApplyPatternIfNumberformatIncompatible(const ScRange &rRange, const ScMarkData &rMark, const ScPatternAttr &rPattern, SvNumFormatType nNewType)
Definition: document.cxx:4813
bool bVisible
SC_DLLPUBLIC void SetScenario(SCTAB nTab, bool bFlag)
Definition: documen3.cxx:426
bool AdjustBlockHeight(bool bPaint=true, ScMarkData *pMarkData=nullptr)
Definition: viewfun2.cxx:114
void RemoveManualBreaks()
Definition: viewfun2.cxx:1006
void SetSelectionFrameLines(const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: viewfun2.cxx:3342
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1914
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: docsh3.cxx:451
void InsertTableLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, std::u16string_view rTabName)
Definition: viewfun2.cxx:2677
SfxChildWindow * GetChildWindow(sal_uInt16)
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
Definition: documen3.cxx:504
const OUString & GetFamilyName() const
void PutItemForScriptType(SvtScriptType nScriptType, const SfxPoolItem &rItem)
bool IsPrinter() const
Definition: sizedev.hxx:43
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
constexpr OUStringLiteral STRING_SCAPP
Definition: global.hxx:57
SCROW Row() const
Definition: address.hxx:261
ocVar
void PostPaintGridAll()
Definition: docsh3.cxx:183
void MarkToMulti()
Definition: markdata.cxx:223
bool GetAutoSumArea(ScRangeList &rRangeList)
Definition: viewfun2.cxx:509
bool AppendTable(const OUString &rName, bool bRecord=true)
Definition: viewfun2.cxx:2423
FillDir
Definition: global.hxx:305
void SetPrintRanges(bool bEntireSheet, const OUString *pPrint, const OUString *pRepCol, const OUString *pRepRow, bool bAddPrint)
Definition: viewfun2.cxx:1045
void FillTab(InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: viewfun2.cxx:1669
const OUString & GetStyleName() const
signed char sal_Int8
SC_DLLPUBLIC bool IsActiveScenario(SCTAB nTab) const
Definition: documen3.cxx:880
SC_DLLPUBLIC void SetDrawPageSize(SCTAB nTab)
Definition: documen9.cxx:195
SC_DLLPUBLIC bool InsertTabs(SCTAB nPos, const std::vector< OUString > &rNames, bool bNamesValid=false)
Definition: document.cxx:592
std::unique_ptr< sal_Int32[]> pData
void SetMultiMarkArea(const ScRange &rRange, bool bMark=true, bool bSetupMulti=false)
Definition: markdata.cxx:121
ScScenarioFlags
Definition: global.hxx:223
void ResetMark()
Definition: markdata.cxx:84
SC_DLLPUBLIC bool MergeCells(const ScCellMergeOption &rOption, bool bContents, bool bRecord, bool bApi, bool bEmptyMergedCells=false)
Definition: docfunc.cxx:4927
void GetCellSelection(std::vector< tools::Rectangle > &rLogicRects)
Get the cell selection, coordinates are in logic units.
Definition: gridwin.cxx:6508
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
const OUString & GetName() const
ScTokenArray * GetCode()
sal_uIntPtr sal_uLong
SCCOL GetMaxColCount() const
Definition: sheetlimits.hxx:63
SC_DLLPUBLIC void ClearPrintRanges(SCTAB nTab)
Removes all print ranges.
Definition: document.cxx:6317
ocSubTotal
ocOpen
sal_Int64 n
void ApplySelectionLineStyle(const ScMarkData &rMark, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: document.cxx:4901
void ResetAutoSpellForContentChange()
Definition: gridwin.cxx:5900
void SetValidation(const ScValidationData &rNew)
Definition: viewfun2.cxx:3446
ScMergeCellsOption GetMergeCellsOption() const
std::vector< sc::ColRowSpan > GetMarkedRowSpans() const
Definition: markdata.cxx:478
aBuf
SvNumFormatType GetType(sal_uInt32 nFIndex) const
void DeleteTable(SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2454
void SetDocumentModified()
Definition: docsh.cxx:2939
const SfxItemSet & GetItemSet() const
void PostPaintExtras()
Definition: docsh3.cxx:198
void EnterBlock(const OUString &rString, const EditTextObject *pData)
Definition: viewfun2.cxx:882
void Solve(const ScSolveParam &rParam)
Definition: viewfun2.cxx:2234
static ScAutoSum lcl_GetAutoSumForRowRange(ScDocument &rDoc, ScRangeList &rRangeList, const ScRange &rRange)
Definition: viewfun2.cxx:429
SC_DLLPUBLIC void SetRepeatColRange(SCTAB nTab, std::unique_ptr< ScRange > pNew)
Definition: document.cxx:6335
constexpr TypedWhichId< SvxBoxInfoItem > ATTR_BORDER_INNER(151)
bool DeleteTable(SCTAB nTab, bool bRecord)
Definition: docfunc.cxx:3314
void InitRangeRel(const ScDocument &rDoc, const ScRange &rRange, const ScAddress &rPos)
Definition: refdata.hxx:135
ScAddress aEnd
Definition: address.hxx:500
SC_DLLPUBLIC bool DeleteTabs(SCTAB nTab, SCTAB nSheets)
Definition: document.cxx:761
bool FillSimple(const ScRange &rRange, const ScMarkData *pTabMark, FillDir eDir, bool bApi)
Definition: docfunc.cxx:4539
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
ocProduct
void SetCellSelectionPixel(int nType, int nPixelX, int nPixelY)
Update the cell selection according to what handles have been dragged.
Definition: gridwin4.cxx:1572
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
void SetLine(const editeng::SvxBorderLine *pNew)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:990
#define SC_TAB_INSERTED
Definition: uiitems.hxx:75
void Invalidate(sal_uInt16 nId)
void TabChanged(bool bSameTabButMoved=false)
Called after moving, copying, inserting or deleting a sheet.
Definition: tabview5.cxx:282
ocCount
ocMin
bool IsLinked(SCTAB nTab) const
Definition: documen3.cxx:485
virtual SfxObjectShell * GetObjectShell() override
bool HasStringWeakCharacters(const OUString &rString)
Definition: documen6.cxx:51
const MarkedTabsType & GetSelectedTabs() const
Definition: markdata.hxx:97
RET_CANCEL
SC_DLLPUBLIC void SetVisible(SCTAB nTab, bool bVisible)
Definition: document.cxx:901
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
sal_uLong TransferTab(ScDocShell &rSrcDocShell, SCTAB nSrcPos, SCTAB nDestPos, bool bInsertNew, bool bNotifyAndPaint)
Definition: docsh5.cxx:854
bool Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab, SCCOL nVCol, SCROW nVRow, SCTAB nVTab, const OUString &sValStr, double &nX)
(Goal Seek) Find a value of x that is a root of f(x)
Definition: documen4.cxx:71
SC_DLLPUBLIC bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, HasAttrFlags nMask) const
Definition: document.cxx:5193
std::unique_ptr< ScPrintRangeSaver > CreatePrintRangeSaver() const
Definition: document.cxx:6347
static void notifyAllViewsSheetGeomInvalidation(const SfxViewShell *pForViewShell, bool bColumns, bool bRows, bool bSizes, bool bHidden, bool bFiltered, bool bGroups, SCTAB nCurrentTabIndex)
Emits a LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY for all views whose current tab is equal to nCurrentTa...
Definition: tabvwshc.cxx:556
SC_DLLPUBLIC SvtScriptType GetStringScriptType(const OUString &rString)
Definition: documen6.cxx:76
ocCount2
void ConvertFormulaToValue()
Definition: viewfun2.cxx:1860
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4180
FontFamily GetFamilyType()
void SetClipParam(const ScClipParam &rParam)
Definition: document.cxx:2578
#define SC_DOC_NEW
Definition: document.hxx:240
SfxApplication * SfxGetpApp()
bool RenameTable(const OUString &rName, SCTAB nTabNr)
Definition: viewfun2.cxx:2631
Internal use only (d&d undo): do not delete caption objects of cell notes.
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6075
void GetMarkArea(ScRange &rRange) const
Definition: markdata.cxx:111
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2925
RET_NO
::std::set< SCTAB > maTabs
static UITestLogger & getInstance()
void InsertTables(std::vector< OUString > &aNames, SCTAB nTab, SCTAB nCount, bool bRecord=true)
Definition: viewfun2.cxx:2381
void logEvent(const EventDescription &rDescription)
static bool lcl_extendMergeRange(ScCellMergeOption &rOption, const ScRange &rRange)
Definition: viewfun2.cxx:1312
sal_uInt16 sal_Unicode
static sal_Int8 GetSubTotal(const OpCode eCode)
Definition: viewfun2.cxx:476
RET_YES
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:853
void FillSeries(FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd, double fStart, double fStep, double fMax)
Definition: viewfun2.cxx:1437
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:878
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
SCTAB GetSelectCount() const
Definition: markdata.cxx:194
bool IsMultiMarked() const
Definition: markdata.hxx:82
SvxSearchCellType GetCellType() const
OpCode
SfxFrame & GetFrame() const
int nCount
FillDateCmd
Definition: global.hxx:330
void ConvertFormulaToValue(const ScRange &rRange, bool bInteraction)
Definition: docfunc.cxx:5721
void TransliterateText(TransliterationFlags nType)
Definition: viewfun2.cxx:1871
void CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, InsertDeleteFlags nFlags, bool bMarked, ScDocument &rDestDoc, const ScMarkData *pMarks=nullptr, bool bColRowFlags=true)
Definition: document.cxx:2054
#define SC_AUTOSUM_MAXCOUNT
Definition: viewfun2.cxx:319
virtual void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
ScDocShell * GetDocShell()
Definition: tablink.hxx:90
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
Definition: document.cxx:260
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1149
void UpdateScriptTypes(const ScAddress &rPos, SCCOL nColSize, SCROW nRowSize)
Definition: document10.cxx:333
void AutoFormat(sal_uInt16 nFormatNo)
Definition: viewfun2.cxx:1913
bool RemoveMerge()
Definition: viewfun2.cxx:1338
bool InsideVisibleRange(SCCOL nPosX, SCROW nPosY)
Definition: gridwin.cxx:5925
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:110
SCTAB Tab() const
Definition: address.hxx:270
void SetRow(SCROW nRowP)
Definition: address.hxx:274
bool SearchAndReplace(const SvxSearchItem *pSearchItem, bool bAddUndo, bool bIsApi)
Definition: viewfun2.cxx:1931
#define SC_TAB_DELETED
Definition: uiitems.hxx:76
static OUString GetOptions(const SfxMedium &rMedium)
Definition: tablink.cxx:422
OUString GetAutoSumFormula(const ScRangeList &rRangeList, bool bSubTotal, const ScAddress &rAddr, const OpCode eCode)
Definition: viewfun2.cxx:841
ScAddress aRefVariableCell
Definition: paramisc.hxx:28
static sal_Unicode GetNativeSymbolChar(OpCode eOp)
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4754
void SetCol(SCCOL nColP)
Definition: address.hxx:278
const char * sName
ScDrawLayer * MakeDrawLayer()
Definition: docsh2.cxx:169
TransliterationFlags
SC_DLLPUBLIC void DeletePageBreak(bool bColumn, bool bRecord=true, const ScAddress *pPos=nullptr, bool bSetModified=true)
Definition: viewfun2.cxx:989
SfxItemPool & GetPool() const
static void AdjustRangesOfChartsOnDestinationPage(const ScDocument &rSrcDoc, ScDocument &rDestDoc, const SCTAB nSrcTab, const SCTAB nDestTab)
sal_Int32 GetStartPointX() const
bool AutoFormat(const ScRange &rRange, const ScMarkData *pTabMark, sal_uInt16 nFormatNo, bool bApi)
Definition: docfunc.cxx:4199
OutputDevice * GetDevice() const
Definition: sizedev.hxx:40
bool empty() const
Definition: rangelst.hxx:88
ocSep
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1947
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_TLBR(141)
ocVarP
constexpr double nPPTX
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALIDDATA(153)
std::optional< OUString > pStrTargetVal
Definition: paramisc.hxx:29
void SetMarkArea(const ScRange &rRange)
Definition: markdata.cxx:96
ScPasteFunc
Definition: global.hxx:178
static bool lcl_FindNextSumEntryInColumn(ScDocument &rDoc, SCCOL nCol, SCROW &nRow, SCTAB nTab, SCCOLROW &nExtend, SCROW nMinRow)
Definition: viewfun2.cxx:352
void SetTab(SCTAB nTabP)
Definition: address.hxx:282
SC_DLLPUBLIC void SetScenarioData(SCTAB nTab, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: documen3.cxx:437
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1064
const editeng::SvxBorderLine * GetTop() const
static void UpdateLineAttrs(::editeng::SvxBorderLine &rLine, const ::editeng::SvxBorderLine *pDestLine, const ::editeng::SvxBorderLine *pSrcLine, bool bColor)
Definition: viewfun2.cxx:3307
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:877
T * get() const
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:442
bool IsChartListenerCollectionNeedsUpdate() const
Definition: document.hxx:2168
void UseScenario(const OUString &rName)
Definition: viewfun2.cxx:2356
void ShowTable(const std::vector< OUString > &rNames)
Definition: viewfun2.cxx:3188
Parameter for data table aka multiple operations.
Definition: paramisc.hxx:45
SvtScriptType
FillCmd
Definition: global.hxx:313
SC_DLLPUBLIC CellType GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:3767
FontPitch GetPitch()
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:601
const SCTAB SC_TAB_APPEND
Definition: address.hxx:83
bool IsMarked() const
Definition: markdata.hxx:81
const editeng::SvxBorderLine * GetLeft() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
SvxSearchCmd GetCommand() const
ScRange getSingleRange(SCTAB nTab) const
SC_DLLPUBLIC void SetActiveScenario(SCTAB nTab, bool bActive)
Definition: documen3.cxx:885
SC_DLLPUBLIC void CreateValidTabNames(std::vector< OUString > &aNames, SCTAB nCount) const
Definition: document.cxx:439
void FillTab(const ScRange &rSrcArea, const ScMarkData &rMark, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: document.cxx:3264
void IncCol(SCCOL nDelta=1)
Definition: address.hxx:303
void SelectTable(SCTAB nTab, bool bNew)
Definition: markdata.cxx:171
void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges, const OUString &rType=OUString("cell-change"), const css::uno::Sequence< css::beans::PropertyValue > &rProperties=css::uno::Sequence< css::beans::PropertyValue >())
Definition: docsh.hxx:483
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2630
sal_Int16 SCCOL
Definition: types.hxx:21
void GetAutoFormatData(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScAutoFormatData &rData)
Definition: documen3.cxx:1203
InsertDeleteFlags
Definition: global.hxx:147
#define SC_TAB_HIDDEN
Definition: uiitems.hxx:79
static void UpdateSearchItemAddressForReplace(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow)
Replace behaves differently to the Search; adjust the rCol and rRow accordingly.
Definition: table6.cxx:546
bool TestMergeCells()
Definition: viewfun2.cxx:1154
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:879
virtual void Clear()
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:392
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxInfoItemLine nLine)
const OUString & GetReplaceString() const
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:453
size_t size() const
Definition: rangelst.hxx:89
void SetCommand(SvxSearchCmd nNewCommand)
static ScAutoSum lcl_SeekAutoSumData(ScDocument &rDoc, SCCOL &nCol, SCROW &nRow, SCTAB nTab, ScDirection eDir, SCCOLROW &nExtend)
Definition: viewfun2.cxx:321
void IncRow(SCROW nDelta=1)
Definition: address.hxx:299
void SetPrintZoom(SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages)
Definition: docsh4.cxx:1638
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
Definition: documen3.cxx:546
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
SC_DLLPUBLIC bool InsertTab(SCTAB nPos, const OUString &rName, bool bExternalDocument=false, bool bUndoDeleteTab=false)
Definition: document.cxx:504
SvNumFormatType
bool GetBackward() const
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1256
ocMax
OUString GetLinkFlt(SCTAB nTab) const
Definition: documen3.cxx:518
void SetAutoSpellData(SCCOL nPosX, SCROW nPosY, const std::vector< editeng::MisspellRanges > *pRanges)
Definition: gridwin.cxx:5906
void UseScenario(SCTAB nTab, const OUString &rName, bool bRecord=true)
Definition: docsh5.cxx:659
iterator end()
Definition: markdata.cxx:952
#define SET_LINE_ATTRIBUTES(LINE, BOXLINE)
Definition: viewfun2.cxx:3329
PaintArea
bool IsEditable() const
Definition: editable.hxx:84
bool hasNumeric() const
Definition: cellvalue.cxx:622
bool IsBlockEmpty(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bIgnoreNotes=false) const
Definition: document.cxx:5310
static ScAutoSum lcl_IsAutoSumData(ScDocument &rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, ScDirection eDir, SCCOLROW &nExtend)
Definition: viewfun2.cxx:270
bool IsAllTables() const
void GetSearchAndReplaceStart(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow)
Definition: documen3.cxx:1217
static void UnmarkFiltered(ScMarkData &rMark, const ScDocument &rDoc)
Definition: viewutil.cxx:223
SC_DLLPUBLIC void AddPrintRange(SCTAB nTab, const ScRange &rNew)
Adds a new print ranges.
Definition: document.cxx:6323
const SCTAB MAXTAB
Definition: address.hxx:70
void RemoveManualBreaks(SCTAB nTab)
Definition: document.cxx:6241
static void notifyAllViewsHeaderInvalidation(const SfxViewShell *pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
Emits a LOK_CALLBACK_INVALIDATE_HEADER for all views whose current tab is equal to nCurrentTabIndex...
Definition: tabvwshc.cxx:498
ScRangeList maRanges
Definition: clipparam.hxx:34
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
SC_DLLPUBLIC bool ExtendMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, SCTAB nTab, bool bRefresh=false)
Definition: document.cxx:5582
bool TabOp(const ScRange &rRange, const ScMarkData *pTabMark, const ScTabOpParam &rParam, bool bRecord, bool bApi)
Definition: docfunc.cxx:4399
TranslateId GetMessageId() const
Definition: editable.cxx:152
const std::shared_ptr< const SfxFilter > & GetFilter() const
void PostDataChanged()
Definition: docsh3.cxx:93
SfxViewShell * GetViewShell() const
static void SetSearchLabel(const SearchLabel &rSL)
bool GetAdjacentExtendOfOuterFuncRefs(SCCOLROW &nExtend, const ScAddress &rPos, ScDirection)
Determines the extent of direct adjacent references.
Definition: token.cxx:2336
SCCOL Col() const
Definition: address.hxx:266
SC_DLLPUBLIC void SetRepeatRowRange(SCTAB nTab, std::unique_ptr< ScRange > pNew)
Definition: document.cxx:6341
static bool IsEmptyCellSearch(const SvxSearchItem &rSearchItem)
Definition: documen3.cxx:1304
void InsertAreaLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, const OUString &rSource, const ScRange &rDestRange, sal_uLong nRefresh, bool bFitBlock, bool bApi)
Definition: docfunc.cxx:5508
void CopyAutoSpellData(FillDir eDir, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount)
Definition: viewfun2.cxx:1508
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2625
virtual void ClearPageView() override
void InsertAreaLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, const OUString &rSource)
Definition: viewfun2.cxx:2664
ScModelObj * getMustPropagateChangesModel(const ScDocShell &rDocShell)
Definition: docsh.hxx:475
bool IsError() const
Definition: tablink.cxx:578
SC_DLLPUBLIC void GetScenarioData(SCTAB nTab, OUString &rComment, Color &rColor, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:468
#define SC_TABS_DELETED
Definition: uiitems.hxx:81
void SetPrintZoom(sal_uInt16 nScale)
Definition: viewfun2.cxx:1030
bool UnmergeCells(const ScRange &rRange, bool bRecord, ScUndoRemoveMerge *pUndoRemoveMerge)
Definition: docfunc.cxx:5044
virtual formula::FormulaToken * AddOpCode(OpCode eCode) override
Definition: token.cxx:2264
CellType meType
Definition: cellvalue.hxx:105
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:448
SC_DLLPUBLIC bool SetOptimalHeight(sc::RowHeightContext &rCxt, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bApi)
Definition: document.cxx:4285
SC_DLLPUBLIC sal_uLong AddValidationEntry(const ScValidationData &rNew)
Definition: documen4.cxx:726
SC_DLLPUBLIC void FillAuto(FillDir eDir, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount)
Definition: viewfun2.cxx:1460
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
iterator begin()
Definition: markdata.cxx:947
sal_Int32 SCROW
Definition: types.hxx:17
void PutInOrder()
Definition: address.cxx:1574
#define SC_PF_LINES
Definition: docsh.hxx:76
void UpdateOle(const ScViewData &rViewData, bool bSnapSize=false)
Definition: docsh6.cxx:152
bool MergeCells(bool bApi, bool &rDoContents, bool bCenter)
Definition: viewfun2.cxx:1171
static SfxViewFrame * Current()
const editeng::SvxBorderLine * GetLine() const
SfxItemState
ocAverage
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
ScDrawView * GetScDrawView()
Definition: tabview.hxx:341
bool AutoSum(const ScRange &rRange, bool bSubTotal, bool bSetCursor, bool bContinue, const OpCode eCode)
Definition: viewfun2.cxx:621
#define SC_TABS_INSERTED
Definition: uiitems.hxx:80
SvBaseLink * pLink
void FindAreaPos(SCCOL &rCol, SCROW &rRow, SCTAB nTab, ScMoveDirection eDirection) const
Definition: document.cxx:6102
CellType
Definition: global.hxx:268
SCTAB MakeScenario(SCTAB nTab, const OUString &rName, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags, ScMarkData &rMark, bool bRecord=true)
Definition: docsh5.cxx:784
OUString aName
field button for datapilot
void SetWhich(sal_uInt16 nId)
SCTAB GetFirstSelected() const
Definition: markdata.cxx:199
sal_uLong GetLinkRefreshDelay(SCTAB nTab) const
Definition: documen3.cxx:539
const OUString & GetSearchString() const
sal_Int32 GetStartPointY() const
RET_OK
const ScSheetEvents * GetSheetEvents(SCTAB nTab) const
Definition: documen3.cxx:663
SCTAB GetLastSelected() const
Definition: markdata.cxx:208
bool SetTabBgColor(const Color &rColor, SCTAB nTabNr)
Definition: viewfun2.cxx:2644
void EnterAutoSum(const ScRangeList &rRangeList, bool bSubTotal, const ScAddress &rAddr, const OpCode eCode)
Definition: viewfun2.cxx:615
static bool lcl_FindNextSumEntryInRow(ScDocument &rDoc, SCCOL &nCol, SCROW nRow, SCTAB nTab, SCCOLROW &nExtend, SCCOL nMinCol)
Definition: viewfun2.cxx:367
bool IsInVBAMode() const
Definition: document.cxx:6505
SC_DLLPUBLIC bool HasData(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen5.cxx:526
virtual short run()
SC_DLLPUBLIC void FillSimple(FillDir eDir)
Definition: viewfun2.cxx:1388
void * p
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
SC_DLLPUBLIC OUString GetLinkTab(SCTAB nTab) const
Definition: documen3.cxx:532
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
const char * pChar
bool IsAutoSpell() const
Definition: docoptio.hxx:53
bool TabKeyInput(const KeyEvent &rKEvt)
Definition: tabvwsh4.cxx:1175
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:570
SC_DLLPUBLIC void SetPrintEntireSheet(SCTAB nTab)
Marks the specified sheet to be printed completely.
Definition: document.cxx:6329
SC_DLLPUBLIC bool DeleteTab(SCTAB nTab)
Definition: document.cxx:673
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:448
void NotifyIfChangesListeners(const ScDocShell &rDocShell, const ScRange &rRange, const OUString &rType=OUString("cell-change"))
Definition: docsh.hxx:491
SvxSearchCmd
void ShowChildWindow(sal_uInt16, bool bVisible=true)
bool DeleteTables(const std::vector< SCTAB > &TheTabs, bool bRecord=true)
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:986
void ImportTables(ScDocShell *pSrcShell, SCTAB nCount, const SCTAB *pSrcTabs, bool bLink, SCTAB nTab)
Definition: viewfun2.cxx:2711
Complex reference (a range) into the sheet.
Definition: refdata.hxx:122
bool SearchAndReplace(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow, SCTAB &rTab, const ScMarkData &rMark, ScRangeList &rMatchedRanges, OUString &rUndoStr, ScDocument *pUndoDoc=nullptr)
Definition: documen3.cxx:1311
sal_uInt32 GetValue() const
ScAddress aRefFormulaCell
Definition: paramisc.hxx:27
bool MoveTable(SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRecord)
Definition: docsh5.cxx:901
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:908
bool IsUndoEnabled() const
Definition: document.hxx:1541
ScDirection
Definition: global.hxx:339
const OUString & GetCodeName() const
Definition: document.hxx:602
void GetMultiMarkArea(ScRange &rRange) const
Definition: markdata.cxx:116
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:222
bool NeedsObject() const
Definition: editutil.hxx:102
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
Definition: docsh4.cxx:2595
bool AdjustRowHeight(SCROW nStartRow, SCROW nEndRow, bool bApi)
Definition: viewfun2.cxx:192
void InsertSpecialChar(const OUString &rStr, const vcl::Font &rFont)
Definition: viewfun2.cxx:3273
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:183
bool TestRemoveMerge()
Definition: viewfun2.cxx:1299
std::map< OUString, OUString > aParameters
bool HasStartPoint() const
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Definition: clipparam.hxx:30
SC_DLLPUBLIC void ExtendOverlapped(SCCOL &rStartCol, SCROW &rStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5492
ScAutoFormatData * CreateAutoFormatData()
Definition: viewfun2.cxx:1892
void FillCrossDblClick()
Downward fill of selected cell(s) by double-clicking cross-hair cursor.
Definition: viewfun2.cxx:1749
void ExtendScenario()
Definition: viewfun2.cxx:2338
SC_DLLPUBLIC sfx2::LinkManager * GetLinkManager()
Definition: documen2.cxx:219
std::set< SCTAB > MarkedTabsType
Definition: markdata.hxx:45
void VBA_DeleteModule(ScDocShell &rDocSh, const OUString &sModuleName)
Definition: docfunc.cxx:3233
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:213
double GetPPTX() const
Definition: sizedev.hxx:41
ocClose
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_BLTR(142)
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
::std::vector< ScUndoTabColorInfo > List
Definition: tabbgcolor.hxx:36
void HideTable(const ScMarkData &rMark, SCTAB nTabToSelect=-1)
Definition: viewfun2.cxx:3223
rtl_TextEncoding GetCharSet() const
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:22
ScAutoSum
Definition: viewfun2.cxx:250
sc::MultiDataCellState HasMultipleDataCells(const ScRange &rRange) const
Check if the specified range contains either: 1) one non-empty cell, 2) more than one non-empty cells...
Definition: document10.cxx:41
void AdjustPrintZoom()
Definition: viewfun2.cxx:1037
ocStDev
void MakeScenario(const OUString &rName, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: viewfun2.cxx:2317
FormulaToken * AddDouble(double fVal)
void TabOp(const ScTabOpParam &rParam, bool bRecord=true)
Definition: viewfun2.cxx:2304
ocSum
static SC_DLLPUBLIC const SvxSearchItem & GetSearchItem()
Definition: global.cxx:213
SC_DLLPUBLIC const ScTableProtection * GetTabProtection(SCTAB nTab) const
Definition: documen3.cxx:1923
SfxMedium * GetMedium() const