sc/source/filter/xml/xmlcelli.cxx | 68 ++++++++++---------------------------- sc/source/filter/xml/xmlcelli.hxx | 4 +- sc/source/filter/xml/xmlsubti.cxx | 32 +---------------- 3 files changed, 24 insertions(+), 80 deletions(-)
New commits: commit 14be196c746fe307ddc7b4abbedf00df62c7dcac Author: Daniel Bankston <daniel.e.banks...@gmail.com> Date: Fri May 25 17:22:21 2012 -0500 Remove unnecessary code in ODS import for matrix and merge MyScTables matrix methods and ScXMLTableRowCellContext merge methods used getCellRangePosition() (that was adopted from ScCellRangeObj) which contains logic that is no longer necessary since since the UNO calls have been converted to direct Sc calls. Change-Id: Ibfa335860d142effb120d3e4f28a36d3d3c58666 diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index e7e0bf4..305a478 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -462,29 +462,6 @@ static bool ScCellExists( const ScAddress& rScAddress ) return( rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW ); } -ScRange getCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom ) -{ - if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 ) - { - SCCOL nStartX = rScRange.aStart.Col() + nLeft; - SCROW nStartY = rScRange.aStart.Row() + nTop; - SCCOL nEndX = rScRange.aStart.Col() + nRight; - SCROW nEndY = rScRange.aStart.Row() + nBottom; - - if( nStartX <= nEndX && nEndX <= rScRange.aEnd.Col() && - nStartY <= nEndY && nEndY <= rScRange.aEnd.Row() ) - { - return ScRange( nStartX, nStartY, rScRange.aStart.Tab(), nEndX, nEndY, rScRange.aEnd.Tab() ); - } - } - return ScRange( ScAddress::INITIALIZE_INVALID ); -} - -ScRange getCellRangeByPosition( const ScRange& rScRange, const ScAddress& rScCell ) -{ - return getCellRangeByPosition( rScRange, rScCell.Col(), rScCell.Row(), rScCell.Col(), rScCell.Row() ); -} - void merge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge ) { if( pDocSh ) @@ -503,18 +480,16 @@ void merge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge ) } //anonymous namespace -bool ScXMLTableRowCellContext::IsMerged( const ScRange& rScRange, const ScAddress& rScCell, ScRange& rScCellRange ) const +bool ScXMLTableRowCellContext::IsMerged( ScRange& rScRange, const ScAddress& rScCell ) const { if( ScCellExists(rScCell) ) { ScDocument* pDoc = rXMLImport.GetDocument(); - rScCellRange = getCellRangeByPosition( rScRange, rScCell ); - if( !rScRange.IsValid() ) return false; - pDoc->ExtendOverlapped( rScCellRange ); - pDoc->ExtendMerge( rScCellRange ); - rScCellRange.Justify(); - if( rScCellRange.aStart.Col() == rScCell.Col() && rScCellRange.aEnd.Col() == rScCell.Col() && - rScCellRange.aStart.Row() == rScCell.Row() && rScCellRange.aEnd.Row() == rScCell.Row() ) + pDoc->ExtendOverlapped( rScRange ); + pDoc->ExtendMerge( rScRange ); + rScRange.Justify(); + if( rScRange.aStart.Col() == rScCell.Col() && rScRange.aEnd.Col() == rScCell.Col() && + rScRange.aStart.Row() == rScCell.Row() && rScRange.aEnd.Row() == rScCell.Row() ) return false; else return true; @@ -522,32 +497,27 @@ bool ScXMLTableRowCellContext::IsMerged( const ScRange& rScRange, const ScAddres return false; } -void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScCellPos, const sal_Int32 nCols, const sal_Int32 nRows ) +void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows ) { if( ScCellExists(rScCellPos) ) { - ScRange aScCellRange; SCTAB nCurrentSheet = GetScImport().GetTables().GetCurrentSheet(); - ScRange aScRange( 0, 0, nCurrentSheet, MAXCOL, MAXROW, nCurrentSheet ); //the whole sheet + ScRange aScRange( + rScCellPos.Col(), rScCellPos.Row(), nCurrentSheet, + rScCellPos.Col(), rScCellPos.Row(), nCurrentSheet + ); ScDocShell* pDocSh = static_cast< ScDocShell* >( rXMLImport.GetDocument()->GetDocumentShell() ); - if( IsMerged(aScRange, rScCellPos, aScCellRange) ) + if( IsMerged(aScRange, rScCellPos) ) { //unmerge - ScRange aScMergeRange( - getCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(), - aScCellRange.aEnd.Col(), aScCellRange.aEnd.Row() ) - ); - if( aScMergeRange.IsValid() ) - merge( pDocSh, aScMergeRange, false ); + merge( pDocSh, aScRange, false ); } - //merge - ScRange aScMergeRange( - getCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(), - aScCellRange.aEnd.Col() + nCols, aScCellRange.aEnd.Row() + nRows ) - ); - if( aScMergeRange.IsValid() ) - merge( pDocSh, aScMergeRange, true ); + SCCOL newEndCol = aScRange.aStart.Col() + nCols; + SCROW newEndRow = aScRange.aStart.Row() + nRows; + aScRange.aEnd.SetCol( newEndCol ); + aScRange.aEnd.SetRow( newEndRow ); + merge( pDocSh, aScRange, true ); } } @@ -828,7 +798,7 @@ void ScXMLTableRowCellContext::EndElement() if (xCellRange.is()) { if (bIsMerged) - DoMerge(aScCellPos, nMergedCols - 1, nMergedRows - 1); + DoMerge(aScCellPos, static_cast<SCCOL>(nMergedCols - 1), static_cast<SCROW>(nMergedRows - 1)); if ( !pOUFormula ) { ::boost::optional< rtl::OUString > pOUText; diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx index 4f8b4f9..9cdcac5 100644 --- a/sc/source/filter/xml/xmlcelli.hxx +++ b/sc/source/filter/xml/xmlcelli.hxx @@ -82,8 +82,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext sal_Int16 GetCellType(const rtl::OUString& sOUValue) const; - bool IsMerged(const ScRange& rScRange, const ScAddress& rScCell, ScRange& rScCellAddress) const; - void DoMerge(const ScAddress& rScCellPos, const sal_Int32 nCols, const sal_Int32 nRows); + bool IsMerged(ScRange& rScRange, const ScAddress& rScCell) const; + void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows); void SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet); void SetCellProperties(const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange, diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx index 9342961..b830a6f 100644 --- a/sc/source/filter/xml/xmlsubti.cxx +++ b/sc/source/filter/xml/xmlsubti.cxx @@ -804,44 +804,18 @@ bool ScMyTables::IsPartOfMatrix(const SCCOL nColumn, const SCROW nRow) return bResult; } -namespace { - -ScRange getCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom ) -{ - if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 ) - { - SCCOL nStartX = rScRange.aStart.Col() + nLeft; - SCROW nStartY = rScRange.aStart.Row() + nTop; - SCCOL nEndX = rScRange.aStart.Col() + nRight; - SCROW nEndY = rScRange.aStart.Row() + nBottom; - - if( nStartX <= nEndX && nEndX <= rScRange.aEnd.Col() && - nStartY <= nEndY && nEndY <= rScRange.aEnd.Row() ) - { - return ScRange( nStartX, nStartY, rScRange.aStart.Tab(), nEndX, nEndY, rScRange.aEnd.Tab() ); - } - } - return ScRange( ScAddress::INITIALIZE_INVALID ); -} - -} //anonymous namespace - void ScMyTables::SetMatrix(const ScRange& rScRange, const rtl::OUString& rFormula, const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar) { - ScRange aWholeSheetRange( 0, 0, nCurrentSheet, MAXCOL, MAXROW, nCurrentSheet ); //the whole sheet - ScRange aMatrixRange( - getCellRangeByPosition( aWholeSheetRange, rScRange.aStart.Col(), rScRange.aStart.Row(), rScRange.aEnd.Col(), rScRange.aEnd.Row() ) - ); ScDocShell* pDocSh = static_cast< ScDocShell* >( rImport.GetDocument()->GetDocumentShell() ); if ( !rFormula.isEmpty() ) - pDocSh->GetDocFunc().EnterMatrix( aMatrixRange, NULL, NULL, rFormula, sal_True, sal_True, rFormulaNmsp, eGrammar ); + pDocSh->GetDocFunc().EnterMatrix( rScRange, NULL, NULL, rFormula, sal_True, sal_True, rFormulaNmsp, eGrammar ); else { // empty string -> erase array formula ScMarkData aMark; - aMark.SetMarkArea( aMatrixRange ); - aMark.SelectTable( aMatrixRange.aStart.Tab(), sal_True ); + aMark.SetMarkArea( rScRange ); + aMark.SelectTable( rScRange.aStart.Tab(), sal_True ); pDocSh->GetDocFunc().DeleteContents( aMark, IDF_CONTENTS, sal_True, sal_True ); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits