sc/Library_sc.mk | 1 sc/source/ui/docshell/docfunc.cxx | 61 ++---------------- sc/source/ui/docshell/docfuncutil.cxx | 115 ++++++++++++++++++++++++++++++++++ sc/source/ui/inc/docfuncutil.hxx | 46 +++++++++++++ sc/source/ui/view/viewfunc.cxx | 67 ++----------------- 5 files changed, 178 insertions(+), 112 deletions(-)
New commits: commit 9aa36a1ad39e37c372cc833a44fba450b8cc30cd Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Wed Oct 8 23:21:17 2014 -0400 Move this one to a common place too. Change-Id: I7f4e007cfc861dc323b42be353c6ba11091e8fa1 diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 6de4d7a..c529527 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -637,11 +637,9 @@ bool ScDocFunc::DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlag // add undo action after drawing undo is complete (objects and note captions) if( bRecord ) { - ScUndoDeleteContents* pUndo = - new ScUndoDeleteContents( - &rDocShell, aMultiMark, aExtendedRange, pUndoDoc, bMulti, nFlags, bDrawUndo); - rDocShell.GetUndoManager()->AddUndoAction(pUndo); - pUndo->SetDataSpans(pDataSpans); + sc::DocFuncUtil::addDeleteContentsUndo( + rDocShell.GetUndoManager(), &rDocShell, aMultiMark, aExtendedRange, + pUndoDoc, nFlags, pDataSpans, bMulti, bDrawUndo); } if (!AdjustRowHeight( aExtendedRange )) diff --git a/sc/source/ui/docshell/docfuncutil.cxx b/sc/source/ui/docshell/docfuncutil.cxx index 35f3fb2..1adb135 100644 --- a/sc/source/ui/docshell/docfuncutil.cxx +++ b/sc/source/ui/docshell/docfuncutil.cxx @@ -22,6 +22,7 @@ #include <markdata.hxx> #include <undobase.hxx> #include <global.hxx> +#include <undoblk.hxx> #include <memory> @@ -70,6 +71,20 @@ ScDocument* DocFuncUtil::createDeleteContentsUndoDoc( return pUndoDoc.release(); } +void DocFuncUtil::addDeleteContentsUndo( + svl::IUndoManager* pUndoMgr, ScDocShell* pDocSh, const ScMarkData& rMark, + const ScRange& rRange, ScDocument* pUndoDoc, InsertDeleteFlags nFlags, + const boost::shared_ptr<ScSimpleUndo::DataSpansType>& pSpans, + bool bMulti, bool bDrawUndo ) +{ + std::unique_ptr<ScUndoDeleteContents> pUndo( + new ScUndoDeleteContents( + pDocSh, rMark, rRange, pUndoDoc, bMulti, nFlags, bDrawUndo)); + pUndo->SetDataSpans(pSpans); + + pUndoMgr->AddUndoAction(pUndo.release()); +} + ScSimpleUndo::DataSpansType* DocFuncUtil::getNonEmptyCellSpans( const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange ) { diff --git a/sc/source/ui/inc/docfuncutil.hxx b/sc/source/ui/inc/docfuncutil.hxx index 553bab6..65bf820 100644 --- a/sc/source/ui/inc/docfuncutil.hxx +++ b/sc/source/ui/inc/docfuncutil.hxx @@ -10,6 +10,8 @@ #include <undobase.hxx> +#include <boost/shared_ptr.hpp> + class ScDocument; class ScMarkData; class ScRange; @@ -27,6 +29,12 @@ public: ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange, InsertDeleteFlags nFlags, bool bOnlyMarked ); + static void addDeleteContentsUndo( + svl::IUndoManager* pUndoMgr, ScDocShell* pDocSh, const ScMarkData& rMark, + const ScRange& rRange, ScDocument* pUndoDoc, InsertDeleteFlags nFlags, + const boost::shared_ptr<ScSimpleUndo::DataSpansType>& pSpans, + bool bMulti, bool bDrawUndo ); + static ScSimpleUndo::DataSpansType* getNonEmptyCellSpans( const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange ); }; diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index cb3db19..f1ab1eb 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -1850,12 +1850,9 @@ void ScViewFunc::DeleteContents( InsertDeleteFlags nFlags, bool bRecord ) if ( bRecord ) { - ScUndoDeleteContents* pUndo = - new ScUndoDeleteContents( - pDocSh, aFuncMark, aExtendedRange, pUndoDoc, bMulti, nFlags, bDrawUndo); - pUndo->SetDataSpans(pDataSpans); - - pDocSh->GetUndoManager()->AddUndoAction(pUndo); + sc::DocFuncUtil::addDeleteContentsUndo( + pDocSh->GetUndoManager(), pDocSh, aFuncMark, aExtendedRange, pUndoDoc, + nFlags, pDataSpans, bMulti, bDrawUndo); } if (!AdjustRowHeight( aExtendedRange.aStart.Row(), aExtendedRange.aEnd.Row() )) commit 7adef94b82f5c71da483f238d05df7800b8da38b Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Wed Oct 8 22:33:47 2014 -0400 Share undo doc creation code. Change-Id: I55f27b61637ba0284479c63c2fa48b0bd8938c0f diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index fedbd20..6de4d7a 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -628,42 +628,8 @@ bool ScDocFunc::DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlag if ( bRecord ) { - pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); - pUndoDoc->InitUndo( &rDoc, aMarkRange.aStart.Tab(), aMarkRange.aEnd.Tab() ); - - // bei "Format/Standard" alle Attribute kopieren, weil CopyToDocument - // nur mit IDF_HARDATTR zu langsam ist: - InsertDeleteFlags nUndoDocFlags = nFlags; - if (nFlags & IDF_ATTRIB) - nUndoDocFlags |= IDF_ATTRIB; - if (nFlags & IDF_EDITATTR) // Edit-Engine-Attribute - nUndoDocFlags |= IDF_STRING; // -> Zellen werden geaendert - if (nFlags & IDF_NOTE) - nUndoDocFlags |= IDF_CONTENTS; // copy all cells with their notes - // note captions are handled in drawing undo - nUndoDocFlags |= IDF_NOCAPTIONS; - rDoc.CopyToDocument( aExtendedRange, nUndoDocFlags, bMulti, pUndoDoc, &aMultiMark ); - - pDataSpans.reset(new ScSimpleUndo::DataSpansType); - - ScMarkData::iterator it = aMultiMark.begin(), itEnd = aMultiMark.end(); - for (; it != itEnd; ++it) - { - SCTAB nTab = *it; - - SCCOL nCol1 = aMarkRange.aStart.Col(), nCol2 = aMarkRange.aEnd.Col(); - SCROW nRow1 = aMarkRange.aStart.Row(), nRow2 = aMarkRange.aEnd.Row(); - - std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r = - pDataSpans->insert(nTab, new sc::ColumnSpanSet(false)); - - if (r.second) - { - ScSimpleUndo::DataSpansType::iterator it2 = r.first; - sc::ColumnSpanSet* pSet = it2->second; - pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true); - } - } + pUndoDoc = sc::DocFuncUtil::createDeleteContentsUndoDoc(rDoc, aMultiMark, aMarkRange, nFlags, bMulti); + pDataSpans.reset(sc::DocFuncUtil::getNonEmptyCellSpans(rDoc, aMultiMark, aMarkRange)); } rDoc.DeleteSelection( nFlags, aMultiMark ); diff --git a/sc/source/ui/docshell/docfuncutil.cxx b/sc/source/ui/docshell/docfuncutil.cxx index 570ed52..35f3fb2 100644 --- a/sc/source/ui/docshell/docfuncutil.cxx +++ b/sc/source/ui/docshell/docfuncutil.cxx @@ -20,6 +20,10 @@ #include <docfuncutil.hxx> #include <document.hxx> #include <markdata.hxx> +#include <undobase.hxx> +#include <global.hxx> + +#include <memory> namespace sc { @@ -34,6 +38,63 @@ bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMa return false; } +ScDocument* DocFuncUtil::createDeleteContentsUndoDoc( + ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange, + InsertDeleteFlags nFlags, bool bOnlyMarked ) +{ + std::unique_ptr<ScDocument> pUndoDoc(new ScDocument(SCDOCMODE_UNDO)); + SCTAB nTab = rRange.aStart.Tab(); + pUndoDoc->InitUndo(&rDoc, nTab, nTab); + SCTAB nTabCount = rDoc.GetTableCount(); + ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end(); + for (; itr != itrEnd; ++itr) + if (*itr != nTab) + pUndoDoc->AddUndoTab( *itr, *itr ); + ScRange aCopyRange = rRange; + aCopyRange.aStart.SetTab(0); + aCopyRange.aEnd.SetTab(nTabCount-1); + + // in case of "Format/Standard" copy all attributes, because CopyToDocument + // with IDF_HARDATTR only is too time-consuming: + InsertDeleteFlags nUndoDocFlags = nFlags; + if (nFlags & IDF_ATTRIB) + nUndoDocFlags |= IDF_ATTRIB; + if (nFlags & IDF_EDITATTR) // Edit-Engine-Attribute + nUndoDocFlags |= IDF_STRING; // -> cells will be changed + if (nFlags & IDF_NOTE) + nUndoDocFlags |= IDF_CONTENTS; // copy all cells with their notes + // do not copy note captions to undo document + nUndoDocFlags |= IDF_NOCAPTIONS; + rDoc.CopyToDocument(aCopyRange, nUndoDocFlags, bOnlyMarked, pUndoDoc.get(), &rMark); + + return pUndoDoc.release(); +} + +ScSimpleUndo::DataSpansType* DocFuncUtil::getNonEmptyCellSpans( + const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange ) +{ + std::unique_ptr<ScSimpleUndo::DataSpansType> pDataSpans(new ScSimpleUndo::DataSpansType); + ScMarkData::const_iterator it = rMark.begin(), itEnd = rMark.end(); + for (; it != itEnd; ++it) + { + SCTAB nTab = *it; + + SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col(); + SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row(); + + std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r = + pDataSpans->insert(nTab, new sc::ColumnSpanSet(false)); + + if (r.second) + { + sc::ColumnSpanSet* pSet = r.first->second; + pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true); + } + } + + return pDataSpans.release(); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/docfuncutil.hxx b/sc/source/ui/inc/docfuncutil.hxx index 20927a0..553bab6 100644 --- a/sc/source/ui/inc/docfuncutil.hxx +++ b/sc/source/ui/inc/docfuncutil.hxx @@ -5,17 +5,34 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef INCLUDED_SC_DOCFUNCUTIL_HXX +#define INCLUDED_SC_DOCFUNCUTIL_HXX + +#include <undobase.hxx> + class ScDocument; class ScMarkData; +class ScRange; +struct InsertDeleteFlags; namespace sc { class DocFuncUtil { public: + static bool hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark ); + + static ScDocument* createDeleteContentsUndoDoc( + ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange, + InsertDeleteFlags nFlags, bool bOnlyMarked ); + + static ScSimpleUndo::DataSpansType* getNonEmptyCellSpans( + const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange ); }; } +#endif + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 201b720..cb3db19 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -1834,50 +1834,8 @@ void ScViewFunc::DeleteContents( InsertDeleteFlags nFlags, bool bRecord ) if ( bRecord ) { - pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); - SCTAB nTab = aMarkRange.aStart.Tab(); - pUndoDoc->InitUndo( pDoc, nTab, nTab ); - SCTAB nTabCount = pDoc->GetTableCount(); - ScMarkData::iterator itr = aFuncMark.begin(), itrEnd = aFuncMark.end(); - for (; itr != itrEnd; ++itr) - if (*itr != nTab) - pUndoDoc->AddUndoTab( *itr, *itr ); - ScRange aCopyRange = aExtendedRange; - aCopyRange.aStart.SetTab(0); - aCopyRange.aEnd.SetTab(nTabCount-1); - - // in case of "Format/Standard" copy all attributes, because CopyToDocument - // with IDF_HARDATTR only is too time-consuming: - InsertDeleteFlags nUndoDocFlags = nFlags; - if (nFlags & IDF_ATTRIB) - nUndoDocFlags |= IDF_ATTRIB; - if (nFlags & IDF_EDITATTR) // Edit-Engine-Attribute - nUndoDocFlags |= IDF_STRING; // -> cells will be changed - if (nFlags & IDF_NOTE) - nUndoDocFlags |= IDF_CONTENTS; // copy all cells with their notes - // do not copy note captions to undo document - nUndoDocFlags |= IDF_NOCAPTIONS; - pDoc->CopyToDocument( aCopyRange, nUndoDocFlags, bMulti, pUndoDoc, &aFuncMark ); - - pDataSpans.reset(new ScSimpleUndo::DataSpansType); - - for (itr = aFuncMark.begin(); itr != itrEnd; ++itr) - { - nTab = *itr; - - SCCOL nCol1 = aCopyRange.aStart.Col(), nCol2 = aCopyRange.aEnd.Col(); - SCROW nRow1 = aCopyRange.aStart.Row(), nRow2 = aCopyRange.aEnd.Row(); - - std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r = - pDataSpans->insert(nTab, new sc::ColumnSpanSet(false)); - - if (r.second) - { - ScSimpleUndo::DataSpansType::iterator it = r.first; - sc::ColumnSpanSet* pSet = it->second; - pSet->scan(*pDoc, nTab, nCol1, nRow1, nCol2, nRow2, true); - } - } + pUndoDoc = sc::DocFuncUtil::createDeleteContentsUndoDoc(*pDoc, aFuncMark, aExtendedRange, nFlags, bMulti); + pDataSpans.reset(sc::DocFuncUtil::getNonEmptyCellSpans(*pDoc, aFuncMark, aExtendedRange)); } HideAllCursors(); // for if summary is cancelled commit ed0e3fdcc13e0925c16aa81f6aa461892f15d81a Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Wed Oct 8 20:01:58 2014 -0400 Start sharing common code between DeleteContents of ScViewFunc/ScDocFunc. The goal is to have ScViewFunc::DeleteContents() simply call ScDocFunc::DeleteContents() while doing the view only stuff in the ScViewFunc variant. This is just a step toward that goal. Change-Id: I2e574f9eb2b2be5340dbfb6f10739dfc2406faae diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 55988a1..20460ee 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -404,6 +404,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/docshell/dbdocfun \ sc/source/ui/docshell/dbdocimp \ sc/source/ui/docshell/docfunc \ + sc/source/ui/docshell/docfuncutil \ sc/source/ui/docshell/docsh \ sc/source/ui/docshell/docsh2 \ sc/source/ui/docshell/docsh3 \ diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index f3a6245..fedbd20 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -86,6 +86,7 @@ #include <rowheightcontext.hxx> #include <cellvalues.hxx> #include <undoconvert.hxx> +#include <docfuncutil.hxx> #include <memory> #include <utility> @@ -595,17 +596,8 @@ bool ScDocFunc::DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlag if ( rDoc.ExtendMerge( aExtendedRange, true ) ) bMulti = false; - // keine Objekte auf geschuetzten Tabellen - bool bObjects = false; - if ( nFlags & IDF_OBJECTS ) - { - bObjects = true; - SCTAB nTabCount = rDoc.GetTableCount(); - ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end(); - for (; itr != itrEnd && *itr < nTabCount; ++itr) - if (rDoc.IsTabProtected(*itr)) - bObjects = false; - } + // no objects on protected tabs + bool bObjects = (nFlags & IDF_OBJECTS) && !sc::DocFuncUtil::hasProtectedTab(rDoc, rMark); sal_uInt16 nExtFlags = 0; // extra flags are needed only if attributes are deleted if ( nFlags & IDF_ATTRIB ) @@ -674,7 +666,6 @@ bool ScDocFunc::DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlag } } -//! HideAllCursors(); // falls Zusammenfassung aufgehoben wird rDoc.DeleteSelection( nFlags, aMultiMark ); // add undo action after drawing undo is complete (objects and note captions) diff --git a/sc/source/ui/docshell/docfuncutil.cxx b/sc/source/ui/docshell/docfuncutil.cxx new file mode 100644 index 0000000..570ed52 --- /dev/null +++ b/sc/source/ui/docshell/docfuncutil.cxx @@ -0,0 +1,39 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <docfuncutil.hxx> +#include <document.hxx> +#include <markdata.hxx> + +namespace sc { + +bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark ) +{ + SCTAB nTabCount = rDoc.GetTableCount(); + ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end(); + for (; itr != itrEnd && *itr < nTabCount; ++itr) + if (rDoc.IsTabProtected(*itr)) + return true; + + return false; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/docfuncutil.hxx b/sc/source/ui/inc/docfuncutil.hxx new file mode 100644 index 0000000..20927a0 --- /dev/null +++ b/sc/source/ui/inc/docfuncutil.hxx @@ -0,0 +1,21 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + */ + +class ScDocument; +class ScMarkData; + +namespace sc { + +class DocFuncUtil +{ +public: + static bool hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark ); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index c3782e4..201b720 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -76,6 +76,8 @@ #include "cellsuno.hxx" #include "tokenarray.hxx" #include <rowheightcontext.hxx> +#include <docfuncutil.hxx> + #include <boost/scoped_ptr.hpp> static void lcl_PostRepaintCondFormat( const ScConditionalFormat *pCondFmt, ScDocShell *pDocSh ) @@ -1800,15 +1802,7 @@ void ScViewFunc::DeleteContents( InsertDeleteFlags nFlags, bool bRecord ) } // no objects on protected tabs - bool bObjects = false; - if ( nFlags & IDF_OBJECTS ) - { - bObjects = true; - ScMarkData::iterator itr = aFuncMark.begin(), itrEnd = aFuncMark.end(); - for (; itr != itrEnd; ++itr) - if (pDoc->IsTabProtected(*itr)) - bObjects = false; - } + bool bObjects = (nFlags & IDF_OBJECTS) && !sc::DocFuncUtil::hasProtectedTab(*pDoc, aFuncMark); sal_uInt16 nExtFlags = 0; // extra flags are needed only if attributes are deleted if ( nFlags & IDF_ATTRIB ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits