LibreOffice Module sc (master)  1
table2.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <algorithm>
21 #include <memory>
22 #include <table.hxx>
23 #include <patattr.hxx>
24 #include <docpool.hxx>
25 #include <formulacell.hxx>
26 #include <document.hxx>
27 #include <drwlayer.hxx>
28 #include <olinetab.hxx>
29 #include <stlpool.hxx>
30 #include <attarray.hxx>
31 #include <markdata.hxx>
32 #include <dociter.hxx>
33 #include <conditio.hxx>
34 #include <chartlis.hxx>
35 #include <fillinfo.hxx>
36 #include <bcaslot.hxx>
37 #include <postit.hxx>
38 #include <sheetevents.hxx>
39 #include <segmenttree.hxx>
40 #include <dbdata.hxx>
41 #include <tokenarray.hxx>
42 #include <clipcontext.hxx>
43 #include <types.hxx>
44 #include <editutil.hxx>
45 #include <mtvcellfunc.hxx>
46 #include <refupdatecontext.hxx>
47 #include <scopetools.hxx>
48 #include <tabprotection.hxx>
49 #include <columnspanset.hxx>
50 #include <rowheightcontext.hxx>
51 #include <listenercontext.hxx>
52 #include <compressedarray.hxx>
53 #include <brdcst.hxx>
54 #include <refdata.hxx>
55 #include <docsh.hxx>
56 
57 #include <scitems.hxx>
58 #include <editeng/boxitem.hxx>
59 #include <editeng/editobj.hxx>
60 #include <o3tl/safeint.hxx>
61 #include <o3tl/unit_conversion.hxx>
62 #include <osl/diagnose.h>
63 #include <svl/poolcach.hxx>
64 #include <unotools/charclass.hxx>
65 #include <math.h>
66 
67 namespace {
68 
69 class ColumnRegroupFormulaCells
70 {
71  ScColContainer& mrCols;
72  std::vector<ScAddress>* mpGroupPos;
73 
74 public:
75  ColumnRegroupFormulaCells( ScColContainer& rCols, std::vector<ScAddress>* pGroupPos ) :
76  mrCols(rCols), mpGroupPos(pGroupPos) {}
77 
78  void operator() (SCCOL nCol)
79  {
80  mrCols[nCol].RegroupFormulaCells(mpGroupPos);
81  }
82 };
83 
84 }
85 
86 sal_uInt16 ScTable::GetTextWidth(SCCOL nCol, SCROW nRow) const
87 {
88  return aCol[nCol].GetTextWidth(nRow);
89 }
90 
91 bool ScTable::SetOutlineTable( const ScOutlineTable* pNewOutline )
92 {
93  sal_uInt16 nOldSizeX = 0;
94  sal_uInt16 nOldSizeY = 0;
95  sal_uInt16 nNewSizeX = 0;
96  sal_uInt16 nNewSizeY = 0;
97 
98  if (pOutlineTable)
99  {
100  nOldSizeX = pOutlineTable->GetColArray().GetDepth();
101  nOldSizeY = pOutlineTable->GetRowArray().GetDepth();
102  pOutlineTable.reset();
103  }
104 
105  if (pNewOutline)
106  {
107  pOutlineTable.reset(new ScOutlineTable( *pNewOutline ));
108  nNewSizeX = pOutlineTable->GetColArray().GetDepth();
109  nNewSizeY = pOutlineTable->GetRowArray().GetDepth();
110  }
111 
112  return ( nNewSizeX != nOldSizeX || nNewSizeY != nOldSizeY ); // changed size?
113 }
114 
116 {
117  if (!pOutlineTable)
118  pOutlineTable.reset(new ScOutlineTable);
119 }
120 
121 void ScTable::SetSheetEvents( std::unique_ptr<ScSheetEvents> pNew )
122 {
123  pSheetEvents = std::move(pNew);
124 
125  SetCalcNotification( false ); // discard notifications before the events were set
126 
127  SetStreamValid(false);
128 }
129 
131 {
132  bCalcNotification = bSet;
133 }
134 
135 bool ScTable::TestInsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize ) const
136 {
137  bool bTest = true;
138 
139  if ( nStartCol==0 && nEndCol==rDocument.MaxCol() && pOutlineTable )
140  bTest = pOutlineTable->TestInsertRow(nSize);
141 
142  for (SCCOL i=nStartCol; (i<=nEndCol) && bTest; i++)
143  bTest = CreateColumnIfNotExists(i).TestInsertRow(nStartRow, nSize);
144 
145  return bTest;
146 }
147 
148 void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize )
149 {
150  if (nStartCol==0 && nEndCol==rDocument.MaxCol())
151  {
152  if (mpRowHeights && pRowFlags)
153  {
154  mpRowHeights->insertSegment(nStartRow, nSize);
155  CRFlags nNewFlags = pRowFlags->Insert( nStartRow, nSize);
156  // only copy manual size flag, clear all others
157  if (nNewFlags != CRFlags::NONE && (nNewFlags != CRFlags::ManualSize))
158  pRowFlags->SetValue( nStartRow, nStartRow + nSize - 1,
159  nNewFlags & CRFlags::ManualSize);
160  }
161 
162  if (pOutlineTable)
163  pOutlineTable->InsertRow( nStartRow, nSize );
164 
165  mpFilteredRows->insertSegment(nStartRow, nSize);
166  mpHiddenRows->insertSegment(nStartRow, nSize);
167 
168  if (!maRowManualBreaks.empty())
169  {
170  // Copy all breaks up to nStartRow (non-inclusive).
171  ::std::set<SCROW>::iterator itr1 = maRowManualBreaks.lower_bound(nStartRow);
172  ::std::set<SCROW> aNewBreaks(maRowManualBreaks.begin(), itr1);
173 
174  // Copy all breaks from nStartRow (inclusive) to the last element,
175  // but add nSize to each value.
176  ::std::set<SCROW>::iterator itr2 = maRowManualBreaks.end();
177  for (; itr1 != itr2; ++itr1)
178  aNewBreaks.insert(static_cast<SCROW>(*itr1 + nSize));
179 
180  maRowManualBreaks.swap(aNewBreaks);
181  }
182  }
183 
184  for (SCCOL j=nStartCol; j<=nEndCol; j++)
185  aCol[j].InsertRow( nStartRow, nSize );
186 
187  mpCondFormatList->InsertRow(nTab, nStartCol, nEndCol, nStartRow, nSize);
188 
190 
191  // TODO: In the future we may want to check if the table has been
192  // really modified before setting the stream invalid.
193  SetStreamValid(false);
194 }
195 
197  const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize,
198  bool* pUndoOutline, std::vector<ScAddress>* pGroupPos )
199 {
200  if (nStartCol==0 && nEndCol==rDocument.MaxCol())
201  {
202  if (pRowFlags)
203  pRowFlags->Remove( nStartRow, nSize);
204 
205  if (mpRowHeights)
206  mpRowHeights->removeSegment(nStartRow, nStartRow+nSize);
207 
208  if (pOutlineTable)
209  if (pOutlineTable->DeleteRow( nStartRow, nSize ))
210  if (pUndoOutline)
211  *pUndoOutline = true;
212 
213  mpFilteredRows->removeSegment(nStartRow, nStartRow+nSize);
214  mpHiddenRows->removeSegment(nStartRow, nStartRow+nSize);
215 
216  if (!maRowManualBreaks.empty())
217  {
218  // Erase all manual breaks between nStartRow and nStartRow + nSize - 1 (inclusive).
219  std::set<SCROW>::iterator itr1 = maRowManualBreaks.lower_bound(nStartRow);
220  std::set<SCROW>::iterator itr2 = maRowManualBreaks.upper_bound(static_cast<SCROW>(nStartRow + nSize - 1));
221  maRowManualBreaks.erase(itr1, itr2);
222 
223  // Copy all breaks from the 1st element up to nStartRow to the new container.
224  itr1 = maRowManualBreaks.lower_bound(nStartRow);
225  ::std::set<SCROW> aNewBreaks(maRowManualBreaks.begin(), itr1);
226 
227  // Copy all breaks from nStartRow to the last element, but subtract each value by nSize.
228  itr2 = maRowManualBreaks.end();
229  for (; itr1 != itr2; ++itr1)
230  aNewBreaks.insert(static_cast<SCROW>(*itr1 - nSize));
231 
232  maRowManualBreaks.swap(aNewBreaks);
233  }
234  }
235 
236  { // scope for bulk broadcast
237  ScBulkBroadcast aBulkBroadcast( rDocument.GetBASM(), SfxHintId::ScDataChanged);
238  for (SCCOL j=nStartCol; j<=nEndCol; j++)
239  aCol[j].DeleteRow(nStartRow, nSize, pGroupPos);
240  }
241 
242  std::vector<SCCOL> aRegroupCols;
243  rRegroupCols.getColumns(nTab, aRegroupCols);
244  std::for_each(
245  aRegroupCols.begin(), aRegroupCols.end(), ColumnRegroupFormulaCells(aCol, pGroupPos));
246 
248 
249  // TODO: In the future we may want to check if the table has been
250  // really modified before setting the stream invalid.
251  SetStreamValid(false);
252 }
253 
254 bool ScTable::TestInsertCol( SCROW nStartRow, SCROW nEndRow, SCSIZE nSize ) const
255 {
256  if ( nSize > o3tl::make_unsigned(rDocument.MaxCol()) )
257  return false;
258 
259  if ( nStartRow==0 && nEndRow==rDocument.MaxRow() && pOutlineTable
260  && ! pOutlineTable->TestInsertCol(nSize) )
261  return false;
262 
263  auto range = GetColumnsRange( rDocument.MaxCol() - static_cast<SCCOL>(nSize) + 1, rDocument.MaxCol() );
264  for (auto it = range.rbegin(); it != range.rend(); ++it )
265  if (! aCol[*it].TestInsertCol(nStartRow, nEndRow))
266  return false;
267 
268  return true;
269 }
270 
272  const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize )
273 {
274  if (nStartRow==0 && nEndRow==rDocument.MaxRow())
275  {
276  if (mpColWidth && mpColFlags)
277  {
278  mpColWidth->InsertPreservingSize(nStartCol, nSize, STD_COL_WIDTH);
279  // The inserted columns have the same widths as the columns, which were selected for insert.
280  for (SCSIZE i=0; i < std::min(rDocument.MaxCol()-nSize-nStartCol, nSize); ++i)
281  mpColWidth->SetValue(nStartCol + i, mpColWidth->GetValue(nStartCol+i+nSize));
282  mpColFlags->InsertPreservingSize(nStartCol, nSize, CRFlags::NONE);
283  }
284  if (pOutlineTable)
285  pOutlineTable->InsertCol( nStartCol, nSize );
286 
287  mpHiddenCols->insertSegment(nStartCol, static_cast<SCCOL>(nSize));
288  mpFilteredCols->insertSegment(nStartCol, static_cast<SCCOL>(nSize));
289 
290  if (!maColManualBreaks.empty())
291  {
292  // Copy all breaks up to nStartCol (non-inclusive).
293  ::std::set<SCCOL>::iterator itr1 = maColManualBreaks.lower_bound(nStartCol);
294  ::std::set<SCCOL> aNewBreaks(maColManualBreaks.begin(), itr1);
295 
296  // Copy all breaks from nStartCol (inclusive) to the last element,
297  // but add nSize to each value.
298  ::std::set<SCCOL>::iterator itr2 = maColManualBreaks.end();
299  for (; itr1 != itr2; ++itr1)
300  aNewBreaks.insert(static_cast<SCCOL>(*itr1 + nSize));
301 
302  maColManualBreaks.swap(aNewBreaks);
303  }
304  }
305 
306  if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
307  {
308  for (SCSIZE i=0; i < nSize; i++)
309  for (SCCOL nCol = aCol.size() - 1; nCol > nStartCol; nCol--)
310  aCol[nCol].SwapCol(aCol[nCol-1]);
311  }
312  else
313  {
314  for (SCSIZE i=0; static_cast<SCCOL>(i+nSize)+nStartCol < aCol.size(); i++)
315  aCol[aCol.size() - 1 - nSize - i].MoveTo(nStartRow, nEndRow, aCol[aCol.size() - 1 - i]);
316  }
317 
318  std::vector<SCCOL> aRegroupCols;
319  rRegroupCols.getColumns(nTab, aRegroupCols);
320  std::for_each(aRegroupCols.begin(), aRegroupCols.end(), ColumnRegroupFormulaCells(aCol, nullptr));
321 
322  if (nStartCol>0) // copy old attributes
323  {
324  sal_uInt16 nWhichArray[2];
325  nWhichArray[0] = ATTR_MERGE;
326  nWhichArray[1] = 0;
327 
329  for (SCSIZE i=0; i<nSize; i++)
330  {
331  aCol[nStartCol-1].CopyToColumn(aCxt, nStartRow, nEndRow, InsertDeleteFlags::ATTRIB,
332  false, aCol[nStartCol+i] );
333  aCol[nStartCol+i].RemoveFlags( nStartRow, nEndRow,
335  aCol[nStartCol+i].ClearItems( nStartRow, nEndRow, nWhichArray );
336  }
337  }
338 
339  mpCondFormatList->InsertCol(nTab, nStartRow, nEndRow, nStartCol, nSize);
340 
342 
343  // TODO: In the future we may want to check if the table has been
344  // really modified before setting the stream invalid.
345  SetStreamValid(false);
346 }
347 
349  const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize, bool* pUndoOutline )
350 {
351  if (nStartRow==0 && nEndRow==rDocument.MaxRow())
352  {
353  if (mpColWidth && mpColFlags)
354  {
355  assert( nStartCol + nSize <= o3tl::make_unsigned(rDocument.MaxCol()+1) ); // moving 0 if ==rDocument.MaxCol()+1 is correct
356  mpColWidth->RemovePreservingSize(nStartCol, nSize, STD_COL_WIDTH);
357  mpColFlags->RemovePreservingSize(nStartCol, nSize, CRFlags::NONE);
358  }
359  if (pOutlineTable)
360  if (pOutlineTable->DeleteCol( nStartCol, nSize ))
361  if (pUndoOutline)
362  *pUndoOutline = true;
363 
364  SCCOL nRmSize = nStartCol + static_cast<SCCOL>(nSize);
365  mpHiddenCols->removeSegment(nStartCol, nRmSize);
366  mpFilteredCols->removeSegment(nStartCol, nRmSize);
367 
368  if (!maColManualBreaks.empty())
369  {
370  // Erase all manual breaks between nStartCol and nStartCol + nSize - 1 (inclusive).
371  std::set<SCCOL>::iterator itr1 = maColManualBreaks.lower_bound(nStartCol);
372  std::set<SCCOL>::iterator itr2 = maColManualBreaks.upper_bound(static_cast<SCCOL>(nStartCol + nSize - 1));
373  maColManualBreaks.erase(itr1, itr2);
374 
375  // Copy all breaks from the 1st element up to nStartCol to the new container.
376  itr1 = maColManualBreaks.lower_bound(nStartCol);
377  ::std::set<SCCOL> aNewBreaks(maColManualBreaks.begin(), itr1);
378 
379  // Copy all breaks from nStartCol to the last element, but subtract each value by nSize.
380  itr2 = maColManualBreaks.end();
381  for (; itr1 != itr2; ++itr1)
382  aNewBreaks.insert(static_cast<SCCOL>(*itr1 - nSize));
383 
384  maColManualBreaks.swap(aNewBreaks);
385  }
386  }
387 
388  for (SCSIZE i = 0; i < nSize; i++)
389  aCol[nStartCol + i].DeleteArea(nStartRow, nEndRow, InsertDeleteFlags::ALL, false);
390 
391  if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
392  {
393  for (SCSIZE i=0; i < nSize; i++)
394  for (SCCOL nCol = nStartCol; nCol < aCol.size() - 1; nCol++)
395  aCol[nCol].SwapCol(aCol[nCol+1]);
396  }
397  else
398  {
399  for (SCSIZE i=0; static_cast<SCCOL>(i+nSize)+nStartCol < aCol.size(); i++)
400  aCol[nStartCol + nSize + i].MoveTo(nStartRow, nEndRow, aCol[nStartCol + i]);
401  }
402 
403  std::vector<SCCOL> aRegroupCols;
404  rRegroupCols.getColumns(nTab, aRegroupCols);
405  std::for_each(aRegroupCols.begin(), aRegroupCols.end(), ColumnRegroupFormulaCells(aCol, nullptr));
406 
408 
409  // TODO: In the future we may want to check if the table has been
410  // really modified before setting the stream invalid.
411  SetStreamValid(false);
412 }
413 
415  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, InsertDeleteFlags nDelFlag,
416  bool bBroadcast, sc::ColumnSpanSet* pBroadcastSpans )
417 {
418  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
419  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
420  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
421  {
422  { // scope for bulk broadcast
423  ScBulkBroadcast aBulkBroadcast( rDocument.GetBASM(), SfxHintId::ScDataChanged);
424  for (SCCOL i = nCol1; i <= nCol2; i++)
425  aCol[i].DeleteArea(nRow1, nRow2, nDelFlag, bBroadcast, pBroadcastSpans);
426  }
427 
428  // Do not set protected cell in a protected table
429 
430  if ( IsProtected() && (nDelFlag & InsertDeleteFlags::ATTRIB) )
431  {
432  ScPatternAttr aPattern(rDocument.GetPool());
433  aPattern.GetItemSet().Put( ScProtectionAttr( false ) );
434  ApplyPatternArea( nCol1, nRow1, nCol2, nRow2, aPattern );
435  }
436 
437  if( nDelFlag & InsertDeleteFlags::ATTRIB )
438  mpCondFormatList->DeleteArea( nCol1, nRow1, nCol2, nRow2 );
439  }
440 
441  // TODO: In the future we may want to check if the table has been
442  // really modified before setting the stream invalid.
443  SetStreamValid(false);
444 }
445 
446 void ScTable::DeleteSelection( InsertDeleteFlags nDelFlag, const ScMarkData& rMark, bool bBroadcast )
447 {
448  { // scope for bulk broadcast
449  ScBulkBroadcast aBulkBroadcast( rDocument.GetBASM(), SfxHintId::ScDataChanged);
450  for (SCCOL i=0; i < aCol.size(); i++)
451  aCol[i].DeleteSelection(nDelFlag, rMark, bBroadcast);
452  }
453 
454  ScRangeList aRangeList;
455  rMark.FillRangeListWithMarks(&aRangeList, false);
456 
457  for (size_t i = 0; i < aRangeList.size(); ++i)
458  {
459  const ScRange & rRange = aRangeList[i];
460 
461  if((nDelFlag & InsertDeleteFlags::ATTRIB) && rRange.aStart.Tab() == nTab)
462  mpCondFormatList->DeleteArea( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row() );
463  }
464 
465  // Do not set protected cell in a protected sheet
466 
467  if ( IsProtected() && (nDelFlag & InsertDeleteFlags::ATTRIB) )
468  {
469  ScDocumentPool* pPool = rDocument.GetPool();
471  aSet.Put( ScProtectionAttr( false ) );
472  SfxItemPoolCache aCache( pPool, &aSet );
473  ApplySelectionCache( &aCache, rMark );
474  }
475 
476  // TODO: In the future we may want to check if the table has been
477  // really modified before setting the stream invalid.
478  SetStreamValid(false);
479 }
480 
481 // pTable = Clipboard
483  sc::CopyToClipContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
484  ScTable* pTable )
485 {
486  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
487  return;
488 
489  // copy content
490  //local range names need to be copied first for formula cells
491  if (!pTable->mpRangeName && mpRangeName)
492  pTable->mpRangeName.reset( new ScRangeName(*mpRangeName) );
493 
494  nCol2 = ClampToAllocatedColumns(nCol2);
495 
496  for ( SCCOL i = nCol1; i <= nCol2; i++)
497  aCol[i].CopyToClip(rCxt, nRow1, nRow2, pTable->CreateColumnIfNotExists(i)); // notes are handled at column level
498 
499  // copy widths/heights, and only "hidden", "filtered" and "manual" flags
500  // also for all preceding columns/rows, to have valid positions for drawing objects
501 
502  if (mpColWidth && pTable->mpColWidth)
503  pTable->mpColWidth->CopyFrom(*mpColWidth, 0, nCol2);
504 
505  pTable->CopyColHidden(*this, 0, nCol2);
506  pTable->CopyColFiltered(*this, 0, nCol2);
507  if (pDBDataNoName)
508  pTable->SetAnonymousDBData(std::unique_ptr<ScDBData>(new ScDBData(*pDBDataNoName)));
509 
510  if (pRowFlags && pTable->pRowFlags && mpRowHeights && pTable->mpRowHeights)
511  {
512  pTable->pRowFlags->CopyFromAnded( *pRowFlags, 0, nRow2, CRFlags::ManualSize);
513  pTable->CopyRowHeight(*this, 0, nRow2, 0);
514  }
515 
516  pTable->CopyRowHidden(*this, 0, nRow2);
517  pTable->CopyRowFiltered(*this, 0, nRow2);
518 
519  // If necessary replace formulas with values
520 
521  if ( IsProtected() )
522  for (SCCOL i = nCol1; i <= nCol2; i++)
523  pTable->aCol[i].RemoveProtected(nRow1, nRow2);
524 
526 }
527 
529  sc::CopyToClipContext& rCxt, const ScRangeList& rRanges, ScTable* pTable )
530 {
531  for ( size_t i = 0, nListSize = rRanges.size(); i < nListSize; ++i )
532  {
533  const ScRange & r = rRanges[ i ];
534  CopyToClip( rCxt, r.aStart.Col(), r.aStart.Row(), r.aEnd.Col(), r.aEnd.Row(), pTable);
535  }
536 }
537 
539  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, const SvNumberFormatterMergeMap& rMap, ScTable* pDestTab )
540 {
541  if (nCol1 > nCol2 || nRow1 > nRow2)
542  return;
543 
544  const SCCOL nFirstUnallocated = std::clamp<SCCOL>(GetAllocatedColumnsCount(), nCol1, nCol2 + 1);
545  if (nFirstUnallocated > nCol1)
546  pDestTab->CreateColumnIfNotExists(nFirstUnallocated - 1);
547 
548  for (SCCOL i = nCol1; i < nFirstUnallocated; ++i)
549  {
550  ScColumn& rSrcCol = aCol[i];
551  ScColumn& rDestCol = pDestTab->aCol[i];
552  rSrcCol.CopyStaticToDocument(nRow1, nRow2, rMap, rDestCol);
553  }
554 
555  // Maybe copy this table's default attrs to dest not limiting to already allocated in dest?
556  const SCCOL nLastInDest = std::min<SCCOL>(pDestTab->GetAllocatedColumnsCount() - 1, nCol2);
557  for (SCCOL i = nFirstUnallocated; i <= nLastInDest; ++i)
558  {
559  ScColumn& rDestCol = pDestTab->aCol[i];
560  rDestCol.maCellTextAttrs.set_empty(nRow1, nRow2);
561  rDestCol.maCells.set_empty(nRow1, nRow2);
562  for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
563  {
564  sal_uInt32 nNumFmt = aDefaultColAttrArray.GetPattern(nRow)->GetNumberFormat(
566  SvNumberFormatterMergeMap::const_iterator itNum = rMap.find(nNumFmt);
567  if (itNum != rMap.end())
568  nNumFmt = itNum->second;
569 
570  rDestCol.SetNumberFormat(nRow, nNumFmt);
571  }
572  rDestCol.CellStorageModified();
573  }
574 }
575 
576 void ScTable::CopyCellToDocument(SCCOL nSrcCol, SCROW nSrcRow, SCCOL nDestCol, SCROW nDestRow, ScTable& rDestTab )
577 {
578  if (!ValidColRow(nSrcCol, nSrcRow) || !ValidColRow(nDestCol, nDestRow))
579  return;
580 
581  if (nSrcCol >= GetAllocatedColumnsCount())
582  {
583  if (nDestCol < rDestTab.GetAllocatedColumnsCount())
584  {
585  ScColumn& rDestCol = rDestTab.aCol[nDestCol];
586  rDestCol.maCells.set_empty(nDestRow, nDestRow);
587  rDestCol.maCellTextAttrs.set_empty(nDestRow, nDestRow);
588  rDestCol.maCellNotes.set_empty(nDestRow, nDestRow);
589  rDestCol.CellStorageModified();
590  }
591  return;
592  }
593 
594  ScColumn& rSrcCol = aCol[nSrcCol];
595  ScColumn& rDestCol = rDestTab.CreateColumnIfNotExists(nDestCol);
596  rSrcCol.CopyCellToDocument(nSrcRow, nDestRow, rDestCol);
597 }
598 
599 namespace {
600 
601 bool CheckAndDeduplicateCondFormat(ScDocument& rDocument, ScConditionalFormat* pOldFormat, const ScConditionalFormat* pNewFormat, SCTAB nTab)
602 {
603  if (!pOldFormat)
604  return false;
605 
606  if (pOldFormat->EqualEntries(*pNewFormat, true))
607  {
608  const ScRangeList& rNewRangeList = pNewFormat->GetRange();
609  ScRangeList& rDstRangeList = pOldFormat->GetRangeList();
610  for (size_t i = 0; i < rNewRangeList.size(); ++i)
611  {
612  rDstRangeList.Join(rNewRangeList[i]);
613  }
614  rDocument.AddCondFormatData(rNewRangeList, nTab, pOldFormat->GetKey());
615  return true;
616  }
617 
618  return false;
619 }
620 
621 }
622 
623 void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
624  SCCOL nDx, SCROW nDy, const ScTable* pTable)
625 {
626  ScRange aOldRange( nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab);
627  ScRange aNewRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
628  bool bSameDoc = rDocument.GetStyleSheetPool() == pTable->rDocument.GetStyleSheetPool();
629 
630  for(const auto& rxCondFormat : *pTable->mpCondFormatList)
631  {
632  const ScRangeList& rCondFormatRange = rxCondFormat->GetRange();
633  if(!rCondFormatRange.Intersects( aOldRange ))
634  continue;
635 
636  ScRangeList aIntersectedRange = rCondFormatRange.GetIntersectedRange(aOldRange);
637  std::unique_ptr<ScConditionalFormat> pNewFormat = rxCondFormat->Clone(&rDocument);
638 
639  pNewFormat->SetRange(aIntersectedRange);
640  sc::RefUpdateContext aRefCxt(rDocument);
641  aRefCxt.meMode = URM_COPY;
642  aRefCxt.maRange = aNewRange;
643  aRefCxt.mnColDelta = nDx;
644  aRefCxt.mnRowDelta = nDy;
645  aRefCxt.mnTabDelta = nTab - pTable->nTab;
646  pNewFormat->UpdateReference(aRefCxt, true);
647 
648  if (bSameDoc && pTable->nTab == nTab && CheckAndDeduplicateCondFormat(rDocument, mpCondFormatList->GetFormat(rxCondFormat->GetKey()), pNewFormat.get(), nTab))
649  {
650  continue;
651  }
652  sal_uLong nMax = 0;
653  bool bDuplicate = false;
654  for(const auto& rxCond : *mpCondFormatList)
655  {
656  // Check if there is the same format in the destination
657  // If there is, then simply expand its range
658  if (CheckAndDeduplicateCondFormat(rDocument, rxCond.get(), pNewFormat.get(), nTab))
659  {
660  bDuplicate = true;
661  break;
662  }
663 
664  if (rxCond->GetKey() > nMax)
665  nMax = rxCond->GetKey();
666  }
667  // Do not add duplicate entries
668  if (bDuplicate)
669  {
670  continue;
671  }
672 
673  pNewFormat->SetKey(nMax + 1);
674  auto pNewFormatTmp = pNewFormat.get();
675  mpCondFormatList->InsertNew(std::move(pNewFormat));
676 
677  if(!bSameDoc)
678  {
679  for(size_t i = 0, n = pNewFormatTmp->size();
680  i < n; ++i)
681  {
682  OUString aStyleName;
683  const ScFormatEntry* pEntry = pNewFormatTmp->GetEntry(i);
684  if(pEntry->GetType() == ScFormatEntry::Type::Condition ||
686  aStyleName = static_cast<const ScCondFormatEntry*>(pEntry)->GetStyle();
687  else if(pEntry->GetType() == ScFormatEntry::Type::Date)
688  aStyleName = static_cast<const ScCondDateFormatEntry*>(pEntry)->GetStyleName();
689 
690  if(!aStyleName.isEmpty())
691  {
692  if(rDocument.GetStyleSheetPool()->Find(aStyleName, SfxStyleFamily::Para))
693  continue;
694 
695  rDocument.GetStyleSheetPool()->CopyStyleFrom(
696  pTable->rDocument.GetStyleSheetPool(), aStyleName, SfxStyleFamily::Para );
697  }
698  }
699  }
700 
701  rDocument.AddCondFormatData( pNewFormatTmp->GetRange(), nTab, pNewFormatTmp->GetKey() );
702  }
703 }
704 
706 {
707  if (!ValidCol(nCol))
708  return false;
709 
711  return true;
712 }
713 
714 // pTable is source
715 
717  sc::CopyFromClipContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
718  SCCOL nDx, SCROW nDy, ScTable* pTable )
719 {
720  if (nCol2 > rDocument.MaxCol())
721  nCol2 = rDocument.MaxCol();
722  if (nRow2 > rDocument.MaxRow())
723  nRow2 = rDocument.MaxRow();
724 
725  if (!(ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2)))
726  return;
727 
729  for ( SCCOL i = nCol1; i <= nCol2; i++)
730  {
731  pTable->CreateColumnIfNotExists(i - nDx);
732  aCol[i].CopyFromClip(rCxt, nRow1, nRow2, nDy, pTable->aCol[i - nDx]); // notes are handles at column level
733  }
734 
736  {
737  // make sure that there are no old references to the cond formats
738  sal_uInt16 nWhichArray[2];
739  nWhichArray[0] = ATTR_CONDITIONAL;
740  nWhichArray[1] = 0;
741  for ( SCCOL i = nCol1; i <= nCol2; ++i)
742  aCol[i].ClearItems(nRow1, nRow2, nWhichArray);
743  }
744 
746  return;
747 
748  if (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pTable->mpColWidth)
749  mpColWidth->CopyFrom(*pTable->mpColWidth, nCol1, nCol2, nCol1 - nDx);
750 
751  if (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pTable->mpRowHeights &&
752  pRowFlags && pTable->pRowFlags)
753  {
754  CopyRowHeight(*pTable, nRow1, nRow2, -nDy);
755  // Must copy CRFlags::ManualSize bit too, otherwise pRowHeight doesn't make sense
756  for (SCROW j=nRow1; j<=nRow2; j++)
757  {
758  if ( pTable->pRowFlags->GetValue(j-nDy) & CRFlags::ManualSize )
759  pRowFlags->OrValue( j, CRFlags::ManualSize);
760  else
761  pRowFlags->AndValue( j, ~CRFlags::ManualSize);
762  }
763  }
764 
765  // Do not set protected cell in a protected sheet
767  {
768  ScPatternAttr aPattern(rDocument.GetPool());
769  aPattern.GetItemSet().Put( ScProtectionAttr( false ) );
770  ApplyPatternArea( nCol1, nRow1, nCol2, nRow2, aPattern );
771  }
772 
773  // create deep copies for conditional formatting
774  CopyConditionalFormat( nCol1, nRow1, nCol2, nRow2, nDx, nDy, pTable);
775 }
776 
778  sc::MixDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
779  ScPasteFunc nFunction, bool bSkipEmpty, const ScTable* pSrcTab )
780 {
781  for (SCCOL i=nCol1; i<=nCol2; i++)
782  aCol[i].MixData(rCxt, nRow1, nRow2, nFunction, bSkipEmpty, pSrcTab->aCol[i]);
783 }
784 
785 // Selection form this document
787  sc::MixDocContext& rCxt, const ScMarkData& rMark, ScPasteFunc nFunction,
788  bool bSkipEmpty, const ScTable* pSrcTab )
789 {
790  for (SCCOL i=0; i < aCol.size(); i++)
791  aCol[i].MixMarked(rCxt, rMark, nFunction, bSkipEmpty, pSrcTab->aCol[i]);
792 }
793 
794 namespace {
795 
796 class TransClipHandler
797 {
798  ScTable& mrClipTab;
799  SCTAB mnSrcTab;
800  SCCOL mnSrcCol;
801  size_t mnTopRow;
802  SCROW mnTransRow;
803  bool mbAsLink;
804  bool mbWasCut;
805 
806  ScAddress getDestPos(size_t nRow) const
807  {
808  return ScAddress(static_cast<SCCOL>(nRow-mnTopRow), mnTransRow, mrClipTab.GetTab());
809  }
810 
811  ScFormulaCell* createRefCell(size_t nSrcRow, const ScAddress& rDestPos) const
812  {
813  ScAddress aSrcPos(mnSrcCol, nSrcRow, mnSrcTab);
814  ScSingleRefData aRef;
815  aRef.InitAddress(aSrcPos); // Absolute reference.
816  aRef.SetFlag3D(true);
817 
818  ScTokenArray aArr(mrClipTab.GetDoc());
819  aArr.AddSingleReference(aRef);
820  return new ScFormulaCell(mrClipTab.GetDoc(), rDestPos, aArr);
821  }
822 
823  void setLink(size_t nRow)
824  {
825  SCCOL nTransCol = nRow - mnTopRow;
826  mrClipTab.SetFormulaCell(
827  nTransCol, mnTransRow, createRefCell(nRow, getDestPos(nRow)));
828  }
829 
830 public:
831  TransClipHandler(ScTable& rClipTab, SCTAB nSrcTab, SCCOL nSrcCol, size_t nTopRow, SCROW nTransRow, bool bAsLink, bool bWasCut) :
832  mrClipTab(rClipTab), mnSrcTab(nSrcTab), mnSrcCol(nSrcCol),
833  mnTopRow(nTopRow), mnTransRow(nTransRow), mbAsLink(bAsLink), mbWasCut(bWasCut) {}
834 
835  void operator() (size_t nRow, double fVal)
836  {
837  if (mbAsLink)
838  {
839  setLink(nRow);
840  return;
841  }
842 
843  SCCOL nTransCol = nRow - mnTopRow;
844  mrClipTab.SetValue(nTransCol, mnTransRow, fVal);
845  }
846 
847  void operator() (size_t nRow, const svl::SharedString& rStr)
848  {
849  if (mbAsLink)
850  {
851  setLink(nRow);
852  return;
853  }
854 
855  SCCOL nTransCol = nRow - mnTopRow;
856  mrClipTab.SetRawString(nTransCol, mnTransRow, rStr);
857  }
858 
859  void operator() (size_t nRow, const EditTextObject* p)
860  {
861  if (mbAsLink)
862  {
863  setLink(nRow);
864  return;
865  }
866 
867  SCCOL nTransCol = nRow - mnTopRow;
868  mrClipTab.SetEditText(nTransCol, mnTransRow, ScEditUtil::Clone(*p, mrClipTab.GetDoc()));
869  }
870 
871  void operator() (size_t nRow, const ScFormulaCell* p)
872  {
873  if (mbAsLink)
874  {
875  setLink(nRow);
876  return;
877  }
878 
879  ScFormulaCell* pNew = new ScFormulaCell(
880  *p, mrClipTab.GetDoc(), getDestPos(nRow), ScCloneFlags::StartListening);
881 
882  // rotate reference
883  // for Cut, the references are later adjusted through UpdateTranspose
884 
885  if (!mbWasCut)
886  pNew->TransposeReference();
887 
888  SCCOL nTransCol = nRow - mnTopRow;
889  mrClipTab.SetFormulaCell(nTransCol, mnTransRow, pNew);
890  }
891 };
892 
893 }
894 
895 void ScTable::TransposeClip( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
896  ScTable* pTransClip, InsertDeleteFlags nFlags, bool bAsLink )
897 {
898  bool bWasCut = rDocument.IsCutMode();
899 
900  ScDocument& rDestDoc = pTransClip->rDocument;
901 
902  for (SCCOL nCol=nCol1; nCol<=nCol2; nCol++)
903  {
904  SCROW nRow;
905  if ( bAsLink && nFlags == InsertDeleteFlags::ALL )
906  {
907  // with InsertDeleteFlags::ALL, also create links (formulas) for empty cells
908 
909  for ( nRow=nRow1; nRow<=nRow2; nRow++ )
910  {
911  // create simple formula, as in ScColumn::CreateRefCell
912 
913  ScAddress aDestPos( static_cast<SCCOL>(nRow-nRow1), static_cast<SCROW>(nCol-nCol1), pTransClip->nTab );
914  ScSingleRefData aRef;
915  aRef.InitAddress(ScAddress(nCol,nRow,nTab));
916  aRef.SetFlag3D(true);
917  ScTokenArray aArr(rDestDoc);
918  aArr.AddSingleReference( aRef );
919 
920  pTransClip->SetFormulaCell(
921  static_cast<SCCOL>(nRow-nRow1), static_cast<SCROW>(nCol-nCol1),
922  new ScFormulaCell(rDestDoc, aDestPos, aArr));
923  }
924  }
925  else
926  {
927  TransClipHandler aFunc(*pTransClip, nTab, nCol, nRow1, static_cast<SCROW>(nCol-nCol1), bAsLink, bWasCut);
928  const sc::CellStoreType& rCells = aCol[nCol].maCells;
929  sc::ParseAllNonEmpty(rCells.begin(), rCells, nRow1, nRow2, aFunc);
930  }
931 
932  // Attribute
933 
934  SCROW nAttrRow1 = {}; // spurious -Werror=maybe-uninitialized
935  SCROW nAttrRow2 = {}; // spurious -Werror=maybe-uninitialized
936  const ScPatternAttr* pPattern;
937  std::unique_ptr<ScAttrIterator> pAttrIter(aCol[nCol].CreateAttrIterator( nRow1, nRow2 ));
938  while ( (pPattern = pAttrIter->Next( nAttrRow1, nAttrRow2 )) != nullptr )
939  {
940  if ( !IsDefaultItem( pPattern ) )
941  {
942  const SfxItemSet& rSet = pPattern->GetItemSet();
943  if ( rSet.GetItemState( ATTR_MERGE, false ) == SfxItemState::DEFAULT &&
944  rSet.GetItemState( ATTR_MERGE_FLAG, false ) == SfxItemState::DEFAULT &&
945  rSet.GetItemState( ATTR_BORDER, false ) == SfxItemState::DEFAULT )
946  {
947  // no borders or merge items involved - use pattern as-is
948  for (nRow = nAttrRow1; nRow<=nAttrRow2; nRow++)
949  pTransClip->SetPattern( static_cast<SCCOL>(nRow-nRow1), static_cast<SCROW>(nCol-nCol1), *pPattern );
950  }
951  else
952  {
953  // transpose borders and merge values, remove merge flags (refreshed after pasting)
954  ScPatternAttr aNewPattern( *pPattern );
955  SfxItemSet& rNewSet = aNewPattern.GetItemSet();
956 
957  const SvxBoxItem& rOldBox = rSet.Get(ATTR_BORDER);
958  if ( rOldBox.GetTop() || rOldBox.GetBottom() || rOldBox.GetLeft() || rOldBox.GetRight() )
959  {
960  SvxBoxItem aNew( ATTR_BORDER );
961  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::TOP ), SvxBoxItemLine::LEFT );
962  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::LEFT ), SvxBoxItemLine::TOP );
963  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::BOTTOM ), SvxBoxItemLine::RIGHT );
964  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::RIGHT ), SvxBoxItemLine::BOTTOM );
965  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::TOP ), SvxBoxItemLine::LEFT );
966  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::LEFT ), SvxBoxItemLine::TOP );
967  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::BOTTOM ), SvxBoxItemLine::RIGHT );
968  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::RIGHT ), SvxBoxItemLine::BOTTOM );
969  rNewSet.Put( aNew );
970  }
971 
972  const ScMergeAttr& rOldMerge = rSet.Get(ATTR_MERGE);
973  if (rOldMerge.IsMerged())
974  rNewSet.Put( ScMergeAttr( std::min(
975  static_cast<SCCOL>(rOldMerge.GetRowMerge()),
976  static_cast<SCCOL>(rDocument.MaxCol()+1 - (nAttrRow2-nRow1))),
977  std::min(
978  static_cast<SCROW>(rOldMerge.GetColMerge()),
979  static_cast<SCROW>(rDocument.MaxRow()+1 - (nCol-nCol1)))));
980  const ScMergeFlagAttr& rOldFlag = rSet.Get(ATTR_MERGE_FLAG);
981  if (rOldFlag.IsOverlapped())
982  {
983  ScMF nNewFlags = rOldFlag.GetValue() & ~ScMF( ScMF::Hor | ScMF::Ver );
984  if ( nNewFlags != ScMF::NONE )
985  rNewSet.Put( ScMergeFlagAttr( nNewFlags ) );
986  else
987  rNewSet.ClearItem( ATTR_MERGE_FLAG );
988  }
989 
990  for (nRow = nAttrRow1; nRow<=nAttrRow2; nRow++)
991  pTransClip->SetPattern( static_cast<SCCOL>(nRow-nRow1),
992  static_cast<SCROW>(nCol-nCol1), aNewPattern);
993  }
994  }
995  }
996 
997  // Cell Notes - fdo#68381 paste cell notes on Transpose
998  if ( rDocument.HasColNotes(nCol, nTab) )
999  TransposeColNotes(pTransClip, nCol1, nCol, nRow1, nRow2);
1000  }
1001 }
1002 
1003 void ScTable::TransposeColNotes(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1, SCROW nRow2)
1004 {
1005  sc::CellNoteStoreType::const_iterator itBlk = aCol[nCol].maCellNotes.begin(), itBlkEnd = aCol[nCol].maCellNotes.end();
1006 
1007  // Locate the top row position.
1008  size_t nOffsetInBlock = 0;
1009  size_t nBlockStart = 0, nBlockEnd = 0, nRowPos = static_cast<size_t>(nRow1);
1010  for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd)
1011  {
1012  nBlockEnd = nBlockStart + itBlk->size;
1013  if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
1014  {
1015  // Found.
1016  nOffsetInBlock = nRowPos - nBlockStart;
1017  break;
1018  }
1019  }
1020 
1021  if (itBlk == itBlkEnd)
1022  // Specified range found
1023  return;
1024 
1025  nRowPos = static_cast<size_t>(nRow2); // End row position.
1026 
1027  // Keep processing until we hit the end row position.
1028  sc::cellnote_block::const_iterator itData, itDataEnd;
1029  for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd, nOffsetInBlock = 0)
1030  {
1031  nBlockEnd = nBlockStart + itBlk->size;
1032 
1033  if (itBlk->data)
1034  {
1035  itData = sc::cellnote_block::begin(*itBlk->data);
1036  std::advance(itData, nOffsetInBlock);
1037 
1038  if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
1039  {
1040  // This block contains the end row. Only process partially.
1041  size_t nOffsetEnd = nRowPos - nBlockStart + 1;
1042  itDataEnd = sc::cellnote_block::begin(*itBlk->data);
1043  std::advance(itDataEnd, nOffsetEnd);
1044  size_t curRow = nBlockStart + nOffsetInBlock;
1045  for (; itData != itDataEnd; ++itData, ++curRow)
1046  {
1047  ScAddress aDestPos( static_cast<SCCOL>(curRow-nRow1), static_cast<SCROW>(nCol-nCol1), pTransClip->nTab );
1048  pTransClip->rDocument.ReleaseNote(aDestPos);
1049  ScPostIt* pNote = *itData;
1050  if (pNote)
1051  {
1052  std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), pTransClip->rDocument, aDestPos, true );
1053  pTransClip->rDocument.SetNote(aDestPos, std::move(pClonedNote));
1054  }
1055  }
1056  break; // we reached the last valid block
1057  }
1058  else
1059  {
1060  itDataEnd = sc::cellnote_block::end(*itBlk->data);
1061  size_t curRow = nBlockStart + nOffsetInBlock;
1062  for (; itData != itDataEnd; ++itData, ++curRow)
1063  {
1064  ScAddress aDestPos( static_cast<SCCOL>(curRow-nRow1), static_cast<SCROW>(nCol-nCol1), pTransClip->nTab );
1065  pTransClip->rDocument.ReleaseNote(aDestPos);
1066  ScPostIt* pNote = *itData;
1067  if (pNote)
1068  {
1069  std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), pTransClip->rDocument, aDestPos, true );
1070  pTransClip->rDocument.SetNote(aDestPos, std::move(pClonedNote));
1071  }
1072  }
1073  }
1074  }
1075  else
1076  {
1077  size_t curRow;
1078  for ( curRow = nBlockStart + nOffsetInBlock; curRow <= nBlockEnd && curRow <= nRowPos; ++curRow)
1079  {
1080  ScAddress aDestPos( static_cast<SCCOL>(curRow-nRow1), static_cast<SCROW>(nCol-nCol1), pTransClip->nTab );
1081  pTransClip->rDocument.ReleaseNote(aDestPos);
1082  }
1083  if (curRow == nRowPos)
1084  break;
1085  }
1086  }
1087 }
1088 
1090 {
1091  if (!ValidCol(nCol))
1092  return nullptr;
1093 
1094  return &CreateColumnIfNotExists(nCol);
1095 }
1096 
1098 {
1099  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1100  return nullptr;
1101 
1102  return &aCol[nCol];
1103 }
1104 
1106 {
1107  std::shared_ptr<const sc::ColumnSet> pColSet = rCxt.getColumnSet();
1108  if (!pColSet)
1109  {
1110  for (SCCOL i=0; i < aCol.size(); i++)
1111  aCol[i].StartListeners(rCxt, bAll);
1112  }
1113  else if (pColSet->hasTab( nTab))
1114  {
1115  std::vector<SCCOL> aColumns;
1116  pColSet->getColumns( nTab, aColumns);
1117  for (auto i : aColumns)
1118  {
1119  if (0 <= i && i < aCol.size())
1120  aCol[i].StartListeners(rCxt, bAll);
1121  }
1122  }
1123 }
1124 
1126  sc::StartListeningContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1127 {
1128  nCol2 = ClampToAllocatedColumns(nCol2);
1129  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
1130  aCol[nCol].AttachFormulaCells(rCxt, nRow1, nRow2);
1131 }
1132 
1134  sc::EndListeningContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1135 {
1136  nCol2 = ClampToAllocatedColumns(nCol2);
1137  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
1138  aCol[nCol].DetachFormulaCells(rCxt, nRow1, nRow2, nullptr);
1139 }
1140 
1142  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, sc::ColumnSpanSet& rBroadcastSpans )
1143 {
1144  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1145  if (nCol2 > rDocument.MaxCol()) nCol2 = rDocument.MaxCol();
1146  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
1147  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
1148  for (SCCOL i = nCol1; i <= nCol2; i++)
1149  aCol[i].SetDirtyFromClip(nRow1, nRow2, rBroadcastSpans);
1150 }
1151 
1154  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1155 {
1156  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1157  if (nCol2 > rDocument.MaxCol()) nCol2 = rDocument.MaxCol();
1158  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
1159  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
1160  for (SCCOL i = nCol1; i <= nCol2; i++)
1161  aCol[i].StartListeningFormulaCells(rStartCxt, rEndCxt, nRow1, nRow2);
1162 }
1163 
1165  sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1166  InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab, const ScMarkData* pMarkData,
1167  bool bAsLink, bool bColRowFlags, bool bGlobalNamesToLocal, bool bCopyCaptions )
1168 {
1169  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
1170  return;
1171 
1172  bool bIsUndoDoc = pDestTab->rDocument.IsUndo();
1173 
1174  if (bIsUndoDoc && (nFlags & InsertDeleteFlags::CONTENTS))
1175  {
1176  // Copying formulas may create sheet-local named expressions on the
1177  // destination sheet. Add existing to Undo first.
1178  pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( *GetRangeName())));
1179  }
1180 
1181  if (nFlags != InsertDeleteFlags::NONE)
1182  {
1183  InsertDeleteFlags nTempFlags( nFlags &
1185  // tdf#102364 - in some pathological cases CopyToTable() replacing cells with new cells
1186  // can lead to repetitive splitting and rejoining of the same formula group, which can get
1187  // quadratically expensive with large groups. So do the grouping just once at the end.
1188  sc::DelayFormulaGroupingSwitch delayGrouping( pDestTab->rDocument, true );
1189  for (SCCOL i = nCol1; i <= ClampToAllocatedColumns(nCol2); i++)
1190  aCol[i].CopyToColumn(rCxt, nRow1, nRow2, bIsUndoDoc ? nFlags : nTempFlags, bMarked,
1191  pDestTab->CreateColumnIfNotExists(i), pMarkData, bAsLink, bGlobalNamesToLocal);
1192  }
1193 
1194  if (!bColRowFlags) // Column widths/Row heights/Flags
1195  return;
1196 
1197  if(bIsUndoDoc && (nFlags & InsertDeleteFlags::ATTRIB))
1198  {
1199  pDestTab->mpCondFormatList.reset(new ScConditionalFormatList(pDestTab->rDocument, *mpCondFormatList));
1200  }
1201 
1202  if (pDBDataNoName)
1203  {
1204  std::unique_ptr<ScDBData> pNewDBData(new ScDBData(*pDBDataNoName));
1205  SCCOL aCol1, aCol2;
1206  SCROW aRow1, aRow2;
1207  SCTAB aTab;
1208  pNewDBData->GetArea(aTab, aCol1, aRow1, aCol2, aRow2);
1209  pNewDBData->MoveTo(pDestTab->nTab, aCol1, aRow1, aCol2, aRow2);
1210  pDestTab->SetAnonymousDBData(std::move(pNewDBData));
1211  }
1212  // Charts have to be adjusted when hide/show
1214 
1215  bool bFlagChange = false;
1216 
1217  bool bWidth = (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pDestTab->mpColWidth);
1218  bool bHeight = (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pDestTab->mpRowHeights);
1219 
1220  if (bWidth || bHeight)
1221  {
1222  if (bWidth)
1223  {
1224  auto destTabColWidthIt = pDestTab->mpColWidth->begin() + nCol1;
1225  auto thisTabColWidthIt = mpColWidth->begin() + nCol1;
1226  pDestTab->mpColWidth->CopyFrom(*mpColWidth, nCol1, nCol2);
1227  pDestTab->mpColFlags->CopyFrom(*mpColFlags, nCol1, nCol2);
1228  for (SCCOL i = nCol1; i <= nCol2; ++i)
1229  {
1230  bool bThisHidden = ColHidden(i);
1231  bool bHiddenChange = (pDestTab->ColHidden(i) != bThisHidden);
1232  bool bChange = bHiddenChange || (*destTabColWidthIt != *thisTabColWidthIt);
1233  pDestTab->SetColHidden(i, i, bThisHidden);
1234  //TODO: collect changes?
1235  if (bHiddenChange && pCharts)
1236  pCharts->SetRangeDirty(ScRange( i, 0, nTab, i, rDocument.MaxRow(), nTab ));
1237 
1238  if (bChange)
1239  bFlagChange = true;
1240 
1241  ++destTabColWidthIt;
1242  ++thisTabColWidthIt;
1243  }
1245  }
1246 
1247  if (bHeight)
1248  {
1249  bool bChange = pDestTab->GetRowHeight(nRow1, nRow2) != GetRowHeight(nRow1, nRow2);
1250 
1251  if (bChange)
1252  bFlagChange = true;
1253 
1254  pDestTab->CopyRowHeight(*this, nRow1, nRow2, 0);
1255  pDestTab->pRowFlags->CopyFrom(*pRowFlags, nRow1, nRow2);
1256 
1257  // Hidden flags.
1258  for (SCROW i = nRow1; i <= nRow2; ++i)
1259  {
1260  SCROW nLastRow;
1261  bool bHidden = RowHidden(i, nullptr, &nLastRow);
1262  if (nLastRow >= nRow2)
1263  // the last row shouldn't exceed the upper bound the caller specified.
1264  nLastRow = nRow2;
1265 
1266  bool bHiddenChanged = pDestTab->SetRowHidden(i, nLastRow, bHidden);
1267  if (bHiddenChanged && pCharts)
1268  // Hidden flags differ.
1269  pCharts->SetRangeDirty(ScRange(0, i, nTab, rDocument.MaxCol(), nLastRow, nTab));
1270 
1271  if (bHiddenChanged)
1272  bFlagChange = true;
1273 
1274  // Jump to the last row of the identical flag segment.
1275  i = nLastRow;
1276  }
1277 
1278  // Filtered flags.
1279  for (SCROW i = nRow1; i <= nRow2; ++i)
1280  {
1281  SCROW nLastRow;
1282  bool bFiltered = RowFiltered(i, nullptr, &nLastRow);
1283  if (nLastRow >= nRow2)
1284  // the last row shouldn't exceed the upper bound the caller specified.
1285  nLastRow = nRow2;
1286  pDestTab->SetRowFiltered(i, nLastRow, bFiltered);
1287  i = nLastRow;
1288  }
1290  }
1291  }
1292 
1293  if (bFlagChange)
1294  pDestTab->InvalidatePageBreaks();
1295 
1296  if(nFlags & InsertDeleteFlags::ATTRIB)
1297  {
1298  pDestTab->mpCondFormatList->DeleteArea(nCol1, nRow1, nCol2, nRow2);
1299  pDestTab->CopyConditionalFormat(nCol1, nRow1, nCol2, nRow2, 0, 0, this);
1300  }
1301 
1302  if(nFlags & InsertDeleteFlags::OUTLINE) // also only when bColRowFlags
1303  pDestTab->SetOutlineTable( pOutlineTable.get() );
1304 
1305  if (!bIsUndoDoc && bCopyCaptions && (nFlags & (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES)))
1306  {
1307  bool bCloneCaption = (nFlags & InsertDeleteFlags::NOCAPTIONS) == InsertDeleteFlags::NONE;
1308  CopyCaptionsToTable( nCol1, nRow1, nCol2, nRow2, pDestTab, bCloneCaption);
1309  }
1310 }
1311 
1312 void ScTable::CopyCaptionsToTable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab,
1313  bool bCloneCaption )
1314 {
1315  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
1316  return;
1317 
1318  nCol2 = ClampToAllocatedColumns(nCol2);
1319  for (SCCOL i = nCol1; i <= nCol2; i++)
1320  {
1321  aCol[i].CopyCellNotesToDocument(nRow1, nRow2, pDestTab->CreateColumnIfNotExists(i), bCloneCaption);
1322  pDestTab->aCol[i].UpdateNoteCaptions(nRow1, nRow2);
1323  }
1324 }
1325 
1327  sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1328  InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab )
1329 {
1330  if (!(ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2)))
1331  return;
1332 
1333  bool bWidth = (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pDestTab->mpColWidth);
1334  bool bHeight = (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pDestTab->mpRowHeights);
1335 
1336  if ((nFlags & InsertDeleteFlags::CONTENTS) && mpRangeName)
1337  {
1338  // Undo sheet-local named expressions created during copying
1339  // formulas. If mpRangeName is not set then the Undo wasn't even
1340  // set to an empty ScRangeName map so don't "undo" that.
1341  pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( *GetRangeName())));
1342  if (!pDestTab->rDocument.IsClipOrUndo())
1343  {
1344  ScDocShell* pDocSh = static_cast<ScDocShell*>(pDestTab->rDocument.GetDocumentShell());
1345  if (pDocSh)
1346  pDocSh->SetAreasChangedNeedBroadcast();
1347  }
1348 
1349  }
1350 
1351  for ( SCCOL i = 0; i < aCol.size(); i++)
1352  {
1353  auto& rDestCol = pDestTab->CreateColumnIfNotExists(i);
1354  if ( i >= nCol1 && i <= nCol2 )
1355  aCol[i].UndoToColumn(rCxt, nRow1, nRow2, nFlags, bMarked, rDestCol);
1356  else
1357  aCol[i].CopyToColumn(rCxt, 0, rDocument.MaxRow(), InsertDeleteFlags::FORMULA, false, rDestCol);
1358  }
1359 
1360  if (nFlags & InsertDeleteFlags::ATTRIB)
1361  pDestTab->mpCondFormatList.reset(new ScConditionalFormatList(pDestTab->rDocument, *mpCondFormatList));
1362 
1363  if (!(bWidth||bHeight))
1364  return;
1365 
1366  if (bWidth)
1367  {
1368  pDestTab->mpColWidth->CopyFrom(*mpColWidth, nCol1, nCol2);
1370  }
1371  if (bHeight)
1372  {
1373  pDestTab->CopyRowHeight(*this, nRow1, nRow2, 0);
1375  }
1376 }
1377 
1378 void ScTable::CopyUpdated( const ScTable* pPosTab, ScTable* pDestTab ) const
1379 {
1380  pPosTab->CreateColumnIfNotExists(aCol.size()-1);
1381  pDestTab->CreateColumnIfNotExists(aCol.size()-1);
1382  for (SCCOL i=0; i < aCol.size(); i++)
1383  aCol[i].CopyUpdated( pPosTab->aCol[i], pDestTab->aCol[i] );
1384 }
1385 
1387 {
1388  bTableAreaValid = false;
1389 }
1390 
1392 {
1393  mbPageBreaksValid = false;
1394 }
1395 
1396 void ScTable::CopyScenarioTo( const ScTable* pDestTab ) const
1397 {
1398  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1399 
1400  for (SCCOL i=0; i < aCol.size(); i++)
1402 }
1403 
1404 void ScTable::CopyScenarioFrom( const ScTable* pSrcTab )
1405 {
1406  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1407 
1408  SCCOL nEndCol = pSrcTab->aCol.size();
1409  CreateColumnIfNotExists(nEndCol);
1410  for (SCCOL i=0; i < nEndCol; i++)
1411  aCol[i].CopyScenarioFrom( pSrcTab->aCol[i] );
1412 }
1413 
1414 void ScTable::MarkScenarioIn( ScMarkData& rDestMark, ScScenarioFlags nNeededBits ) const
1415 {
1416  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1417 
1418  if ( ( nScenarioFlags & nNeededBits ) != nNeededBits ) // Are all Bits set?
1419  return;
1420 
1421  for (SCCOL i=0; i < aCol.size(); i++)
1422  aCol[i].MarkScenarioIn( rDestMark );
1423 }
1424 
1425 bool ScTable::HasScenarioRange( const ScRange& rRange ) const
1426 {
1427  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1428 
1429  ScRange aTabRange = rRange;
1430  aTabRange.aStart.SetTab( nTab );
1431  aTabRange.aEnd.SetTab( nTab );
1432 
1433  const ScRangeList* pList = GetScenarioRanges();
1434 
1435  if (pList)
1436  {
1437  for ( size_t j = 0, n = pList->size(); j < n; j++ )
1438  {
1439  const ScRange & rR = (*pList)[j];
1440  if ( rR.Intersects( aTabRange ) )
1441  return true;
1442  }
1443  }
1444 
1445  return false;
1446 }
1447 
1449 {
1450  pScenarioRanges.reset();
1451 }
1452 
1454 {
1455  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1456 
1457  if (!pScenarioRanges)
1458  {
1459  const_cast<ScTable*>(this)->pScenarioRanges.reset(new ScRangeList);
1460  ScMarkData aMark(rDocument.GetSheetLimits());
1461  MarkScenarioIn( aMark, ScScenarioFlags::NONE ); // always
1462  aMark.FillRangeListWithMarks( pScenarioRanges.get(), false );
1463  }
1464  return pScenarioRanges.get();
1465 }
1466 
1467 bool ScTable::TestCopyScenarioTo( const ScTable* pDestTab ) const
1468 {
1469  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1470 
1471  if (!pDestTab->IsProtected())
1472  return true;
1473 
1474  bool bOk = true;
1475  for (SCCOL i=0; i < aCol.size() && bOk; i++)
1476  bOk = aCol[i].TestCopyScenarioTo( pDestTab->aCol[i] );
1477  return bOk;
1478 }
1479 
1480 bool ScTable::SetString( SCCOL nCol, SCROW nRow, SCTAB nTabP, const OUString& rString,
1481  const ScSetStringParam * pParam )
1482 {
1483  if (!ValidColRow(nCol,nRow))
1484  {
1485  return false;
1486  }
1487 
1488  return CreateColumnIfNotExists(nCol).SetString(
1489  nRow, nTabP, rString, rDocument.GetAddressConvention(), pParam);
1490 }
1491 
1492 bool ScTable::SetEditText( SCCOL nCol, SCROW nRow, std::unique_ptr<EditTextObject> pEditText )
1493 {
1494  if (!ValidColRow(nCol, nRow))
1495  {
1496  return false;
1497  }
1498 
1499  CreateColumnIfNotExists(nCol).SetEditText(nRow, std::move(pEditText));
1500  return true;
1501 }
1502 
1503 void ScTable::SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool )
1504 {
1505  if (!ValidColRow(nCol, nRow))
1506  return;
1507 
1508  CreateColumnIfNotExists(nCol).SetEditText(nRow, rEditText, pEditPool);
1509 }
1510 
1511 SCROW ScTable::GetFirstEditTextRow( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const
1512 {
1513  if (!ValidCol(nCol1) || !ValidCol(nCol2) || nCol2 < nCol1)
1514  return -1;
1515 
1516  if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow2 < nRow1)
1517  return -1;
1518 
1519  nCol2 = ClampToAllocatedColumns(nCol2);
1520  SCROW nFirst = rDocument.MaxRow()+1;
1521  for (SCCOL i = nCol1; i <= nCol2; ++i)
1522  {
1523  const ScColumn& rCol = aCol[i];
1524  SCROW nThisFirst = -1;
1525  if (const_cast<ScColumn&>(rCol).HasEditCells(nRow1, nRow2, nThisFirst))
1526  {
1527  if (nThisFirst == nRow1)
1528  return nRow1;
1529 
1530  if (nThisFirst < nFirst)
1531  nFirst = nThisFirst;
1532  }
1533  }
1534 
1535  return nFirst == (rDocument.MaxRow()+1) ? -1 : nFirst;
1536 }
1537 
1539 {
1540  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1541  return;
1542 
1543  aCol[nCol].Delete(nRow);
1544 }
1545 
1547  SCCOL nCol, SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
1548 {
1549  if (!ValidColRow(nCol, nRow))
1550  return;
1551 
1552  CreateColumnIfNotExists(nCol).SetFormula(nRow, rArray, eGram);
1553 }
1554 
1556  SCCOL nCol, SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
1557 {
1558  if (!ValidColRow(nCol, nRow))
1559  return;
1560 
1561  CreateColumnIfNotExists(nCol).SetFormula(nRow, rFormula, eGram);
1562 }
1563 
1565 {
1566  if (!ValidColRow(nCol, nRow))
1567  {
1568  delete pCell;
1569  return nullptr;
1570  }
1571 
1573 }
1574 
1575 bool ScTable::SetFormulaCells( SCCOL nCol, SCROW nRow, std::vector<ScFormulaCell*>& rCells )
1576 {
1577  if (!ValidCol(nCol))
1578  return false;
1579 
1580  return CreateColumnIfNotExists(nCol).SetFormulaCells(nRow, rCells);
1581 }
1582 
1584 {
1585  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1586  return svl::SharedString();
1587 
1588  return aCol[nCol].GetSharedString(nRow);
1589 }
1590 
1591 void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal )
1592 {
1593  if (ValidColRow(nCol, nRow))
1594  CreateColumnIfNotExists(nCol).SetValue(nRow, rVal);
1595 }
1596 
1597 void ScTable::SetRawString( SCCOL nCol, SCROW nRow, const svl::SharedString& rStr )
1598 {
1599  if (ValidColRow(nCol, nRow))
1600  CreateColumnIfNotExists(nCol).SetRawString(nRow, rStr);
1601 }
1602 
1603 void ScTable::GetString( SCCOL nCol, SCROW nRow, OUString& rString, const ScInterpreterContext* pContext ) const
1604 {
1605  if (ValidColRow(nCol,nRow) && nCol < GetAllocatedColumnsCount())
1606  aCol[nCol].GetString( nRow, rString, pContext );
1607  else
1608  rString.clear();
1609 }
1610 
1611 double* ScTable::GetValueCell( SCCOL nCol, SCROW nRow )
1612 {
1613  if (!ValidColRow(nCol, nRow))
1614  return nullptr;
1615 
1616  return CreateColumnIfNotExists(nCol).GetValueCell(nRow);
1617 }
1618 
1619 void ScTable::GetInputString( SCCOL nCol, SCROW nRow, OUString& rString ) const
1620 {
1621  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1622  aCol[nCol].GetInputString( nRow, rString );
1623  else
1624  rString.clear();
1625 }
1626 
1627 double ScTable::GetValue( SCCOL nCol, SCROW nRow ) const
1628 {
1629  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1630  return aCol[nCol].GetValue( nRow );
1631  return 0.0;
1632 }
1633 
1635 {
1636  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1637  return nullptr;
1638 
1639  return aCol[nCol].GetEditText(nRow);
1640 }
1641 
1643 {
1644  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1645  return;
1646 
1647  return aCol[nCol].RemoveEditTextCharAttribs(nRow, rAttr);
1648 }
1649 
1650 void ScTable::GetFormula( SCCOL nCol, SCROW nRow, OUString& rFormula ) const
1651 {
1652  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1653  aCol[nCol].GetFormula( nRow, rFormula );
1654  else
1655  rFormula.clear();
1656 }
1657 
1659 {
1660  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1661  return nullptr;
1662 
1663  return aCol[nCol].GetFormulaCell(nRow);
1664 }
1665 
1667 {
1668  if (!ValidColRow(nCol, nRow))
1669  return nullptr;
1670  return CreateColumnIfNotExists(nCol).GetFormulaCell(nRow);
1671 }
1672 
1673 std::unique_ptr<ScPostIt> ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
1674 {
1675  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1676  return nullptr;
1677 
1678  return aCol[nCol].ReleaseNote(nRow);
1679 }
1680 
1681 size_t ScTable::GetNoteCount( SCCOL nCol ) const
1682 {
1683  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1684  return 0;
1685 
1686  return aCol[nCol].GetNoteCount();
1687 }
1688 
1689 SCROW ScTable::GetNotePosition( SCCOL nCol, size_t nIndex ) const
1690 {
1691  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1692  return -1;
1693 
1694  return aCol[nCol].GetNotePosition(nIndex);
1695 }
1696 
1698 {
1699  for (SCCOL i = 0; i < aCol.size(); ++i)
1701 }
1702 
1703 void ScTable::ForgetNoteCaptions( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bPreserveData )
1704 {
1705  if (!ValidCol(nCol1) || !ValidCol(nCol2))
1706  return;
1707  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1708  for (SCCOL i = nCol1; i <= nCol2; ++i)
1709  aCol[i].ForgetNoteCaptions(nRow1, nRow2, bPreserveData);
1710 }
1711 
1712 void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
1713 {
1714  for (SCCOL nCol = 0; nCol < aCol.size(); ++nCol)
1715  aCol[nCol].GetAllNoteEntries(rNotes);
1716 }
1717 
1718 void ScTable::GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const
1719 {
1720  SCROW nStartRow = rRange.aStart.Row();
1721  SCROW nEndRow = rRange.aEnd.Row();
1722  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
1723  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1724  {
1725  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1726  }
1727 }
1728 
1729 CommentCaptionState ScTable::GetAllNoteCaptionsState(const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes )
1730 {
1731  SCROW nStartRow = rRange.aStart.Row();
1732  SCROW nEndRow = rRange.aEnd.Row();
1733  bool bIsFirstNoteShownState = true; // because of error: -Werror=maybe-uninitialized
1734  bool bFirstControl = true;
1735 
1736  ScTable* pTab = rDocument.FetchTable(nTab);
1737  assert(pTab);
1738  const SCCOL nEndCol = pTab->ClampToAllocatedColumns(rRange.aEnd.Col());
1739  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1740  {
1741  if (bFirstControl && rDocument.HasColNotes(nCol, nTab)) // detect status of first note caption
1742  {
1743  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1744  bIsFirstNoteShownState = rNotes.begin()->mpNote->IsCaptionShown();
1745  bFirstControl = false;
1746  }
1747 
1748  if (rDocument.HasColNotes(nCol, nTab))
1749  {
1750  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1751 
1752  bool bIsMixedState = std::any_of(rNotes.begin(), rNotes.end(), [bIsFirstNoteShownState](const sc::NoteEntry& rNote) {
1753  // compare the first note caption with others
1754  return bIsFirstNoteShownState != rNote.mpNote->IsCaptionShown(); });
1755  if (bIsMixedState)
1757  }
1758  }
1759  return bIsFirstNoteShownState ? CommentCaptionState::ALLSHOWN : CommentCaptionState::ALLHIDDEN;
1760 }
1761 
1763 {
1764  for (auto const & pCol : aCol)
1765  pCol->GetUnprotectedCells(0, rDocument.MaxRow(), rRangeList);
1766 }
1767 
1768 bool ScTable::ContainsNotesInRange( const ScRange& rRange ) const
1769 {
1770  SCROW nStartRow = rRange.aStart.Row();
1771  SCROW nEndRow = rRange.aEnd.Row();
1772  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
1773  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1774  {
1775  bool bContainsNote = !aCol[nCol].IsNotesEmptyBlock(nStartRow, nEndRow);
1776  if(bContainsNote)
1777  return true;
1778  }
1779 
1780  return false;
1781 }
1782 
1784 {
1785  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1786  return aCol[nCol].GetCellType( nRow );
1787  return CELLTYPE_NONE;
1788 }
1789 
1791 {
1792  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1793  return ScRefCellValue();
1794 
1795  return aCol[nCol].GetCellValue(nRow);
1796 }
1797 
1798 void ScTable::GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const
1799 {
1800  rCol = 0;
1801  rRow = rDocument.MaxRow()+1;
1802  while (rCol < (aCol.size() - 1) && aCol[rCol].IsEmptyData() )
1803  ++rCol;
1804  SCCOL nCol = rCol;
1805  while (nCol < aCol.size() && rRow > 0)
1806  {
1807  if (!aCol[nCol].IsEmptyData())
1808  rRow = ::std::min( rRow, aCol[nCol].GetFirstDataPos());
1809  ++nCol;
1810  }
1811 }
1812 
1813 void ScTable::GetLastDataPos(SCCOL& rCol, SCROW& rRow) const
1814 {
1815  rCol = aCol.size() - 1;
1816  rRow = 0;
1817  while (aCol[rCol].IsEmptyData() && (rCol > 0))
1818  rCol--;
1819  SCCOL nCol = rCol;
1820  while (nCol >= 0 && rRow < rDocument.MaxRow())
1821  rRow = ::std::max( rRow, aCol[nCol--].GetLastDataPos());
1822 }
1823 
1824 bool ScTable::HasData( SCCOL nCol, SCROW nRow ) const
1825 {
1826  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1827  return aCol[nCol].HasDataAt( nRow );
1828  else
1829  return false;
1830 }
1831 
1832 bool ScTable::HasStringData( SCCOL nCol, SCROW nRow ) const
1833 {
1834  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1835  return aCol[nCol].HasStringData( nRow );
1836  else
1837  return false;
1838 }
1839 
1840 bool ScTable::HasValueData( SCCOL nCol, SCROW nRow ) const
1841 {
1842  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1843  return aCol[nCol].HasValueData( nRow );
1844  else
1845  return false;
1846 }
1847 
1848 bool ScTable::HasStringCells( SCCOL nStartCol, SCROW nStartRow,
1849  SCCOL nEndCol, SCROW nEndRow ) const
1850 {
1851  if (ValidCol(nEndCol))
1852  {
1853  nEndCol = ClampToAllocatedColumns(nEndCol);
1854  for (SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++)
1855  if (aCol[nCol].HasStringCells(nStartRow, nEndRow))
1856  return true;
1857  }
1858 
1859  return false;
1860 }
1861 
1863 {
1864  for (SCCOL i=0; i < aCol.size(); i++)
1865  aCol[i].SetDirtyVar();
1866 }
1867 
1869 {
1870  sc::AutoCalcSwitch aACSwitch(rDocument, false);
1871 
1872  for (SCCOL i = 0; i < aCol.size(); i++)
1874 }
1875 
1877 {
1878  sc::AutoCalcSwitch aACSwitch(rDocument, false);
1879 
1880  for (SCCOL i=0; i < aCol.size(); i++)
1881  aCol[i].SetAllFormulasDirty(rCxt);
1882 }
1883 
1885 {
1886  bool bOldAutoCalc = rDocument.GetAutoCalc();
1887  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
1888  SCCOL nCol2 = rRange.aEnd.Col();
1889  nCol2 = ClampToAllocatedColumns(nCol2);
1890  for (SCCOL i=rRange.aStart.Col(); i<=nCol2; i++)
1891  aCol[i].SetDirty(rRange.aStart.Row(), rRange.aEnd.Row(), eMode);
1892  rDocument.SetAutoCalc( bOldAutoCalc );
1893 }
1894 
1895 void ScTable::SetTableOpDirty( const ScRange& rRange )
1896 {
1897  bool bOldAutoCalc = rDocument.GetAutoCalc();
1898  rDocument.SetAutoCalc( false ); // no multiple recalculation
1899  const SCCOL nCol2 = ClampToAllocatedColumns(rRange.aEnd.Col());
1900  for (SCCOL i=rRange.aStart.Col(); i<=nCol2; i++)
1901  aCol[i].SetTableOpDirty( rRange );
1902  rDocument.SetAutoCalc( bOldAutoCalc );
1903 }
1904 
1906 {
1907  bool bOldAutoCalc = rDocument.GetAutoCalc();
1908  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
1909  for (SCCOL i=0; i < aCol.size(); i++)
1911  rDocument.SetAutoCalc( bOldAutoCalc );
1912 }
1913 
1915 {
1916  bool bOldAutoCalc = rDocument.GetAutoCalc();
1917  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
1918  for (SCCOL i=0; i < aCol.size(); i++)
1920  rDocument.SetAutoCalc( bOldAutoCalc );
1921 }
1922 
1924 {
1925  sc::AutoCalcSwitch aSwitch(rDocument, false);
1926  for (SCCOL i = 0; i < aCol.size(); ++i)
1928 }
1929 
1930 bool ScTable::BroadcastBroadcasters( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScHint& rHint )
1931 {
1932  bool bBroadcasted = false;
1933  sc::AutoCalcSwitch aSwitch(rDocument, false);
1934  rHint.GetAddress().SetTab(nTab);
1935  nCol2 = ClampToAllocatedColumns(nCol2);
1936  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
1937  bBroadcasted |= aCol[nCol].BroadcastBroadcasters( nRow1, nRow2, rHint);
1938  return bBroadcasted;
1939 }
1940 
1941 void ScTable::SetLoadingMedium(bool bLoading)
1942 {
1943  mpRowHeights->enableTreeSearch(!bLoading);
1944 }
1945 
1947 {
1948  for (SCCOL i=0; i < aCol.size(); i++)
1949  aCol[i].CalcAll();
1950 
1951  mpCondFormatList->CalcAll();
1952 }
1953 
1955 {
1956  for (SCCOL i = 0; i < aCol.size(); ++i)
1957  aCol[i].CompileAll(rCxt);
1958 
1959  if(mpCondFormatList)
1960  mpCondFormatList->CompileAll();
1961 }
1962 
1964 {
1965  if (mpRangeName)
1966  mpRangeName->CompileUnresolvedXML(rCxt);
1967 
1968  for (SCCOL i=0; i < aCol.size(); i++)
1969  {
1970  aCol[i].CompileXML(rCxt, rProgress);
1971  }
1972 
1973  if(mpCondFormatList)
1974  mpCondFormatList->CompileXML();
1975 }
1976 
1978 {
1979  bool bCompiled = false;
1980  for (SCCOL i = 0; i < aCol.size(); ++i)
1981  {
1982  if (aCol[i].CompileErrorCells(rCxt, nErrCode))
1983  bCompiled = true;
1984  }
1985 
1986  return bCompiled;
1987 }
1988 
1989 void ScTable::CalcAfterLoad( sc::CompileFormulaContext& rCxt, bool bStartListening )
1990 {
1991  for (SCCOL i = 0; i < aCol.size(); ++i)
1992  aCol[i].CalcAfterLoad(rCxt, bStartListening);
1993 }
1994 
1995 void ScTable::ResetChanged( const ScRange& rRange )
1996 {
1997  SCCOL nStartCol = rRange.aStart.Col();
1998  SCROW nStartRow = rRange.aStart.Row();
1999  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
2000  SCROW nEndRow = rRange.aEnd.Row();
2001 
2002  for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
2003  aCol[nCol].ResetChanged(nStartRow, nEndRow);
2004 }
2005 
2006 // Attribute
2007 
2008 const SfxPoolItem* ScTable::GetAttr( SCCOL nCol, SCROW nRow, sal_uInt16 nWhich ) const
2009 {
2010  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
2011  return &aCol[nCol].GetAttr( nRow, nWhich );
2012  else
2013  return nullptr;
2014 }
2015 
2016 sal_uInt32 ScTable::GetNumberFormat( const ScInterpreterContext& rContext, const ScAddress& rPos ) const
2017 {
2018  if (ValidColRow(rPos.Col(), rPos.Row()))
2019  {
2020  if (rPos.Col() < GetAllocatedColumnsCount())
2021  return aCol[rPos.Col()].GetNumberFormat(rContext, rPos.Row());
2022  return aDefaultColAttrArray.GetPattern(rPos.Row())
2023  ->GetNumberFormat(rContext.GetFormatTable());
2024  }
2025  return 0;
2026 }
2027 
2028 sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nRow ) const
2029 {
2030  if (ValidColRow(nCol,nRow))
2031  return CreateColumnIfNotExists(nCol).GetNumberFormat(rDocument.GetNonThreadedContext(), nRow);
2032  else
2033  return 0;
2034 }
2035 
2036 sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
2037 {
2038  if (!ValidCol(nCol) || !ValidRow(nStartRow) || !ValidRow(nEndRow))
2039  return 0;
2040 
2041  return CreateColumnIfNotExists(nCol).GetNumberFormat(nStartRow, nEndRow);
2042 }
2043 
2044 void ScTable::SetNumberFormat( SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat )
2045 {
2046  if (!ValidColRow(nCol, nRow))
2047  return;
2048 
2049  CreateColumnIfNotExists(nCol).SetNumberFormat(nRow, nNumberFormat);
2050 }
2051 
2052 const ScPatternAttr* ScTable::GetPattern( SCCOL nCol, SCROW nRow ) const
2053 {
2054  if (ValidColRow(nCol,nRow))
2055  return CreateColumnIfNotExists(nCol).GetPattern( nRow );
2056  else
2057  {
2058  OSL_FAIL("wrong column or row");
2059  return rDocument.GetDefPattern(); // for safety
2060  }
2061 }
2062 
2063 const ScPatternAttr* ScTable::GetMostUsedPattern( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
2064 {
2065  if ( ValidColRow( nCol, nStartRow ) && ValidRow( nEndRow ) && (nStartRow <= nEndRow)
2066  && nCol < GetAllocatedColumnsCount())
2067  return aCol[nCol].GetMostUsedPattern( nStartRow, nEndRow );
2068  else
2069  return nullptr;
2070 }
2071 
2072 bool ScTable::HasAttrib( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, HasAttrFlags nMask ) const
2073 {
2074  if ( nCol1 >= aCol.size() )
2075  return false;
2076  if ( nCol2 >= aCol.size() )
2077  nCol2 = aCol.size() - 1; // Rows above range, doesn't contains flags
2078 
2079  bool bFound = false;
2080  for (SCCOL i=nCol1; i<=nCol2 && !bFound; i++)
2081  bFound |= aCol[i].HasAttrib( nRow1, nRow2, nMask );
2082  return bFound;
2083 }
2084 
2085 bool ScTable::HasAttribSelection( const ScMarkData& rMark, HasAttrFlags nMask ) const
2086 {
2087  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2088 
2089  for (const sc::ColRowSpan & aSpan : aSpans)
2090  {
2091  for (SCCOLROW j = aSpan.mnStart; j <= aSpan.mnEnd; ++j)
2092  {
2093  if (aCol[j].HasAttribSelection(rMark, nMask))
2094  return true;
2095  }
2096  }
2097  return false;
2098 }
2099 
2100 bool ScTable::ExtendMerge( SCCOL nStartCol, SCROW nStartRow,
2101  SCCOL& rEndCol, SCROW& rEndRow,
2102  bool bRefresh )
2103 {
2104  if (!(ValidCol(nStartCol) && ValidCol(rEndCol)))
2105  {
2106  OSL_FAIL("ScTable::ExtendMerge: invalid column number");
2107  return false;
2108  }
2109  if ( nStartCol >= aCol.size() )
2110  {
2111  OSL_FAIL("ScTable::ExtendMerge: invalid nStartCol");
2112  return false;
2113  }
2114  bool bFound = false;
2115  SCCOL nOldEndX = std::min( rEndCol, static_cast<SCCOL>(aCol.size()-1) );
2116  SCROW nOldEndY = rEndRow;
2117  for (SCCOL i=nStartCol; i<=nOldEndX; i++)
2118  bFound |= aCol[i].ExtendMerge( i, nStartRow, nOldEndY, rEndCol, rEndRow, bRefresh );
2119  return bFound;
2120 }
2121 
2122 void ScTable::SetMergedCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
2123 {
2124  ScMergeAttr aAttr(nCol2-nCol1+1, nRow2-nRow1+1);
2125  ApplyAttr(nCol1, nRow1, aAttr);
2126 
2127  if (nCol1 < nCol2)
2128  ApplyFlags(nCol1+1, nRow1, nCol2, nRow2, ScMF::Hor);
2129 
2130  if (nRow1 < nRow2)
2131  ApplyFlags(nCol1, nRow1+1, nCol1, nRow2, ScMF::Ver);
2132 
2133  if (nCol1 < nCol2 && nRow1 < nRow2)
2134  ApplyFlags(nCol1+1, nRow1+1, nCol2, nRow2, ScMF::Hor | ScMF::Ver);
2135 }
2136 
2137 bool ScTable::IsBlockEmpty( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bIgnoreNotes ) const
2138 {
2139  if (!(ValidCol(nCol1) && ValidCol(nCol2)))
2140  {
2141  OSL_FAIL("ScTable::IsBlockEmpty: invalid column number");
2142  return false;
2143  }
2144  nCol2 = ClampToAllocatedColumns(nCol2);
2145  bool bEmpty = true;
2146  for (SCCOL i=nCol1; i<=nCol2 && bEmpty; i++)
2147  {
2148  bEmpty = aCol[i].IsEmptyBlock( nRow1, nRow2 );
2149  if (!bIgnoreNotes && bEmpty)
2150  {
2151  bEmpty = aCol[i].IsNotesEmptyBlock(nRow1, nRow2);
2152  }
2153  }
2154  return bEmpty;
2155 }
2156 
2157 SCSIZE ScTable::FillMaxRot( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2,
2158  SCCOL nCol, SCROW nAttrRow1, SCROW nAttrRow2, SCSIZE nArrY,
2159  const ScPatternAttr* pPattern, const SfxItemSet* pCondSet )
2160 {
2161  // Return value = new nArrY
2162 
2163  ScRotateDir nRotDir = pPattern->GetRotateDir( pCondSet );
2164  if ( nRotDir != ScRotateDir::NONE )
2165  {
2166  bool bHit = true;
2167  if ( nCol+1 < nX1 ) // column to the left
2168  bHit = ( nRotDir != ScRotateDir::Left );
2169  else if ( nCol > nX2+1 ) // column to the right
2170  bHit = ( nRotDir != ScRotateDir::Right ); // ScRotateDir::Standard may now also be extended to the left
2171 
2172  if ( bHit )
2173  {
2174  double nFactor = 0.0;
2175  if ( nCol > nX2+1 )
2176  {
2177  Degree100 nRotVal = pPattern->
2178  GetItem( ATTR_ROTATE_VALUE, pCondSet ).GetValue();
2179  double nRealOrient = nRotVal.get() * F_PI18000; // 1/100 degree
2180  double nCos = cos( nRealOrient );
2181  double nSin = sin( nRealOrient );
2182  //TODO: limit !!!
2183  //TODO: additional factor for varying PPT X/Y !!!
2184 
2185  // for ScRotateDir::Left this gives a negative value,
2186  // if the mode is considered
2187  nFactor = -fabs( nCos / nSin );
2188  }
2189 
2190  for ( SCROW nRow = nAttrRow1; nRow <= nAttrRow2; nRow++ )
2191  {
2192  if (!RowHidden(nRow))
2193  {
2194  bool bHitOne = true;
2195  if ( nCol > nX2+1 )
2196  {
2197  // Does the rotated cell extend into the visible range?
2198 
2199  SCCOL nTouchedCol = nCol;
2200  tools::Long nWidth = static_cast<tools::Long>(mpRowHeights->getValue(nRow) * nFactor);
2201  OSL_ENSURE(nWidth <= 0, "Wrong direction");
2202  while ( nWidth < 0 && nTouchedCol > 0 )
2203  {
2204  --nTouchedCol;
2205  nWidth += GetColWidth( nTouchedCol );
2206  }
2207  if ( nTouchedCol > nX2 )
2208  bHitOne = false;
2209  }
2210 
2211  if (bHitOne)
2212  {
2213  while ( nArrY<nArrCount && pRowInfo[nArrY].nRowNo < nRow )
2214  ++nArrY;
2215  if ( nArrY<nArrCount && pRowInfo[nArrY].nRowNo == nRow )
2216  pRowInfo[nArrY].nRotMaxCol = nCol;
2217  }
2218  }
2219  }
2220  }
2221  }
2222 
2223  return nArrY;
2224 }
2225 
2226 void ScTable::FindMaxRotCol( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2 )
2227 {
2228  if ( !mpColWidth || !mpRowHeights || !mpColFlags || !pRowFlags )
2229  {
2230  OSL_FAIL( "Row/column info missing" );
2231  return;
2232  }
2233 
2234  // nRotMaxCol is initialized to SC_ROTMAX_NONE, nRowNo is already set
2235 
2236  SCROW nY1 = pRowInfo[0].nRowNo;
2237  SCROW nY2 = pRowInfo[nArrCount-1].nRowNo;
2238 
2239  for (SCCOL nCol : GetColumnsRange(0, rDocument.MaxCol()))
2240  {
2241  if (!ColHidden(nCol))
2242  {
2243  SCSIZE nArrY = 0;
2244  ScDocAttrIterator aIter( rDocument, nTab, nCol, nY1, nCol, nY2 );
2245  SCCOL nAttrCol;
2246  SCROW nAttrRow1, nAttrRow2;
2247  const ScPatternAttr* pPattern = aIter.GetNext( nAttrCol, nAttrRow1, nAttrRow2 );
2248  while ( pPattern )
2249  {
2250  const SfxPoolItem* pCondItem;
2251  if ( pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, true, &pCondItem )
2252  == SfxItemState::SET )
2253  {
2254  // Run through all formats, so that each cell does not have to be
2255  // handled individually
2256 
2257  const ScCondFormatIndexes& rCondFormatData = static_cast<const ScCondFormatItem*>(pCondItem)->GetCondFormatData();
2258  ScStyleSheetPool* pStylePool = rDocument.GetStyleSheetPool();
2259  if (mpCondFormatList && pStylePool && !rCondFormatData.empty())
2260  {
2261  for(const auto& rItem : rCondFormatData)
2262  {
2263  const ScConditionalFormat* pFormat = mpCondFormatList->GetFormat(rItem);
2264  if ( pFormat )
2265  {
2266  size_t nEntryCount = pFormat->size();
2267  for (size_t nEntry=0; nEntry<nEntryCount; nEntry++)
2268  {
2269  const ScFormatEntry* pEntry = pFormat->GetEntry(nEntry);
2270  if(pEntry->GetType() != ScFormatEntry::Type::Condition &&
2272  continue;
2273 
2274  OUString aStyleName = static_cast<const ScCondFormatEntry*>(pEntry)->GetStyle();
2275  if (!aStyleName.isEmpty())
2276  {
2277  SfxStyleSheetBase* pStyleSheet =
2278  pStylePool->Find( aStyleName, SfxStyleFamily::Para );
2279  if ( pStyleSheet )
2280  {
2281  FillMaxRot( pRowInfo, nArrCount, nX1, nX2,
2282  nCol, nAttrRow1, nAttrRow2,
2283  nArrY, pPattern, &pStyleSheet->GetItemSet() );
2284  // not changing nArrY
2285  }
2286  }
2287  }
2288  }
2289  }
2290  }
2291  }
2292 
2293  nArrY = FillMaxRot( pRowInfo, nArrCount, nX1, nX2,
2294  nCol, nAttrRow1, nAttrRow2,
2295  nArrY, pPattern, nullptr );
2296 
2297  pPattern = aIter.GetNext( nAttrCol, nAttrRow1, nAttrRow2 );
2298  }
2299  }
2300  }
2301 }
2302 
2303 bool ScTable::HasBlockMatrixFragment( const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2,
2304  bool bNoMatrixAtAll ) const
2305 {
2306  using namespace sc;
2307 
2308  if ( !IsColValid( nCol1 ) )
2309  return false;
2310 
2311  const SCCOL nMaxCol2 = std::min<SCCOL>( nCol2, aCol.size() - 1 );
2312 
2313  MatrixEdge nEdges = MatrixEdge::Nothing;
2314 
2315  if ( nCol1 == nMaxCol2 )
2316  { // left and right column
2318  nEdges = aCol[nCol1].GetBlockMatrixEdges( nRow1, nRow2, n, bNoMatrixAtAll );
2319  if ((nEdges != MatrixEdge::Nothing) && (((nEdges & n)!=n) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2320  return true; // left or right edge is missing or open
2321  }
2322  else
2323  { // left column
2324  nEdges = aCol[nCol1].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Left, bNoMatrixAtAll);
2325  if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Left)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2326  return true; // left edge missing or open
2327  // right column
2328  nEdges = aCol[nMaxCol2].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Right, bNoMatrixAtAll);
2329  if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Right)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2330  return true; // right edge is missing or open
2331  }
2332 
2333  if (bNoMatrixAtAll)
2334  {
2335  for (SCCOL i=nCol1; i<=nMaxCol2; i++)
2336  {
2337  nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow2, MatrixEdge::Nothing, bNoMatrixAtAll);
2338  if (nEdges != MatrixEdge::Nothing
2339  && (nEdges != (MatrixEdge::Top | MatrixEdge::Left | MatrixEdge::Bottom | MatrixEdge::Right)))
2340  return true;
2341  }
2342  }
2343  else if ( nRow1 == nRow2 )
2344  { // Row on top and on bottom
2345  bool bOpen = false;
2346  const MatrixEdge n = MatrixEdge::Bottom | MatrixEdge::Top;
2347  for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
2348  {
2349  nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow1, n, bNoMatrixAtAll );
2350  if (nEdges != MatrixEdge::Nothing)
2351  {
2352  if ( (nEdges & n) != n )
2353  return true; // Top or bottom edge missing
2354  if (nEdges & MatrixEdge::Left)
2355  bOpen = true; // left edge open, continue
2356  else if ( !bOpen )
2357  return true; // Something exist that has not been opened
2358  if (nEdges & MatrixEdge::Right)
2359  bOpen = false; // Close right edge
2360  }
2361  }
2362  if ( bOpen )
2363  return true;
2364  }
2365  else
2366  {
2367  int j;
2368  MatrixEdge n;
2369  SCROW nR;
2370  // first top row, then bottom row
2371  for ( j=0, n = MatrixEdge::Top, nR=nRow1; j<2;
2372  j++, n = MatrixEdge::Bottom, nR=nRow2)
2373  {
2374  bool bOpen = false;
2375  for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
2376  {
2377  nEdges = aCol[i].GetBlockMatrixEdges( nR, nR, n, bNoMatrixAtAll );
2378  if ( nEdges != MatrixEdge::Nothing)
2379  {
2380  // in top row no top edge respectively
2381  // in bottom row no bottom edge
2382  if ( (nEdges & n) != n )
2383  return true;
2384  if (nEdges & MatrixEdge::Left)
2385  bOpen = true; // open left edge, continue
2386  else if ( !bOpen )
2387  return true; // Something exist that has not been opened
2388  if (nEdges & MatrixEdge::Right)
2389  bOpen = false; // Close right edge
2390  }
2391  }
2392  if ( bOpen )
2393  return true;
2394  }
2395  }
2396  return false;
2397 }
2398 
2400 {
2401  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2402 
2403  for (const sc::ColRowSpan & aSpan : aSpans)
2404  {
2405  SCCOL nEndCol = ClampToAllocatedColumns(aSpan.mnEnd);
2406  for ( SCCOLROW j=aSpan.mnStart; j<=nEndCol; j++ )
2407  {
2408  if ( aCol[j].HasSelectionMatrixFragment(rMark) )
2409  return true;
2410  }
2411  }
2412  return false;
2413 }
2414 
2415 bool ScTable::IsBlockEditable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2,
2416  SCROW nRow2, bool* pOnlyNotBecauseOfMatrix /* = NULL */,
2417  bool bNoMatrixAtAll ) const
2418 {
2419  if ( !ValidColRow( nCol2, nRow2 ) )
2420  {
2421  SAL_WARN("sc", "IsBlockEditable: invalid column or row " << nCol2 << " " << nRow2);
2422  if (pOnlyNotBecauseOfMatrix)
2423  *pOnlyNotBecauseOfMatrix = false;
2424  return false;
2425  }
2426  nCol1 = ClampToAllocatedColumns(nCol1);
2427  nCol2 = ClampToAllocatedColumns(nCol2);
2428 
2429  bool bIsEditable = true;
2430  if ( nLockCount )
2431  bIsEditable = false;
2432  else if ( IsProtected() && !rDocument.IsScenario(nTab) )
2433  {
2434  bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, HasAttrFlags::Protected );
2435  if (!bIsEditable)
2436  {
2437  // An enhanced protection permission may override the attribute.
2438  if (pTabProtection)
2439  bIsEditable = pTabProtection->isBlockEditable( ScRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab));
2440  }
2441  if (bIsEditable)
2442  {
2443  // If Sheet is protected and cells are not protected then
2444  // check the active scenario protect flag if this range is
2445  // on the active scenario range. Note the 'copy back' must also
2446  // be set to apply protection.
2447  sal_uInt16 nScenTab = nTab+1;
2448  while(rDocument.IsScenario(nScenTab))
2449  {
2450  ScRange aEditRange(nCol1, nRow1, nScenTab, nCol2, nRow2, nScenTab);
2451  if(rDocument.IsActiveScenario(nScenTab) && rDocument.HasScenarioRange(nScenTab, aEditRange))
2452  {
2453  ScScenarioFlags nFlags;
2454  rDocument.GetScenarioFlags(nScenTab,nFlags);
2455  bIsEditable = !((nFlags & ScScenarioFlags::Protected) && (nFlags & ScScenarioFlags::TwoWay));
2456  break;
2457  }
2458  nScenTab++;
2459  }
2460  }
2461  }
2462  else if (rDocument.IsScenario(nTab))
2463  {
2464  // Determine if the preceding sheet is protected
2465  SCTAB nActualTab = nTab;
2466  do
2467  {
2468  nActualTab--;
2469  }
2470  while(rDocument.IsScenario(nActualTab));
2471 
2472  if(rDocument.IsTabProtected(nActualTab))
2473  {
2474  ScRange aEditRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab);
2475  if(rDocument.HasScenarioRange(nTab, aEditRange))
2476  {
2477  ScScenarioFlags nFlags;
2478  rDocument.GetScenarioFlags(nTab,nFlags);
2479  bIsEditable = !(nFlags & ScScenarioFlags::Protected);
2480  }
2481  }
2482  }
2483  if ( bIsEditable )
2484  {
2485  if (HasBlockMatrixFragment( nCol1, nRow1, nCol2, nRow2, bNoMatrixAtAll))
2486  {
2487  bIsEditable = false;
2488  if ( pOnlyNotBecauseOfMatrix )
2489  *pOnlyNotBecauseOfMatrix = true;
2490  }
2491  else if ( pOnlyNotBecauseOfMatrix )
2492  *pOnlyNotBecauseOfMatrix = false;
2493  }
2494  else if ( pOnlyNotBecauseOfMatrix )
2495  *pOnlyNotBecauseOfMatrix = false;
2496  return bIsEditable;
2497 }
2498 
2500  bool* pOnlyNotBecauseOfMatrix /* = NULL */ ) const
2501 {
2502  bool bIsEditable = true;
2503  if ( nLockCount )
2504  bIsEditable = false;
2505  else if ( IsProtected() && !rDocument.IsScenario(nTab) )
2506  {
2507  ScRangeList aRanges;
2508  rMark.FillRangeListWithMarks( &aRanges, false );
2509  bIsEditable = !HasAttribSelection( rMark, HasAttrFlags::Protected );
2510  if (!bIsEditable)
2511  {
2512  // An enhanced protection permission may override the attribute.
2513  if (pTabProtection)
2514  bIsEditable = pTabProtection->isSelectionEditable( aRanges);
2515  }
2516  if (bIsEditable)
2517  {
2518  // If Sheet is protected and cells are not protected then
2519  // check the active scenario protect flag if this area is
2520  // in the active scenario range.
2521  SCTAB nScenTab = nTab+1;
2522  while(rDocument.IsScenario(nScenTab) && bIsEditable)
2523  {
2524  if(rDocument.IsActiveScenario(nScenTab))
2525  {
2526  for (size_t i=0, nRange = aRanges.size(); (i < nRange) && bIsEditable; i++ )
2527  {
2528  const ScRange & rRange = aRanges[ i ];
2529  if(rDocument.HasScenarioRange(nScenTab, rRange))
2530  {
2531  ScScenarioFlags nFlags;
2532  rDocument.GetScenarioFlags(nScenTab,nFlags);
2533  bIsEditable = !((nFlags & ScScenarioFlags::Protected) && (nFlags & ScScenarioFlags::TwoWay));
2534  }
2535  }
2536  }
2537  nScenTab++;
2538  }
2539  }
2540  }
2541  else if (rDocument.IsScenario(nTab))
2542  {
2543  // Determine if the preceding sheet is protected
2544  SCTAB nActualTab = nTab;
2545  do
2546  {
2547  nActualTab--;
2548  }
2549  while(rDocument.IsScenario(nActualTab));
2550 
2551  if(rDocument.IsTabProtected(nActualTab))
2552  {
2553  ScRangeList aRanges;
2554  rMark.FillRangeListWithMarks( &aRanges, false );
2555  for (size_t i = 0, nRange = aRanges.size(); (i < nRange) && bIsEditable; i++)
2556  {
2557  const ScRange & rRange = aRanges[ i ];
2558  if(rDocument.HasScenarioRange(nTab, rRange))
2559  {
2560  ScScenarioFlags nFlags;
2561  rDocument.GetScenarioFlags(nTab,nFlags);
2562  bIsEditable = !(nFlags & ScScenarioFlags::Protected);
2563  }
2564  }
2565  }
2566  }
2567  if ( bIsEditable )
2568  {
2569  if ( HasSelectionMatrixFragment( rMark ) )
2570  {
2571  bIsEditable = false;
2572  if ( pOnlyNotBecauseOfMatrix )
2573  *pOnlyNotBecauseOfMatrix = true;
2574  }
2575  else if ( pOnlyNotBecauseOfMatrix )
2576  *pOnlyNotBecauseOfMatrix = false;
2577  }
2578  else if ( pOnlyNotBecauseOfMatrix )
2579  *pOnlyNotBecauseOfMatrix = false;
2580  return bIsEditable;
2581 }
2582 
2584 {
2585  ++nLockCount;
2586 }
2587 
2589 {
2590  if (nLockCount)
2591  --nLockCount;
2592  else
2593  {
2594  OSL_FAIL("UnlockTable without LockTable");
2595  }
2596 }
2597 
2598 void ScTable::MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, bool bDeep ) const
2599 {
2600  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2601 
2602  for (const sc::ColRowSpan & rSpan : aSpans)
2603  {
2604  for (SCCOLROW i = rSpan.mnStart; i <= rSpan.mnEnd; ++i)
2605  {
2606  CreateColumnIfNotExists(i).MergeSelectionPattern( rState, rMark, bDeep );
2607  }
2608  }
2609 }
2610 
2612  SCCOL nCol2, SCROW nRow2, bool bDeep ) const
2613 {
2614  nCol2 = ClampToAllocatedColumns(nCol2);
2615  for (SCCOL i=nCol1; i<=nCol2; i++)
2616  aCol[i].MergePatternArea( rState, nRow1, nRow2, bDeep );
2617 }
2618 
2619 void ScTable::MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags,
2620  SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const
2621 {
2622  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2623  {
2624  PutInOrder(nStartCol, nEndCol);
2625  PutInOrder(nStartRow, nEndRow);
2626  nEndCol = ClampToAllocatedColumns(nEndCol);
2627  for (SCCOL i=nStartCol; i<=nEndCol; i++)
2628  aCol[i].MergeBlockFrame( pLineOuter, pLineInner, rFlags,
2629  nStartRow, nEndRow, (i==nStartCol), nEndCol-i );
2630  }
2631 }
2632 
2633 void ScTable::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
2634  SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
2635 {
2636  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2637  {
2638  PutInOrder(nStartCol, nEndCol);
2639  PutInOrder(nStartRow, nEndRow);
2640  nEndCol = ClampToAllocatedColumns(nEndCol);
2641  for (SCCOL i=nStartCol; i<=nEndCol; i++)
2642  aCol[i].ApplyBlockFrame(rLineOuter, pLineInner,
2643  nStartRow, nEndRow, (i==nStartCol), nEndCol-i);
2644  }
2645 }
2646 
2647 void ScTable::ApplyPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr )
2648 {
2649  if (ValidColRow(nCol,nRow))
2650  CreateColumnIfNotExists(nCol).ApplyPattern( nRow, rAttr );
2651 }
2652 
2653 void ScTable::ApplyPatternArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2654  const ScPatternAttr& rAttr, ScEditDataArray* pDataArray,
2655  bool* const pIsChanged )
2656 {
2657  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2658  {
2659  PutInOrder(nStartCol, nEndCol);
2660  PutInOrder(nStartRow, nEndRow);
2661  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2662  CreateColumnIfNotExists(i).ApplyPatternArea(nStartRow, nEndRow, rAttr, pDataArray, pIsChanged);
2663  }
2664 }
2665 
2667  const ScPatternAttr& rPattern, SvNumFormatType nNewType )
2668 {
2669  SCCOL nEndCol = rRange.aEnd.Col();
2670  for ( SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; nCol++ )
2671  {
2672  aCol[nCol].ApplyPatternIfNumberformatIncompatible( rRange, rPattern, nNewType );
2673  }
2674 }
2675 
2676 void ScTable::AddCondFormatData( const ScRangeList& rRangeList, sal_uInt32 nIndex )
2677 {
2678  size_t n = rRangeList.size();
2679  for(size_t i = 0; i < n; ++i)
2680  {
2681  const ScRange & rRange = rRangeList[i];
2682  SCCOL nColStart = rRange.aStart.Col();
2683  SCCOL nColEnd = rRange.aEnd.Col();
2684  SCROW nRowStart = rRange.aStart.Row();
2685  SCROW nRowEnd = rRange.aEnd.Row();
2686  for(SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
2687  {
2688  CreateColumnIfNotExists(nCol).AddCondFormat(nRowStart, nRowEnd, nIndex);
2689  }
2690  }
2691 }
2692 
2693 void ScTable::RemoveCondFormatData( const ScRangeList& rRangeList, sal_uInt32 nIndex )
2694 {
2695  size_t n = rRangeList.size();
2696  for(size_t i = 0; i < n; ++i)
2697  {
2698  const ScRange & rRange = rRangeList[i];
2699  SCCOL nColStart = rRange.aStart.Col();
2700  SCCOL nColEnd = ClampToAllocatedColumns(rRange.aEnd.Col());
2701  SCROW nRowStart = rRange.aStart.Row();
2702  SCROW nRowEnd = rRange.aEnd.Row();
2703  for(SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
2704  {
2705  aCol[nCol].RemoveCondFormat(nRowStart, nRowEnd, nIndex);
2706  }
2707  }
2708 }
2709 
2710 void ScTable::SetPatternAreaCondFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow,
2711  const ScPatternAttr& rAttr, const ScCondFormatIndexes& rCondFormatIndexes )
2712 {
2713  aCol[nCol].SetPatternArea( nStartRow, nEndRow, rAttr);
2714 
2715  for (const auto& rIndex : rCondFormatIndexes)
2716  {
2717  ScConditionalFormat* pCondFormat = mpCondFormatList->GetFormat(rIndex);
2718  if (pCondFormat)
2719  {
2720  ScRangeList aRange = pCondFormat->GetRange();
2721  aRange.Join( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab));
2722  pCondFormat->SetRange(aRange);
2723  }
2724  }
2725 }
2726 
2727 void ScTable::ApplyStyle( SCCOL nCol, SCROW nRow, const ScStyleSheet* rStyle )
2728 {
2729  if (ValidColRow(nCol,nRow))
2730  // If column not exists then we need to create it
2731  CreateColumnIfNotExists( nCol ).ApplyStyle( nRow, rStyle );
2732 }
2733 
2734 void ScTable::ApplyStyleArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScStyleSheet& rStyle )
2735 {
2736  if (!(ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow)))
2737  return;
2738 
2739  PutInOrder(nStartCol, nEndCol);
2740  PutInOrder(nStartRow, nEndRow);
2741  if ( nEndCol == rDocument.MaxCol() )
2742  {
2743  if ( nStartCol < aCol.size() )
2744  {
2745  // If we would like set all columns to specific style, then change only default style for not existing columns
2746  nEndCol = aCol.size() - 1;
2747  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2748  aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
2749  aDefaultColAttrArray.ApplyStyleArea(nStartRow, nEndRow, rStyle );
2750  }
2751  else
2752  {
2753  CreateColumnIfNotExists( nStartCol - 1 );
2754  aDefaultColAttrArray.ApplyStyleArea(nStartRow, nEndRow, rStyle );
2755  }
2756  }
2757  else
2758  {
2759  CreateColumnIfNotExists( nEndCol );
2760  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2761  aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
2762  }
2763 }
2764 
2765 void ScTable::ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark)
2766 {
2767  for (SCCOL i=0; i < aCol.size(); i++)
2768  aCol[i].ApplySelectionStyle( rStyle, rMark );
2769 }
2770 
2772  const ::editeng::SvxBorderLine* pLine, bool bColorOnly )
2773 {
2774  if ( bColorOnly && !pLine )
2775  return;
2776 
2777  for (SCCOL i=0; i < aCol.size(); i++)
2778  aCol[i].ApplySelectionLineStyle( rMark, pLine, bColorOnly );
2779 }
2780 
2781 const ScStyleSheet* ScTable::GetStyle( SCCOL nCol, SCROW nRow ) const
2782 {
2783  if ( !ValidColRow( nCol, nRow ) )
2784  return nullptr;
2785  if ( nCol < aCol.size() )
2786  return aCol[nCol].GetStyle( nRow );
2787  else
2788  return aDefaultColAttrArray.GetPattern( nRow )->GetStyleSheet();
2789 }
2790 
2791 const ScStyleSheet* ScTable::GetSelectionStyle( const ScMarkData& rMark, bool& rFound ) const
2792 {
2793  rFound = false;
2794 
2795  bool bEqual = true;
2796  bool bColFound;
2797 
2798  const ScStyleSheet* pStyle = nullptr;
2799  const ScStyleSheet* pNewStyle;
2800 
2801  for (SCCOL i=0; i < aCol.size() && bEqual; i++)
2802  if (rMark.HasMultiMarks(i))
2803  {
2804  pNewStyle = aCol[i].GetSelectionStyle( rMark, bColFound );
2805  if (bColFound)
2806  {
2807  rFound = true;
2808  if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
2809  bEqual = false;
2810  pStyle = pNewStyle;
2811  }
2812  }
2813 
2814  return bEqual ? pStyle : nullptr;
2815 }
2816 
2817 const ScStyleSheet* ScTable::GetAreaStyle( bool& rFound, SCCOL nCol1, SCROW nRow1,
2818  SCCOL nCol2, SCROW nRow2 ) const
2819 {
2820  rFound = false;
2821 
2822  bool bEqual = true;
2823  bool bColFound;
2824 
2825  const ScStyleSheet* pStyle = nullptr;
2826  const ScStyleSheet* pNewStyle;
2827  nCol2 = ClampToAllocatedColumns(nCol2);
2828  for (SCCOL i=nCol1; i<=nCol2 && bEqual; i++)
2829  {
2830  pNewStyle = aCol[i].GetAreaStyle(bColFound, nRow1, nRow2);
2831  if (bColFound)
2832  {
2833  rFound = true;
2834  if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
2835  bEqual = false;
2836  pStyle = pNewStyle;
2837  }
2838  }
2839 
2840  return bEqual ? pStyle : nullptr;
2841 }
2842 
2843 bool ScTable::IsStyleSheetUsed( const ScStyleSheet& rStyle ) const
2844 {
2845  bool bIsUsed = false;
2846 
2847  for ( SCCOL i=0; i < aCol.size(); i++ )
2848  {
2849  if ( aCol[i].IsStyleSheetUsed( rStyle ) )
2850  {
2851  bIsUsed = true;
2852  }
2853  }
2854 
2855  return bIsUsed;
2856 }
2857 
2858 void ScTable::StyleSheetChanged( const SfxStyleSheetBase* pStyleSheet, bool bRemoved,
2859  OutputDevice* pDev,
2860  double nPPTX, double nPPTY,
2861  const Fraction& rZoomX, const Fraction& rZoomY )
2862 {
2863  ScFlatBoolRowSegments aUsedRows(rDocument.MaxRow());
2864  for (SCCOL i = 0; i < aCol.size(); ++i)
2865  aCol[i].FindStyleSheet(pStyleSheet, aUsedRows, bRemoved);
2866 
2867  sc::RowHeightContext aCxt(rDocument.MaxRow(), nPPTX, nPPTY, rZoomX, rZoomY, pDev);
2868  SCROW nRow = 0;
2869  while (nRow <= rDocument.MaxRow())
2870  {
2872  if (!aUsedRows.getRangeData(nRow, aData))
2873  // search failed!
2874  return;
2875 
2876  SCROW nEndRow = aData.mnRow2;
2877  if (aData.mbValue)
2878  SetOptimalHeight(aCxt, nRow, nEndRow, true);
2879 
2880  nRow = nEndRow + 1;
2881  }
2882 }
2883 
2884 bool ScTable::ApplyFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2885  ScMF nFlags )
2886 {
2887  bool bChanged = false;
2888  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2889  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2890  bChanged |= CreateColumnIfNotExists(i).ApplyFlags(nStartRow, nEndRow, nFlags);
2891  return bChanged;
2892 }
2893 
2894 bool ScTable::RemoveFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2895  ScMF nFlags )
2896 {
2897  if (!ValidColRow(nStartCol, nStartRow) || !ValidColRow(nEndCol, nEndRow))
2898  return false;
2899  bool bChanged = false;
2900  nEndCol = ClampToAllocatedColumns(nEndCol);
2901  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2902  bChanged |= aCol[i].RemoveFlags(nStartRow, nEndRow, nFlags);
2903  return bChanged;
2904 }
2905 
2906 void ScTable::SetPattern( const ScAddress& rPos, const ScPatternAttr& rAttr )
2907 {
2908  if (ValidColRow(rPos.Col(),rPos.Row()))
2909  aCol[rPos.Col()].SetPattern( rPos.Row(), rAttr );
2910 }
2911 
2912 const ScPatternAttr* ScTable::SetPattern( SCCOL nCol, SCROW nRow, std::unique_ptr<ScPatternAttr> pAttr )
2913 {
2914  if (ValidColRow(nCol,nRow))
2915  return aCol[nCol].SetPattern( nRow, std::move(pAttr) );
2916  return nullptr;
2917 }
2918 
2919 void ScTable::SetPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr )
2920 {
2921  if (ValidColRow(nCol,nRow))
2922  aCol[nCol].SetPattern( nRow, rAttr );
2923 }
2924 
2925 void ScTable::ApplyAttr( SCCOL nCol, SCROW nRow, const SfxPoolItem& rAttr )
2926 {
2927  if (ValidColRow(nCol,nRow))
2928  CreateColumnIfNotExists(nCol).ApplyAttr( nRow, rAttr );
2929 }
2930 
2932  ScEditDataArray* pDataArray, bool* const pIsChanged )
2933 {
2934  for (SCCOL i=0; i < aCol.size(); i++)
2935  aCol[i].ApplySelectionCache( pCache, rMark, pDataArray, pIsChanged );
2936 }
2937 
2938 void ScTable::ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark )
2939 {
2940  for (SCCOL i=0; i < aCol.size(); i++)
2941  aCol[i].ChangeSelectionIndent( bIncrement, rMark );
2942 }
2943 
2944 void ScTable::ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark )
2945 {
2946  for (SCCOL i=0; i < aCol.size(); i++)
2947  aCol[i].ClearSelectionItems( pWhich, rMark );
2948 }
2949 
2950 // Column widths / Row heights
2951 
2952 void ScTable::SetColWidth( SCCOL nCol, sal_uInt16 nNewWidth )
2953 {
2954  if (ValidCol(nCol) && mpColWidth)
2955  {
2956  if (!nNewWidth)
2957  {
2958  nNewWidth = STD_COL_WIDTH;
2959  }
2960 
2961  if ( nNewWidth != mpColWidth->GetValue(nCol) )
2962  {
2963  mpColWidth->SetValue(nCol, nNewWidth);
2965  }
2966  }
2967  else
2968  {
2969  OSL_FAIL("Invalid column number or no widths");
2970  }
2971 }
2972 
2973 void ScTable::SetColWidthOnly( SCCOL nCol, sal_uInt16 nNewWidth )
2974 {
2975  if (!ValidCol(nCol) || !mpColWidth)
2976  return;
2977 
2978  if (!nNewWidth)
2979  nNewWidth = STD_COL_WIDTH;
2980 
2981  if (nNewWidth != mpColWidth->GetValue(nCol))
2982  mpColWidth->SetValue(nCol, nNewWidth);
2983 }
2984 
2985 void ScTable::SetRowHeight( SCROW nRow, sal_uInt16 nNewHeight )
2986 {
2987  if (ValidRow(nRow) && mpRowHeights)
2988  {
2989  if (!nNewHeight)
2990  {
2991  OSL_FAIL("SetRowHeight: Row height zero");
2992  nNewHeight = ScGlobal::nStdRowHeight;
2993  }
2994 
2995  sal_uInt16 nOldHeight = mpRowHeights->getValue(nRow);
2996  if ( nNewHeight != nOldHeight )
2997  {
2998  mpRowHeights->setValue(nRow, nRow, nNewHeight);
3000  }
3001  }
3002  else
3003  {
3004  OSL_FAIL("Invalid row number or no heights");
3005  }
3006 }
3007 
3008 namespace {
3009 
3014 bool lcl_pixelSizeChanged(
3015  ScFlatUInt16RowSegments& rRowHeights, SCROW nStartRow, SCROW nEndRow,
3016  sal_uInt16 nNewHeight, double nPPTY, bool bApi)
3017 {
3018  tools::Long nNewPix = static_cast<tools::Long>(nNewHeight * nPPTY);
3019 
3020  ScFlatUInt16RowSegments::ForwardIterator aFwdIter(rRowHeights);
3021  for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
3022  {
3023  sal_uInt16 nHeight;
3024  if (!aFwdIter.getValue(nRow, nHeight))
3025  break;
3026 
3027  if (nHeight != nNewHeight)
3028  {
3029  tools::Long nOldPix = static_cast<tools::Long>(nHeight * nPPTY);
3030 
3031  // Heuristic: Don't bother when handling interactive input, if changing just one row and
3032  // the height will shrink.
3033  bool bChanged = (nNewPix != nOldPix) && (bApi || nEndRow - nStartRow > 0 || nNewPix > nOldPix);
3034  if (bChanged)
3035  return true;
3036  }
3037 
3038  // Skip ahead to the last position of the current range.
3039  nRow = aFwdIter.getLastPos();
3040  }
3041  return false;
3042 }
3043 
3044 }
3045 
3046 bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight,
3047  double nPPTY, bool bApi )
3048 {
3049  bool bChanged = false;
3050  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3051  {
3052  if (!nNewHeight)
3053  {
3054  OSL_FAIL("SetRowHeight: Row height zero");
3055  nNewHeight = ScGlobal::nStdRowHeight;
3056  }
3057 
3058  bool bSingle = false; // true = process every row for its own
3059  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
3060  if (pDrawLayer)
3061  if (pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ))
3062  bSingle = true;
3063 
3064  if (bSingle)
3065  {
3067  if (mpRowHeights->getRangeData(nStartRow, aData) &&
3068  nNewHeight == aData.mnValue && nEndRow <= aData.mnRow2)
3069  {
3070  bSingle = false; // no difference in this range
3071  }
3072  }
3073 
3074  // No idea why 20 is used here
3075  if (!bSingle || nEndRow - nStartRow < 20)
3076  {
3077  bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, nNewHeight, nPPTY, bApi);
3078  if (bChanged)
3079  mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
3080  }
3081  else
3082  {
3083  SCROW nMid = (nStartRow + nEndRow) / 2;
3084  // No idea why nPPTY is ignored in these recursive calls and instead 1.0 is used
3085  if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0, bApi))
3086  bChanged = true;
3087  if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0, bApi))
3088  bChanged = true;
3089  }
3090 
3091  if (bChanged)
3093  }
3094  else
3095  {
3096  OSL_FAIL("Invalid row number or no heights");
3097  }
3098 
3099  return bChanged;
3100 }
3101 
3102 void ScTable::SetRowHeightOnly( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight )
3103 {
3104  if (!ValidRow(nStartRow) || !ValidRow(nEndRow) || !mpRowHeights)
3105  return;
3106 
3107  if (!nNewHeight)
3108  nNewHeight = ScGlobal::nStdRowHeight;
3109 
3110  mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
3111 }
3112 
3113 void ScTable::SetManualHeight( SCROW nStartRow, SCROW nEndRow, bool bManual )
3114 {
3115  if (ValidRow(nStartRow) && ValidRow(nEndRow) && pRowFlags)
3116  {
3117  if (bManual)
3118  pRowFlags->OrValue( nStartRow, nEndRow, CRFlags::ManualSize);
3119  else
3120  pRowFlags->AndValue( nStartRow, nEndRow, ~CRFlags::ManualSize);
3121  }
3122  else
3123  {
3124  OSL_FAIL("Invalid row number or no column flags");
3125  }
3126 }
3127 
3128 sal_uInt16 ScTable::GetColWidth( SCCOL nCol, bool bHiddenAsZero ) const
3129 {
3130  OSL_ENSURE(ValidCol(nCol),"wrong column number");
3131 
3132  if (ValidCol(nCol) && mpColFlags && mpColWidth)
3133  {
3134  if (bHiddenAsZero && ColHidden(nCol))
3135  return 0;
3136  else
3137  return mpColWidth->GetValue(nCol);
3138  }
3139  else
3140  return sal_uInt16(STD_COL_WIDTH);
3141 }
3142 
3143 sal_uLong ScTable::GetColWidth( SCCOL nStartCol, SCCOL nEndCol ) const
3144 {
3145  if (!ValidCol(nStartCol) || !ValidCol(nEndCol) || nStartCol > nEndCol)
3146  return 0;
3147 
3148  sal_uLong nW = 0;
3149  bool bHidden = false;
3150  SCCOL nLastHiddenCol = -1;
3151  auto colWidthIt = mpColWidth->begin() + nStartCol;
3152  for (SCCOL nCol = nStartCol; nCol <= nEndCol; (++nCol <= nEndCol) ? ++colWidthIt : (void)false)
3153  {
3154  if (nCol > nLastHiddenCol)
3155  bHidden = ColHidden(nCol, nullptr, &nLastHiddenCol);
3156 
3157  if (bHidden)
3158  continue;
3159 
3160  nW += *colWidthIt;
3161  }
3162  return nW;
3163 }
3164 
3165 sal_uInt16 ScTable::GetOriginalWidth( SCCOL nCol ) const // always the set value
3166 {
3167  OSL_ENSURE(ValidCol(nCol),"wrong column number");
3168 
3169  if (ValidCol(nCol) && mpColWidth)
3170  return mpColWidth->GetValue(nCol);
3171  else
3172  return sal_uInt16(STD_COL_WIDTH);
3173 }
3174 
3175 sal_uInt16 ScTable::GetCommonWidth( SCCOL nEndCol ) const
3176 {
3177  // get the width that is used in the largest continuous column range (up to nEndCol)
3178 
3179  if ( !ValidCol(nEndCol) )
3180  {
3181  OSL_FAIL("wrong column");
3182  nEndCol = rDocument.MaxCol();
3183  }
3184 
3185  sal_uInt16 nMaxWidth = 0;
3186  sal_uInt16 nMaxCount = 0;
3187  SCCOL nRangeStart = 0;
3188  while ( nRangeStart <= nEndCol )
3189  {
3190  // skip hidden columns
3191  while ( nRangeStart <= nEndCol && ColHidden(nRangeStart) )
3192  ++nRangeStart;
3193  if ( nRangeStart <= nEndCol )
3194  {
3195  sal_uInt16 nThisCount = 0;
3196  auto colWidthIt = mpColWidth->begin() + nRangeStart;
3197  sal_uInt16 nThisWidth = *colWidthIt;
3198  SCCOL nRangeEnd = nRangeStart;
3199  while ( nRangeEnd <= nEndCol && *colWidthIt == nThisWidth )
3200  {
3201  ++nThisCount;
3202  ++nRangeEnd;
3203  ++colWidthIt;
3204 
3205  // skip hidden columns
3206  while ( nRangeEnd <= nEndCol && ColHidden(nRangeEnd) )
3207  {
3208  ++nRangeEnd;
3209  ++colWidthIt;
3210  }
3211  }
3212 
3213  if ( nThisCount > nMaxCount )
3214  {
3215  nMaxCount = nThisCount;
3216  nMaxWidth = nThisWidth;
3217  }
3218 
3219  nRangeStart = nRangeEnd; // next range
3220  }
3221  }
3222 
3223  return nMaxWidth;
3224 }
3225 
3226 sal_uInt16 ScTable::GetRowHeight( SCROW nRow, SCROW* pStartRow, SCROW* pEndRow, bool bHiddenAsZero ) const
3227 {
3228  SAL_WARN_IF(!ValidRow(nRow), "sc", "Invalid row number " << nRow);
3229 
3230  if (ValidRow(nRow) && mpRowHeights)
3231  {
3232  if (bHiddenAsZero && RowHidden( nRow, pStartRow, pEndRow))
3233  return 0;
3234  else
3235  {
3237  if (!mpRowHeights->getRangeData(nRow, aData))
3238  {
3239  if (pStartRow)
3240  *pStartRow = nRow;
3241  if (pEndRow)
3242  *pEndRow = nRow;
3243  // TODO: What should we return in case the search fails?
3244  return 0;
3245  }
3246 
3247  // If bHiddenAsZero, pStartRow and pEndRow were initialized to
3248  // boundaries of a non-hidden segment. Assume that the previous and
3249  // next segment are hidden then and limit the current height
3250  // segment.
3251  if (pStartRow)
3252  *pStartRow = (bHiddenAsZero ? std::max( *pStartRow, aData.mnRow1) : aData.mnRow1);
3253  if (pEndRow)
3254  *pEndRow = (bHiddenAsZero ? std::min( *pEndRow, aData.mnRow2) : aData.mnRow2);
3255  return aData.mnValue;
3256  }
3257  }
3258  else
3259  {
3260  if (pStartRow)
3261  *pStartRow = nRow;
3262  if (pEndRow)
3263  *pEndRow = nRow;
3264  return ScGlobal::nStdRowHeight;
3265  }
3266 }
3267 
3268 sal_uLong ScTable::GetRowHeight( SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZero ) const
3269 {
3270  OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
3271 
3272  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3273  {
3274  sal_uLong nHeight = 0;
3275  SCROW nRow = nStartRow;
3276  while (nRow <= nEndRow)
3277  {
3278  SCROW nLastRow = -1;
3279  if (!( ( RowHidden(nRow, nullptr, &nLastRow) ) && bHiddenAsZero ) )
3280  {
3281  if (nLastRow > nEndRow)
3282  nLastRow = nEndRow;
3283  nHeight += mpRowHeights->getSumValue(nRow, nLastRow);
3284  }
3285  nRow = nLastRow + 1;
3286  }
3287  return nHeight;
3288  }
3289  else
3290  return (nEndRow - nStartRow + 1) * static_cast<sal_uLong>(ScGlobal::nStdRowHeight);
3291 }
3292 
3293 sal_uLong ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong* pnMaxHeight ) const
3294 {
3295  OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
3296 
3297  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3298  {
3299  sal_uLong nHeight = 0;
3300  SCROW nRow = nStartRow;
3301  while (nRow <= nEndRow)
3302  {
3303  SCROW nLastRow = -1;
3304  if (!RowHidden(nRow, nullptr, &nLastRow))
3305  {
3306  if (nLastRow > nEndRow)
3307  nLastRow = nEndRow;
3308 
3309  // #i117315# can't use getSumValue, because individual values must be rounded
3311  while (nRow <= nLastRow)
3312  {
3313  sal_uInt16 nRowVal;
3314  if (!aSegmentIter.getValue(nRow, nRowVal))
3315  return nHeight; // shouldn't happen
3316 
3317  SCROW nSegmentEnd = std::min( nLastRow, aSegmentIter.getLastPos() );
3318 
3319  // round-down a single height value, multiply resulting (pixel) values
3320  const sal_uLong nOneHeight = static_cast<sal_uLong>( nRowVal * fScale );
3321  // sometimes scaling results in zero height
3322  if (nOneHeight)
3323  {
3324  SCROW nRowsInSegment = nSegmentEnd + 1 - nRow;
3325  if (pnMaxHeight)
3326  {
3327  nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
3328  nHeight += nOneHeight * nRowsInSegment;
3329  if (nHeight > *pnMaxHeight)
3330  return nHeight;
3331  }
3332  else
3333  nHeight += nOneHeight * nRowsInSegment;
3334  }
3335 
3336  nRow = nSegmentEnd + 1;
3337  }
3338  }
3339  nRow = nLastRow + 1;
3340  }
3341  return nHeight;
3342  }
3343  else
3344  {
3345  const sal_uLong nOneHeight = static_cast<sal_uLong>(ScGlobal::nStdRowHeight * fScale);
3346  SCROW nRowsInSegment = nEndRow - nStartRow + 1;
3347  if (pnMaxHeight)
3348  {
3349  nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
3350  return nOneHeight * nRowsInSegment;
3351  }
3352  else
3353  return static_cast<sal_uLong>(nRowsInSegment * nOneHeight);
3354  }
3355 }
3356 
3357 sal_uInt16 ScTable::GetOriginalHeight( SCROW nRow ) const // non-0 even if hidden
3358 {
3359  OSL_ENSURE(ValidRow(nRow),"wrong row number");
3360 
3361  if (ValidRow(nRow) && mpRowHeights)
3362  return mpRowHeights->getValue(nRow);
3363  else
3364  return ScGlobal::nStdRowHeight;
3365 }
3366 
3367 // Column/Row -Flags
3368 
3370 {
3371  if (!ValidRow(nRow))
3372  return 0;
3373 
3374  SCROW nLastRow = -1;
3375  if (!RowHidden(nRow, nullptr, &nLastRow) || !ValidRow(nLastRow))
3376  return 0;
3377 
3378  return nLastRow - nRow + 1;
3379 }
3380 
3381 //TODO: combine ShowRows / DBShowRows
3382 
3383 void ScTable::ShowCol(SCCOL nCol, bool bShow)
3384 {
3385  if (ValidCol(nCol))
3386  {
3387  bool bWasVis = !ColHidden(nCol);
3388  if (bWasVis != bShow)
3389  {
3390  SetColHidden(nCol, nCol, !bShow);
3391 
3393  if ( pCharts )
3394  pCharts->SetRangeDirty(ScRange( nCol, 0, nTab, nCol, rDocument.MaxRow(), nTab ));
3395  }
3396  }
3397  else
3398  {
3399  OSL_FAIL("Invalid column number or no flags");
3400  }
3401 }
3402 
3403 void ScTable::ShowRow(SCROW nRow, bool bShow)
3404 {
3405  if (ValidRow(nRow) && pRowFlags)
3406  {
3407  bool bWasVis = !RowHidden(nRow);
3408  if (bWasVis != bShow)
3409  {
3410  SetRowHidden(nRow, nRow, !bShow);
3411  if (bShow)
3412  SetRowFiltered(nRow, nRow, false);
3414  if ( pCharts )
3415  pCharts->SetRangeDirty(ScRange( 0, nRow, nTab, rDocument.MaxCol(), nRow, nTab ));
3416 
3418  }
3419  }
3420  else
3421  {
3422  OSL_FAIL("Invalid row number or no flags");
3423  }
3424 }
3425 
3426 void ScTable::DBShowRow(SCROW nRow, bool bShow)
3427 {
3428  if (ValidRow(nRow) && pRowFlags)
3429  {
3430  // Always set filter flag; unchanged when Hidden
3431  bool bChanged = SetRowHidden(nRow, nRow, !bShow);
3432  SetRowFiltered(nRow, nRow, !bShow);
3433 
3434  if (bChanged)
3435  {
3437  if ( pCharts )
3438  pCharts->SetRangeDirty(ScRange( 0, nRow, nTab, rDocument.MaxCol(), nRow, nTab ));
3439 
3440  if (pOutlineTable)
3441  UpdateOutlineRow( nRow, nRow, bShow );
3442 
3444  }
3445  }
3446  else
3447  {
3448  OSL_FAIL("Invalid row number or no flags");
3449  }
3450 }
3451 
3452 void ScTable::DBShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
3453 {
3454  SCROW nStartRow = nRow1;
3455  while (nStartRow <= nRow2)
3456  {
3457  SCROW nEndRow = -1;
3458  bool bWasVis = !RowHiddenLeaf(nStartRow, nullptr, &nEndRow);
3459  if (nEndRow > nRow2)
3460  nEndRow = nRow2;
3461 
3462  bool bChanged = ( bWasVis != bShow );
3463 
3464  SetRowHidden(nStartRow, nEndRow, !bShow);
3465  SetRowFiltered(nStartRow, nEndRow, !bShow);
3466 
3467  if ( bChanged )
3468  {
3470  if ( pCharts )
3471  pCharts->SetRangeDirty(ScRange( 0, nStartRow, nTab, rDocument.MaxCol(), nEndRow, nTab ));
3472  }
3473 
3474  nStartRow = nEndRow + 1;
3475  }
3476 
3477  // #i12341# For Show/Hide rows, the outlines are updated separately from the outside.
3478  // For filtering, the changes aren't visible to the caller, so UpdateOutlineRow has
3479  // to be done here.
3480  if (pOutlineTable)
3481  UpdateOutlineRow( nRow1, nRow2, bShow );
3482 }
3483 
3484 void ScTable::ShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
3485 {
3486  SCROW nStartRow = nRow1;
3487 
3488  // #i116164# if there are no drawing objects within the row range, a single HeightChanged call is enough
3489  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
3490  bool bHasObjects = pDrawLayer && pDrawLayer->HasObjectsInRows( nTab, nRow1, nRow2 );
3491 
3492  while (nStartRow <= nRow2)
3493  {
3494  SCROW nEndRow = -1;
3495  bool bWasVis = !RowHiddenLeaf(nStartRow, nullptr, &nEndRow);
3496  if (nEndRow > nRow2)
3497  nEndRow = nRow2;
3498 
3499  bool bChanged = ( bWasVis != bShow );
3500 
3501  SetRowHidden(nStartRow, nEndRow, !bShow);
3502  if (bShow)
3503  SetRowFiltered(nStartRow, nEndRow, false);
3504 
3505  if ( bChanged )
3506  {
3508  if ( pCharts )
3509  pCharts->SetRangeDirty(ScRange( 0, nStartRow, nTab, rDocument.MaxCol(), nEndRow, nTab ));
3510 
3512  }
3513 
3514  nStartRow = nEndRow + 1;
3515  }
3516 
3517  if ( !bHasObjects )
3518  {
3519  // #i116164# set the flags for the whole range at once
3520  SetRowHidden(nRow1, nRow2, !bShow);
3521  if (bShow)
3522  SetRowFiltered(nRow1, nRow2, false);
3523  }
3524 }
3525 
3526 bool ScTable::IsDataFiltered(SCCOL nColStart, SCROW nRowStart, SCCOL nColEnd, SCROW nRowEnd) const
3527 {
3528  for (SCROW i = nRowStart; i <= nRowEnd; ++i)
3529  {
3530  if (RowHidden(i))
3531  return true;
3532  }
3533  for (SCCOL i = nColStart; i <= nColEnd; ++i)
3534  {
3535  if (ColHidden(i))
3536  return true;
3537  }
3538  return false;
3539 }
3540 
3541 bool ScTable::IsDataFiltered(const ScRange& rRange) const
3542 {
3543  return IsDataFiltered(rRange.aStart.Col(), rRange.aStart.Row(),
3544  rRange.aEnd.Col(), rRange.aEnd.Row());
3545 }
3546 
3547 void ScTable::SetRowFlags( SCROW nRow, CRFlags nNewFlags )
3548 {
3549  if (ValidRow(nRow) && pRowFlags)
3550  pRowFlags->SetValue( nRow, nNewFlags);
3551  else
3552  {
3553  OSL_FAIL("Invalid row number or no flags");
3554  }
3555 }
3556 
3557 void ScTable::SetRowFlags( SCROW nStartRow, SCROW nEndRow, CRFlags nNewFlags )
3558 {
3559  if (ValidRow(nStartRow) && ValidRow(nEndRow) && pRowFlags)
3560  pRowFlags->SetValue( nStartRow, nEndRow, nNewFlags);
3561  else
3562  {
3563  OSL_FAIL("Invalid row number(s) or no flags");
3564  }
3565 }
3566 
3568 {
3569  if (ValidCol(nCol) && mpColFlags)
3570  return mpColFlags->GetValue(nCol);
3571  else
3572  return CRFlags::NONE;
3573 }
3574 
3576 {
3577  if (ValidRow(nRow) && pRowFlags)
3578  return pRowFlags->GetValue(nRow);
3579  else
3580  return CRFlags::NONE;
3581 }
3582 
3584 {
3585  SCROW nLastFound = 0;
3586  if (pRowFlags)
3587  {
3588  SCROW nRow = pRowFlags->GetLastAnyBitAccess( CRFlags::All );
3589  if (ValidRow(nRow))
3590  nLastFound = nRow;
3591  }
3592 
3593  if (!maRowManualBreaks.empty())
3594  nLastFound = ::std::max(nLastFound, *maRowManualBreaks.rbegin());
3595 
3596  if (mpHiddenRows)
3597  {
3598  SCROW nRow = mpHiddenRows->findLastTrue();
3599  if (ValidRow(nRow))
3600  nLastFound = ::std::max(nLastFound, nRow);
3601  }
3602 
3603  if (mpFilteredRows)
3604  {
3605  SCROW nRow = mpFilteredRows->findLastTrue();
3606  if (ValidRow(nRow))
3607  nLastFound = ::std::max(nLastFound, nRow);
3608  }
3609 
3610  return nLastFound;
3611 }
3612 
3614 {
3615  if ( !mpColFlags )
3616  return 0;
3617 
3618  SCCOL nLastFound = 0;
3619  const auto nColSize = aCol.size();
3620  auto colWidthIt = mpColWidth->begin() + 1;
3621  for (SCCOL nCol = 1; nCol < nColSize; (++nCol < nColSize) ? ++colWidthIt : (void)false)
3622  if ((mpColFlags->GetValue(nCol) & CRFlags::All) || (*colWidthIt != STD_COL_WIDTH))
3623  nLastFound = nCol;
3624 
3625  return nLastFound;
3626 }
3627 
3629 {
3630  if ( !pRowFlags )
3631  return 0;
3632 
3633  SCROW nLastFlags = GetLastFlaggedRow();
3634 
3635  // Find the last row position where the height is NOT the standard row
3636  // height.
3637  // KOHEI: Test this to make sure it does what it's supposed to.
3638  SCROW nLastHeight = mpRowHeights->findLastTrue(ScGlobal::nStdRowHeight);
3639  if (!ValidRow(nLastHeight))
3640  nLastHeight = 0;
3641 
3642  return std::max( nLastFlags, nLastHeight);
3643 }
3644 
3645 bool ScTable::UpdateOutlineCol( SCCOL nStartCol, SCCOL nEndCol, bool bShow )
3646 {
3647  if (pOutlineTable && mpColFlags)
3648  {
3649  return pOutlineTable->GetColArray().ManualAction( nStartCol, nEndCol, bShow, *this, true );
3650  }
3651  else
3652  return false;
3653 }
3654 
3655 bool ScTable::UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, bool bShow )
3656 {
3657  if (pOutlineTable && pRowFlags)
3658  return pOutlineTable->GetRowArray().ManualAction( nStartRow, nEndRow, bShow, *this, false );
3659  else
3660  return false;
3661 }
3662 
3663 void ScTable::ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
3664 {
3665  // Column-wise expansion
3666 
3667  while (rX1 > 0 && ColHidden(rX1-1))
3668  --rX1;
3669 
3670  while (rX2 < rDocument.MaxCol() && ColHidden(rX2+1))
3671  ++rX2;
3672 
3673  // Row-wise expansion
3674 
3675  if (rY1 > 0)
3676  {
3678  if (mpHiddenRows->getRangeData(rY1-1, aData) && aData.mbValue)
3679  {
3680  SCROW nStartRow = aData.mnRow1;
3681  if (ValidRow(nStartRow))
3682  rY1 = nStartRow;
3683  }
3684  }
3685  if (rY2 < rDocument.MaxRow())
3686  {
3687  SCROW nEndRow = -1;
3688  if (RowHidden(rY2+1, nullptr, &nEndRow) && ValidRow(nEndRow))
3689  rY2 = nEndRow;
3690  }
3691 }
3692 
3693 void ScTable::StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
3694 {
3695  while ( rX2>rX1 && ColHidden(rX2) )
3696  --rX2;
3697  while ( rX2>rX1 && ColHidden(rX1) )
3698  ++rX1;
3699 
3700  if (rY1 < rY2)
3701  {
3703  if (mpHiddenRows->getRangeData(rY2, aData) && aData.mbValue)
3704  {
3705  SCROW nStartRow = aData.mnRow1;
3706  if (ValidRow(nStartRow) && nStartRow >= rY1)
3707  rY2 = nStartRow;
3708  }
3709  }
3710 
3711  if (rY1 < rY2)
3712  {
3713  SCROW nEndRow = -1;
3714  if (RowHidden(rY1, nullptr, &nEndRow) && ValidRow(nEndRow) && nEndRow <= rY2)
3715  rY1 = nEndRow;
3716  }
3717 }
3718 
3719 // Auto-Outline
3720 
3721 template< typename T >
3722 static short DiffSign( T a, T b )
3723 {
3724  return (a<b) ? -1 :
3725  (a>b) ? 1 : 0;
3726 }
3727 
3728 namespace {
3729 
3730 class OutlineArrayFinder
3731 {
3732  ScRange maRef;
3733  SCCOL mnCol;
3734  SCTAB mnTab;
3736  bool mbSizeChanged;
3737 
3738 public:
3739  OutlineArrayFinder(const ScRange& rRef, SCCOL nCol, SCTAB nTab, ScOutlineArray* pArray, bool bSizeChanged) :
3740  maRef(rRef), mnCol(nCol), mnTab(nTab), mpArray(pArray),
3741  mbSizeChanged(bSizeChanged) {}
3742 
3743  bool operator() (size_t nRow, const ScFormulaCell* pCell)
3744  {
3745  SCROW nRow2 = static_cast<SCROW>(nRow);
3746 
3747  if (!pCell->HasRefListExpressibleAsOneReference(maRef))
3748  return false;
3749 
3750  if (maRef.aStart.Row() != nRow2 || maRef.aEnd.Row() != nRow2 ||
3751  maRef.aStart.Tab() != mnTab || maRef.aEnd.Tab() != mnTab)
3752  return false;
3753 
3754  if (DiffSign(maRef.aStart.Col(), mnCol) != DiffSign(maRef.aEnd.Col(), mnCol))
3755  return false;
3756 
3757  return mpArray->Insert(maRef.aStart.Col(), maRef.aEnd.Col(), mbSizeChanged);
3758  }
3759 };
3760 
3761 }
3762 
3763 void ScTable::DoAutoOutline( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
3764 {
3765  typedef mdds::flat_segment_tree<SCROW, bool> UsedRowsType;
3766 
3767  bool bSizeChanged = false;
3768 
3769  SCCOL nCol;
3770  SCROW nRow;
3771  bool bFound;
3772  ScRange aRef;
3773 
3774  nEndCol = ClampToAllocatedColumns(nEndCol);
3775 
3777 
3778  // Rows
3779 
3780  UsedRowsType aUsed(0, rDocument.MaxRow()+1, false);
3781  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
3782  aCol[nCol].FindUsed(nStartRow, nEndRow, aUsed);
3783  aUsed.build_tree();
3784 
3785  ScOutlineArray& rRowArray = pOutlineTable->GetRowArray();
3786  for (nRow=nStartRow; nRow<=nEndRow; nRow++)
3787  {
3788  bool bUsed = false;
3789  SCROW nLastRow = nRow;
3790  aUsed.search_tree(nRow, bUsed, nullptr, &nLastRow);
3791  if (!bUsed)
3792  {
3793  nRow = nLastRow;
3794  continue;
3795  }
3796 
3797  bFound = false;
3798  for (nCol=nStartCol; nCol<=nEndCol && !bFound; nCol++)
3799  {
3800  ScRefCellValue aCell = aCol[nCol].GetCellValue(nRow);
3801 
3802  if (aCell.meType != CELLTYPE_FORMULA)
3803  continue;
3804 
3806  continue;
3807 
3808  if ( aRef.aStart.Col() == nCol && aRef.aEnd.Col() == nCol &&
3809  aRef.aStart.Tab() == nTab && aRef.aEnd.Tab() == nTab &&
3810  DiffSign( aRef.aStart.Row(), nRow ) ==
3811  DiffSign( aRef.aEnd.Row(), nRow ) )
3812  {
3813  if (rRowArray.Insert( aRef.aStart.Row(), aRef.aEnd.Row(), bSizeChanged ))
3814  {
3815  bFound = true;
3816  }
3817  }
3818  }
3819  }
3820 
3821  // Column
3822  ScOutlineArray& rColArray = pOutlineTable->GetColArray();
3823  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
3824  {
3825  if (aCol[nCol].IsEmptyData())
3826  continue;
3827 
3828  OutlineArrayFinder aFunc(aRef, nCol, nTab, &rColArray, bSizeChanged);
3829  sc::FindFormula(aCol[nCol].maCells, nStartRow, nEndRow, aFunc);
3830  }
3831 }
3832 
3833  // CopyData - for Query in other range
3834 
3835 void ScTable::CopyData( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
3836  SCCOL nDestCol, SCROW nDestRow, SCTAB nDestTab )
3837 {
3838  //TODO: if used for multiple rows, optimize after columns!
3839 
3840  ScAddress aSrc( nStartCol, nStartRow, nTab );
3841  ScAddress aDest( nDestCol, nDestRow, nDestTab );
3842  ScRange aRange( aSrc, aDest );
3843  bool bThisTab = ( nDestTab == nTab );
3844  SCROW nDestY = nDestRow;
3845  for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
3846  {
3847  aSrc.SetRow( nRow );
3848  aDest.SetRow( nDestY );
3849  SCCOL nDestX = nDestCol;
3850  for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
3851  {
3852  aSrc.SetCol( nCol );
3853  aDest.SetCol( nDestX );
3854  ScCellValue aCell;
3855  aCell.assign(rDocument, ScAddress(nCol, nRow, nTab));
3856 
3857  if (aCell.meType == CELLTYPE_FORMULA)
3858  {
3859  sc::RefUpdateContext aCxt(rDocument);
3860  aCxt.meMode = URM_COPY;
3861  aCxt.maRange = aRange;
3862  aCxt.mnColDelta = nDestCol - nStartCol;
3863  aCxt.mnRowDelta = nDestRow - nStartRow;
3864  aCxt.mnTabDelta = nDestTab - nTab;
3865  aCell.mpFormula->UpdateReference(aCxt);
3866  aCell.mpFormula->aPos = aDest;
3867  }
3868 
3869  if (bThisTab)
3870  {
3871  aCell.release(CreateColumnIfNotExists(nDestX), nDestY);
3872  SetPattern( nDestX, nDestY, *GetPattern( nCol, nRow ) );
3873  }
3874  else
3875  {
3876  aCell.release(rDocument, aDest);
3877  rDocument.SetPattern( aDest, *GetPattern( nCol, nRow ) );
3878  }
3879 
3880  ++nDestX;
3881  }
3882  ++nDestY;
3883  }
3884 }
3885 
3887 {
3888  ScRange aRef;
3889 
3890  if (pCell->HasOneReference(aRef))
3891  {
3892  if (aRef.aStart.Col()==aRef.aEnd.Col() && aRef.aStart.Tab()==aRef.aEnd.Tab())
3893  {
3894  SCROW nEndRow;
3895  if (!RowFiltered(aRef.aStart.Row(), nullptr, &nEndRow))
3896  // row not filtered.
3897  nEndRow = ::std::numeric_limits<SCROW>::max();
3898 
3899  if (!ValidRow(nEndRow) || nEndRow < aRef.aEnd.Row())
3900  return true; // at least partly visible
3901  return false; // completely invisible
3902  }
3903  }
3904 
3905  return true; // somehow different
3906 }
3907 
3908 void ScTable::GetUpperCellString(SCCOL nCol, SCROW nRow, OUString& rStr)
3909 {
3910  GetInputString(nCol, nRow, rStr);
3911  rStr = ScGlobal::getCharClassPtr()->uppercase(rStr.trim());
3912 }
3913 
3914 // Calculate the size of the sheet and set the size on DrawPage
3915 
3916 void ScTable::SetDrawPageSize(bool bResetStreamValid, bool bUpdateNoteCaptionPos,
3917  ScObjectHandling eObjectHandling)
3918 {
3919  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
3920  if( pDrawLayer )
3921  {
3922  const sal_Int64 nMax = ::std::numeric_limits<tools::Long>::max();
3923  // #i113884# Avoid int32 overflow with possible negative results than can cause bad effects.
3924  // If the draw page size is smaller than all rows, only the bottom of the sheet is affected.
3925  tools::Long x = std::min(o3tl::convert(GetColOffset(rDocument.MaxCol() + 1),
3927  nMax);
3928  tools::Long y = std::min(o3tl::convert(GetRowOffset(rDocument.MaxRow() + 1),
3930  nMax);
3931 
3932  if ( IsLayoutRTL() ) // IsNegativePage
3933  x = -x;
3934 
3935  pDrawLayer->SetPageSize(static_cast<sal_uInt16>(nTab), Size(x, y), bUpdateNoteCaptionPos,
3936  eObjectHandling);
3937  }
3938 
3939  // #i102616# actions that modify the draw page size count as sheet modification
3940  // (exception: InitDrawLayer)
3941  if (bResetStreamValid)
3942  SetStreamValid(false);
3943 }
3944 
3945 void ScTable::SetRangeName(std::unique_ptr<ScRangeName> pNew)
3946 {
3947  mpRangeName = std::move(pNew);
3948 
3949  //fdo#39792: mark stream as invalid, otherwise new ScRangeName will not be written to file
3950  SetStreamValid(false);
3951 }
3952 
3954 {
3955  if (!mpRangeName)
3956  mpRangeName.reset(new ScRangeName);
3957  return mpRangeName.get();
3958 }
3959 
3960 sal_uLong ScTable::GetRowOffset( SCROW nRow, bool bHiddenAsZero ) const
3961 {
3962  sal_uLong n = 0;
3963  if ( mpHiddenRows && mpRowHeights )
3964  {
3965  if (nRow == 0)
3966  return 0;
3967  else if (nRow == 1)
3968  return GetRowHeight(0, nullptr, nullptr, bHiddenAsZero );
3969 
3970  n = GetTotalRowHeight(0, nRow-1, bHiddenAsZero);
3971 #if OSL_DEBUG_LEVEL > 0
3972  if (n == ::std::numeric_limits<tools::ULong>::max())
3973  OSL_FAIL("ScTable::GetRowOffset: row heights overflow");
3974 #endif
3975  }
3976  else
3977  {
3978  OSL_FAIL("GetRowOffset: Data missing");
3979  }
3980  return n;
3981 }
3982 
3984 {
3985  sal_uLong nSum = 0;
3986 
3988 
3989  ScFlatUInt16RowSegments::RangeData aRowHeightRange;
3990  aRowHeightRange.mnRow2 = -1;
3991  aRowHeightRange.mnValue = 0; // silence MSVC C4701
3992 
3993  for (SCROW nRow = 0; nRow <= rDocument.MaxRow(); ++nRow)
3994  {
3995  if (!mpHiddenRows->getRangeData(nRow, aData))
3996  // Failed to fetch the range data for whatever reason.
3997  break;
3998 
3999  if (aData.mbValue)
4000  {
4001  // This row is hidden. Skip ahead all hidden rows.
4002  nRow = aData.mnRow2;
4003  continue;
4004  }
4005 
4006  if (aRowHeightRange.mnRow2 < nRow)
4007  {
4008  if (!mpRowHeights->getRangeData(nRow, aRowHeightRange))
4009  // Failed to fetch the range data for whatever reason.
4010  break;
4011  }
4012 
4013  // find the last common row between hidden & height spans
4014  SCROW nLastCommon = std::min(aData.mnRow2, aRowHeightRange.mnRow2);
4015  assert (nLastCommon >= nRow);
4016  SCROW nCommon = nLastCommon - nRow + 1;
4017 
4018  // how much further to go ?
4019  sal_uLong nPixelsLeft = nHeight - nSum;
4020  sal_uLong nCommonPixels = static_cast<sal_uLong>(aRowHeightRange.mnValue) * nCommon;
4021 
4022  // are we in the zone ?
4023  if (nCommonPixels > nPixelsLeft)
4024  {
4025  nRow += (nPixelsLeft + aRowHeightRange.mnValue - 1) / aRowHeightRange.mnValue;
4026 
4027  // FIXME: finding this next row is far from elegant,
4028  // we have a single caller, which subtracts one as well(!?)
4029  if (nRow >= rDocument.MaxRow())
4030  return rDocument.MaxRow();
4031 
4032  if (!mpHiddenRows->getRangeData(nRow, aData))
4033  // Failed to fetch the range data for whatever reason.
4034  break;
4035 
4036  if (aData.mbValue)
4037  // These rows are hidden.
4038  nRow = aData.mnRow2 + 1;
4039 
4040  return nRow <= rDocument.MaxRow() ? nRow : rDocument.MaxRow();
4041  }
4042 
4043  // skip the range and keep hunting
4044  nSum += nCommonPixels;
4045  nRow = nLastCommon;
4046  }
4047  return -1;
4048 }
4049 
4050 sal_uLong ScTable::GetColOffset( SCCOL nCol, bool bHiddenAsZero ) const
4051 {
4052  sal_uLong n = 0;
4053  if ( mpColWidth )
4054  {
4055  auto colWidthIt = mpColWidth->begin();
4056  for (SCCOL i = 0; i < nCol; (++i < nCol) ? ++colWidthIt : (void)false)
4057  if (!( bHiddenAsZero && ColHidden(i) ))
4058  n += *colWidthIt;
4059  }
4060  else
4061  {
4062  OSL_FAIL("GetColumnOffset: Data missing");
4063  }
4064  return n;
4065 }
4066 
4067 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
If set, cloned formula cells will start to listen to the document.
void FindMaxRotCol(RowInfo *pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2)
Definition: table2.cxx:2226
void SetFormula(SCCOL nCol, SCROW nRow, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGram)
Definition: table2.cxx:1546
void SetMergedCells(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:2122
void CellStorageModified()
Called whenever the state of cell array gets modified i.e.
Definition: column2.cxx:1603
void ApplyStyle(SCROW nRow, const ScStyleSheet *rStyle)
Definition: column.cxx:560
void CalcAfterLoad(sc::CompileFormulaContext &rCxt, bool bStartListening)
Definition: table2.cxx:1989
void CopyUpdated(const ScTable *pPosTab, ScTable *pDestTab) const
Definition: table2.cxx:1378
svl::SharedString GetSharedString(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1583
constexpr double nPPTY
bool TestCopyScenarioTo(const ScTable *pDestTab) const
Definition: table2.cxx:1467
SCCOL GetColMerge() const
Definition: attrib.hxx:68
SCTAB nTab
Definition: table.hxx:203
SCROW mnRowDelta
Amount and direction of movement in the row direction.
const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:2052
bool SetRowHeightRange(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight, double nPPTY, bool bApi)
Definition: table2.cxx:3046
Temporarily switch on/off auto calculation mode.
Definition: scopetools.hxx:26
SCCOL GetLastChangedCol() const
Definition: table2.cxx:3613
bool Intersects(const ScRange &) const
Definition: rangelst.cxx:1082
CellType meType
Definition: cellvalue.hxx:37
ScRotateDir GetRotateDir(const SfxItemSet *pCondSet) const
Definition: patattr.cxx:1327
ScFormulaCell * SetFormulaCell(SCCOL nCol, SCROW nRow, ScFormulaCell *pCell)
Takes ownership of pCell.
Definition: table2.cxx:1564
void ApplyStyleArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: table2.cxx:2734
bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, HasAttrFlags nMask) const
Definition: table2.cxx:2072
bool HasScenarioRange(SCTAB nTab, const ScRange &rRange) const
Definition: documen3.cxx:864
ScAddress aStart
Definition: address.hxx:499
ScRotateDir
Definition: fillinfo.hxx:40
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1906
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
void UnlockTable()
Definition: table2.cxx:2588
bool HasBlockMatrixFragment(const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2, bool bNoMatrixAtAll=false) const
Definition: table2.cxx:2303
void CompileAll(sc::CompileFormulaContext &rCxt)
Definition: table2.cxx:1954
Store parameters used in the ScDocument::SetString() method.
Definition: stringutil.hxx:34
void ForgetNoteCaptions(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bPreserveData)
Definition: table2.cxx:1703
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: table2.cxx:1876
void SetRowFlags(SCROW nRow, CRFlags nNewFlags)
Definition: table2.cxx:3547
bool IsBlockEmpty(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bIgnoreNotes) const
Definition: table2.cxx:2137
void MergeSelectionPattern(ScMergePatternState &rState, const ScMarkData &rMark, bool bDeep) const
Definition: column.cxx:335
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: column.cxx:370
void SetRowHeight(SCROW nRow, sal_uInt16 nNewHeight)
Definition: table2.cxx:2985
std::unique_ptr< ScFlatUInt16RowSegments > mpRowHeights
Definition: table.hxx:180
HasAttrFlags
Definition: global.hxx:192
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
void SetPatternAreaCondFormat(SCCOL nCol, SCROW nStartRow, SCROW nEndRow, const ScPatternAttr &rAttr, const ScCondFormatIndexes &rCondFormatIndexes)
Definition: table2.cxx:2710
Sheet / outlining (grouping) information.
SCROW Row() const
Definition: address.hxx:261
Simple container to keep track of sheet - column pair.
Definition: columnset.hxx:23
Single reference (one address) into the sheet.
Definition: refdata.hxx:29
ScTable * FetchTable(SCTAB nTab)
Definition: document.cxx:2497
bool IsDataFiltered(SCCOL nColStart, SCROW nRowStart, SCCOL nColEnd, SCROW nRowEnd) const
Definition: table2.cxx:3526
bool IsSelectionEditable(const ScMarkData &rMark, bool *pOnlyNotBecauseOfMatrix=nullptr) const
Definition: table2.cxx:2499
void SetRowHeightOnly(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight)
Set specified row height to specified ranges.
Definition: table2.cxx:3102
SCTAB GetTab() const
Definition: table.hxx:280
SC_DLLPUBLIC bool IsActiveScenario(SCTAB nTab) const
Definition: documen3.cxx:877
size_t GetNoteCount(SCCOL nCol) const
Definition: table2.cxx:1681
ScRangeList & GetRangeList()
Definition: conditio.hxx:561
void ApplyPattern(SCCOL nCol, SCROW nRow, const ScPatternAttr &rAttr)
Definition: table2.cxx:2647
ScColumn * FetchColumn(SCCOL nCol)
Definition: table2.cxx:1089
ScObjectHandling
Definition: drwlayer.hxx:89
std::unique_ptr< ScPostIt > ReleaseNote(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1673
ScScenarioFlags
Definition: global.hxx:235
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
void CopyData(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCCOL nDestCol, SCROW nDestRow, SCTAB nDestTab)
Definition: table2.cxx:3835
SC_DLLPUBLIC bool Intersects(const ScRange &rRange) const
Definition: address.cxx:1558
void TransposeReference()
SCCOL size() const
ScMF GetValue() const
Definition: attrib.hxx:97
sal_uIntPtr sal_uLong
long Long
bool TestInsertRow(SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize) const
Definition: table2.cxx:135
Context for reference update during shifting, moving or copying of cell ranges.
void CopyRowFiltered(const ScTable &rTable, SCROW nStartRow, SCROW nEndRow)
Definition: table5.cxx:901
bool IsOverlapped() const
Definition: attrib.hxx:101
CellType GetCellType(const ScAddress &rPos) const
Definition: table.hxx:457
void SetCalcNotification(bool bSet)
Definition: table2.cxx:130
void SetEditText(SCROW nRow, std::unique_ptr< EditTextObject > pEditText)
Definition: column3.cxx:2211
sal_Int64 n
void GetString(SCCOL nCol, SCROW nRow, OUString &rString, const ScInterpreterContext *pContext=nullptr) const
Definition: table2.cxx:1603
bool IsUndo() const
Definition: document.hxx:1531
void DetachFormulaCells(sc::EndListeningContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1133
std::unique_ptr< ScFlatBoolColSegments > mpFilteredCols
Definition: table.hxx:186
const ScStyleSheet * GetSelectionStyle(const ScMarkData &rMark, bool &rFound) const
Definition: table2.cxx:2791
Rich-text attributes.
ScColumnVector::const_iterator end() const
bool HasScenarioRange(const ScRange &rRange) const
Definition: table2.cxx:1425
sal_Int32 mnCol
sal_uInt16 nLockCount
Definition: table.hxx:218
CommentCaptionState GetAllNoteCaptionsState(const ScRange &rRange, std::vector< sc::NoteEntry > &rNotes)
Definition: table2.cxx:1729
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:387
formula::FormulaToken * AddSingleReference(const ScSingleRefData &rRef)
ScSingleRefToken with ocPush.
Definition: token.cxx:2194
Store position data for column array storage.
const SfxItemSet & GetItemSet() const
sal_uInt16 GetDistance(SvxBoxItemLine nLine) const
bool mbPageBreaksValid
Definition: table.hxx:244
InsertDeleteFlags getInsertFlag() const
bool IsClipOrUndo() const
Definition: document.hxx:1530
bool HasObjectsInRows(SCTAB nTab, SCROW nStartRow, SCROW nEndRow)
Definition: drwlayer.cxx:1474
void CopyStaticToDocument(SCROW nRow1, SCROW nRow2, const SvNumberFormatterMergeMap &rMap, ScColumn &rDestCol)
Definition: column.cxx:1062
bool CompileErrorCells(sc::CompileFormulaContext &rCxt, FormulaError nErrCode)
Definition: table2.cxx:1977
sal_uInt16 GetTextWidth(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:86
void GetFirstDataPos(SCCOL &rCol, SCROW &rRow) const
Definition: table2.cxx:1798
ScAddress aEnd
Definition: address.hxx:500
CellStoreType::const_iterator ParseAllNonEmpty(const typename CellStoreType::const_iterator &itPos, const CellStoreType &rCells, SCROW nRow1, SCROW nRow2, Func &rFunc)
Definition: mtvcellfunc.hxx:95
void SetManualHeight(SCROW nStartRow, SCROW nEndRow, bool bManual)
Definition: table2.cxx:3113
void SetColHidden(SCCOL nStartCol, SCCOL nEndCol, bool bHidden)
Definition: table5.cxx:638
void ApplyPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr &rPatAttr, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: column.cxx:516
virtual SfxItemSet & GetItemSet()
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
void CopyScenarioTo(const ScTable *pDestTab) const
Definition: table2.cxx:1396
void UndoToTable(sc::CopyToDocContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, InsertDeleteFlags nFlags, bool bMarked, ScTable *pDestTab)
Definition: table2.cxx:1326
void DeleteRow(const sc::ColumnSet &rRegroupCols, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize, bool *pUndoOutline, std::vector< ScAddress > *pGroupPos)
Definition: table2.cxx:196
sal_uInt16 GetOriginalHeight(SCROW nRow) const
Definition: table2.cxx:3357
void RemoveEditTextCharAttribs(SCCOL nCol, SCROW nRow, const ScPatternAttr &rAttr)
Definition: table2.cxx:1642
const editeng::SvxBorderLine * GetRight() const
mdds::multi_type_vector< CellFunc, CellStoreEvent > CellStoreType
const ScStyleSheet * GetStyle(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:2781
float x
void MixData(sc::MixDocContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScPasteFunc nFunction, bool bSkipEmpty, const ScTable *pSrcTab)
Definition: table2.cxx:777
bool HasData(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1824
void SetDirtyAfterLoad()
Definition: table2.cxx:1905
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
void MergeBlockFrame(SvxBoxItem *pLineOuter, SvxBoxInfoItem *pLineInner, ScLineFlags &rFlags, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow) const
Definition: table2.cxx:2619
void ApplySelectionStyle(const ScStyleSheet &rStyle, const ScMarkData &rMark)
Definition: table2.cxx:2765
std::unique_ptr< ScRangeName > mpRangeName
Definition: table.hxx:225
SCROW nRowNo
Definition: fillinfo.hxx:181
SCROW GetRowForHeight(sal_uLong nHeight) const
Get the last row such that the height of row 0 to the end row is as high as possible without exceedin...
Definition: table2.cxx:3983
const ScAddress & GetAddress() const
Definition: brdcst.hxx:30
constexpr TypedWhichId< ScMergeAttr > ATTR_MERGE(144)
void ApplyAttr(SCCOL nCol, SCROW nRow, const SfxPoolItem &rAttr)
Definition: table2.cxx:2925
void TransposeClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable *pTransClip, InsertDeleteFlags nFlags, bool bAsLink)
Definition: table2.cxx:895
Internal use only (d&d undo): do not delete caption objects of cell notes.
void MarkScenarioIn(ScMarkData &rMark, ScScenarioFlags nNeededBits) const
Definition: table2.cxx:1414
bool UpdateReference(const sc::RefUpdateContext &rCxt, ScDocument *pUndoDoc=nullptr, const ScAddress *pUndoCellPos=nullptr)
bool ValidRow(SCROW nRow) const
Definition: table.hxx:330
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6048
void StartListeners(sc::StartListeningContext &rCxt, bool bAll)
Either start all formula cells as listeners unconditionally, or start those that are marked "needs li...
Definition: table2.cxx:1105
void SetStreamValid(bool bSet, bool bIgnoreLock=false)
Definition: table1.cxx:374
ScColumn & CreateColumnIfNotExists(const SCCOL nScCol) const
Definition: table.hxx:284
void AttachFormulaCells(sc::StartListeningContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1125
Store arbitrary cell value of any kind.
Definition: cellvalue.hxx:35
void TransposeColNotes(ScTable *pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1, SCROW nRow2)
Definition: table2.cxx:1003
constexpr TypedWhichId< ScRotateValueItem > ATTR_ROTATE_VALUE(135)
void ResetChanged(const ScRange &rRange)
Definition: table2.cxx:1995
ScFormulaCell * SetFormulaCell(SCROW nRow, ScFormulaCell *pCell, sc::StartListeningType eListenType=sc::SingleCellListening, bool bInheritNumFormatIfNeeded=true)
Takes ownership of pCell.
Definition: column3.cxx:2309
const ScRangeList & GetRange() const
Definition: conditio.hxx:559
sal_uLong GetColOffset(SCCOL nCol, bool bHiddenAsZero=true) const
Definition: table2.cxx:4050
#define STD_COL_WIDTH
Definition: global.hxx:94
void SetNumberFormat(SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat)
Definition: table2.cxx:2044
bool IsBlockEditable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool *pOnlyNotBecauseOfMatrix=nullptr, bool bNoMatrixAtAll=false) const
Definition: table2.cxx:2415
void InsertRow(SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize)
Definition: table2.cxx:148
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:42
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:871
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
void SetTableOpDirty(const ScRange &)
Definition: table2.cxx:1895
void SetAnonymousDBData(std::unique_ptr< ScDBData > pDBData)
Definition: table1.cxx:2373
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Additional class containing cell annotation data.
Definition: postit.hxx:159
void SetColManualBreaks(const ::std::set< SCCOL > &rBreaks)
Definition: table5.cxx:329
static short DiffSign(T a, T b)
Definition: table2.cxx:3722
void GetFormula(SCCOL nCol, SCROW nRow, OUString &rFormula) const
Definition: table2.cxx:1650
sal_uLong GetScaledRowHeight(SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong *pnMaxHeight=nullptr) const
Definition: table2.cxx:3293
bool UpdateOutlineCol(SCCOL nStartCol, SCCOL nEndCol, bool bShow)
Definition: table2.cxx:3645
void SetNumberFormat(SCROW nRow, sal_uInt32 nNumberFormat)
Definition: column2.cxx:3047
double * GetValueCell(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1611
sc::CellStoreType maCells
Definition: column.hxx:128
const std::shared_ptr< const ColumnSet > & getColumnSet() const
void SetColWidthOnly(SCCOL nCol, sal_uInt16 nNewWidth)
Definition: table2.cxx:2973
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:110
SCTAB Tab() const
Definition: address.hxx:270
void CopyToClip(sc::CopyToClipContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable *pTable)
Definition: table2.cxx:482
void StripHidden(SCCOL &rX1, SCROW &rY1, SCCOL &rX2, SCROW &rY2)
Definition: table2.cxx:3693
void SetRow(SCROW nRowP)
Definition: address.hxx:274
void release(ScDocument &rDoc, const ScAddress &rPos)
Set cell value at specified position in specified document.
Definition: cellvalue.cxx:432
void CopyColHidden(const ScTable &rTable, SCCOL nStartCol, SCCOL nEndCol)
Definition: table5.cxx:672
bool SetRowHidden(SCROW nStartRow, SCROW nEndRow, bool bHidden)
Definition: table5.cxx:588
void SetColWidth(SCCOL nCol, sal_uInt16 nNewWidth)
Definition: table2.cxx:2952
const editeng::SvxBorderLine * GetLine(SvxBoxItemLine nLine) const
bool HasValueData(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1840
bool SetFormulaCells(SCROW nRow, std::vector< ScFormulaCell * > &rCells)
Definition: column3.cxx:2347
sal_uInt32 GetNumberFormat(const ScInterpreterContext &rContext, SCROW nRow) const
Definition: column.cxx:421
ScColumnVector::const_iterator begin() const
void SetValue(SCCOL nCol, SCROW nRow, const double &rVal)
Definition: table2.cxx:1591
std::unique_ptr< ScOutlineTable > pOutlineTable
Definition: table.hxx:194
ScAddress aPos
void DoAutoOutline(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: table2.cxx:3763
void SetRangeName(std::unique_ptr< ScRangeName > pNew)
Definition: table2.cxx:3945
void SetPattern(const ScAddress &rPos, const ScPatternAttr &rAttr)
Definition: table2.cxx:2906
bool RemoveFlags(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScMF nFlags)
Definition: table2.cxx:2894
ScBroadcastAreaSlotMachine * GetBASM() const
Definition: document.hxx:2144
void SetRowManualBreaks(const ::std::set< SCROW > &rBreaks)
Definition: table5.cxx:322
void SetCol(SCCOL nColP)
Definition: address.hxx:278
size_t size() const
Definition: conditio.cxx:1767
sal_uInt16 GetOriginalWidth(SCCOL nCol) const
Definition: table2.cxx:3165
bool HasSelectionMatrixFragment(const ScMarkData &rMark) const
Definition: table2.cxx:2399
std::unique_ptr< ScBitMaskCompressedArray< SCCOL, CRFlags > > mpColFlags
Definition: table.hxx:182
constexpr auto convert(N n, sal_Int64 mul, sal_Int64 div)
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:953
bool IsLayoutRTL() const
Definition: table.hxx:339
float y
bool IsColValid(const SCCOL nScCol) const
Definition: table.hxx:317
constexpr OUStringLiteral aData
bool SetString(SCROW nRow, SCTAB nTab, const OUString &rString, formula::FormulaGrammar::AddressConvention eConv, const ScSetStringParam *pParam=nullptr)
Returns true if the cell format was set as well.
Definition: column3.cxx:2191
bool HasRefListExpressibleAsOneReference(ScRange &rRange) const
constexpr double nPPTX
bool SetOutlineTable(const ScOutlineTable *pNewOutline)
Definition: table2.cxx:91
static SC_DLLPUBLIC sal_uInt16 nStdRowHeight
Definition: global.hxx:583
sal_uInt32 GetKey() const
Definition: conditio.hxx:591
void SetRange(const ScRangeList &rRanges)
Definition: conditio.cxx:1741
std::unique_ptr< ScFlatBoolColSegments > mpHiddenCols
Definition: table.hxx:184
bool SetFormulaCells(SCCOL nCol, SCROW nRow, std::vector< ScFormulaCell * > &rCells)
Definition: table2.cxx:1575
const ScFormatEntry * GetEntry(sal_uInt16 nPos) const
Definition: conditio.cxx:1781
ScPasteFunc
Definition: global.hxx:188
void ShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
Definition: table2.cxx:3484
void ApplyStyle(SCCOL nCol, SCROW nRow, const ScStyleSheet *rStyle)
Definition: table2.cxx:2727
void SetTab(SCTAB nTabP)
Definition: address.hxx:282
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1057
const editeng::SvxBorderLine * GetTop() const
void SetDrawPageSize(bool bResetStreamValid=true, bool bUpdateNoteCaptionPos=true, const ScObjectHandling eObjectHandling=ScObjectHandling::RecalcPosMode)
Definition: table2.cxx:3916
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:870
bool ColHidden(SCCOL nCol, SCCOL *pFirstCol=nullptr, SCCOL *pLastCol=nullptr) const
Definition: table5.cxx:571
bool IsProtected() const
Definition: table5.cxx:1088
SC_DLLPUBLIC void SetPattern(const ScAddress &, const ScPatternAttr &rAttr)
Definition: document.cxx:5036
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
UNDERLYING_TYPE get() const
void GetScenarioFlags(SCTAB nTab, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:479
bool ValidCol(SCCOL nCol) const
Definition: table.hxx:329
SCCOL nRotMaxCol
Definition: fillinfo.hxx:182
const ScFormulaCell * GetFormulaCell(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1658
ScDocument & GetDoc()
Definition: table.hxx:278
void InitBlockPosition(sc::ColumnBlockPosition &rBlockPos)
Definition: column3.cxx:1044
const editeng::SvxBorderLine * GetLeft() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
void SetDirtyVar()
Definition: table2.cxx:1862
void SetRawString(SCROW nRow, const OUString &rStr)
Definition: column3.cxx:2837
void AddCondFormatData(const ScRangeList &rRange, sal_uInt32 nIndex)
Definition: table2.cxx:2676
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
const ScRangeList * GetScenarioRanges() const
Definition: table2.cxx:1453
void CheckVectorizationState()
Definition: table2.cxx:1868
void SetFlag3D(bool bVal)
Definition: refdata.hxx:89
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
Definition: refdata.cxx:27
sal_Int16 SCCOL
Definition: types.hxx:21
sal_uInt16 GetColWidth(SCCOL nCol, bool bHiddenAsZero=true) const
Definition: table2.cxx:3128
InsertDeleteFlags
Definition: global.hxx:157
void InvalidateScenarioRanges()
Definition: table2.cxx:1448
void CopyCaptionsToTable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable *pDestTab, bool bCloneCaption)
Definition: table2.cxx:1312
std::unique_ptr< ScDBData > pDBDataNoName
Definition: table.hxx:224
SC_DLLPUBLIC void SetAutoCalc(bool bNewAutoCalc)
Definition: documen7.cxx:602
void CopyRowHidden(const ScTable &rTable, SCROW nStartRow, SCROW nEndRow)
Definition: table5.cxx:687
sc::CellTextAttrStoreType maCellTextAttrs
Definition: column.hxx:117
std::unique_ptr< ScPostIt > Clone(const ScAddress &rOwnPos, ScDocument &rDestDoc, const ScAddress &rDestPos, bool bCloneCaption) const
Clones this note and its caption object, if specified.
Definition: postit.cxx:877
CRFlags GetRowFlags(SCROW nRow) const
Definition: table2.cxx:3575
void SetEmptyCell(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1538
::std::map< sal_uInt32, sal_uInt32 > SvNumberFormatterMergeMap
const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, sal_uInt16 nWhich) const
Definition: table2.cxx:2008
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:872
SvNumberFormatter * GetFormatTable() const
const SvxPageUsage aArr[]
ScScenarioFlags nScenarioFlags
Definition: table.hxx:223
void ApplyStyleArea(SCROW nStartRow, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: attarray.cxx:626
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:126
void GetUnprotectedCells(ScRangeList &rRangeList) const
Definition: table2.cxx:1762
void ShowCol(SCCOL nCol, bool bShow)
Definition: table2.cxx:3383
bool HasAttribSelection(const ScMarkData &rMark, HasAttrFlags nMask) const
Definition: table2.cxx:2085
void CopyFromClip(sc::CopyFromClipContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCCOL nDx, SCROW nDy, ScTable *pTable)
Definition: table2.cxx:716
const EditTextObject * GetEditText(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1634
void DBShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
Definition: table2.cxx:3452
void GetNotesInRange(const ScRange &rRange, std::vector< sc::NoteEntry > &rNotes) const
Definition: table2.cxx:1718
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
bool TestInsertRow(SCROW nStartRow, SCSIZE nSize) const
Definition: column.cxx:837
size_t size() const
Definition: rangelst.hxx:89
std::unique_ptr< ScTableProtection > pTabProtection
Definition: table.hxx:177
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
void GetLastDataPos(SCCOL &rCol, SCROW &rRow) const
Definition: table2.cxx:1813
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
bool IsCutMode()
Definition: document.cxx:2057
void SetNote(const ScAddress &rPos, std::unique_ptr< ScPostIt > pNote)
Definition: document.cxx:6510
void SetRangeDirty(const ScRange &rRange)
Definition: chartlis.cxx:570
void CompileXML(sc::CompileFormulaContext &rCxt, ScProgress &rProgress)
Definition: table2.cxx:1963
SvNumFormatType
bool EqualEntries(const ScConditionalFormat &r, bool bIgnoreSrcPos=false) const
Definition: conditio.cxx:1722
bool bTableAreaValid
Definition: table.hxx:235
ScColContainer aCol
Definition: table.hxx:156
void SetRawString(SCCOL nCol, SCROW nRow, const svl::SharedString &rStr)
Definition: table2.cxx:1597
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1255
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1152
void LockTable()
Definition: table2.cxx:2583
void DBShowRow(SCROW nRow, bool bShow)
Definition: table2.cxx:3426
::std::set< SCROW > maRowManualBreaks
Definition: table.hxx:190
std::unique_ptr< ScConditionalFormatList > mpCondFormatList
Definition: table.hxx:227
double * GetValueCell(SCROW nRow)
Definition: column3.cxx:2935
void SetDistance(sal_uInt16 nNew, SvxBoxItemLine nLine)
void ApplySelectionLineStyle(const ScMarkData &rMark, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: table2.cxx:2771
void BroadcastRecalcOnRefMove()
Broadcast dirty formula cells that contain functions such as CELL(), COLUMN() or ROW() which may chan...
Definition: table2.cxx:1923
bool empty() const
CommentCaptionState
Definition: document.hxx:252
void ExtendHidden(SCCOL &rX1, SCROW &rY1, SCCOL &rX2, SCROW &rY2)
Definition: table2.cxx:3663
void SetAreasChangedNeedBroadcast()
Definition: docsh.hxx:384
bool ApplyFlags(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScMF nFlags)
Definition: table2.cxx:2884
ScRange maRange
Range of cells that are about to be moved for insert/delete/move modes.
void ApplyAttr(SCROW nRow, const SfxPoolItem &rAttr)
Definition: column.cxx:715
BroadcastMode
Broadcast mode for SetDirty(SCROW,SCROW,BroadcastMode).
Definition: column.hxx:171
bool ContainsNotesInRange(const ScRange &rRange) const
Definition: table2.cxx:1768
void getColumns(SCTAB nTab, std::vector< SCCOL > &rCols) const
Definition: columnset.cxx:34
FormulaError
SCCOL Col() const
Definition: address.hxx:266
bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: table2.cxx:1480
bool RefVisible(const ScFormulaCell *pCell)
Definition: table2.cxx:3886
void DeleteArea(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, InsertDeleteFlags nDelFlag, bool bBroadcast=true, sc::ColumnSpanSet *pBroadcastSpans=nullptr)
Definition: table2.cxx:414
void MergePatternArea(ScMergePatternState &rState, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bDeep) const
Definition: table2.cxx:2611
Internal use only (undo etc.): do not copy/delete caption objects of cell notes.
bool IsMerged() const
Definition: attrib.hxx:71
void CopyToTable(sc::CopyToDocContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, InsertDeleteFlags nFlags, bool bMarked, ScTable *pDestTab, const ScMarkData *pMarkData, bool bAsLink, bool bColRowFlags, bool bGlobalNamesToLocal, bool bCopyCaptions)
Definition: table2.cxx:1164
void InvalidatePageBreaks()
Definition: table2.cxx:1391
bool ApplyFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: column.cxx:684
CellType meType
Definition: cellvalue.hxx:105
bool RowHidden(SCROW nRow, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: table5.cxx:496
constexpr TypedWhichId< ScMergeFlagAttr > ATTR_MERGE_FLAG(145)
CRFlags
Definition: global.hxx:134
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:17
void SetPageSize(sal_uInt16 nPageNo, const Size &rSize, bool bUpdateNoteCaptionPos, const ScObjectHandling eObjectHandling=ScObjectHandling::RecalcPosMode)
Definition: drwlayer.cxx:563
void SetFormula(SCROW nRow, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGram)
Definition: column3.cxx:2273
ScMF
Definition: attrib.hxx:34
std::unique_ptr< ScFlatBoolRowSegments > mpFilteredRows
Definition: table.hxx:187
sc::CellNoteStoreType maCellNotes
Definition: column.hxx:120
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
void CopyScenarioFrom(const ScTable *pSrcTab)
Definition: table2.cxx:1404
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define SAL_WARN_IF(condition, area, stream)
sal_uInt32 GetTotalRowHeight(SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZero=true) const
Definition: table5.cxx:788
ScRangeName * GetRangeName() const
Definition: table2.cxx:3953
void CopyStyleFrom(ScStyleSheetPool *pSrcPool, const OUString &rName, SfxStyleFamily eFamily)
Definition: stlpool.cxx:128
void Join(const ScRange &, bool bIsInList=false)
Definition: rangelst.cxx:164
ScRefCellValue GetCellValue(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1790
void DeleteCol(const sc::ColumnSet &rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize, bool *pUndoOutline)
Definition: table2.cxx:348
bool ValidColRow(SCCOL nCol, SCROW nRow) const
Definition: table.hxx:331
SCTAB mnTabDelta
Amount and direction of movement in the sheet direction.
CellType
Definition: global.hxx:280
bool BroadcastBroadcasters(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScHint &rHint)
Broadcast single broadcasters in range, without explicitly setting anything dirty, not doing area broadcasts.
Definition: table2.cxx:1930
sal_uInt16 GetCommonWidth(SCCOL nEndCol) const
Definition: table2.cxx:3175
void CopyConditionalFormat(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCCOL nDx, SCROW nDy, const ScTable *pTable)
Definition: table2.cxx:623
void MergeSelectionPattern(ScMergePatternState &rState, const ScMarkData &rMark, bool bDeep) const
Definition: table2.cxx:2598
void assign(const ScDocument &rDoc, const ScAddress &rPos)
Take cell value from specified position in specified document.
Definition: cellvalue.cxx:330
ScColumnsRange GetColumnsRange(SCCOL begin, SCCOL end) const
Definition: table1.cxx:2626
const ScPatternAttr * GetMostUsedPattern(SCCOL nCol, SCROW nStartRow, SCROW nEndRow) const
Definition: table2.cxx:2063
SCROW GetLastChangedRow() const
Definition: table2.cxx:3628
::std::set< SCCOL > maColManualBreaks
Definition: table.hxx:192
void CopyRowHeight(const ScTable &rSrcTable, SCROW nStartRow, SCROW nEndRow, SCROW nSrcOffset)
Definition: table5.cxx:701
SC_DLLPUBLIC bool HasColNotes(SCCOL nCol, SCTAB nTab) const
Definition: document.cxx:6541
void ApplyPattern(SCROW nRow, const ScPatternAttr &rPatAttr)
Definition: column.cxx:501
void CalcAll()
Definition: table2.cxx:1946
void GetInputString(SCCOL nCol, SCROW nRow, OUString &rString) const
Definition: table2.cxx:1619
#define F_PI18000