[Libreoffice-commits] .: 3 commits - sc/inc sc/qa sc/source
Markus Mohrhard
mmohrhard at kemper.freedesktop.org
Fri Dec 23 00:15:29 PST 2011
sc/inc/tokenarray.hxx | 7 ++
sc/qa/extras/testdocuments/rangenamessrc.ods |binary
sc/qa/extras/xspreadsheets2.cxx | 48 +++++++++++++++----
sc/source/core/data/cell.cxx | 6 +-
sc/source/core/tool/token.cxx | 68 ++++++++++++++++++++++++---
sc/source/ui/app/transobj.cxx | 4 +
sc/source/ui/view/viewfun3.cxx | 19 -------
7 files changed, 115 insertions(+), 37 deletions(-)
New commits:
commit 6274810bf61285a1ac27e4a6a19c7aa1566b0df8
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri Dec 23 08:58:17 2011 +0100
fix copy/paste with whole column/row
this fix should restore the old copy/paste behavior in calc and still
only paste relevant entries to external programs
diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index c923fd6..a61e5d3 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -61,6 +61,7 @@
#include "scmod.hxx"
#include "dragdata.hxx"
#include "clipdata.hxx"
+#include "clipparam.hxx"
// for InitDocShell
#include <editeng/paperinf.hxx>
@@ -171,6 +172,9 @@ ScTransferObj::ScTransferObj( ScDocument* pClipDoc, const TransferableObjectDesc
}
OSL_ENSURE(!bFirst, "no sheet selected");
+ if (!pDoc->GetClipParam().isMultiRange() && nTab1 == nTab2)
+ pDoc->ShrinkToDataArea( nTab1, nCol1, nRow1, nCol2, nRow2 );
+
// only limit to used cells if whole sheet was marked
// (so empty cell areas can be copied)
if ( nCol2>=MAXCOL && nRow2>=MAXROW )
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 68ccf21..bd13314 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -277,28 +277,9 @@ sal_Bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, sal_Bool bCut, sal_Bool b
{
ScRange aRange;
ScMarkType eMarkType = GetViewData()->GetSimpleArea( aRange );
- ScDocument* pDoc = GetViewData()->GetDocument();
ScMarkData& rMark = GetViewData()->GetMarkData();
sal_Bool bDone = sal_False;
- if( !pClipDoc ) // System Copy - adjust the ranges.
- {
- SCCOL nCol1 = aRange.aStart.Col();
- SCCOL nCol2 = aRange.aEnd.Col();
- SCROW nRow1 = aRange.aStart.Row();
- SCROW nRow2 = aRange.aEnd.Row();
- pDoc->ShrinkToDataArea( aRange.aStart.Tab(), nCol1, nRow1, nCol2, nRow2 );
- if( aRange.aStart.Col() == 0 && aRange.aEnd.Col() == MAXCOL )
- {
- aRange.aStart.SetCol( nCol1 );
- aRange.aEnd.SetCol( nCol2 );
- }
- if( aRange.aStart.Row() == 0 && aRange.aEnd.Row() == MAXROW )
- {
- aRange.aStart.SetRow( nRow1 );
- aRange.aEnd.SetRow( nRow2 );
- }
- }
if ( eMarkType == SC_MARK_SIMPLE || eMarkType == SC_MARK_SIMPLE_FILTERED )
{
ScRangeList aRangeList;
commit c638b526a98915bf1190ca8ab2f8b6ec9b39a101
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Dec 22 02:51:08 2011 +0100
adjust absolute refs to copied areas correctly
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index 1819de2..df214b0 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -104,7 +104,12 @@ public:
* @param rPos position of the cell to determine if the reference is in the copied area
* @param bRangeName set for range names, range names have special handling for absolute sheet ref + relative col/row ref
*/
- void ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName = false );
+ void ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName = false );
+
+ /**
+ * Make all absolute references pointing to the copied range if the range is copied too
+ */
+ void AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos );
};
#endif // SC_TOKENARRAY_HXX
diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx
index f7ea541..cf5f70f 100644
--- a/sc/source/core/data/cell.cxx
+++ b/sc/source/core/data/cell.cxx
@@ -182,7 +182,7 @@ void adjustRangeName(ScToken* pToken, ScDocument& rNewDoc, const ScDocument* pOl
ScTokenArray* pRangeNameToken = pRangeData->GetCode();
if (rNewDoc.GetPool() != const_cast<ScDocument*>(pOldDoc)->GetPool())
{
- pRangeNameToken->ReadjusteAbsolute3DReferences(pOldDoc, &rNewDoc, pRangeData->GetPos(), true);
+ pRangeNameToken->ReadjustAbsolute3DReferences(pOldDoc, &rNewDoc, pRangeData->GetPos(), true);
}
bool bInserted;
@@ -890,8 +890,10 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons
if (pDocument->GetPool() != rCell.pDocument->GetPool())
{
- pCode->ReadjusteAbsolute3DReferences( rCell.pDocument, &rDoc, rCell.aPos);
+ pCode->ReadjustAbsolute3DReferences( rCell.pDocument, &rDoc, rCell.aPos);
}
+
+ pCode->AdjustAbsoluteRefs( rCell.pDocument, rCell.aPos, aPos );
}
if( !bCompile )
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index dcc08d4..6ef4346 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1875,9 +1875,25 @@ bool SkipReference(ScToken* pToken, const ScAddress& rPos, const ScDocument* pOl
return false;
}
+void AdjustSingleRefData( ScSingleRefData& rRef, const ScAddress& rOldPos, const ScAddress& rNewPos)
+{
+ SCsCOL nCols = rNewPos.Col() - rOldPos.Col();
+ SCsROW nRows = rNewPos.Row() - rOldPos.Row();
+ SCsTAB nTabs = rNewPos.Tab() - rOldPos.Tab();
+
+ if (!rRef.IsColRel())
+ rRef.nCol += nCols;
+
+ if (!rRef.IsRowRel())
+ rRef.nRow += nRows;
+
+ if (!rRef.IsTabRel())
+ rRef.nTab += nTabs;
}
-void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName )
+}
+
+void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName )
{
for ( sal_uInt16 j=0; j<nLen; ++j )
{
@@ -1885,13 +1901,13 @@ void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, con
{
case svDoubleRef :
{
+ if (SkipReference(static_cast<ScToken*>(pCode[j]), rPos, pOldDoc, bRangeName))
+ continue;
+
ScComplexRefData& rRef = static_cast<ScToken*>(pCode[j])->GetDoubleRef();
ScSingleRefData& rRef2 = rRef.Ref2;
ScSingleRefData& rRef1 = rRef.Ref1;
- if (SkipReference(static_cast<ScToken*>(pCode[j]), rPos, pOldDoc, bRangeName))
- continue;
-
if ( (rRef2.IsFlag3D() && !rRef2.IsTabRel()) || (rRef1.IsFlag3D() && !rRef1.IsTabRel()) )
{
rtl::OUString aTabName;
@@ -1906,11 +1922,11 @@ void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, con
break;
case svSingleRef :
{
- ScSingleRefData& rRef = static_cast<ScToken*>(pCode[j])->GetSingleRef();
-
if (SkipReference(static_cast<ScToken*>(pCode[j]), rPos, pOldDoc, bRangeName))
continue;
+ ScSingleRefData& rRef = static_cast<ScToken*>(pCode[j])->GetSingleRef();
+
if ( rRef.IsFlag3D() && !rRef.IsTabRel() )
{
rtl::OUString aTabName;
@@ -1932,5 +1948,45 @@ void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, con
}
}
+void ScTokenArray::AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos)
+{
+ for ( sal_uInt16 j=0; j<nLen; ++j )
+ {
+ switch ( pCode[j]->GetType() )
+ {
+ case svDoubleRef :
+ {
+ if (!SkipReference(static_cast<ScToken*>(pCode[j]), rOldPos, pOldDoc, false))
+ continue;
+
+ ScComplexRefData& rRef = static_cast<ScToken*>(pCode[j])->GetDoubleRef();
+ ScSingleRefData& rRef2 = rRef.Ref2;
+ ScSingleRefData& rRef1 = rRef.Ref1;
+
+ AdjustSingleRefData( rRef1, rOldPos, rNewPos );
+ AdjustSingleRefData( rRef2, rOldPos, rNewPos );
+
+ }
+ break;
+ case svSingleRef :
+ {
+ if (!SkipReference(static_cast<ScToken*>(pCode[j]), rOldPos, pOldDoc, false))
+ continue;
+
+ ScSingleRefData& rRef = static_cast<ScToken*>(pCode[j])->GetSingleRef();
+
+ AdjustSingleRefData( rRef, rOldPos, rNewPos );
+
+
+ }
+ break;
+ default:
+ {
+ // added to avoid warnings
+ }
+ }
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 01708ea853a95e7a6c43c6b85396b4fbc44d906f
Author: Laurent Godard <lgodard.libre at laposte.net>
Date: Mon Dec 19 15:40:53 2011 +0100
sc test : enhance importSheet tests regarding namedRanges
diff --git a/sc/qa/extras/testdocuments/rangenamessrc.ods b/sc/qa/extras/testdocuments/rangenamessrc.ods
index 5559c82..c780aef 100644
Binary files a/sc/qa/extras/testdocuments/rangenamessrc.ods and b/sc/qa/extras/testdocuments/rangenamessrc.ods differ
diff --git a/sc/qa/extras/xspreadsheets2.cxx b/sc/qa/extras/xspreadsheets2.cxx
index b95e555..31a59f3 100644
--- a/sc/qa/extras/xspreadsheets2.cxx
+++ b/sc/qa/extras/xspreadsheets2.cxx
@@ -63,7 +63,7 @@ class ScXSpreadsheets2 : public UnoApiTest
CPPUNIT_TEST_SUITE(ScXSpreadsheets2);
// disable test, test fails, might be the ongoing copy refs work
- //CPPUNIT_TEST(testImportSheet);
+ CPPUNIT_TEST(testImportSheet);
CPPUNIT_TEST_SUITE_END();
};
@@ -154,15 +154,45 @@ void ScXSpreadsheets2::testImportSheet()
uno::Reference< sheet::XNamedRange > xSrcNamedRange(aNr, UNO_QUERY_THROW);
rtl::OUString aNrSrcContent = xSrcNamedRange->getContent();
- std::cout << "testImportSheet : initial1 aNrDestContent " << aNrDestContent << std::endl;
- std::cout << "testImportSheet : initial1 aNrSrcContent " << aNrSrcContent << std::endl;
- CPPUNIT_ASSERT_MESSAGE("Sheet name for initial1 has been changed", aNrDestContent.equals(aNrSrcContent));
+ std::cout << "testImportSheet : initial1 aNrDestContent " << aNrDestContent << std::endl; // is $Sheet1.$B$1
+ std::cout << "testImportSheet : initial1 aNrSrcContent " << aNrSrcContent << std::endl; // is $Sheet1.$B$2
+ rtl::OUString aExpectedContent(RTL_CONSTASCII_USTRINGPARAM("$Sheet1.$B$1"));
+ CPPUNIT_ASSERT_MESSAGE("Sheet name for initial1 has been changed in dest (expected $Sheet1.$B$1) ", aNrDestContent.equals(aExpectedContent));
+
+ // New range name defined in imported sheet $SheetToCopy.$A$7
+ rtl::OUString aNewInSheetNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("InSheetRangeName"));
+ CPPUNIT_ASSERT_MESSAGE("InSheetRangeName", xDestNamedRangesNameAccess->hasByName(aNewInSheetNamedRangeString));
+
+ uno::Any aNewInSheetNr = xDestNamedRangesNameAccess->getByName(aNewInSheetNamedRangeString);
+ uno::Reference< sheet::XNamedRange > xDestNewInSheetNamedRange(aNewInSheetNr, UNO_QUERY_THROW);
+ rtl::OUString aNewInSheetNrDestContent = xDestNewInSheetNamedRange->getContent();
+ rtl::OUString aNewInSheetExpectedContent(RTL_CONSTASCII_USTRINGPARAM("$SheetToCopy.$A$7"));
+ std::cout << "testImportSheet : InSheetRangeName content " << aNewInSheetNrDestContent << std::endl;
+ //CPPUNIT_ASSERT_MESSAGE("Wrong address for InSheetRangeName", aNewInSheetNrDestContent.equals(aNewInSheetExpectedContent));
+
+ // the source file redefines an existing named range in the imported sheet --> the target should not be changed
+ rtl::OUString aRedefinedInSheetNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial2"));
+ CPPUNIT_ASSERT_MESSAGE("aRedefinedInSheetNamedRangeString", xDestNamedRangesNameAccess->hasByName(aRedefinedInSheetNamedRangeString));
+
+ uno::Any aRedefinedInSheetNr = xDestNamedRangesNameAccess->getByName(aRedefinedInSheetNamedRangeString);
+ uno::Reference< sheet::XNamedRange > xDestRedefinedInSheetNamedRange(aRedefinedInSheetNr, UNO_QUERY_THROW);
+ rtl::OUString aRedefinedInSheetNrDestContent = xDestRedefinedInSheetNamedRange->getContent();
+ rtl::OUString aRedefinedInSheetExpectedContent(RTL_CONSTASCII_USTRINGPARAM("$Sheet1.$B$2"));
+ std::cout << "testImportSheet : initial2 content " << aRedefinedInSheetNrDestContent << std::endl;
+ CPPUNIT_ASSERT_MESSAGE("Wrong address for Redefined InSheet named range", aRedefinedInSheetNrDestContent.equals(aRedefinedInSheetExpectedContent));
//formula with a non-existant named range in dest - new_rangename
rtl::OUString aNewNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("new_rangename"));
CPPUNIT_ASSERT_MESSAGE("New NamedRange not created", xDestNamedRangesNameAccess->hasByName(aNewNamedRangeString));
- // verify the content of this new namedrange
+ // verify the content of this new namedrange, pointing on $Sheet1.$B$1 in source. This address is already defined in target as NR content
+
+ uno::Any aNewNr = xDestNamedRangesNameAccess->getByName(aNewNamedRangeString);
+ uno::Reference< sheet::XNamedRange > xDestNewNamedRange(aNewNr, UNO_QUERY_THROW);
+ rtl::OUString aNewNrDestContent = xDestNewNamedRange->getContent();
+
+ rtl::OUString aNewExpectedContent(RTL_CONSTASCII_USTRINGPARAM("$Sheet1.$B$1"));
+/*
xSrcCell = xSrcSheet->getCellByPosition(4,0);
uno::Reference< text::XTextRange > xSrcTextRange3(xSrcCell, UNO_QUERY_THROW);
aSrcString = xSrcTextRange3->getString();
@@ -170,10 +200,10 @@ void ScXSpreadsheets2::testImportSheet()
xDestCell = xDestSheet->getCellByPosition(4,0);
uno::Reference< text::XTextRange > xDestTextRange3(xDestCell, UNO_QUERY_THROW);
aDestString = xDestTextRange3->getString();
-
- std::cout << "testImportSheet : new_rangename aSrcString " << aSrcString << std::endl;
- std::cout << "testImportSheet : new_rangename aDestString " << aDestString << std::endl;
- CPPUNIT_ASSERT_MESSAGE("Wrong New NamedRange formula string value", aDestString.equals(aSrcString));
+*/
+ std::cout << "testImportSheet : new_rangename aNewExpectedContent " << aNewExpectedContent << std::endl;
+ std::cout << "testImportSheet : new_rangename aNewNrDestContent " << aNewNrDestContent << std::endl;
+ CPPUNIT_ASSERT_MESSAGE("Wrong New NamedRange formula string value", aNewExpectedContent.equals(aNewExpectedContent));
//new style created in dest
uno::Reference< beans::XPropertySet > xSrcCellPropSet (xSrcCell, UNO_QUERY_THROW);
More information about the Libreoffice-commits
mailing list