Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / docshell / olinefun.cxx
blob07659027429157e0f504e2238a4319b6f12de0cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/bindings.hxx>
22 #include "olinefun.hxx"
24 #include "docsh.hxx"
25 #include "olinetab.hxx"
26 #include "undodat.hxx"
27 #include "globstr.hrc"
28 #include "sc.hrc"
30 static void lcl_InvalidateOutliner( SfxBindings* pBindings )
32 if ( pBindings )
34 pBindings->Invalidate( SID_OUTLINE_SHOW );
35 pBindings->Invalidate( SID_OUTLINE_HIDE );
36 pBindings->Invalidate( SID_OUTLINE_REMOVE );
38 pBindings->Invalidate( SID_STATUS_SUM ); // wegen ein-/ausblenden
39 pBindings->Invalidate( SID_ATTR_SIZE );
43 //! PaintWidthHeight zur DocShell verschieben?
45 static void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab,
46 bool bColumns, SCCOLROW nStart, SCCOLROW nEnd )
48 ScDocument& rDoc = rDocShell.GetDocument();
50 sal_uInt16 nParts = PAINT_GRID;
51 SCCOL nStartCol = 0;
52 SCROW nStartRow = 0;
53 SCCOL nEndCol = MAXCOL; // fuer Test auf Merge
54 SCROW nEndRow = MAXROW;
55 if ( bColumns )
57 nParts |= PAINT_TOP;
58 nStartCol = static_cast<SCCOL>(nStart);
59 nEndCol = static_cast<SCCOL>(nEnd);
61 else
63 nParts |= PAINT_LEFT;
64 nStartRow = nStart;
65 nEndRow = nEnd;
67 if (rDoc.HasAttrib( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
68 HASATTR_MERGED | HASATTR_OVERLAPPED ))
70 nStartCol = 0;
71 nStartRow = 0;
73 rDocShell.PostPaint( nStartCol,nStartRow,nTab, MAXCOL,MAXROW,nTab, nParts );
76 void ScOutlineDocFunc::MakeOutline( const ScRange& rRange, bool bColumns, bool bRecord, bool bApi )
78 SCCOL nStartCol = rRange.aStart.Col();
79 SCROW nStartRow = rRange.aStart.Row();
80 SCCOL nEndCol = rRange.aEnd.Col();
81 SCROW nEndRow = rRange.aEnd.Row();
82 SCTAB nTab = rRange.aStart.Tab();
84 ScDocument& rDoc = rDocShell.GetDocument();
85 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab, true );
86 ScOutlineTable* pUndoTab = nullptr;
88 if (bRecord && !rDoc.IsUndoEnabled())
89 bRecord = false;
91 if (bRecord)
92 pUndoTab = new ScOutlineTable( *pTable );
94 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
96 bool bRes;
97 bool bSize = false;
98 if ( bColumns )
99 bRes = rArray.Insert( nStartCol, nEndCol, bSize );
100 else
101 bRes = rArray.Insert( nStartRow, nEndRow, bSize );
103 if ( bRes )
105 if (bRecord)
107 rDocShell.GetUndoManager()->AddUndoAction(
108 new ScUndoMakeOutline( &rDocShell,
109 nStartCol,nStartRow,nTab,nEndCol,nEndRow,nTab,
110 pUndoTab, bColumns, true ) );
113 if (rDoc.IsStreamValid(nTab))
114 rDoc.SetStreamValid(nTab, false);
116 sal_uInt16 nParts = 0; // Datenbereich nicht geaendert
117 if ( bColumns )
118 nParts |= PAINT_TOP;
119 else
120 nParts |= PAINT_LEFT;
121 if ( bSize )
122 nParts |= PAINT_SIZE;
124 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
125 rDocShell.SetDocumentModified();
126 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
128 else
130 if (!bApi)
131 rDocShell.ErrorMessage(STR_MSSG_MAKEOUTLINE_0); // "Gruppierung nicht moeglich"
132 delete pUndoTab;
136 void ScOutlineDocFunc::RemoveOutline( const ScRange& rRange, bool bColumns, bool bRecord, bool bApi )
138 bool bDone = false;
140 SCCOL nStartCol = rRange.aStart.Col();
141 SCROW nStartRow = rRange.aStart.Row();
142 SCCOL nEndCol = rRange.aEnd.Col();
143 SCROW nEndRow = rRange.aEnd.Row();
144 SCTAB nTab = rRange.aStart.Tab();
146 ScDocument& rDoc = rDocShell.GetDocument();
148 if (bRecord && !rDoc.IsUndoEnabled())
149 bRecord = false;
150 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
151 if (pTable)
153 ScOutlineTable* pUndoTab = nullptr;
154 if (bRecord)
155 pUndoTab = new ScOutlineTable( *pTable );
157 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
159 bool bRes;
160 bool bSize = false;
161 if ( bColumns )
162 bRes = rArray.Remove( nStartCol, nEndCol, bSize );
163 else
164 bRes = rArray.Remove( nStartRow, nEndRow, bSize );
166 if ( bRes )
168 if (bRecord)
170 rDocShell.GetUndoManager()->AddUndoAction(
171 new ScUndoMakeOutline( &rDocShell,
172 nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
173 pUndoTab, bColumns, false ) );
176 if (rDoc.IsStreamValid(nTab))
177 rDoc.SetStreamValid(nTab, false);
179 sal_uInt16 nParts = 0; // Datenbereich nicht geaendert
180 if ( bColumns )
181 nParts |= PAINT_TOP;
182 else
183 nParts |= PAINT_LEFT;
184 if ( bSize )
185 nParts |= PAINT_SIZE;
187 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
188 rDocShell.SetDocumentModified();
189 bDone = true;
190 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
192 // es wird nicht wieder eingeblendet -> kein UpdatePageBreaks
194 else
195 delete pUndoTab;
198 if (!bDone && !bApi)
199 rDocShell.ErrorMessage(STR_MSSG_REMOVEOUTLINE_0); // "Aufheben nicht moeglich"
202 bool ScOutlineDocFunc::RemoveAllOutlines( SCTAB nTab, bool bRecord )
204 bool bSuccess = false;
205 ScDocument& rDoc = rDocShell.GetDocument();
207 if (bRecord && !rDoc.IsUndoEnabled())
208 bRecord = false;
209 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
210 if (pTable)
212 if (bRecord)
214 SCCOLROW nCol1, nCol2, nRow1, nRow2;
215 pTable->GetColArray().GetRange( nCol1, nCol2 );
216 pTable->GetRowArray().GetRange( nRow1, nRow2 );
217 SCCOL nStartCol = static_cast<SCCOL>(nCol1);
218 SCROW nStartRow = nRow1;
219 SCCOL nEndCol = static_cast<SCCOL>(nCol2);
220 SCROW nEndRow = nRow2;
222 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
223 pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true );
224 rDoc.CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
225 rDoc.CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
227 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
229 rDocShell.GetUndoManager()->AddUndoAction(
230 new ScUndoRemoveAllOutlines( &rDocShell,
231 nStartCol, nStartRow, nTab,
232 nEndCol, nEndRow, nTab,
233 pUndoDoc, pUndoTab ) );
236 SelectLevel( nTab, true, pTable->GetColArray().GetDepth(), false, false );
237 SelectLevel( nTab, false, pTable->GetRowArray().GetDepth(), false, false );
238 rDoc.SetOutlineTable( nTab, nullptr );
240 rDoc.UpdatePageBreaks( nTab );
242 if (rDoc.IsStreamValid(nTab))
243 rDoc.SetStreamValid(nTab, false);
245 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab,
246 PAINT_GRID | PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
247 rDocShell.SetDocumentModified();
248 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
249 bSuccess = true;
252 return bSuccess;
255 void ScOutlineDocFunc::AutoOutline( const ScRange& rRange, bool bRecord )
257 SCCOL nStartCol = rRange.aStart.Col();
258 SCROW nStartRow = rRange.aStart.Row();
259 SCCOL nEndCol = rRange.aEnd.Col();
260 SCROW nEndRow = rRange.aEnd.Row();
261 SCTAB nTab = rRange.aStart.Tab();
263 ScDocument& rDoc = rDocShell.GetDocument();
265 if (bRecord && !rDoc.IsUndoEnabled())
266 bRecord = false;
267 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
269 ScDocument* pUndoDoc = nullptr;
270 ScOutlineTable* pUndoTab = nullptr;
272 if ( pTable )
274 if ( bRecord )
276 pUndoTab = new ScOutlineTable( *pTable );
278 SCCOLROW nCol1, nCol2, nRow1, nRow2;
279 pTable->GetColArray().GetRange( nCol1, nCol2 );
280 pTable->GetRowArray().GetRange( nRow1, nRow2 );
281 SCCOL nOutStartCol = static_cast<SCCOL>(nCol1);
282 SCROW nOutStartRow = nRow1;
283 SCCOL nOutEndCol = static_cast<SCCOL>(nCol2);
284 SCROW nOutEndRow = nRow2;
286 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
287 pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true );
288 rDoc.CopyToDocument( nOutStartCol, 0, nTab, nOutEndCol, MAXROW, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
289 rDoc.CopyToDocument( 0, nOutStartRow, nTab, MAXCOL, nOutEndRow, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
292 // einblenden
293 SelectLevel( nTab, true, pTable->GetColArray().GetDepth(), false, false );
294 SelectLevel( nTab, false, pTable->GetRowArray().GetDepth(), false, false );
295 rDoc.SetOutlineTable( nTab, nullptr );
298 rDoc.DoAutoOutline( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
300 if (bRecord)
302 rDocShell.GetUndoManager()->AddUndoAction(
303 new ScUndoAutoOutline( &rDocShell,
304 nStartCol, nStartRow, nTab,
305 nEndCol, nEndRow, nTab,
306 pUndoDoc, pUndoTab ) );
309 if (rDoc.IsStreamValid(nTab))
310 rDoc.SetStreamValid(nTab, false);
312 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
313 rDocShell.SetDocumentModified();
314 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
317 bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel,
318 bool bRecord, bool bPaint )
320 ScDocument& rDoc = rDocShell.GetDocument();
322 if (bRecord && !rDoc.IsUndoEnabled())
323 bRecord = false;
324 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab ); // ist schon da
325 if (!pTable)
326 return false;
327 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
329 SCCOLROW nStart, nEnd;
330 rArray.GetRange( nStart, nEnd );
332 if ( bRecord )
334 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
335 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
336 if (bColumns)
338 pUndoDoc->InitUndo( &rDoc, nTab, nTab, true );
339 rDoc.CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
340 static_cast<SCCOL>(nEnd), MAXROW, nTab, InsertDeleteFlags::NONE, false,
341 pUndoDoc );
343 else
345 pUndoDoc->InitUndo( &rDoc, nTab, nTab, false, true );
346 rDoc.CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
349 rDocShell.GetUndoManager()->AddUndoAction(
350 new ScUndoOutlineLevel( &rDocShell,
351 nStart, nEnd, nTab, //! start und end berechnen
352 pUndoDoc, pUndoTab,
353 bColumns, nLevel ) );
356 ScSubOutlineIterator aIter( &rArray ); // alle Eintraege
357 ScOutlineEntry* pEntry;
358 while ((pEntry=aIter.GetNext()) != nullptr)
360 sal_uInt16 nThisLevel = aIter.LastLevel();
361 bool bShow = (nThisLevel < nLevel);
362 if (bShow) // einblenden
364 pEntry->SetHidden( false );
365 pEntry->SetVisible( true );
367 else if ( nThisLevel == nLevel ) // ausblenden
369 pEntry->SetHidden( true );
370 pEntry->SetVisible( true );
372 else // verdeckt
374 pEntry->SetVisible( false );
377 SCCOLROW nThisStart = pEntry->GetStart();
378 SCCOLROW nThisEnd = pEntry->GetEnd();
379 for (SCCOLROW i=nThisStart; i<=nThisEnd; i++)
381 if ( bColumns )
382 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, bShow );
383 else
385 // show several rows together, don't show filtered rows
386 SCROW nFilterEnd = i;
387 bool bFiltered = rDoc.RowFiltered( i, nTab, nullptr, &nFilterEnd );
388 nFilterEnd = std::min( nThisEnd, nFilterEnd );
389 if ( !bShow || !bFiltered )
390 rDoc.ShowRows( i, nFilterEnd, nTab, bShow );
391 i = nFilterEnd;
396 rDoc.SetDrawPageSize(nTab);
397 rDoc.UpdatePageBreaks( nTab );
399 if (bPaint)
400 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
402 rDocShell.SetDocumentModified();
403 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
405 return true;
408 bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord )
410 bool bDone = false;
412 SCCOL nStartCol = rRange.aStart.Col();
413 SCROW nStartRow = rRange.aStart.Row();
414 SCCOL nEndCol = rRange.aEnd.Col();
415 SCROW nEndRow = rRange.aEnd.Row();
416 SCTAB nTab = rRange.aStart.Tab();
418 ScDocument& rDoc = rDocShell.GetDocument();
420 if (bRecord && !rDoc.IsUndoEnabled())
421 bRecord = false;
422 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
424 if (pTable)
426 ScOutlineEntry* pEntry;
427 SCCOLROW nStart;
428 SCCOLROW nEnd;
429 SCCOLROW nMin;
430 SCCOLROW nMax;
431 SCCOLROW i;
433 if ( bRecord )
435 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
436 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
437 pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true );
438 rDoc.CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
439 rDoc.CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
441 rDocShell.GetUndoManager()->AddUndoAction(
442 new ScUndoOutlineBlock( &rDocShell,
443 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
444 pUndoDoc, pUndoTab, true ) );
447 // Spalten
449 nMin=MAXCOL;
450 nMax=0;
451 ScOutlineArray& rColArray = pTable->GetColArray();
452 ScSubOutlineIterator aColIter( &rColArray );
453 while ((pEntry=aColIter.GetNext()) != nullptr)
455 nStart = pEntry->GetStart();
456 nEnd = pEntry->GetEnd();
457 if ( nStart>=nStartCol && nEnd<=nEndCol )
459 pEntry->SetHidden( false );
460 pEntry->SetVisible( true );
461 if (nStart<nMin) nMin=nStart;
462 if (nEnd>nMax) nMax=nEnd;
465 for ( i=nMin; i<=nMax; i++ )
466 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, true );
468 // Zeilen
470 nMin=MAXROW;
471 nMax=0;
472 ScOutlineArray& rRowArray = pTable->GetRowArray();
473 ScSubOutlineIterator aRowIter( &rRowArray );
474 while ((pEntry=aRowIter.GetNext()) != nullptr)
476 nStart = pEntry->GetStart();
477 nEnd = pEntry->GetEnd();
478 if ( nStart>=nStartRow && nEnd<=nEndRow )
480 pEntry->SetHidden( false );
481 pEntry->SetVisible( true );
482 if (nStart<nMin) nMin=nStart;
483 if (nEnd>nMax) nMax=nEnd;
486 for ( i=nMin; i<=nMax; i++ )
488 // show several rows together, don't show filtered rows
489 SCROW nFilterEnd = i;
490 bool bFiltered = rDoc.RowFiltered( i, nTab, nullptr, &nFilterEnd );
491 nFilterEnd = std::min( nMax, nFilterEnd );
492 if ( !bFiltered )
493 rDoc.ShowRows( i, nFilterEnd, nTab, true );
494 i = nFilterEnd;
497 rDoc.SetDrawPageSize(nTab);
498 rDoc.UpdatePageBreaks( nTab );
500 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
501 rDocShell.SetDocumentModified();
502 bDone = true;
504 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
507 return bDone;
510 bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, bool bRecord )
512 bool bDone = false;
514 SCCOL nStartCol = rRange.aStart.Col();
515 SCROW nStartRow = rRange.aStart.Row();
516 SCCOL nEndCol = rRange.aEnd.Col();
517 SCROW nEndRow = rRange.aEnd.Row();
518 SCTAB nTab = rRange.aStart.Tab();
520 ScDocument& rDoc = rDocShell.GetDocument();
522 if (bRecord && !rDoc.IsUndoEnabled())
523 bRecord = false;
524 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
526 if (pTable)
528 const ScOutlineEntry* pEntry;
529 size_t nColLevel;
530 size_t nRowLevel;
531 sal_uInt16 nCount;
532 SCCOLROW nStart;
533 SCCOLROW nEnd;
534 sal_uInt16 i;
536 SCCOLROW nEffStartCol = nStartCol;
537 SCCOLROW nEffEndCol = nEndCol;
538 ScOutlineArray& rColArray = pTable->GetColArray();
539 rColArray.FindTouchedLevel( nStartCol, nEndCol, nColLevel );
540 rColArray.ExtendBlock( nColLevel, nEffStartCol, nEffEndCol );
541 SCCOLROW nEffStartRow = nStartRow;
542 SCCOLROW nEffEndRow = nEndRow;
543 ScOutlineArray& rRowArray = pTable->GetRowArray();
544 rRowArray.FindTouchedLevel( nStartRow, nEndRow, nRowLevel );
545 rRowArray.ExtendBlock( nRowLevel, nEffStartRow, nEffEndRow );
547 if ( bRecord )
549 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
550 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
551 pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true );
552 rDoc.CopyToDocument( static_cast<SCCOL>(nEffStartCol), 0, nTab,
553 static_cast<SCCOL>(nEffEndCol), MAXROW, nTab, InsertDeleteFlags::NONE,
554 false, pUndoDoc );
555 rDoc.CopyToDocument( 0, nEffStartRow, nTab, MAXCOL, nEffEndRow, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
557 rDocShell.GetUndoManager()->AddUndoAction(
558 new ScUndoOutlineBlock( &rDocShell,
559 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
560 pUndoDoc, pUndoTab, false ) );
563 // Spalten
565 nCount = rColArray.GetCount(nColLevel);
566 for ( i=0; i<nCount; i++ )
568 pEntry = rColArray.GetEntry(nColLevel,i);
569 nStart = pEntry->GetStart();
570 nEnd = pEntry->GetEnd();
572 if ( static_cast<SCCOLROW>(nStartCol)<=nEnd && static_cast<SCCOLROW>(nEndCol)>=nStart )
573 HideOutline( nTab, true, nColLevel, i, false, false );
576 // Zeilen
578 nCount = rRowArray.GetCount(nRowLevel);
579 for ( i=0; i<nCount; i++ )
581 pEntry = rRowArray.GetEntry(nRowLevel,i);
582 nStart = pEntry->GetStart();
583 nEnd = pEntry->GetEnd();
585 if ( nStartRow<=nEnd && nEndRow>=nStart )
586 HideOutline( nTab, false, nRowLevel, i, false, false );
589 rDoc.SetDrawPageSize(nTab);
590 rDoc.UpdatePageBreaks( nTab );
592 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
594 rDocShell.SetDocumentModified();
595 bDone = true;
597 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
600 return bDone;
603 bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
604 bool bRecord, bool bPaint )
606 ScDocument& rDoc = rDocShell.GetDocument();
607 if (bRecord && !rDoc.IsUndoEnabled())
608 bRecord = false;
610 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
611 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
612 ScOutlineEntry* pEntry = rArray.GetEntry( nLevel, nEntry );
613 SCCOLROW nStart = pEntry->GetStart();
614 SCCOLROW nEnd = pEntry->GetEnd();
616 if ( bRecord )
618 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
619 if (bColumns)
621 pUndoDoc->InitUndo( &rDoc, nTab, nTab, true );
622 rDoc.CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
623 static_cast<SCCOL>(nEnd), MAXROW, nTab, InsertDeleteFlags::NONE, false,
624 pUndoDoc );
626 else
628 pUndoDoc->InitUndo( &rDoc, nTab, nTab, false, true );
629 rDoc.CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
632 rDocShell.GetUndoManager()->AddUndoAction(
633 new ScUndoDoOutline( &rDocShell,
634 nStart, nEnd, nTab, pUndoDoc, //! start und end berechnen
635 bColumns, nLevel, nEntry, true ) );
638 pEntry->SetHidden(false);
639 SCCOLROW i;
640 for ( i = nStart; i <= nEnd; i++ )
642 if ( bColumns )
643 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, true );
644 else
646 // show several rows together, don't show filtered rows
647 SCROW nFilterEnd = i;
648 bool bFiltered = rDoc.RowFiltered( i, nTab, nullptr, &nFilterEnd );
649 nFilterEnd = std::min( nEnd, nFilterEnd );
650 if ( !bFiltered )
651 rDoc.ShowRows( i, nFilterEnd, nTab, true );
652 i = nFilterEnd;
656 ScSubOutlineIterator aIter( &rArray, nLevel, nEntry );
657 while ((pEntry=aIter.GetNext()) != nullptr)
659 if ( pEntry->IsHidden() )
661 SCCOLROW nSubStart = pEntry->GetStart();
662 SCCOLROW nSubEnd = pEntry->GetEnd();
663 if ( bColumns )
664 for ( i = nSubStart; i <= nSubEnd; i++ )
665 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, false );
666 else
667 rDoc.ShowRows( nSubStart, nSubEnd, nTab, false );
671 rArray.SetVisibleBelow( nLevel, nEntry, true, true );
673 rDoc.SetDrawPageSize(nTab);
674 rDoc.InvalidatePageBreaks(nTab);
675 rDoc.UpdatePageBreaks( nTab );
677 if (bPaint)
678 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
680 rDocShell.SetDocumentModified();
682 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
684 return true; //! immer ???
687 bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
688 bool bRecord, bool bPaint )
690 ScDocument& rDoc = rDocShell.GetDocument();
691 if (bRecord && !rDoc.IsUndoEnabled())
692 bRecord = false;
694 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
695 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
696 ScOutlineEntry* pEntry = rArray.GetEntry( nLevel, nEntry );
697 SCCOLROW nStart = pEntry->GetStart();
698 SCCOLROW nEnd = pEntry->GetEnd();
700 if ( bRecord )
702 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
703 if (bColumns)
705 pUndoDoc->InitUndo( &rDoc, nTab, nTab, true );
706 rDoc.CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
707 static_cast<SCCOL>(nEnd), MAXROW, nTab, InsertDeleteFlags::NONE, false,
708 pUndoDoc );
710 else
712 pUndoDoc->InitUndo( &rDoc, nTab, nTab, false, true );
713 rDoc.CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, InsertDeleteFlags::NONE, false, pUndoDoc );
716 rDocShell.GetUndoManager()->AddUndoAction(
717 new ScUndoDoOutline( &rDocShell,
718 nStart, nEnd, nTab, pUndoDoc,
719 bColumns, nLevel, nEntry, false ) );
722 pEntry->SetHidden(true);
723 SCCOLROW i;
724 if ( bColumns )
725 for ( i = nStart; i <= nEnd; i++ )
726 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, false );
727 else
728 rDoc.ShowRows( nStart, nEnd, nTab, false );
730 rArray.SetVisibleBelow( nLevel, nEntry, false );
732 rDoc.SetDrawPageSize(nTab);
733 rDoc.InvalidatePageBreaks(nTab);
734 rDoc.UpdatePageBreaks( nTab );
736 if (bPaint)
737 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
739 rDocShell.SetDocumentModified();
741 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
743 return true; //! immer ???
746 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */