diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-07-11 00:46:46 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-07-11 12:30:16 -0400 |
commit | 67ffff37ed16dff6529daf36835554f54a28fe5e (patch) | |
tree | 0c67b55817631941bb57266237892d6e80269ed2 /sc | |
parent | d35cf5e19652989419aa598119ccd978307111fe (diff) |
Move UnshareFormulaCell() out of ScColumn into SharedFormulaUtil.
This one too doesn't operate on column.
Change-Id: Ieb23641ca4860d6f137b266813ad56f4984e0523
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/inc/sharedformula.hxx | 9 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 126 | ||||
-rw-r--r-- | sc/source/core/tool/sharedformula.cxx | 118 |
5 files changed, 135 insertions, 130 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 2c59b77275f5..b223a2d2c30b 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -500,8 +500,6 @@ public: void DetachFormulaCells( const sc::CellStoreType::position_type& aPos, size_t nLength ); - void UnshareFormulaCell( const sc::CellStoreType::position_type& aPos, ScFormulaCell& rCell ) const; - /** * Regroup formula cells for the entire column. */ diff --git a/sc/inc/sharedformula.hxx b/sc/inc/sharedformula.hxx index fa75e8058199..866c22f6486d 100644 --- a/sc/inc/sharedformula.hxx +++ b/sc/inc/sharedformula.hxx @@ -83,6 +83,15 @@ public: * @param aPos position of cell to examine. */ static void joinFormulaCellAbove(const CellStoreType::position_type& aPos); + + /** + * Turn a shared formula cell into a non-shared one, and split it off from + * the adjacent formula cell groups. + * + * @param aPos position of cell to examine + * @param rCell formula cell instance + */ + static void unshareFormulaCell(const CellStoreType::position_type& aPos, ScFormulaCell& rCell); }; } diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 730fed47753d..e9f4b8045ad9 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -1136,14 +1136,14 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol) { ScFormulaCell& rCell = *sc::formula_block::at(*aPos1.first->data, aPos1.second); updateRefInFormulaCell(rCell, rCol.nCol, nTab, rCol.nCol - nCol); - UnshareFormulaCell(aPos1, rCell); + sc::SharedFormulaUtil::unshareFormulaCell(aPos1, rCell); } if (aPos2.first->type == sc::element_type_formula) { ScFormulaCell& rCell = *sc::formula_block::at(*aPos2.first->data, aPos2.second); updateRefInFormulaCell(rCell, nCol, nTab, nCol - rCol.nCol); - UnshareFormulaCell(aPos2, rCell); + sc::SharedFormulaUtil::unshareFormulaCell(aPos2, rCell); } maCells.swap(nRow, nRow, rCol.maCells, nRow); @@ -2375,7 +2375,7 @@ public: { sc::CellStoreType::position_type aPos = mrColumn.GetCellStore().position(miPos, nRow); miPos = aPos.first; - mrColumn.UnshareFormulaCell(aPos, *pCell); + sc::SharedFormulaUtil::unshareFormulaCell(aPos, *pCell); pCell->UpdateTranspose(maSource, maDest, mpUndoDoc); mrColumn.JoinNewFormulaCell(aPos, *pCell); } @@ -2398,7 +2398,7 @@ public: { sc::CellStoreType::position_type aPos = mrColumn.GetCellStore().position(miPos, nRow); miPos = aPos.first; - mrColumn.UnshareFormulaCell(aPos, *pCell); + sc::SharedFormulaUtil::unshareFormulaCell(aPos, *pCell); pCell->UpdateGrow(maArea, mnGrowX, mnGrowY); mrColumn.JoinNewFormulaCell(aPos, *pCell); } @@ -2784,7 +2784,7 @@ public: sc::CellStoreType::position_type aPos = mrColumn.GetCellStore().position(miPos, nRow); miPos = aPos.first; - mrColumn.UnshareFormulaCell(aPos, *pCell); + sc::SharedFormulaUtil::unshareFormulaCell(aPos, *pCell); pCell->GetCode()->SetCodeError(0); OUStringBuffer aBuf; pCell->GetFormula(aBuf, meGram); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 2136e04f30b3..07d6e94b1e01 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -118,7 +118,7 @@ void ScColumn::Delete( SCROW nRow ) { ScFormulaCell* p = sc::formula_block::at(*it->data, aPos.second); p->EndListeningTo(pDocument); - UnshareFormulaCell(aPos, *p); + sc::SharedFormulaUtil::unshareFormulaCell(aPos, *p); } maCells.set_empty(nRow, nRow); maCellTextAttrs.set_empty(nRow, nRow); @@ -333,8 +333,7 @@ void ScColumn::DetachFormulaCell( // Have the dying formula cell stop listening. rCell.EndListeningTo(pDocument); - if (rCell.IsShared()) - UnshareFormulaCell(aPos, rCell); + sc::SharedFormulaUtil::unshareFormulaCell(aPos, rCell); } namespace { @@ -373,125 +372,6 @@ void ScColumn::DetachFormulaCells( sc::ProcessFormula(aPos.first, maCells, nRow, nNextTopRow-1, aFunc); } -void ScColumn::UnshareFormulaCell( - const sc::CellStoreType::position_type& aPos, ScFormulaCell& rCell ) const -{ - if (!rCell.IsShared()) - return; - - ScFormulaCellGroupRef xNone; - sc::CellStoreType::iterator it = aPos.first; - - // This formula cell is shared. Adjust the shared group. - if (rCell.aPos.Row() == rCell.GetSharedTopRow()) - { - // Top of the shared range. - ScFormulaCellGroupRef xGroup = rCell.GetCellGroup(); - if (xGroup->mnLength == 2) - { - // Group consists only only two cells. Mark the second one non-shared. -#if DEBUG_COLUMN_STORAGE - if (aPos.second+1 >= aPos.first->size) - { - cerr << "ScColumn::UnshareFormulaCell: There is no next formula cell but there should be!" << endl; - cerr.flush(); - abort(); - } -#endif - ScFormulaCell& rNext = *sc::formula_block::at(*it->data, aPos.second+1); - rNext.SetCellGroup(xNone); - } - else - { - // Move the top cell to the next formula cell down. - --xGroup->mnLength; - ++xGroup->mnStart; - } - } - else if (rCell.aPos.Row() == rCell.GetSharedTopRow() + rCell.GetSharedLength() - 1) - { - // Bottom of the shared range. - ScFormulaCellGroupRef xGroup = rCell.GetCellGroup(); - if (xGroup->mnLength == 2) - { - // Mark the top cell non-shared. -#if DEBUG_COLUMN_STORAGE - if (aPos.second == 0) - { - cerr << "ScColumn::UnshareFormulaCell: There is no previous formula cell but there should be!" << endl; - cerr.flush(); - abort(); - } -#endif - ScFormulaCell& rPrev = *sc::formula_block::at(*it->data, aPos.second-1); - rPrev.SetCellGroup(xNone); - } - else - { - // Just shortern the shared range length by one. - --xGroup->mnLength; - } - } - else - { - // In the middle of the shared range. Split it into two groups. - ScFormulaCellGroupRef xGroup = rCell.GetCellGroup(); - SCROW nEndRow = xGroup->mnStart + xGroup->mnLength - 1; - xGroup->mnLength = rCell.aPos.Row() - xGroup->mnStart; // Shorten the top group. - if (xGroup->mnLength == 1) - { - // Make the top cell non-shared. -#if DEBUG_COLUMN_STORAGE - if (aPos.second == 0) - { - cerr << "ScColumn::UnshareFormulaCell: There is no previous formula cell but there should be!" << endl; - cerr.flush(); - abort(); - } -#endif - ScFormulaCell& rPrev = *sc::formula_block::at(*it->data, aPos.second-1); - rPrev.SetCellGroup(xNone); - } - - SCROW nLength2 = nEndRow - rCell.aPos.Row(); - if (nLength2 >= 2) - { - ScFormulaCellGroupRef xGroup2; - xGroup2.reset(new ScFormulaCellGroup); - xGroup2->mnStart = rCell.aPos.Row() + 1; - xGroup2->mnLength = nLength2; - xGroup2->mbInvariant = xGroup->mbInvariant; -#if DEBUG_COLUMN_STORAGE - if (xGroup2->mnStart + xGroup2->mnLength > it->position + it->size) - { - cerr << "ScColumn::UnshareFormulaCell: Shared formula region goes beyond the formula block. Not good." << endl; - cerr.flush(); - abort(); - } -#endif - sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data); - std::advance(itCell, aPos.second+1); - sc::formula_block::iterator itCellEnd = itCell; - std::advance(itCellEnd, xGroup2->mnLength); - for (; itCell != itCellEnd; ++itCell) - { - ScFormulaCell& rCell2 = **itCell; - rCell2.SetCellGroup(xGroup2); - } - } - else - { - // Make the next cell non-shared. - sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data); - std::advance(itCell, aPos.second+1); - ScFormulaCell& rCell2 = **itCell; - rCell2.SetCellGroup(xNone); - } - } - - rCell.SetCellGroup(xNone); -} - sc::CellStoreType::iterator ScColumn::GetPositionToInsert( const sc::CellStoreType::iterator& it, SCROW nRow ) { // See if we are overwriting an existing formula cell. @@ -662,7 +542,7 @@ class EmptyCells if (rPos.first->type == sc::element_type_formula) { ScFormulaCell& rCell = *sc::formula_block::at(*rPos.first->data, rPos.second); - mrColumn.UnshareFormulaCell(rPos, rCell); + sc::SharedFormulaUtil::unshareFormulaCell(rPos, rCell); } } diff --git a/sc/source/core/tool/sharedformula.cxx b/sc/source/core/tool/sharedformula.cxx index 5cdfc78522b5..2ea5cf881907 100644 --- a/sc/source/core/tool/sharedformula.cxx +++ b/sc/source/core/tool/sharedformula.cxx @@ -139,6 +139,124 @@ void SharedFormulaUtil::joinFormulaCellAbove(const CellStoreType::position_type& joinFormulaCells(aPosPrev, rPrev, rCell); } +void SharedFormulaUtil::unshareFormulaCell(const CellStoreType::position_type& aPos, ScFormulaCell& rCell) +{ + if (!rCell.IsShared()) + return; + + ScFormulaCellGroupRef xNone; + sc::CellStoreType::iterator it = aPos.first; + + // This formula cell is shared. Adjust the shared group. + if (rCell.aPos.Row() == rCell.GetSharedTopRow()) + { + // Top of the shared range. + ScFormulaCellGroupRef xGroup = rCell.GetCellGroup(); + if (xGroup->mnLength == 2) + { + // Group consists only only two cells. Mark the second one non-shared. +#if DEBUG_COLUMN_STORAGE + if (aPos.second+1 >= aPos.first->size) + { + cerr << "ScColumn::UnshareFormulaCell: There is no next formula cell but there should be!" << endl; + cerr.flush(); + abort(); + } +#endif + ScFormulaCell& rNext = *sc::formula_block::at(*it->data, aPos.second+1); + rNext.SetCellGroup(xNone); + } + else + { + // Move the top cell to the next formula cell down. + --xGroup->mnLength; + ++xGroup->mnStart; + } + } + else if (rCell.aPos.Row() == rCell.GetSharedTopRow() + rCell.GetSharedLength() - 1) + { + // Bottom of the shared range. + ScFormulaCellGroupRef xGroup = rCell.GetCellGroup(); + if (xGroup->mnLength == 2) + { + // Mark the top cell non-shared. +#if DEBUG_COLUMN_STORAGE + if (aPos.second == 0) + { + cerr << "ScColumn::UnshareFormulaCell: There is no previous formula cell but there should be!" << endl; + cerr.flush(); + abort(); + } +#endif + ScFormulaCell& rPrev = *sc::formula_block::at(*it->data, aPos.second-1); + rPrev.SetCellGroup(xNone); + } + else + { + // Just shortern the shared range length by one. + --xGroup->mnLength; + } + } + else + { + // In the middle of the shared range. Split it into two groups. + ScFormulaCellGroupRef xGroup = rCell.GetCellGroup(); + SCROW nEndRow = xGroup->mnStart + xGroup->mnLength - 1; + xGroup->mnLength = rCell.aPos.Row() - xGroup->mnStart; // Shorten the top group. + if (xGroup->mnLength == 1) + { + // Make the top cell non-shared. +#if DEBUG_COLUMN_STORAGE + if (aPos.second == 0) + { + cerr << "ScColumn::UnshareFormulaCell: There is no previous formula cell but there should be!" << endl; + cerr.flush(); + abort(); + } +#endif + ScFormulaCell& rPrev = *sc::formula_block::at(*it->data, aPos.second-1); + rPrev.SetCellGroup(xNone); + } + + SCROW nLength2 = nEndRow - rCell.aPos.Row(); + if (nLength2 >= 2) + { + ScFormulaCellGroupRef xGroup2; + xGroup2.reset(new ScFormulaCellGroup); + xGroup2->mnStart = rCell.aPos.Row() + 1; + xGroup2->mnLength = nLength2; + xGroup2->mbInvariant = xGroup->mbInvariant; +#if DEBUG_COLUMN_STORAGE + if (xGroup2->mnStart + xGroup2->mnLength > it->position + it->size) + { + cerr << "ScColumn::UnshareFormulaCell: Shared formula region goes beyond the formula block. Not good." << endl; + cerr.flush(); + abort(); + } +#endif + sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data); + std::advance(itCell, aPos.second+1); + sc::formula_block::iterator itCellEnd = itCell; + std::advance(itCellEnd, xGroup2->mnLength); + for (; itCell != itCellEnd; ++itCell) + { + ScFormulaCell& rCell2 = **itCell; + rCell2.SetCellGroup(xGroup2); + } + } + else + { + // Make the next cell non-shared. + sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data); + std::advance(itCell, aPos.second+1); + ScFormulaCell& rCell2 = **itCell; + rCell2.SetCellGroup(xNone); + } + } + + rCell.SetCellGroup(xNone); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |