sc/qa/unit/ucalc.cxx | 87 ++++++++++++++++++++++++++++++---------- sc/qa/unit/ucalc.hxx | 9 ++++ sc/source/core/data/column3.cxx | 25 +++++++++-- 3 files changed, 95 insertions(+), 26 deletions(-)
New commits: commit ca50752c34de4477c696471b707e1b8136e27661 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Tue Feb 18 22:57:39 2014 -0500 fdo#72491: Always set input as text when that's requested. Even when the text begins with '='. Change-Id: I6e0a995f3042240b9f78068b5d0b9b758eb253ed diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 1445848..5776ac9 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1485,6 +1485,19 @@ void ScColumn::StartListeningInArea( sc::StartListeningContext& rCxt, SCROW nRow sc::ProcessFormula(maCells.begin(), maCells, nRow1, nRow2, aFunc); } +namespace { + +void applyTextNumFormat( ScColumn& rCol, SCROW nRow, SvNumberFormatter* pFormatter ) +{ + sal_uInt32 nFormat = pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT); + ScPatternAttr aNewAttrs(rCol.GetDoc().GetPool()); + SfxItemSet& rSet = aNewAttrs.GetItemSet(); + rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); + rCol.ApplyPattern(nRow, aNewAttrs); +} + +} + bool ScColumn::ParseString( ScCellValue& rCell, SCROW nRow, SCTAB nTabP, const OUString& rString, formula::FormulaGrammar::AddressConvention eConv, @@ -1521,6 +1534,12 @@ bool ScColumn::ParseString( { rCell.set(rPool.intern(rString)); } + else if (aParam.meSetTextNumFormat == ScSetStringParam::Always) + { + // Set the cell format type to Text. + applyTextNumFormat(*this, nRow, aParam.mpNumFormatter); + rCell.set(rPool.intern(rString)); + } else // = Formula rCell.set( new ScFormulaCell( @@ -1625,11 +1644,7 @@ bool ScColumn::ParseString( if (aParam.meSetTextNumFormat != ScSetStringParam::Never && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) { // Set the cell format type to Text. - sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT); - ScPatternAttr aNewAttrs(pDocument->GetPool()); - SfxItemSet& rSet = aNewAttrs.GetItemSet(); - rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) ); - ApplyPattern(nRow, aNewAttrs); + applyTextNumFormat(*this, nRow, aParam.mpNumFormatter); } rCell.set(rPool.intern(rString)); commit 891817922121765cef65ae73ebf7fdc524083d20 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Tue Feb 18 22:11:10 2014 -0500 fdo#72491: Add test for this. Change-Id: Ic37402cb950783b080e5f185b98b19aea62efa7e diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index c7c9ba5..ed84bf2 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1729,9 +1729,7 @@ void Test::testFuncParam() void Test::testNamedRange() { - struct { - const char* pName; const char* pExpr; sal_uInt16 nIndex; - } aNames[] = { + RangeNameDef aNames[] = { { "Divisor", "$Sheet1.$A$1:$A$1048576", 1 }, { "MyRange1", "$Sheet1.$A$1:$A$100", 2 }, { "MyRange2", "$Sheet1.$B$1:$B$100", 3 }, @@ -1742,31 +1740,22 @@ void Test::testNamedRange() m_pDoc->SetValue (0, 0, 0, 101); - ScAddress aA1(0, 0, 0); - ScRangeName* pNewRanges = new ScRangeName(); - for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i) - { - ScRangeData* pNew = new ScRangeData( - m_pDoc, - OUString::createFromAscii(aNames[i].pName), - OUString::createFromAscii(aNames[i].pExpr), - aA1, 0, formula::FormulaGrammar::GRAM_ENGLISH); - pNew->SetIndex(aNames[i].nIndex); - bool bSuccess = pNewRanges->insert(pNew); - CPPUNIT_ASSERT_MESSAGE ("insertion failed", bSuccess); - } + bool bSuccess = insertRangeNames(m_pDoc, aNames, aNames + SAL_N_ELEMENTS(aNames)); + CPPUNIT_ASSERT_MESSAGE("Failed to insert range names.", bSuccess); + + ScRangeName* pNewRanges = m_pDoc->GetRangeName(); + CPPUNIT_ASSERT(pNewRanges); // Make sure the index lookup does the right thing. for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i) { - const ScRangeData* p = pNewRanges->findByIndex(aNames[i].nIndex); + const ScRangeData* p = pNewRanges->findByIndex(aNames[i].mnIndex); CPPUNIT_ASSERT_MESSAGE("lookup of range name by index failed.", p); OUString aName = p->GetName(); - CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved.", aName.equalsAscii(aNames[i].pName)); + CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved.", aName.equalsAscii(aNames[i].mpName)); } // Test usage in formula expression. - m_pDoc->SetRangeName(pNewRanges); m_pDoc->SetString (1, 0, 0, OUString("=A1/Divisor")); m_pDoc->CalcAll(); @@ -1780,16 +1769,48 @@ void Test::testNamedRange() // Make sure the index lookup still works. for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i) { - const ScRangeData* p = pCopiedRanges->findByIndex(aNames[i].nIndex); + const ScRangeData* p = pCopiedRanges->findByIndex(aNames[i].mnIndex); CPPUNIT_ASSERT_MESSAGE("lookup of range name by index failed with the copied instance.", p); OUString aName = p->GetName(); - CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved with the copied instance.", aName.equalsAscii(aNames[i].pName)); + CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved with the copied instance.", aName.equalsAscii(aNames[i].mpName)); } m_pDoc->SetRangeName(NULL); // Delete the names. m_pDoc->DeleteTab(0); } +void Test::testInsertNameList() +{ + m_pDoc->InsertTab(0, "Test"); + + RangeNameDef aNames[] = { + { "MyRange1", "$Test.$A$1:$A$100", 1 }, + { "MyRange2", "$Test.$B$1:$B$100", 2 }, + { "MyRange3", "$Test.$C$1:$C$100", 3 } + }; + + bool bSuccess = insertRangeNames(m_pDoc, aNames, aNames + SAL_N_ELEMENTS(aNames)); + CPPUNIT_ASSERT_MESSAGE("Failed to insert range names.", bSuccess); + + ScDocFunc& rDocFunc = getDocShell().GetDocFunc(); + ScAddress aPos(1,1,0); + rDocFunc.InsertNameList(aPos, true); + + for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i, aPos.IncRow()) + { + OUString aName = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(aNames[i].mpName), aName); + ScAddress aExprPos = aPos; + aExprPos.IncCol(); + OUString aExpr = m_pDoc->GetString(aExprPos); + OUString aExpected = "="; + aExpected += OUString::createFromAscii(aNames[i].mpExpr); + CPPUNIT_ASSERT_EQUAL(aExpected, aExpr); + } + + m_pDoc->DeleteTab(0); +} + void Test::testCSV() { const int English = 0, European = 1; @@ -5845,6 +5866,30 @@ void Test::testMixData() m_pDoc->DeleteTab(0); } +bool Test::insertRangeNames(ScDocument* pDoc, const RangeNameDef* p, const RangeNameDef* pEnd) +{ + ScAddress aA1(0, 0, 0); + ScRangeName* pNewRanges = new ScRangeName(); + for (; p != pEnd; ++p) + { + ScRangeData* pNew = new ScRangeData( + pDoc, + OUString::createFromAscii(p->mpName), + OUString::createFromAscii(p->mpExpr), + aA1, 0, formula::FormulaGrammar::GRAM_ENGLISH); + pNew->SetIndex(p->mnIndex); + bool bSuccess = pNewRanges->insert(pNew); + if (!bSuccess) + { + cerr << "Insertion failed." << endl; + return false; + } + } + + pDoc->SetRangeName(pNewRanges); + return true; +} + void Test::printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption) { SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row(); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 01cb908..c40469a 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -31,7 +31,14 @@ public: class Test : public test::BootstrapFixture { public: + struct RangeNameDef + { + const char* mpName; + const char* mpExpr; + sal_uInt16 mnIndex; + }; + static bool insertRangeNames(ScDocument* pDoc, const RangeNameDef* p, const RangeNameDef* pEnd); static void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption); static void clearRange(ScDocument* pDoc, const ScRange& rRange); static void copyToClip(ScDocument* pSrcDoc, const ScRange& rRange, ScDocument* pClipDoc); @@ -160,6 +167,7 @@ public: void testFuncParam(); void testNamedRange(); + void testInsertNameList(); void testCSV(); void testMatrix(); void testEnterMixedMatrix(); @@ -377,6 +385,7 @@ public: CPPUNIT_TEST(testCellBroadcaster); CPPUNIT_TEST(testFuncParam); CPPUNIT_TEST(testNamedRange); + CPPUNIT_TEST(testInsertNameList); CPPUNIT_TEST(testCSV); CPPUNIT_TEST(testMatrix); CPPUNIT_TEST(testEnterMixedMatrix); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits