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

Move some of the code to local functions to make it easier to read.

Change-Id: Ib7ca5c04ec057dbce958d580ad3b7d52d19ed21f
üst 7b6d3e8f
...@@ -303,6 +303,53 @@ void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize ) ...@@ -303,6 +303,53 @@ void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize )
pDocument->SetAutoCalc( bOldAutoCalc ); pDocument->SetAutoCalc( bOldAutoCalc );
} }
namespace {
bool isDate(const ScDocument& rDoc, const ScColumn& rCol, SCROW nRow)
{
sal_uLong nIndex = (sal_uLong)((SfxUInt32Item*)rCol.GetAttr(nRow, ATTR_VALUE_FORMAT))->GetValue();
short nType = rDoc.GetFormatTable()->GetType(nIndex);
return (nType == NUMBERFORMAT_DATE) || (nType == NUMBERFORMAT_TIME) || (nType == NUMBERFORMAT_DATETIME);
}
bool checkDeleteCellByFlag(
CellType eCellType, sal_uInt16 nDelFlag, const ScDocument& rDoc, const ScColumn& rCol, const ColEntry& rEntry)
{
bool bDelete = false;
switch (eCellType)
{
case CELLTYPE_VALUE:
{
sal_uInt16 nValFlags = nDelFlag & (IDF_DATETIME|IDF_VALUE);
// delete values and dates?
bDelete = nValFlags == (IDF_DATETIME|IDF_VALUE);
// if not, decide according to cell number format
if (!bDelete && (nValFlags != 0))
{
bool bIsDate = isDate(rDoc, rCol, rEntry.nRow);
bDelete = nValFlags == (bIsDate ? IDF_DATETIME : IDF_VALUE);
}
}
break;
case CELLTYPE_STRING:
case CELLTYPE_EDIT:
bDelete = (nDelFlag & IDF_STRING) != 0;
break;
case CELLTYPE_FORMULA:
bDelete = (nDelFlag & IDF_FORMULA) != 0;
break;
case CELLTYPE_NOTE:
// do note delete note cell with broadcaster
bDelete = !rEntry.pCell->GetBroadcaster();
break;
default:; // added to avoid warnings
}
return bDelete;
}
}
void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag ) void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag )
{ {
...@@ -323,7 +370,7 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe ...@@ -323,7 +370,7 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
typedef mdds::flat_segment_tree<SCSIZE, bool> RemovedSegments_t; typedef mdds::flat_segment_tree<SCSIZE, bool> RemovedSegments_t;
RemovedSegments_t aRemovedSegments(nStartIndex, maItems.size(), false); RemovedSegments_t aRemovedSegments(nStartIndex, maItems.size(), false);
SCSIZE nFirst(nStartIndex); SCSIZE nFirst = nStartIndex;
// dummy replacement for old cells, to prevent that interpreter uses old cell // dummy replacement for old cells, to prevent that interpreter uses old cell
boost::scoped_ptr<ScNoteCell> pDummyCell(new ScNoteCell); boost::scoped_ptr<ScNoteCell> pDummyCell(new ScNoteCell);
...@@ -357,57 +404,27 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe ...@@ -357,57 +404,27 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
ScBaseCell* pOldCell = maItems[nIdx].pCell; ScBaseCell* pOldCell = maItems[nIdx].pCell;
CellType eCellType = pOldCell->GetCellType(); CellType eCellType = pOldCell->GetCellType();
if ((nDelFlag & IDF_CONTENTS) == IDF_CONTENTS) if ((nDelFlag & IDF_CONTENTS) == IDF_CONTENTS)
// All cell types to be deleted.
bDelete = true; bDelete = true;
else else
{ {
// decide whether to delete the cell object according to passed // Decide whether to delete the cell object according to passed
// flags // flags.
switch ( eCellType ) bDelete = checkDeleteCellByFlag(eCellType, nDelFlag, *pDocument, *this, maItems[nIdx]);
{
case CELLTYPE_VALUE:
{
sal_uInt16 nValFlags = nDelFlag & (IDF_DATETIME|IDF_VALUE);
// delete values and dates?
bDelete = nValFlags == (IDF_DATETIME|IDF_VALUE);
// if not, decide according to cell number format
if (!bDelete && (nValFlags != 0))
{
sal_uLong nIndex = (sal_uLong)((SfxUInt32Item*)GetAttr(
maItems[nIdx].nRow, ATTR_VALUE_FORMAT))->GetValue();
short nType = pDocument->GetFormatTable()->GetType(nIndex);
bool bIsDate = (nType == NUMBERFORMAT_DATE) ||
(nType == NUMBERFORMAT_TIME) || (nType == NUMBERFORMAT_DATETIME);
bDelete = nValFlags == (bIsDate ? IDF_DATETIME : IDF_VALUE);
}
}
break;
case CELLTYPE_STRING:
case CELLTYPE_EDIT:
bDelete = (nDelFlag & IDF_STRING) != 0;
break;
case CELLTYPE_FORMULA:
bDelete = (nDelFlag & IDF_FORMULA) != 0;
break;
case CELLTYPE_NOTE:
// do note delete note cell with broadcaster
bDelete = !pOldCell->GetBroadcaster();
break;
default:; // added to avoid warnings
}
} }
if (bDelete) if (bDelete)
{ {
// try to create a replacement note cell, if note or broadcaster exists // Try to create a replacement "note" cell if broadcaster exists.
ScNoteCell* pNoteCell = NULL; ScNoteCell* pNoteCell = NULL;
SvtBroadcaster* pBC = pOldCell->GetBroadcaster(); SvtBroadcaster* pBC = pOldCell->GetBroadcaster();
if (pBC && pBC->HasListeners()) if (pBC && pBC->HasListeners())
{ {
pNoteCell = new ScNoteCell( pBC ); // NOTE: the broadcaster here is transferred and released only
// NOTE: the broadcaster here is transferred and released // if it has listeners! If it does not, it will simply be
// only if it has listeners! If it does not, it will simply // deleted when the cell is deleted and no replacement cell is
// be deleted when the cell is deleted and no replacement // created.
// cell is created. pNoteCell = new ScNoteCell(pBC);
pOldCell->ReleaseBroadcaster(); pOldCell->ReleaseBroadcaster();
} }
...@@ -423,16 +440,16 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe ...@@ -423,16 +440,16 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
else else
maItems[nIdx].pCell = pDummyCell.get(); maItems[nIdx].pCell = pDummyCell.get();
// cache formula cells (will be deleted later), delete cell of other type
if (eCellType == CELLTYPE_FORMULA) if (eCellType == CELLTYPE_FORMULA)
{ {
aDelCells.push_back( static_cast< ScFormulaCell* >( pOldCell ) ); // Cache formula cells (will be deleted later), delete cell of other type.
aDelCells.push_back(static_cast<ScFormulaCell*>(pOldCell));
} }
else else
{ {
aHint.GetAddress().SetRow( nOldRow ); aHint.GetAddress().SetRow(nOldRow);
aHint.SetCell( pNoteCell ? pNoteCell : pOldCell ); aHint.SetCell(pNoteCell ? pNoteCell : pOldCell);
pDocument->Broadcast( aHint ); pDocument->Broadcast(aHint);
if (pNoteCell != pOldCell) if (pNoteCell != pOldCell)
{ {
pOldCell->Delete(); pOldCell->Delete();
......
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