#79771#; implements and use a better AddRange method

This commit is contained in:
Sascha Ballach 2001-06-20 13:23:54 +00:00
parent f10041f7f9
commit e1fdbf27e6
4 changed files with 95 additions and 25 deletions

View file

@ -2,9 +2,9 @@
*
* $RCSfile: XMLStylesImportHelper.cxx,v $
*
* $Revision: 1.5 $
* $Revision: 1.6 $
*
* last change: $Author: sab $ $Date: 2001-06-11 05:48:08 $
* last change: $Author: sab $ $Date: 2001-06-20 14:23:54 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -289,11 +289,11 @@ void ScMyStyleRanges::SetStylesToRanges(const rtl::OUString& rStyleName, ScXMLIm
//----------------------------------------------------------------------------
ScMyStylesImportHelper::ScMyStylesImportHelper(const rtl::OUString& rPrefix)
ScMyStylesImportHelper::ScMyStylesImportHelper()
:
aCellStyles(),
aColDefaultStyles(),
sPrefix(rPrefix)
bPrevRangeAdded(sal_True)
{
aRowDefaultStyle = aCellStyles.end();
}
@ -304,6 +304,9 @@ ScMyStylesImportHelper::~ScMyStylesImportHelper()
void ScMyStylesImportHelper::ResetAttributes()
{
sPrevStyleName = sStyleName;
sPrevCurrency = sCurrency;
nPrevCellType = nCellType;
sStyleName = sEmpty;
sCurrency = sEmpty;
nCellType = 0;
@ -345,7 +348,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
ScRange aRange(rRange);
aRange.aStart.SetCol(static_cast<sal_uInt16>(nStartCol));
aRange.aEnd.SetCol(i - 1);
sStyleName = aPrevItr->sStyleName;
sPrevStyleName = aPrevItr->sStyleName;
AddSingleRange(aRange);
nStartCol = i;
aPrevItr = aColDefaultStyles[i];
@ -354,28 +357,37 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
DBG_ASSERT(aPrevItr != aCellStyles.end(), "no column default style")
ScRange aRange(rRange);
aRange.aStart.SetCol(static_cast<sal_uInt16>(nStartCol));
sStyleName = aPrevItr->sStyleName;
sPrevStyleName = aPrevItr->sStyleName;
AddSingleRange(aRange);
}
else
{
sStyleName = aRowDefaultStyle->sStyleName;
sPrevStyleName = aRowDefaultStyle->sStyleName;
AddSingleRange(rRange);
}
}
void ScMyStylesImportHelper::AddSingleRange(const ScRange& rRange)
{
ScMyStylesSet::iterator aItr = GetIterator(sStyleName);
ScMyStylesSet::iterator aItr = GetIterator(sPrevStyleName);
if (aItr != aCellStyles.end())
{
if (nCellType != util::NumberFormat::CURRENCY)
aItr->xRanges->AddRange(rRange, nCellType);
if (nPrevCellType != util::NumberFormat::CURRENCY)
aItr->xRanges->AddRange(rRange, nPrevCellType);
else
aItr->xRanges->AddCurrencyRange(rRange, sCurrency);
aItr->xRanges->AddCurrencyRange(rRange, sPrevCurrency);
}
}
void ScMyStylesImportHelper::AddRange()
{
if (sPrevStyleName.getLength())
AddSingleRange(aPrevRange);
else
AddDefaultRange(aPrevRange);
ResetAttributes();
}
void ScMyStylesImportHelper::AddColumnStyle(const rtl::OUString& sStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat)
{
DBG_ASSERT(static_cast<sal_uInt32>(nColumn) == aColDefaultStyles.size(), "some columns are absent");
@ -400,11 +412,51 @@ void ScMyStylesImportHelper::SetAttributes(const rtl::OUString& sStyleName,
void ScMyStylesImportHelper::AddRange(const ScRange& rRange)
{
if (sStyleName.getLength())
AddSingleRange(rRange);
if (!bPrevRangeAdded)
{
sal_Bool bAddRange(sal_False);
if (nCellType == nPrevCellType &&
sStyleName.equals(sPrevStyleName) &&
sCurrency.equals(sPrevCurrency))
{
if (rRange.aStart.Row() == aPrevRange.aStart.Row())
{
if (rRange.aEnd.Row() == aPrevRange.aEnd.Row())
{
DBG_ASSERT(aPrevRange.aEnd.Col() + 1 == rRange.aStart.Col(), "something wents wrong");
aPrevRange.aEnd.SetCol(rRange.aEnd.Col());
}
else
bAddRange = sal_True;
}
else
{
if (rRange.aStart.Col() == aPrevRange.aStart.Col() &&
rRange.aEnd.Col() == aPrevRange.aEnd.Col())
{
DBG_ASSERT(aPrevRange.aEnd.Row() + 1 == rRange.aStart.Row(), "something wents wrong");
aPrevRange.aEnd.SetRow(rRange.aEnd.Row());
}
else
bAddRange = sal_True;
}
}
else
bAddRange = sal_True;
if (bAddRange)
{
AddRange();
aPrevRange = rRange;
}
}
else
AddDefaultRange(rRange);
ResetAttributes();
{
aPrevRange = rRange;
sPrevStyleName = sStyleName;
sPrevCurrency = sCurrency;
nPrevCellType = nCellType;
bPrevRangeAdded = sal_False;
}
}
void ScMyStylesImportHelper::AddRange(const com::sun::star::table::CellRangeAddress& rRange)
@ -447,6 +499,15 @@ void ScMyStylesImportHelper::InsertCol(const sal_Int32 nCol, const sal_Int32 nTa
}
}
void ScMyStylesImportHelper::EndTable()
{
if (!bPrevRangeAdded)
{
AddRange();
bPrevRangeAdded = sal_True;
}
}
void ScMyStylesImportHelper::SetStylesToRanges(ScXMLImport& rImport)
{
ScMyStylesSet::iterator aItr = aCellStyles.begin();

View file

@ -2,9 +2,9 @@
*
* $RCSfile: XMLStylesImportHelper.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: sab $ $Date: 2001-06-11 05:48:08 $
* last change: $Author: sab $ $Date: 2001-06-20 14:23:54 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -190,18 +190,23 @@ class ScMyStylesImportHelper
ScMyStylesSet aCellStyles;
ScMyStyles aColDefaultStyles;
ScMyStylesSet::iterator aRowDefaultStyle;
rtl::OUString sPrefix;
rtl::OUString sStyleName;
rtl::OUString sPrevStyleName;
rtl::OUString sCurrency;
rtl::OUString sPrevCurrency;
rtl::OUString sEmpty;
ScRange aPrevRange;
sal_Int16 nCellType;
sal_Int16 nPrevCellType;
sal_Bool bPrevRangeAdded;
void ResetAttributes();
ScMyStylesSet::iterator GetIterator(const rtl::OUString& sStyleName);
void AddDefaultRange(const ScRange& rRange);
void AddSingleRange(const ScRange& rRange);
void AddRange();
public:
ScMyStylesImportHelper(const rtl::OUString& rPrefix);
ScMyStylesImportHelper();
~ScMyStylesImportHelper();
void AddColumnStyle(const rtl::OUString& rStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat);
void SetRowStyle(const rtl::OUString& rStyleName);
@ -213,6 +218,7 @@ public:
void AddCell(const com::sun::star::table::CellAddress& rAddress);
void InsertRow(const sal_Int32 nRow, const sal_Int32 nTab, ScDocument* pDoc); // a row is inserted before nRow
void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc); // a col is inserted before nCol
void EndTable();
void SetStylesToRanges(ScXMLImport& rImport);
};

