merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / docshell / olinefun.cxx
blobfd120a882c0b2aa7183df2e7ef66c83cec98db42
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: olinefun.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <vcl/sound.hxx>
39 #include <sfx2/bindings.hxx>
41 #include "olinefun.hxx"
43 #include "docsh.hxx"
44 #include "olinetab.hxx"
45 #include "undodat.hxx"
46 #include "globstr.hrc"
47 #include "sc.hrc"
50 //========================================================================
52 void lcl_InvalidateOutliner( SfxBindings* pBindings )
54 if ( pBindings )
56 pBindings->Invalidate( SID_OUTLINE_SHOW );
57 pBindings->Invalidate( SID_OUTLINE_HIDE );
58 pBindings->Invalidate( SID_OUTLINE_REMOVE );
60 pBindings->Invalidate( SID_STATUS_SUM ); // wegen ein-/ausblenden
61 pBindings->Invalidate( SID_ATTR_SIZE );
65 //------------------------------------------------------------------------
67 //! PaintWidthHeight zur DocShell verschieben?
69 void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab,
70 BOOL bColumns, SCCOLROW nStart, SCCOLROW nEnd )
72 ScDocument* pDoc = rDocShell.GetDocument();
74 USHORT nParts = PAINT_GRID;
75 SCCOL nStartCol = 0;
76 SCROW nStartRow = 0;
77 SCCOL nEndCol = MAXCOL; // fuer Test auf Merge
78 SCROW nEndRow = MAXROW;
79 if ( bColumns )
81 nParts |= PAINT_TOP;
82 nStartCol = static_cast<SCCOL>(nStart);
83 nEndCol = static_cast<SCCOL>(nEnd);
85 else
87 nParts |= PAINT_LEFT;
88 nStartRow = nStart;
89 nEndRow = nEnd;
91 if (pDoc->HasAttrib( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
92 HASATTR_MERGED | HASATTR_OVERLAPPED ))
94 nStartCol = 0;
95 nStartRow = 0;
97 rDocShell.PostPaint( nStartCol,nStartRow,nTab, MAXCOL,MAXROW,nTab, nParts );
100 //------------------------------------------------------------------------
102 BOOL ScOutlineDocFunc::MakeOutline( const ScRange& rRange, BOOL bColumns, BOOL bRecord, BOOL bApi )
104 BOOL bSuccess = FALSE;
105 SCCOL nStartCol = rRange.aStart.Col();
106 SCROW nStartRow = rRange.aStart.Row();
107 SCCOL nEndCol = rRange.aEnd.Col();
108 SCROW nEndRow = rRange.aEnd.Row();
109 SCTAB nTab = rRange.aStart.Tab();
111 ScDocument* pDoc = rDocShell.GetDocument();
112 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab, TRUE );
113 ScOutlineTable* pUndoTab = NULL;
115 if (bRecord && !pDoc->IsUndoEnabled())
116 bRecord = FALSE;
118 if (bRecord)
119 pUndoTab = new ScOutlineTable( *pTable );
121 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
123 BOOL bRes;
124 BOOL bSize = FALSE;
125 if ( bColumns )
126 bRes = pArray->Insert( nStartCol, nEndCol, bSize );
127 else
128 bRes = pArray->Insert( nStartRow, nEndRow, bSize );
130 if ( bRes )
132 if (bRecord)
134 rDocShell.GetUndoManager()->AddUndoAction(
135 new ScUndoMakeOutline( &rDocShell,
136 nStartCol,nStartRow,nTab,nEndCol,nEndRow,nTab,
137 pUndoTab, bColumns, TRUE ) );
140 USHORT nParts = 0; // Datenbereich nicht geaendert
141 if ( bColumns )
142 nParts |= PAINT_TOP;
143 else
144 nParts |= PAINT_LEFT;
145 if ( bSize )
146 nParts |= PAINT_SIZE;
148 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
149 rDocShell.SetDocumentModified();
150 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
151 bSuccess = TRUE;
153 else
155 if (!bApi)
156 rDocShell.ErrorMessage(STR_MSSG_MAKEOUTLINE_0); // "Gruppierung nicht moeglich"
157 delete pUndoTab;
160 return bSuccess;
163 BOOL ScOutlineDocFunc::RemoveOutline( const ScRange& rRange, BOOL bColumns, BOOL bRecord, BOOL bApi )
165 BOOL bDone = FALSE;
167 SCCOL nStartCol = rRange.aStart.Col();
168 SCROW nStartRow = rRange.aStart.Row();
169 SCCOL nEndCol = rRange.aEnd.Col();
170 SCROW nEndRow = rRange.aEnd.Row();
171 SCTAB nTab = rRange.aStart.Tab();
173 ScDocument* pDoc = rDocShell.GetDocument();
175 if (bRecord && !pDoc->IsUndoEnabled())
176 bRecord = FALSE;
177 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
178 if (pTable)
180 ScOutlineTable* pUndoTab = NULL;
181 if (bRecord)
182 pUndoTab = new ScOutlineTable( *pTable );
184 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
186 BOOL bRes;
187 BOOL bSize = FALSE;
188 if ( bColumns )
189 bRes = pArray->Remove( nStartCol, nEndCol, bSize );
190 else
191 bRes = pArray->Remove( nStartRow, nEndRow, bSize );
193 if ( bRes )
195 if (bRecord)
197 rDocShell.GetUndoManager()->AddUndoAction(
198 new ScUndoMakeOutline( &rDocShell,
199 nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
200 pUndoTab, bColumns, FALSE ) );
203 USHORT nParts = 0; // Datenbereich nicht geaendert
204 if ( bColumns )
205 nParts |= PAINT_TOP;
206 else
207 nParts |= PAINT_LEFT;
208 if ( bSize )
209 nParts |= PAINT_SIZE;
211 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
212 rDocShell.SetDocumentModified();
213 bDone = TRUE;
214 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
216 // es wird nicht wieder eingeblendet -> kein UpdatePageBreaks
218 else
219 delete pUndoTab;
222 if (!bDone && !bApi)
223 rDocShell.ErrorMessage(STR_MSSG_REMOVEOUTLINE_0); // "Aufheben nicht moeglich"
225 return bDone;
228 BOOL ScOutlineDocFunc::RemoveAllOutlines( SCTAB nTab, BOOL bRecord, BOOL bApi )
230 BOOL bSuccess = FALSE;
231 ScDocument* pDoc = rDocShell.GetDocument();
233 if (bRecord && !pDoc->IsUndoEnabled())
234 bRecord = FALSE;
235 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
236 if (pTable)
238 if (bRecord)
240 SCCOLROW nCol1, nCol2, nRow1, nRow2;
241 pTable->GetColArray()->GetRange( nCol1, nCol2 );
242 pTable->GetRowArray()->GetRange( nRow1, nRow2 );
243 SCCOL nStartCol = static_cast<SCCOL>(nCol1);
244 SCROW nStartRow = nRow1;
245 SCCOL nEndCol = static_cast<SCCOL>(nCol2);
246 SCROW nEndRow = nRow2;
248 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
249 pUndoDoc->InitUndo( pDoc, nTab, nTab, TRUE, TRUE );
250 pDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, FALSE, pUndoDoc );
251 pDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, FALSE, pUndoDoc );
253 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
255 rDocShell.GetUndoManager()->AddUndoAction(
256 new ScUndoRemoveAllOutlines( &rDocShell,
257 nStartCol, nStartRow, nTab,
258 nEndCol, nEndRow, nTab,
259 pUndoDoc, pUndoTab ) );
262 SelectLevel( nTab, TRUE, pTable->GetColArray()->GetDepth(), FALSE, FALSE, bApi );
263 SelectLevel( nTab, FALSE, pTable->GetRowArray()->GetDepth(), FALSE, FALSE, bApi );
264 pDoc->SetOutlineTable( nTab, NULL );
266 pDoc->UpdatePageBreaks( nTab );
268 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab,
269 PAINT_GRID | PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
270 rDocShell.SetDocumentModified();
271 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
272 bSuccess = TRUE;
274 else if (!bApi)
275 Sound::Beep();
277 return bSuccess;
280 //------------------------------------------------------------------------
282 BOOL ScOutlineDocFunc::AutoOutline( const ScRange& rRange, BOOL bRecord, BOOL bApi )
284 SCCOL nStartCol = rRange.aStart.Col();
285 SCROW nStartRow = rRange.aStart.Row();
286 SCCOL nEndCol = rRange.aEnd.Col();
287 SCROW nEndRow = rRange.aEnd.Row();
288 SCTAB nTab = rRange.aStart.Tab();
290 ScDocument* pDoc = rDocShell.GetDocument();
292 if (bRecord && !pDoc->IsUndoEnabled())
293 bRecord = FALSE;
294 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
296 ScDocument* pUndoDoc = NULL;
297 ScOutlineTable* pUndoTab = NULL;
299 if ( pTable )
301 if ( bRecord )
303 pUndoTab = new ScOutlineTable( *pTable );
305 SCCOLROW nCol1, nCol2, nRow1, nRow2;
306 pTable->GetColArray()->GetRange( nCol1, nCol2 );
307 pTable->GetRowArray()->GetRange( nRow1, nRow2 );
308 SCCOL nOutStartCol = static_cast<SCCOL>(nCol1);;
309 SCROW nOutStartRow = nRow1;
310 SCCOL nOutEndCol = static_cast<SCCOL>(nCol2);;
311 SCROW nOutEndRow = nRow2;
313 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
314 pUndoDoc->InitUndo( pDoc, nTab, nTab, TRUE, TRUE );
315 pDoc->CopyToDocument( nOutStartCol, 0, nTab, nOutEndCol, MAXROW, nTab, IDF_NONE, FALSE, pUndoDoc );
316 pDoc->CopyToDocument( 0, nOutStartRow, nTab, MAXCOL, nOutEndRow, nTab, IDF_NONE, FALSE, pUndoDoc );
319 // einblenden
320 SelectLevel( nTab, TRUE, pTable->GetColArray()->GetDepth(), FALSE, FALSE, bApi );
321 SelectLevel( nTab, FALSE, pTable->GetRowArray()->GetDepth(), FALSE, FALSE, bApi );
322 pDoc->SetOutlineTable( nTab, NULL );
325 pDoc->DoAutoOutline( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
327 if (bRecord)
329 rDocShell.GetUndoManager()->AddUndoAction(
330 new ScUndoAutoOutline( &rDocShell,
331 nStartCol, nStartRow, nTab,
332 nEndCol, nEndRow, nTab,
333 pUndoDoc, pUndoTab ) );
336 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
337 rDocShell.SetDocumentModified();
338 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
340 return TRUE;
343 //------------------------------------------------------------------------
345 BOOL ScOutlineDocFunc::SelectLevel( SCTAB nTab, BOOL bColumns, USHORT nLevel,
346 BOOL bRecord, BOOL bPaint, BOOL /* bApi */ )
348 ScDocument* pDoc = rDocShell.GetDocument();
350 if (bRecord && !pDoc->IsUndoEnabled())
351 bRecord = FALSE;
352 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab ); // ist schon da
353 if (!pTable)
354 return FALSE;
355 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
356 if (!pArray)
357 return FALSE;
359 SCCOLROW nStart, nEnd;
360 pArray->GetRange( nStart, nEnd );
362 if ( bRecord )
364 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
365 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
366 if (bColumns)
368 pUndoDoc->InitUndo( pDoc, nTab, nTab, TRUE, FALSE );
369 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
370 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, FALSE,
371 pUndoDoc );
373 else
375 pUndoDoc->InitUndo( pDoc, nTab, nTab, FALSE, TRUE );
376 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, FALSE, pUndoDoc );
379 rDocShell.GetUndoManager()->AddUndoAction(
380 new ScUndoOutlineLevel( &rDocShell,
381 nStart, nEnd, nTab, //! start und end berechnen
382 pUndoDoc, pUndoTab,
383 bColumns, nLevel ) );
386 ScSubOutlineIterator aIter( pArray ); // alle Eintraege
387 ScOutlineEntry* pEntry;
388 while ((pEntry=aIter.GetNext()) != NULL)
390 USHORT nThisLevel = aIter.LastLevel();
391 BOOL bShow = (nThisLevel < nLevel);
392 if (bShow) // einblenden
394 pEntry->SetHidden( FALSE );
395 pEntry->SetVisible( TRUE );
397 else if ( nThisLevel == nLevel ) // ausblenden
399 pEntry->SetHidden( TRUE );
400 pEntry->SetVisible( TRUE );
402 else // verdeckt
404 pEntry->SetVisible( FALSE );
407 SCCOLROW nThisStart = pEntry->GetStart();
408 SCCOLROW nThisEnd = pEntry->GetEnd();
409 for (SCCOLROW i=nThisStart; i<=nThisEnd; i++)
411 if ( bColumns )
412 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, bShow );
413 else
414 if ( !bShow || !pDoc->RowFiltered( i,nTab ) )
415 pDoc->ShowRow( i, nTab, bShow );
419 pDoc->UpdatePageBreaks( nTab );
421 if (bPaint)
422 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
424 rDocShell.SetDocumentModified();
425 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
427 return TRUE;
430 //------------------------------------------------------------------------
432 BOOL ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, BOOL bRecord, BOOL bApi )
434 BOOL bDone = FALSE;
436 SCCOL nStartCol = rRange.aStart.Col();
437 SCROW nStartRow = rRange.aStart.Row();
438 SCCOL nEndCol = rRange.aEnd.Col();
439 SCROW nEndRow = rRange.aEnd.Row();
440 SCTAB nTab = rRange.aStart.Tab();
442 ScDocument* pDoc = rDocShell.GetDocument();
444 if (bRecord && !pDoc->IsUndoEnabled())
445 bRecord = FALSE;
446 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
448 if (pTable)
450 ScOutlineArray* pArray;
451 ScOutlineEntry* pEntry;
452 SCCOLROW nStart;
453 SCCOLROW nEnd;
454 SCCOLROW nMin;
455 SCCOLROW nMax;
456 SCCOLROW i;
458 if ( bRecord )
460 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
461 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
462 pUndoDoc->InitUndo( pDoc, nTab, nTab, TRUE, TRUE );
463 pDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, FALSE, pUndoDoc );
464 pDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, FALSE, pUndoDoc );
466 rDocShell.GetUndoManager()->AddUndoAction(
467 new ScUndoOutlineBlock( &rDocShell,
468 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
469 pUndoDoc, pUndoTab, TRUE ) );
472 // Spalten
474 nMin=MAXCOL;
475 nMax=0;
476 pArray = pTable->GetColArray();
477 ScSubOutlineIterator aColIter( pArray );
478 while ((pEntry=aColIter.GetNext()) != NULL)
480 nStart = pEntry->GetStart();
481 nEnd = pEntry->GetEnd();
482 if ( nStart>=nStartCol && nEnd<=nEndCol )
484 pEntry->SetHidden( FALSE );
485 pEntry->SetVisible( TRUE );
486 if (nStart<nMin) nMin=nStart;
487 if (nEnd>nMax) nMax=nEnd;
490 for ( i=nMin; i<=nMax; i++ )
491 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, TRUE );
493 // Zeilen
495 nMin=MAXROW;
496 nMax=0;
497 pArray = pTable->GetRowArray();
498 ScSubOutlineIterator aRowIter( pArray );
499 while ((pEntry=aRowIter.GetNext()) != NULL)
501 nStart = pEntry->GetStart();
502 nEnd = pEntry->GetEnd();
503 if ( nStart>=nStartRow && nEnd<=nEndRow )
505 pEntry->SetHidden( FALSE );
506 pEntry->SetVisible( TRUE );
507 if (nStart<nMin) nMin=nStart;
508 if (nEnd>nMax) nMax=nEnd;
511 for ( i=nMin; i<=nMax; i++ )
512 if ( !pDoc->RowFiltered( i,nTab ) ) // weggefilterte nicht einblenden
513 pDoc->ShowRow( i, nTab, TRUE );
515 pDoc->UpdatePageBreaks( nTab );
517 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
519 rDocShell.SetDocumentModified();
520 bDone = TRUE;
522 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
525 if (!bDone && !bApi)
526 Sound::Beep();
528 return bDone;
531 BOOL ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, BOOL bRecord, BOOL bApi )
533 BOOL bDone = FALSE;
535 SCCOL nStartCol = rRange.aStart.Col();
536 SCROW nStartRow = rRange.aStart.Row();
537 SCCOL nEndCol = rRange.aEnd.Col();
538 SCROW nEndRow = rRange.aEnd.Row();
539 SCTAB nTab = rRange.aStart.Tab();
541 ScDocument* pDoc = rDocShell.GetDocument();
543 if (bRecord && !pDoc->IsUndoEnabled())
544 bRecord = FALSE;
545 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
547 if (pTable)
549 ScOutlineEntry* pEntry;
550 USHORT nColLevel;
551 USHORT nRowLevel;
552 USHORT nCount;
553 SCCOLROW nStart;
554 SCCOLROW nEnd;
555 USHORT i;
557 SCCOLROW nEffStartCol = nStartCol;
558 SCCOLROW nEffEndCol = nEndCol;
559 ScOutlineArray* pColArray = pTable->GetColArray();
560 pColArray->FindTouchedLevel( nStartCol, nEndCol, nColLevel );
561 pColArray->ExtendBlock( nColLevel, nEffStartCol, nEffEndCol );
562 SCCOLROW nEffStartRow = nStartRow;
563 SCCOLROW nEffEndRow = nEndRow;
564 ScOutlineArray* pRowArray = pTable->GetRowArray();
565 pRowArray->FindTouchedLevel( nStartRow, nEndRow, nRowLevel );
566 pRowArray->ExtendBlock( nRowLevel, nEffStartRow, nEffEndRow );
568 if ( bRecord )
570 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
571 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
572 pUndoDoc->InitUndo( pDoc, nTab, nTab, TRUE, TRUE );
573 pDoc->CopyToDocument( static_cast<SCCOL>(nEffStartCol), 0, nTab,
574 static_cast<SCCOL>(nEffEndCol), MAXROW, nTab, IDF_NONE,
575 FALSE, pUndoDoc );
576 pDoc->CopyToDocument( 0, nEffStartRow, nTab, MAXCOL, nEffEndRow, nTab, IDF_NONE, FALSE, pUndoDoc );
578 rDocShell.GetUndoManager()->AddUndoAction(
579 new ScUndoOutlineBlock( &rDocShell,
580 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
581 pUndoDoc, pUndoTab, FALSE ) );
584 // Spalten
586 nCount = pColArray->GetCount(nColLevel);
587 for ( i=0; i<nCount; i++ )
589 pEntry = pColArray->GetEntry(nColLevel,i);
590 nStart = pEntry->GetStart();
591 nEnd = pEntry->GetEnd();
593 if ( static_cast<SCCOLROW>(nStartCol)<=nEnd && static_cast<SCCOLROW>(nEndCol)>=nStart )
594 HideOutline( nTab, TRUE, nColLevel, i, FALSE, FALSE, bApi );
597 // Zeilen
599 nCount = pRowArray->GetCount(nRowLevel);
600 for ( i=0; i<nCount; i++ )
602 pEntry = pRowArray->GetEntry(nRowLevel,i);
603 nStart = pEntry->GetStart();
604 nEnd = pEntry->GetEnd();
606 if ( nStartRow<=nEnd && nEndRow>=nStart )
607 HideOutline( nTab, FALSE, nRowLevel, i, FALSE, FALSE, bApi );
610 pDoc->UpdatePageBreaks( nTab );
612 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
614 rDocShell.SetDocumentModified();
615 bDone = TRUE;
617 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
620 if (!bDone && !bApi)
621 Sound::Beep();
623 return bDone;
626 //------------------------------------------------------------------------
628 BOOL ScOutlineDocFunc::ShowOutline( SCTAB nTab, BOOL bColumns, USHORT nLevel, USHORT nEntry,
629 BOOL bRecord, BOOL bPaint, BOOL /* bApi */ )
631 ScDocument* pDoc = rDocShell.GetDocument();
632 if (bRecord && !pDoc->IsUndoEnabled())
633 bRecord = FALSE;
635 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
636 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
637 ScOutlineEntry* pEntry = pArray->GetEntry( nLevel, nEntry );
638 SCCOLROW nStart = pEntry->GetStart();
639 SCCOLROW nEnd = pEntry->GetEnd();
641 if ( bRecord )
643 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
644 if (bColumns)
646 pUndoDoc->InitUndo( pDoc, nTab, nTab, TRUE, FALSE );
647 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
648 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, FALSE,
649 pUndoDoc );
651 else
653 pUndoDoc->InitUndo( pDoc, nTab, nTab, FALSE, TRUE );
654 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, FALSE, pUndoDoc );
657 rDocShell.GetUndoManager()->AddUndoAction(
658 new ScUndoDoOutline( &rDocShell,
659 nStart, nEnd, nTab, pUndoDoc, //! start und end berechnen
660 bColumns, nLevel, nEntry, TRUE ) );
663 //! HideCursor();
665 pEntry->SetHidden(FALSE);
666 SCCOLROW i;
667 for ( i = nStart; i <= nEnd; i++ )
669 if ( bColumns )
670 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, TRUE );
671 else
672 if ( !pDoc->RowFiltered( i,nTab ) ) // weggefilterte nicht einblenden
673 pDoc->ShowRow( i, nTab, TRUE );
676 ScSubOutlineIterator aIter( pArray, nLevel, nEntry );
677 while ((pEntry=aIter.GetNext()) != NULL)
679 if ( pEntry->IsHidden() )
681 SCCOLROW nSubStart = pEntry->GetStart();
682 SCCOLROW nSubEnd = pEntry->GetEnd();
683 for ( i = nSubStart; i <= nSubEnd; i++ )
685 if ( bColumns )
686 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, FALSE );
687 else
688 pDoc->ShowRow( i, nTab, FALSE );
693 pArray->SetVisibleBelow( nLevel, nEntry, TRUE, TRUE );
695 pDoc->InvalidatePageBreaks(nTab);
696 pDoc->UpdatePageBreaks( nTab );
698 if (bPaint)
699 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
701 //! ShowCursor();
702 rDocShell.SetDocumentModified();
704 //! if (bPaint)
705 //! UpdateScrollBars();
707 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
709 return TRUE; //! immer ???
712 BOOL ScOutlineDocFunc::HideOutline( SCTAB nTab, BOOL bColumns, USHORT nLevel, USHORT nEntry,
713 BOOL bRecord, BOOL bPaint, BOOL /* bApi */ )
715 ScDocument* pDoc = rDocShell.GetDocument();
716 if (bRecord && !pDoc->IsUndoEnabled())
717 bRecord = FALSE;
719 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
720 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
721 ScOutlineEntry* pEntry = pArray->GetEntry( nLevel, nEntry );
722 SCCOLROW nStart = pEntry->GetStart();
723 SCCOLROW nEnd = pEntry->GetEnd();
725 if ( bRecord )
727 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
728 if (bColumns)
730 pUndoDoc->InitUndo( pDoc, nTab, nTab, TRUE, FALSE );
731 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
732 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, FALSE,
733 pUndoDoc );
735 else
737 pUndoDoc->InitUndo( pDoc, nTab, nTab, FALSE, TRUE );
738 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, FALSE, pUndoDoc );
741 rDocShell.GetUndoManager()->AddUndoAction(
742 new ScUndoDoOutline( &rDocShell,
743 nStart, nEnd, nTab, pUndoDoc,
744 bColumns, nLevel, nEntry, FALSE ) );
747 //! HideCursor();
749 pEntry->SetHidden(TRUE);
750 SCCOLROW i;
751 for ( i = nStart; i <= nEnd; i++ )
753 if ( bColumns )
754 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, FALSE );
755 else
756 pDoc->ShowRow( i, nTab, FALSE );
759 pArray->SetVisibleBelow( nLevel, nEntry, FALSE );
761 pDoc->InvalidatePageBreaks(nTab);
762 pDoc->UpdatePageBreaks( nTab );
764 if (bPaint)
765 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
767 //! ShowCursor();
768 rDocShell.SetDocumentModified();
770 //! if (bPaint)
771 //! UpdateScrollBars();
773 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
775 return TRUE; //! immer ???