diff options
-rw-r--r-- | sc/inc/sharedformula.hxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 67 | ||||
-rw-r--r-- | sc/source/core/tool/sharedformula.cxx | 6 |
3 files changed, 13 insertions, 70 deletions
diff --git a/sc/inc/sharedformula.hxx b/sc/inc/sharedformula.hxx index 6767d4a2c151..fa75e8058199 100644 --- a/sc/inc/sharedformula.hxx +++ b/sc/inc/sharedformula.hxx @@ -66,6 +66,16 @@ public: static void splitFormulaCellGroup(const CellStoreType::position_type& aPos); /** + * See if two specified adjacent formula cells can be merged, and if they + * can, merge them into the same group. + * + * @param rPos position object of the first cell + * @param rCell1 first cell + * @param rCell2 second cell located immediately below the first cell. + */ + static void joinFormulaCells( + const CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2); + /** * Merge with an existing formula group (if any) located immediately above * if the cell at specified position is a formula cell, and its formula * tokens are identical to that of the above formula group. diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index de8adde65b8a..2136e04f30b3 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -306,69 +306,6 @@ sc::CellStoreType::iterator ScColumn::GetPositionToInsert( SCROW nRow ) return GetPositionToInsert(maCells.begin(), nRow); } -namespace { - -void joinFormulaCells(const sc::CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2) -{ - ScFormulaCell::CompareState eState = rCell1.CompareByTokenArray(rCell2); - if (eState == ScFormulaCell::NotEqual) - return; - - SCROW nRow = rPos.first->position + rPos.second; - - // Formula tokens equal those of the previous formula cell. - ScFormulaCellGroupRef xGroup1 = rCell1.GetCellGroup(); - ScFormulaCellGroupRef xGroup2 = rCell2.GetCellGroup(); - if (xGroup1) - { - if (xGroup2) - { - // Both cell 1 and cell 2 are shared. Merge them together. - if (xGroup1.get() == xGroup2.get()) - // They belong to the same group. - return; - - // Set the group object from cell 1 to all cells in group 2. - xGroup1->mnLength += xGroup2->mnLength; - size_t nOffset = rPos.second + 1; // position of cell 2 - for (size_t i = 0, n = xGroup2->mnLength; i < n; ++i) - { - ScFormulaCell& rCell = *sc::formula_block::at(*rPos.first->data, nOffset+i); - rCell.SetCellGroup(xGroup1); - } - } - else - { - // cell 1 is shared but cell 2 is not. - rCell2.SetCellGroup(xGroup1); - ++xGroup1->mnLength; - } - } - else - { - if (xGroup2) - { - // cell 1 is not shared, but cell 2 is already shared. - rCell1.SetCellGroup(xGroup2); - xGroup2->mnStart = nRow; - ++xGroup2->mnLength; - } - else - { - // neither cells are shared. - xGroup1.reset(new ScFormulaCellGroup); - xGroup1->mnStart = nRow; - xGroup1->mbInvariant = (eState == ScFormulaCell::EqualInvariant); - xGroup1->mnLength = 2; - - rCell1.SetCellGroup(xGroup1); - rCell2.SetCellGroup(xGroup1); - } - } -} - -} - void ScColumn::JoinNewFormulaCell( const sc::CellStoreType::position_type& aPos, ScFormulaCell& rCell ) const { @@ -378,14 +315,14 @@ void ScColumn::JoinNewFormulaCell( ScFormulaCell& rPrev = *sc::formula_block::at(*aPos.first->data, aPos.second-1); sc::CellStoreType::position_type aPosPrev = aPos; --aPosPrev.second; - joinFormulaCells(aPosPrev, rPrev, rCell); + sc::SharedFormulaUtil::joinFormulaCells(aPosPrev, rPrev, rCell); } // Check the next row position for possible grouping. if (aPos.first->type == sc::element_type_formula && aPos.second+1 < aPos.first->size) { ScFormulaCell& rNext = *sc::formula_block::at(*aPos.first->data, aPos.second+1); - joinFormulaCells(aPos, rCell, rNext); + sc::SharedFormulaUtil::joinFormulaCells(aPos, rCell, rNext); } } diff --git a/sc/source/core/tool/sharedformula.cxx b/sc/source/core/tool/sharedformula.cxx index c1bc56447dd6..5cdfc78522b5 100644 --- a/sc/source/core/tool/sharedformula.cxx +++ b/sc/source/core/tool/sharedformula.cxx @@ -62,9 +62,7 @@ void SharedFormulaUtil::splitFormulaCellGroup(const CellStoreType::position_type } } -namespace { - -void joinFormulaCells(const sc::CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2) +void SharedFormulaUtil::joinFormulaCells(const CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2) { ScFormulaCell::CompareState eState = rCell1.CompareByTokenArray(rCell2); if (eState == ScFormulaCell::NotEqual) @@ -123,8 +121,6 @@ void joinFormulaCells(const sc::CellStoreType::position_type& rPos, ScFormulaCel } } -} - void SharedFormulaUtil::joinFormulaCellAbove(const CellStoreType::position_type& aPos) { if (aPos.first->type != sc::element_type_formula) |