summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-02-12 11:23:26 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-02-12 12:33:00 -0500
commit0585322e70d3c0f1d26d6bd9c04a388a1ff55abf (patch)
treebd206df6f4f80ab4ea461137deccb6887dc72777 /sc
parent117b3a13b82aaac0977fd17ee5b7b63204e659f4 (diff)
Go through all ScEditCell instantiations and fix memory leaks.
Changed the signature of the constructor (one that clones the text object) to take a reference instead of a pointer, to smoke out the callers that use this constructor. Went through all its callers and made changes to either 1) pass ownership to the cell instance (if the text object uses the SfxItemPool instance returned from ScDocument::GetEditPool()), or 2) pass as const reference to make it clear that the instance will get cloned. Change-Id: I669e066d4739536bf8d3b356186503dcdfa303b0
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/cell.hxx16
-rw-r--r--sc/source/core/data/cell2.cxx12
-rw-r--r--sc/source/core/data/documen8.cxx21
-rw-r--r--sc/source/core/data/table4.cxx7
-rw-r--r--sc/source/filter/excel/xicontent.cxx6
-rw-r--r--sc/source/filter/excel/xihelper.cxx4
-rw-r--r--sc/source/filter/oox/richstring.cxx4
-rw-r--r--sc/source/filter/oox/worksheethelper.cxx4
-rw-r--r--sc/source/filter/rtf/eeimpars.cxx11
-rw-r--r--sc/source/filter/xml/XMLTrackedChangesContext.cxx3
-rw-r--r--sc/source/ui/docshell/docfunc.cxx6
-rw-r--r--sc/source/ui/inc/viewfunc.hxx7
-rw-r--r--sc/source/ui/undo/undocell.cxx9
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx7
-rw-r--r--sc/source/ui/view/cellsh3.cxx2
-rw-r--r--sc/source/ui/view/viewfun2.cxx5
-rw-r--r--sc/source/ui/view/viewfun4.cxx20
-rw-r--r--sc/source/ui/view/viewfunc.cxx11
18 files changed, 93 insertions, 62 deletions
diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index a66d7795fd0d..a6d1480923e2 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -244,8 +244,20 @@ public:
*/
ScEditCell(EditTextObject* pObject, ScDocument* pDocP);
- ScEditCell( const EditTextObject* pObject, ScDocument*,
- const SfxItemPool* pFromPool /* = NULL */ );
+ /**
+ * Constructor. The caller is responsible for deleting the text object
+ * instance passed on to this constructor, since it creates a clone and
+ * stores it instead of the original.
+ *
+ * @param rObject text object to clone from.
+ * @param pDocP pointer to the document instance.
+ * @param pFromPool pointer to SfxItemPool instance that the new text
+ * object that is to be stored in the cell instance
+ * should use. If it's NULL, it uses the default pool
+ * for edit cells from the document instance (one
+ * returned from GetEditPool()).
+ */
+ ScEditCell(const EditTextObject& rObject, ScDocument* pDocP, const SfxItemPool* pFromPool);
ScEditCell(const ScEditCell& rCell, ScDocument& rDoc, const ScAddress& rDestPos);
// for line breaks
ScEditCell( const rtl::OUString& rString, ScDocument* );
diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx
index 004b553b7078..849fd698fdf1 100644
--- a/sc/source/core/data/cell2.cxx
+++ b/sc/source/core/data/cell2.cxx
@@ -56,13 +56,13 @@ ScEditCell::ScEditCell(EditTextObject* pObject, ScDocument* pDocP) :
ScBaseCell(CELLTYPE_EDIT),
pData(pObject), pString(NULL), pDoc(pDocP) {}
-ScEditCell::ScEditCell( const EditTextObject* pObject, ScDocument* pDocP,
- const SfxItemPool* pFromPool ) :
- ScBaseCell( CELLTYPE_EDIT ),
- pString( NULL ),
- pDoc( pDocP )
+ScEditCell::ScEditCell(
+ const EditTextObject& rObject, ScDocument* pDocP, const SfxItemPool* pFromPool) :
+ ScBaseCell(CELLTYPE_EDIT),
+ pString(NULL),
+ pDoc(pDocP)
{
- SetTextObject( pObject, pFromPool );
+ SetTextObject(&rObject, pFromPool);
}
ScEditCell::ScEditCell(const ScEditCell& rCell, ScDocument& rDoc, const ScAddress& rDestPos) :
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 134fdf31d9c0..2c9d62888298 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -86,6 +86,8 @@
#include "docuno.hxx"
#include "scresid.hxx"
+#include <memory>
+
#define GET_SCALEVALUE(set,id) ((const SfxUInt16Item&)(set.Get( id ))).GetValue()
// states for online spelling in the visible range (0 is set initially)
@@ -739,14 +741,15 @@ bool ScDocument::OnlineSpellInRange( const ScRange& rSpellRange, ScAddress& rSpe
if ( bNeedEdit )
{
- EditTextObject* pNewData = pEngine->CreateTextObject();
+ SAL_WNODEPRECATED_DECLARATIONS_PUSH
+ std::auto_ptr<EditTextObject> pNewData(pEngine->CreateTextObject());
+ SAL_WNODEPRECATED_DECLARATIONS_POP
if ( eType == CELLTYPE_EDIT )
- ((ScEditCell*)pCell)->SetData( pNewData,
- pEngine->GetEditTextObjectPool() );
+ // SetData will create a clone of pNewData and stores the clone.
+ static_cast<ScEditCell*>(pCell)->SetData(pNewData.get(), pEngine->GetEditTextObjectPool());
else
- PutCell( nCol, nRow, nTab, new ScEditCell( pNewData,
- this, pEngine->GetEditTextObjectPool() ) );
- delete pNewData;
+ // The cell will take ownership of pNewData.
+ PutCell(nCol, nRow, nTab, new ScEditCell(pNewData.release(), this));
}
else // einfacher String
PutCell( nCol, nRow, nTab, new ScStringCell( pEngine->GetText() ) );
@@ -1582,10 +1585,8 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
SfxItemSet* pEmpty = new SfxItemSet( pEngine->GetEmptyItemSet() );
pEngine->SetDefaults( pEmpty, true );
- EditTextObject* pNewData = pEngine->CreateTextObject();
- PutCell( nCol, nRow, nTab,
- new ScEditCell( pNewData, this, pEngine->GetEditTextObjectPool() ) );
- delete pNewData;
+ // The cell will take ownership of the text object instance.
+ PutCell(nCol, nRow, nTab, new ScEditCell(pEngine->CreateTextObject(), this));
}
else
{
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 38adeb830698..674f212862c6 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -61,6 +61,7 @@
#include "conditio.hxx"
#include <math.h>
+#include <boost/scoped_ptr.hpp>
// STATIC DATA -----------------------------------------------------------
@@ -158,6 +159,8 @@ static ScBaseCell * lcl_getSuffixCell( ScDocument* pDocument, sal_Int32 nValue,
return new ScStringCell( aValue += aOrdinalSuffix);
EditEngine aEngine( pDocument->GetEnginePool() );
+ aEngine.SetEditTextObjectPool(pDocument->GetEditPool());
+
SfxItemSet aAttr = aEngine.GetEmptyItemSet();
aAttr.Put( SvxEscapementItem( SVX_ESCAPEMENT_SUPERSCRIPT, EE_CHAR_ESCAPEMENT));
aEngine.SetText( aValue );
@@ -165,7 +168,9 @@ static ScBaseCell * lcl_getSuffixCell( ScDocument* pDocument, sal_Int32 nValue,
aValue.Len() + aOrdinalSuffix.Len()));
aEngine.QuickSetAttribs( aAttr, ESelection( 0, aValue.Len(), 0, aValue.Len() +
aOrdinalSuffix.Len()));
- return new ScEditCell( aEngine.CreateTextObject(), pDocument, NULL );
+
+ // Text object instance will be owned by the cell.
+ return new ScEditCell(aEngine.CreateTextObject(), pDocument);
}
void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx
index b4606ab51714..a455d89c462e 100644
--- a/sc/source/filter/excel/xicontent.cxx
+++ b/sc/source/filter/excel/xicontent.cxx
@@ -195,11 +195,9 @@ void lclInsertUrl( const XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SC
rEE.QuickSetAttribs( aItemSet, ESelection( 0, 0, 0xFFFF, 0 ) );
}
}
- SAL_WNODEPRECATED_DECLARATIONS_PUSH
- ::std::auto_ptr< EditTextObject > xTextObj( rEE.CreateTextObject() );
- SAL_WNODEPRECATED_DECLARATIONS_POP
- ScEditCell* pCell = new ScEditCell( xTextObj.get(), &rDoc, rEE.GetEditTextObjectPool() );
+ // The cell will own the text object instance.
+ ScEditCell* pCell = new ScEditCell(rEE.CreateTextObject(), &rDoc);
rDoc.PutCell( aScPos, pCell );
}
break;
diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx
index ad5d1f8c1f12..ef840f9a476b 100644
--- a/sc/source/filter/excel/xihelper.cxx
+++ b/sc/source/filter/excel/xihelper.cxx
@@ -231,8 +231,8 @@ ScBaseCell* XclImpStringHelper::CreateCell(
ScDocument& rDoc = rRoot.GetDoc();
if( pTextObj.get() )
- // ScEditCell creates own copy of text object
- pCell = new ScEditCell( pTextObj.get(), &rDoc, rRoot.GetEditEngine().GetEditTextObjectPool() );
+ // ScEditCell will own the text object instance.
+ pCell = new ScEditCell(pTextObj.release(), &rDoc);
else
pCell = ScBaseCell::CreateTextCell( rString.GetText(), &rDoc );
}
diff --git a/sc/source/filter/oox/richstring.cxx b/sc/source/filter/oox/richstring.cxx
index acbaea6cc13f..1a746d6d2831 100644
--- a/sc/source/filter/oox/richstring.cxx
+++ b/sc/source/filter/oox/richstring.cxx
@@ -417,7 +417,6 @@ void RichString::convert( const Reference< XText >& rxText, bool bReplaceOld, co
::EditTextObject* RichString::convert( ScEditEngineDefaulter& rEE, const Font* pFirstPortionFont ) const
{
- EditTextObject* pTextObj = NULL;
ESelection aSelection;
OUString sString;
@@ -432,8 +431,7 @@ void RichString::convert( const Reference< XText >& rxText, bool bReplaceOld, co
pFirstPortionFont = 0;
}
- pTextObj = rEE.CreateTextObject();
- return pTextObj;
+ return rEE.CreateTextObject();
}
// private --------------------------------------------------------------------
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index b993e340bc75..fe072cb54996 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -1552,8 +1552,8 @@ void WorksheetHelper::putRichString( const CellAddress& rAddress, const RichStri
ScDocument& rDoc = getScDocument();
ScEditEngineDefaulter& rEE = getEditEngine();
- ::std::auto_ptr< ::EditTextObject > pTextObj( rString.convert( rEE, pFirstPortionFont ) );
- ScBaseCell* pNewCell = new ScEditCell( pTextObj.get(), &rDoc, rEE.GetEditTextObjectPool() );
+ // The cell will own the text object instance returned from convert().
+ ScBaseCell* pNewCell = new ScEditCell(rString.convert(rEE, pFirstPortionFont), &rDoc);
ScAddress aAddress;
ScUnoConversion::FillScAddress( aAddress, rAddress );
rDoc.PutCell( aAddress, pNewCell );
diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index 95dba198c1ec..522ab3b0af91 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -56,6 +56,8 @@
#include "globstr.hrc"
+#include <boost/scoped_ptr.hpp>
+
// in fuins1.cxx
extern void ScLimitSizeOnDrawPage( Size& rSize, Point& rPos, const Size& rPage );
@@ -68,7 +70,7 @@ ScEEImport::ScEEImport( ScDocument* pDocP, const ScRange& rRange ) :
{
const ScPatternAttr* pPattern = mpDoc->GetPattern(
maRange.aStart.Col(), maRange.aStart.Row(), maRange.aStart.Tab() );
- mpEngine = new ScTabEditEngine( *pPattern, mpDoc->GetEditPool() );
+ mpEngine = new ScTabEditEngine(*pPattern, mpDoc->GetEditPool(), mpDoc->GetEditPool());
mpEngine->SetUpdateMode( false );
mpEngine->EnableUndo( false );
}
@@ -394,10 +396,9 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu
}
else
{
- EditTextObject* pObject = mpEngine->CreateTextObject( pE->aSel );
- mpDoc->PutCell( nCol, nRow, nTab, new ScEditCell( pObject,
- mpDoc, mpEngine->GetEditTextObjectPool() ) );
- delete pObject;
+ // The cell will own the text object instance.
+ mpDoc->PutCell(
+ nCol, nRow, nTab, new ScEditCell(mpEngine->CreateTextObject(pE->aSel), mpDoc));
}
if ( pE->maImageList.size() )
bHasGraphics |= GraphicSize( nCol, nRow, nTab, pE );
diff --git a/sc/source/filter/xml/XMLTrackedChangesContext.cxx b/sc/source/filter/xml/XMLTrackedChangesContext.cxx
index 9673851df303..64a3dc41c69a 100644
--- a/sc/source/filter/xml/XMLTrackedChangesContext.cxx
+++ b/sc/source/filter/xml/XMLTrackedChangesContext.cxx
@@ -1280,7 +1280,8 @@ void ScXMLChangeCellContext::EndElement()
}
}
if (GetScImport().GetDocument())
- rOldCell = new ScEditCell(pEditTextObj->CreateTextObject(), GetScImport().GetDocument(), GetScImport().GetDocument()->GetEditPool());
+ // The cell will own the text object instance.
+ rOldCell = new ScEditCell(pEditTextObj->CreateTextObject(), GetScImport().GetDocument());
GetScImport().GetTextImport()->ResetCursor();
pEditTextObj->release();
}
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 4115377c0d48..2c8e5e5bfbdf 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -944,11 +944,11 @@ sal_Bool ScDocFunc::PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngi
}
}
- EditTextObject* pNewData = rEngine.CreateTextObject();
+ // A copy of pNewData will be stored in the cell.
+ boost::scoped_ptr<EditTextObject> pNewData(rEngine.CreateTextObject());
bRet = PutCell( rPos,
- new ScEditCell( pNewData, pDoc, rEngine.GetEditTextObjectPool() ),
+ new ScEditCell(*pNewData, pDoc, rEngine.GetEditTextObjectPool()),
bApi );
- delete pNewData;
// Set the paragraph attributes back to the EditEngine.
if (!aRememberItems.empty())
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 057a74cf3a94..2ef5b44c02b4 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -81,10 +81,15 @@ public:
void EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString,
const EditTextObject* pData = NULL );
void EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
- const EditTextObject* pData, bool bTestSimple = false );
+ const EditTextObject& rData, bool bTestSimple = false );
void EnterValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rValue );
void EnterMatrix( const String& rString, ::formula::FormulaGrammar::Grammar eGram );
+
+ /**
+ * @param pData The caller must manage the life cycle of the object this
+ * pointer points to. NULL is allowed.
+ */
void EnterBlock( const String& rString, const EditTextObject* pData );
void EnterDataAtCursor( const String& rString ); //! Not used?
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index a96d1925ee56..b1f7c98e37e4 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -296,7 +296,8 @@ void ScUndoEnterData::Redo()
for (sal_uInt16 i=0; i<nCount; i++)
{
if (pNewEditData)
- pDoc->PutCell( nCol, nRow, pTabs[i], new ScEditCell( pNewEditData,
+ // A clone of pNewEditData will be stored in ScEditCell.
+ pDoc->PutCell( nCol, nRow, pTabs[i], new ScEditCell(*pNewEditData,
pDoc, NULL ) );
else
pDoc->SetString( nCol, nRow, pTabs[i], aNewString );
@@ -661,7 +662,8 @@ ScUndoThesaurus::ScUndoThesaurus( ScDocShell* pNewDocShell,
ScBaseCell* pOldCell;
if ( pUndoTObject )
- pOldCell = new ScEditCell( pUndoTObject, pDocShell->GetDocument(), NULL );
+ // A clone of pUndoTObject will be stored in the cell.
+ pOldCell = new ScEditCell(*pUndoTObject, pDocShell->GetDocument(), NULL);
else
pOldCell = new ScStringCell( aUndoStr );
SetChangeTrack( pOldCell );
@@ -713,7 +715,8 @@ void ScUndoThesaurus::DoChange( sal_Bool bUndo, const String& rStr,
{
if (pCell->GetCellType() == CELLTYPE_EDIT )
{
- ScEditCell* pNewCell = new ScEditCell( pTObj, pDoc, NULL );
+ // A copy of pTObj will be stored in the cell.
+ ScEditCell* pNewCell = new ScEditCell(*pTObj, pDoc, NULL);
pDoc->PutCell( nCol, nRow, nTab, pNewCell );
if ( !bUndo )
SetChangeTrack( pCell );
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 4bd38550455c..669b3b6ba594 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -120,6 +120,7 @@
#include "editeng/escpitem.hxx"
#include <list>
+#include <boost/scoped_ptr.hpp>
using namespace com::sun::star;
@@ -2341,6 +2342,8 @@ void ScCellRangesBase::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pE
ScBaseCell *pCell = pDoc->GetCell( aAddr );
String aStr( pCell->GetStringData() );
EditEngine aEngine( pDoc->GetEnginePool() );
+ aEngine.SetEditTextObjectPool(pDoc->GetEditPool());
+
/* EE_CHAR_ESCAPEMENT seems to be set on the cell _only_ when
* there are no other attribs for the cell.
* So, it is safe to overwrite the complete attribute set.
@@ -2354,7 +2357,9 @@ void ScCellRangesBase::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pE
else // Superscript
aAttr.Put( SvxEscapementItem( SVX_ESCAPEMENT_SUPERSCRIPT, EE_CHAR_ESCAPEMENT ) );
aEngine.QuickSetAttribs( aAttr, ESelection( 0, 0, 0, aStr.Len()));
- pDoc->PutCell( (aRanges[ 0 ])->aStart, new ScEditCell( aEngine.CreateTextObject(), pDoc, NULL ) );
+
+ // The cell will own the text object instance.
+ pDoc->PutCell(aRanges[0]->aStart, new ScEditCell(aEngine.CreateTextObject(), pDoc));
}
}
}
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 88a41dd9997c..e916bda38783 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -245,7 +245,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
}
else
{
- pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), pData );
+ pTabViewShell->EnterData(aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), *pData);
}
}
else
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 2dd4871d217f..64cea573b9cd 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -772,7 +772,7 @@ void ScViewFunc::EnterBlock( const String& rString, const EditTextObject* pData
// insert into single cell
if ( pData )
- EnterData( nCol, nRow, nTab, pData );
+ EnterData(nCol, nRow, nTab, *pData);
else
EnterData( nCol, nRow, nTab, rString );
return;
@@ -811,7 +811,8 @@ void ScViewFunc::EnterBlock( const String& rString, const EditTextObject* pData
pInsDoc->PutCell( nCol, nRow, nTab, pFCell );
}
else if ( pData )
- pInsDoc->PutCell( nCol, nRow, nTab, new ScEditCell( pData, pDoc, NULL ) );
+ // A copy of pData will be stored.
+ pInsDoc->PutCell(nCol, nRow, nTab, new ScEditCell(*pData, pDoc, NULL));
else
pInsDoc->SetString( nCol, nRow, nTab, aNewStr );
diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx
index 5698878afdc3..695b2ab7669d 100644
--- a/sc/source/ui/view/viewfun4.cxx
+++ b/sc/source/ui/view/viewfun4.cxx
@@ -65,6 +65,8 @@
#include "reffind.hxx"
#include "compiler.hxx"
+#include <boost/scoped_ptr.hpp>
+
using namespace com::sun::star;
// STATIC DATA -----------------------------------------------------------
@@ -127,9 +129,8 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
pDoc->EnableUndo( false );
for( sal_uInt16 n = 0; n < nParCnt; n++ )
{
- EditTextObject* pObject = pEngine->CreateTextObject( n );
- EnterData( nStartCol, nRow, nTab, pObject, true );
- delete pObject;
+ boost::scoped_ptr<EditTextObject> pObject(pEngine->CreateTextObject(n));
+ EnterData(nStartCol, nRow, nTab, *pObject, true);
if( ++nRow > MAXROW )
break;
}
@@ -413,10 +414,10 @@ void ScViewFunc::DoThesaurus( sal_Bool bRecord )
EditTextObject* pNewTObj = NULL;
if (pCell && pTObject)
{
- pNewTObj = pThesaurusEngine->CreateTextObject();
- pCell = new ScEditCell( pNewTObj, pDoc,
- pThesaurusEngine->GetEditTextObjectPool() );
- pDoc->PutCell( nCol, nRow, nTab, pCell );
+ // The cell will own the text object instance.
+ pDoc->PutCell(
+ nCol, nRow, nTab,
+ new ScEditCell(pThesaurusEngine->CreateTextObject(), pDoc));
}
else
{
@@ -764,9 +765,8 @@ void ScViewFunc::InsertBookmark( const String& rDescription, const String& rURL,
aField.SetTargetFrame(*pTarget);
aEngine.QuickInsertField( SvxFieldItem( aField, EE_FEATURE_FIELD ), aInsSel );
- EditTextObject* pData = aEngine.CreateTextObject();
- EnterData( nPosX, nPosY, nTab, pData );
- delete pData;
+ boost::scoped_ptr<EditTextObject> pData(aEngine.CreateTextObject());
+ EnterData(nPosX, nPosY, nTab, *pData);
}
sal_Bool ScViewFunc::HasBookmarkAtCursor( SvxHyperlinkItem* pContent )
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 2ff86f12178f..02e73667e860 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -504,7 +504,8 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
{
ScBaseCell *pCell;
if ( pData )
- pCell = new ScEditCell( pData, pDoc, NULL );
+ // A clone of pData will be stored in the cell.
+ pCell = new ScEditCell(*pData, pDoc, NULL);
else
pCell = new ScStringCell( aFormula );
rFunc.PutCell( aPos, pCell, sal_False );
@@ -611,7 +612,7 @@ void ScViewFunc::EnterValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& r
}
void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
- const EditTextObject* pData, bool bTestSimple )
+ const EditTextObject& rData, bool bTestSimple )
{
ScDocShell* pDocSh = GetViewData()->GetDocShell();
ScMarkData& rMark = GetViewData()->GetMarkData();
@@ -634,7 +635,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
const ScPatternAttr* pOldPattern = pDoc->GetPattern( nCol, nRow, nTab );
ScTabEditEngine aEngine( *pOldPattern, pDoc->GetEnginePool() );
- aEngine.SetText(*pData);
+ aEngine.SetText(rData);
if (bTestSimple) // test, if simple string without attribute
{
@@ -690,7 +691,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
OSL_ENSURE( nPos==nSelCount, "nPos!=nSelCount" );
- pUndoData = pData->Clone();
+ pUndoData = rData.Clone();
}
//
@@ -711,7 +712,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
{
ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
for (; itr != itrEnd; ++itr)
- pDoc->PutCell( nCol, nRow, *itr, new ScEditCell( pData, pDoc, NULL ) );
+ pDoc->PutCell(nCol, nRow, *itr, new ScEditCell(rData, pDoc, NULL));
if ( bRecord )
{ // because of ChangeTrack current first