diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-02 18:29:27 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-07-13 18:07:14 -0400 |
commit | 5c6ee09126631342939ae8766fe36083d8c011e3 (patch) | |
tree | 48081d36ae5000542adb49cc037267992f59ec66 /sc/source/ui | |
parent | b5bb15013617c6b9f1cdd089acae0bfb7104fa3a (diff) |
fdo#81309: Adjust references during sort.
Change-Id: I2b98610f6b774400ecfaffe2905201c27fcab33f
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/docshell/dbdocfun.cxx | 161 | ||||
-rw-r--r-- | sc/source/ui/inc/undodat.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/undo/undobase.cxx | 1 | ||||
-rw-r--r-- | sc/source/ui/undo/undodat.cxx | 18 | ||||
-rw-r--r-- | sc/source/ui/undo/undosort.cxx | 55 | ||||
-rw-r--r-- | sc/source/ui/unoobj/cellsuno.cxx | 1 | ||||
-rw-r--r-- | sc/source/ui/unoobj/datauno.cxx | 1 |
7 files changed, 79 insertions, 162 deletions
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 94578f2e957f..187621dc2b26 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -47,6 +47,7 @@ #include "queryentry.hxx" #include "markdata.hxx" #include "progress.hxx" +#include <undosort.hxx> #include <set> #include <memory> @@ -430,8 +431,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, ScDocument& rDoc = rDocShell.GetDocument(); if (bRecord && !rDoc.IsUndoEnabled()) bRecord = false; - SCTAB nSrcTab = nTab; - ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); ScDBData* pDBData = rDoc.GetDBAtArea( nTab, rSortParam.nCol1, rSortParam.nRow1, rSortParam.nCol2, rSortParam.nRow2 ); @@ -441,28 +440,25 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, return false; } - ScDBData* pDestData = NULL; - ScRange aOldDest; bool bCopy = !rSortParam.bInplace; if ( bCopy && rSortParam.nDestCol == rSortParam.nCol1 && rSortParam.nDestRow == rSortParam.nRow1 && rSortParam.nDestTab == nTab ) bCopy = false; + ScSortParam aLocalParam( rSortParam ); if ( bCopy ) { - aLocalParam.MoveToDest(); - if ( !ValidColRow( aLocalParam.nCol2, aLocalParam.nRow2 ) ) - { - if (!bApi) - rDocShell.ErrorMessage(STR_PASTE_FULL); + // Copy the data range to the destination then move the sort range to it. + ScRange aSrcRange(rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab); + ScAddress aDestPos(rSortParam.nDestCol,rSortParam.nDestRow,rSortParam.nDestTab); + + ScDocFunc& rDocFunc = rDocShell.GetDocFunc(); + bool bRet = rDocFunc.MoveBlock(aSrcRange, aDestPos, false, bRecord, bPaint, bApi); + + if (!bRet) return false; - } - nTab = rSortParam.nDestTab; - pDestData = rDoc.GetDBAtCursor( rSortParam.nDestCol, rSortParam.nDestRow, - rSortParam.nDestTab, true ); - if (pDestData) - pDestData->GetArea(aOldDest); + aLocalParam.MoveToDest(); } ScEditableTester aTester( &rDoc, nTab, aLocalParam.nCol1,aLocalParam.nRow1, @@ -511,133 +507,23 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, if ( aQueryParam.GetEntry(0).bDoQuery ) bRepeatQuery = true; - if (bRepeatQuery && bCopy) - { - if ( aQueryParam.bInplace || - aQueryParam.nDestCol != rSortParam.nDestCol || - aQueryParam.nDestRow != rSortParam.nDestRow || - aQueryParam.nDestTab != rSortParam.nDestTab ) // Query auf selben Zielbereich? - bRepeatQuery = false; - } - - ScUndoSort* pUndoAction = 0; - if ( bRecord ) - { - // Referenzen ausserhalb des Bereichs werden nicht veraendert ! - - ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); - // Zeilenhoehen immer (wegen automatischer Anpassung) - //! auf ScBlockUndo umstellen - pUndoDoc->InitUndo( &rDoc, nTab, nTab, false, true ); - - /* #i59745# Do not copy note captions to undo document. All existing - caption objects will be repositioned while sorting which is tracked - in drawing undo. When undo is executed, the old positions will be - restored, and the cells with the old notes (which still refer to the - existing captions) will be copied back into the source document. */ - rDoc.CopyToDocument( aLocalParam.nCol1, aLocalParam.nRow1, nTab, - aLocalParam.nCol2, aLocalParam.nRow2, nTab, - IDF_ALL|IDF_NOCAPTIONS, false, pUndoDoc ); - - const ScRange* pR = 0; - if (pDestData) - { - /* #i59745# Do not copy note captions from destination range to - undo document. All existing caption objects will be removed - which is tracked in drawing undo. When undo is executed, the - caption objects are reinserted with drawing undo, and the cells - with the old notes (which still refer to the existing captions) - will be copied back into the source document. */ - rDoc.CopyToDocument( aOldDest, IDF_ALL|IDF_NOCAPTIONS, false, pUndoDoc ); - pR = &aOldDest; - } - - // Zeilenhoehen immer (wegen automatischer Anpassung) - //! auf ScBlockUndo umstellen -// if (bRepeatQuery) - rDoc.CopyToDocument( 0, aLocalParam.nRow1, nTab, MAXCOL, aLocalParam.nRow2, nTab, - IDF_NONE, false, pUndoDoc ); - - ScDBCollection* pUndoDB = NULL; - ScDBCollection* pDocDB = rDoc.GetDBCollection(); - if (!pDocDB->empty()) - pUndoDB = new ScDBCollection( *pDocDB ); - - pUndoAction = new ScUndoSort( &rDocShell, nTab, rSortParam, pUndoDoc, pUndoDB, pR ); - rDocShell.GetUndoManager()->AddUndoAction( pUndoAction ); - - // #i59745# collect all drawing undo actions affecting cell note captions - if( pDrawLayer ) - pDrawLayer->BeginCalcUndo(false); - } - - if ( bCopy ) - { - if (pDestData) - rDoc.DeleteAreaTab(aOldDest, IDF_CONTENTS); // Zielbereich vorher loeschen - - ScRange aSource( rSortParam.nCol1,rSortParam.nRow1,nSrcTab, - rSortParam.nCol2,rSortParam.nRow2,nSrcTab ); - ScAddress aDest( rSortParam.nDestCol, rSortParam.nDestRow, rSortParam.nDestTab ); - - rDocShell.GetDocFunc().MoveBlock( aSource, aDest, false, false, false, true ); - } + sc::ReorderParam aUndoParam; // don't call ScDocument::Sort with an empty SortParam (may be empty here if bCopy is set) if (aLocalParam.GetSortKeyCount() && aLocalParam.maKeyState[0].bDoSort) { ScProgress aProgress(&rDocShell, ScGlobal::GetRscString(STR_PROGRESS_SORTING), 0); - rDoc.Sort( nTab, aLocalParam, bRepeatQuery, &aProgress ); + rDoc.Sort(nTab, aLocalParam, bRepeatQuery, &aProgress, &aUndoParam); } - bool bSave = true; - if (bCopy) - { - ScSortParam aOldSortParam; - pDBData->GetSortParam( aOldSortParam ); - if (aOldSortParam.GetSortKeyCount() && - aOldSortParam.maKeyState[0].bDoSort && aOldSortParam.bInplace) - { - bSave = false; - aOldSortParam.nDestCol = rSortParam.nDestCol; - aOldSortParam.nDestRow = rSortParam.nDestRow; - aOldSortParam.nDestTab = rSortParam.nDestTab; - pDBData->SetSortParam( aOldSortParam ); // dann nur DestPos merken - } - } - if (bSave) // Parameter merken + if (bRecord) { - pDBData->SetSortParam( rSortParam ); - pDBData->SetHeader( rSortParam.bHasHeader ); //! ??? - pDBData->SetByRow( rSortParam.bByRow ); //! ??? + // Set up an undo object. + sc::UndoSort* pUndoAction = new sc::UndoSort(&rDocShell, aUndoParam); + rDocShell.GetUndoManager()->AddUndoAction(pUndoAction); } - if (bCopy) // neuen DB-Bereich merken - { - // Tabelle umschalten von aussen (View) - //! SetCursor ??!?! - - ScRange aDestPos( aLocalParam.nCol1, aLocalParam.nRow1, nTab, - aLocalParam.nCol2, aLocalParam.nRow2, nTab ); - ScDBData* pNewData; - if (pDestData) - pNewData = pDestData; // Bereich vorhanden -> anpassen - else // Bereich ab Cursor/Markierung wird angelegt - pNewData = rDocShell.GetDBData(aDestPos, SC_DB_MAKE, SC_DBSEL_FORCE_MARK ); - if (pNewData) - { - pNewData->SetArea( nTab, - aLocalParam.nCol1,aLocalParam.nRow1, - aLocalParam.nCol2,aLocalParam.nRow2 ); - pNewData->SetSortParam( aLocalParam ); - pNewData->SetHeader( aLocalParam.bHasHeader ); //! ??? - pNewData->SetByRow( aLocalParam.bByRow ); - } - else - { - OSL_FAIL("Zielbereich nicht da"); - } - } + pDBData->SetSortParam(rSortParam); ScRange aDirtyRange( aLocalParam.nCol1, nStartRow, nTab, @@ -657,23 +543,12 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, nStartX = 0; nEndX = MAXCOL; } - if (pDestData) - { - if ( nEndX < aOldDest.aEnd.Col() ) - nEndX = aOldDest.aEnd.Col(); - if ( nEndY < aOldDest.aEnd.Row() ) - nEndY = aOldDest.aEnd.Row(); - } rDocShell.PostPaint(ScRange(nStartX, nStartY, nTab, nEndX, nEndY, nTab), nPaint); } if (!bUniformRowHeight) rDocShell.AdjustRowHeight(nStartRow, aLocalParam.nRow2, nTab); - // #i59745# set collected drawing undo actions at sorting undo action - if( pUndoAction && pDrawLayer ) - pUndoAction->SetDrawUndoAction( pDrawLayer->GetCalcUndo() ); - aModificator.SetDocumentModified(); return true; diff --git a/sc/source/ui/inc/undodat.hxx b/sc/source/ui/inc/undodat.hxx index 00388d71b6a3..cbe115265b15 100644 --- a/sc/source/ui/inc/undodat.hxx +++ b/sc/source/ui/inc/undodat.hxx @@ -231,7 +231,7 @@ public: ScUndoSort( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScSortParam& rParam, ScDocument* pNewUndoDoc, - ScDBCollection* pNewUndoDB, const ScRange* pDest = NULL ); + ScDBCollection* pNewUndoDB ); virtual ~ScUndoSort(); virtual void Undo() SAL_OVERRIDE; @@ -246,8 +246,6 @@ private: ScSortParam aSortParam; ScDocument* pUndoDoc; ScDBCollection* pUndoDB; // due to source and target range - bool bDestArea; - ScRange aDestRange; }; class ScUndoQuery: public ScDBFuncUndo diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx index 8740c6b31077..dc7efd49756e 100644 --- a/sc/source/ui/undo/undobase.cxx +++ b/sc/source/ui/undo/undobase.cxx @@ -33,6 +33,7 @@ #include "globstr.hrc" #include <rowheightcontext.hxx> #include <column.hxx> +#include <sortparam.hxx> TYPEINIT1(ScSimpleUndo, SfxUndoAction); TYPEINIT1(ScBlockUndo, ScSimpleUndo); diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx index b6bc5d614a33..d0a7c809faa8 100644 --- a/sc/source/ui/undo/undodat.cxx +++ b/sc/source/ui/undo/undodat.cxx @@ -739,21 +739,14 @@ bool ScUndoSubTotals::CanRepeat(SfxRepeatTarget& /* rTarget */) const ScUndoSort::ScUndoSort( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScSortParam& rParam, - ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB, - const ScRange* pDest ) : + ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB ) : ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab, rParam.nCol2, rParam.nRow2, nNewTab ) ), nTab( nNewTab ), aSortParam( rParam ), pUndoDoc( pNewUndoDoc ), - pUndoDB( pNewUndoDB ), - bDestArea( false ) + pUndoDB( pNewUndoDB ) { - if ( pDest ) - { - bDestArea = true; - aDestRange = *pDest; - } } ScUndoSort::~ScUndoSort() @@ -796,13 +789,6 @@ void ScUndoSort::Undo() pUndoDoc->CopyToDocument( nStartCol, nStartRow, nSortTab, nEndCol, nEndRow, nSortTab, IDF_ALL|IDF_NOCAPTIONS, false, &rDoc ); - if (bDestArea) - { - // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo) - rDoc.DeleteAreaTab( aDestRange, IDF_ALL|IDF_NOCAPTIONS ); - pUndoDoc->CopyToDocument( aDestRange, IDF_ALL|IDF_NOCAPTIONS, false, &rDoc ); - } - // Row heights always (due to automatic adjustment) // TODO change to use ScBlockUndo pUndoDoc->CopyToDocument( 0, nStartRow, nSortTab, MAXCOL, nEndRow, nSortTab, diff --git a/sc/source/ui/undo/undosort.cxx b/sc/source/ui/undo/undosort.cxx new file mode 100644 index 000000000000..d138491c3abb --- /dev/null +++ b/sc/source/ui/undo/undosort.cxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <undosort.hxx> +#include <globstr.hrc> +#include <global.hxx> +#include <undoutil.hxx> + +namespace sc { + +UndoSort::UndoSort( ScDocShell* pDocSh, const ReorderParam& rParam ) : + ScSimpleUndo(pDocSh), maParam(rParam) {} + +OUString UndoSort::GetComment() const +{ + return ScGlobal::GetRscString(STR_UNDO_SORT); +} + +void UndoSort::Undo() +{ + BeginUndo(); + Execute(true); + EndUndo(); +} + +void UndoSort::Redo() +{ + BeginRedo(); + Execute(false); + EndRedo(); +} + +void UndoSort::Execute( bool bUndo ) +{ + ScDocument& rDoc = pDocShell->GetDocument(); + sc::ReorderParam aParam = maParam; + if (bUndo) + aParam.reverse(); + rDoc.Reorder(aParam, NULL); + + ScUndoUtil::MarkSimpleBlock(pDocShell, maParam.maSortRange); + + pDocShell->PostPaint(maParam.maSortRange, PAINT_GRID); + pDocShell->PostDataChanged(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 3a94df0175ab..7ad020265790 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -125,6 +125,7 @@ #include "tokenarray.hxx" #include "stylehelper.hxx" #include "dputil.hxx" +#include <sortparam.hxx> #include <list> #include <boost/scoped_array.hpp> diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index b84879116d3f..0dc0bcf639ba 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -51,6 +51,7 @@ #include "dpshttab.hxx" #include "queryentry.hxx" #include "dputil.hxx" +#include <sortparam.hxx> #include <comphelper/extract.hxx> #include <comphelper/servicehelper.hxx> |