View file

@ -2,9 +2,9 @@
*
* $RCSfile: xmlimprt.cxx,v $
*
* $Revision: 1.59 $
* $Revision: 1.60 $
*
* last change: $Author: dvo $ $Date: 2001-06-15 17:22:36 $
* last change: $Author: sab $ $Date: 2001-06-20 14:23:54 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -1491,8 +1491,7 @@ ScXMLImport::ScXMLImport(const sal_uInt16 nImportFlag) :
sXML_n_text, XML_NAMESPACE_TEXT );
GetNamespaceMap().AddAtIndex( XML_NAMESPACE_TABLE, sXML_np__table,
sXML_n_table, XML_NAMESPACE_TABLE );*/
pStylesImportHelper = new ScMyStylesImportHelper(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX)));
pStylesImportHelper = new ScMyStylesImportHelper();
xScPropHdlFactory = new XMLScPropHdlFactory;
xCellStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScCellStylesProperties, xScPropHdlFactory);

View file

@ -2,9 +2,9 @@
*
* $RCSfile: xmltabi.cxx,v $
*
* $Revision: 1.20 $
* $Revision: 1.21 $
*
* last change: $Author: fs $ $Date: 2001-03-20 15:09:00 $
* last change: $Author: sab $ $Date: 2001-06-20 14:23:54 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -86,6 +86,9 @@
#ifndef _SC_XMLTABLESOURCECONTEXT_HXX
#include "XMLTableSourceContext.hxx"
#endif
#ifndef _SC_XMLSTYLESIMPORTHELPER_HXX
#include "XMLStylesImportHelper.hxx"
#endif
#include <xmloff/xmltkmap.hxx>
#include <xmloff/nmspmap.hxx>
@ -240,6 +243,7 @@ SvXMLImportContext *ScXMLTableContext::CreateChildContext( USHORT nPrefix,
void ScXMLTableContext::EndElement()
{
GetScImport().GetStylesImportHelper()->EndTable();
ScDocument* pDoc = GetScImport().GetDocument();
if (sPrintRanges.getLength())
{