sc/inc/column.hxx | 5 +-- sc/inc/document.hxx | 6 ++- sc/inc/scopetools.hxx | 9 +++++ sc/inc/table.hxx | 2 - sc/qa/unit/ucalc.cxx | 58 +++++++++++++++++++++++++++++++++++-- sc/qa/unit/ucalc.hxx | 3 + sc/source/core/data/column.cxx | 4 +- sc/source/core/data/column3.cxx | 12 +++++-- sc/source/core/data/documen7.cxx | 25 +++++++++++++++ sc/source/core/data/document.cxx | 9 +++-- sc/source/core/data/table2.cxx | 4 +- sc/source/core/tool/scopetools.cxx | 11 +++++++ sc/source/ui/docshell/impex.cxx | 8 +++++ sc/source/ui/undo/undobase.cxx | 22 -------------- sc/source/ui/undo/undoblk.cxx | 5 ++- 15 files changed, 142 insertions(+), 41 deletions(-)
New commits: commit f5d8029a456c2c708cbc2b67f2d7875540dff1ab Author: Kohei Yoshida <[email protected]> Date: Wed Jan 29 14:00:47 2014 -0500 fdo#74014: Broadcast changes during undo and redo after paste. Change-Id: I271bbba5e5eb70e48274a4a062d125456af8ff6c diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index e08226c..1ac1e3f 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -214,7 +214,8 @@ public: bool TestInsertRow( SCROW nStartRow, SCSIZE nSize ) const; void InsertRow( SCROW nStartRow, SCSIZE nSize ); void DeleteRow( SCROW nStartRow, SCSIZE nSize ); - void DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag ); + void DeleteArea( + SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag, bool bBroadcast = true ); void CopyToClip( sc::CopyToClipContext& rCxt, SCROW nRow1, SCROW nRow2, ScColumn& rColumn ) const; void CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol); @@ -412,7 +413,7 @@ public: void RemoveProtected( SCROW nStartRow, SCROW nEndRow ); SCsROW ApplySelectionCache( SfxItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = NULL ); - void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ); + void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast ); void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark ); void ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark ); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 5fb5f6d..d39cb09 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1441,8 +1441,8 @@ public: SC_DLLPUBLIC void ApplySelectionPattern( const ScPatternAttr& rAttr, const ScMarkData& rMark, ScEditDataArray* pDataArray = NULL ); - void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ); - void DeleteSelectionTab( SCTAB nTab, sal_uInt16 nDelFlag, const ScMarkData& rMark ); + void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast = true ); + void DeleteSelectionTab( SCTAB nTab, sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast = true ); SC_DLLPUBLIC void SetColWidth( SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth ); SC_DLLPUBLIC void SetColWidthOnly( SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth ); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 00bddb9..bc10089 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -629,7 +629,7 @@ public: bool RemoveFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_Int16 nFlags ); void ApplySelectionCache( SfxItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = NULL ); - void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ); + void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast = true ); void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark ); void ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark ); diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 8c6102f..7771f0e 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -484,7 +484,7 @@ void ScColumn::ClearSelectionItems( const sal_uInt16* pWhich,const ScMarkData& r } -void ScColumn::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ) +void ScColumn::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast ) { SCROW nTop; SCROW nBottom; @@ -493,7 +493,7 @@ void ScColumn::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ) { ScMarkArrayIter aMarkIter( rMark.GetArray() + nCol ); while (aMarkIter.Next( nTop, nBottom )) - DeleteArea(nTop, nBottom, nDelFlag); + DeleteArea(nTop, nBottom, nDelFlag, bBroadcast); } } diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 2301b0f..542fa88 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -574,7 +574,8 @@ public: } -void ScColumn::DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag) +void ScColumn::DeleteArea( + SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag, bool bBroadcast ) { sal_uInt16 nContMask = IDF_CONTENTS; // IDF_NOCAPTIONS needs to be passed too, if IDF_NOTE is set @@ -626,9 +627,12 @@ void ScColumn::DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag) else if ((nDelFlag & IDF_HARDATTR) == IDF_HARDATTR) pAttrArray->DeleteHardAttr( nStartRow, nEndRow ); - // Broadcast on only cells that were deleted; no point broadcasting on - // cells that were already empty before the deletion. - BroadcastCells(aDeletedRows, SC_HINT_DATACHANGED); + if (bBroadcast) + { + // Broadcast on only cells that were deleted; no point broadcasting on + // cells that were already empty before the deletion. + BroadcastCells(aDeletedRows, SC_HINT_DATACHANGED); + } } bool ScColumn::InitBlockPosition( sc::ColumnBlockPosition& rBlockPos ) diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 1f00bd7..94167a5 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -5618,20 +5618,21 @@ void ScDocument::ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData } -void ScDocument::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ) +void ScDocument::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast ) { SCTAB nMax = static_cast<SCTAB>(maTabs.size()); ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end(); for (; itr != itrEnd && *itr < nMax; ++itr) if (maTabs[*itr]) - maTabs[*itr]->DeleteSelection( nDelFlag, rMark ); + maTabs[*itr]->DeleteSelection(nDelFlag, rMark, bBroadcast); } -void ScDocument::DeleteSelectionTab( SCTAB nTab, sal_uInt16 nDelFlag, const ScMarkData& rMark ) +void ScDocument::DeleteSelectionTab( + SCTAB nTab, sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast ) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->DeleteSelection( nDelFlag, rMark ); + maTabs[nTab]->DeleteSelection(nDelFlag, rMark, bBroadcast); else { OSL_FAIL("wrong table"); diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index f96d913b..ce4871a 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -453,12 +453,12 @@ void ScTable::DeleteArea(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, sal } -void ScTable::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ) +void ScTable::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark, bool bBroadcast ) { { // scope for bulk broadcast ScBulkBroadcast aBulkBroadcast( pDocument->GetBASM()); for (SCCOL i=0; i<=MAXCOL; i++) - aCol[i].DeleteSelection( nDelFlag, rMark ); + aCol[i].DeleteSelection(nDelFlag, rMark, bBroadcast); } ScRangeList aRangeList; diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx index 54c2486..13f529e 100644 --- a/sc/source/ui/undo/undoblk.cxx +++ b/sc/source/ui/undo/undoblk.cxx @@ -950,7 +950,10 @@ void ScUndoPaste::DoChange(bool bUndo) pDocShell->UpdatePaintExt(nExtFlags, maBlockRanges.Combine()); aMarkData.MarkToMulti(); - pDoc->DeleteSelection( nUndoFlags, aMarkData ); + pDoc->DeleteSelection(nUndoFlags, aMarkData, false); // no broadcasting here + for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i) + pDoc->BroadcastCells(*maBlockRanges[i], SC_HINT_DATACHANGED); + aMarkData.MarkToSimple(); SCTAB nFirstSelected = aMarkData.GetFirstSelected(); commit ccd7953e0042c8063e3cbd8e3a3dd9004c1b4f7e Author: Kohei Yoshida <[email protected]> Date: Wed Jan 29 12:32:10 2014 -0500 fdo#74014: Add unit test for pasting an unformatted text into cells. Change-Id: I87f7b3012a2c139b0ecc3dd699ccecb31af77ac7 diff --git a/sc/inc/scopetools.hxx b/sc/inc/scopetools.hxx index a7983e0..5a16c2c 100644 --- a/sc/inc/scopetools.hxx +++ b/sc/inc/scopetools.hxx @@ -37,6 +37,15 @@ public: ~ExpandRefsSwitch(); }; +class SC_DLLPUBLIC UndoSwitch +{ + ScDocument& mrDoc; + bool mbOldValue; +public: + UndoSwitch(ScDocument& rDoc, bool bUndo); + ~UndoSwitch(); +}; + } #endif diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 8cdcb4d..4a9907a 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -6,6 +6,9 @@ * 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 "ucalc.hxx" + #include <sal/config.h> #include <test/bootstrapfixture.hxx> @@ -50,6 +53,8 @@ #include "queryparam.hxx" #include "edittextiterator.hxx" #include "editutil.hxx" +#include <asciiopt.hxx> +#include <impex.hxx> #include "formula/IFunctionDescription.hxx" @@ -72,8 +77,6 @@ #include <sstream> #include <vector> -#include "ucalc.hxx" - struct TestImpl { ScDocShellRef m_xDocShell; @@ -5167,6 +5170,57 @@ void Test::testCondCopyPaste() m_pDoc->DeleteTab(0); } +void Test::testImportStream() +{ + sc::AutoCalcSwitch aAC(*m_pDoc, true); // turn on auto calc. + sc::UndoSwitch aUndo(*m_pDoc, true); // enable undo. + + m_pDoc->InsertTab(0, "Test"); + + m_pDoc->SetString(ScAddress(0,1,0), "=SUM(A1:C1)"); + + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(0,1,0))); + + // CSV import options. + ScAsciiOptions aOpt; + aOpt.SetFieldSeps(","); + + ScImportExport aObj(m_pDoc, ScAddress(0,0,0)); + aObj.SetExtOptions(aOpt); + aObj.ImportString("1,2,3", FORMAT_STRING); + + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(1,0,0))); + CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,0,0))); + + // Formula value should have been updated. + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,1,0))); + + // Undo, and check the result. + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT_MESSAGE("Failed to get the undo manager.", pUndoMgr); + pUndoMgr->Undo(); + + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(1,0,0))); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(2,0,0))); + + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(0,1,0))); // formula + + // Redo, and check the result. + pUndoMgr->Redo(); + + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(1,0,0))); + CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,0,0))); + + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,1,0))); // formula + + + pUndoMgr->Clear(); + m_pDoc->DeleteTab(0); +} + void Test::testMixData() { m_pDoc->InsertTab(0, "Test"); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 8a4e350..8ddd6f0 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -307,6 +307,8 @@ public: void testCondFormatInsertCol(); void testCondCopyPaste(); + void testImportStream(); + CPPUNIT_TEST_SUITE(Test); #if CALC_TEST_PERF CPPUNIT_TEST(testPerf); @@ -425,6 +427,7 @@ public: CPPUNIT_TEST(testCondFormatInsertRow); CPPUNIT_TEST(testCondFormatInsertCol); CPPUNIT_TEST(testCondCopyPaste); + CPPUNIT_TEST(testImportStream); CPPUNIT_TEST_SUITE_END(); private: diff --git a/sc/source/core/tool/scopetools.cxx b/sc/source/core/tool/scopetools.cxx index af65cff..a1a52a1 100644 --- a/sc/source/core/tool/scopetools.cxx +++ b/sc/source/core/tool/scopetools.cxx @@ -34,6 +34,17 @@ ExpandRefsSwitch::~ExpandRefsSwitch() mrDoc.SetExpandRefs(mbOldValue); } +UndoSwitch::UndoSwitch(ScDocument& rDoc, bool bUndo) : + mrDoc(rDoc), mbOldValue(rDoc.IsUndoEnabled()) +{ + mrDoc.EnableUndo(bUndo); +} + +UndoSwitch::~UndoSwitch() +{ + mrDoc.EnableUndo(mbOldValue); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 8a36879eaf0977448b113c2239014d2e2b7ab258 Author: Kohei Yoshida <[email protected]> Date: Wed Jan 29 11:42:27 2014 -0500 fdo#74014: More on broadcasting at appropriate places. Also, call PostDataChanged() to re-paint re-calculated formula cells. Change-Id: I63161329d4bfe937f754773fd68c37e3836c4950 diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 6a980ab..5fb5f6d 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1808,6 +1808,8 @@ public: */ void Broadcast( const ScHint& rHint ); + void BroadcastCells( const ScRange& rRange, sal_uLong nHint ); + /// only area, no cell broadcast void AreaBroadcast( const ScHint& rHint ); /// only areas in range, no cell broadcasts diff --git a/sc/source/core/data/documen7.cxx b/sc/source/core/data/documen7.cxx index b8f691b..210d87b 100644 --- a/sc/source/core/data/documen7.cxx +++ b/sc/source/core/data/documen7.cxx @@ -104,6 +104,31 @@ void ScDocument::Broadcast( const ScHint& rHint ) } } +void ScDocument::BroadcastCells( const ScRange& rRange, sal_uLong nHint ) +{ + CellContentModified(); + + ScBulkBroadcast aBulkBroadcast(pBASM); + + ScHint aHint(nHint, ScAddress()); + ScAddress& rPos = aHint.GetAddress(); + for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab) + { + rPos.SetTab(nTab); + for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) + { + rPos.SetCol(nCol); + for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow) + { + rPos.SetRow(nRow); + Broadcast(aHint); + } + } + } + + BroadcastUno(SfxSimpleHint(SC_HINT_DATACHANGED)); +} + void ScDocument::AreaBroadcast( const ScHint& rHint ) { if ( !pBASM ) diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index c6ebff1..bf1c048 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -947,6 +947,12 @@ bool ScImportExport::Text2Doc( SvStream& rStrm ) } EndPaste(); + if (bOk) + { + pDoc->BroadcastCells(aRange, SC_HINT_DATACHANGED); + pDocSh->PostDataChanged(); + } + return bOk; } @@ -1484,6 +1490,8 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) if (bRangeIsDetermined) EndPaste(false); + pDoc->BroadcastCells(aRange, SC_HINT_DATACHANGED); + pDocSh->PostDataChanged(); return true; } diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx index fdb2cfc5..16cabf6 100644 --- a/sc/source/ui/undo/undobase.cxx +++ b/sc/source/ui/undo/undobase.cxx @@ -146,27 +146,7 @@ void ScSimpleUndo::EndRedo() void ScSimpleUndo::BroadcastChanges( const ScRange& rRange ) { ScDocument* pDoc = pDocShell->GetDocument(); - pDoc->CellContentModified(); - - ScBulkBroadcast aBulkBroadcast( pDoc->GetBASM()); - - ScHint aHint(SC_HINT_DATACHANGED, ScAddress()); - ScAddress& rPos = aHint.GetAddress(); - for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab) - { - rPos.SetTab(nTab); - for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) - { - rPos.SetCol(nCol); - for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow) - { - rPos.SetRow(nRow); - pDoc->Broadcast(aHint); - } - } - } - - pDoc->BroadcastUno(SfxSimpleHint(SC_HINT_DATACHANGED)); + pDoc->BroadcastCells(rRange, SC_HINT_DATACHANGED); } void ScSimpleUndo::ShowTable( SCTAB nTab ) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
