[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Tue Mar 12 18:13:48 PDT 2013
sc/inc/column.hxx | 8 ++-
sc/source/core/data/column.cxx | 84 +++++++++++++++++++++-------------------
sc/source/core/data/column2.cxx | 10 ++++
sc/source/core/data/column3.cxx | 28 ++++++++++---
4 files changed, 82 insertions(+), 48 deletions(-)
New commits:
commit a120309902981d9afa5f2068ed0979d1fccb0949
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Mar 12 21:12:22 2013 -0400
Turns out I can't really use ScColumnImpl.
Because the column source files are split; not all source files had
access to the impl class definition.
Change-Id: Ic8cff0eeec3504660304be9f020c40bcd98cee85
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 39f9753..0fbd743 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -28,6 +28,9 @@
#include <set>
#include <vector>
+#include <mdds/multi_type_vector.hpp>
+#include <mdds/multi_type_vector_trait.hpp>
+
namespace editeng { class SvxBorderLine; }
class Fraction;
@@ -79,8 +82,9 @@ struct ColEntry
class ScColumn
{
-private:
- ScColumnImpl* mpImpl;
+ typedef mdds::multi_type_vector<mdds::mtv::element_block_func> TextWidthType;
+
+ TextWidthType maTextWidths;
SCCOL nCol;
SCTAB nTab;
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 1226f9b..e81456d 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -36,8 +36,6 @@
#include <cstring>
#include <map>
-#include <mdds/multi_type_vector.hpp>
-#include <mdds/multi_type_vector_trait.hpp>
using ::editeng::SvxBorderLine;
using namespace formula;
@@ -55,22 +53,13 @@ inline bool IsAmbiguousScriptNonZero( sal_uInt8 nScript )
}
-struct ScColumnImpl
-{
- typedef mdds::multi_type_vector<mdds::mtv::element_block_func> TextWidthType;
-
- TextWidthType maTextWidths;
-
- ScColumnImpl() : maTextWidths(MAXROWCOUNT) {}
-};
-
ScNeededSizeOptions::ScNeededSizeOptions() :
pPattern(NULL), bFormula(false), bSkipMerged(true), bGetFont(true), bTotalSize(false)
{
}
ScColumn::ScColumn() :
- mpImpl(new ScColumnImpl),
+ maTextWidths(MAXROWCOUNT),
nCol( 0 ),
pAttrArray( NULL ),
pDocument( NULL )
@@ -862,15 +851,23 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
be performed (but keep broadcasters and notes at old position). */
maItems[nIndex1].pCell = pCell2;
maItems[nIndex2].pCell = pCell1;
+ CellStorageModified();
SvtBroadcaster* pBC2 = pCell2->ReleaseBroadcaster();
pCell1->TakeBroadcaster( pBC2 );
pCell2->TakeBroadcaster( pBC1 );
- CellStorageModified();
+ // Swap text width values.
+ unsigned short nVal1 = maTextWidths.get<unsigned short>(nRow1);
+ unsigned short nVal2 = maTextWidths.get<unsigned short>(nRow2);
+ maTextWidths.set<unsigned short>(nRow1, nVal2);
+ maTextWidths.set<unsigned short>(nRow2, nVal1);
}
else
{
+ // Only cell 1 exists; cell 2 is empty. Move cell 1 from to row
+ // 2.
+
ScNoteCell* pDummyCell = pBC1 ? new ScNoteCell( pBC1 ) : 0;
if ( pDummyCell )
{
@@ -885,7 +882,12 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
CellStorageModified();
}
- // insert ColEntry at new position
+ // Empty text width at the cell 1 position. For now, we don't
+ // transfer the old value to the cell 2 position since Insert() is
+ // quite complicated.
+ maTextWidths.set_empty(nRow1, nRow1);
+
+ // insert ColEntry at new position.
Insert( nRow2, pCell1 );
}
@@ -988,11 +990,10 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
if ( pCell2 )
{
- // swap
+ // Both cell 1 and cell 2 exist. Swap them.
+
maItems[nIndex1].pCell = pCell2;
- CellStorageModified();
rCol.maItems[nIndex2].pCell = pCell1;
- rCol.CellStorageModified();
// update references
SCsCOL dx = rCol.nCol - nCol;
@@ -1010,12 +1011,20 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
pFmlaCell2->aPos.SetCol( nCol );
pFmlaCell2->UpdateReference(URM_MOVE, aRange, -dx, 0, 0);
}
+
+ CellStorageModified();
+ rCol.CellStorageModified();
+
+ // Swap the text widths.
+ unsigned short nVal1 = maTextWidths.get<unsigned short>(nRow);
+ unsigned short nVal2 = rCol.maTextWidths.get<unsigned short>(nRow);
+ maTextWidths.set<unsigned short>(nRow, nVal2);
+ rCol.maTextWidths.set<unsigned short>(nRow, nVal1);
}
else
{
- // remove
+ // Cell 1 exists but cell 2 isn't.
maItems.erase(maItems.begin() + nIndex1);
- CellStorageModified();
// update references
SCsCOL dx = rCol.nCol - nCol;
@@ -1026,6 +1035,12 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
pFmlaCell1->aPos.SetCol( rCol.nCol );
pFmlaCell1->UpdateReference(URM_MOVE, aRange, dx, 0, 0);
}
+
+ CellStorageModified();
+ maTextWidths.set_empty(nRow, nRow);
+ // We don't transfer the text width to the destination column because
+ // of Insert()'s complexity.
+
// insert
rCol.Insert(nRow, pCell1);
}
@@ -1174,6 +1189,7 @@ void ScColumn::InsertRow( SCROW nStartRow, SCSIZE nSize )
pDocument->SetAutoCalc( bOldAutoCalc );
CellStorageModified();
+ maTextWidths.insert_empty(nStartRow, nSize);
}
@@ -1571,6 +1587,8 @@ void ScColumn::MarkScenarioIn( ScMarkData& rDestMark ) const
void ScColumn::SwapCol(ScColumn& rCol)
{
maItems.swap(rCol.maItems);
+ maTextWidths.swap(rCol.maTextWidths);
+
CellStorageModified();
rCol.CellStorageModified();
@@ -1651,6 +1669,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
ScNoteCell* pNoteCell = new ScNoteCell; // Dummy like in DeleteRange
// must iterate backwards, because indexes of following cells become invalid
+ bool bErased = false;
for (EntryPosPairs::reverse_iterator it( aEntries.rbegin());
it != aEntries.rend(); ++it)
{
@@ -1665,11 +1684,16 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
}
// Erase the slots containing pointers to the dummy cell instance.
maItems.erase(maItems.begin() + nStartPos, maItems.begin() + nStopPos);
- CellStorageModified();
+ bErased = true;
}
pNoteCell->Delete(); // Delete the dummy cell instance.
- }
+ if (bErased)
+ {
+ CellStorageModified();
+ maTextWidths.set_empty(nStartRow, nEndRow);
+ }
+ }
}
bool ScColumn::UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
@@ -2294,22 +2318,4 @@ bool ScColumn::SearchStyleRange(
return pAttrArray->SearchStyleRange( rRow, rEndRow, pSearchStyle, bUp, NULL );
}
-sal_uInt16 ScColumn::GetTextWidth(SCROW nRow) const
-{
- switch (mpImpl->maTextWidths.get_type(nRow))
- {
- case mdds::mtv::element_type_ushort:
- return mpImpl->maTextWidths.get<unsigned short>(nRow);
- default:
- ;
- }
- return TEXTWIDTH_DIRTY;
-}
-
-void ScColumn::SetTextWidth(SCROW nRow, sal_uInt16 nWidth)
-{
- // We only use unsigned short type in this container.
- mpImpl->maTextWidths.set(nRow, static_cast<unsigned short>(nWidth));
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 91ddbb1..c586b34 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1386,6 +1386,16 @@ void ScColumn::CellStorageModified()
{
}
+unsigned short ScColumn::GetTextWidth(SCROW nRow) const
+{
+ return maTextWidths.get<unsigned short>(nRow);
+}
+
+void ScColumn::SetTextWidth(SCROW nRow, unsigned short nWidth)
+{
+ maTextWidths.set(nRow, nWidth);
+}
+
void ScColumn::FindDataAreaPos(SCROW& rRow, bool bDown) const
{
// check if we are in a data area
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index c43320a..5054a81 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -58,13 +58,13 @@ using namespace formula;
void ScColumn::Insert( SCROW nRow, ScBaseCell* pNewCell )
{
- sal_Bool bIsAppended = false;
+ bool bIsAppended = false;
if ( !maItems.empty() )
{
if (maItems.back().nRow < nRow)
{
- Append(nRow, pNewCell );
- bIsAppended = sal_True;
+ Append(nRow, pNewCell);
+ bIsAppended = true;
}
}
if ( !bIsAppended )
@@ -81,7 +81,7 @@ void ScColumn::Insert( SCROW nRow, ScBaseCell* pNewCell )
if ( pOldCell->GetCellType() == CELLTYPE_FORMULA && !pDocument->IsClipOrUndo() )
{
pOldCell->EndListeningTo( pDocument );
- // If in EndListening NoteCell is destroied in same Col
+ // If in EndListening NoteCell is destroyed in same Col
if ( nIndex >= maItems.size() || maItems[nIndex].nRow != nRow )
Search(nRow, nIndex);
}
@@ -96,6 +96,8 @@ void ScColumn::Insert( SCROW nRow, ScBaseCell* pNewCell )
maItems[nIndex].nRow = nRow;
CellStorageModified();
}
+
+ maTextWidths.set<unsigned short>(nRow, TEXTWIDTH_DIRTY);
}
// When we insert from the Clipboard we still have wrong (old) References!
// First they are rewired in CopyBlockFromClip via UpdateReference and the
@@ -140,6 +142,7 @@ void ScColumn::Append( SCROW nRow, ScBaseCell* pCell )
maItems.back().nRow = nRow;
CellStorageModified();
+ maTextWidths.set<unsigned short>(nRow, TEXTWIDTH_DIRTY);
}
@@ -152,6 +155,7 @@ void ScColumn::Delete( SCROW nRow )
ScBaseCell* pCell = maItems[nIndex].pCell;
ScNoteCell* pNoteCell = new ScNoteCell;
maItems[nIndex].pCell = pNoteCell; // Dummy for Interpret
+ CellStorageModified();
pDocument->Broadcast( ScHint( SC_HINT_DYING,
ScAddress( nCol, nRow, nTab ), pCell ) );
if ( SvtBroadcaster* pBC = pCell->ReleaseBroadcaster() )
@@ -162,12 +166,13 @@ void ScColumn::Delete( SCROW nRow )
{
pNoteCell->Delete();
maItems.erase( maItems.begin() + nIndex);
+ CellStorageModified();
// Should we free memory here (delta)? It'll be slower!
}
pCell->EndListeningTo( pDocument );
pCell->Delete();
- CellStorageModified();
+ maTextWidths.set_empty(nRow, nRow);
}
}
@@ -175,16 +180,18 @@ void ScColumn::Delete( SCROW nRow )
void ScColumn::DeleteAtIndex( SCSIZE nIndex )
{
ScBaseCell* pCell = maItems[nIndex].pCell;
+ SCROW nRow = maItems[nIndex].nRow;
ScNoteCell* pNoteCell = new ScNoteCell;
maItems[nIndex].pCell = pNoteCell; // Dummy for Interpret
- pDocument->Broadcast( ScHint( SC_HINT_DYING,
- ScAddress( nCol, maItems[nIndex].nRow, nTab ), pCell ) );
+ pDocument->Broadcast(
+ ScHint(SC_HINT_DYING, ScAddress(nCol, nRow, nTab), pCell));
pNoteCell->Delete();
maItems.erase(maItems.begin() + nIndex);
pCell->EndListeningTo( pDocument );
pCell->Delete();
CellStorageModified();
+ maTextWidths.set_empty(nRow, nRow);
}
@@ -195,6 +202,7 @@ void ScColumn::FreeAll()
maItems.clear();
CellStorageModified();
+ maTextWidths.clear();
}
@@ -306,6 +314,9 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
ScHint aHint( SC_HINT_DYING, ScAddress( nCol, 0, nTab ), 0 );
+ SCROW nStartRow = maItems[nStartIndex].nRow;
+ SCROW nEndRow = maItems[nEndIndex].nRow;
+
// cache all formula cells, they will be deleted at end of this function
typedef ::std::vector< ScFormulaCell* > FormulaCellVector;
FormulaCellVector aDelCells;
@@ -491,6 +502,7 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
nShift += maItems.size() - nStartSegment;
maItems.erase(maItems.end() - nShift, maItems.end());
CellStorageModified();
+ maTextWidths.set_empty(nStartRow, nEndRow);
}
// *** delete all formula cells ***
@@ -1418,6 +1430,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
pOldCell->Delete();
maItems[i].pCell = pNewCell; // Replace
CellStorageModified();
+ SetTextWidth(nRow, TEXTWIDTH_DIRTY);
if ( pNewCell->GetCellType() == CELLTYPE_FORMULA )
{
@@ -1642,6 +1655,7 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow )
delete pFormula;
CellStorageModified();
+ SetTextWidth(maItems[nIndex].nRow, TEXTWIDTH_DIRTY);
}
++nIndex;
}
More information about the Libreoffice-commits
mailing list