Kaydet (Commit) 75571c29 authored tarafından Dennis Francis's avatar Dennis Francis Kaydeden (comit) Eike Rathke

tdf#120660: Populate rNewSharedRows even if no FC...

at specified position. At least in case of ScUndoPaste, during
undo operation, the content from changed area in main-document
is removed before actual undo-paste, so when cloned formula-cell
from undo-doc is inserted to main-doc, there is no "old" cell
to detach, so "rNewSharedRows" is not populated which is needed
for proper re-establishment of listeners if there are formula/
formula-groups adjacent to insertion position.

Change-Id: Id2bfb65a2a7a5abb03effbdcc4405015fddc401c
Next: fix the vector version of this case and write unit tests.
Reviewed-on: https://gerrit.libreoffice.org/69737
Tested-by: Jenkins
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
(cherry picked from commit e7d0785a)
Reviewed-on: https://gerrit.libreoffice.org/69905
üst cc9ff57e
...@@ -702,9 +702,10 @@ public: ...@@ -702,9 +702,10 @@ public:
bool ReservePatternCount( SCSIZE nReserve ); bool ReservePatternCount( SCSIZE nReserve );
private: private:
sc::CellStoreType::iterator GetPositionToInsert( SCROW nRow, std::vector<SCROW>& rNewSharedRows ); sc::CellStoreType::iterator GetPositionToInsert( SCROW nRow, std::vector<SCROW>& rNewSharedRows,
bool bInsertFormula );
sc::CellStoreType::iterator GetPositionToInsert( const sc::CellStoreType::iterator& it, SCROW nRow, sc::CellStoreType::iterator GetPositionToInsert( const sc::CellStoreType::iterator& it, SCROW nRow,
std::vector<SCROW>& rNewSharedRows ); std::vector<SCROW>& rNewSharedRows, bool bInsertFormula );
void AttachNewFormulaCell( void AttachNewFormulaCell(
const sc::CellStoreType::iterator& itPos, SCROW nRow, ScFormulaCell& rCell, const sc::CellStoreType::iterator& itPos, SCROW nRow, ScFormulaCell& rCell,
......
...@@ -257,9 +257,10 @@ void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize, std::vector<ScAddress>* ...@@ -257,9 +257,10 @@ void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize, std::vector<ScAddress>*
CellStorageModified(); CellStorageModified();
} }
sc::CellStoreType::iterator ScColumn::GetPositionToInsert( SCROW nRow, std::vector<SCROW>& rNewSharedRows ) sc::CellStoreType::iterator ScColumn::GetPositionToInsert( SCROW nRow, std::vector<SCROW>& rNewSharedRows,
bool bInsertFormula )
{ {
return GetPositionToInsert(maCells.begin(), nRow, rNewSharedRows); return GetPositionToInsert(maCells.begin(), nRow, rNewSharedRows, bInsertFormula);
} }
void ScColumn::JoinNewFormulaCell( void ScColumn::JoinNewFormulaCell(
...@@ -535,17 +536,54 @@ void ScColumn::DetachFormulaCells( sc::EndListeningContext& rCxt, SCROW nRow1, S ...@@ -535,17 +536,54 @@ void ScColumn::DetachFormulaCells( sc::EndListeningContext& rCxt, SCROW nRow1, S
sc::ProcessFormula(it, maCells, nRow1, nRow2, aFunc); sc::ProcessFormula(it, maCells, nRow1, nRow2, aFunc);
} }
sc::CellStoreType::iterator ScColumn::GetPositionToInsert( const sc::CellStoreType::iterator& it, SCROW nRow, static void lcl_AddFormulaGroupBoundaries(const sc::CellStoreType::position_type& rPos,
std::vector<SCROW>& rNewSharedRows ) std::vector<SCROW>& rNewSharedRows )
{
sc::CellStoreType::iterator itRet = rPos.first;
if (itRet->type != sc::element_type_formula)
return;
ScFormulaCell& rFC = *sc::formula_block::at(*itRet->data, rPos.second);
if ( rFC.IsShared() )
{
const SCROW nSharedTopRow = rFC.GetSharedTopRow();
const SCROW nSharedLength = rFC.GetSharedLength();
rNewSharedRows.push_back( nSharedTopRow);
rNewSharedRows.push_back( nSharedTopRow + nSharedLength - 1);
}
else
{
const SCROW nRow = rFC.aPos.Row();
rNewSharedRows.push_back( nRow);
rNewSharedRows.push_back( nRow);
}
}
sc::CellStoreType::iterator ScColumn::GetPositionToInsert( const sc::CellStoreType::iterator& it, SCROW nRow,
std::vector<SCROW>& rNewSharedRows, bool bInsertFormula )
{ {
// See if we are overwriting an existing formula cell. // See if we are overwriting an existing formula cell.
sc::CellStoreType::position_type aPos = maCells.position(it, nRow); sc::CellStoreType::position_type aPos = maCells.position(it, nRow);
sc::CellStoreType::iterator itRet = aPos.first; sc::CellStoreType::iterator itRet = aPos.first;
if (itRet->type == sc::element_type_formula) if (itRet->type == sc::element_type_formula)
{ {
ScFormulaCell& rCell = *sc::formula_block::at(*itRet->data, aPos.second); ScFormulaCell& rCell = *sc::formula_block::at(*itRet->data, aPos.second);
DetachFormulaCell(aPos, rCell, rNewSharedRows); DetachFormulaCell(aPos, rCell, rNewSharedRows);
} }
else if (bInsertFormula && !GetDoc()->IsClipOrUndo())
{
if (nRow > 0)
{
sc::CellStoreType::position_type aPosBefore = maCells.position(maCells.begin(), nRow-1);
lcl_AddFormulaGroupBoundaries(aPosBefore, rNewSharedRows);
}
if (nRow < MAXROW)
{
sc::CellStoreType::position_type aPosAfter = maCells.position(maCells.begin(), nRow+1);
lcl_AddFormulaGroupBoundaries(aPosAfter, rNewSharedRows);
}
}
return itRet; return itRet;
} }
...@@ -2089,7 +2127,7 @@ void ScColumn::SetEditText( SCROW nRow, std::unique_ptr<EditTextObject> pEditTex ...@@ -2089,7 +2127,7 @@ void ScColumn::SetEditText( SCROW nRow, std::unique_ptr<EditTextObject> pEditTex
{ {
pEditText->NormalizeString(GetDoc()->GetSharedStringPool()); pEditText->NormalizeString(GetDoc()->GetSharedStringPool());
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows); sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows, false);
maCells.set(it, nRow, pEditText.release()); maCells.set(it, nRow, pEditText.release());
maCellTextAttrs.set(nRow, sc::CellTextAttr()); maCellTextAttrs.set(nRow, sc::CellTextAttr());
CellStorageModified(); CellStorageModified();
...@@ -2103,7 +2141,7 @@ void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, std: ...@@ -2103,7 +2141,7 @@ void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, std:
{ {
pEditText->NormalizeString(GetDoc()->GetSharedStringPool()); pEditText->NormalizeString(GetDoc()->GetSharedStringPool());
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows); rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows, false);
rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, pEditText.release()); rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, pEditText.release());
rBlockPos.miCellTextAttrPos = maCellTextAttrs.set( rBlockPos.miCellTextAttrPos = maCellTextAttrs.set(
rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr()); rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr());
...@@ -2152,7 +2190,7 @@ void ScColumn::SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::Form ...@@ -2152,7 +2190,7 @@ void ScColumn::SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::Form
ScAddress aPos(nCol, nRow, nTab); ScAddress aPos(nCol, nRow, nTab);
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows); sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows, true);
ScFormulaCell* pCell = new ScFormulaCell(GetDoc(), aPos, rArray, eGram); ScFormulaCell* pCell = new ScFormulaCell(GetDoc(), aPos, rArray, eGram);
sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow); sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow);
if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0) if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
...@@ -2170,7 +2208,7 @@ void ScColumn::SetFormula( SCROW nRow, const OUString& rFormula, formula::Formul ...@@ -2170,7 +2208,7 @@ void ScColumn::SetFormula( SCROW nRow, const OUString& rFormula, formula::Formul
ScAddress aPos(nCol, nRow, nTab); ScAddress aPos(nCol, nRow, nTab);
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows); sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows, true);
ScFormulaCell* pCell = new ScFormulaCell(GetDoc(), aPos, rFormula, eGram); ScFormulaCell* pCell = new ScFormulaCell(GetDoc(), aPos, rFormula, eGram);
sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow); sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow);
if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0) if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
...@@ -2188,7 +2226,7 @@ ScFormulaCell* ScColumn::SetFormulaCell( ...@@ -2188,7 +2226,7 @@ ScFormulaCell* ScColumn::SetFormulaCell(
bool bInheritNumFormatIfNeeded ) bool bInheritNumFormatIfNeeded )
{ {
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows); sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows, true);
sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow); sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow);
if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && bInheritNumFormatIfNeeded ) if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && bInheritNumFormatIfNeeded )
pCell->SetNeedNumberFormat(true); pCell->SetNeedNumberFormat(true);
...@@ -2208,7 +2246,7 @@ void ScColumn::SetFormulaCell( ...@@ -2208,7 +2246,7 @@ void ScColumn::SetFormulaCell(
bool bInheritNumFormatIfNeeded ) bool bInheritNumFormatIfNeeded )
{ {
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows); rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows, true);
sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow); sal_uInt32 nCellFormat = GetNumberFormat(GetDoc()->GetNonThreadedContext(), nRow);
if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && bInheritNumFormatIfNeeded ) if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && bInheritNumFormatIfNeeded )
pCell->SetNeedNumberFormat(true); pCell->SetNeedNumberFormat(true);
...@@ -2695,7 +2733,7 @@ void ScColumn::SetError( SCROW nRow, const FormulaError nError) ...@@ -2695,7 +2733,7 @@ void ScColumn::SetError( SCROW nRow, const FormulaError nError)
pCell->SetErrCode(nError); pCell->SetErrCode(nError);
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows); sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows, true);
it = maCells.set(it, nRow, pCell); it = maCells.set(it, nRow, pCell);
maCellTextAttrs.set(nRow, sc::CellTextAttr()); maCellTextAttrs.set(nRow, sc::CellTextAttr());
...@@ -2722,7 +2760,7 @@ void ScColumn::SetRawString( SCROW nRow, const svl::SharedString& rStr ) ...@@ -2722,7 +2760,7 @@ void ScColumn::SetRawString( SCROW nRow, const svl::SharedString& rStr )
return; return;
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows); sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows, false);
maCells.set(it, nRow, rStr); maCells.set(it, nRow, rStr);
maCellTextAttrs.set(nRow, sc::CellTextAttr()); maCellTextAttrs.set(nRow, sc::CellTextAttr());
...@@ -2740,7 +2778,7 @@ void ScColumn::SetRawString( ...@@ -2740,7 +2778,7 @@ void ScColumn::SetRawString(
return; return;
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows); rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows, false);
rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, rStr); rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, rStr);
rBlockPos.miCellTextAttrPos = maCellTextAttrs.set( rBlockPos.miCellTextAttrPos = maCellTextAttrs.set(
rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr()); rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr());
...@@ -2759,7 +2797,7 @@ void ScColumn::SetValue( SCROW nRow, double fVal ) ...@@ -2759,7 +2797,7 @@ void ScColumn::SetValue( SCROW nRow, double fVal )
return; return;
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows); sc::CellStoreType::iterator it = GetPositionToInsert(nRow, aNewSharedRows, false);
maCells.set(it, nRow, fVal); maCells.set(it, nRow, fVal);
maCellTextAttrs.set(nRow, sc::CellTextAttr()); maCellTextAttrs.set(nRow, sc::CellTextAttr());
...@@ -2777,7 +2815,7 @@ void ScColumn::SetValue( ...@@ -2777,7 +2815,7 @@ void ScColumn::SetValue(
return; return;
std::vector<SCROW> aNewSharedRows; std::vector<SCROW> aNewSharedRows;
rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows); rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow, aNewSharedRows, false);
rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, fVal); rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, fVal);
rBlockPos.miCellTextAttrPos = maCellTextAttrs.set( rBlockPos.miCellTextAttrPos = maCellTextAttrs.set(
rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr()); rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr());
......
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