Kaydet (Commit) 3f41b12c authored tarafından Kohei Yoshida's avatar Kohei Yoshida

SwapRow() is no more!

Good riddance.  It was optimized for the old cell storage.

Change-Id: I374194fe211d5b13dd60dbb68b9511a366fb32bd
üst bd532483
...@@ -186,7 +186,6 @@ public: ...@@ -186,7 +186,6 @@ public:
void Delete( SCROW nRow ); void Delete( SCROW nRow );
void FreeAll(); void FreeAll();
void SwapRow( SCROW nRow1, SCROW nRow2 );
void SwapCell( SCROW nRow, ScColumn& rCol); void SwapCell( SCROW nRow, ScColumn& rCol);
bool HasAttrib( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const; bool HasAttrib( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const;
......
...@@ -1007,7 +1007,6 @@ private: ...@@ -1007,7 +1007,6 @@ private:
bool IsSorted(SCCOLROW nStart, SCCOLROW nEnd) const; bool IsSorted(SCCOLROW nStart, SCCOLROW nEnd) const;
void DecoladeRow( ScSortInfoArray*, SCROW nRow1, SCROW nRow2 ); void DecoladeRow( ScSortInfoArray*, SCROW nRow1, SCROW nRow2 );
void SwapCol(SCCOL nCol1, SCCOL nCol2); void SwapCol(SCCOL nCol1, SCCOL nCol2);
void SwapRow(SCROW nRow1, SCROW nRow2);
short CompareCell( short CompareCell(
sal_uInt16 nSort, sal_uInt16 nSort,
ScRefCellValue& rCell1, SCCOL nCell1Col, SCROW nCell1Row, ScRefCellValue& rCell1, SCCOL nCell1Col, SCROW nCell1Row,
......
...@@ -841,338 +841,6 @@ const sc::CellTextAttr* ScColumn::GetCellTextAttr( sc::ColumnBlockConstPosition& ...@@ -841,338 +841,6 @@ const sc::CellTextAttr* ScColumn::GetCellTextAttr( sc::ColumnBlockConstPosition&
namespace { namespace {
ScFormulaCell* cloneFormulaCell(ScDocument* pDoc, const ScAddress& rNewPos, ScFormulaCell& rOldCell)
{
ScFormulaCell* pNew = new ScFormulaCell(rOldCell, *pDoc, rNewPos, SC_CLONECELL_ADJUST3DREL);
rOldCell.EndListeningTo(pDoc);
pNew->StartListeningTo(pDoc);
pNew->SetDirty();
return pNew;
}
}
void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
{
if (nRow1 == nRow2)
// Nothing to swap.
return;
// Ensure that nRow1 < nRow2.
if (nRow2 < nRow1)
std::swap(nRow1, nRow2);
// Broadcasters (if exist) should NOT be swapped.
sc::CellStoreType::position_type aPos1 = maCells.position(nRow1);
if (aPos1.first == maCells.end())
return;
sc::CellStoreType::position_type aPos2 = maCells.position(aPos1.first, nRow2);
if (aPos2.first == maCells.end())
return;
std::vector<SCROW> aRows;
aRows.reserve(2);
aRows.push_back(nRow1);
aRows.push_back(nRow2);
sc::CellStoreType::iterator it1 = aPos1.first, it2 = aPos2.first;
if (it1->type == it2->type)
{
// Both positions are of the same type. Do a simple value swap.
switch (it1->type)
{
case sc::element_type_empty:
// Both are empty. Nothing to swap.
return;
case sc::element_type_numeric:
std::swap(
sc::numeric_block::at(*it1->data, aPos1.second),
sc::numeric_block::at(*it2->data, aPos2.second));
break;
case sc::element_type_string:
std::swap(
sc::string_block::at(*it1->data, aPos1.second),
sc::string_block::at(*it2->data, aPos2.second));
break;
case sc::element_type_edittext:
std::swap(
sc::edittext_block::at(*it1->data, aPos1.second),
sc::edittext_block::at(*it2->data, aPos2.second));
break;
case sc::element_type_formula:
{
// Swapping of formula cells involve adjustment of references wrt their positions.
sc::formula_block::iterator itf1 = sc::formula_block::begin(*it1->data);
sc::formula_block::iterator itf2 = sc::formula_block::begin(*it2->data);
std::advance(itf1, aPos1.second);
std::advance(itf2, aPos2.second);
// Is it an identical formula in the same group - if so,
// take a shortcut to swap the result data:
if(!(*itf1)->SwapWithinGroup(*itf2))
{
// otherwise we need to really move the formula &
// re-write dependencies etc.
boost::scoped_ptr<ScFormulaCell> pOld1(*itf1);
boost::scoped_ptr<ScFormulaCell> pOld2(*itf2);
DetachFormulaCell(aPos1, **itf1);
DetachFormulaCell(aPos2, **itf2);
ScFormulaCell* pNew1 = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *pOld2);
ScFormulaCell* pNew2 = cloneFormulaCell(pDocument, ScAddress(nCol, nRow2, nTab), *pOld1);
*itf1 = pNew1;
*itf2 = pNew2;
ActivateNewFormulaCell(aPos1, *pNew1);
ActivateNewFormulaCell(aPos2, *pNew2);
}
}
break;
default:
;
}
SwapCellTextAttrs(nRow1, nRow2);
SwapCellNotes(nRow1, nRow2);
CellStorageModified();
BroadcastCells(aRows, SC_HINT_DATACHANGED);
return;
}
// The two cells are of different types.
ScRefCellValue aCell1 = GetCellValue(aPos1.first, aPos1.second);
ScRefCellValue aCell2 = GetCellValue(aPos2.first, aPos2.second);
// Make sure to put cells in row 1 first then row 2!
if (aCell1.meType == CELLTYPE_NONE)
{
// cell 1 is empty and cell 2 is not.
switch (aCell2.meType)
{
case CELLTYPE_VALUE:
it1 = maCells.set(it1, nRow1, aCell2.mfValue); // it2 becomes invalid.
maCells.set_empty(it1, nRow2, nRow2);
break;
case CELLTYPE_STRING:
it1 = maCells.set(it1, nRow1, *aCell2.mpString);
maCells.set_empty(it1, nRow2, nRow2);
break;
case CELLTYPE_EDIT:
{
it1 = maCells.set(
it1, nRow1, const_cast<EditTextObject*>(aCell2.mpEditText));
EditTextObject* p;
maCells.release(it1, nRow2, p);
}
break;
case CELLTYPE_FORMULA:
{
// cell 1 is empty and cell 2 is a formula cell.
ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
DetachFormulaCell(aPos2, *aCell2.mpFormula);
it1 = maCells.set(it1, nRow1, pNew);
maCells.set_empty(it1, nRow2, nRow2); // original formula cell gets deleted.
ActivateNewFormulaCell(it1, nRow1, *pNew);
}
break;
default:
;
}
SwapCellTextAttrs(nRow1, nRow2);
SwapCellNotes(nRow1, nRow2);
CellStorageModified();
BroadcastCells(aRows, SC_HINT_DATACHANGED);
return;
}
if (aCell2.meType == CELLTYPE_NONE)
{
// cell 1 is not empty and cell 2 is empty.
switch (aCell1.meType)
{
case CELLTYPE_VALUE:
// Value is copied in Cell1.
it1 = maCells.set_empty(it1, nRow1, nRow1);
maCells.set(it1, nRow2, aCell1.mfValue);
break;
case CELLTYPE_STRING:
{
svl::SharedString aStr = *aCell1.mpString; // make a copy.
it1 = maCells.set_empty(it1, nRow1, nRow1); // original string is gone.
maCells.set(it1, nRow2, aStr);
}
break;
case CELLTYPE_EDIT:
{
EditTextObject* p;
it1 = maCells.release(it1, nRow1, p);
maCells.set(it1, nRow2, p);
}
break;
case CELLTYPE_FORMULA:
{
// cell 1 is a formula cell and cell 2 is empty.
ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow2, nTab), *aCell1.mpFormula);
DetachFormulaCell(aPos1, *aCell1.mpFormula);
it1 = maCells.set_empty(it1, nRow1, nRow1); // original formula cell is gone.
it1 = maCells.set(it1, nRow2, pNew);
ActivateNewFormulaCell(it1, nRow2, *pNew);
}
break;
default:
;
}
SwapCellTextAttrs(nRow1, nRow2);
SwapCellNotes(nRow1, nRow2);
CellStorageModified();
BroadcastCells(aRows, SC_HINT_DATACHANGED);
return;
}
// Neither cells are empty, and they are of different types.
switch (aCell1.meType)
{
case CELLTYPE_VALUE:
{
switch (aCell2.meType)
{
case CELLTYPE_STRING:
it1 = maCells.set(it1, nRow1, *aCell2.mpString);
break;
case CELLTYPE_EDIT:
{
it1 = maCells.set(
it1, nRow1, const_cast<EditTextObject*>(aCell2.mpEditText));
EditTextObject* p;
it1 = maCells.release(it1, nRow2, p);
}
break;
case CELLTYPE_FORMULA:
{
DetachFormulaCell(aPos2, *aCell2.mpFormula);
ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
it1 = maCells.set(it1, nRow1, pNew);
ActivateNewFormulaCell(it1, nRow1, *pNew);
// The old formula cell will get overwritten below.
}
break;
default:
;
}
maCells.set(it1, nRow2, aCell1.mfValue);
}
break;
case CELLTYPE_STRING:
{
svl::SharedString aStr = *aCell1.mpString; // make a copy.
switch (aCell2.meType)
{
case CELLTYPE_VALUE:
it1 = maCells.set(it1, nRow1, aCell2.mfValue);
break;
case CELLTYPE_EDIT:
{
it1 = maCells.set(
it1, nRow1, const_cast<EditTextObject*>(aCell2.mpEditText));
EditTextObject* p;
it1 = maCells.release(it1, nRow2, p); // prevent it being overwritten.
}
break;
case CELLTYPE_FORMULA:
{
// cell 1 - string, cell 2 - formula
DetachFormulaCell(aPos2, *aCell2.mpFormula);
ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
it1 = maCells.set(it1, nRow1, pNew);
ActivateNewFormulaCell(it1, nRow1, *pNew);
// Old formula cell will get overwritten below.
}
break;
default:
;
}
maCells.set(it1, nRow2, aStr);
}
break;
case CELLTYPE_EDIT:
{
EditTextObject* p;
it1 = maCells.release(it1, nRow1, p);
switch (aCell2.meType)
{
case CELLTYPE_VALUE:
it1 = maCells.set(it1, nRow1, aCell2.mfValue);
break;
case CELLTYPE_STRING:
it1 = maCells.set(it1, nRow1, *aCell2.mpString);
break;
case CELLTYPE_FORMULA:
{
DetachFormulaCell(aPos2, *aCell2.mpFormula);
ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
it1 = maCells.set(it1, nRow1, pNew);
ActivateNewFormulaCell(it1, nRow1, *pNew);
// Old formula cell will get overwritten below.
}
break;
default:
;
}
maCells.set(it1, nRow2, const_cast<EditTextObject*>(aCell1.mpEditText));
}
break;
case CELLTYPE_FORMULA:
{
// cell 1 is a formula cell and cell 2 is not.
DetachFormulaCell(aPos1, *aCell1.mpFormula);
ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow2, nTab), *aCell1.mpFormula);
switch (aCell2.meType)
{
case CELLTYPE_VALUE:
it1 = maCells.set(it1, nRow1, aCell2.mfValue);
break;
case CELLTYPE_STRING:
it1 = maCells.set(it1, nRow1, *aCell2.mpString);
break;
case CELLTYPE_EDIT:
{
it1 = maCells.set(it1, nRow1, aCell2.mpEditText);
EditTextObject* p;
it1 = maCells.release(it1, nRow2, p);
}
break;
default:
;
}
it1 = maCells.set(it1, nRow2, pNew);
ActivateNewFormulaCell(it1, nRow2, *pNew);
}
break;
default:
;
}
SwapCellTextAttrs(nRow1, nRow2);
SwapCellNotes(nRow1, nRow2);
CellStorageModified();
BroadcastCells(aRows, SC_HINT_DATACHANGED);
}
namespace {
/** /**
* Adjust references in formula cell with respect to column-wise relocation. * Adjust references in formula cell with respect to column-wise relocation.
*/ */
......
...@@ -935,40 +935,6 @@ void ScTable::SwapCol(SCCOL nCol1, SCCOL nCol2) ...@@ -935,40 +935,6 @@ void ScTable::SwapCol(SCCOL nCol1, SCCOL nCol2)
} }
} }
void ScTable::SwapRow(SCROW nRow1, SCROW nRow2)
{
SCCOL nColStart = aSortParam.nCol1;
SCCOL nColEnd = aSortParam.nCol2;
for (SCCOL nCol = nColStart; nCol <= nColEnd; nCol++)
{
aCol[nCol].SwapRow(nRow1, nRow2);
if (aSortParam.bIncludePattern)
{
const ScPatternAttr* pPat1 = GetPattern(nCol, nRow1);
const ScPatternAttr* pPat2 = GetPattern(nCol, nRow2);
if (pPat1 != pPat2)
{
pDocument->GetPool()->Put(*pPat1);
SetPattern(nCol, nRow1, *pPat2, true);
SetPattern(nCol, nRow2, *pPat1, true);
pDocument->GetPool()->Remove(*pPat1);
}
}
}
if (bGlobalKeepQuery)
{
bool bRow1Hidden = RowHidden(nRow1);
bool bRow2Hidden = RowHidden(nRow2);
SetRowHidden(nRow1, nRow1, bRow2Hidden);
SetRowHidden(nRow2, nRow2, bRow1Hidden);
bool bRow1Filtered = RowFiltered(nRow1);
bool bRow2Filtered = RowFiltered(nRow2);
SetRowFiltered(nRow1, nRow1, bRow2Filtered);
SetRowFiltered(nRow2, nRow2, bRow1Filtered);
}
}
short ScTable::Compare(SCCOLROW nIndex1, SCCOLROW nIndex2) const short ScTable::Compare(SCCOLROW nIndex1, SCCOLROW nIndex2) const
{ {
short nRes; short nRes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment