Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / docshell / olinefun.cxx
blob8be9257a17164d9d96d09200351b36d7ab78571e
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"
31 //========================================================================
33 static void lcl_InvalidateOutliner( SfxBindings* pBindings )
35 if ( pBindings )
37 pBindings->Invalidate( SID_OUTLINE_SHOW );
38 pBindings->Invalidate( SID_OUTLINE_HIDE );
39 pBindings->Invalidate( SID_OUTLINE_REMOVE );
41 pBindings->Invalidate( SID_STATUS_SUM ); // wegen ein-/ausblenden
42 pBindings->Invalidate( SID_ATTR_SIZE );
46 //------------------------------------------------------------------------
48 //! PaintWidthHeight zur DocShell verschieben?
50 static void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab,
51 sal_Bool bColumns, SCCOLROW nStart, SCCOLROW nEnd )
53 ScDocument* pDoc = rDocShell.GetDocument();
55 sal_uInt16 nParts = PAINT_GRID;
56 SCCOL nStartCol = 0;
57 SCROW nStartRow = 0;
58 SCCOL nEndCol = MAXCOL; // fuer Test auf Merge
59 SCROW nEndRow = MAXROW;
60 if ( bColumns )
62 nParts |= PAINT_TOP;
63 nStartCol = static_cast<SCCOL>(nStart);
64 nEndCol = static_cast<SCCOL>(nEnd);
66 else
68 nParts |= PAINT_LEFT;
69 nStartRow = nStart;
70 nEndRow = nEnd;
72 if (pDoc->HasAttrib( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
73 HASATTR_MERGED | HASATTR_OVERLAPPED ))
75 nStartCol = 0;
76 nStartRow = 0;
78 rDocShell.PostPaint( nStartCol,nStartRow,nTab, MAXCOL,MAXROW,nTab, nParts );
81 //------------------------------------------------------------------------
83 sal_Bool ScOutlineDocFunc::MakeOutline( const ScRange& rRange, sal_Bool bColumns, sal_Bool bRecord, sal_Bool bApi )
85 sal_Bool bSuccess = false;
86 SCCOL nStartCol = rRange.aStart.Col();
87 SCROW nStartRow = rRange.aStart.Row();
88 SCCOL nEndCol = rRange.aEnd.Col();
89 SCROW nEndRow = rRange.aEnd.Row();
90 SCTAB nTab = rRange.aStart.Tab();
92 ScDocument* pDoc = rDocShell.GetDocument();
93 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab, sal_True );
94 ScOutlineTable* pUndoTab = NULL;
96 if (bRecord && !pDoc->IsUndoEnabled())
97 bRecord = false;
99 if (bRecord)
100 pUndoTab = new ScOutlineTable( *pTable );
102 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
104 bool bRes;
105 bool bSize = false;
106 if ( bColumns )
107 bRes = pArray->Insert( nStartCol, nEndCol, bSize );
108 else
109 bRes = pArray->Insert( nStartRow, nEndRow, bSize );
111 if ( bRes )
113 if (bRecord)
115 rDocShell.GetUndoManager()->AddUndoAction(
116 new ScUndoMakeOutline( &rDocShell,
117 nStartCol,nStartRow,nTab,nEndCol,nEndRow,nTab,
118 pUndoTab, bColumns, sal_True ) );
121 if (pDoc->IsStreamValid(nTab))
122 pDoc->SetStreamValid(nTab, false);
124 sal_uInt16 nParts = 0; // Datenbereich nicht geaendert
125 if ( bColumns )
126 nParts |= PAINT_TOP;
127 else
128 nParts |= PAINT_LEFT;
129 if ( bSize )
130 nParts |= PAINT_SIZE;
132 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
133 rDocShell.SetDocumentModified();
134 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
135 bSuccess = sal_True;
137 else
139 if (!bApi)
140 rDocShell.ErrorMessage(STR_MSSG_MAKEOUTLINE_0); // "Gruppierung nicht moeglich"
141 delete pUndoTab;
144 return bSuccess;
147 sal_Bool ScOutlineDocFunc::RemoveOutline( const ScRange& rRange, sal_Bool bColumns, sal_Bool bRecord, sal_Bool bApi )
149 sal_Bool bDone = false;
151 SCCOL nStartCol = rRange.aStart.Col();
152 SCROW nStartRow = rRange.aStart.Row();
153 SCCOL nEndCol = rRange.aEnd.Col();
154 SCROW nEndRow = rRange.aEnd.Row();
155 SCTAB nTab = rRange.aStart.Tab();
157 ScDocument* pDoc = rDocShell.GetDocument();
159 if (bRecord && !pDoc->IsUndoEnabled())
160 bRecord = false;
161 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
162 if (pTable)
164 ScOutlineTable* pUndoTab = NULL;
165 if (bRecord)
166 pUndoTab = new ScOutlineTable( *pTable );
168 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
170 bool bRes;
171 bool bSize = false;
172 if ( bColumns )
173 bRes = pArray->Remove( nStartCol, nEndCol, bSize );
174 else
175 bRes = pArray->Remove( nStartRow, nEndRow, bSize );
177 if ( bRes )
179 if (bRecord)
181 rDocShell.GetUndoManager()->AddUndoAction(
182 new ScUndoMakeOutline( &rDocShell,
183 nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
184 pUndoTab, bColumns, false ) );
187 if (pDoc->IsStreamValid(nTab))
188 pDoc->SetStreamValid(nTab, false);
190 sal_uInt16 nParts = 0; // Datenbereich nicht geaendert
191 if ( bColumns )
192 nParts |= PAINT_TOP;
193 else
194 nParts |= PAINT_LEFT;
195 if ( bSize )
196 nParts |= PAINT_SIZE;
198 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
199 rDocShell.SetDocumentModified();
200 bDone = sal_True;
201 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
203 // es wird nicht wieder eingeblendet -> kein UpdatePageBreaks
205 else
206 delete pUndoTab;
209 if (!bDone && !bApi)
210 rDocShell.ErrorMessage(STR_MSSG_REMOVEOUTLINE_0); // "Aufheben nicht moeglich"
212 return bDone;
215 sal_Bool ScOutlineDocFunc::RemoveAllOutlines( SCTAB nTab, sal_Bool bRecord, sal_Bool bApi )
217 sal_Bool bSuccess = false;
218 ScDocument* pDoc = rDocShell.GetDocument();
220 if (bRecord && !pDoc->IsUndoEnabled())
221 bRecord = false;
222 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
223 if (pTable)
225 if (bRecord)
227 SCCOLROW nCol1, nCol2, nRow1, nRow2;
228 pTable->GetColArray()->GetRange( nCol1, nCol2 );
229 pTable->GetRowArray()->GetRange( nRow1, nRow2 );
230 SCCOL nStartCol = static_cast<SCCOL>(nCol1);
231 SCROW nStartRow = nRow1;
232 SCCOL nEndCol = static_cast<SCCOL>(nCol2);
233 SCROW nEndRow = nRow2;
235 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
236 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
237 pDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, false, pUndoDoc );
238 pDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pUndoDoc );
240 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
242 rDocShell.GetUndoManager()->AddUndoAction(
243 new ScUndoRemoveAllOutlines( &rDocShell,
244 nStartCol, nStartRow, nTab,
245 nEndCol, nEndRow, nTab,
246 pUndoDoc, pUndoTab ) );
249 SelectLevel( nTab, sal_True, pTable->GetColArray()->GetDepth(), false, false, bApi );
250 SelectLevel( nTab, false, pTable->GetRowArray()->GetDepth(), false, false, bApi );
251 pDoc->SetOutlineTable( nTab, NULL );
253 pDoc->UpdatePageBreaks( nTab );
255 if (pDoc->IsStreamValid(nTab))
256 pDoc->SetStreamValid(nTab, false);
258 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab,
259 PAINT_GRID | PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
260 rDocShell.SetDocumentModified();
261 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
262 bSuccess = sal_True;
265 return bSuccess;
268 //------------------------------------------------------------------------
270 sal_Bool ScOutlineDocFunc::AutoOutline( const ScRange& rRange, sal_Bool bRecord, sal_Bool bApi )
272 SCCOL nStartCol = rRange.aStart.Col();
273 SCROW nStartRow = rRange.aStart.Row();
274 SCCOL nEndCol = rRange.aEnd.Col();
275 SCROW nEndRow = rRange.aEnd.Row();
276 SCTAB nTab = rRange.aStart.Tab();
278 ScDocument* pDoc = rDocShell.GetDocument();
280 if (bRecord && !pDoc->IsUndoEnabled())
281 bRecord = false;
282 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
284 ScDocument* pUndoDoc = NULL;
285 ScOutlineTable* pUndoTab = NULL;
287 if ( pTable )
289 if ( bRecord )
291 pUndoTab = new ScOutlineTable( *pTable );
293 SCCOLROW nCol1, nCol2, nRow1, nRow2;
294 pTable->GetColArray()->GetRange( nCol1, nCol2 );
295 pTable->GetRowArray()->GetRange( nRow1, nRow2 );
296 SCCOL nOutStartCol = static_cast<SCCOL>(nCol1);
297 SCROW nOutStartRow = nRow1;
298 SCCOL nOutEndCol = static_cast<SCCOL>(nCol2);
299 SCROW nOutEndRow = nRow2;
301 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
302 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
303 pDoc->CopyToDocument( nOutStartCol, 0, nTab, nOutEndCol, MAXROW, nTab, IDF_NONE, false, pUndoDoc );
304 pDoc->CopyToDocument( 0, nOutStartRow, nTab, MAXCOL, nOutEndRow, nTab, IDF_NONE, false, pUndoDoc );
307 // einblenden
308 SelectLevel( nTab, sal_True, pTable->GetColArray()->GetDepth(), false, false, bApi );
309 SelectLevel( nTab, false, pTable->GetRowArray()->GetDepth(), false, false, bApi );
310 pDoc->SetOutlineTable( nTab, NULL );
313 pDoc->DoAutoOutline( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
315 if (bRecord)
317 rDocShell.GetUndoManager()->AddUndoAction(
318 new ScUndoAutoOutline( &rDocShell,
319 nStartCol, nStartRow, nTab,
320 nEndCol, nEndRow, nTab,
321 pUndoDoc, pUndoTab ) );
324 if (pDoc->IsStreamValid(nTab))
325 pDoc->SetStreamValid(nTab, false);
327 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
328 rDocShell.SetDocumentModified();
329 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
331 return sal_True;
334 //------------------------------------------------------------------------
336 sal_Bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, sal_Bool bColumns, sal_uInt16 nLevel,
337 sal_Bool bRecord, sal_Bool bPaint, sal_Bool /* bApi */ )
339 ScDocument* pDoc = rDocShell.GetDocument();
341 if (bRecord && !pDoc->IsUndoEnabled())
342 bRecord = false;
343 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab ); // ist schon da
344 if (!pTable)
345 return false;
346 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
347 if (!pArray)
348 return false;
350 SCCOLROW nStart, nEnd;
351 pArray->GetRange( nStart, nEnd );
353 if ( bRecord )
355 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
356 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
357 if (bColumns)
359 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, false );
360 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
361 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false,
362 pUndoDoc );
364 else
366 pUndoDoc->InitUndo( pDoc, nTab, nTab, false, sal_True );
367 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pUndoDoc );
370 rDocShell.GetUndoManager()->AddUndoAction(
371 new ScUndoOutlineLevel( &rDocShell,
372 nStart, nEnd, nTab, //! start und end berechnen
373 pUndoDoc, pUndoTab,
374 bColumns, nLevel ) );
377 ScSubOutlineIterator aIter( pArray ); // alle Eintraege
378 ScOutlineEntry* pEntry;
379 while ((pEntry=aIter.GetNext()) != NULL)
381 sal_uInt16 nThisLevel = aIter.LastLevel();
382 sal_Bool bShow = (nThisLevel < nLevel);
383 if (bShow) // einblenden
385 pEntry->SetHidden( false );
386 pEntry->SetVisible( sal_True );
388 else if ( nThisLevel == nLevel ) // ausblenden
390 pEntry->SetHidden( sal_True );
391 pEntry->SetVisible( sal_True );
393 else // verdeckt
395 pEntry->SetVisible( false );
398 SCCOLROW nThisStart = pEntry->GetStart();
399 SCCOLROW nThisEnd = pEntry->GetEnd();
400 for (SCCOLROW i=nThisStart; i<=nThisEnd; i++)
402 if ( bColumns )
403 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, bShow );
404 else
406 // show several rows together, don't show filtered rows
407 SCROW nFilterEnd = i;
408 bool bFiltered = pDoc->RowFiltered( i, nTab, NULL, &nFilterEnd );
409 nFilterEnd = std::min( nThisEnd, nFilterEnd );
410 if ( !bShow || !bFiltered )
411 pDoc->ShowRows( i, nFilterEnd, nTab, bShow );
412 i = nFilterEnd;
417 pDoc->SetDrawPageSize(nTab);
418 pDoc->UpdatePageBreaks( nTab );
420 if (bPaint)
421 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
423 rDocShell.SetDocumentModified();
424 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
426 return sal_True;
429 //------------------------------------------------------------------------
431 sal_Bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, sal_Bool bRecord )
433 sal_Bool bDone = false;
435 SCCOL nStartCol = rRange.aStart.Col();
436 SCROW nStartRow = rRange.aStart.Row();
437 SCCOL nEndCol = rRange.aEnd.Col();
438 SCROW nEndRow = rRange.aEnd.Row();
439 SCTAB nTab = rRange.aStart.Tab();
441 ScDocument* pDoc = rDocShell.GetDocument();
443 if (bRecord && !pDoc->IsUndoEnabled())
444 bRecord = false;
445 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
447 if (pTable)
449 ScOutlineArray* pArray;
450 ScOutlineEntry* pEntry;
451 SCCOLROW nStart;
452 SCCOLROW nEnd;
453 SCCOLROW nMin;
454 SCCOLROW nMax;
455 SCCOLROW i;
457 if ( bRecord )
459 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
460 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
461 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
462 pDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, false, pUndoDoc );
463 pDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pUndoDoc );
465 rDocShell.GetUndoManager()->AddUndoAction(
466 new ScUndoOutlineBlock( &rDocShell,
467 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
468 pUndoDoc, pUndoTab, sal_True ) );
471 // Spalten
473 nMin=MAXCOL;
474 nMax=0;
475 pArray = pTable->GetColArray();
476 ScSubOutlineIterator aColIter( pArray );
477 while ((pEntry=aColIter.GetNext()) != NULL)
479 nStart = pEntry->GetStart();
480 nEnd = pEntry->GetEnd();
481 if ( nStart>=nStartCol && nEnd<=nEndCol )
483 pEntry->SetHidden( false );
484 pEntry->SetVisible( sal_True );
485 if (nStart<nMin) nMin=nStart;
486 if (nEnd>nMax) nMax=nEnd;
489 for ( i=nMin; i<=nMax; i++ )
490 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, sal_True );
492 // Zeilen
494 nMin=MAXROW;
495 nMax=0;
496 pArray = pTable->GetRowArray();
497 ScSubOutlineIterator aRowIter( pArray );
498 while ((pEntry=aRowIter.GetNext()) != NULL)
500 nStart = pEntry->GetStart();
501 nEnd = pEntry->GetEnd();
502 if ( nStart>=nStartRow && nEnd<=nEndRow )
504 pEntry->SetHidden( false );
505 pEntry->SetVisible( sal_True );
506 if (nStart<nMin) nMin=nStart;
507 if (nEnd>nMax) nMax=nEnd;
510 for ( i=nMin; i<=nMax; i++ )
512 // show several rows together, don't show filtered rows
513 SCROW nFilterEnd = i;
514 bool bFiltered = pDoc->RowFiltered( i, nTab, NULL, &nFilterEnd );
515 nFilterEnd = std::min( nMax, nFilterEnd );
516 if ( !bFiltered )
517 pDoc->ShowRows( i, nFilterEnd, nTab, sal_True );
518 i = nFilterEnd;
521 pDoc->SetDrawPageSize(nTab);
522 pDoc->UpdatePageBreaks( nTab );
524 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
525 rDocShell.SetDocumentModified();
526 bDone = sal_True;
528 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
531 return bDone;
534 sal_Bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, sal_Bool bRecord, sal_Bool bApi )
536 sal_Bool bDone = false;
538 SCCOL nStartCol = rRange.aStart.Col();
539 SCROW nStartRow = rRange.aStart.Row();
540 SCCOL nEndCol = rRange.aEnd.Col();
541 SCROW nEndRow = rRange.aEnd.Row();
542 SCTAB nTab = rRange.aStart.Tab();
544 ScDocument* pDoc = rDocShell.GetDocument();
546 if (bRecord && !pDoc->IsUndoEnabled())
547 bRecord = false;
548 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
550 if (pTable)
552 const ScOutlineEntry* pEntry;
553 size_t nColLevel;
554 size_t nRowLevel;
555 sal_uInt16 nCount;
556 SCCOLROW nStart;
557 SCCOLROW nEnd;
558 sal_uInt16 i;
560 SCCOLROW nEffStartCol = nStartCol;
561 SCCOLROW nEffEndCol = nEndCol;
562 ScOutlineArray* pColArray = pTable->GetColArray();
563 pColArray->FindTouchedLevel( nStartCol, nEndCol, nColLevel );
564 pColArray->ExtendBlock( nColLevel, nEffStartCol, nEffEndCol );
565 SCCOLROW nEffStartRow = nStartRow;
566 SCCOLROW nEffEndRow = nEndRow;
567 ScOutlineArray* pRowArray = pTable->GetRowArray();
568 pRowArray->FindTouchedLevel( nStartRow, nEndRow, nRowLevel );
569 pRowArray->ExtendBlock( nRowLevel, nEffStartRow, nEffEndRow );
571 if ( bRecord )
573 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
574 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
575 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
576 pDoc->CopyToDocument( static_cast<SCCOL>(nEffStartCol), 0, nTab,
577 static_cast<SCCOL>(nEffEndCol), MAXROW, nTab, IDF_NONE,
578 false, pUndoDoc );
579 pDoc->CopyToDocument( 0, nEffStartRow, nTab, MAXCOL, nEffEndRow, nTab, IDF_NONE, false, pUndoDoc );
581 rDocShell.GetUndoManager()->AddUndoAction(
582 new ScUndoOutlineBlock( &rDocShell,
583 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
584 pUndoDoc, pUndoTab, false ) );
587 // Spalten
589 nCount = pColArray->GetCount(nColLevel);
590 for ( i=0; i<nCount; i++ )
592 pEntry = pColArray->GetEntry(nColLevel,i);
593 nStart = pEntry->GetStart();
594 nEnd = pEntry->GetEnd();
596 if ( static_cast<SCCOLROW>(nStartCol)<=nEnd && static_cast<SCCOLROW>(nEndCol)>=nStart )
597 HideOutline( nTab, sal_True, nColLevel, i, false, false, bApi );
600 // Zeilen
602 nCount = pRowArray->GetCount(nRowLevel);
603 for ( i=0; i<nCount; i++ )
605 pEntry = pRowArray->GetEntry(nRowLevel,i);
606 nStart = pEntry->GetStart();
607 nEnd = pEntry->GetEnd();
609 if ( nStartRow<=nEnd && nEndRow>=nStart )
610 HideOutline( nTab, false, nRowLevel, i, false, false, bApi );
613 pDoc->SetDrawPageSize(nTab);
614 pDoc->UpdatePageBreaks( nTab );
616 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
618 rDocShell.SetDocumentModified();
619 bDone = sal_True;
621 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
624 return bDone;
627 //------------------------------------------------------------------------
629 sal_Bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, sal_Bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
630 sal_Bool bRecord, sal_Bool bPaint, sal_Bool /* bApi */ )
632 ScDocument* pDoc = rDocShell.GetDocument();
633 if (bRecord && !pDoc->IsUndoEnabled())
634 bRecord = false;
636 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
637 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
638 ScOutlineEntry* pEntry = pArray->GetEntry( nLevel, nEntry );
639 SCCOLROW nStart = pEntry->GetStart();
640 SCCOLROW nEnd = pEntry->GetEnd();
642 if ( bRecord )
644 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
645 if (bColumns)
647 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, false );
648 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
649 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false,
650 pUndoDoc );
652 else
654 pUndoDoc->InitUndo( pDoc, nTab, nTab, false, sal_True );
655 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pUndoDoc );
658 rDocShell.GetUndoManager()->AddUndoAction(
659 new ScUndoDoOutline( &rDocShell,
660 nStart, nEnd, nTab, pUndoDoc, //! start und end berechnen
661 bColumns, nLevel, nEntry, sal_True ) );
664 pEntry->SetHidden(false);
665 SCCOLROW i;
666 for ( i = nStart; i <= nEnd; i++ )
668 if ( bColumns )
669 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, sal_True );
670 else
672 // show several rows together, don't show filtered rows
673 SCROW nFilterEnd = i;
674 bool bFiltered = pDoc->RowFiltered( i, nTab, NULL, &nFilterEnd );
675 nFilterEnd = std::min( nEnd, nFilterEnd );
676 if ( !bFiltered )
677 pDoc->ShowRows( i, nFilterEnd, nTab, sal_True );
678 i = nFilterEnd;
682 ScSubOutlineIterator aIter( pArray, nLevel, nEntry );
683 while ((pEntry=aIter.GetNext()) != NULL)
685 if ( pEntry->IsHidden() )
687 SCCOLROW nSubStart = pEntry->GetStart();
688 SCCOLROW nSubEnd = pEntry->GetEnd();
689 if ( bColumns )
690 for ( i = nSubStart; i <= nSubEnd; i++ )
691 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, false );
692 else
693 pDoc->ShowRows( nSubStart, nSubEnd, nTab, sal_False );
697 pArray->SetVisibleBelow( nLevel, nEntry, sal_True, sal_True );
699 pDoc->SetDrawPageSize(nTab);
700 pDoc->InvalidatePageBreaks(nTab);
701 pDoc->UpdatePageBreaks( nTab );
703 if (bPaint)
704 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
706 rDocShell.SetDocumentModified();
708 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
710 return sal_True; //! immer ???
713 sal_Bool ScOutlineDocFunc::HideOutline( SCTAB nTab, sal_Bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
714 sal_Bool bRecord, sal_Bool bPaint, sal_Bool /* bApi */ )
716 ScDocument* pDoc = rDocShell.GetDocument();
717 if (bRecord && !pDoc->IsUndoEnabled())
718 bRecord = false;
720 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
721 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
722 ScOutlineEntry* pEntry = pArray->GetEntry( nLevel, nEntry );
723 SCCOLROW nStart = pEntry->GetStart();
724 SCCOLROW nEnd = pEntry->GetEnd();
726 if ( bRecord )
728 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
729 if (bColumns)
731 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, false );
732 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
733 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false,
734 pUndoDoc );
736 else
738 pUndoDoc->InitUndo( pDoc, nTab, nTab, false, sal_True );
739 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pUndoDoc );
742 rDocShell.GetUndoManager()->AddUndoAction(
743 new ScUndoDoOutline( &rDocShell,
744 nStart, nEnd, nTab, pUndoDoc,
745 bColumns, nLevel, nEntry, false ) );
748 pEntry->SetHidden(true);
749 SCCOLROW i;
750 if ( bColumns )
751 for ( i = nStart; i <= nEnd; i++ )
752 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, sal_False );
753 else
754 pDoc->ShowRows( nStart, nEnd, nTab, sal_False );
756 pArray->SetVisibleBelow( nLevel, nEntry, false );
758 pDoc->SetDrawPageSize(nTab);
759 pDoc->InvalidatePageBreaks(nTab);
760 pDoc->UpdatePageBreaks( nTab );
762 if (bPaint)
763 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
765 rDocShell.SetDocumentModified();
767 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
769 return sal_True; //! immer ???
776 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */