[Libreoffice-commits] core.git: 2 commits - sc/inc sc/qa sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Mon Feb 3 11:40:23 PST 2014
sc/inc/document.hxx | 2 -
sc/inc/mtvfunctions.hxx | 2 -
sc/inc/table.hxx | 2 -
sc/qa/unit/ucalc_column.cxx | 51 ++++++++++++++++++++++++++-------------
sc/source/core/data/column.cxx | 8 +++---
sc/source/core/data/document.cxx | 6 ++--
sc/source/core/data/table2.cxx | 21 ++++++++++------
7 files changed, 59 insertions(+), 33 deletions(-)
New commits:
commit 3e2ffb053f9749c6f6990c5ce8f47dc63ea7c148
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Feb 3 14:42:30 2014 -0500
fdo#72470: Correctly calculate the first edit cell row position.
Else it could go into an infinite loop.
Change-Id: I269cd118dcb3ab83ea8a2243576a360d3d4bc142
diff --git a/sc/inc/mtvfunctions.hxx b/sc/inc/mtvfunctions.hxx
index 3c2a940..6955d21 100644
--- a/sc/inc/mtvfunctions.hxx
+++ b/sc/inc/mtvfunctions.hxx
@@ -618,7 +618,7 @@ FindElement2(
break;
default:
{
- ElseRetType aRet = rFuncElse(it->type, nTopRow, nDataSize);
+ ElseRetType aRet = rFuncElse(*it, nOffset);
if (aRet.second)
return PositionType(it, aRet.first);
}
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 7771f0e..f65c3c7 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2956,16 +2956,16 @@ public:
return const_cast<ScFormulaCell*>(p)->IsMultilineResult();
}
- std::pair<size_t,bool> operator() (mdds::mtv::element_t type, size_t nTopRow, size_t nDataSize)
+ std::pair<size_t,bool> operator() (const sc::CellStoreType::value_type& node, size_t nOffset)
{
typedef std::pair<size_t,bool> RetType;
- if (type == sc::element_type_empty)
+ if (node.type == sc::element_type_empty)
return RetType(0, false);
- for (size_t i = 0; i < nDataSize; ++i)
+ for (size_t i = nOffset; i < node.size; ++i)
{
- SCROW nRow = nTopRow + i;
+ SCROW nRow = node.position + i;
sal_uInt8 nScriptType = mrColumn.GetRangeScriptType(miAttrPos, nRow, nRow, miCellPos);
if (IsAmbiguousScriptNonZero(nScriptType))
// Return the offset from the first row.
commit 99a262dc954c19ebd8d07fa8b0f9c9f9a45305a8
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Feb 3 14:39:51 2014 -0500
Finally found a way to get this test to fail.
Change-Id: I67cf68ee7e51794de374581016ffb13ebdff59d3
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 6ffcc69..98b40b0 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -802,7 +802,7 @@ public:
SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, const OUString& rStr );
- SC_DLLPUBLIC bool HasEditText( const ScRange& rRange ) const;
+ SC_DLLPUBLIC SCROW GetFirstEditTextRow( const ScRange& rRange ) const;
/**
* Call this if you are not sure whether to put this as an edit text or a
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 2b38473..52a6cf6 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -329,7 +329,7 @@ public:
void SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText );
void SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool );
- bool HasEditText( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const;
+ SCROW GetFirstEditTextRow( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const;
void SetEmptyCell( SCCOL nCol, SCROW nRow );
void SetFormula(
diff --git a/sc/qa/unit/ucalc_column.cxx b/sc/qa/unit/ucalc_column.cxx
index 0959ee1..0ed75b4 100644
--- a/sc/qa/unit/ucalc_column.cxx
+++ b/sc/qa/unit/ucalc_column.cxx
@@ -10,17 +10,20 @@
#include <ucalc.hxx>
#include <editutil.hxx>
#include <cellvalue.hxx>
+#include <svl/languageoptions.hxx>
void Test::testColumnFindEditCells()
{
m_pDoc->InsertTab(0, "Test");
- bool bRes = m_pDoc->HasEditText(ScRange(0,0,0,0,MAXROW,0));
- CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", !bRes);
- bRes = m_pDoc->HasEditText(ScRange(0,0,0,0,0,0));
- CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", !bRes);
- bRes = m_pDoc->HasEditText(ScRange(0,0,0,0,10,0));
- CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", !bRes);
+ // Test the basics with real edit cells, using Column A.
+
+ SCROW nResRow = m_pDoc->GetFirstEditTextRow(ScRange(0,0,0,0,MAXROW,0));
+ CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", nResRow == -1);
+ nResRow = m_pDoc->GetFirstEditTextRow(ScRange(0,0,0,0,0,0));
+ CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", nResRow == -1);
+ nResRow = m_pDoc->GetFirstEditTextRow(ScRange(0,0,0,0,10,0));
+ CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", nResRow == -1);
ScFieldEditEngine& rEE = m_pDoc->GetEditEngine();
rEE.SetText("Test");
@@ -29,23 +32,23 @@ void Test::testColumnFindEditCells()
CPPUNIT_ASSERT_MESSAGE("There should be an edit cell here.", pObj);
ScRange aRange(0,0,0,0,0,0);
- bRes = m_pDoc->HasEditText(aRange);
- CPPUNIT_ASSERT_MESSAGE("There is an edit cell here.", bRes);
+ nResRow = m_pDoc->GetFirstEditTextRow(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There is an edit cell here.", nResRow == 0);
aRange.aStart.SetRow(1);
aRange.aEnd.SetRow(1);
- bRes = m_pDoc->HasEditText(aRange);
- CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", !bRes);
+ nResRow = m_pDoc->GetFirstEditTextRow(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", nResRow == -1);
aRange.aStart.SetRow(2);
aRange.aEnd.SetRow(4);
- bRes = m_pDoc->HasEditText(aRange);
- CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", !bRes);
+ nResRow = m_pDoc->GetFirstEditTextRow(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", nResRow == -1);
aRange.aStart.SetRow(0);
aRange.aEnd.SetRow(MAXROW);
- bRes = m_pDoc->HasEditText(aRange);
- CPPUNIT_ASSERT_MESSAGE("There shouldn be an edit cell in specified range.", bRes);
+ nResRow = m_pDoc->GetFirstEditTextRow(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There should be an edit cell in specified range.", nResRow == 0);
m_pDoc->SetString(ScAddress(0,0,0), "Test");
m_pDoc->SetValue(ScAddress(0,2,0), 1.0);
@@ -61,8 +64,24 @@ void Test::testColumnFindEditCells()
aRange.aStart.SetRow(1);
aRange.aEnd.SetRow(1);
- bRes = m_pDoc->HasEditText(aRange);
- CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", !bRes);
+ nResRow = m_pDoc->GetFirstEditTextRow(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", nResRow == -1);
+
+ // Test with non-edit cell but with ambiguous script type.
+
+ m_pDoc->SetString(ScAddress(1,11,0), "Some text");
+ m_pDoc->SetString(ScAddress(1,12,0), "Some text");
+ m_pDoc->SetString(ScAddress(1,13,0), "Other text");
+
+ m_pDoc->SetScriptType(ScAddress(1,11,0), (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN));
+ m_pDoc->SetScriptType(ScAddress(1,12,0), (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN));
+ m_pDoc->SetScriptType(ScAddress(1,13,0), (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN));
+
+ nResRow = m_pDoc->GetFirstEditTextRow(ScAddress(1,11,0));
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(11), nResRow);
+ CPPUNIT_ASSERT_MESSAGE("String with mixed script types is considered an edit cell.", nResRow == 11);
+ nResRow = m_pDoc->GetFirstEditTextRow(ScAddress(1,12,0));
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), nResRow);
m_pDoc->DeleteTab(0);
}
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index bbd3ce2..b2126b2 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3210,13 +3210,13 @@ void ScDocument::SetEditText( const ScAddress& rPos, const OUString& rStr )
maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), rEngine.CreateTextObject());
}
-bool ScDocument::HasEditText( const ScRange& rRange ) const
+SCROW ScDocument::GetFirstEditTextRow( const ScRange& rRange ) const
{
const ScTable* pTab = FetchTable(rRange.aStart.Tab());
if (!pTab)
- return false;
+ return -1;
- return pTab->HasEditText(rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row());
+ return pTab->GetFirstEditTextRow(rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row());
}
void ScDocument::SetTextCell( const ScAddress& rPos, const OUString& rStr )
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index af4587d..dc35b16 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1347,23 +1347,30 @@ void ScTable::SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditTe
aCol[nCol].SetEditText(nRow, rEditText, pEditPool);
}
-bool ScTable::HasEditText( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const
+SCROW ScTable::GetFirstEditTextRow( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const
{
if (!ValidCol(nCol1) || !ValidCol(nCol2) || nCol2 < nCol1)
- return false;
+ return -1;
if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow2 < nRow1)
- return false;
+ return -1;
- SCROW nFirst = -1;
+ SCROW nFirst = MAXROW+1;
for (SCCOL i = nCol1; i <= nCol2; ++i)
{
const ScColumn& rCol = aCol[i];
- if (const_cast<ScColumn&>(rCol).HasEditCells(nRow1, nRow2, nFirst))
- return true;
+ SCROW nThisFirst = -1;
+ if (const_cast<ScColumn&>(rCol).HasEditCells(nRow1, nRow2, nThisFirst))
+ {
+ if (nThisFirst == nRow1)
+ return nRow1;
+
+ if (nThisFirst < nFirst)
+ nFirst = nThisFirst;
+ }
}
- return false;
+ return nFirst == (MAXROW+1) ? -1 : nFirst;
}
void ScTable::SetEmptyCell( SCCOL nCol, SCROW nRow )
More information about the Libreoffice-commits
mailing list