summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2013-05-24 09:52:12 +0100
committerNoel Power <noel.power@suse.com>2013-05-27 19:44:49 +0100
commitf3611760f307949a17bfdcceadb3c6a7bfb20952 (patch)
treeabc3e51dd882f7d1fbfaede8d576de7ba1013b64 /sc
parentfc861c7088e9b639a1c2c80f8ba4535c798aeb34 (diff)
reorg styles code slightly, process normal (and row ) style in own method
Change-Id: I701d12cf8f672824d7cfca1e995f02040fdd3095
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/inc/sheetdatabuffer.hxx19
-rw-r--r--sc/source/filter/oox/sheetdatabuffer.cxx158
2 files changed, 89 insertions, 88 deletions
diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx b/sc/source/filter/inc/sheetdatabuffer.hxx
index 103418aa7d7a..563145e2e210 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -192,7 +192,7 @@ private:
/** Writes all cell formatting attributes to the passed cell range list. (depreciates writeXfIdRangeProperties) */
void writeXfIdRangeListProperties( sal_Int32 nXfId, sal_Int32 nNumFmtId, const ApiCellRangeList& rRanges ) const;
void applyCellMerging( const ::com::sun::star::table::CellRangeAddress& rRange );
-
+ void addColXfStyle( sal_Int32 nXfId, sal_Int32 nFormatId, const ::com::sun::star::table::CellRangeAddress& rAddress, bool bProcessRowRange = false );
private:
/** Stores cell range address and formula token array of an array formula. */
typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, ApiTokenSequence > ArrayFormula;
@@ -217,6 +217,22 @@ private:
typedef ::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey;
typedef ::std::map< XfIdNumFmtKey, ApiCellRangeList > XfIdRangeListMap;
+ typedef ::std::pair< sal_Int32, sal_Int32 > RowRange;
+ struct RowRangeStyle
+ {
+ sal_Int32 mnStartRow;
+ sal_Int32 mnEndRow;
+ XfIdNumFmtKey mnNumFmt;
+ };
+ struct StyleRowRangeComp
+ {
+ bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
+ {
+ return lhs.mnEndRow<rhs.mnStartRow;
+ }
+ };
+ typedef ::std::set< RowRangeStyle, StyleRowRangeComp > RowStyles;
+ typedef ::std::map< sal_Int32, RowStyles > ColStyles;
/** Stores information about a merged cell range. */
struct MergedRange
{
@@ -230,6 +246,7 @@ private:
};
typedef ::std::list< MergedRange > MergedRangeList;
+ ColStyles maStylesPerColumn; /// Stores cell styles by column ( in row ranges )
CellBlockBuffer maCellBlocks; /// Manages all open cell blocks.
ArrayFormulaList maArrayFormulas; /// All array formulas in the sheet.
TableOperationList maTableOperations; /// All table operations in the sheet.
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx
index 48b5e8ec709a..174842a001bc 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -346,6 +346,66 @@ void addIfNotInMyMap( StylesBuffer& rStyles, std::map< std::pair< sal_Int32, sal
}
}
+void SheetDataBuffer::addColXfStyle( sal_Int32 nXfId, sal_Int32 nFormatId, const ::com::sun::star::table::CellRangeAddress& rAddress, bool bProcessRowRange )
+{
+ RowRangeStyle aStyleRows;
+ aStyleRows.mnNumFmt.first = nXfId;
+ aStyleRows.mnNumFmt.second = nFormatId;
+ aStyleRows.mnStartRow = rAddress.StartRow;
+ aStyleRows.mnEndRow = rAddress.EndRow;
+ for ( sal_Int32 nCol = rAddress.StartColumn; nCol <= rAddress.EndColumn; ++nCol )
+ {
+ if ( !bProcessRowRange )
+ maStylesPerColumn[ nCol ].insert( aStyleRows );
+ else
+ {
+ RowStyles& rRowStyles = maStylesPerColumn[ nCol ];
+ // If the rowrange style includes rows already
+ // allocated to a style then we need to split
+ // the range style Rows into sections ( to
+ // occupy only rows that have no style definition )
+
+ // We dont want to set any rowstyle 'rows'
+ // for rows where there is an existing 'style' )
+ std::vector< RowRangeStyle > aRangeRowsSplits;
+
+ RowStyles::iterator rows_it = rRowStyles.begin();
+ RowStyles::iterator rows_end = rRowStyles.end();
+ bool bAddRange = true;
+ for ( ; rows_it != rows_end; ++rows_it )
+ {
+ const RowRangeStyle& r = *rows_it;
+ // if row is completely within existing style, discard it
+ if ( aStyleRows.mnStartRow >= r.mnStartRow && aStyleRows.mnEndRow <= r.mnEndRow )
+ bAddRange = false;
+ else if ( aStyleRows.mnStartRow <= r.mnStartRow )
+ {
+ // not intersecting at all?, if so finish as none left
+ // to check ( row ranges are in ascending order
+ if ( aStyleRows.mnEndRow < r.mnStartRow )
+ break;
+ else if ( aStyleRows.mnEndRow <= r.mnEndRow )
+ {
+ aStyleRows.mnEndRow = r.mnStartRow - 1;
+ break;
+ }
+ if ( aStyleRows.mnStartRow < r.mnStartRow )
+ {
+ RowRangeStyle aSplit = aStyleRows;
+ aSplit.mnEndRow = r.mnStartRow - 1;
+ aRangeRowsSplits.push_back( aSplit );
+ }
+ }
+ }
+ std::vector< RowRangeStyle >::iterator splits_it = aRangeRowsSplits.begin();
+ std::vector< RowRangeStyle >::iterator splits_end = aRangeRowsSplits.end();
+ for ( ; splits_it != splits_end; ++splits_it )
+ rRowStyles.insert( *splits_it );
+ if ( bAddRange )
+ rRowStyles.insert( aStyleRows );
+ }
+ }
+}
void SheetDataBuffer::finalizeImport()
{
// insert all cells of all open cell blocks
@@ -362,49 +422,19 @@ void SheetDataBuffer::finalizeImport()
// write default formatting of remaining row range
maXfIdRowRangeList[ maXfIdRowRange.mnXfId ].push_back( maXfIdRowRange.maRowRange );
- typedef ::std::pair< sal_Int32, sal_Int32 > RowRange;
- struct RowRangeStyle
- {
- sal_Int32 mnStartRow;
- sal_Int32 mnEndRow;
- XfIdNumFmtKey mnNumFmt;
- };
- struct StyleRowRangeComp
- {
- bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
- {
- return lhs.mnEndRow<rhs.mnStartRow;
- }
- };
-
- typedef ::std::set< RowRangeStyle, StyleRowRangeComp > RowStyles;
- typedef ::std::map< sal_Int32, RowStyles > ColStyles;
-
- ColStyles aStylesPerColumn;
- StylesBuffer& rStyles = getStyles();
-
std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList > rangeStyleListMap;
-
for( XfIdRangeListMap::const_iterator aIt = maXfIdRangeLists.begin(), aEnd = maXfIdRangeLists.end(); aIt != aEnd; ++aIt )
+ {
addIfNotInMyMap( getStyles(), rangeStyleListMap, aIt->first.first, aIt->first.second, aIt->second );
-
+ }
// gather all ranges that have the same style and apply them in bulk
for ( std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rangeStyleListMap.begin(), it_end = rangeStyleListMap.end(); it != it_end; ++it )
{
const ApiCellRangeList& rRanges( it->second );
for ( ApiCellRangeList::const_iterator it_range = rRanges.begin(), it_rangeend = rRanges.end(); it_range!=it_rangeend; ++it_range )
- {
- RowRangeStyle aStyleRows;
- aStyleRows.mnNumFmt.first = it->first.first;
- aStyleRows.mnNumFmt.second = it->first.second;
- aStyleRows.mnStartRow = it_range->StartRow;
- aStyleRows.mnEndRow = it_range->EndRow;
- for ( sal_Int32 nCol = it_range->StartColumn; nCol <= it_range->EndColumn; ++nCol )
- aStylesPerColumn[ nCol ].insert( aStyleRows );
- }
+ addColXfStyle( it->first.first, it->first.second, *it_range );
}
- // process row ranges for each column, don't overwrite any existing row entries for a column
for ( std::map< sal_Int32, std::vector< ValueRange > >::iterator it = maXfIdRowRangeList.begin(), it_end = maXfIdRowRangeList.end(); it != it_end; ++it )
{
ApiCellRangeList rangeList;
@@ -412,64 +442,17 @@ void SheetDataBuffer::finalizeImport()
// get all row ranges for id
for ( std::vector< ValueRange >::iterator rangeIter = it->second.begin(), rangeIter_end = it->second.end(); rangeIter != rangeIter_end; ++rangeIter )
{
- RowRangeStyle aStyleRows;
- aStyleRows.mnNumFmt.first = it->first;
- if ( aStyleRows.mnNumFmt.first == -1 ) // dud
+ if ( it->first == -1 ) // it's a dud skip it
continue;
- aStyleRows.mnNumFmt.second = -1;
- aStyleRows.mnStartRow = rangeIter->mnFirst;
- aStyleRows.mnEndRow = rangeIter->mnLast;
- for ( sal_Int32 nCol = 0; nCol <= rAddrConv.getMaxApiAddress().Column; ++nCol )
- {
- RowStyles& rRowStyles = aStylesPerColumn[ nCol ];
- // If the rowrange style includes rows already
- // allocated to a style then we need to split
- // the range style Rows into sections ( to
- // occupy only rows that have no style definition )
-
- // We dont want to set any rowstyle 'rows'
- // for rows where there is an existing 'style' )
- std::vector< RowRangeStyle > aRangeRowsSplits;
-
- RowStyles::iterator rows_it = rRowStyles.begin();
- RowStyles::iterator rows_end = rRowStyles.end();
- bool bAddRange = true;
- for ( ; rows_it != rows_end; ++rows_it )
- {
- const RowRangeStyle& r = *rows_it;
- // if row is completely within existing style, discard it
- if ( aStyleRows.mnStartRow >= r.mnStartRow && aStyleRows.mnEndRow <= r.mnEndRow )
- bAddRange = false;
- else if ( aStyleRows.mnStartRow <= r.mnStartRow )
- {
- // not intersecting at all?, if so finish as none left
- // to check ( row ranges are in ascending order
- if ( aStyleRows.mnEndRow < r.mnStartRow )
- break;
- else if ( aStyleRows.mnEndRow <= r.mnEndRow )
- {
- aStyleRows.mnEndRow = r.mnStartRow - 1;
- break;
- }
- if ( aStyleRows.mnStartRow < r.mnStartRow )
- {
- RowRangeStyle aSplit = aStyleRows;
- aSplit.mnEndRow = r.mnStartRow - 1;
- aRangeRowsSplits.push_back( aSplit );
- }
- }
- }
- std::vector< RowRangeStyle >::iterator splits_it = aRangeRowsSplits.begin();
- std::vector< RowRangeStyle >::iterator splits_end = aRangeRowsSplits.end();
- for ( ; splits_it != splits_end; ++splits_it )
- rRowStyles.insert( *splits_it );
- if ( bAddRange )
- rRowStyles.insert( aStyleRows );
- }
+ CellRangeAddress aRange( getSheetIndex(), 0, rangeIter->mnFirst, rAddrConv.getMaxApiAddress().Column, rangeIter->mnLast );
+
+ addColXfStyle( it->first, -1, aRange, true );
}
}
+
ScDocument& rDoc = getScDocument();
- for ( ColStyles::iterator col = aStylesPerColumn.begin(), col_end = aStylesPerColumn.end(); col != col_end; ++col )
+ StylesBuffer& rStyles = getStyles();
+ for ( ColStyles::iterator col = maStylesPerColumn.begin(), col_end = maStylesPerColumn.end(); col != col_end; ++col )
{
RowStyles& rRowStyles = col->second;
std::list<ScAttrEntry> aAttrs;
@@ -497,6 +480,7 @@ void SheetDataBuffer::finalizeImport()
rDoc.SetAttrEntries(nScCol, getSheetIndex(), pData, static_cast<SCSIZE>(nAttrSize));
}
+
// merge all cached merged ranges and update right/bottom cell borders
for( MergedRangeList::iterator aIt = maMergedRanges.begin(), aEnd = maMergedRanges.end(); aIt != aEnd; ++aIt )
applyCellMerging( aIt->maRange );