summaryrefslogtreecommitdiff
path: root/sc/inc
diff options
context:
space:
mode:
authorKevin Hunter <hunteke@earlham.edu>2011-10-31 13:23:06 -0400
committerKevin Hunter <hunteke@earlham.edu>2011-10-31 13:23:06 -0400
commit249faa5cb64a7270e852862a26b4a5e3a69a9895 (patch)
treeb0f4a3bedd589874315c08abcf4b4e4cd316c76a /sc/inc
parentcb8b7a86176a0684751354fa957ca18e6eb366d0 (diff)
Move ScPostIt storage from ScBaseCell->ScDocument
ScPostIt is the behind-the-scenes name for Notes. This move removes a usually empty pointer for each ScBaseCell to list of pointers within ScDocument. The advantage is basically a reduction in size of 8 bytes per cell. The current sizeof(ScBaseCell) is 16. Here are the highlights: * Remove mpNote from ScBaseCell, and add a std::map (data structure) to ScDocument to store notes and associate with addresses. * Remove ScPostIt accessors and mutators from ScTable, ScColumn, and ScBaseCell * Replace ScPostIt accessors and mutators in ScDocument with ones to handle move of data structure from ScBaseCell to ScDocument * Rename ScPostIt.CloneWithoutNote to ScPostIt.Clone, while completely removing ScPostIt.CloneWithNote. Any cloning of cell notes must now be handled outside external to the ScPostIt class, through ScDocument.*Note() functions. * Rename ScNoteCell to a more ScEmptyCell. I expect this can be completely removed at some point the future, if we can handle broadcasters external to the cell logic. * Add ScDocument and ScTable to ScUsedAreaIterator data structure to accomodate for new placement of ScPostIt objects in ScDocument. * Convert CELLTYPE_NOTE to CELLTYPE_EMPTY (and all ensuing uses). * Wherever possible, respect 80-columns. * New ScDocument based API (individually block-comment documented before their definitions): SC_DLLPUBLIC ScPostIt* GetNote( ScAddress const & ); SC_DLLPUBLIC ScPostIt* GetOrCreateNote( const ScAddress& rPos ); bool SetNote( ScAddress const &, ScPostIt* ); bool MoveNote( ScAddress const & from, ScAddress const & to ); bool SwapNotes( ScAddress const &, ScAddress const & ); ScPostIt* ReleaseNote( ScAddress const & ); void DeleteNote( ScAddress const & ); Of note, TakeNote has been replaced with SetNote, which returns true on success, and false on failure. TakeNote indicated failure by removing the passed note. The SetNote approach leaves room for the caller to attempt to fix the issue, but also means the caller is now on the hook to cleanup the memory. For now, the Calc-internal API is lazy and does not take advantage of this, but merely says "You failed? Oh well, delete the note." ... which is exactly what TakeNote did. This means, the lazy-programmer's idiom for SetNote use is: if ( ! pDoc->SetNote( aAddress, pNotePointer ) ) DELETEZ( pNotePointer );
Diffstat (limited to 'sc/inc')
-rw-r--r--sc/inc/cell.hxx64
-rw-r--r--sc/inc/column.hxx9
-rw-r--r--sc/inc/dociter.hxx2
-rw-r--r--sc/inc/document.hxx19
-rw-r--r--sc/inc/global.hxx2
-rw-r--r--sc/inc/table.hxx8
6 files changed, 39 insertions, 65 deletions
diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 7551ba693b15..c1d5cf2a2873 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -65,7 +65,7 @@ class ScPatternAttr;
// ============================================================================
/** Default cell clone flags: do not start listening, do not adjust 3D refs to
- old position, clone note captions of cell notes. */
+ old position. Note: Notes must be cloned separately, through ScDocument.*/
const int SC_CLONECELL_DEFAULT = 0x0000;
/** If set, cloned formula cells will start to listen to the document. */
@@ -92,27 +92,29 @@ public:
/** Base copy constructor. Does NOT clone cell note or broadcaster! */
ScBaseCell( const ScBaseCell& rCell );
- /** Returns a clone of this cell at the same position, cell note and
- broadcaster will not be cloned. */
- ScBaseCell* CloneWithoutNote( ScDocument& rDestDoc, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
+ /** Returns a clone of this cell at the same position; cell broadcaster
+ will not be cloned. */
+ ScBaseCell* Clone( ScDocument& rDestDoc,
+ int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
/** Returns a clone of this cell for the passed document position, cell
- note and broadcaster will not be cloned. */
- ScBaseCell* CloneWithoutNote( ScDocument& rDestDoc, const ScAddress& rDestPos, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
-
- /** Returns a clone of this cell, clones cell note and caption object too
- (unless SC_CLONECELL_NOCAPTION flag is set). Broadcaster will not be cloned. */
- ScBaseCell* CloneWithNote( const ScAddress& rOwnPos, ScDocument& rDestDoc, const ScAddress& rDestPos, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
+ broadcaster will not be cloned. */
+ ScBaseCell* Clone( ScDocument& rDestDoc, const ScAddress& rDestPos,
+ int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
/** Due to the fact that ScBaseCell does not have a vtable, this function
- deletes the cell by calling the appropriate d'tor of the derived class. */
+ deletes the cell by calling the appropriate d'tor of the derived class.
+ */
void Delete();
inline CellType GetCellType() const { return (CellType)eCellType; }
- /** Returns true, if the cell is empty (neither value nor formula nor cell note).
- Returns false for formula cells returning nothing, use HasEmptyData() for that. */
- bool IsBlank( bool bIgnoreNotes = false ) const;
+ /** Returns true, if the cell is empty (neither value nor formula).
+ Returns false for formula cells returning nothing; use HasEmptyData()
+ for that.
+ Does *not* check for notes; use ScDocument.GetNote() for that.
+ */
+ bool IsBlank( ) const;
// for idle-calculations
inline sal_uInt16 GetTextWidth() const { return nTextWidth; }
@@ -121,18 +123,6 @@ public:
inline sal_uInt8 GetScriptType() const { return nScriptType; }
inline void SetScriptType( sal_uInt8 nNew ) { nScriptType = nNew; }
- /** Returns true, if the cell contains a note. */
- inline bool HasNote() const { return mpNote != 0; }
- /** Returns the pointer to a cell note object (read-only). */
- inline const ScPostIt* GetNote() const { return mpNote; }
- /** Returns the pointer to a cell note object. */
- inline ScPostIt* GetNote() { return mpNote; }
- /** Takes ownership of the passed cell note object. */
- void TakeNote( ScPostIt* pNote );
- /** Returns and forgets the own cell note object. Caller takes ownership! */
- ScPostIt* ReleaseNote();
- /** Deletes the own cell note object. */
- void DeleteNote();
/** Returns true, if the cell contains a broadcaster. */
inline bool HasBroadcaster() const { return mpBroadcaster != 0; }
@@ -156,20 +146,20 @@ public:
/** Error code if ScFormulaCell, else 0. */
sal_uInt16 GetErrorCode() const;
- /** ScFormulaCell with formula::svEmptyCell result, or ScNoteCell (may have been
- created due to reference to empty cell). */
+
+ /** ScFormulaCell with formula::svEmptyCell result, or ScEmptyCell */
bool HasEmptyData() const;
bool HasValueData() const;
bool HasStringData() const;
String GetStringData() const; // only real strings
+
static bool CellEqual( const ScBaseCell* pCell1, const ScBaseCell* pCell2 );
private:
ScBaseCell& operator=( const ScBaseCell& );
private:
- ScPostIt* mpNote; /// The cell note. Cell takes ownership!
SvtBroadcaster* mpBroadcaster; /// Broadcaster for changed values. Cell takes ownership!
protected:
@@ -180,26 +170,24 @@ protected:
// ============================================================================
-class SC_DLLPUBLIC ScNoteCell : public ScBaseCell
+
+// Empty cell to take broadcaster
+class SC_DLLPUBLIC ScEmptyCell : public ScBaseCell
{
public:
#ifdef USE_MEMPOOL
- DECL_FIXEDMEMPOOL_NEWDEL( ScNoteCell )
+ DECL_FIXEDMEMPOOL_NEWDEL( ScEmptyCell )
#endif
/** Cell takes ownership of the passed broadcaster. */
- explicit ScNoteCell( SvtBroadcaster* pBC = 0 );
- /** Cell takes ownership of the passed note and broadcaster. */
- explicit ScNoteCell( ScPostIt* pNote, SvtBroadcaster* pBC = 0 );
+ explicit ScEmptyCell( SvtBroadcaster* pBC = 0 );
#if OSL_DEBUG_LEVEL > 0
- ~ScNoteCell();
+ ~ScEmptyCell();
#endif
-
-private:
- ScNoteCell( const ScNoteCell& );
};
+
class SC_DLLPUBLIC ScValueCell : public ScBaseCell
{
public:
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 7e21ba884740..b665e399aaee 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -265,15 +265,6 @@ public:
bool HasValueData( SCROW nRow ) const;
bool HasStringCells( SCROW nStartRow, SCROW nEndRow ) const;
- /** Returns the pointer to a cell note object at the passed row. */
- ScPostIt* GetNote( SCROW nRow );
- /** Sets the passed cell note object at the passed row. Takes ownership! */
- void TakeNote( SCROW nRow, ScPostIt* pNote );
- /** Returns and forgets a cell note object at the passed row. */
- ScPostIt* ReleaseNote( SCROW nRow );
- /** Deletes the note at the passed row. */
- void DeleteNote( SCROW nRow );
-
void SetDirty();
void SetDirty( const ScRange& );
void SetDirtyVar();
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index c06b9935e1b1..43e13bf3788f 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -479,6 +479,8 @@ private:
ScHorizontalCellIterator aCellIter;
ScHorizontalAttrIterator aAttrIter;
+ ScDocument * pDoc;
+ const SCTAB nTable;
SCCOL nNextCol;
SCROW nNextRow;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index a7ae1c3bb576..cbcc3b1021ec 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -273,6 +273,7 @@ private:
::std::auto_ptr<ScExternalRefManager> pExternalRefMgr;
::std::auto_ptr<ScMacroManager> mpMacroMgr;
+ std::map< const ScAddress, ScPostIt* > pNotes;
// mutable for lazy construction
mutable ::std::auto_ptr< ScFormulaParserPool >
@@ -802,16 +803,16 @@ public:
/** Returns true, if there is any data to create a selection list for rPos. */
sal_Bool HasSelectionData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
- /** Returns the pointer to a cell note object at the passed cell address. */
- SC_DLLPUBLIC ScPostIt* GetNote( const ScAddress& rPos );
- /** Sets the passed note at the cell with the passed cell address. */
- void TakeNote( const ScAddress& rPos, ScPostIt*& rpNote );
- /** Returns and forgets the cell note object at the passed cell address. */
- ScPostIt* ReleaseNote( const ScAddress& rPos );
- /** Returns the pointer to an existing or created cell note object at the passed cell address. */
+ /* Note management API
+ */
+ SC_DLLPUBLIC ScPostIt* GetNote( ScAddress const & );
SC_DLLPUBLIC ScPostIt* GetOrCreateNote( const ScAddress& rPos );
- /** Deletes the note at the passed cell address. */
- void DeleteNote( const ScAddress& rPos );
+ bool SetNote( ScAddress const &, ScPostIt* );
+ bool MoveNote( ScAddress const & from, ScAddress const & to );
+ bool SwapNotes( ScAddress const &, ScAddress const & );
+ ScPostIt* ReleaseNote( ScAddress const & );
+ void DeleteNote( ScAddress const & );
+
/** Creates the captions of all uninitialized cell notes in the specified sheet.
@param bForced True = always create all captions, false = skip when Undo is disabled. */
void InitializeNoteCaptions( SCTAB nTab, bool bForced = false );
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index e8f7da17e4f5..7d72340ff943 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -273,7 +273,7 @@ enum CellType
CELLTYPE_VALUE,
CELLTYPE_STRING,
CELLTYPE_FORMULA,
- CELLTYPE_NOTE,
+ CELLTYPE_EMPTY,
CELLTYPE_EDIT,
CELLTYPE_SYMBOLS // for load/save
#if OSL_DEBUG_LEVEL > 0
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 9cd3c573a072..2859dd008778 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -340,14 +340,6 @@ public:
void GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const;
void GetLastDataPos(SCCOL& rCol, SCROW& rRow) const;
- /** Returns the pointer to a cell note object at the passed cell address. */
- ScPostIt* GetNote( SCCOL nCol, SCROW nRow );
- /** Sets the passed cell note object at the passed cell address. Takes ownership! */
- void TakeNote( SCCOL nCol, SCROW nRow, ScPostIt*& rpNote );
- /** Returns and forgets the cell note object at the passed cell address. */
- ScPostIt* ReleaseNote( SCCOL nCol, SCROW nRow );
- /** Deletes the note at the passed cell address. */
- void DeleteNote( SCCOL nCol, SCROW nRow );
/** Creates the captions of all uninitialized cell notes.
@param bForced True = always create all captions, false = skip when Undo is disabled. */
void InitializeNoteCaptions( bool bForced = false );