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

Normalize all string objects that are cell contents before they get stored.

Hopefully I've covered all entry points. There may be more lurking in some
dark corneres...

Change-Id: I62e655cc579aad08fa64b5d58e739c55425cd216
üst bc1c67dc
...@@ -234,6 +234,7 @@ friend class ScDocRowHeightUpdater; ...@@ -234,6 +234,7 @@ friend class ScDocRowHeightUpdater;
friend class ScColumnTextWidthIterator; friend class ScColumnTextWidthIterator;
friend class ScFormulaCell; friend class ScFormulaCell;
friend class ScTable; friend class ScTable;
friend class ScColumn;
friend struct ScRefCellValue; friend struct ScRefCellValue;
friend class ScDocumentImport; friend class ScDocumentImport;
friend class sc::ColumnSpanSet; friend class sc::ColumnSpanSet;
...@@ -2065,6 +2066,8 @@ private: // CLOOK-Impl-methods ...@@ -2065,6 +2066,8 @@ private: // CLOOK-Impl-methods
ScRefCellValue GetRefCellValue( const ScAddress& rPos ); ScRefCellValue GetRefCellValue( const ScAddress& rPos );
svl::StringPool& GetCellStringPool();
std::map< SCTAB, ScSortParam > mSheetSortParams; std::map< SCTAB, ScSortParam > mSheetSortParams;
}; };
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <svl/zforlist.hxx> #include <svl/zforlist.hxx>
#include <svl/zformat.hxx> #include <svl/zformat.hxx>
#include <svl/broadcast.hxx> #include <svl/broadcast.hxx>
#include "svl/stringpool.hxx"
#include "editeng/editstat.hxx" #include "editeng/editstat.hxx"
#include <cstdio> #include <cstdio>
...@@ -1601,6 +1602,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, ...@@ -1601,6 +1602,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
void ScColumn::SetEditText( SCROW nRow, EditTextObject* pEditText ) void ScColumn::SetEditText( SCROW nRow, EditTextObject* pEditText )
{ {
pEditText->NormalizeString(pDocument->GetCellStringPool());
sc::CellStoreType::iterator it = GetPositionToInsert(nRow); sc::CellStoreType::iterator it = GetPositionToInsert(nRow);
maCells.set(it, nRow, pEditText); maCells.set(it, nRow, pEditText);
maCellTextAttrs.set(nRow, sc::CellTextAttr()); maCellTextAttrs.set(nRow, sc::CellTextAttr());
...@@ -1611,6 +1613,7 @@ void ScColumn::SetEditText( SCROW nRow, EditTextObject* pEditText ) ...@@ -1611,6 +1613,7 @@ void ScColumn::SetEditText( SCROW nRow, EditTextObject* pEditText )
void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, EditTextObject* pEditText ) void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, EditTextObject* pEditText )
{ {
pEditText->NormalizeString(pDocument->GetCellStringPool());
rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow); rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow);
rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, pEditText); rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, pEditText);
rBlockPos.miCellTextAttrPos = maCellTextAttrs.set( rBlockPos.miCellTextAttrPos = maCellTextAttrs.set(
...@@ -1632,24 +1635,9 @@ void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, cons ...@@ -1632,24 +1635,9 @@ void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, cons
// Sadly there is no other way to change the Pool than to // Sadly there is no other way to change the Pool than to
// "spool" the Object through a corresponding Engine // "spool" the Object through a corresponding Engine
EditEngine& rEngine = pDocument->GetEditEngine(); EditEngine& rEngine = pDocument->GetEditEngine();
if (!rEditText.HasOnlineSpellErrors())
{
rEngine.SetText(rEditText);
SetEditText(rBlockPos, nRow, rEngine.CreateTextObject());
return;
}
sal_uLong nControl = rEngine.GetControlWord();
const sal_uLong nSpellControl = EE_CNTRL_ONLINESPELLING | EE_CNTRL_ALLOWBIGOBJS;
bool bNewControl = (nControl & nSpellControl) != nSpellControl;
if (bNewControl)
rEngine.SetControlWord(nControl | nSpellControl);
rEngine.SetText(rEditText); rEngine.SetText(rEditText);
EditTextObject* pData = rEngine.CreateTextObject(); SetEditText(rBlockPos, nRow, rEngine.CreateTextObject());
if (bNewControl) return;
rEngine.SetControlWord(nControl);
SetEditText(rBlockPos, nRow, pData);
} }
void ScColumn::SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool ) void ScColumn::SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool )
...@@ -1664,24 +1652,9 @@ void ScColumn::SetEditText( SCROW nRow, const EditTextObject& rEditText, const S ...@@ -1664,24 +1652,9 @@ void ScColumn::SetEditText( SCROW nRow, const EditTextObject& rEditText, const S
// Sadly there is no other way to change the Pool than to // Sadly there is no other way to change the Pool than to
// "spool" the Object through a corresponding Engine // "spool" the Object through a corresponding Engine
EditEngine& rEngine = pDocument->GetEditEngine(); EditEngine& rEngine = pDocument->GetEditEngine();
if (!rEditText.HasOnlineSpellErrors())
{
rEngine.SetText(rEditText);
SetEditText(nRow, rEngine.CreateTextObject());
return;
}
sal_uLong nControl = rEngine.GetControlWord();
const sal_uLong nSpellControl = EE_CNTRL_ONLINESPELLING | EE_CNTRL_ALLOWBIGOBJS;
bool bNewControl = (nControl & nSpellControl) != nSpellControl;
if (bNewControl)
rEngine.SetControlWord(nControl | nSpellControl);
rEngine.SetText(rEditText); rEngine.SetText(rEditText);
EditTextObject* pData = rEngine.CreateTextObject(); SetEditText(nRow, rEngine.CreateTextObject());
if (bNewControl) return;
rEngine.SetControlWord(nControl);
SetEditText(nRow, pData);
} }
void ScColumn::SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ) void ScColumn::SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
...@@ -2157,8 +2130,12 @@ void ScColumn::SetRawString( SCROW nRow, const OUString& rStr, bool bBroadcast ) ...@@ -2157,8 +2130,12 @@ void ScColumn::SetRawString( SCROW nRow, const OUString& rStr, bool bBroadcast )
if (!ValidRow(nRow)) if (!ValidRow(nRow))
return; return;
rtl_uString* pStr = pDocument->GetCellStringPool().intern(rStr);
if (!pStr)
return;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow); sc::CellStoreType::iterator it = GetPositionToInsert(nRow);
maCells.set(it, nRow, rStr); maCells.set(it, nRow, OUString(pStr));
maCellTextAttrs.set(nRow, sc::CellTextAttr()); maCellTextAttrs.set(nRow, sc::CellTextAttr());
CellStorageModified(); CellStorageModified();
...@@ -2172,8 +2149,12 @@ void ScColumn::SetRawString( ...@@ -2172,8 +2149,12 @@ void ScColumn::SetRawString(
if (!ValidRow(nRow)) if (!ValidRow(nRow))
return; return;
rtl_uString* pStr = pDocument->GetCellStringPool().intern(rStr);
if (!pStr)
return;
rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow); rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow);
rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, rStr); rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, OUString(pStr));
rBlockPos.miCellTextAttrPos = maCellTextAttrs.set( rBlockPos.miCellTextAttrPos = maCellTextAttrs.set(
rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr()); rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr());
CellStorageModified(); CellStorageModified();
......
...@@ -118,8 +118,8 @@ private: ...@@ -118,8 +118,8 @@ private:
// STATIC DATA ----------------------------------------------------------- // STATIC DATA -----------------------------------------------------------
ScDocument::ScDocument( ScDocumentMode eMode, ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
SfxObjectShell* pDocShell ) : mpCellStringPool(new svl::StringPool(ScGlobal::pCharClass)),
mpUndoManager( NULL ), mpUndoManager( NULL ),
pEditEngine( NULL ), pEditEngine( NULL ),
pNoteEngine( NULL ), pNoteEngine( NULL ),
...@@ -600,6 +600,11 @@ ScRefCellValue ScDocument::GetRefCellValue( const ScAddress& rPos ) ...@@ -600,6 +600,11 @@ ScRefCellValue ScDocument::GetRefCellValue( const ScAddress& rPos )
return maTabs[rPos.Tab()]->GetRefCellValue(rPos.Col(), rPos.Row()); return maTabs[rPos.Tab()]->GetRefCellValue(rPos.Col(), rPos.Row());
} }
svl::StringPool& ScDocument::GetCellStringPool()
{
return *mpCellStringPool;
}
bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow, bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow,
bool bNotes ) const bool bNotes ) const
{ {
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "mtvelements.hxx" #include "mtvelements.hxx"
#include "tokenarray.hxx" #include "tokenarray.hxx"
#include "svl/stringpool.hxx"
struct ScDocumentImportImpl struct ScDocumentImportImpl
{ {
ScDocument& mrDoc; ScDocument& mrDoc;
...@@ -148,8 +150,12 @@ void ScDocumentImport::setStringCell(const ScAddress& rPos, const OUString& rStr ...@@ -148,8 +150,12 @@ void ScDocumentImport::setStringCell(const ScAddress& rPos, const OUString& rStr
if (!pBlockPos) if (!pBlockPos)
return; return;
rtl_uString* pStr = mpImpl->mrDoc.GetCellStringPool().intern(rStr);
if (!pStr)
return;
sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), rStr); pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), OUString(pStr));
} }
void ScDocumentImport::setEditCell(const ScAddress& rPos, EditTextObject* pEditText) void ScDocumentImport::setEditCell(const ScAddress& rPos, EditTextObject* pEditText)
...@@ -164,6 +170,7 @@ void ScDocumentImport::setEditCell(const ScAddress& rPos, EditTextObject* pEditT ...@@ -164,6 +170,7 @@ void ScDocumentImport::setEditCell(const ScAddress& rPos, EditTextObject* pEditT
if (!pBlockPos) if (!pBlockPos)
return; return;
pEditText->NormalizeString(mpImpl->mrDoc.GetCellStringPool());
sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), pEditText); pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), pEditText);
} }
......
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