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  const ScTable& mrSrcTab;
800  SCTAB mnSrcTab;
801  SCCOL mnCol1;
802  SCCOL mnSrcCol;
803  size_t mnTopRow;
804  size_t mnEndRow;
805  SCROW mnTransRow;
806  SCROW mnFilteredRows = 0;
807  SCROW mnRowDestOffset = 0;
808  bool mbAsLink;
809  bool mbWasCut;
810  bool mbIncludeFiltered;
812 
813  ScAddress getDestPos(size_t nRow) const
814  {
815  return ScAddress(static_cast<SCCOL>(mnCol1 + nRow - mnTopRow), mnTransRow,
816  mrClipTab.GetTab());
817  }
818 
819  ScFormulaCell* createRefCell(size_t nSrcRow, const ScAddress& rDestPos) const
820  {
821  ScAddress aSrcPos(mnSrcCol, nSrcRow, mnSrcTab);
822  ScSingleRefData aRef;
823  aRef.InitAddress(aSrcPos); // Absolute reference.
824  aRef.SetFlag3D(true);
825 
826  ScTokenArray aArr(mrClipTab.GetDoc());
827  aArr.AddSingleReference(aRef);
828  return new ScFormulaCell(mrClipTab.GetDoc(), rDestPos, aArr);
829  }
830 
831  void setLink(size_t nRow)
832  {
833  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
834  mrClipTab.SetFormulaCell(nTransCol, mnTransRow,
835  createRefCell(nRow, getDestPos(nRow)));
836  }
837 
838 public:
839  TransClipHandler(ScTable& rClipTab, const ScTable& rSrcTab, SCTAB nSrcTab, SCCOL nCol1,
840  SCCOL nSrcCol, size_t nTopRow, size_t nEndRow, SCROW nCombinedStartRow,
841  SCROW nRowDestOffset, bool bAsLink, bool bWasCut,
842  const InsertDeleteFlags& nFlags, const bool bIncludeFiltered,
843  std::vector<SCROW>& rFilteredRows)
844  : mrClipTab(rClipTab)
845  , mrSrcTab(rSrcTab)
846  , mnSrcTab(nSrcTab)
847  , mnCol1(nCol1)
848  , mnSrcCol(nSrcCol)
849  , mnTopRow(nTopRow)
850  , mnEndRow(nEndRow)
851  , mnTransRow(nSrcCol - nCol1 + nCombinedStartRow)
852  , mnRowDestOffset(nRowDestOffset)
853  , mbAsLink(bAsLink)
854  , mbWasCut(bWasCut)
855  , mbIncludeFiltered(bIncludeFiltered)
856  , mnFlags(nFlags)
857  {
858  // Create list of filtered rows.
859  if (!mbIncludeFiltered)
860  {
861  for (SCROW curRow = nTopRow; curRow <= static_cast<SCROW>(mnEndRow); ++curRow)
862  {
863  // maybe this loop could be optimized
864  bool bFiltered = mrSrcTab.RowFiltered(curRow, nullptr, nullptr);
865  if (bFiltered)
866  rFilteredRows.push_back(curRow);
867  }
868  }
869  }
870 
871  void operator() (size_t nRow, double fVal)
872  {
873  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
874  if (!mbIncludeFiltered && bFiltered)
875  {
876  mnFilteredRows++;
877  return;
878  }
879 
880  if (mbAsLink)
881  {
882  setLink(nRow);
883  return;
884  }
885 
886  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
887  mrClipTab.SetValue(nTransCol, mnTransRow, fVal);
888  }
889 
890  void operator() (size_t nRow, const svl::SharedString& rStr)
891  {
892  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
893  if (!mbIncludeFiltered && bFiltered)
894  {
895  mnFilteredRows++;
896  return;
897  }
898 
899  if (mbAsLink)
900  {
901  setLink(nRow);
902  return;
903  }
904 
905  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
906  mrClipTab.SetRawString(nTransCol, mnTransRow, rStr);
907  }
908 
909  void operator() (size_t nRow, const EditTextObject* p)
910  {
911  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
912  if (!mbIncludeFiltered && bFiltered)
913  {
914  mnFilteredRows++;
915  return;
916  }
917 
918  if (mbAsLink)
919  {
920  setLink(nRow);
921  return;
922  }
923 
924  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
925  mrClipTab.SetEditText(nTransCol, mnTransRow, ScEditUtil::Clone(*p, mrClipTab.GetDoc()));
926  }
927 
928  void operator() (size_t nRow, const ScFormulaCell* p)
929  {
930  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
931  if (!mbIncludeFiltered && bFiltered)
932  {
933  mnFilteredRows++;
934  return;
935  }
936 
937  if (mbAsLink)
938  {
939  setLink(nRow);
940  return;
941  }
942 
943  ScFormulaCell* pNew = new ScFormulaCell(*p, mrClipTab.GetDoc(),
944  getDestPos(nRow - mnFilteredRows + mnRowDestOffset),
946 
947  // rotate reference
948  // for Cut, the references are later adjusted through UpdateTranspose
949 
950  if (!mbWasCut)
951  pNew->TransposeReference();
952 
953  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
954  mrClipTab.SetFormulaCell(nTransCol, mnTransRow, pNew);
955  }
956 
957  // empty cells
958  void operator()(const int /*type*/, size_t nRow, size_t nDataSize)
959  {
960  for (size_t curRow = nRow; curRow < nRow + nDataSize; ++curRow)
961  {
962  bool bFiltered = mrSrcTab.RowFiltered(curRow, nullptr, nullptr);
963  if (!mbIncludeFiltered && bFiltered)
964  {
965  mnFilteredRows++;
966  continue;
967  }
968 
969  if (mbAsLink && mnFlags == InsertDeleteFlags::ALL)
970  {
971  // with InsertDeleteFlags::ALL, also create links (formulas) for empty cells
972  setLink(nRow);
973  continue;
974  }
975  }
976  }
977 };
978 }
979 
980 void ScTable::TransposeClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
981  SCROW nCombinedStartRow, SCROW nRowDestOffset, ScTable* pTransClip,
982  InsertDeleteFlags nFlags, bool bAsLink, bool bIncludeFiltered)
983 {
984  bool bWasCut = rDocument.IsCutMode();
985 
986  for (SCCOL nCol=nCol1; nCol<=nCol2; nCol++)
987  {
988  std::vector<SCROW> aFilteredRows;
989 
990  TransClipHandler aFunc(*pTransClip, *this, nTab, nCol1, nCol, nRow1, nRow2,
991  nCombinedStartRow, nRowDestOffset, bAsLink, bWasCut, nFlags,
992  bIncludeFiltered, aFilteredRows);
993 
994  const sc::CellStoreType& rCells = aCol[nCol].maCells;
995 
996  // Loop through all rows by iterator and call aFunc operators
997  sc::ParseAll(rCells.begin(), rCells, nRow1, nRow2, aFunc,
998  aFunc);
999 
1000  // Attributes
1001  if (nFlags & InsertDeleteFlags::ATTRIB)
1002  TransposeColPatterns(pTransClip, nCol1, nCol, nRow1, nRow2, nCombinedStartRow,
1003  bIncludeFiltered, aFilteredRows, nRowDestOffset);
1004 
1005  // Cell Notes - fdo#68381 paste cell notes on Transpose
1006  if ((nFlags & InsertDeleteFlags::NOTE) && rDocument.HasColNotes(nCol, nTab))
1007  TransposeColNotes(pTransClip, nCol1, nCol, nRow1, nRow2, nCombinedStartRow,
1008  bIncludeFiltered, nRowDestOffset);
1009  }
1010 }
1011 
1012 static void lcl_SetTransposedPatternInRows(ScTable* pTransClip, SCROW nAttrRow1, SCROW nAttrRow2,
1013  SCCOL nCol1, SCROW nRow1, SCROW nCombinedStartRow, SCCOL nCol,
1014  const ScPatternAttr& rPatternAttr, bool bIncludeFiltered,
1015  const std::vector<SCROW>& rFilteredRows,
1016  SCROW nRowDestOffset)
1017 {
1018  for (SCROW nRow = nAttrRow1; nRow <= nAttrRow2; nRow++)
1019  {
1020  size_t nFilteredRowAdjustment = 0;
1021  if (!bIncludeFiltered)
1022  {
1023  // aFilteredRows is sorted thus lower_bound() can be used.
1024  // lower_bound() has a logarithmic complexity O(log(n))
1025  auto itRow1 = std::lower_bound(rFilteredRows.begin(), rFilteredRows.end(), nRow1);
1026  auto itRow = std::lower_bound(rFilteredRows.begin(), rFilteredRows.end(), nRow);
1027  bool bRefRowIsFiltered = itRow != rFilteredRows.end() && *itRow == nRow;
1028  if (bRefRowIsFiltered)
1029  continue;
1030 
1031  // How many filtered rows are between the formula cell and the reference?
1032  // distance() has a constant complexity O(1) for vectors
1033  nFilteredRowAdjustment = std::distance(itRow1, itRow);
1034  }
1035 
1036  pTransClip->SetPattern(
1037  static_cast<SCCOL>(nCol1 + nRow - nRow1 - nFilteredRowAdjustment + nRowDestOffset),
1038  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), rPatternAttr);
1039  }
1040 }
1041 
1042 void ScTable::TransposeColPatterns(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1,
1043  SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered,
1044  const std::vector<SCROW>& rFilteredRows, SCROW nRowDestOffset)
1045 {
1046  SCROW nAttrRow1 = {}; // spurious -Werror=maybe-uninitialized
1047  SCROW nAttrRow2 = {}; // spurious -Werror=maybe-uninitialized
1048  const ScPatternAttr* pPattern;
1049  std::unique_ptr<ScAttrIterator> pAttrIter(aCol[nCol].CreateAttrIterator( nRow1, nRow2 ));
1050  while ( (pPattern = pAttrIter->Next( nAttrRow1, nAttrRow2 )) != nullptr )
1051  {
1052  if ( !IsDefaultItem( pPattern ) )
1053  {
1054  const SfxItemSet& rSet = pPattern->GetItemSet();
1055  if ( rSet.GetItemState( ATTR_MERGE, false ) == SfxItemState::DEFAULT &&
1056  rSet.GetItemState( ATTR_MERGE_FLAG, false ) == SfxItemState::DEFAULT &&
1057  rSet.GetItemState( ATTR_BORDER, false ) == SfxItemState::DEFAULT )
1058  {
1059  // Set pattern in cells from nAttrRow1 to nAttrRow2
1060  // no borders or merge items involved - use pattern as-is
1061  lcl_SetTransposedPatternInRows(pTransClip, nAttrRow1, nAttrRow2, nCol1, nRow1,
1062  nCombinedStartRow, nCol, *pPattern,
1063  bIncludeFiltered, rFilteredRows, nRowDestOffset);
1064  }
1065  else
1066  {
1067  // transpose borders and merge values, remove merge flags (refreshed after pasting)
1068  ScPatternAttr aNewPattern( *pPattern );
1069  SfxItemSet& rNewSet = aNewPattern.GetItemSet();
1070 
1071  const SvxBoxItem& rOldBox = rSet.Get(ATTR_BORDER);
1072  if ( rOldBox.GetTop() || rOldBox.GetBottom() || rOldBox.GetLeft() || rOldBox.GetRight() )
1073  {
1074  SvxBoxItem aNew( ATTR_BORDER );
1075  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::TOP ), SvxBoxItemLine::LEFT );
1076  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::LEFT ), SvxBoxItemLine::TOP );
1077  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::BOTTOM ), SvxBoxItemLine::RIGHT );
1078  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::RIGHT ), SvxBoxItemLine::BOTTOM );
1079  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::TOP ), SvxBoxItemLine::LEFT );
1080  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::LEFT ), SvxBoxItemLine::TOP );
1081  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::BOTTOM ), SvxBoxItemLine::RIGHT );
1082  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::RIGHT ), SvxBoxItemLine::BOTTOM );
1083  rNewSet.Put( aNew );
1084  }
1085 
1086  const ScMergeAttr& rOldMerge = rSet.Get(ATTR_MERGE);
1087  if (rOldMerge.IsMerged())
1088  rNewSet.Put( ScMergeAttr( std::min(
1089  static_cast<SCCOL>(rOldMerge.GetRowMerge()),
1090  static_cast<SCCOL>(rDocument.MaxCol()+1 - (nAttrRow2-nRow1))),
1091  std::min(
1092  static_cast<SCROW>(rOldMerge.GetColMerge()),
1093  static_cast<SCROW>(rDocument.MaxRow()+1 - (nCol-nCol1)))));
1094  const ScMergeFlagAttr& rOldFlag = rSet.Get(ATTR_MERGE_FLAG);
1095  if (rOldFlag.IsOverlapped())
1096  {
1097  ScMF nNewFlags = rOldFlag.GetValue() & ~ScMF( ScMF::Hor | ScMF::Ver );
1098  if ( nNewFlags != ScMF::NONE )
1099  rNewSet.Put( ScMergeFlagAttr( nNewFlags ) );
1100  else
1101  rNewSet.ClearItem( ATTR_MERGE_FLAG );
1102  }
1103 
1104  // Set pattern in cells from nAttrRow1 to nAttrRow2
1105  lcl_SetTransposedPatternInRows(pTransClip, nAttrRow1, nAttrRow2, nCol1, nRow1,
1106  nCombinedStartRow, nCol, aNewPattern,
1107  bIncludeFiltered, rFilteredRows, nRowDestOffset);
1108  }
1109  }
1110  }
1111 }
1112 
1113 void ScTable::TransposeColNotes(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1,
1114  SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered,
1115  SCROW nRowDestOffset)
1116 {
1117  sc::CellNoteStoreType::const_iterator itBlk = aCol[nCol].maCellNotes.begin(), itBlkEnd = aCol[nCol].maCellNotes.end();
1118 
1119  // Locate the top row position.
1120  size_t nOffsetInBlock = 0;
1121  size_t nBlockStart = 0, nBlockEnd = 0, nRowPos = static_cast<size_t>(nRow1);
1122  for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd)
1123  {
1124  nBlockEnd = nBlockStart + itBlk->size;
1125  if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
1126  {
1127  // Found.
1128  nOffsetInBlock = nRowPos - nBlockStart;
1129  break;
1130  }
1131  }
1132 
1133  if (itBlk == itBlkEnd)
1134  // Specified range found
1135  return;
1136 
1137  nRowPos = static_cast<size_t>(nRow2); // End row position.
1138  SCCOL nFilteredRows = 0;
1139 
1140  // Keep processing until we hit the end row position.
1141  sc::cellnote_block::const_iterator itData, itDataEnd;
1142  for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd, nOffsetInBlock = 0)
1143  {
1144  nBlockEnd = nBlockStart + itBlk->size;
1145 
1146  if (itBlk->data)
1147  {
1148  itData = sc::cellnote_block::begin(*itBlk->data);
1149  std::advance(itData, nOffsetInBlock);
1150 
1151  // selected area is smaller than the iteration block
1152  if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
1153  {
1154  // This block contains the end row. Only process partially.
1155  size_t nOffsetEnd = nRowPos - nBlockStart + 1;
1156  itDataEnd = sc::cellnote_block::begin(*itBlk->data);
1157  std::advance(itDataEnd, nOffsetEnd);
1158  size_t curRow = nBlockStart + nOffsetInBlock;
1159  for (; itData != itDataEnd; ++itData, ++curRow)
1160  {
1161  bool bFiltered = this->RowFiltered(curRow, nullptr, nullptr);
1162  if (!bIncludeFiltered && bFiltered)
1163  {
1164  nFilteredRows++;
1165  continue;
1166  }
1167 
1168  ScAddress aDestPos(
1169  static_cast<SCCOL>(nCol1 + curRow - nRow1 - nFilteredRows + nRowDestOffset),
1170  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), pTransClip->nTab);
1171  pTransClip->rDocument.ReleaseNote(aDestPos);
1172  ScPostIt* pNote = *itData;
1173  if (pNote)
1174  {
1175  std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), pTransClip->rDocument, aDestPos, true );
1176  pTransClip->rDocument.SetNote(aDestPos, std::move(pClonedNote));
1177  }
1178  }
1179  break; // we reached the last valid block
1180  }
1181  else
1182  {
1183  itDataEnd = sc::cellnote_block::end(*itBlk->data);
1184  size_t curRow = nBlockStart + nOffsetInBlock;
1185  for (; itData != itDataEnd; ++itData, ++curRow)
1186  {
1187  bool bFiltered = this->RowFiltered(curRow, nullptr, nullptr);
1188  if (!bIncludeFiltered && bFiltered)
1189  {
1190  nFilteredRows++;
1191  continue;
1192  }
1193 
1194  ScAddress aDestPos(
1195  static_cast<SCCOL>(nCol1 + curRow - nRow1 - nFilteredRows + nRowDestOffset),
1196  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), pTransClip->nTab);
1197  pTransClip->rDocument.ReleaseNote(aDestPos);
1198  ScPostIt* pNote = *itData;
1199  if (pNote)
1200  {
1201  std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), pTransClip->rDocument, aDestPos, true );
1202  pTransClip->rDocument.SetNote(aDestPos, std::move(pClonedNote));
1203  }
1204  }
1205  }
1206  }
1207  else // remove dest notes for rows without notes
1208  {
1209  for (size_t curRow = nBlockStart + nOffsetInBlock;
1210  curRow <= nBlockEnd && curRow <= nRowPos; ++curRow)
1211  {
1212  bool bFiltered = this->RowFiltered(curRow, nullptr, nullptr);
1213  if (!bIncludeFiltered && bFiltered && curRow < nBlockEnd)
1214  {
1215  nFilteredRows++;
1216  continue;
1217  }
1218 
1219  ScAddress aDestPos(
1220  static_cast<SCCOL>(nCol1 + curRow - nRow1 - nFilteredRows + nRowDestOffset),
1221  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), pTransClip->nTab);
1222  pTransClip->rDocument.ReleaseNote(aDestPos);
1223  }
1224  }
1225  }
1226 }
1227 
1229 {
1230  if (!ValidCol(nCol))
1231  return nullptr;
1232 
1233  return &CreateColumnIfNotExists(nCol);
1234 }
1235 
1237 {
1238  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1239  return nullptr;
1240 
1241  return &aCol[nCol];
1242 }
1243 
1245 {
1246  std::shared_ptr<const sc::ColumnSet> pColSet = rCxt.getColumnSet();
1247  if (!pColSet)
1248  {
1249  for (SCCOL i=0; i < aCol.size(); i++)
1250  aCol[i].StartListeners(rCxt, bAll);
1251  }
1252  else if (pColSet->hasTab( nTab))
1253  {
1254  std::vector<SCCOL> aColumns;
1255  pColSet->getColumns( nTab, aColumns);
1256  for (auto i : aColumns)
1257  {
1258  if (0 <= i && i < aCol.size())
1259  aCol[i].StartListeners(rCxt, bAll);
1260  }
1261  }
1262 }
1263 
1265  sc::StartListeningContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1266 {
1267  nCol2 = ClampToAllocatedColumns(nCol2);
1268  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
1269  aCol[nCol].AttachFormulaCells(rCxt, nRow1, nRow2);
1270 }
1271 
1273  sc::EndListeningContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1274 {
1275  nCol2 = ClampToAllocatedColumns(nCol2);
1276  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
1277  aCol[nCol].DetachFormulaCells(rCxt, nRow1, nRow2, nullptr);
1278 }
1279 
1281  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, sc::ColumnSpanSet& rBroadcastSpans )
1282 {
1283  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1284  if (nCol2 > rDocument.MaxCol()) nCol2 = rDocument.MaxCol();
1285  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
1286  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
1287  for (SCCOL i = nCol1; i <= nCol2; i++)
1288  aCol[i].SetDirtyFromClip(nRow1, nRow2, rBroadcastSpans);
1289 }
1290 
1293  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1294 {
1295  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1296  if (nCol2 > rDocument.MaxCol()) nCol2 = rDocument.MaxCol();
1297  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
1298  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
1299  for (SCCOL i = nCol1; i <= nCol2; i++)
1300  aCol[i].StartListeningFormulaCells(rStartCxt, rEndCxt, nRow1, nRow2);
1301 }
1302 
1304  sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1305  InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab, const ScMarkData* pMarkData,
1306  bool bAsLink, bool bColRowFlags, bool bGlobalNamesToLocal, bool bCopyCaptions )
1307 {
1308  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
1309  return;
1310 
1311  bool bIsUndoDoc = pDestTab->rDocument.IsUndo();
1312 
1313  if (bIsUndoDoc && (nFlags & InsertDeleteFlags::CONTENTS))
1314  {
1315  // Copying formulas may create sheet-local named expressions on the
1316  // destination sheet. Add existing to Undo first.
1317  pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( *GetRangeName())));
1318  }
1319 
1320  if (nFlags != InsertDeleteFlags::NONE)
1321  {
1322  InsertDeleteFlags nTempFlags( nFlags &
1324  // tdf#102364 - in some pathological cases CopyToTable() replacing cells with new cells
1325  // can lead to repetitive splitting and rejoining of the same formula group, which can get
1326  // quadratically expensive with large groups. So do the grouping just once at the end.
1327  sc::DelayFormulaGroupingSwitch delayGrouping( pDestTab->rDocument, true );
1328  for (SCCOL i = nCol1; i <= ClampToAllocatedColumns(nCol2); i++)
1329  aCol[i].CopyToColumn(rCxt, nRow1, nRow2, bIsUndoDoc ? nFlags : nTempFlags, bMarked,
1330  pDestTab->CreateColumnIfNotExists(i), pMarkData, bAsLink, bGlobalNamesToLocal);
1331  }
1332 
1333  if (!bColRowFlags) // Column widths/Row heights/Flags
1334  return;
1335 
1336  if(bIsUndoDoc && (nFlags & InsertDeleteFlags::ATTRIB))
1337  {
1338  pDestTab->mpCondFormatList.reset(new ScConditionalFormatList(pDestTab->rDocument, *mpCondFormatList));
1339  }
1340 
1341  if (pDBDataNoName)
1342  {
1343  std::unique_ptr<ScDBData> pNewDBData(new ScDBData(*pDBDataNoName));
1344  SCCOL aCol1, aCol2;
1345  SCROW aRow1, aRow2;
1346  SCTAB aTab;
1347  pNewDBData->GetArea(aTab, aCol1, aRow1, aCol2, aRow2);
1348  pNewDBData->MoveTo(pDestTab->nTab, aCol1, aRow1, aCol2, aRow2);
1349  pDestTab->SetAnonymousDBData(std::move(pNewDBData));
1350  }
1351  // Charts have to be adjusted when hide/show
1353 
1354  bool bFlagChange = false;
1355 
1356  bool bWidth = (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pDestTab->mpColWidth);
1357  bool bHeight = (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pDestTab->mpRowHeights);
1358 
1359  if (bWidth || bHeight)
1360  {
1361  if (bWidth)
1362  {
1363  auto destTabColWidthIt = pDestTab->mpColWidth->begin() + nCol1;
1364  auto thisTabColWidthIt = mpColWidth->begin() + nCol1;
1365  pDestTab->mpColWidth->CopyFrom(*mpColWidth, nCol1, nCol2);
1366  pDestTab->mpColFlags->CopyFrom(*mpColFlags, nCol1, nCol2);
1367  for (SCCOL i = nCol1; i <= nCol2; ++i)
1368  {
1369  bool bThisHidden = ColHidden(i);
1370  bool bHiddenChange = (pDestTab->ColHidden(i) != bThisHidden);
1371  bool bChange = bHiddenChange || (*destTabColWidthIt != *thisTabColWidthIt);
1372  pDestTab->SetColHidden(i, i, bThisHidden);
1373  //TODO: collect changes?
1374  if (bHiddenChange && pCharts)
1375  pCharts->SetRangeDirty(ScRange( i, 0, nTab, i, rDocument.MaxRow(), nTab ));
1376 
1377  if (bChange)
1378  bFlagChange = true;
1379 
1380  ++destTabColWidthIt;
1381  ++thisTabColWidthIt;
1382  }
1383  pDestTab->SetColManualBreaks( std::set(maColManualBreaks) );
1384  }
1385 
1386  if (bHeight)
1387  {
1388  bool bChange = pDestTab->GetRowHeight(nRow1, nRow2) != GetRowHeight(nRow1, nRow2);
1389 
1390  if (bChange)
1391  bFlagChange = true;
1392 
1393  pDestTab->CopyRowHeight(*this, nRow1, nRow2, 0);
1394  pDestTab->pRowFlags->CopyFrom(*pRowFlags, nRow1, nRow2);
1395 
1396  // Hidden flags.
1397  for (SCROW i = nRow1; i <= nRow2; ++i)
1398  {
1399  SCROW nLastRow;
1400  bool bHidden = RowHidden(i, nullptr, &nLastRow);
1401  if (nLastRow >= nRow2)
1402  // the last row shouldn't exceed the upper bound the caller specified.
1403  nLastRow = nRow2;
1404 
1405  bool bHiddenChanged = pDestTab->SetRowHidden(i, nLastRow, bHidden);
1406  if (bHiddenChanged && pCharts)
1407  // Hidden flags differ.
1408  pCharts->SetRangeDirty(ScRange(0, i, nTab, rDocument.MaxCol(), nLastRow, nTab));
1409 
1410  if (bHiddenChanged)
1411  bFlagChange = true;
1412 
1413  // Jump to the last row of the identical flag segment.
1414  i = nLastRow;
1415  }
1416 
1417  // Filtered flags.
1418  for (SCROW i = nRow1; i <= nRow2; ++i)
1419  {
1420  SCROW nLastRow;
1421  bool bFiltered = RowFiltered(i, nullptr, &nLastRow);
1422  if (nLastRow >= nRow2)
1423  // the last row shouldn't exceed the upper bound the caller specified.
1424  nLastRow = nRow2;
1425  pDestTab->SetRowFiltered(i, nLastRow, bFiltered);
1426  i = nLastRow;
1427  }
1428  pDestTab->SetRowManualBreaks( std::set(maRowManualBreaks) );
1429  }
1430  }
1431 
1432  if (bFlagChange)
1433  pDestTab->InvalidatePageBreaks();
1434 
1435  if(nFlags & InsertDeleteFlags::ATTRIB)
1436  {
1437  pDestTab->mpCondFormatList->DeleteArea(nCol1, nRow1, nCol2, nRow2);
1438  pDestTab->CopyConditionalFormat(nCol1, nRow1, nCol2, nRow2, 0, 0, this);
1439  }
1440 
1441  if(nFlags & InsertDeleteFlags::OUTLINE) // also only when bColRowFlags
1442  pDestTab->SetOutlineTable( pOutlineTable.get() );
1443 
1444  if (!bIsUndoDoc && bCopyCaptions && (nFlags & (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES)))
1445  {
1446  bool bCloneCaption = (nFlags & InsertDeleteFlags::NOCAPTIONS) == InsertDeleteFlags::NONE;
1447  CopyCaptionsToTable( nCol1, nRow1, nCol2, nRow2, pDestTab, bCloneCaption);
1448  }
1449 }
1450 
1451 void ScTable::CopyCaptionsToTable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab,
1452  bool bCloneCaption )
1453 {
1454  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
1455  return;
1456 
1457  nCol2 = ClampToAllocatedColumns(nCol2);
1458  for (SCCOL i = nCol1; i <= nCol2; i++)
1459  {
1460  aCol[i].CopyCellNotesToDocument(nRow1, nRow2, pDestTab->CreateColumnIfNotExists(i), bCloneCaption);
1461  pDestTab->aCol[i].UpdateNoteCaptions(nRow1, nRow2);
1462  }
1463 }
1464 
1466  sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1467  InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab )
1468 {
1469  if (!(ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2)))
1470  return;
1471 
1472  bool bWidth = (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pDestTab->mpColWidth);
1473  bool bHeight = (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pDestTab->mpRowHeights);
1474 
1475  if ((nFlags & InsertDeleteFlags::CONTENTS) && mpRangeName)
1476  {
1477  // Undo sheet-local named expressions created during copying
1478  // formulas. If mpRangeName is not set then the Undo wasn't even
1479  // set to an empty ScRangeName map so don't "undo" that.
1480  pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( *GetRangeName())));
1481  if (!pDestTab->rDocument.IsClipOrUndo())
1482  {
1483  ScDocShell* pDocSh = static_cast<ScDocShell*>(pDestTab->rDocument.GetDocumentShell());
1484  if (pDocSh)
1485  pDocSh->SetAreasChangedNeedBroadcast();
1486  }
1487 
1488  }
1489 
1490  for ( SCCOL i = 0; i < aCol.size(); i++)
1491  {
1492  auto& rDestCol = pDestTab->CreateColumnIfNotExists(i);
1493  if ( i >= nCol1 && i <= nCol2 )
1494  aCol[i].UndoToColumn(rCxt, nRow1, nRow2, nFlags, bMarked, rDestCol);
1495  else
1496  aCol[i].CopyToColumn(rCxt, 0, rDocument.MaxRow(), InsertDeleteFlags::FORMULA, false, rDestCol);
1497  }
1498 
1499  if (nFlags & InsertDeleteFlags::ATTRIB)
1500  pDestTab->mpCondFormatList.reset(new ScConditionalFormatList(pDestTab->rDocument, *mpCondFormatList));
1501 
1502  if (!(bWidth||bHeight))
1503  return;
1504 
1505  if (bWidth)
1506  {
1507  pDestTab->mpColWidth->CopyFrom(*mpColWidth, nCol1, nCol2);
1508  pDestTab->SetColManualBreaks( std::set(maColManualBreaks) );
1509  }
1510  if (bHeight)
1511  {
1512  pDestTab->CopyRowHeight(*this, nRow1, nRow2, 0);
1513  pDestTab->SetRowManualBreaks( std::set(maRowManualBreaks) );
1514  }
1515 }
1516 
1517 void ScTable::CopyUpdated( const ScTable* pPosTab, ScTable* pDestTab ) const
1518 {
1519  pPosTab->CreateColumnIfNotExists(aCol.size()-1);
1520  pDestTab->CreateColumnIfNotExists(aCol.size()-1);
1521  for (SCCOL i=0; i < aCol.size(); i++)
1522  aCol[i].CopyUpdated( pPosTab->aCol[i], pDestTab->aCol[i] );
1523 }
1524 
1526 {
1527  bTableAreaValid = false;
1528  bTableAreaVisibleValid = false;
1529 }
1530 
1532 {
1533  mbPageBreaksValid = false;
1534 }
1535 
1536 void ScTable::CopyScenarioTo( const ScTable* pDestTab ) const
1537 {
1538  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1539 
1540  for (SCCOL i=0; i < aCol.size(); i++)
1542 }
1543 
1544 void ScTable::CopyScenarioFrom( const ScTable* pSrcTab )
1545 {
1546  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1547 
1548  SCCOL nEndCol = pSrcTab->aCol.size();
1549  CreateColumnIfNotExists(nEndCol);
1550  for (SCCOL i=0; i < nEndCol; i++)
1551  aCol[i].CopyScenarioFrom( pSrcTab->aCol[i] );
1552 }
1553 
1554 void ScTable::MarkScenarioIn( ScMarkData& rDestMark, ScScenarioFlags nNeededBits ) const
1555 {
1556  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1557 
1558  if ( ( nScenarioFlags & nNeededBits ) != nNeededBits ) // Are all Bits set?
1559  return;
1560 
1561  for (SCCOL i=0; i < aCol.size(); i++)
1562  aCol[i].MarkScenarioIn( rDestMark );
1563 }
1564 
1565 bool ScTable::HasScenarioRange( const ScRange& rRange ) const
1566 {
1567  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1568 
1569  ScRange aTabRange = rRange;
1570  aTabRange.aStart.SetTab( nTab );
1571  aTabRange.aEnd.SetTab( nTab );
1572 
1573  const ScRangeList* pList = GetScenarioRanges();
1574 
1575  if (pList)
1576  {
1577  for ( size_t j = 0, n = pList->size(); j < n; j++ )
1578  {
1579  const ScRange & rR = (*pList)[j];
1580  if ( rR.Intersects( aTabRange ) )
1581  return true;
1582  }
1583  }
1584 
1585  return false;
1586 }
1587 
1589 {
1590  pScenarioRanges.reset();
1591 }
1592 
1594 {
1595  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1596 
1597  if (!pScenarioRanges)
1598  {
1599  const_cast<ScTable*>(this)->pScenarioRanges.reset(new ScRangeList);
1600  ScMarkData aMark(rDocument.GetSheetLimits());
1601  MarkScenarioIn( aMark, ScScenarioFlags::NONE ); // always
1602  aMark.FillRangeListWithMarks( pScenarioRanges.get(), false );
1603  }
1604  return pScenarioRanges.get();
1605 }
1606 
1607 bool ScTable::TestCopyScenarioTo( const ScTable* pDestTab ) const
1608 {
1609  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1610 
1611  if (!pDestTab->IsProtected())
1612  return true;
1613 
1614  bool bOk = true;
1615  for (SCCOL i=0; i < aCol.size() && bOk; i++)
1616  bOk = aCol[i].TestCopyScenarioTo( pDestTab->aCol[i] );
1617  return bOk;
1618 }
1619 
1620 bool ScTable::SetString( SCCOL nCol, SCROW nRow, SCTAB nTabP, const OUString& rString,
1621  const ScSetStringParam * pParam )
1622 {
1623  if (!ValidColRow(nCol,nRow))
1624  {
1625  return false;
1626  }
1627 
1628  return CreateColumnIfNotExists(nCol).SetString(
1629  nRow, nTabP, rString, rDocument.GetAddressConvention(), pParam);
1630 }
1631 
1632 bool ScTable::SetEditText( SCCOL nCol, SCROW nRow, std::unique_ptr<EditTextObject> pEditText )
1633 {
1634  if (!ValidColRow(nCol, nRow))
1635  {
1636  return false;
1637  }
1638 
1639  CreateColumnIfNotExists(nCol).SetEditText(nRow, std::move(pEditText));
1640  return true;
1641 }
1642 
1643 void ScTable::SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool )
1644 {
1645  if (!ValidColRow(nCol, nRow))
1646  return;
1647 
1648  CreateColumnIfNotExists(nCol).SetEditText(nRow, rEditText, pEditPool);
1649 }
1650 
1651 SCROW ScTable::GetFirstEditTextRow( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const
1652 {
1653  if (!ValidCol(nCol1) || !ValidCol(nCol2) || nCol2 < nCol1)
1654  return -1;
1655 
1656  if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow2 < nRow1)
1657  return -1;
1658 
1659  nCol2 = ClampToAllocatedColumns(nCol2);
1660  SCROW nFirst = rDocument.MaxRow()+1;
1661  for (SCCOL i = nCol1; i <= nCol2; ++i)
1662  {
1663  const ScColumn& rCol = aCol[i];
1664  SCROW nThisFirst = -1;
1665  if (const_cast<ScColumn&>(rCol).HasEditCells(nRow1, nRow2, nThisFirst))
1666  {
1667  if (nThisFirst == nRow1)
1668  return nRow1;
1669 
1670  if (nThisFirst < nFirst)
1671  nFirst = nThisFirst;
1672  }
1673  }
1674 
1675  return nFirst == (rDocument.MaxRow()+1) ? -1 : nFirst;
1676 }
1677 
1679 {
1680  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1681  return;
1682 
1683  aCol[nCol].Delete(nRow);
1684 }
1685 
1687  SCCOL nCol, SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
1688 {
1689  if (!ValidColRow(nCol, nRow))
1690  return;
1691 
1692  CreateColumnIfNotExists(nCol).SetFormula(nRow, rArray, eGram);
1693 }
1694 
1696  SCCOL nCol, SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
1697 {
1698  if (!ValidColRow(nCol, nRow))
1699  return;
1700 
1701  CreateColumnIfNotExists(nCol).SetFormula(nRow, rFormula, eGram);
1702 }
1703 
1705 {
1706  if (!ValidColRow(nCol, nRow))
1707  {
1708  delete pCell;
1709  return nullptr;
1710  }
1711 
1713 }
1714 
1715 bool ScTable::SetFormulaCells( SCCOL nCol, SCROW nRow, std::vector<ScFormulaCell*>& rCells )
1716 {
1717  if (!ValidCol(nCol))
1718  return false;
1719 
1720  return CreateColumnIfNotExists(nCol).SetFormulaCells(nRow, rCells);
1721 }
1722 
1724 {
1725  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1726  return svl::SharedString();
1727 
1728  return aCol[nCol].GetSharedString(nRow);
1729 }
1730 
1731 void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal )
1732 {
1733  if (ValidColRow(nCol, nRow))
1734  CreateColumnIfNotExists(nCol).SetValue(nRow, rVal);
1735 }
1736 
1737 void ScTable::SetRawString( SCCOL nCol, SCROW nRow, const svl::SharedString& rStr )
1738 {
1739  if (ValidColRow(nCol, nRow))
1740  CreateColumnIfNotExists(nCol).SetRawString(nRow, rStr);
1741 }
1742 
1743 void ScTable::GetString( SCCOL nCol, SCROW nRow, OUString& rString, const ScInterpreterContext* pContext ) const
1744 {
1745  if (ValidColRow(nCol,nRow) && nCol < GetAllocatedColumnsCount())
1746  aCol[nCol].GetString( nRow, rString, pContext );
1747  else
1748  rString.clear();
1749 }
1750 
1751 double* ScTable::GetValueCell( SCCOL nCol, SCROW nRow )
1752 {
1753  if (!ValidColRow(nCol, nRow))
1754  return nullptr;
1755 
1756  return CreateColumnIfNotExists(nCol).GetValueCell(nRow);
1757 }
1758 
1759 void ScTable::GetInputString( SCCOL nCol, SCROW nRow, OUString& rString ) const
1760 {
1761  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1762  aCol[nCol].GetInputString( nRow, rString );
1763  else
1764  rString.clear();
1765 }
1766 
1767 double ScTable::GetValue( SCCOL nCol, SCROW nRow ) const
1768 {
1769  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1770  return aCol[nCol].GetValue( nRow );
1771  return 0.0;
1772 }
1773 
1775 {
1776  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1777  return nullptr;
1778 
1779  return aCol[nCol].GetEditText(nRow);
1780 }
1781 
1783 {
1784  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1785  return;
1786 
1787  return aCol[nCol].RemoveEditTextCharAttribs(nRow, rAttr);
1788 }
1789 
1790 void ScTable::GetFormula( SCCOL nCol, SCROW nRow, OUString& rFormula ) const
1791 {
1792  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1793  aCol[nCol].GetFormula( nRow, rFormula );
1794  else
1795  rFormula.clear();
1796 }
1797 
1799 {
1800  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1801  return nullptr;
1802 
1803  return aCol[nCol].GetFormulaCell(nRow);
1804 }
1805 
1807 {
1808  if (!ValidColRow(nCol, nRow))
1809  return nullptr;
1810  return CreateColumnIfNotExists(nCol).GetFormulaCell(nRow);
1811 }
1812 
1813 std::unique_ptr<ScPostIt> ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
1814 {
1815  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1816  return nullptr;
1817 
1818  return aCol[nCol].ReleaseNote(nRow);
1819 }
1820 
1821 size_t ScTable::GetNoteCount( SCCOL nCol ) const
1822 {
1823  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1824  return 0;
1825 
1826  return aCol[nCol].GetNoteCount();
1827 }
1828 
1829 SCROW ScTable::GetNotePosition( SCCOL nCol, size_t nIndex ) const
1830 {
1831  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1832  return -1;
1833 
1834  return aCol[nCol].GetNotePosition(nIndex);
1835 }
1836 
1838 {
1839  for (SCCOL i = 0; i < aCol.size(); ++i)
1841 }
1842 
1843 void ScTable::ForgetNoteCaptions( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bPreserveData )
1844 {
1845  if (!ValidCol(nCol1) || !ValidCol(nCol2))
1846  return;
1847  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1848  for (SCCOL i = nCol1; i <= nCol2; ++i)
1849  aCol[i].ForgetNoteCaptions(nRow1, nRow2, bPreserveData);
1850 }
1851 
1852 void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
1853 {
1854  for (SCCOL nCol = 0; nCol < aCol.size(); ++nCol)
1855  aCol[nCol].GetAllNoteEntries(rNotes);
1856 }
1857 
1858 void ScTable::GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const
1859 {
1860  SCROW nStartRow = rRange.aStart.Row();
1861  SCROW nEndRow = rRange.aEnd.Row();
1862  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
1863  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1864  {
1865  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1866  }
1867 }
1868 
1869 CommentCaptionState ScTable::GetAllNoteCaptionsState(const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes )
1870 {
1871  SCROW nStartRow = rRange.aStart.Row();
1872  SCROW nEndRow = rRange.aEnd.Row();
1873  bool bIsFirstNoteShownState = true; // because of error: -Werror=maybe-uninitialized
1874  bool bFirstControl = true;
1875 
1876  ScTable* pTab = rDocument.FetchTable(nTab);
1877  assert(pTab);
1878  const SCCOL nEndCol = pTab->ClampToAllocatedColumns(rRange.aEnd.Col());
1879  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1880  {
1881  if (bFirstControl && rDocument.HasColNotes(nCol, nTab)) // detect status of first note caption
1882  {
1883  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1884  bIsFirstNoteShownState = rNotes.begin()->mpNote->IsCaptionShown();
1885  bFirstControl = false;
1886  }
1887 
1888  if (rDocument.HasColNotes(nCol, nTab))
1889  {
1890  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1891 
1892  bool bIsMixedState = std::any_of(rNotes.begin(), rNotes.end(), [bIsFirstNoteShownState](const sc::NoteEntry& rNote) {
1893  // compare the first note caption with others
1894  return bIsFirstNoteShownState != rNote.mpNote->IsCaptionShown(); });
1895  if (bIsMixedState)
1897  }
1898  }
1899  return bIsFirstNoteShownState ? CommentCaptionState::ALLSHOWN : CommentCaptionState::ALLHIDDEN;
1900 }
1901 
1903 {
1904  for (auto const & pCol : aCol)
1905  pCol->GetUnprotectedCells(0, rDocument.MaxRow(), rRangeList);
1906 }
1907 
1908 bool ScTable::ContainsNotesInRange( const ScRange& rRange ) const
1909 {
1910  SCROW nStartRow = rRange.aStart.Row();
1911  SCROW nEndRow = rRange.aEnd.Row();
1912  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
1913  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1914  {
1915  bool bContainsNote = !aCol[nCol].IsNotesEmptyBlock(nStartRow, nEndRow);
1916  if(bContainsNote)
1917  return true;
1918  }
1919 
1920  return false;
1921 }
1922 
1924 {
1925  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1926  return aCol[nCol].GetCellType( nRow );
1927  return CELLTYPE_NONE;
1928 }
1929 
1931 {
1932  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1933  return ScRefCellValue();
1934 
1935  return aCol[nCol].GetCellValue(nRow);
1936 }
1937 
1938 void ScTable::GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const
1939 {
1940  rCol = 0;
1941  rRow = rDocument.MaxRow()+1;
1942  while (rCol < (aCol.size() - 1) && aCol[rCol].IsEmptyData() )
1943  ++rCol;
1944  SCCOL nCol = rCol;
1945  while (nCol < aCol.size() && rRow > 0)
1946  {
1947  if (!aCol[nCol].IsEmptyData())
1948  rRow = ::std::min( rRow, aCol[nCol].GetFirstDataPos());
1949  ++nCol;
1950  }
1951 }
1952 
1953 void ScTable::GetLastDataPos(SCCOL& rCol, SCROW& rRow) const
1954 {
1955  rCol = aCol.size() - 1;
1956  rRow = 0;
1957  while (aCol[rCol].IsEmptyData() && (rCol > 0))
1958  rCol--;
1959  SCCOL nCol = rCol;
1960  while (nCol >= 0 && rRow < rDocument.MaxRow())
1961  rRow = ::std::max( rRow, aCol[nCol--].GetLastDataPos());
1962 }
1963 
1964 bool ScTable::HasData( SCCOL nCol, SCROW nRow ) const
1965 {
1966  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1967  return aCol[nCol].HasDataAt( nRow );
1968  else
1969  return false;
1970 }
1971 
1972 bool ScTable::HasStringData( SCCOL nCol, SCROW nRow ) const
1973 {
1974  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1975  return aCol[nCol].HasStringData( nRow );
1976  else
1977  return false;
1978 }
1979 
1980 bool ScTable::HasValueData( SCCOL nCol, SCROW nRow ) const
1981 {
1982  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1983  return aCol[nCol].HasValueData( nRow );
1984  else
1985  return false;
1986 }
1987 
1988 bool ScTable::HasStringCells( SCCOL nStartCol, SCROW nStartRow,
1989  SCCOL nEndCol, SCROW nEndRow ) const
1990 {
1991  if (ValidCol(nEndCol))
1992  {
1993  nEndCol = ClampToAllocatedColumns(nEndCol);
1994  for (SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++)
1995  if (aCol[nCol].HasStringCells(nStartRow, nEndRow))
1996  return true;
1997  }
1998 
1999  return false;
2000 }
2001 
2003 {
2004  for (SCCOL i=0; i < aCol.size(); i++)
2005  aCol[i].SetDirtyVar();
2006 }
2007 
2009 {
2010  sc::AutoCalcSwitch aACSwitch(rDocument, false);
2011 
2012  for (SCCOL i = 0; i < aCol.size(); i++)
2014 }
2015 
2017 {
2018  sc::AutoCalcSwitch aACSwitch(rDocument, false);
2019 
2020  for (SCCOL i=0; i < aCol.size(); i++)
2021  aCol[i].SetAllFormulasDirty(rCxt);
2022 }
2023 
2025 {
2026  bool bOldAutoCalc = rDocument.GetAutoCalc();
2027  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
2028  SCCOL nCol2 = rRange.aEnd.Col();
2029  nCol2 = ClampToAllocatedColumns(nCol2);
2030  for (SCCOL i=rRange.aStart.Col(); i<=nCol2; i++)
2031  aCol[i].SetDirty(rRange.aStart.Row(), rRange.aEnd.Row(), eMode);
2032  rDocument.SetAutoCalc( bOldAutoCalc );
2033 }
2034 
2035 void ScTable::SetTableOpDirty( const ScRange& rRange )
2036 {
2037  bool bOldAutoCalc = rDocument.GetAutoCalc();
2038  rDocument.SetAutoCalc( false ); // no multiple recalculation
2039  const SCCOL nCol2 = ClampToAllocatedColumns(rRange.aEnd.Col());
2040  for (SCCOL i=rRange.aStart.Col(); i<=nCol2; i++)
2041  aCol[i].SetTableOpDirty( rRange );
2042  rDocument.SetAutoCalc( bOldAutoCalc );
2043 }
2044 
2046 {
2047  bool bOldAutoCalc = rDocument.GetAutoCalc();
2048  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
2049  for (SCCOL i=0; i < aCol.size(); i++)
2051  rDocument.SetAutoCalc( bOldAutoCalc );
2052 }
2053 
2055 {
2056  bool bOldAutoCalc = rDocument.GetAutoCalc();
2057  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
2058  for (SCCOL i=0; i < aCol.size(); i++)
2060  rDocument.SetAutoCalc( bOldAutoCalc );
2061 }
2062 
2064 {
2065  sc::AutoCalcSwitch aSwitch(rDocument, false);
2066  for (SCCOL i = 0; i < aCol.size(); ++i)
2068 }
2069 
2070 bool ScTable::BroadcastBroadcasters( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScHint& rHint )
2071 {
2072  bool bBroadcasted = false;
2073  sc::AutoCalcSwitch aSwitch(rDocument, false);
2074  rHint.GetAddress().SetTab(nTab);
2075  nCol2 = ClampToAllocatedColumns(nCol2);
2076  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
2077  bBroadcasted |= aCol[nCol].BroadcastBroadcasters( nRow1, nRow2, rHint);
2078  return bBroadcasted;
2079 }
2080 
2081 void ScTable::SetLoadingMedium(bool bLoading)
2082 {
2083  mpRowHeights->enableTreeSearch(!bLoading);
2084 }
2085 
2087 {
2088  for (SCCOL i=0; i < aCol.size(); i++)
2089  aCol[i].CalcAll();
2090 
2091  mpCondFormatList->CalcAll();
2092 }
2093 
2095 {
2096  for (SCCOL i = 0; i < aCol.size(); ++i)
2097  aCol[i].CompileAll(rCxt);
2098 
2099  if(mpCondFormatList)
2100  mpCondFormatList->CompileAll();
2101 }
2102 
2104 {
2105  if (mpRangeName)
2106  mpRangeName->CompileUnresolvedXML(rCxt);
2107 
2108  for (SCCOL i=0; i < aCol.size(); i++)
2109  {
2110  aCol[i].CompileXML(rCxt, rProgress);
2111  }
2112 
2113  if(mpCondFormatList)
2114  mpCondFormatList->CompileXML();
2115 }
2116 
2118 {
2119  bool bCompiled = false;
2120  for (SCCOL i = 0; i < aCol.size(); ++i)
2121  {
2122  if (aCol[i].CompileErrorCells(rCxt, nErrCode))
2123  bCompiled = true;
2124  }
2125 
2126  return bCompiled;
2127 }
2128 
2129 void ScTable::CalcAfterLoad( sc::CompileFormulaContext& rCxt, bool bStartListening )
2130 {
2131  for (SCCOL i = 0; i < aCol.size(); ++i)
2132  aCol[i].CalcAfterLoad(rCxt, bStartListening);
2133 }
2134 
2135 void ScTable::ResetChanged( const ScRange& rRange )
2136 {
2137  SCCOL nStartCol = rRange.aStart.Col();
2138  SCROW nStartRow = rRange.aStart.Row();
2139  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
2140  SCROW nEndRow = rRange.aEnd.Row();
2141 
2142  for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
2143  aCol[nCol].ResetChanged(nStartRow, nEndRow);
2144 }
2145 
2146 // Attribute
2147 
2148 const SfxPoolItem* ScTable::GetAttr( SCCOL nCol, SCROW nRow, sal_uInt16 nWhich ) const
2149 {
2150  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
2151  return &aCol[nCol].GetAttr( nRow, nWhich );
2152  else
2153  return nullptr;
2154 }
2155 
2156 sal_uInt32 ScTable::GetNumberFormat( const ScInterpreterContext& rContext, const ScAddress& rPos ) const
2157 {
2158  if (ValidColRow(rPos.Col(), rPos.Row()))
2159  {
2160  if (rPos.Col() < GetAllocatedColumnsCount())
2161  return aCol[rPos.Col()].GetNumberFormat(rContext, rPos.Row());
2162  return aDefaultColAttrArray.GetPattern(rPos.Row())
2163  ->GetNumberFormat(rContext.GetFormatTable());
2164  }
2165  return 0;
2166 }
2167 
2168 sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nRow ) const
2169 {
2170  if (ValidColRow(nCol,nRow))
2171  return CreateColumnIfNotExists(nCol).GetNumberFormat(rDocument.GetNonThreadedContext(), nRow);
2172  else
2173  return 0;
2174 }
2175 
2176 sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
2177 {
2178  if (!ValidCol(nCol) || !ValidRow(nStartRow) || !ValidRow(nEndRow))
2179  return 0;
2180 
2181  return CreateColumnIfNotExists(nCol).GetNumberFormat(nStartRow, nEndRow);
2182 }
2183 
2184 void ScTable::SetNumberFormat( SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat )
2185 {
2186  if (!ValidColRow(nCol, nRow))
2187  return;
2188 
2189  CreateColumnIfNotExists(nCol).SetNumberFormat(nRow, nNumberFormat);
2190 }
2191 
2192 const ScPatternAttr* ScTable::GetPattern( SCCOL nCol, SCROW nRow ) const
2193 {
2194  if (ValidColRow(nCol,nRow))
2195  return CreateColumnIfNotExists(nCol).GetPattern( nRow );
2196  else
2197  {
2198  OSL_FAIL("wrong column or row");
2199  return rDocument.GetDefPattern(); // for safety
2200  }
2201 }
2202 
2203 const ScPatternAttr* ScTable::GetMostUsedPattern( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
2204 {
2205  if ( ValidColRow( nCol, nStartRow ) && ValidRow( nEndRow ) && (nStartRow <= nEndRow)
2206  && nCol < GetAllocatedColumnsCount())
2207  return aCol[nCol].GetMostUsedPattern( nStartRow, nEndRow );
2208  else
2209  return nullptr;
2210 }
2211 
2212 bool ScTable::HasAttrib( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, HasAttrFlags nMask ) const
2213 {
2214  if ( nCol1 >= aCol.size() )
2215  return false;
2216  if ( nCol2 >= aCol.size() )
2217  nCol2 = aCol.size() - 1; // Rows above range, doesn't contains flags
2218 
2219  bool bFound = false;
2220  for (SCCOL i=nCol1; i<=nCol2 && !bFound; i++)
2221  bFound |= aCol[i].HasAttrib( nRow1, nRow2, nMask );
2222  return bFound;
2223 }
2224 
2225 bool ScTable::HasAttribSelection( const ScMarkData& rMark, HasAttrFlags nMask ) const
2226 {
2227  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2228 
2229  for (const sc::ColRowSpan & aSpan : aSpans)
2230  {
2231  for (SCCOLROW j = aSpan.mnStart; j <= aSpan.mnEnd; ++j)
2232  {
2233  if (aCol[j].HasAttribSelection(rMark, nMask))
2234  return true;
2235  }
2236  }
2237  return false;
2238 }
2239 
2240 bool ScTable::ExtendMerge( SCCOL nStartCol, SCROW nStartRow,
2241  SCCOL& rEndCol, SCROW& rEndRow,
2242  bool bRefresh )
2243 {
2244  if (!(ValidCol(nStartCol) && ValidCol(rEndCol)))
2245  {
2246  OSL_FAIL("ScTable::ExtendMerge: invalid column number");
2247  return false;
2248  }
2249  if ( nStartCol >= aCol.size() )
2250  {
2251  OSL_FAIL("ScTable::ExtendMerge: invalid nStartCol");
2252  return false;
2253  }
2254  bool bFound = false;
2255  SCCOL nOldEndX = std::min( rEndCol, static_cast<SCCOL>(aCol.size()-1) );
2256  SCROW nOldEndY = rEndRow;
2257  for (SCCOL i=nStartCol; i<=nOldEndX; i++)
2258  bFound |= aCol[i].ExtendMerge( i, nStartRow, nOldEndY, rEndCol, rEndRow, bRefresh );
2259  return bFound;
2260 }
2261 
2262 void ScTable::SetMergedCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
2263 {
2264  ScMergeAttr aAttr(nCol2-nCol1+1, nRow2-nRow1+1);
2265  ApplyAttr(nCol1, nRow1, aAttr);
2266 
2267  if (nCol1 < nCol2)
2268  ApplyFlags(nCol1+1, nRow1, nCol2, nRow2, ScMF::Hor);
2269 
2270  if (nRow1 < nRow2)
2271  ApplyFlags(nCol1, nRow1+1, nCol1, nRow2, ScMF::Ver);
2272 
2273  if (nCol1 < nCol2 && nRow1 < nRow2)
2274  ApplyFlags(nCol1+1, nRow1+1, nCol2, nRow2, ScMF::Hor | ScMF::Ver);
2275 }
2276 
2277 bool ScTable::IsBlockEmpty( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bIgnoreNotes ) const
2278 {
2279  if (!(ValidCol(nCol1) && ValidCol(nCol2)))
2280  {
2281  OSL_FAIL("ScTable::IsBlockEmpty: invalid column number");
2282  return false;
2283  }
2284  nCol2 = ClampToAllocatedColumns(nCol2);
2285  bool bEmpty = true;
2286  for (SCCOL i=nCol1; i<=nCol2 && bEmpty; i++)
2287  {
2288  bEmpty = aCol[i].IsEmptyBlock( nRow1, nRow2 );
2289  if (!bIgnoreNotes && bEmpty)
2290  {
2291  bEmpty = aCol[i].IsNotesEmptyBlock(nRow1, nRow2);
2292  }
2293  }
2294  return bEmpty;
2295 }
2296 
2297 SCSIZE ScTable::FillMaxRot( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2,
2298  SCCOL nCol, SCROW nAttrRow1, SCROW nAttrRow2, SCSIZE nArrY,
2299  const ScPatternAttr* pPattern, const SfxItemSet* pCondSet )
2300 {
2301  // Return value = new nArrY
2302 
2303  ScRotateDir nRotDir = pPattern->GetRotateDir( pCondSet );
2304  if ( nRotDir != ScRotateDir::NONE )
2305  {
2306  bool bHit = true;
2307  if ( nCol+1 < nX1 ) // column to the left
2308  bHit = ( nRotDir != ScRotateDir::Left );
2309  else if ( nCol > nX2+1 ) // column to the right
2310  bHit = ( nRotDir != ScRotateDir::Right ); // ScRotateDir::Standard may now also be extended to the left
2311 
2312  if ( bHit )
2313  {
2314  double nFactor = 0.0;
2315  if ( nCol > nX2+1 )
2316  {
2317  Degree100 nRotVal = pPattern->
2318  GetItem( ATTR_ROTATE_VALUE, pCondSet ).GetValue();
2319  double nRealOrient = nRotVal.get() * F_PI18000; // 1/100 degree
2320  double nCos = cos( nRealOrient );
2321  double nSin = sin( nRealOrient );
2322  //TODO: limit !!!
2323  //TODO: additional factor for varying PPT X/Y !!!
2324 
2325  // for ScRotateDir::Left this gives a negative value,
2326  // if the mode is considered
2327  nFactor = -fabs( nCos / nSin );
2328  }
2329 
2330  for ( SCROW nRow = nAttrRow1; nRow <= nAttrRow2; nRow++ )
2331  {
2332  if (!RowHidden(nRow))
2333  {
2334  bool bHitOne = true;
2335  if ( nCol > nX2+1 )
2336  {
2337  // Does the rotated cell extend into the visible range?
2338 
2339  SCCOL nTouchedCol = nCol;
2340  tools::Long nWidth = static_cast<tools::Long>(mpRowHeights->getValue(nRow) * nFactor);
2341  OSL_ENSURE(nWidth <= 0, "Wrong direction");
2342  while ( nWidth < 0 && nTouchedCol > 0 )
2343  {
2344  --nTouchedCol;
2345  nWidth += GetColWidth( nTouchedCol );
2346  }
2347  if ( nTouchedCol > nX2 )
2348  bHitOne = false;
2349  }
2350 
2351  if (bHitOne)
2352  {
2353  while ( nArrY<nArrCount && pRowInfo[nArrY].nRowNo < nRow )
2354  ++nArrY;
2355  if ( nArrY<nArrCount && pRowInfo[nArrY].nRowNo == nRow )
2356  pRowInfo[nArrY].nRotMaxCol = nCol;
2357  }
2358  }
2359  }
2360  }
2361  }
2362 
2363  return nArrY;
2364 }
2365 
2366 void ScTable::FindMaxRotCol( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2 )
2367 {
2368  if ( !mpColWidth || !mpRowHeights || !mpColFlags || !pRowFlags )
2369  {
2370  OSL_FAIL( "Row/column info missing" );
2371  return;
2372  }
2373 
2374  // nRotMaxCol is initialized to SC_ROTMAX_NONE, nRowNo is already set
2375 
2376  SCROW nY1 = pRowInfo[0].nRowNo;
2377  SCROW nY2 = pRowInfo[nArrCount-1].nRowNo;
2378 
2379  for (SCCOL nCol : GetColumnsRange(0, rDocument.MaxCol()))
2380  {
2381  if (!ColHidden(nCol))
2382  {
2383  SCSIZE nArrY = 0;
2384  ScDocAttrIterator aIter( rDocument, nTab, nCol, nY1, nCol, nY2 );
2385  SCCOL nAttrCol;
2386  SCROW nAttrRow1, nAttrRow2;
2387  const ScPatternAttr* pPattern = aIter.GetNext( nAttrCol, nAttrRow1, nAttrRow2 );
2388  while ( pPattern )
2389  {
2390  const SfxPoolItem* pCondItem;
2391  if ( pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, true, &pCondItem )
2392  == SfxItemState::SET )
2393  {
2394  // Run through all formats, so that each cell does not have to be
2395  // handled individually
2396 
2397  const ScCondFormatIndexes& rCondFormatData = static_cast<const ScCondFormatItem*>(pCondItem)->GetCondFormatData();
2398  ScStyleSheetPool* pStylePool = rDocument.GetStyleSheetPool();
2399  if (mpCondFormatList && pStylePool && !rCondFormatData.empty())
2400  {
2401  for(const auto& rItem : rCondFormatData)
2402  {
2403  const ScConditionalFormat* pFormat = mpCondFormatList->GetFormat(rItem);
2404  if ( pFormat )
2405  {
2406  size_t nEntryCount = pFormat->size();
2407  for (size_t nEntry=0; nEntry<nEntryCount; nEntry++)
2408  {
2409  const ScFormatEntry* pEntry = pFormat->GetEntry(nEntry);
2410  if(pEntry->GetType() != ScFormatEntry::Type::Condition &&
2412  continue;
2413 
2414  OUString aStyleName = static_cast<const ScCondFormatEntry*>(pEntry)->GetStyle();
2415  if (!aStyleName.isEmpty())
2416  {
2417  SfxStyleSheetBase* pStyleSheet =
2418  pStylePool->Find( aStyleName, SfxStyleFamily::Para );
2419  if ( pStyleSheet )
2420  {
2421  FillMaxRot( pRowInfo, nArrCount, nX1, nX2,
2422  nCol, nAttrRow1, nAttrRow2,
2423  nArrY, pPattern, &pStyleSheet->GetItemSet() );
2424  // not changing nArrY
2425  }
2426  }
2427  }
2428  }
2429  }
2430  }
2431  }
2432 
2433  nArrY = FillMaxRot( pRowInfo, nArrCount, nX1, nX2,
2434  nCol, nAttrRow1, nAttrRow2,
2435  nArrY, pPattern, nullptr );
2436 
2437  pPattern = aIter.GetNext( nAttrCol, nAttrRow1, nAttrRow2 );
2438  }
2439  }
2440  }
2441 }
2442 
2443 bool ScTable::HasBlockMatrixFragment( const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2,
2444  bool bNoMatrixAtAll ) const
2445 {
2446  using namespace sc;
2447 
2448  if ( !IsColValid( nCol1 ) )
2449  return false;
2450 
2451  const SCCOL nMaxCol2 = std::min<SCCOL>( nCol2, aCol.size() - 1 );
2452 
2453  MatrixEdge nEdges = MatrixEdge::Nothing;
2454 
2455  if ( nCol1 == nMaxCol2 )
2456  { // left and right column
2458  nEdges = aCol[nCol1].GetBlockMatrixEdges( nRow1, nRow2, n, bNoMatrixAtAll );
2459  if ((nEdges != MatrixEdge::Nothing) && (((nEdges & n)!=n) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2460  return true; // left or right edge is missing or open
2461  }
2462  else
2463  { // left column
2464  nEdges = aCol[nCol1].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Left, bNoMatrixAtAll);
2465  if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Left)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2466  return true; // left edge missing or open
2467  // right column
2468  nEdges = aCol[nMaxCol2].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Right, bNoMatrixAtAll);
2469  if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Right)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2470  return true; // right edge is missing or open
2471  }
2472 
2473  if (bNoMatrixAtAll)
2474  {
2475  for (SCCOL i=nCol1; i<=nMaxCol2; i++)
2476  {
2477  nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow2, MatrixEdge::Nothing, bNoMatrixAtAll);
2478  if (nEdges != MatrixEdge::Nothing
2479  && (nEdges != (MatrixEdge::Top | MatrixEdge::Left | MatrixEdge::Bottom | MatrixEdge::Right)))
2480  return true;
2481  }
2482  }
2483  else if ( nRow1 == nRow2 )
2484  { // Row on top and on bottom
2485  bool bOpen = false;
2486  const MatrixEdge n = MatrixEdge::Bottom | MatrixEdge::Top;
2487  for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
2488  {
2489  nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow1, n, bNoMatrixAtAll );
2490  if (nEdges != MatrixEdge::Nothing)
2491  {
2492  if ( (nEdges & n) != n )
2493  return true; // Top or bottom edge missing
2494  if (nEdges & MatrixEdge::Left)
2495  bOpen = true; // left edge open, continue
2496  else if ( !bOpen )
2497  return true; // Something exist that has not been opened
2498  if (nEdges & MatrixEdge::Right)
2499  bOpen = false; // Close right edge
2500  }
2501  }
2502  if ( bOpen )
2503  return true;
2504  }
2505  else
2506  {
2507  int j;
2508  MatrixEdge n;
2509  SCROW nR;
2510  // first top row, then bottom row
2511  for ( j=0, n = MatrixEdge::Top, nR=nRow1; j<2;
2512  j++, n = MatrixEdge::Bottom, nR=nRow2)
2513  {
2514  bool bOpen = false;
2515  for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
2516  {
2517  nEdges = aCol[i].GetBlockMatrixEdges( nR, nR, n, bNoMatrixAtAll );
2518  if ( nEdges != MatrixEdge::Nothing)
2519  {
2520  // in top row no top edge respectively
2521  // in bottom row no bottom edge
2522  if ( (nEdges & n) != n )
2523  return true;
2524  if (nEdges & MatrixEdge::Left)
2525  bOpen = true; // open left edge, continue
2526  else if ( !bOpen )
2527  return true; // Something exist that has not been opened
2528  if (nEdges & MatrixEdge::Right)
2529  bOpen = false; // Close right edge
2530  }
2531  }
2532  if ( bOpen )
2533  return true;
2534  }
2535  }
2536  return false;
2537 }
2538 
2540 {
2541  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2542 
2543  for (const sc::ColRowSpan & aSpan : aSpans)
2544  {
2545  SCCOL nEndCol = ClampToAllocatedColumns(aSpan.mnEnd);
2546  for ( SCCOLROW j=aSpan.mnStart; j<=nEndCol; j++ )
2547  {
2548  if ( aCol[j].HasSelectionMatrixFragment(rMark) )
2549  return true;
2550  }
2551  }
2552  return false;
2553 }
2554 
2555 bool ScTable::IsBlockEditable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2,
2556  SCROW nRow2, bool* pOnlyNotBecauseOfMatrix /* = NULL */,
2557  bool bNoMatrixAtAll ) const
2558 {
2559  if ( !ValidColRow( nCol2, nRow2 ) )
2560  {
2561  SAL_WARN("sc", "IsBlockEditable: invalid column or row " << nCol2 << " " << nRow2);
2562  if (pOnlyNotBecauseOfMatrix)
2563  *pOnlyNotBecauseOfMatrix = false;
2564  return false;
2565  }
2566  nCol1 = ClampToAllocatedColumns(nCol1);
2567  nCol2 = ClampToAllocatedColumns(nCol2);
2568 
2569  bool bIsEditable = true;
2570  if ( nLockCount )
2571  bIsEditable = false;
2572  else if ( IsProtected() && !rDocument.IsScenario(nTab) )
2573  {
2574  bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, HasAttrFlags::Protected );
2575  if (!bIsEditable)
2576  {
2577  // An enhanced protection permission may override the attribute.
2578  if (pTabProtection)
2579  bIsEditable = pTabProtection->isBlockEditable( ScRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab));
2580  }
2581  if (bIsEditable)
2582  {
2583  // If Sheet is protected and cells are not protected then
2584  // check the active scenario protect flag if this range is
2585  // on the active scenario range. Note the 'copy back' must also
2586  // be set to apply protection.
2587  sal_uInt16 nScenTab = nTab+1;
2588  while(rDocument.IsScenario(nScenTab))
2589  {
2590  ScRange aEditRange(nCol1, nRow1, nScenTab, nCol2, nRow2, nScenTab);
2591  if(rDocument.IsActiveScenario(nScenTab) && rDocument.HasScenarioRange(nScenTab, aEditRange))
2592  {
2593  ScScenarioFlags nFlags;
2594  rDocument.GetScenarioFlags(nScenTab,nFlags);
2595  bIsEditable = !((nFlags & ScScenarioFlags::Protected) && (nFlags & ScScenarioFlags::TwoWay));
2596  break;
2597  }
2598  nScenTab++;
2599  }
2600  }
2601  }
2602  else if (rDocument.IsScenario(nTab))
2603  {
2604  // Determine if the preceding sheet is protected
2605  SCTAB nActualTab = nTab;
2606  do
2607  {
2608  nActualTab--;
2609  }
2610  while(rDocument.IsScenario(nActualTab));
2611 
2612  if(rDocument.IsTabProtected(nActualTab))
2613  {
2614  ScRange aEditRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab);
2615  if(rDocument.HasScenarioRange(nTab, aEditRange))
2616  {
2617  ScScenarioFlags nFlags;
2618  rDocument.GetScenarioFlags(nTab,nFlags);
2619  bIsEditable = !(nFlags & ScScenarioFlags::Protected);
2620  }
2621  }
2622  }
2623  if ( bIsEditable )
2624  {
2625  if (HasBlockMatrixFragment( nCol1, nRow1, nCol2, nRow2, bNoMatrixAtAll))
2626  {
2627  bIsEditable = false;
2628  if ( pOnlyNotBecauseOfMatrix )
2629  *pOnlyNotBecauseOfMatrix = true;
2630  }
2631  else if ( pOnlyNotBecauseOfMatrix )
2632  *pOnlyNotBecauseOfMatrix = false;
2633  }
2634  else if ( pOnlyNotBecauseOfMatrix )
2635  *pOnlyNotBecauseOfMatrix = false;
2636  return bIsEditable;
2637 }
2638 
2640  bool* pOnlyNotBecauseOfMatrix /* = NULL */ ) const
2641 {
2642  bool bIsEditable = true;
2643  if ( nLockCount )
2644  bIsEditable = false;
2645  else if ( IsProtected() && !rDocument.IsScenario(nTab) )
2646  {
2647  ScRangeList aRanges;
2648  rMark.FillRangeListWithMarks( &aRanges, false );
2649  bIsEditable = !HasAttribSelection( rMark, HasAttrFlags::Protected );
2650  if (!bIsEditable)
2651  {
2652  // An enhanced protection permission may override the attribute.
2653  if (pTabProtection)
2654  bIsEditable = pTabProtection->isSelectionEditable( aRanges);
2655  }
2656  if (bIsEditable)
2657  {
2658  // If Sheet is protected and cells are not protected then
2659  // check the active scenario protect flag if this area is
2660  // in the active scenario range.
2661  SCTAB nScenTab = nTab+1;
2662  while(rDocument.IsScenario(nScenTab) && bIsEditable)
2663  {
2664  if(rDocument.IsActiveScenario(nScenTab))
2665  {
2666  for (size_t i=0, nRange = aRanges.size(); (i < nRange) && bIsEditable; i++ )
2667  {
2668  const ScRange & rRange = aRanges[ i ];
2669  if(rDocument.HasScenarioRange(nScenTab, rRange))
2670  {
2671  ScScenarioFlags nFlags;
2672  rDocument.GetScenarioFlags(nScenTab,nFlags);
2673  bIsEditable = !((nFlags & ScScenarioFlags::Protected) && (nFlags & ScScenarioFlags::TwoWay));
2674  }
2675  }
2676  }
2677  nScenTab++;
2678  }
2679  }
2680  }
2681  else if (rDocument.IsScenario(nTab))
2682  {
2683  // Determine if the preceding sheet is protected
2684  SCTAB nActualTab = nTab;
2685  do
2686  {
2687  nActualTab--;
2688  }
2689  while(rDocument.IsScenario(nActualTab));
2690 
2691  if(rDocument.IsTabProtected(nActualTab))
2692  {
2693  ScRangeList aRanges;
2694  rMark.FillRangeListWithMarks( &aRanges, false );
2695  for (size_t i = 0, nRange = aRanges.size(); (i < nRange) && bIsEditable; i++)
2696  {
2697  const ScRange & rRange = aRanges[ i ];
2698  if(rDocument.HasScenarioRange(nTab, rRange))
2699  {
2700  ScScenarioFlags nFlags;
2701  rDocument.GetScenarioFlags(nTab,nFlags);
2702  bIsEditable = !(nFlags & ScScenarioFlags::Protected);
2703  }
2704  }
2705  }
2706  }
2707  if ( bIsEditable )
2708  {
2709  if ( HasSelectionMatrixFragment( rMark ) )
2710  {
2711  bIsEditable = false;
2712  if ( pOnlyNotBecauseOfMatrix )
2713  *pOnlyNotBecauseOfMatrix = true;
2714  }
2715  else if ( pOnlyNotBecauseOfMatrix )
2716  *pOnlyNotBecauseOfMatrix = false;
2717  }
2718  else if ( pOnlyNotBecauseOfMatrix )
2719  *pOnlyNotBecauseOfMatrix = false;
2720  return bIsEditable;
2721 }
2722 
2724 {
2725  ++nLockCount;
2726 }
2727 
2729 {
2730  if (nLockCount)
2731  --nLockCount;
2732  else
2733  {
2734  OSL_FAIL("UnlockTable without LockTable");
2735  }
2736 }
2737 
2738 void ScTable::MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, bool bDeep ) const
2739 {
2740  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2741 
2742  for (const sc::ColRowSpan & rSpan : aSpans)
2743  {
2744  for (SCCOLROW i = rSpan.mnStart; i <= rSpan.mnEnd; ++i)
2745  {
2746  CreateColumnIfNotExists(i).MergeSelectionPattern( rState, rMark, bDeep );
2747  }
2748  }
2749 }
2750 
2752  SCCOL nCol2, SCROW nRow2, bool bDeep ) const
2753 {
2754  nCol2 = ClampToAllocatedColumns(nCol2);
2755  for (SCCOL i=nCol1; i<=nCol2; i++)
2756  aCol[i].MergePatternArea( rState, nRow1, nRow2, bDeep );
2757 }
2758 
2759 void ScTable::MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags,
2760  SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const
2761 {
2762  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2763  {
2764  PutInOrder(nStartCol, nEndCol);
2765  PutInOrder(nStartRow, nEndRow);
2766  nEndCol = ClampToAllocatedColumns(nEndCol);
2767  for (SCCOL i=nStartCol; i<=nEndCol; i++)
2768  aCol[i].MergeBlockFrame( pLineOuter, pLineInner, rFlags,
2769  nStartRow, nEndRow, (i==nStartCol), nEndCol-i );
2770  }
2771 }
2772 
2773 void ScTable::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
2774  SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
2775 {
2776  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2777  {
2778  PutInOrder(nStartCol, nEndCol);
2779  PutInOrder(nStartRow, nEndRow);
2780  nEndCol = ClampToAllocatedColumns(nEndCol);
2781  for (SCCOL i=nStartCol; i<=nEndCol; i++)
2782  aCol[i].ApplyBlockFrame(rLineOuter, pLineInner,
2783  nStartRow, nEndRow, (i==nStartCol), nEndCol-i);
2784  }
2785 }
2786 
2787 void ScTable::ApplyPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr )
2788 {
2789  if (ValidColRow(nCol,nRow))
2790  CreateColumnIfNotExists(nCol).ApplyPattern( nRow, rAttr );
2791 }
2792 
2793 void ScTable::ApplyPatternArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2794  const ScPatternAttr& rAttr, ScEditDataArray* pDataArray,
2795  bool* const pIsChanged )
2796 {
2797  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2798  {
2799  PutInOrder(nStartCol, nEndCol);
2800  PutInOrder(nStartRow, nEndRow);
2801  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2802  CreateColumnIfNotExists(i).ApplyPatternArea(nStartRow, nEndRow, rAttr, pDataArray, pIsChanged);
2803  }
2804 }
2805 
2807  const ScPatternAttr& rPattern, SvNumFormatType nNewType )
2808 {
2809  SCCOL nEndCol = rRange.aEnd.Col();
2810  for ( SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; nCol++ )
2811  {
2812  aCol[nCol].ApplyPatternIfNumberformatIncompatible( rRange, rPattern, nNewType );
2813  }
2814 }
2815 
2816 void ScTable::AddCondFormatData( const ScRangeList& rRangeList, sal_uInt32 nIndex )
2817 {
2818  size_t n = rRangeList.size();
2819  for(size_t i = 0; i < n; ++i)
2820  {
2821  const ScRange & rRange = rRangeList[i];
2822  SCCOL nColStart = rRange.aStart.Col();
2823  SCCOL nColEnd = rRange.aEnd.Col();
2824  SCROW nRowStart = rRange.aStart.Row();
2825  SCROW nRowEnd = rRange.aEnd.Row();
2826  for(SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
2827  {
2828  CreateColumnIfNotExists(nCol).AddCondFormat(nRowStart, nRowEnd, nIndex);
2829  }
2830  }
2831 }
2832 
2833 void ScTable::RemoveCondFormatData( const ScRangeList& rRangeList, sal_uInt32 nIndex )
2834 {
2835  size_t n = rRangeList.size();
2836  for(size_t i = 0; i < n; ++i)
2837  {
2838  const ScRange & rRange = rRangeList[i];
2839  SCCOL nColStart = rRange.aStart.Col();
2840  SCCOL nColEnd = ClampToAllocatedColumns(rRange.aEnd.Col());
2841  SCROW nRowStart = rRange.aStart.Row();
2842  SCROW nRowEnd = rRange.aEnd.Row();
2843  for(SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
2844  {
2845  aCol[nCol].RemoveCondFormat(nRowStart, nRowEnd, nIndex);
2846  }
2847  }
2848 }
2849 
2850 void ScTable::SetPatternAreaCondFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow,
2851  const ScPatternAttr& rAttr, const ScCondFormatIndexes& rCondFormatIndexes )
2852 {
2853  aCol[nCol].SetPatternArea( nStartRow, nEndRow, rAttr);
2854 
2855  for (const auto& rIndex : rCondFormatIndexes)
2856  {
2857  ScConditionalFormat* pCondFormat = mpCondFormatList->GetFormat(rIndex);
2858  if (pCondFormat)
2859  {
2860  ScRangeList aRange = pCondFormat->GetRange();
2861  aRange.Join( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab));
2862  pCondFormat->SetRange(aRange);
2863  }
2864  }
2865 }
2866 
2867 void ScTable::ApplyStyle( SCCOL nCol, SCROW nRow, const ScStyleSheet* rStyle )
2868 {
2869  if (ValidColRow(nCol,nRow))
2870  // If column not exists then we need to create it
2871  CreateColumnIfNotExists( nCol ).ApplyStyle( nRow, rStyle );
2872 }
2873 
2874 void ScTable::ApplyStyleArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScStyleSheet& rStyle )
2875 {
2876  if (!(ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow)))
2877  return;
2878 
2879  PutInOrder(nStartCol, nEndCol);
2880  PutInOrder(nStartRow, nEndRow);
2881  if ( nEndCol == rDocument.MaxCol() )
2882  {
2883  if ( nStartCol < aCol.size() )
2884  {
2885  // If we would like set all columns to specific style, then change only default style for not existing columns
2886  nEndCol = aCol.size() - 1;
2887  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2888  aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
2889  aDefaultColAttrArray.ApplyStyleArea(nStartRow, nEndRow, rStyle );
2890  }
2891  else
2892  {
2893  CreateColumnIfNotExists( nStartCol - 1 );
2894  aDefaultColAttrArray.ApplyStyleArea(nStartRow, nEndRow, rStyle );
2895  }
2896  }
2897  else
2898  {
2899  CreateColumnIfNotExists( nEndCol );
2900  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2901  aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
2902  }
2903 }
2904 
2905 void ScTable::ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark)
2906 {
2907  for (SCCOL i=0; i < aCol.size(); i++)
2908  aCol[i].ApplySelectionStyle( rStyle, rMark );
2909 }
2910 
2912  const ::editeng::SvxBorderLine* pLine, bool bColorOnly )
2913 {
2914  if ( bColorOnly && !pLine )
2915  return;
2916 
2917  for (SCCOL i=0; i < aCol.size(); i++)
2918  aCol[i].ApplySelectionLineStyle( rMark, pLine, bColorOnly );
2919 }
2920 
2921 const ScStyleSheet* ScTable::GetStyle( SCCOL nCol, SCROW nRow ) const
2922 {
2923  if ( !ValidColRow( nCol, nRow ) )
2924  return nullptr;
2925  if ( nCol < aCol.size() )
2926  return aCol[nCol].GetStyle( nRow );
2927  else
2928  return aDefaultColAttrArray.GetPattern( nRow )->GetStyleSheet();
2929 }
2930 
2931 const ScStyleSheet* ScTable::GetSelectionStyle( const ScMarkData& rMark, bool& rFound ) const
2932 {
2933  rFound = false;
2934 
2935  bool bEqual = true;
2936  bool bColFound;
2937 
2938  const ScStyleSheet* pStyle = nullptr;
2939  const ScStyleSheet* pNewStyle;
2940 
2941  for (SCCOL i=0; i < aCol.size() && bEqual; i++)
2942  if (rMark.HasMultiMarks(i))
2943  {
2944  pNewStyle = aCol[i].GetSelectionStyle( rMark, bColFound );
2945  if (bColFound)
2946  {
2947  rFound = true;
2948  if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
2949  bEqual = false;
2950  pStyle = pNewStyle;
2951  }
2952  }
2953 
2954  return bEqual ? pStyle : nullptr;
2955 }
2956 
2957 const ScStyleSheet* ScTable::GetAreaStyle( bool& rFound, SCCOL nCol1, SCROW nRow1,
2958  SCCOL nCol2, SCROW nRow2 ) const
2959 {
2960  rFound = false;
2961 
2962  bool bEqual = true;
2963  bool bColFound;
2964 
2965  const ScStyleSheet* pStyle = nullptr;
2966  const ScStyleSheet* pNewStyle;
2967  nCol2 = ClampToAllocatedColumns(nCol2);
2968  for (SCCOL i=nCol1; i<=nCol2 && bEqual; i++)
2969  {
2970  pNewStyle = aCol[i].GetAreaStyle(bColFound, nRow1, nRow2);
2971  if (bColFound)
2972  {
2973  rFound = true;
2974  if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
2975  bEqual = false;
2976  pStyle = pNewStyle;
2977  }
2978  }
2979 
2980  return bEqual ? pStyle : nullptr;
2981 }
2982 
2983 bool ScTable::IsStyleSheetUsed( const ScStyleSheet& rStyle ) const
2984 {
2985  bool bIsUsed = false;
2986 
2987  for ( SCCOL i=0; i < aCol.size(); i++ )
2988  {
2989  if ( aCol[i].IsStyleSheetUsed( rStyle ) )
2990  {
2991  bIsUsed = true;
2992  }
2993  }
2994 
2995  return bIsUsed;
2996 }
2997 
2998 void ScTable::StyleSheetChanged( const SfxStyleSheetBase* pStyleSheet, bool bRemoved,
2999  OutputDevice* pDev,
3000  double nPPTX, double nPPTY,
3001  const Fraction& rZoomX, const Fraction& rZoomY )
3002 {
3003  ScFlatBoolRowSegments aUsedRows(rDocument.MaxRow());
3004  for (SCCOL i = 0; i < aCol.size(); ++i)
3005  aCol[i].FindStyleSheet(pStyleSheet, aUsedRows, bRemoved);
3006 
3007  sc::RowHeightContext aCxt(rDocument.MaxRow(), nPPTX, nPPTY, rZoomX, rZoomY, pDev);
3008  SCROW nRow = 0;
3009  while (nRow <= rDocument.MaxRow())
3010  {
3012  if (!aUsedRows.getRangeData(nRow, aData))
3013  // search failed!
3014  return;
3015 
3016  SCROW nEndRow = aData.mnRow2;
3017  if (aData.mbValue)
3018  SetOptimalHeight(aCxt, nRow, nEndRow, true);
3019 
3020  nRow = nEndRow + 1;
3021  }
3022 }
3023 
3024 bool ScTable::ApplyFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
3025  ScMF nFlags )
3026 {
3027  bool bChanged = false;
3028  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
3029  for (SCCOL i = nStartCol; i <= nEndCol; i++)
3030  bChanged |= CreateColumnIfNotExists(i).ApplyFlags(nStartRow, nEndRow, nFlags);
3031  return bChanged;
3032 }
3033 
3034 bool ScTable::RemoveFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
3035  ScMF nFlags )
3036 {
3037  if (!ValidColRow(nStartCol, nStartRow) || !ValidColRow(nEndCol, nEndRow))
3038  return false;
3039  bool bChanged = false;
3040  nEndCol = ClampToAllocatedColumns(nEndCol);
3041  for (SCCOL i = nStartCol; i <= nEndCol; i++)
3042  bChanged |= aCol[i].RemoveFlags(nStartRow, nEndRow, nFlags);
3043  return bChanged;
3044 }
3045 
3046 void ScTable::SetPattern( const ScAddress& rPos, const ScPatternAttr& rAttr )
3047 {
3048  if (ValidColRow(rPos.Col(),rPos.Row()))
3049  CreateColumnIfNotExists(rPos.Col()).SetPattern(rPos.Row(), rAttr);
3050 }
3051 
3052 const ScPatternAttr* ScTable::SetPattern( SCCOL nCol, SCROW nRow, std::unique_ptr<ScPatternAttr> pAttr )
3053 {
3054  if (ValidColRow(nCol,nRow))
3055  return CreateColumnIfNotExists(nCol).SetPattern(nRow, std::move(pAttr));
3056  return nullptr;
3057 }
3058 
3059 void ScTable::SetPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr )
3060 {
3061  if (ValidColRow(nCol,nRow))
3062  CreateColumnIfNotExists(nCol).SetPattern(nRow, rAttr);
3063 }
3064 
3065 void ScTable::ApplyAttr( SCCOL nCol, SCROW nRow, const SfxPoolItem& rAttr )
3066 {
3067  if (ValidColRow(nCol,nRow))
3068  CreateColumnIfNotExists(nCol).ApplyAttr( nRow, rAttr );
3069 }
3070 
3072  ScEditDataArray* pDataArray, bool* const pIsChanged )
3073 {
3074  for (SCCOL i=0; i < aCol.size(); i++)
3075  aCol[i].ApplySelectionCache( pCache, rMark, pDataArray, pIsChanged );
3076 }
3077 
3078 void ScTable::ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark )
3079 {
3080  for (SCCOL i=0; i < aCol.size(); i++)
3081  aCol[i].ChangeSelectionIndent( bIncrement, rMark );
3082 }
3083 
3084 void ScTable::ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark )
3085 {
3086  for (SCCOL i=0; i < aCol.size(); i++)
3087  aCol[i].ClearSelectionItems( pWhich, rMark );
3088 }
3089 
3090 // Column widths / Row heights
3091 
3092 void ScTable::SetColWidth( SCCOL nCol, sal_uInt16 nNewWidth )
3093 {
3094  if (ValidCol(nCol) && mpColWidth)
3095  {
3096  if (!nNewWidth)
3097  {
3098  nNewWidth = STD_COL_WIDTH;
3099  }
3100 
3101  if ( nNewWidth != mpColWidth->GetValue(nCol) )
3102  {
3103  mpColWidth->SetValue(nCol, nNewWidth);
3105  }
3106  }
3107  else
3108  {
3109  OSL_FAIL("Invalid column number or no widths");
3110  }
3111 }
3112 
3113 void ScTable::SetColWidthOnly( SCCOL nCol, sal_uInt16 nNewWidth )
3114 {
3115  if (!ValidCol(nCol) || !mpColWidth)
3116  return;
3117 
3118  if (!nNewWidth)
3119  nNewWidth = STD_COL_WIDTH;
3120 
3121  if (nNewWidth != mpColWidth->GetValue(nCol))
3122  mpColWidth->SetValue(nCol, nNewWidth);
3123 }
3124 
3125 void ScTable::SetRowHeight( SCROW nRow, sal_uInt16 nNewHeight )
3126 {
3127  if (ValidRow(nRow) && mpRowHeights)
3128  {
3129  if (!nNewHeight)
3130  {
3131  OSL_FAIL("SetRowHeight: Row height zero");
3132  nNewHeight = ScGlobal::nStdRowHeight;
3133  }
3134 
3135  sal_uInt16 nOldHeight = mpRowHeights->getValue(nRow);
3136  if ( nNewHeight != nOldHeight )
3137  {
3138  mpRowHeights->setValue(nRow, nRow, nNewHeight);
3140  }
3141  }
3142  else
3143  {
3144  OSL_FAIL("Invalid row number or no heights");
3145  }
3146 }
3147 
3148 namespace {
3149 
3154 bool lcl_pixelSizeChanged(
3155  ScFlatUInt16RowSegments& rRowHeights, SCROW nStartRow, SCROW nEndRow,
3156  sal_uInt16 nNewHeight, double nPPTY, bool bApi)
3157 {
3158  tools::Long nNewPix = static_cast<tools::Long>(nNewHeight * nPPTY);
3159 
3160  ScFlatUInt16RowSegments::ForwardIterator aFwdIter(rRowHeights);
3161  for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
3162  {
3163  sal_uInt16 nHeight;
3164  if (!aFwdIter.getValue(nRow, nHeight))
3165  break;
3166 
3167  if (nHeight != nNewHeight)
3168  {
3169  tools::Long nOldPix = static_cast<tools::Long>(nHeight * nPPTY);
3170 
3171  // Heuristic: Don't bother when handling interactive input, if changing just one row and
3172  // the height will shrink.
3173  bool bChanged = (nNewPix != nOldPix) && (bApi || nEndRow - nStartRow > 0 || nNewPix > nOldPix);
3174  if (bChanged)
3175  return true;
3176  }
3177 
3178  // Skip ahead to the last position of the current range.
3179  nRow = aFwdIter.getLastPos();
3180  }
3181  return false;
3182 }
3183 
3184 }
3185 
3186 bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight,
3187  double nPPTY, bool bApi )
3188 {
3189  bool bChanged = false;
3190  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3191  {
3192  if (!nNewHeight)
3193  {
3194  OSL_FAIL("SetRowHeight: Row height zero");
3195  nNewHeight = ScGlobal::nStdRowHeight;
3196  }
3197 
3198  bool bSingle = false; // true = process every row for its own
3199  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
3200  if (pDrawLayer)
3201  if (pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ))
3202  bSingle = true;
3203 
3204  if (bSingle)
3205  {
3207  if (mpRowHeights->getRangeData(nStartRow, aData) &&
3208  nNewHeight == aData.mnValue && nEndRow <= aData.mnRow2)
3209  {
3210  bSingle = false; // no difference in this range
3211  }
3212  }
3213 
3214  // No idea why 20 is used here
3215  if (!bSingle || nEndRow - nStartRow < 20)
3216  {
3217  bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, nNewHeight, nPPTY, bApi);
3218  if (bChanged)
3219  mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
3220  }
3221  else
3222  {
3223  SCROW nMid = (nStartRow + nEndRow) / 2;
3224  // No idea why nPPTY is ignored in these recursive calls and instead 1.0 is used
3225  if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0, bApi))
3226  bChanged = true;
3227  if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0, bApi))
3228  bChanged = true;
3229  }
3230 
3231  if (bChanged)
3233  }
3234  else
3235  {
3236  OSL_FAIL("Invalid row number or no heights");
3237  }
3238 
3239  return bChanged;
3240 }
3241 
3242 void ScTable::SetRowHeightOnly( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight )
3243 {
3244  if (!ValidRow(nStartRow) || !ValidRow(nEndRow) || !mpRowHeights)
3245  return;
3246 
3247  if (!nNewHeight)
3248  nNewHeight = ScGlobal::nStdRowHeight;
3249 
3250  mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
3251 }
3252 
3253 void ScTable::SetManualHeight( SCROW nStartRow, SCROW nEndRow, bool bManual )
3254 {
3255  if (ValidRow(nStartRow) && ValidRow(nEndRow) && pRowFlags)
3256  {
3257  if (bManual)
3258  pRowFlags->OrValue( nStartRow, nEndRow, CRFlags::ManualSize);
3259  else
3260  pRowFlags->AndValue( nStartRow, nEndRow, ~CRFlags::ManualSize);
3261  }
3262  else
3263  {
3264  OSL_FAIL("Invalid row number or no column flags");
3265  }
3266 }
3267 
3268 sal_uInt16 ScTable::GetColWidth( SCCOL nCol, bool bHiddenAsZero ) const
3269 {
3270  OSL_ENSURE(ValidCol(nCol),"wrong column number");
3271 
3272  if (ValidCol(nCol) && mpColFlags && mpColWidth)
3273  {
3274  if (bHiddenAsZero && ColHidden(nCol))
3275  return 0;
3276  else
3277  return mpColWidth->GetValue(nCol);
3278  }
3279  else
3280  return sal_uInt16(STD_COL_WIDTH);
3281 }
3282 
3283 sal_uLong ScTable::GetColWidth( SCCOL nStartCol, SCCOL nEndCol ) const
3284 {
3285  if (!ValidCol(nStartCol) || !ValidCol(nEndCol) || nStartCol > nEndCol)
3286  return 0;
3287 
3288  sal_uLong nW = 0;
3289  bool bHidden = false;
3290  SCCOL nLastHiddenCol = -1;
3291  auto colWidthIt = mpColWidth->begin() + nStartCol;
3292  for (SCCOL nCol = nStartCol; nCol <= nEndCol; (++nCol <= nEndCol) ? ++colWidthIt : (void)false)
3293  {
3294  if (nCol > nLastHiddenCol)
3295  bHidden = ColHidden(nCol, nullptr, &nLastHiddenCol);
3296 
3297  if (bHidden)
3298  continue;
3299 
3300  nW += *colWidthIt;
3301  }
3302  return nW;
3303 }
3304 
3305 sal_uInt16 ScTable::GetOriginalWidth( SCCOL nCol ) const // always the set value
3306 {
3307  OSL_ENSURE(ValidCol(nCol),"wrong column number");
3308 
3309  if (ValidCol(nCol) && mpColWidth)
3310  return mpColWidth->GetValue(nCol);
3311  else
3312  return sal_uInt16(STD_COL_WIDTH);
3313 }
3314 
3315 sal_uInt16 ScTable::GetCommonWidth( SCCOL nEndCol ) const
3316 {
3317  // get the width that is used in the largest continuous column range (up to nEndCol)
3318 
3319  if ( !ValidCol(nEndCol) )
3320  {
3321  OSL_FAIL("wrong column");
3322  nEndCol = rDocument.MaxCol();
3323  }
3324 
3325  sal_uInt16 nMaxWidth = 0;
3326  sal_uInt16 nMaxCount = 0;
3327  SCCOL nRangeStart = 0;
3328  while ( nRangeStart <= nEndCol )
3329  {
3330  // skip hidden columns
3331  while ( nRangeStart <= nEndCol && ColHidden(nRangeStart) )
3332  ++nRangeStart;
3333  if ( nRangeStart <= nEndCol )
3334  {
3335  sal_uInt16 nThisCount = 0;
3336  auto colWidthIt = mpColWidth->begin() + nRangeStart;
3337  sal_uInt16 nThisWidth = *colWidthIt;
3338  SCCOL nRangeEnd = nRangeStart;
3339  while ( nRangeEnd <= nEndCol && *colWidthIt == nThisWidth )
3340  {
3341  ++nThisCount;
3342  ++nRangeEnd;
3343  ++colWidthIt;
3344 
3345  // skip hidden columns
3346  while ( nRangeEnd <= nEndCol && ColHidden(nRangeEnd) )
3347  {
3348  ++nRangeEnd;
3349  ++colWidthIt;
3350  }
3351  }
3352 
3353  if ( nThisCount > nMaxCount )
3354  {
3355  nMaxCount = nThisCount;
3356  nMaxWidth = nThisWidth;
3357  }
3358 
3359  nRangeStart = nRangeEnd; // next range
3360  }
3361  }
3362 
3363  return nMaxWidth;
3364 }
3365 
3366 sal_uInt16 ScTable::GetRowHeight( SCROW nRow, SCROW* pStartRow, SCROW* pEndRow, bool bHiddenAsZero ) const
3367 {
3368  SAL_WARN_IF(!ValidRow(nRow), "sc", "Invalid row number " << nRow);
3369 
3370  if (ValidRow(nRow) && mpRowHeights)
3371  {
3372  if (bHiddenAsZero && RowHidden( nRow, pStartRow, pEndRow))
3373  return 0;
3374  else
3375  {
3377  if (!mpRowHeights->getRangeData(nRow, aData))
3378  {
3379  if (pStartRow)
3380  *pStartRow = nRow;
3381  if (pEndRow)
3382  *pEndRow = nRow;
3383  // TODO: What should we return in case the search fails?
3384  return 0;
3385  }
3386 
3387  // If bHiddenAsZero, pStartRow and pEndRow were initialized to
3388  // boundaries of a non-hidden segment. Assume that the previous and
3389  // next segment are hidden then and limit the current height
3390  // segment.
3391  if (pStartRow)
3392  *pStartRow = (bHiddenAsZero ? std::max( *pStartRow, aData.mnRow1) : aData.mnRow1);
3393  if (pEndRow)
3394  *pEndRow = (bHiddenAsZero ? std::min( *pEndRow, aData.mnRow2) : aData.mnRow2);
3395  return aData.mnValue;
3396  }
3397  }
3398  else
3399  {
3400  if (pStartRow)
3401  *pStartRow = nRow;
3402  if (pEndRow)
3403  *pEndRow = nRow;
3404  return ScGlobal::nStdRowHeight;
3405  }
3406 }
3407 
3408 sal_uLong ScTable::GetRowHeight( SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZero ) const
3409 {
3410  OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
3411 
3412  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3413  {
3414  sal_uLong nHeight = 0;
3415  SCROW nRow = nStartRow;
3416  while (nRow <= nEndRow)
3417  {
3418  SCROW nLastRow = -1;
3419  if (!( ( RowHidden(nRow, nullptr, &nLastRow) ) && bHiddenAsZero ) )
3420  {
3421  if (nLastRow > nEndRow)
3422  nLastRow = nEndRow;
3423  nHeight += mpRowHeights->getSumValue(nRow, nLastRow);
3424  }
3425  nRow = nLastRow + 1;
3426  }
3427  return nHeight;
3428  }
3429  else
3430  return (nEndRow - nStartRow + 1) * static_cast<sal_uLong>(ScGlobal::nStdRowHeight);
3431 }
3432 
3433 sal_uLong ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong* pnMaxHeight ) const
3434 {
3435  OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
3436 
3437  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3438  {
3439  sal_uLong nHeight = 0;
3440  SCROW nRow = nStartRow;
3441  while (nRow <= nEndRow)
3442  {
3443  SCROW nLastRow = -1;
3444  if (!RowHidden(nRow, nullptr, &nLastRow))
3445  {
3446  if (nLastRow > nEndRow)
3447  nLastRow = nEndRow;
3448 
3449  // #i117315# can't use getSumValue, because individual values must be rounded
3451  while (nRow <= nLastRow)
3452  {
3453  sal_uInt16 nRowVal;
3454  if (!aSegmentIter.getValue(nRow, nRowVal))
3455  return nHeight; // shouldn't happen
3456 
3457  SCROW nSegmentEnd = std::min( nLastRow, aSegmentIter.getLastPos() );
3458 
3459  // round-down a single height value, multiply resulting (pixel) values
3460  const sal_uLong nOneHeight = static_cast<sal_uLong>( nRowVal * fScale );
3461  // sometimes scaling results in zero height
3462  if (nOneHeight)
3463  {
3464  SCROW nRowsInSegment = nSegmentEnd + 1 - nRow;
3465  if (pnMaxHeight)
3466  {
3467  nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
3468  nHeight += nOneHeight * nRowsInSegment;
3469  if (nHeight > *pnMaxHeight)
3470  return nHeight;
3471  }
3472  else
3473  nHeight += nOneHeight * nRowsInSegment;
3474  }
3475 
3476  nRow = nSegmentEnd + 1;
3477  }
3478  }
3479  nRow = nLastRow + 1;
3480  }
3481  return nHeight;
3482  }
3483  else
3484  {
3485  const sal_uLong nOneHeight = static_cast<sal_uLong>(ScGlobal::nStdRowHeight * fScale);
3486  SCROW nRowsInSegment = nEndRow - nStartRow + 1;
3487  if (pnMaxHeight)
3488  {
3489  nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
3490  return nOneHeight * nRowsInSegment;
3491  }
3492  else
3493  return static_cast<sal_uLong>(nRowsInSegment * nOneHeight);
3494  }
3495 }
3496 
3497 sal_uInt16 ScTable::GetOriginalHeight( SCROW nRow ) const // non-0 even if hidden
3498 {
3499  OSL_ENSURE(ValidRow(nRow),"wrong row number");
3500 
3501  if (ValidRow(nRow) && mpRowHeights)
3502  return mpRowHeights->getValue(nRow);
3503  else
3504  return ScGlobal::nStdRowHeight;
3505 }
3506 
3507 // Column/Row -Flags
3508 
3510 {
3511  if (!ValidRow(nRow))
3512  return 0;
3513 
3514  SCROW nLastRow = -1;
3515  if (!RowHidden(nRow, nullptr, &nLastRow) || !ValidRow(nLastRow))
3516  return 0;
3517 
3518  return nLastRow - nRow + 1;
3519 }
3520 
3521 //TODO: combine ShowRows / DBShowRows
3522 
3523 void ScTable::ShowCol(SCCOL nCol, bool bShow)
3524 {
3525  if (ValidCol(nCol))
3526  {
3527  bool bWasVis = !ColHidden(nCol);
3528  if (bWasVis != bShow)
3529  {
3530  SetColHidden(nCol, nCol, !bShow);
3531 
3533  if ( pCharts )
3534  pCharts->SetRangeDirty(ScRange( nCol, 0, nTab, nCol, rDocument.MaxRow(), nTab ));
3535  }
3536  }
3537  else
3538  {
3539  OSL_FAIL("Invalid column number or no flags");
3540  }
3541 }
3542 
3543 void ScTable::ShowRow(SCROW nRow, bool bShow)
3544 {
3545  if (ValidRow(nRow) && pRowFlags)
3546  {
3547  bool bWasVis = !RowHidden(nRow);
3548  if (bWasVis != bShow)
3549  {
3550  SetRowHidden(nRow, nRow, !bShow);
3551  if (bShow)
3552  SetRowFiltered(nRow, nRow, false);
3554  if ( pCharts )
3555  pCharts->SetRangeDirty(ScRange( 0, nRow, nTab, rDocument.MaxCol(), nRow, nTab ));
3556 
3558  }
3559  }
3560  else
3561  {
3562  OSL_FAIL("Invalid row number or no flags");
3563  }
3564 }
3565 
3566 void ScTable::DBShowRow(SCROW nRow, bool bShow)
3567 {
3568  if (ValidRow(nRow) && pRowFlags)
3569  {
3570  // Always set filter flag; unchanged when Hidden
3571  bool bChanged = SetRowHidden(nRow, nRow, !bShow);
3572  SetRowFiltered(nRow, nRow, !bShow);
3573 
3574  if (bChanged)
3575  {
3577  if ( pCharts )
3578  pCharts->SetRangeDirty(ScRange( 0, nRow, nTab, rDocument.MaxCol(), nRow, nTab ));
3579 
3580  if (pOutlineTable)
3581  UpdateOutlineRow( nRow, nRow, bShow );
3582 
3584  }
3585  }
3586  else
3587  {
3588  OSL_FAIL("Invalid row number or no flags");
3589  }
3590 }
3591 
3592 void ScTable::DBShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
3593 {
3594  SCROW nStartRow = nRow1;
3595  while (nStartRow <= nRow2)
3596  {
3597  SCROW nEndRow = -1;
3598  bool bWasVis = !RowHiddenLeaf(nStartRow, nullptr, &nEndRow);
3599  if (nEndRow > nRow2)
3600  nEndRow = nRow2;
3601 
3602  bool bChanged = ( bWasVis != bShow );
3603 
3604  SetRowHidden(nStartRow, nEndRow, !bShow);
3605  SetRowFiltered(nStartRow, nEndRow, !bShow);
3606 
3607  if ( bChanged )
3608  {
3610  if ( pCharts )
3611  pCharts->SetRangeDirty(ScRange( 0, nStartRow, nTab, rDocument.MaxCol(), nEndRow, nTab ));
3612  }
3613 
3614  nStartRow = nEndRow + 1;
3615  }
3616 
3617  // #i12341# For Show/Hide rows, the outlines are updated separately from the outside.
3618  // For filtering, the changes aren't visible to the caller, so UpdateOutlineRow has
3619  // to be done here.
3620  if (pOutlineTable)
3621  UpdateOutlineRow( nRow1, nRow2, bShow );
3622 }
3623 
3624 void ScTable::ShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
3625 {
3626  SCROW nStartRow = nRow1;
3627 
3628  // #i116164# if there are no drawing objects within the row range, a single HeightChanged call is enough
3629  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
3630  bool bHasObjects = pDrawLayer && pDrawLayer->HasObjectsInRows( nTab, nRow1, nRow2 );
3631 
3632  while (nStartRow <= nRow2)
3633  {
3634  SCROW nEndRow = -1;
3635  bool bWasVis = !RowHiddenLeaf(nStartRow, nullptr, &nEndRow);
3636  if (nEndRow > nRow2)
3637  nEndRow = nRow2;
3638 
3639  bool bChanged = ( bWasVis != bShow );
3640 
3641  SetRowHidden(nStartRow, nEndRow, !bShow);
3642  if (bShow)
3643  SetRowFiltered(nStartRow, nEndRow, false);
3644 
3645  if ( bChanged )
3646  {
3648  if ( pCharts )
3649  pCharts->SetRangeDirty(ScRange( 0, nStartRow, nTab, rDocument.MaxCol(), nEndRow, nTab ));
3650 
3652  }
3653 
3654  nStartRow = nEndRow + 1;
3655  }
3656 
3657  if ( !bHasObjects )
3658  {
3659  // #i116164# set the flags for the whole range at once
3660  SetRowHidden(nRow1, nRow2, !bShow);
3661  if (bShow)
3662  SetRowFiltered(nRow1, nRow2, false);
3663  }
3664 }
3665 
3666 bool ScTable::IsDataFiltered(SCCOL nColStart, SCROW nRowStart, SCCOL nColEnd, SCROW nRowEnd) const
3667 {
3668  for (SCROW i = nRowStart; i <= nRowEnd; ++i)
3669  {
3670  if (RowHidden(i))
3671  return true;
3672  }
3673  for (SCCOL i = nColStart; i <= nColEnd; ++i)
3674  {
3675  if (ColHidden(i))
3676  return true;
3677  }
3678  return false;
3679 }
3680 
3681 bool ScTable::IsDataFiltered(const ScRange& rRange) const
3682 {
3683  return IsDataFiltered(rRange.aStart.Col(), rRange.aStart.Row(),
3684  rRange.aEnd.Col(), rRange.aEnd.Row());
3685 }
3686 
3687 void ScTable::SetRowFlags( SCROW nRow, CRFlags nNewFlags )
3688 {
3689  if (ValidRow(nRow) && pRowFlags)
3690  pRowFlags->SetValue( nRow, nNewFlags);
3691  else
3692  {
3693  OSL_FAIL("Invalid row number or no flags");
3694  }
3695 }
3696 
3697 void ScTable::SetRowFlags( SCROW nStartRow, SCROW nEndRow, CRFlags nNewFlags )
3698 {
3699  if (ValidRow(nStartRow) && ValidRow(nEndRow) && pRowFlags)
3700  pRowFlags->SetValue( nStartRow, nEndRow, nNewFlags);
3701  else
3702  {
3703  OSL_FAIL("Invalid row number(s) or no flags");
3704  }
3705 }
3706 
3708 {
3709  if (ValidCol(nCol) && mpColFlags)
3710  return mpColFlags->GetValue(nCol);
3711  else
3712  return CRFlags::NONE;
3713 }
3714 
3716 {
3717  if (ValidRow(nRow) && pRowFlags)
3718  return pRowFlags->GetValue(nRow);
3719  else
3720  return CRFlags::NONE;
3721 }
3722 
3724 {
3725  SCROW nLastFound = 0;
3726  if (pRowFlags)
3727  {
3728  SCROW nRow = pRowFlags->GetLastAnyBitAccess( CRFlags::All );
3729  if (ValidRow(nRow))
3730  nLastFound = nRow;
3731  }
3732 
3733  if (!maRowManualBreaks.empty())
3734  nLastFound = ::std::max(nLastFound, *maRowManualBreaks.rbegin());
3735 
3736  if (mpHiddenRows)
3737  {
3738  SCROW nRow = mpHiddenRows->findLastTrue();
3739  if (ValidRow(nRow))
3740  nLastFound = ::std::max(nLastFound, nRow);
3741  }
3742 
3743  if (mpFilteredRows)
3744  {
3745  SCROW nRow = mpFilteredRows->findLastTrue();
3746  if (ValidRow(nRow))
3747  nLastFound = ::std::max(nLastFound, nRow);
3748  }
3749 
3750  return nLastFound;
3751 }
3752 
3754 {
3755  if ( !mpColFlags )
3756  return 0;
3757 
3758  SCCOL nLastFound = 0;
3759  const auto nColSize = aCol.size();
3760  auto colWidthIt = mpColWidth->begin() + 1;
3761  for (SCCOL nCol = 1; nCol < nColSize; (++nCol < nColSize) ? ++colWidthIt : (void)false)
3762  if ((mpColFlags->GetValue(nCol) & CRFlags::All) || (*colWidthIt != STD_COL_WIDTH))
3763  nLastFound = nCol;
3764 
3765  return nLastFound;
3766 }
3767 
3769 {
3770  if ( !pRowFlags )
3771  return 0;
3772 
3773  SCROW nLastFlags = GetLastFlaggedRow();
3774 
3775  // Find the last row position where the height is NOT the standard row
3776  // height.
3777  // KOHEI: Test this to make sure it does what it's supposed to.
3778  SCROW nLastHeight = mpRowHeights->findLastTrue(ScGlobal::nStdRowHeight);
3779  if (!ValidRow(nLastHeight))
3780  nLastHeight = 0;
3781 
3782  return std::max( nLastFlags, nLastHeight);
3783 }
3784 
3785 bool ScTable::UpdateOutlineCol( SCCOL nStartCol, SCCOL nEndCol, bool bShow )
3786 {
3787  if (pOutlineTable && mpColFlags)
3788  {
3789  return pOutlineTable->GetColArray().ManualAction( nStartCol, nEndCol, bShow, *this, true );
3790  }
3791  else
3792  return false;
3793 }
3794 
3795 bool ScTable::UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, bool bShow )
3796 {
3797  if (pOutlineTable && pRowFlags)
3798  return pOutlineTable->GetRowArray().ManualAction( nStartRow, nEndRow, bShow, *this, false );
3799  else
3800  return false;
3801 }
3802 
3803 void ScTable::ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
3804 {
3805  // Column-wise expansion
3806 
3807  while (rX1 > 0 && ColHidden(rX1-1))
3808  --rX1;
3809 
3810  while (rX2 < rDocument.MaxCol() && ColHidden(rX2+1))
3811  ++rX2;
3812 
3813  // Row-wise expansion
3814 
3815  if (rY1 > 0)
3816  {
3818  if (mpHiddenRows->getRangeData(rY1-1, aData) && aData.mbValue)
3819  {
3820  SCROW nStartRow = aData.mnRow1;
3821  if (ValidRow(nStartRow))
3822  rY1 = nStartRow;
3823  }
3824  }
3825  if (rY2 < rDocument.MaxRow())
3826  {
3827  SCROW nEndRow = -1;
3828  if (RowHidden(rY2+1, nullptr, &nEndRow) && ValidRow(nEndRow))
3829  rY2 = nEndRow;
3830  }
3831 }
3832 
3833 void ScTable::StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
3834 {
3835  while ( rX2>rX1 && ColHidden(rX2) )
3836  --rX2;
3837  while ( rX2>rX1 && ColHidden(rX1) )
3838  ++rX1;
3839 
3840  if (rY1 < rY2)
3841  {
3843  if (mpHiddenRows->getRangeData(rY2, aData) && aData.mbValue)
3844  {
3845  SCROW nStartRow = aData.mnRow1;
3846  if (ValidRow(nStartRow) && nStartRow >= rY1)
3847  rY2 = nStartRow;
3848  }
3849  }
3850 
3851  if (rY1 < rY2)
3852  {
3853  SCROW nEndRow = -1;
3854  if (RowHidden(rY1, nullptr, &nEndRow) && ValidRow(nEndRow) && nEndRow <= rY2)
3855  rY1 = nEndRow;
3856  }
3857 }
3858 
3859 // Auto-Outline
3860 
3861 template< typename T >
3862 static short DiffSign( T a, T b )
3863 {
3864  return (a<b) ? -1 :
3865  (a>b) ? 1 : 0;
3866 }
3867 
3868 namespace {
3869 
3870 class OutlineArrayFinder
3871 {
3872  ScRange maRef;
3873  SCCOL mnCol;
3874  SCTAB mnTab;
3876  bool mbSizeChanged;
3877 
3878 public:
3879  OutlineArrayFinder(const ScRange& rRef, SCCOL nCol, SCTAB nTab, ScOutlineArray* pArray, bool bSizeChanged) :
3880  maRef(rRef), mnCol(nCol), mnTab(nTab), mpArray(pArray),
3881  mbSizeChanged(bSizeChanged) {}
3882 
3883  bool operator() (size_t nRow, const ScFormulaCell* pCell)
3884  {
3885  SCROW nRow2 = static_cast<SCROW>(nRow);
3886 
3887  if (!pCell->HasRefListExpressibleAsOneReference(maRef))
3888  return false;
3889 
3890  if (maRef.aStart.Row() != nRow2 || maRef.aEnd.Row() != nRow2 ||
3891  maRef.aStart.Tab() != mnTab || maRef.aEnd.Tab() != mnTab)
3892  return false;
3893 
3894  if (DiffSign(maRef.aStart.Col(), mnCol) != DiffSign(maRef.aEnd.Col(), mnCol))
3895  return false;
3896 
3897  return mpArray->Insert(maRef.aStart.Col(), maRef.aEnd.Col(), mbSizeChanged);
3898  }
3899 };
3900 
3901 }
3902 
3903 void ScTable::DoAutoOutline( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
3904 {
3905  typedef mdds::flat_segment_tree<SCROW, bool> UsedRowsType;
3906 
3907  bool bSizeChanged = false;
3908 
3909  SCCOL nCol;
3910  SCROW nRow;
3911  bool bFound;
3912  ScRange aRef;
3913 
3914  nEndCol = ClampToAllocatedColumns(nEndCol);
3915 
3917 
3918  // Rows
3919 
3920  UsedRowsType aUsed(0, rDocument.MaxRow()+1, false);
3921  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
3922  aCol[nCol].FindUsed(nStartRow, nEndRow, aUsed);
3923  aUsed.build_tree();
3924 
3925  ScOutlineArray& rRowArray = pOutlineTable->GetRowArray();
3926  for (nRow=nStartRow; nRow<=nEndRow; nRow++)
3927  {
3928  bool bUsed = false;
3929  SCROW nLastRow = nRow;
3930  aUsed.search_tree(nRow, bUsed, nullptr, &nLastRow);
3931  if (!bUsed)
3932  {
3933  nRow = nLastRow;
3934  continue;
3935  }
3936 
3937  bFound = false;
3938  for (nCol=nStartCol; nCol<=nEndCol && !bFound; nCol++)
3939  {
3940  ScRefCellValue aCell = aCol[nCol].GetCellValue(nRow);
3941 
3942  if (aCell.meType != CELLTYPE_FORMULA)
3943  continue;
3944 
3946  continue;
3947 
3948  if ( aRef.aStart.Col() == nCol && aRef.aEnd.Col() == nCol &&
3949  aRef.aStart.Tab() == nTab && aRef.aEnd.Tab() == nTab &&
3950  DiffSign( aRef.aStart.Row(), nRow ) ==
3951  DiffSign( aRef.aEnd.Row(), nRow ) )
3952  {
3953  if (rRowArray.Insert( aRef.aStart.Row(), aRef.aEnd.Row(), bSizeChanged ))
3954  {
3955  bFound = true;
3956  }
3957  }
3958  }
3959  }
3960 
3961  // Column
3962  ScOutlineArray& rColArray = pOutlineTable->GetColArray();
3963  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
3964  {
3965  if (aCol[nCol].IsEmptyData())
3966  continue;
3967 
3968  OutlineArrayFinder aFunc(aRef, nCol, nTab, &rColArray, bSizeChanged);
3969  sc::FindFormula(aCol[nCol].maCells, nStartRow, nEndRow, aFunc);
3970  }
3971 }
3972 
3973  // CopyData - for Query in other range
3974 
3975 void ScTable::CopyData( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
3976  SCCOL nDestCol, SCROW nDestRow, SCTAB nDestTab )
3977 {
3978  //TODO: if used for multiple rows, optimize after columns!
3979 
3980  ScAddress aSrc( nStartCol, nStartRow, nTab );
3981  ScAddress aDest( nDestCol, nDestRow, nDestTab );
3982  ScRange aRange( aSrc, aDest );
3983  bool bThisTab = ( nDestTab == nTab );
3984  SCROW nDestY = nDestRow;
3985  for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
3986  {
3987  aSrc.SetRow( nRow );
3988  aDest.SetRow( nDestY );
3989  SCCOL nDestX = nDestCol;
3990  for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
3991  {
3992  aSrc.SetCol( nCol );
3993  aDest.SetCol( nDestX );
3994  ScCellValue aCell;
3995  aCell.assign(rDocument, ScAddress(nCol, nRow, nTab));
3996 
3997  if (aCell.meType == CELLTYPE_FORMULA)
3998  {
3999  sc::RefUpdateContext aCxt(rDocument);
4000  aCxt.meMode = URM_COPY;
4001  aCxt.maRange = aRange;
4002  aCxt.mnColDelta = nDestCol - nStartCol;
4003  aCxt.mnRowDelta = nDestRow - nStartRow;
4004  aCxt.mnTabDelta = nDestTab - nTab;
4005  aCell.mpFormula->UpdateReference(aCxt);
4006  aCell.mpFormula->aPos = aDest;
4007  }
4008 
4009  if (bThisTab)
4010  {
4011  aCell.release(CreateColumnIfNotExists(nDestX), nDestY);
4012  SetPattern( nDestX, nDestY, *GetPattern( nCol, nRow ) );
4013  }
4014  else
4015  {
4016  aCell.release(rDocument, aDest);
4017  rDocument.SetPattern( aDest, *GetPattern( nCol, nRow ) );
4018  }
4019 
4020  ++nDestX;
4021  }
4022  ++nDestY;
4023  }
4024 }
4025 
4027 {
4028  ScRange aRef;
4029 
4030  if (pCell->HasOneReference(aRef))
4031  {
4032  if (aRef.aStart.Col()==aRef.aEnd.Col() && aRef.aStart.Tab()==aRef.aEnd.Tab())
4033  {
4034  SCROW nEndRow;
4035  if (!RowFiltered(aRef.aStart.Row(), nullptr, &nEndRow))
4036  // row not filtered.
4037  nEndRow = ::std::numeric_limits<SCROW>::max();
4038 
4039  if (!ValidRow(nEndRow) || nEndRow < aRef.aEnd.Row())
4040  return true; // at least partly visible
4041  return false; // completely invisible
4042  }
4043  }
4044 
4045  return true; // somehow different
4046 }
4047 
4048 void ScTable::GetUpperCellString(SCCOL nCol, SCROW nRow, OUString& rStr)
4049 {
4050  GetInputString(nCol, nRow, rStr);
4051  rStr = ScGlobal::getCharClass().uppercase(rStr.trim());
4052 }
4053 
4054 // Calculate the size of the sheet and set the size on DrawPage
4055 
4056 void ScTable::SetDrawPageSize(bool bResetStreamValid, bool bUpdateNoteCaptionPos,
4057  ScObjectHandling eObjectHandling)
4058 {
4059  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
4060  if( pDrawLayer )
4061  {
4062  const sal_Int64 nMax = ::std::numeric_limits<tools::Long>::max();
4063  // #i113884# Avoid int32 overflow with possible negative results than can cause bad effects.
4064  // If the draw page size is smaller than all rows, only the bottom of the sheet is affected.
4065  tools::Long x = std::min(o3tl::convert(GetColOffset(rDocument.MaxCol() + 1),
4067  nMax);
4068  tools::Long y = std::min(o3tl::convert(GetRowOffset(rDocument.MaxRow() + 1),
4070  nMax);
4071 
4072  if ( IsLayoutRTL() ) // IsNegativePage
4073  x = -x;
4074 
4075  pDrawLayer->SetPageSize(static_cast<sal_uInt16>(nTab), Size(x, y), bUpdateNoteCaptionPos,
4076  eObjectHandling);
4077  }
4078 
4079  // #i102616# actions that modify the draw page size count as sheet modification
4080  // (exception: InitDrawLayer)
4081  if (bResetStreamValid)
4082  SetStreamValid(false);
4083 }
4084 
4085 void ScTable::SetRangeName(std::unique_ptr<ScRangeName> pNew)
4086 {
4087  mpRangeName = std::move(pNew);
4088 
4089  //fdo#39792: mark stream as invalid, otherwise new ScRangeName will not be written to file
4090  SetStreamValid(false);
4091 }
4092 
4094 {
4095  if (!mpRangeName)
4096  mpRangeName.reset(new ScRangeName);
4097  return mpRangeName.get();
4098 }
4099 
4100 sal_uLong ScTable::GetRowOffset( SCROW nRow, bool bHiddenAsZero ) const
4101 {
4102  sal_uLong n = 0;
4103  if ( mpHiddenRows && mpRowHeights )
4104  {
4105  if (nRow == 0)
4106  return 0;
4107  else if (nRow == 1)
4108  return GetRowHeight(0, nullptr, nullptr, bHiddenAsZero );
4109 
4110  n = GetTotalRowHeight(0, nRow-1, bHiddenAsZero);
4111 #if OSL_DEBUG_LEVEL > 0
4112  if (n == ::std::numeric_limits<tools::ULong>::max())
4113  OSL_FAIL("ScTable::GetRowOffset: row heights overflow");
4114 #endif
4115  }
4116  else
4117  {
4118  OSL_FAIL("GetRowOffset: Data missing");
4119  }
4120  return n;
4121 }
4122 
4124 {
4125  sal_uLong nSum = 0;
4126 
4128 
4129  ScFlatUInt16RowSegments::RangeData aRowHeightRange;
4130  aRowHeightRange.mnRow2 = -1;
4131  aRowHeightRange.mnValue = 0; // silence MSVC C4701
4132 
4133  for (SCROW nRow = 0; nRow <= rDocument.MaxRow(); ++nRow)
4134  {
4135  if (!mpHiddenRows->getRangeData(nRow, aData))
4136  // Failed to fetch the range data for whatever reason.
4137  break;
4138 
4139  if (aData.mbValue)
4140  {
4141  // This row is hidden. Skip ahead all hidden rows.
4142  nRow = aData.mnRow2;
4143  continue;
4144  }
4145 
4146  if (aRowHeightRange.mnRow2 < nRow)
4147  {
4148  if (!mpRowHeights->getRangeData(nRow, aRowHeightRange))
4149  // Failed to fetch the range data for whatever reason.
4150  break;
4151  }
4152 
4153  // find the last common row between hidden & height spans
4154  SCROW nLastCommon = std::min(aData.mnRow2, aRowHeightRange.mnRow2);
4155  assert (nLastCommon >= nRow);
4156  SCROW nCommon = nLastCommon - nRow + 1;
4157 
4158  // how much further to go ?
4159  sal_uLong nPixelsLeft = nHeight - nSum;
4160  sal_uLong nCommonPixels = static_cast<sal_uLong>(aRowHeightRange.mnValue) * nCommon;
4161 
4162  // are we in the zone ?
4163  if (nCommonPixels > nPixelsLeft)
4164  {
4165  nRow += (nPixelsLeft + aRowHeightRange.mnValue - 1) / aRowHeightRange.mnValue;
4166 
4167  // FIXME: finding this next row is far from elegant,
4168  // we have a single caller, which subtracts one as well(!?)
4169  if (nRow >= rDocument.MaxRow())
4170  return rDocument.MaxRow();
4171 
4172  if (!mpHiddenRows->getRangeData(nRow, aData))
4173  // Failed to fetch the range data for whatever reason.
4174  break;
4175 
4176  if (aData.mbValue)
4177  // These rows are hidden.
4178  nRow = aData.mnRow2 + 1;
4179 
4180  return nRow <= rDocument.MaxRow() ? nRow : rDocument.MaxRow();
4181  }
4182 
4183  // skip the range and keep hunting
4184  nSum += nCommonPixels;
4185  nRow = nLastCommon;
4186  }
4187  return -1;
4188 }
4189 
4190 sal_uLong ScTable::GetColOffset( SCCOL nCol, bool bHiddenAsZero ) const
4191 {
4192  sal_uLong n = 0;
4193  if ( mpColWidth )
4194  {
4195  auto colWidthIt = mpColWidth->begin();
4196  for (SCCOL i = 0; i < nCol; (++i < nCol) ? ++colWidthIt : (void)false)
4197  if (!( bHiddenAsZero && ColHidden(i) ))
4198  n += *colWidthIt;
4199  }
4200  else
4201  {
4202  OSL_FAIL("GetColumnOffset: Data missing");
4203  }
4204  return n;
4205 }
4206 
4207 /* 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:2366
void SetFormula(SCCOL nCol, SCROW nRow, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGram)
Definition: table2.cxx:1686
void SetMergedCells(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:2262
void CellStorageModified()
Called whenever the state of cell array gets modified i.e.
Definition: column2.cxx:1653
void ApplyStyle(SCROW nRow, const ScStyleSheet *rStyle)
Definition: column.cxx:561
void CalcAfterLoad(sc::CompileFormulaContext &rCxt, bool bStartListening)
Definition: table2.cxx:2129
void CopyUpdated(const ScTable *pPosTab, ScTable *pDestTab) const
Definition: table2.cxx:1517
svl::SharedString GetSharedString(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1723
constexpr double nPPTY
bool TestCopyScenarioTo(const ScTable *pDestTab) const
Definition: table2.cxx:1607
SCCOL GetColMerge() const
Definition: attrib.hxx:68
SCTAB nTab
Definition: table.hxx:205
SCROW mnRowDelta
Amount and direction of movement in the row direction.
const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:2192
bool SetRowHeightRange(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight, double nPPTY, bool bApi)
Definition: table2.cxx:3186
Temporarily switch on/off auto calculation mode.
Definition: scopetools.hxx:26
SCCOL GetLastChangedCol() const
Definition: table2.cxx:3753
bool Intersects(const ScRange &) const
Definition: rangelst.cxx:1089
CellType meType
Definition: cellvalue.hxx:37
ScRotateDir GetRotateDir(const SfxItemSet *pCondSet) const
Definition: patattr.cxx:1328
ScFormulaCell * SetFormulaCell(SCCOL nCol, SCROW nRow, ScFormulaCell *pCell)
Takes ownership of pCell.
Definition: table2.cxx:1704
void ApplyStyleArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: table2.cxx:2874
bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, HasAttrFlags nMask) const
Definition: table2.cxx:2212
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:1914
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:2728
bool HasBlockMatrixFragment(const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2, bool bNoMatrixAtAll=false) const
Definition: table2.cxx:2443
void CompileAll(sc::CompileFormulaContext &rCxt)
Definition: table2.cxx:2094
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:1843
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: table2.cxx:2016
void SetRowFlags(SCROW nRow, CRFlags nNewFlags)
Definition: table2.cxx:3687
bool IsBlockEmpty(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bIgnoreNotes) const
Definition: table2.cxx:2277
void MergeSelectionPattern(ScMergePatternState &rState, const ScMarkData &rMark, bool bDeep) const
Definition: column.cxx:336
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: column.cxx:371
void SetRowHeight(SCROW nRow, sal_uInt16 nNewHeight)
Definition: table2.cxx:3125
std::unique_ptr< ScFlatUInt16RowSegments > mpRowHeights
Definition: table.hxx:182
HasAttrFlags
Definition: global.hxx:193
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
void SetPatternAreaCondFormat(SCCOL nCol, SCROW nStartRow, SCROW nEndRow, const ScPatternAttr &rAttr, const ScCondFormatIndexes &rCondFormatIndexes)
Definition: table2.cxx:2850
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:2521
bool IsDataFiltered(SCCOL nColStart, SCROW nRowStart, SCCOL nColEnd, SCROW nRowEnd) const
Definition: table2.cxx:3666
bool IsSelectionEditable(const ScMarkData &rMark, bool *pOnlyNotBecauseOfMatrix=nullptr) const
Definition: table2.cxx:2639
void SetRowHeightOnly(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight)
Set specified row height to specified ranges.
Definition: table2.cxx:3242
SCTAB GetTab() const
Definition: table.hxx:283
SC_DLLPUBLIC bool IsActiveScenario(SCTAB nTab) const
Definition: documen3.cxx:877
size_t GetNoteCount(SCCOL nCol) const
Definition: table2.cxx:1821
ScRangeList & GetRangeList()
Definition: conditio.hxx:561
void ApplyPattern(SCCOL nCol, SCROW nRow, const ScPatternAttr &rAttr)
Definition: table2.cxx:2787
ScColumn * FetchColumn(SCCOL nCol)
Definition: table2.cxx:1228
ScObjectHandling
Definition: drwlayer.hxx:89
std::unique_ptr< ScPostIt > ReleaseNote(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1813
ScScenarioFlags
Definition: global.hxx:236
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:3975
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:897
bool IsOverlapped() const
Definition: attrib.hxx:101
CellType GetCellType(const ScAddress &rPos) const
Definition: table.hxx:460
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
void SetCalcNotification(bool bSet)
Definition: table2.cxx:130
void SetEditText(SCROW nRow, std::unique_ptr< EditTextObject > pEditText)
Definition: column3.cxx:2217
sal_Int64 n
void GetString(SCCOL nCol, SCROW nRow, OUString &rString, const ScInterpreterContext *pContext=nullptr) const
Definition: table2.cxx:1743
bool IsUndo() const
Definition: document.hxx:1533
void DetachFormulaCells(sc::EndListeningContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1272
std::unique_ptr< ScFlatBoolColSegments > mpFilteredCols
Definition: table.hxx:188
const ScStyleSheet * GetSelectionStyle(const ScMarkData &rMark, bool &rFound) const
Definition: table2.cxx:2931
Rich-text attributes.
ScColumnVector::const_iterator end() const
bool HasScenarioRange(const ScRange &rRange) const
Definition: table2.cxx:1565
sal_Int32 mnCol
sal_uInt16 nLockCount
Definition: table.hxx:220
CommentCaptionState GetAllNoteCaptionsState(const ScRange &rRange, std::vector< sc::NoteEntry > &rNotes)
Definition: table2.cxx:1869
std::unordered_map< sal_uInt32, sal_uInt32 > SvNumberFormatterMergeMap
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:386
Store position data for column array storage.
const SfxItemSet & GetItemSet() const
sal_uInt16 GetDistance(SvxBoxItemLine nLine) const
bool mbPageBreaksValid
Definition: table.hxx:245
InsertDeleteFlags getInsertFlag() const
bool IsClipOrUndo() const
Definition: document.hxx:1532
void TransposeColPatterns(ScTable *pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1, SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered, const std::vector< SCROW > &rFilteredRows, SCROW nRowDestOffset)
Transpose clipboard patterns.
Definition: table2.cxx:1042
bool HasObjectsInRows(SCTAB nTab, SCROW nStartRow, SCROW nEndRow)
Definition: drwlayer.cxx:1478
void CopyStaticToDocument(SCROW nRow1, SCROW nRow2, const SvNumberFormatterMergeMap &rMap, ScColumn &rDestCol)
Definition: column.cxx:1063
bool CompileErrorCells(sc::CompileFormulaContext &rCxt, FormulaError nErrCode)
Definition: table2.cxx:2117
sal_uInt16 GetTextWidth(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:86
void GetFirstDataPos(SCCOL &rCol, SCROW &rRow) const
Definition: table2.cxx:1938
ScAddress aEnd
Definition: address.hxx:500
void SetManualHeight(SCROW nStartRow, SCROW nEndRow, bool bManual)
Definition: table2.cxx:3253
void SetColHidden(SCCOL nStartCol, SCCOL nEndCol, bool bHidden)
Definition: table5.cxx:634
void ApplyPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr &rPatAttr, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: column.cxx:517
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:1536
void UndoToTable(sc::CopyToDocContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, InsertDeleteFlags nFlags, bool bMarked, ScTable *pDestTab)
Definition: table2.cxx:1465
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:3497
void RemoveEditTextCharAttribs(SCCOL nCol, SCROW nRow, const ScPatternAttr &rAttr)
Definition: table2.cxx:1782
const editeng::SvxBorderLine * GetRight() const
mdds::multi_type_vector< CellFunc, CellStoreEvent > CellStoreType
const ScStyleSheet * GetStyle(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:2921
float x
void TransposeClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCROW nCombinedStartRow, SCROW nRowDestOffset, ScTable *pTransClip, InsertDeleteFlags nFlags, bool bAsLink, bool bIncludeFiltered)
Definition: table2.cxx:980
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:1964
void SetDirtyAfterLoad()
Definition: table2.cxx:2045
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:2759
void ApplySelectionStyle(const ScStyleSheet &rStyle, const ScMarkData &rMark)
Definition: table2.cxx:2905
std::unique_ptr< ScRangeName > mpRangeName
Definition: table.hxx:227
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:4123
const ScAddress & GetAddress() const
Definition: brdcst.hxx:30
constexpr TypedWhichId< ScMergeAttr > ATTR_MERGE(144)
bool bTableAreaVisibleValid
Definition: table.hxx:238
void ApplyAttr(SCCOL nCol, SCROW nRow, const SfxPoolItem &rAttr)
Definition: table2.cxx:3065
Internal use only (d&d undo): do not delete caption objects of cell notes.
void MarkScenarioIn(ScMarkData &rMark, ScScenarioFlags nNeededBits) const
Definition: table2.cxx:1554
bool UpdateReference(const sc::RefUpdateContext &rCxt, ScDocument *pUndoDoc=nullptr, const ScAddress *pUndoCellPos=nullptr)
bool ValidRow(SCROW nRow) const
Definition: table.hxx:333
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6087
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:1244
void SetStreamValid(bool bSet, bool bIgnoreLock=false)
Definition: table1.cxx:374
ScColumn & CreateColumnIfNotExists(const SCCOL nScCol) const
Definition: table.hxx:287
FuncFlags mnFlags
Information about all parameters.
void AttachFormulaCells(sc::StartListeningContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1264
Store arbitrary cell value of any kind.
Definition: cellvalue.hxx:35
constexpr TypedWhichId< ScRotateValueItem > ATTR_ROTATE_VALUE(135)
void ResetChanged(const ScRange &rRange)
Definition: table2.cxx:2135
ScFormulaCell * SetFormulaCell(SCROW nRow, ScFormulaCell *pCell, sc::StartListeningType eListenType=sc::SingleCellListening, bool bInheritNumFormatIfNeeded=true)
Takes ownership of pCell.
Definition: column3.cxx:2315
const ScRangeList & GetRange() const
Definition: conditio.hxx:559
sal_uLong GetColOffset(SCCOL nCol, bool bHiddenAsZero=true) const
Definition: table2.cxx:4190
static void lcl_SetTransposedPatternInRows(ScTable *pTransClip, SCROW nAttrRow1, SCROW nAttrRow2, SCCOL nCol1, SCROW nRow1, SCROW nCombinedStartRow, SCCOL nCol, const ScPatternAttr &rPatternAttr, bool bIncludeFiltered, const std::vector< SCROW > &rFilteredRows, SCROW nRowDestOffset)
Definition: table2.cxx:1012
#define STD_COL_WIDTH
Definition: global.hxx:95
void SetNumberFormat(SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat)
Definition: table2.cxx:2184
bool IsBlockEditable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool *pOnlyNotBecauseOfMatrix=nullptr, bool bNoMatrixAtAll=false) const
Definition: table2.cxx:2555
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:872
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:2035
void SetAnonymousDBData(std::unique_ptr< ScDBData > pDBData)
Definition: table1.cxx:2377
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
Additional class containing cell annotation data.
Definition: postit.hxx:161
void TransposeColNotes(ScTable *pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1, SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered, SCROW nRowDestOffset)
Transpose clipboard notes.
Definition: table2.cxx:1113
static short DiffSign(T a, T b)
Definition: table2.cxx:3862
void GetFormula(SCCOL nCol, SCROW nRow, OUString &rFormula) const
Definition: table2.cxx:1790
sal_uLong GetScaledRowHeight(SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong *pnMaxHeight=nullptr) const
Definition: table2.cxx:3433
bool UpdateOutlineCol(SCCOL nStartCol, SCCOL nEndCol, bool bShow)
Definition: table2.cxx:3785
void SetNumberFormat(SCROW nRow, sal_uInt32 nNumberFormat)
Definition: column2.cxx:3080
double * GetValueCell(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1751
sc::CellStoreType maCells
Definition: column.hxx:129
const std::shared_ptr< const ColumnSet > & getColumnSet() const
void SetColWidthOnly(SCCOL nCol, sal_uInt16 nNewWidth)
Definition: table2.cxx:3113
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:3833
void SetRowManualBreaks(::std::set< SCROW > &&rBreaks)
Definition: table5.cxx:322
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:668
bool SetRowHidden(SCROW nStartRow, SCROW nEndRow, bool bHidden)
Definition: table5.cxx:584
void SetColWidth(SCCOL nCol, sal_uInt16 nNewWidth)
Definition: table2.cxx:3092
const editeng::SvxBorderLine * GetLine(SvxBoxItemLine nLine) const
bool HasValueData(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1980
bool SetFormulaCells(SCROW nRow, std::vector< ScFormulaCell * > &rCells)
Definition: column3.cxx:2353
sal_uInt32 GetNumberFormat(const ScInterpreterContext &rContext, SCROW nRow) const
Definition: column.cxx:422
ScColumnVector::const_iterator begin() const
void SetValue(SCCOL nCol, SCROW nRow, const double &rVal)
Definition: table2.cxx:1731
std::unique_ptr< ScOutlineTable > pOutlineTable
Definition: table.hxx:196
ScAddress aPos
void DoAutoOutline(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: table2.cxx:3903
void SetRangeName(std::unique_ptr< ScRangeName > pNew)
Definition: table2.cxx:4085
void SetPattern(const ScAddress &rPos, const ScPatternAttr &rAttr)
Definition: table2.cxx:3046
bool RemoveFlags(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScMF nFlags)
Definition: table2.cxx:3034
ScBroadcastAreaSlotMachine * GetBASM() const
Definition: document.hxx:2154
void SetCol(SCCOL nColP)
Definition: address.hxx:278
size_t size() const
Definition: conditio.cxx:1772
sal_uInt16 GetOriginalWidth(SCCOL nCol) const
Definition: table2.cxx:3305
bool HasSelectionMatrixFragment(const ScMarkData &rMark) const
Definition: table2.cxx:2539
std::unique_ptr< ScBitMaskCompressedArray< SCCOL, CRFlags > > mpColFlags
Definition: table.hxx:184
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:953
bool IsLayoutRTL() const
Definition: table.hxx:342
float y
bool IsColValid(const SCCOL nScCol) const
Definition: table.hxx:320
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:2197
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:589
sal_uInt32 GetKey() const
Definition: conditio.hxx:591
void SetRange(const ScRangeList &rRanges)
Definition: conditio.cxx:1746
std::unique_ptr< ScFlatBoolColSegments > mpHiddenCols
Definition: table.hxx:186
bool SetFormulaCells(SCCOL nCol, SCROW nRow, std::vector< ScFormulaCell * > &rCells)
Definition: table2.cxx:1715
const ScFormatEntry * GetEntry(sal_uInt16 nPos) const
Definition: conditio.cxx:1786
ScPasteFunc
Definition: global.hxx:189
void ShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
Definition: table2.cxx:3624
void ApplyStyle(SCCOL nCol, SCROW nRow, const ScStyleSheet *rStyle)
Definition: table2.cxx:2867
void SetTab(SCTAB nTabP)
Definition: address.hxx:282
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1058
const editeng::SvxBorderLine * GetTop() const
void SetDrawPageSize(bool bResetStreamValid=true, bool bUpdateNoteCaptionPos=true, const ScObjectHandling eObjectHandling=ScObjectHandling::RecalcPosMode)
Definition: table2.cxx:4056
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
bool ColHidden(SCCOL nCol, SCCOL *pFirstCol=nullptr, SCCOL *pLastCol=nullptr) const
Definition: table5.cxx:567
bool IsProtected() const
Definition: table5.cxx:1084
SC_DLLPUBLIC void SetPattern(const ScAddress &, const ScPatternAttr &rAttr)
Definition: document.cxx:5075
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:332
SCCOL nRotMaxCol
Definition: fillinfo.hxx:182
const ScFormulaCell * GetFormulaCell(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1798
ScDocument & GetDoc()
Definition: table.hxx:281
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
void SetColManualBreaks(::std::set< SCCOL > &&rBreaks)
Definition: table5.cxx:329
int i
void SetDirtyVar()
Definition: table2.cxx:2002
void SetRawString(SCROW nRow, const OUString &rStr)
Definition: column3.cxx:2888
void AddCondFormatData(const ScRangeList &rRange, sal_uInt32 nIndex)
Definition: table2.cxx:2816
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
const ScRangeList * GetScenarioRanges() const
Definition: table2.cxx:1593
void CheckVectorizationState()
Definition: table2.cxx:2008
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:3268
InsertDeleteFlags
Definition: global.hxx:158
void InvalidateScenarioRanges()
Definition: table2.cxx:1588
void CopyCaptionsToTable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable *pDestTab, bool bCloneCaption)
Definition: table2.cxx:1451
std::unique_ptr< ScDBData > pDBDataNoName
Definition: table.hxx:226
SC_DLLPUBLIC void SetAutoCalc(bool bNewAutoCalc)
Definition: documen7.cxx:602
void CopyRowHidden(const ScTable &rTable, SCROW nStartRow, SCROW nEndRow)
Definition: table5.cxx:683
static SC_DLLPUBLIC const CharClass & getCharClass()
Definition: global.cxx:1016
sc::CellTextAttrStoreType maCellTextAttrs
Definition: column.hxx:118
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:3715
void SetEmptyCell(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1678
const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, sal_uInt16 nWhich) const
Definition: table2.cxx:2148
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:873
SvNumberFormatter * GetFormatTable() const
const SvxPageUsage aArr[]
ScScenarioFlags nScenarioFlags
Definition: table.hxx:225
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:1902
void ShowCol(SCCOL nCol, bool bShow)
Definition: table2.cxx:3523
const ScPatternAttr * SetPattern(SCROW nRow, std::unique_ptr< ScPatternAttr >)
Definition: column.cxx:700
bool HasAttribSelection(const ScMarkData &rMark, HasAttrFlags nMask) const
Definition: table2.cxx:2225
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:1774
void DBShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
Definition: table2.cxx:3592
void GetNotesInRange(const ScRange &rRange, std::vector< sc::NoteEntry > &rNotes) const
Definition: table2.cxx:1858
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:838
size_t size() const
Definition: rangelst.hxx:89
std::unique_ptr< ScTableProtection > pTabProtection
Definition: table.hxx:179
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
void GetLastDataPos(SCCOL &rCol, SCROW &rRow) const
Definition: table2.cxx:1953
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
bool IsCutMode()
Definition: document.cxx:2039
CellStoreType::const_iterator ParseAll(const typename CellStoreType::const_iterator &itPos, const CellStoreType &rCells, SCROW nRow1, SCROW nRow2, FuncElem &rFuncElem, FuncElse &rFuncElse)
Definition: mtvcellfunc.hxx:83
void SetNote(const ScAddress &rPos, std::unique_ptr< ScPostIt > pNote)
Definition: document.cxx:6549
void SetRangeDirty(const ScRange &rRange)
Definition: chartlis.cxx:569
void CompileXML(sc::CompileFormulaContext &rCxt, ScProgress &rProgress)
Definition: table2.cxx:2103
SvNumFormatType
bool EqualEntries(const ScConditionalFormat &r, bool bIgnoreSrcPos=false) const
Definition: conditio.cxx:1727
bool bTableAreaValid
Definition: table.hxx:237
ScColContainer aCol
Definition: table.hxx:158
void SetRawString(SCCOL nCol, SCROW nRow, const svl::SharedString &rStr)
Definition: table2.cxx:1737
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1256
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1291
void LockTable()
Definition: table2.cxx:2723
void DBShowRow(SCROW nRow, bool bShow)
Definition: table2.cxx:3566
::std::set< SCROW > maRowManualBreaks
Definition: table.hxx:192
std::unique_ptr< ScConditionalFormatList > mpCondFormatList
Definition: table.hxx:229
double * GetValueCell(SCROW nRow)
Definition: column3.cxx:2986
void SetDistance(sal_uInt16 nNew, SvxBoxItemLine nLine)
void ApplySelectionLineStyle(const ScMarkData &rMark, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: table2.cxx:2911
void BroadcastRecalcOnRefMove()
Broadcast dirty formula cells that contain functions such as CELL(), COLUMN() or ROW() which may chan...
Definition: table2.cxx:2063
bool empty() const
CommentCaptionState
Definition: document.hxx:253
void ExtendHidden(SCCOL &rX1, SCROW &rY1, SCCOL &rX2, SCROW &rY2)
Definition: table2.cxx:3803
void SetAreasChangedNeedBroadcast()
Definition: docsh.hxx:389