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