diff options
author | Matthew Pottage <matthewpottage@invincitech.com> | 2014-07-26 17:17:27 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2014-07-31 15:48:32 +0000 |
commit | 4c3ba3a413be7339115ea5e6edc825a8434cd345 (patch) | |
tree | a07c20989ba32fede18bce7d449c45ccbbc18430 | |
parent | 8fea536cebefe319a7fd5971b28e0936ac91ecb9 (diff) |
fdo#75757: Remove inheritance from std::map.
Done for writerfilter::dmapper::PropertyMap.
Added public functions getPropertyValue, bool isSet and Erase. The function
getPropertyValue returns boost::optional<PropertyMap::Property>,
where PropertyMap::Property is an alias for std::pair<PropertyIds,css::uno::Any>.
Fixed all resulting compilation errors. The functions which iterated the map
(ListLevel::GetCharStyleProperties, ListLevel::GetLevelProperties and
SectionPropertyMap::_ApplyProperties) have been written to either used
GetPropertyValues or not iterate over the PropertyMap's attributes.
The properties of the public member functions are now properly used
(Erase and Insert(...,false)).
Change-Id: Ibd90a4ad831c9b7d18b2a50d4aa4eb3f2610cff8
Reviewed-on: https://gerrit.libreoffice.org/10558
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 46 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 159 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableManager.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 44 | ||||
-rw-r--r-- | writerfilter/source/dmapper/NumberingManager.cxx | 85 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 230 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.hxx | 35 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SdtHelper.cxx | 12 | ||||
-rw-r--r-- | writerfilter/source/dmapper/StyleSheetTable.cxx | 44 |
9 files changed, 325 insertions, 332 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index c9973c2e0d79..5507934ac13f 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -184,7 +184,6 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) OUString sStringValue = val.getString(); SectionPropertyMap * pSectionContext = m_pImpl->GetSectionContext(); - PropertyMap::iterator oldPropValue; switch( nName ) { case NS_ooxml::LN_CT_Lvl_start: @@ -374,16 +373,10 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) #define SINGLE_LINE_SPACING 240 style::LineSpacing aSpacing; PropertyMapPtr pTopContext = m_pImpl->GetTopContext(); - bool bFound = false; - PropertyMap::iterator aLineSpacingIter; - if (pTopContext) - { - aLineSpacingIter = pTopContext->find(PROP_PARA_LINE_SPACING); - bFound = aLineSpacingIter != pTopContext->end(); - } - if (bFound) + boost::optional<PropertyMap::Property> aLineSpacingVal; + if (pTopContext && (aLineSpacingVal = pTopContext->getProperty(PROP_PARA_LINE_SPACING)) ) { - aLineSpacingIter->second.getValue() >>= aSpacing; + aLineSpacingVal->second >>= aSpacing; } else { @@ -404,7 +397,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) { // direct formatting is applied for table cell data TablePropertyMapPtr pTblCellWithDirectFormatting(new TablePropertyMap); - pTblCellWithDirectFormatting->insert(std::pair< PropertyIds, PropValue >(PROP_PARA_LINE_SPACING, uno::makeAny( aSpacing ))); + pTblCellWithDirectFormatting->Insert(PROP_PARA_LINE_SPACING, uno::makeAny( aSpacing ), false); m_pImpl->getTableManager().cellProps(pTblCellWithDirectFormatting); } } @@ -1035,11 +1028,11 @@ sal_Int32 lcl_getCurrentNumberingProperty( static bool ExchangeLeftRight( const PropertyMapPtr rContext, DomainMapper_Impl* m_pImpl ) { bool bExchangeLeftRight = false; - PropertyMap::const_iterator aPropParaIte = rContext->find(PROP_WRITING_MODE); - if( aPropParaIte != rContext->end()) + boost::optional<PropertyMap::Property> aPropPara = rContext->getProperty(PROP_WRITING_MODE); + if( aPropPara ) { sal_Int32 aAdjust ; - if( (aPropParaIte->second.getValue() >>= aAdjust) && aAdjust == text::WritingMode2::RL_TB ) + if( (aPropPara->second >>= aAdjust) && aAdjust == text::WritingMode2::RL_TB ) bExchangeLeftRight = true; } else @@ -1048,11 +1041,11 @@ static bool ExchangeLeftRight( const PropertyMapPtr rContext, DomainMapper_Impl* StyleSheetEntryPtr pTable = m_pImpl->GetStyleSheetTable()->FindDefaultParaStyle(); if ( pTable ) { - PropertyMap::const_iterator aPropStyle = pTable->pProperties->find(PROP_WRITING_MODE); - if( aPropStyle != pTable->pProperties->end()) + boost::optional<PropertyMap::Property> aPropStyle = pTable->pProperties->getProperty(PROP_WRITING_MODE); + if( aPropStyle ) { sal_Int32 aDirect; - if( (aPropStyle->second.getValue() >>= aDirect) && aDirect == text::WritingMode2::RL_TB ) + if( (aPropStyle->second >>= aDirect) && aDirect == text::WritingMode2::RL_TB ) bExchangeLeftRight = true; } } @@ -1140,7 +1133,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext ) uno::Any aRules = uno::makeAny( pList->GetNumberingRules( ) ); rContext->Insert( PROP_NUMBERING_RULES, aRules ); // erase numbering from pStyle if already set - rContext->erase(PROP_NUMBERING_STYLE_NAME); + rContext->Erase(PROP_NUMBERING_STYLE_NAME); } } else @@ -1511,7 +1504,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext ) break; case NS_ooxml::LN_EG_RPrBase_smallCaps: // If smallcaps would be just disabled and an other casemap is already inserted, don't do anything. - if (nIntValue || rContext->find(ePropertyId) == rContext->end()) + if (nIntValue || !rContext->isSet(ePropertyId) ) rContext->Insert(ePropertyId, uno::makeAny( nIntValue ? style::CaseMap::SMALLCAPS : style::CaseMap::NONE)); m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "smallCaps", OUString::number(nIntValue)); break; @@ -1546,7 +1539,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext ) { // If the default para style contains PROP_CHAR_HEIGHT, that should have priority over the table style. StyleSheetEntryPtr pTable = m_pImpl->GetStyleSheetTable()->FindDefaultParaStyle(); - if (pTable && pTable->pProperties->find(PROP_CHAR_HEIGHT) != pTable->pProperties->end()) + if (pTable && pTable->pProperties->isSet(PROP_CHAR_HEIGHT) ) bIgnore = true; } if (!bIgnore) @@ -2005,7 +1998,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext ) m_pImpl->GetTopContext()->Insert( PROP_PARA_STYLE_NAME, uno::makeAny( sConvertedStyleName )); //apply numbering to paragraph if it was set at the style, but only if the paragraph itself //does not specify the numbering - if( rContext->find(PROP_NUMBERING_RULES) == rContext->end()) // !contains + if( !rContext->isSet(PROP_NUMBERING_RULES) ) // !contains { const StyleSheetEntryPtr pEntry = pStyleTable->FindStyleSheetByISTD(sStringValue); OSL_ENSURE( pEntry.get(), "no style sheet found" ); @@ -2022,8 +2015,9 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext ) { const StyleSheetEntryPtr pParent = pStyleTable->FindStyleSheetByISTD(pEntry->sBaseStyleIdentifier); const StyleSheetPropertyMap* pParentProperties = dynamic_cast<const StyleSheetPropertyMap*>(pParent ? pParent->pProperties.get() : 0); - if (pParentProperties && pParentProperties->find(PROP_PARA_RIGHT_MARGIN) != pParentProperties->end()) - nParaRightMargin = pParentProperties->find(PROP_PARA_RIGHT_MARGIN)->second.getValue().get<sal_Int32>(); + boost::optional<PropertyMap::Property> pPropMargin; + if (pParentProperties && (pPropMargin = pParentProperties->getProperty(PROP_PARA_RIGHT_MARGIN)) ) + nParaRightMargin = pPropMargin->second.get<sal_Int32>(); } if (nParaRightMargin != 0) { @@ -2502,7 +2496,7 @@ void DomainMapper::processDeferredCharacterProperties( const std::map< sal_Int32 { std::map< sal_Int32, uno::Any >::const_iterator font = deferredCharacterProperties.find( NS_ooxml::LN_EG_RPrBase_sz ); PropertyMapPtr pDefaultCharProps = m_pImpl->GetStyleSheetTable()->GetDefaultCharProps(); - PropertyMap::iterator aDefaultFont = pDefaultCharProps->find(PROP_CHAR_HEIGHT); + boost::optional<PropertyMap::Property> aDefaultFont = pDefaultCharProps->getProperty(PROP_CHAR_HEIGHT); if( font != deferredCharacterProperties.end()) { double fontSize = 0; @@ -2510,10 +2504,10 @@ void DomainMapper::processDeferredCharacterProperties( const std::map< sal_Int32 nEscapement = nIntValue * 100 / fontSize; } // TODO if not direct formatting, check the style first, not directly the default char props. - else if (aDefaultFont != pDefaultCharProps->end()) + else if (aDefaultFont) { double fHeight = 0; - aDefaultFont->second.getValue() >>= fHeight; + aDefaultFont->second >>= fHeight; // fHeight is in points, nIntValue is in half points, nEscapement is in percents. nEscapement = nIntValue * 100 / fHeight / 2; } diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 7692597dcd38..401aaebf1f16 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -135,68 +135,64 @@ PropertyMapPtr lcl_SearchParentStyleSheetAndMergeProperties(const StyleSheetEntr void lcl_mergeBorder( PropertyIds nId, PropertyMapPtr pOrig, PropertyMapPtr pDest ) { - PropertyMap::iterator pOrigIt = pOrig->find(nId); + boost::optional<PropertyMap::Property> pOrigVal = pOrig->getProperty(nId); - if ( pOrigIt != pOrig->end( ) ) + if ( pOrigVal ) { - pDest->Insert( nId, pOrigIt->second.getValue(), false ); + pDest->Insert( nId, pOrigVal->second, false ); } } void lcl_computeCellBorders( PropertyMapPtr pTableBorders, PropertyMapPtr pCellProps, sal_Int32 nCell, sal_Int32 nRow, bool bIsEndCol, bool bIsEndRow ) { - PropertyMap::iterator aVerticalIter = pCellProps->find(META_PROP_VERTICAL_BORDER); - PropertyMap::iterator aHorizontalIter = pCellProps->find(META_PROP_HORIZONTAL_BORDER); + boost::optional<PropertyMap::Property> pVerticalVal = pCellProps->getProperty(META_PROP_VERTICAL_BORDER); + boost::optional<PropertyMap::Property> pHorizontalVal = pCellProps->getProperty(META_PROP_HORIZONTAL_BORDER); // Handle the vertical and horizontal borders - bool bHasVert = ( aVerticalIter != pCellProps->end( ) ); uno::Any aVertProp; - if ( !bHasVert ) + if ( !pVerticalVal) { - aVerticalIter = pTableBorders->find(META_PROP_VERTICAL_BORDER); - bHasVert = ( aVerticalIter != pTableBorders->end( ) ); - if ( bHasVert ) - aVertProp = aVerticalIter->second.getValue(); + pVerticalVal = pTableBorders->getProperty(META_PROP_VERTICAL_BORDER); + if ( pVerticalVal ) + aVertProp = pVerticalVal->second; } else { - aVertProp = aVerticalIter->second.getValue(); - pCellProps->erase( aVerticalIter ); + aVertProp = pVerticalVal->second; + pCellProps->Erase( pVerticalVal->first ); } - bool bHasHoriz = ( aHorizontalIter != pCellProps->end( ) ); uno::Any aHorizProp; - if ( !bHasHoriz ) + if ( !pHorizontalVal ) { - aHorizontalIter = pTableBorders->find(META_PROP_HORIZONTAL_BORDER); - bHasHoriz = ( aHorizontalIter != pTableBorders->end( ) ); - if ( bHasHoriz ) - aHorizProp = aHorizontalIter->second.getValue(); + pHorizontalVal = pTableBorders->getProperty(META_PROP_HORIZONTAL_BORDER); + if ( pHorizontalVal ) + aHorizProp = pHorizontalVal->second; } else { - aHorizProp = aHorizontalIter->second.getValue(); - pCellProps->erase( aHorizontalIter ); + aHorizProp = pHorizontalVal->second; + pCellProps->Erase( pHorizontalVal->first ); } if ( nCell == 0 ) { lcl_mergeBorder( PROP_LEFT_BORDER, pTableBorders, pCellProps ); - if ( bHasVert ) + if ( pVerticalVal ) pCellProps->Insert( PROP_RIGHT_BORDER, aVertProp, false ); } if ( bIsEndCol ) { lcl_mergeBorder( PROP_RIGHT_BORDER, pTableBorders, pCellProps ); - if ( bHasVert ) + if ( pVerticalVal ) pCellProps->Insert( PROP_LEFT_BORDER, aVertProp, false ); } if ( nCell > 0 && !bIsEndCol ) { - if ( bHasVert ) + if ( pVerticalVal ) { pCellProps->Insert( PROP_RIGHT_BORDER, aVertProp, false ); pCellProps->Insert( PROP_LEFT_BORDER, aVertProp, false ); @@ -206,20 +202,20 @@ void lcl_computeCellBorders( PropertyMapPtr pTableBorders, PropertyMapPtr pCellP if ( nRow == 0 ) { lcl_mergeBorder( PROP_TOP_BORDER, pTableBorders, pCellProps ); - if ( bHasHoriz ) + if ( pHorizontalVal ) pCellProps->Insert( PROP_BOTTOM_BORDER, aHorizProp, false ); } if ( bIsEndRow ) { lcl_mergeBorder( PROP_BOTTOM_BORDER, pTableBorders, pCellProps ); - if ( bHasHoriz ) + if ( pHorizontalVal ) pCellProps->Insert( PROP_TOP_BORDER, aHorizProp, false ); } if ( nRow > 0 && !bIsEndRow ) { - if ( bHasHoriz ) + if ( pHorizontalVal ) { pCellProps->Insert( PROP_TOP_BORDER, aHorizProp, false ); pCellProps->Insert( PROP_BOTTOM_BORDER, aHorizProp, false ); @@ -293,15 +289,13 @@ namespace bool lcl_extractTableBorderProperty(PropertyMapPtr pTableProperties, const PropertyIds nId, TableInfo& rInfo, table::BorderLine2& rLine) { - PropertyMap::iterator aTblBorderIter = pTableProperties->find(nId); - if( aTblBorderIter != pTableProperties->end() ) + const boost::optional<PropertyMap::Property> aTblBorder = pTableProperties->getProperty(nId); + if( aTblBorder ) { - OSL_VERIFY(aTblBorderIter->second.getValue() >>= rLine); + OSL_VERIFY(aTblBorder->second >>= rLine); rInfo.pTableBorders->Insert( nId, uno::makeAny( rLine ) ); - PropertyMap::iterator pIt = rInfo.pTableDefaults->find(nId); - if ( pIt != rInfo.pTableDefaults->end( ) ) - rInfo.pTableDefaults->erase( pIt ); + rInfo.pTableDefaults->Erase( nId ); return true; } @@ -356,8 +350,6 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo sal_Int32 nTableWidth = 0; sal_Int32 nTableWidthType = text::SizeType::FIX; - PropertyMap::iterator aTableStyleIter = - m_aTableProperties->find(META_PROP_TABLE_STYLE_NAME); uno::Sequence< beans::PropertyValue > aGrabBag( 6 ); sal_Int32 nGrabBagSize = 0; @@ -402,15 +394,16 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo nGrabBagSize++; } - if(aTableStyleIter != m_aTableProperties->end()) + boost::optional<PropertyMap::Property> aTableStyleVal = m_aTableProperties->getProperty(META_PROP_TABLE_STYLE_NAME); + if(aTableStyleVal) { // Apply table style properties recursively OUString sTableStyleName; - aTableStyleIter->second.getValue() >>= sTableStyleName; + aTableStyleVal->second >>= sTableStyleName; StyleSheetTablePtr pStyleSheetTable = m_rDMapper_Impl.GetStyleSheetTable(); const StyleSheetEntryPtr pStyleSheet = pStyleSheetTable->FindStyleSheetByISTD( sTableStyleName ); pTableStyle = dynamic_cast<TableStyleSheetEntry*>( pStyleSheet.get( ) ); - m_aTableProperties->erase( aTableStyleIter ); + m_aTableProperties->Erase( aTableStyleVal->first ); aGrabBag[nGrabBagSize].Name = "TableStyleName"; aGrabBag[nGrabBagSize].Value = uno::makeAny( sTableStyleName ); @@ -470,12 +463,11 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo } } - PropertyMap::iterator const aTblLookIter = - m_aTableProperties->find(PROP_TBL_LOOK); - if(aTblLookIter != m_aTableProperties->end()) + const boost::optional<PropertyMap::Property> aTblLook = m_aTableProperties->getProperty(PROP_TBL_LOOK); + if(aTblLook) { - aTblLookIter->second.getValue() >>= rInfo.nTblLook; - m_aTableProperties->erase( aTblLookIter ); + aTblLook->second >>= rInfo.nTblLook; + m_aTableProperties->Erase( aTblLook->first ); } // Set the table default attributes for the cells @@ -608,10 +600,7 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo lcl_extractHoriOrient( rFrameProperties, nHoriOrient ); m_aTableProperties->Insert( PROP_HORI_ORIENT, uno::makeAny( sal_Int16(nHoriOrient) ) ); //fill default value - if not available - const PropertyMap::const_iterator aRepeatIter = - m_aTableProperties->find(PROP_HEADER_ROW_COUNT); - if( aRepeatIter == m_aTableProperties->end() ) - m_aTableProperties->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny( (sal_Int32)0 )); + m_aTableProperties->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny( (sal_Int32)0), false); rInfo.aTableProperties = m_aTableProperties->GetPropertyValues(); @@ -681,7 +670,7 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl if(rInfo.nTblLook&0x40) nRowStyleMask |= CNF_LAST_ROW; // last row style used } - else if (aRowIter->get() && aRowIter->get()->find(PROP_TBL_HEADER) != aRowIter->get()->end()) + else if (*aRowIter && (*aRowIter)->isSet(PROP_TBL_HEADER)) nRowStyleMask |= CNF_FIRST_ROW; // table header implies first row if(!nRowStyleMask) // if no row style used yet { @@ -710,10 +699,9 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl bool bIsEndRow = aRowOfCellsIterator == aLastRowIterator; //aCellIterator points to a PropertyMapPtr; - if( aCellIterator->get() ) + if( *aCellIterator ) { - if ( rInfo.pTableDefaults->size( ) ) - pAllCellProps->InsertProps(rInfo.pTableDefaults); + pAllCellProps->InsertProps(rInfo.pTableDefaults); sal_Int32 nCellStyleMask = 0; if (aCellIterator==aRowOfCellsIterator->begin()) @@ -756,18 +744,12 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl } // Remove properties from style/row that aren't allowed in cells - PropertyMap::iterator aDefaultRepeatIt = pAllCellProps->find(PROP_HEADER_ROW_COUNT); - if ( aDefaultRepeatIt != pAllCellProps->end( ) ) - pAllCellProps->erase( aDefaultRepeatIt ); - - - aDefaultRepeatIt = pAllCellProps->find(PROP_TBL_HEADER); - if ( aDefaultRepeatIt != pAllCellProps->end( ) ) - pAllCellProps->erase( aDefaultRepeatIt ); + pAllCellProps->Erase( PROP_HEADER_ROW_COUNT ); + pAllCellProps->Erase( PROP_TBL_HEADER ); // Then add the cell properties pAllCellProps->InsertProps(*aCellIterator); - aCellIterator->get( )->swap( *pAllCellProps.get( ) ); + std::swap(*(*aCellIterator), *pAllCellProps ); #ifdef DEBUG_DOMAINMAPPER dmapper_logger->startElement("cell"); @@ -778,34 +760,20 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl lcl_computeCellBorders( rInfo.pTableBorders, *aCellIterator, nCell, nRow, bIsEndCol, bIsEndRow ); //now set the default left+right border distance TODO: there's an sprm containing the default distance! - const PropertyMap::const_iterator aLeftDistanceIter = - aCellIterator->get()->find(PROP_LEFT_BORDER_DISTANCE); - if( aLeftDistanceIter == aCellIterator->get()->end() ) - aCellIterator->get()->Insert( PROP_LEFT_BORDER_DISTANCE, - uno::makeAny(rInfo.nLeftBorderDistance ) ); - const PropertyMap::const_iterator aRightDistanceIter = - aCellIterator->get()->find(PROP_RIGHT_BORDER_DISTANCE); - if( aRightDistanceIter == aCellIterator->get()->end() ) - aCellIterator->get()->Insert( PROP_RIGHT_BORDER_DISTANCE, - uno::makeAny((sal_Int32) rInfo.nRightBorderDistance ) ); - - const PropertyMap::const_iterator aTopDistanceIter = - aCellIterator->get()->find(PROP_TOP_BORDER_DISTANCE); - if( aTopDistanceIter == aCellIterator->get()->end() ) - aCellIterator->get()->Insert( PROP_TOP_BORDER_DISTANCE, - uno::makeAny((sal_Int32) rInfo.nTopBorderDistance ) ); - - const PropertyMap::const_iterator aBottomDistanceIter = - aCellIterator->get()->find(PROP_BOTTOM_BORDER_DISTANCE); - if( aBottomDistanceIter == aCellIterator->get()->end() ) - aCellIterator->get()->Insert( PROP_BOTTOM_BORDER_DISTANCE, - uno::makeAny((sal_Int32) rInfo.nBottomBorderDistance ) ); + aCellIterator->get()->Insert( PROP_LEFT_BORDER_DISTANCE, + uno::makeAny(rInfo.nLeftBorderDistance ), false); + aCellIterator->get()->Insert( PROP_RIGHT_BORDER_DISTANCE, + uno::makeAny((sal_Int32) rInfo.nRightBorderDistance ), false); + aCellIterator->get()->Insert( PROP_TOP_BORDER_DISTANCE, + uno::makeAny((sal_Int32) rInfo.nTopBorderDistance ), false); + aCellIterator->get()->Insert( PROP_BOTTOM_BORDER_DISTANCE, + uno::makeAny((sal_Int32) rInfo.nBottomBorderDistance ), false); // Horizontal merge is not an UNO property, extract that info here to rMerges, and then remove it from the map. - const PropertyMap::const_iterator aHorizontalMergeIter = aCellIterator->get()->find(PROP_HORIZONTAL_MERGE); - if (aHorizontalMergeIter != aCellIterator->get()->end()) + const boost::optional<PropertyMap::Property> aHorizontalMergeVal = (*aCellIterator)->getProperty(PROP_HORIZONTAL_MERGE); + if (aHorizontalMergeVal) { - if (aHorizontalMergeIter->second.getValue().get<sal_Bool>()) + if (aHorizontalMergeVal->second.get<sal_Bool>()) { // first cell in a merge HorizontallyMergedCell aMerge(nRow, nCell); @@ -818,24 +786,24 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl rMerge.m_nLastRow = nRow; rMerge.m_nLastCol = nCell; } - aCellIterator->get()->erase(PROP_HORIZONTAL_MERGE); + (*aCellIterator)->Erase(PROP_HORIZONTAL_MERGE); } // Cell direction is not an UNO Property, either. - const PropertyMap::const_iterator aCellDirectionIter = aCellIterator->get()->find(PROP_CELL_DIRECTION); - if (aCellDirectionIter != aCellIterator->get()->end()) + const boost::optional<PropertyMap::Property> aCellDirectionVal = (*aCellIterator)->getProperty(PROP_CELL_DIRECTION); + if (aCellDirectionVal) { - if (aCellDirectionIter->second.getValue().get<sal_Int32>() == 3) + if (aCellDirectionVal->second.get<sal_Int32>() == 3) { // btLr, so map ParagraphAdjust_CENTER to VertOrientation::CENTER. uno::Reference<beans::XPropertySet> xPropertySet((*m_pTableSeq)[nRow][nCell][0], uno::UNO_QUERY); if (xPropertySet->getPropertyValue("ParaAdjust").get<sal_Int16>() == style::ParagraphAdjust_CENTER) - aCellIterator->get()->Insert(PROP_VERT_ORIENT, uno::makeAny(text::VertOrientation::CENTER)); + (*aCellIterator)->Insert(PROP_VERT_ORIENT, uno::makeAny(text::VertOrientation::CENTER)); } - aCellIterator->get()->erase(PROP_CELL_DIRECTION); + (*aCellIterator)->Erase(PROP_CELL_DIRECTION); } - pSingleCellProperties[nCell] = aCellIterator->get()->GetPropertyValues(); + pSingleCellProperties[nCell] = (*aCellIterator)->GetPropertyValues(); #ifdef DEBUG_DOMAINMAPPER dmapper_logger->endElement(); #endif @@ -896,12 +864,9 @@ RowPropertyValuesSeq_t DomainMapperTableHandler::endTableGetRowProperties() if( aRowIter->get() ) { //set default to 'break across pages" - if( aRowIter->get()->find(PROP_IS_SPLIT_ALLOWED) == aRowIter->get()->end()) - aRowIter->get()->Insert( PROP_IS_SPLIT_ALLOWED, uno::makeAny(sal_True ) ); + (*aRowIter)->Insert( PROP_IS_SPLIT_ALLOWED, uno::makeAny(sal_True ), false ); // tblHeader is only our property, remove before the property map hits UNO - PropertyMap::iterator const aIter = aRowIter->get()->find(PROP_TBL_HEADER); - if (aIter != aRowIter->get()->end()) - aRowIter->get()->erase(aIter); + (*aRowIter)->Erase(PROP_TBL_HEADER); aRowProperties[nRow] = (*aRowIter)->GetPropertyValues(); #ifdef DEBUG_DOMAINMAPPER diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx index 4fce5e67a1fe..e5a5b8bb4d68 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx @@ -352,7 +352,7 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm) SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue ); // We're faking a text direction, so don't allow multiple lines. - if (!getCellProps() || getCellProps()->find(PROP_VERTICAL_MERGE) == getCellProps()->end()) + if (!getCellProps() || !getCellProps()->isSet(PROP_VERTICAL_MERGE)) { // Though in case there will be a vertical merge, don't do this, it hides text that is supposed to be visible. m_bRowSizeTypeInserted = true; diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 2f5b441c77a9..685a98c3fed4 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -628,11 +628,11 @@ uno::Any DomainMapper_Impl::GetPropertyFromStyleSheet(PropertyIds eId) //is there a tab stop set? if(pEntry->pProperties) { - PropertyMap::const_iterator aPropertyIter = - pEntry->pProperties->find(eId); - if( aPropertyIter != pEntry->pProperties->end()) + boost::optional<PropertyMap::Property> aProperty = + pEntry->pProperties->getProperty(eId); + if( aProperty ) { - return aPropertyIter->second.getValue(); + return aProperty->second; } } //search until the property is set or no parent is available @@ -790,11 +790,11 @@ void lcl_AddRangeAndStyle( pToBeSavedProperties->SetStartingRange(xParaCursor->getStart()); if(pPropertyMap) { - PropertyMap::iterator aParaStyleIter = pPropertyMap->find(PROP_PARA_STYLE_NAME); - if( aParaStyleIter != pPropertyMap->end()) + boost::optional<PropertyMap::Property> aParaStyle = pPropertyMap->getProperty(PROP_PARA_STYLE_NAME); + if( aParaStyle ) { OUString sName; - aParaStyleIter->second.getValue() >>= sName; + aParaStyle->second >>= sName; pToBeSavedProperties->SetParaStyleName(sName); } } @@ -1872,9 +1872,9 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape // Fix spacing for as-character objects. If the paragraph has CT_Spacing_after set, // it needs to be set on the object too, as that's what object placement code uses. PropertyMapPtr paragraphContext = GetTopContextOfType( CONTEXT_PARAGRAPH ); - PropertyMap::const_iterator pos = paragraphContext->find(PROP_PARA_BOTTOM_MARGIN); - if( pos != paragraphContext->end()) - xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_BOTTOM_MARGIN ), (*pos).second.getValue() ); + boost::optional<PropertyMap::Property> aPropMargin = paragraphContext->getProperty(PROP_PARA_BOTTOM_MARGIN); + if(aPropMargin) + xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_BOTTOM_MARGIN ), aPropMargin->second ); } else { @@ -2262,16 +2262,16 @@ bool lcl_FindInCommand( void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale) { PropertyMapPtr pTopContext = GetTopContext(); - PropertyMap::iterator aLocaleIter = pTopContext->find(PROP_CHAR_LOCALE); - if( aLocaleIter != pTopContext->end()) - aLocaleIter->second.getValue() >>= rLocale; + boost::optional<PropertyMap::Property> pLocale = pTopContext->getProperty(PROP_CHAR_LOCALE); + if( pLocale ) + pLocale->second >>= rLocale; else { PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH); - aLocaleIter = pParaContext->find(PROP_CHAR_LOCALE); - if( aLocaleIter != pParaContext->end()) + pLocale = pParaContext->getProperty(PROP_CHAR_LOCALE); + if( pLocale ) { - aLocaleIter->second.getValue() >>= rLocale; + pLocale->second >>= rLocale; } } } @@ -4770,14 +4770,14 @@ sal_Int32 DomainMapper_Impl::getCurrentNumberingProperty(const OUString& aProp) { sal_Int32 nRet = 0; - PropertyMap::iterator it = m_pTopContext->find(PROP_NUMBERING_RULES); + boost::optional<PropertyMap::Property> pProp = m_pTopContext->getProperty(PROP_NUMBERING_RULES); uno::Reference<container::XIndexAccess> xNumberingRules; - if (it != m_pTopContext->end()) - xNumberingRules.set(it->second.getValue(), uno::UNO_QUERY); - it = m_pTopContext->find(PROP_NUMBERING_LEVEL); + if (pProp) + xNumberingRules.set(pProp->second, uno::UNO_QUERY); + pProp = m_pTopContext->getProperty(PROP_NUMBERING_LEVEL); sal_Int32 nNumberingLevel = -1; - if (it != m_pTopContext->end()) - it->second.getValue() >>= nNumberingLevel; + if (pProp) + pProp->second >>= nNumberingLevel; if (xNumberingRules.is() && nNumberingLevel != -1) { uno::Sequence<beans::PropertyValue> aProps; diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx index 7fc2066368f2..d5cf4129ae2a 100644 --- a/writerfilter/source/dmapper/NumberingManager.cxx +++ b/writerfilter/source/dmapper/NumberingManager.cxx @@ -210,33 +210,36 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetProperties( ) return aLevelProps; } +static bool IgnoreForCharStyle(const OUString& aStr) +{ + //Names found in PropertyIds.cxx, Lines 56-396 + return (aStr=="Adjust" || aStr=="IndentAt" || aStr=="FirstLineIndent" + || aStr=="FirstLineOffset" || aStr=="LeftMargin" || aStr=="CharFontName" + ); +} uno::Sequence< beans::PropertyValue > ListLevel::GetCharStyleProperties( ) { PropertyValueVector_t rProperties; PropertyNameSupplier& aPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); - _PropertyMap::const_iterator aMapIter = begin(); - _PropertyMap::const_iterator aEndIter = end(); - for( ; aMapIter != aEndIter; ++aMapIter ) + uno::Sequence< beans::PropertyValue > vPropVals = PropertyMap::GetPropertyValues(); + beans::PropertyValue* aValIter = vPropVals.begin(); + beans::PropertyValue* aEndIter = vPropVals.end(); + for( ; aValIter != aEndIter; ++aValIter ) { - switch( aMapIter->first ) - { - case PROP_ADJUST: - case PROP_INDENT_AT: - case PROP_FIRST_LINE_INDENT: - case PROP_FIRST_LINE_OFFSET: - case PROP_LEFT_MARGIN: - case PROP_CHAR_FONT_NAME: - // Do nothing: handled in the GetPropertyValues method - break; - default: - { - rProperties.push_back( - beans::PropertyValue( - aPropNameSupplier.GetName( aMapIter->first ), 0, - aMapIter->second.getValue(), beans::PropertyState_DIRECT_VALUE )); + if (IgnoreForCharStyle(aValIter->Name)) + continue; + else if(aValIter->Name=="CharInteropGrabBag" || aValIter->Name=="ParaInteropGrabBag") { + uno::Sequence<beans::PropertyValue> vGrabVals; + aValIter->Value >>= vGrabVals; + beans::PropertyValue* aGrabIter = vGrabVals.begin(); + for(; aGrabIter!=vGrabVals.end(); ++aGrabIter) { + if(!IgnoreForCharStyle(aGrabIter->Name)) + rProperties.push_back(beans::PropertyValue(aGrabIter->Name, 0, aGrabIter->Value, beans::PropertyState_DIRECT_VALUE)); } } + else + rProperties.push_back(beans::PropertyValue(aValIter->Name, 0, aValIter->Value, beans::PropertyState_DIRECT_VALUE)); } uno::Sequence< beans::PropertyValue > aRet( rProperties.size() ); @@ -320,36 +323,26 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetLevelProperties( ) // nXChFollow; following character 0 - tab, 1 - space, 2 - nothing aNumberingProperties.push_back( MAKE_PROPVAL( PROP_LEVEL_FOLLOW, m_nXChFollow )); - - _PropertyMap::const_iterator aMapIter = begin(); - _PropertyMap::const_iterator aEndIter = end(); - for( ; aMapIter != aEndIter; ++aMapIter ) + const int nIds = 5; + PropertyIds aReadIds[nIds] = { - switch( aMapIter->first ) - { - case PROP_ADJUST: - case PROP_INDENT_AT: - case PROP_FIRST_LINE_INDENT: - case PROP_FIRST_LINE_OFFSET: - case PROP_LEFT_MARGIN: - aNumberingProperties.push_back( - beans::PropertyValue( aPropNameSupplier.GetName( aMapIter->first ), 0, aMapIter->second.getValue(), beans::PropertyState_DIRECT_VALUE )); - break; - case PROP_CHAR_FONT_NAME: - if( !isOutlineNumbering()) - { - aNumberingProperties.push_back( - beans::PropertyValue( aPropNameSupplier.GetName( PROP_BULLET_FONT_NAME ), 0, aMapIter->second.getValue(), beans::PropertyState_DIRECT_VALUE )); - } - break; - default: - { - // Handled in GetCharStyleProperties method - } - - } + PROP_ADJUST, PROP_INDENT_AT, PROP_FIRST_LINE_INDENT, + PROP_FIRST_LINE_OFFSET, PROP_LEFT_MARGIN + }; + for(int i=0; i<nIds; ++i) { + boost::optional<PropertyMap::Property> aProp = getProperty(aReadIds[i]); + if (aProp) + aNumberingProperties.push_back( + beans::PropertyValue( aPropNameSupplier.GetName(aProp->first), 0, aProp->second, beans::PropertyState_DIRECT_VALUE ) + ); } + boost::optional<PropertyMap::Property> aPropFont = getProperty(PROP_CHAR_FONT_NAME); + if(aPropFont && !isOutlineNumbering()) + aNumberingProperties.push_back( + beans::PropertyValue( aPropNameSupplier.GetName(PROP_BULLET_FONT_NAME), 0, aPropFont->second, beans::PropertyState_DIRECT_VALUE ) + ); + uno::Sequence< beans::PropertyValue > aRet(aNumberingProperties.size()); beans::PropertyValue* pValues = aRet.getArray(); PropertyValueVector_t::const_iterator aIt = aNumberingProperties.begin(); diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 4ded0548a808..18e68e738fcc 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -62,11 +62,11 @@ PropertyMap::~PropertyMap() uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharGrabBag) { - if(!m_aValues.getLength() && size()) + if(!m_aValues.getLength() && !m_vMap.empty()) { size_t nCharGrabBag = 0; size_t nParaGrabBag = 0; - for (PropertyMap::iterator i = begin(); i != end(); ++i) + for (MapIterator i = m_vMap.begin(); i != m_vMap.end(); ++i) { if ( i->second.getGrabBagType() == CHAR_GRAB_BAG ) nCharGrabBag++; @@ -80,7 +80,7 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG nCharGrabBagSize = nCharGrabBag ? 1 : 0; // If there are any grab bag properties, we need one slot for them. - m_aValues.realloc( size() - nCharGrabBag + nCharGrabBagSize + m_aValues.realloc( m_vMap.size() - nCharGrabBag + nCharGrabBagSize - nParaGrabBag + (nParaGrabBag ? 1 : 0)); ::com::sun::star::beans::PropertyValue* pValues = m_aValues.getArray(); uno::Sequence<beans::PropertyValue> aCharGrabBagValues(nCharGrabBag); @@ -93,30 +93,30 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG sal_Int32 nParaGrabBagValue = 0; sal_Int32 nCharGrabBagValue = 0; PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); - PropertyMap::iterator aParaStyleIter = find(PROP_PARA_STYLE_NAME); - if( aParaStyleIter != end()) + MapIterator aParaStyleIter = m_vMap.find(PROP_PARA_STYLE_NAME); + if( aParaStyleIter != m_vMap.end()) { pValues[nValue].Name = rPropNameSupplier.GetName( aParaStyleIter->first ); pValues[nValue].Value = aParaStyleIter->second.getValue(); ++nValue; } - PropertyMap::iterator aCharStyleIter = find(PROP_CHAR_STYLE_NAME); - if( aCharStyleIter != end()) + MapIterator aCharStyleIter = m_vMap.find(PROP_CHAR_STYLE_NAME); + if( aCharStyleIter != m_vMap.end()) { pValues[nValue].Name = rPropNameSupplier.GetName( aCharStyleIter->first ); pValues[nValue].Value = aCharStyleIter->second.getValue(); ++nValue; } - PropertyMap::iterator aNumRuleIter = find(PROP_NUMBERING_RULES); - if( aNumRuleIter != end()) + MapIterator aNumRuleIter = m_vMap.find(PROP_NUMBERING_RULES); + if( aNumRuleIter != m_vMap.end()) { pValues[nValue].Name = rPropNameSupplier.GetName( aNumRuleIter->first ); pValues[nValue].Value = aNumRuleIter->second.getValue(); ++nValue; } - PropertyMap::iterator aMapIter = begin(); - for( ; aMapIter != end(); ++aMapIter ) + MapIterator aMapIter = m_vMap.begin(); + for( ; aMapIter != m_vMap.end(); ++aMapIter ) { if( aMapIter != aParaStyleIter && aMapIter != aCharStyleIter && aMapIter != aNumRuleIter ) { @@ -196,19 +196,36 @@ void PropertyMap::Insert( PropertyIds eId, const uno::Any& rAny, bool bOverwrite dmapper_logger->endElement(); #endif - PropertyMap::iterator aElement = find(eId); - if (aElement != end()) - { - if (bOverwrite) - aElement->second = PropValue(rAny, i_GrabBagType); + if (!bOverwrite) + m_vMap.insert(std::make_pair(eId, PropValue(rAny, i_GrabBagType))); + else + m_vMap[eId] = PropValue(rAny, i_GrabBagType); - return; - } - _PropertyMap::insert(_PropertyMap::value_type(eId, PropValue(rAny, i_GrabBagType))); + Invalidate(); +} + +void PropertyMap::Erase( PropertyIds eId ) +{ + //Safe call to erase, it throws no exceptions, even if eId is not in m_vMap + m_vMap.erase(eId); Invalidate(); } +boost::optional<PropertyMap::Property> PropertyMap::getProperty( PropertyIds eId ) const +{ + MapIterator aIter = m_vMap.find(eId); + if (aIter==m_vMap.end()) + return boost::optional<Property>(); + else + return std::make_pair( eId, aIter->second.getValue() ) ; +} + +bool PropertyMap::isSet( PropertyIds eId) const +{ + return m_vMap.find(eId)!=m_vMap.end(); +} + #if OSL_DEBUG_LEVEL > 1 void PropertyMap::dumpXml( const TagLogger::Pointer_t pLogger ) const { @@ -261,29 +278,14 @@ void PropertyMap::dumpXml( const TagLogger::Pointer_t pLogger ) const } #endif - - -template<class T> - struct removeExistingElements : public ::std::unary_function<T, void> -{ - PropertyMap& rMap; - - removeExistingElements(PropertyMap& _rMap ) : rMap(_rMap) {} - void operator() (T x) - { - PropertyMap::iterator aElement = rMap.find(x.first); - if( aElement != rMap.end()) - rMap.erase( aElement ); - } -}; - void PropertyMap::InsertProps(const PropertyMapPtr pMap) { - if( pMap.get() ) + if(pMap) { - ::std::for_each( pMap->begin(), pMap->end(), - removeExistingElements<PropertyMap::value_type>(*this) ); - _PropertyMap::insert(pMap->begin(), pMap->end()); + MapIterator pEnd = pMap->m_vMap.end(); + for ( MapIterator iter = pMap->m_vMap.begin(); iter!=pEnd; ++iter ) + m_vMap[iter->first] = iter->second; + insertTableProperties(pMap.get()); Invalidate(); @@ -815,20 +817,20 @@ void SectionPropertyMap::PrepareHeaderFooterProperties( bool bFirstPage ) if( m_nTopMargin >= 0 ) //fixed height header -> see WW8Par6.hxx { - operator[](PROP_HEADER_IS_DYNAMIC_HEIGHT) = uno::makeAny( true ); - operator[](PROP_HEADER_DYNAMIC_SPACING) = uno::makeAny( true ); - operator[](PROP_HEADER_BODY_DISTANCE) = uno::makeAny( nHeaderTop - MIN_HEAD_FOOT_HEIGHT );// ULSpace.Top() - operator[](PROP_HEADER_HEIGHT) = uno::makeAny( nHeaderTop ); + Insert(PROP_HEADER_IS_DYNAMIC_HEIGHT, uno::makeAny( true )); + Insert(PROP_HEADER_DYNAMIC_SPACING, uno::makeAny( true )); + Insert(PROP_HEADER_BODY_DISTANCE, uno::makeAny( nHeaderTop - MIN_HEAD_FOOT_HEIGHT ));// ULSpace.Top() + Insert(PROP_HEADER_HEIGHT, uno::makeAny( nHeaderTop )); } else { //todo: old filter fakes a frame into the header/footer to support overlapping //current setting is completely wrong! - operator[](PROP_HEADER_HEIGHT) = uno::makeAny( nHeaderTop ); - operator[](PROP_HEADER_BODY_DISTANCE) = uno::makeAny( m_nTopMargin - nHeaderTop ); - operator[](PROP_HEADER_IS_DYNAMIC_HEIGHT) = uno::makeAny( false ); - operator[](PROP_HEADER_DYNAMIC_SPACING) = uno::makeAny( false ); + Insert(PROP_HEADER_HEIGHT, uno::makeAny( nHeaderTop )); + Insert(PROP_HEADER_BODY_DISTANCE, uno::makeAny( m_nTopMargin - nHeaderTop )); + Insert(PROP_HEADER_IS_DYNAMIC_HEIGHT, uno::makeAny( false )); + Insert(PROP_HEADER_DYNAMIC_SPACING, uno::makeAny( false )); } sal_Int32 nBottomMargin = m_nBottomMargin; @@ -846,24 +848,24 @@ void SectionPropertyMap::PrepareHeaderFooterProperties( bool bFirstPage ) if( m_nBottomMargin >= 0 ) //fixed height footer -> see WW8Par6.hxx { - operator[](PROP_FOOTER_IS_DYNAMIC_HEIGHT) = uno::makeAny( true ); - operator[](PROP_FOOTER_DYNAMIC_SPACING) = uno::makeAny( true ); - operator[](PROP_FOOTER_BODY_DISTANCE) = uno::makeAny( nHeaderBottom - MIN_HEAD_FOOT_HEIGHT); - operator[](PROP_FOOTER_HEIGHT) = uno::makeAny( nHeaderBottom ); + Insert(PROP_FOOTER_IS_DYNAMIC_HEIGHT, uno::makeAny( true )); + Insert(PROP_FOOTER_DYNAMIC_SPACING, uno::makeAny( true )); + Insert(PROP_FOOTER_BODY_DISTANCE, uno::makeAny( nHeaderBottom - MIN_HEAD_FOOT_HEIGHT)); + Insert(PROP_FOOTER_HEIGHT, uno::makeAny( nHeaderBottom )); } else { //todo: old filter fakes a frame into the header/footer to support overlapping //current setting is completely wrong! - operator[](PROP_FOOTER_IS_DYNAMIC_HEIGHT) = uno::makeAny( false ); - operator[](PROP_FOOTER_DYNAMIC_SPACING) = uno::makeAny( false ); - operator[](PROP_FOOTER_HEIGHT) = uno::makeAny( m_nBottomMargin - nHeaderBottom ); - operator[](PROP_FOOTER_BODY_DISTANCE) = uno::makeAny( nHeaderBottom ); + Insert(PROP_FOOTER_IS_DYNAMIC_HEIGHT, uno::makeAny( false )); + Insert(PROP_FOOTER_DYNAMIC_SPACING, uno::makeAny( false )); + Insert(PROP_FOOTER_HEIGHT, uno::makeAny( m_nBottomMargin - nHeaderBottom )); + Insert(PROP_FOOTER_BODY_DISTANCE, uno::makeAny( nHeaderBottom )); } //now set the top/bottom margin for the follow page style - operator[](PROP_TOP_MARGIN) = uno::makeAny( nTopMargin ); - operator[](PROP_BOTTOM_MARGIN) = uno::makeAny( nBottomMargin ); + Insert(PROP_TOP_MARGIN, uno::makeAny( nTopMargin )); + Insert(PROP_BOTTOM_MARGIN, uno::makeAny( nBottomMargin )); } uno::Reference<beans::XPropertySet> lcl_GetRangeProperties(bool bIsFirstSection, @@ -892,14 +894,14 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl) else m_nLeftMargin += m_nDzaGutter; } - operator[](PROP_LEFT_MARGIN) = uno::makeAny( m_nLeftMargin ); - operator[](PROP_RIGHT_MARGIN) = uno::makeAny( m_nRightMargin ); + Insert(PROP_LEFT_MARGIN, uno::makeAny( m_nLeftMargin )); + Insert(PROP_RIGHT_MARGIN, uno::makeAny( m_nRightMargin )); if (rDM_Impl.m_oBackgroundColor) - operator[](PROP_BACK_COLOR) = uno::makeAny(*rDM_Impl.m_oBackgroundColor); + Insert(PROP_BACK_COLOR, uno::makeAny(*rDM_Impl.m_oBackgroundColor)); if (!rDM_Impl.m_bHasFtnSep) // Set footnote line width to zero, document has no footnote separator. - operator[](PROP_FOOTNOTE_LINE_RELATIVE_WIDTH) = uno::makeAny(sal_Int32(0)); + Insert(PROP_FOOTNOTE_LINE_RELATIVE_WIDTH, uno::makeAny(sal_Int32(0))); /*** if headers/footers are available then the top/bottom margins of the header/footer are copied to the top/bottom margin of the page @@ -1028,19 +1030,19 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) //prepare text grid properties sal_Int32 nHeight = 1; - PropertyMap::iterator aElement = find(PROP_HEIGHT); - if( aElement != end()) - aElement->second.getValue() >>= nHeight; + boost::optional<PropertyMap::Property> pProp = getProperty(PROP_HEIGHT); + if(pProp) + pProp->second >>= nHeight; sal_Int32 nWidth = 1; - aElement = find(PROP_WIDTH); - if( aElement != end()) - aElement->second.getValue() >>= nWidth; + pProp = getProperty(PROP_WIDTH); + if(pProp) + pProp->second >>= nWidth; text::WritingMode eWritingMode = text::WritingMode_LR_TB; - aElement = find(PROP_WRITING_MODE); - if( aElement != end()) - aElement->second.getValue() >>= eWritingMode; + pProp = getProperty(PROP_WRITING_MODE); + if(pProp) + pProp->second >>= eWritingMode; sal_Int32 nTextAreaHeight = eWritingMode == text::WritingMode_LR_TB ? nHeight - m_nTopMargin - m_nBottomMargin : @@ -1054,23 +1056,21 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) nGridLinePitch = 1; } - operator[](PROP_GRID_LINES) = - uno::makeAny( static_cast<sal_Int16>(nTextAreaHeight/nGridLinePitch)); + Insert(PROP_GRID_LINES, uno::makeAny( static_cast<sal_Int16>(nTextAreaHeight/nGridLinePitch))); // PROP_GRID_MODE - operator[]( PROP_GRID_MODE) = - uno::makeAny( static_cast<sal_Int16> (m_nGridType) ); + Insert( PROP_GRID_MODE, uno::makeAny( static_cast<sal_Int16> (m_nGridType) )); sal_Int32 nCharWidth = 423; //240 twip/ 12 pt //todo: is '0' the right index here? const StyleSheetEntryPtr pEntry = rDM_Impl.GetStyleSheetTable()->FindStyleSheetByISTD(OUString::number(0, 16)); if( pEntry.get( ) ) { - PropertyMap::iterator aElement_ = pEntry->pProperties->find(PROP_CHAR_HEIGHT_ASIAN); - if( aElement_ != pEntry->pProperties->end()) + boost::optional<PropertyMap::Property> pPropHeight = pEntry->pProperties->getProperty(PROP_CHAR_HEIGHT_ASIAN); + if(pProp) { double fHeight = 0; - if( aElement_->second.getValue() >>= fHeight ) + if( pPropHeight->second >>= fHeight ) nCharWidth = ConversionHelper::convertTwipToMM100( (long)( fHeight * 20.0 + 0.5 )); } } @@ -1088,11 +1088,11 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) nFraction = (nFraction * 20)/0xFFF; nCharWidth += ConversionHelper::convertTwipToMM100( nFraction ); } - operator[](PROP_GRID_BASE_HEIGHT) = uno::makeAny( nCharWidth ); + Insert(PROP_GRID_BASE_HEIGHT, uno::makeAny( nCharWidth )); sal_Int32 nRubyHeight = nGridLinePitch - nCharWidth; if(nRubyHeight < 0 ) nRubyHeight = 0; - operator[](PROP_GRID_RUBY_HEIGHT) = uno::makeAny( nRubyHeight ); + Insert(PROP_GRID_RUBY_HEIGHT, uno::makeAny( nRubyHeight )); // #i119558#, force to set document as standard page mode, // refer to ww8 import process function "SwWW8ImplReader::SetDocumentGrid" @@ -1101,7 +1101,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) uno::Reference< beans::XPropertySet > xDocProperties; xDocProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetTextDocument(), uno::UNO_QUERY_THROW ); bool bSquaredPageMode = false; - operator[](PROP_GRID_STANDARD_MODE) = uno::makeAny( !bSquaredPageMode ); + Insert(PROP_GRID_STANDARD_MODE, uno::makeAny( !bSquaredPageMode )); xDocProperties->setPropertyValue("DefaultPageMode", uno::makeAny( bSquaredPageMode )); } catch (const uno::Exception& rEx) @@ -1171,26 +1171,66 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) rDM_Impl.SetIsFirstParagraphInSection(true); } - +class NamedPropertyValue { + OUString m_aName; +public: + NamedPropertyValue(const OUString& i_aStr) + : m_aName(i_aStr) { } + bool operator() (beans::PropertyValue& aVal) + { return aVal.Name == m_aName; } +}; void SectionPropertyMap::_ApplyProperties( uno::Reference< beans::XPropertySet > const& xStyle) { PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); uno::Reference<beans::XMultiPropertySet> const xMultiSet(xStyle, uno::UNO_QUERY); - if (xMultiSet.is()) - { // FIXME why is "this" a STL container??? - uno::Sequence<OUString> names(this->size()); - uno::Sequence<uno::Any> values(this->size()); - PropertyMap::iterator it = this->begin(); - for (size_t i = 0; it != this->end(); ++it, ++i) - { - names[i] = rPropNameSupplier.GetName(it->first); - values[i] = it->second.getValue(); + + uno::Sequence<OUString> vNames; + uno::Sequence<uno::Any> vValues; + { //Convert GetPropertyValues() value into something useful + uno::Sequence<beans::PropertyValue> vPropVals = GetPropertyValues(); + int nProperties = vPropVals.getLength(); + + //Temporarily store the items that are in grab bags + uno::Sequence<beans::PropertyValue> vCharVals; + uno::Sequence<beans::PropertyValue> vParaVals; + beans::PropertyValue* pCharGrabBag = std::find_if(vPropVals.begin(),vPropVals.end(),NamedPropertyValue("CharInteropGrabBag") ); + if (pCharGrabBag!=vPropVals.end()) { + (pCharGrabBag->Value)>>=vCharVals; + nProperties += vCharVals.getLength()-1; //-1 to accomodate for grab bag property in vPropVals + } + beans::PropertyValue* pParaGrabBag = std::find_if(vPropVals.begin(),vPropVals.end(),NamedPropertyValue("ParaInteropGrabBag") ); + if (pParaGrabBag!=vPropVals.end()) { + (pParaGrabBag->Value)>>=vParaVals; + nProperties += vParaVals.getLength()-1; + } + + //Allocate enough space to store the properties + vNames.realloc(nProperties); + vValues.realloc(nProperties); + + int i = 0; + for (beans::PropertyValue* pIter = vPropVals.begin(); pIter!=vPropVals.end(); ++pIter, ++i) { + if(pIter!=pCharGrabBag && pIter!=pParaGrabBag) { + vNames[i] = pIter->Name; + vValues[i] = pIter->Value; + } + } + for (beans::PropertyValue* iter = vCharVals.begin(); iter!=vCharVals.end(); ++iter, ++i) { + vNames[i] = iter->Name; + vValues[i] = iter->Value; + } + for (beans::PropertyValue* iter = vParaVals.begin(); iter!=vParaVals.end(); ++iter, ++i) { + vNames[i] = iter->Name; + vValues[i] = iter->Value; } + } + if (xMultiSet.is()) + { try { - xMultiSet->setPropertyValues(names, values); + xMultiSet->setPropertyValues(vNames, vValues); } catch( const uno::Exception& ) { @@ -1198,19 +1238,17 @@ void SectionPropertyMap::_ApplyProperties( } return; } - PropertyMap::iterator aMapIter = begin(); - while( aMapIter != end()) + for (int i=0; i<vNames.getLength(); ++i) { try { if (xStyle.is()) - xStyle->setPropertyValue( rPropNameSupplier.GetName( aMapIter->first ), aMapIter->second.getValue() ); + xStyle->setPropertyValue( vNames[i], vValues[i] ); } catch( const uno::Exception& ) { OSL_FAIL( "Exception in <PageStyle>::setPropertyValue"); } - ++aMapIter; } } sal_Int32 lcl_AlignPaperBin( sal_Int32 nSet ) @@ -1239,7 +1277,7 @@ void SectionPropertyMap::SetFirstPaperBin( sal_Int32 nSet ) sal_Int32 SectionPropertyMap::GetPageWidth() { - return operator[](PROP_WIDTH).getValue().get<sal_Int32>(); + return getProperty(PROP_WIDTH)->second.get<sal_Int32>(); } StyleSheetPropertyMap::StyleSheetPropertyMap() : diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index a4c99154176b..2183f964b2f2 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -26,6 +26,7 @@ #include <com/sun/star/uno/Any.h> #include "PropertyIds.hxx" #include <boost/shared_ptr.hpp> +#include <boost/optional.hpp> #include <map> #include <vector> @@ -82,22 +83,16 @@ public: PropValue() : m_aValue(), m_GrabBagType(NO_GRAB_BAG) {} - PropValue& operator=(const PropValue& rProp) { - m_aValue = rProp.m_aValue; - m_GrabBagType = rProp.m_GrabBagType; - return *this; - } - const css::uno::Any& getValue() const { return m_aValue; } bool hasGrabBag() const { return m_GrabBagType != NO_GRAB_BAG; } GrabBagType getGrabBagType() const { return m_GrabBagType; } }; -typedef std::map< PropertyIds, PropValue > _PropertyMap; -class PropertyMap : public _PropertyMap +class PropertyMap { /// Cache the property values for the GetPropertyValues() call(s). ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aValues; + //marks context as footnote context - ::text( ) events contain either the footnote character or can be ignored //depending on sprmCSymbol sal_Unicode m_cFootnoteSymbol; // 0 == invalid @@ -105,6 +100,9 @@ class PropertyMap : public _PropertyMap OUString m_sFootnoteFontName; ::com::sun::star::uno::Reference< ::com::sun::star::text::XFootnote > m_xFootnote; + std::map< PropertyIds, PropValue > m_vMap; + + typedef std::map<PropertyIds,PropValue>::const_iterator MapIterator; protected: void Invalidate() { @@ -113,16 +111,31 @@ protected: } public: + typedef std::pair<PropertyIds,css::uno::Any> Property; + PropertyMap(); virtual ~PropertyMap(); ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetPropertyValues(bool bCharGrabBag = true); + //Sequence: Grab Bags: The CHAR_GRAB_BAG has Name "CharInteropGrabBag" and the PARA_GRAB_BAG has Name "ParaInteropGrabBag" + // the contained properties are their Value. bool hasEmptyPropertyValues() const {return !m_aValues.getLength();} - /** Add property, usually overwrites already available attributes. It shouldn't overwrite in case of default attributes - */ + + //Add property, optionally overwriting existing attributes void Insert( PropertyIds eId, const ::com::sun::star::uno::Any& rAny, bool bOverwrite = true, GrabBagType i_GrabBagType = NO_GRAB_BAG ); void Insert( PropertyIds eId, const PropValue& rValue, bool bOverwrite = true ); + //Remove a named property from *this, does nothing if the property id has not been set + void Erase( PropertyIds eId); + + //Imports properties from pMap, overwriting those with the same PropertyIds as the current map void InsertProps(const boost::shared_ptr<PropertyMap> pMap); + + //Returns a copy of the property if it exists, .first is its PropertyIds and .second is its Value (type css::uno::Any) + boost::optional<Property> getProperty( PropertyIds eId ) const; + + //Has the property named been set (via Insert or Set)? + bool isSet( PropertyIds eId ) const; + const ::com::sun::star::uno::Reference< ::com::sun::star::text::XFootnote>& GetFootnote() const { return m_xFootnote;} void SetFootnote( ::com::sun::star::uno::Reference< ::com::sun::star::text::XFootnote> const& xF ) { m_xFootnote = xF; } @@ -145,8 +158,6 @@ public: }; typedef boost::shared_ptr<PropertyMap> PropertyMapPtr; - - class SectionPropertyMap : public PropertyMap { //--> debug diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx index 693b248b99cf..692d96723a0f 100644 --- a/writerfilter/source/dmapper/SdtHelper.cxx +++ b/writerfilter/source/dmapper/SdtHelper.cxx @@ -44,13 +44,13 @@ awt::Size lcl_getOptimalWidth(StyleSheetTablePtr pStyleSheet, OUString& rDefault PropertyMapPtr pDefaultCharProps = pStyleSheet->GetDefaultCharProps(); Font aFont(pOut->GetFont()); - PropertyMap::iterator aFontName = pDefaultCharProps->find(PROP_CHAR_FONT_NAME); - if (aFontName != pDefaultCharProps->end()) - aFont.SetName(aFontName->second.getValue().get<OUString>()); - PropertyMap::iterator aHeight = pDefaultCharProps->find(PROP_CHAR_HEIGHT); - if (aHeight != pDefaultCharProps->end()) + boost::optional<PropertyMap::Property> aFontName = pDefaultCharProps->getProperty(PROP_CHAR_FONT_NAME); + if (aFontName) + aFont.SetName(aFontName->second.get<OUString>()); + boost::optional<PropertyMap::Property> aHeight = pDefaultCharProps->getProperty(PROP_CHAR_HEIGHT); + if (aHeight) { - nHeight = aHeight->second.getValue().get<double>() * 35; // points -> mm100 + nHeight = aHeight->second.get<double>() * 35; // points -> mm100 aFont.SetSize(Size(0, nHeight)); } pOut->SetFont(aFont); diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx index 7c698efb25a1..d7dc1fc48ca3 100644 --- a/writerfilter/source/dmapper/StyleSheetTable.cxx +++ b/writerfilter/source/dmapper/StyleSheetTable.cxx @@ -99,7 +99,8 @@ TableStyleSheetEntry::~TableStyleSheetEntry( ) void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, PropertyMapPtr pProps ) { - static const TblStyleType pTypesToFix[] = + static const int nTypesProps = 4; + static const TblStyleType pTypesToFix[nTypesProps] = { TBL_STYLE_FIRSTROW, TBL_STYLE_LASTROW, @@ -107,7 +108,7 @@ void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, PropertyMapPtr pPr TBL_STYLE_LASTCOL }; - static const PropertyIds pPropsToCheck[] = + static const PropertyIds pPropsToCheck[nTypesProps] = { PROP_BOTTOM_BORDER, PROP_TOP_BORDER, @@ -115,29 +116,24 @@ void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, PropertyMapPtr pPr PROP_LEFT_BORDER }; - int i = 0; - while ( i < 4 ) + for (int i=0; i < nTypesProps; ++i ) { if ( nType == pTypesToFix[i] ) { PropertyIds nChecked = pPropsToCheck[i]; - PropertyMap::iterator pCheckedIt = pProps->find(nChecked); + boost::optional<PropertyMap::Property> pChecked = pProps->getProperty(nChecked); PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER; - PropertyMap::iterator pInsideIt = pProps->find(nInsideProp); - - bool bHasChecked = pCheckedIt != pProps->end( ); - bool bHasInside = pInsideIt != pProps->end( ); + boost::optional<PropertyMap::Property> pInside = pProps->getProperty(nInsideProp); - if ( bHasChecked && bHasInside ) + if ( pChecked && pProps ) { // In this case, remove the inside border - pProps->erase( pInsideIt ); + pProps->Erase( nInsideProp ); } - i = 4; // Stop looping stupidly + break; } - i++; } // Append the tblStylePr @@ -162,11 +158,11 @@ PropertyMapPtr TableStyleSheetEntry::GetProperties( sal_Int32 nMask, StyleSheetE { pStack->push_back(pEntry); - TableStyleSheetEntry* pParent = static_cast<TableStyleSheetEntry *>( pEntry.get( ) ); + TableStyleSheetEntry* pParent = static_cast<TableStyleSheetEntry *>( pEntry.get( ) ); pProps->InsertProps(pParent->GetProperties(nMask)); pStack->pop_back(); - } + } } // And finally get the mask ones @@ -221,19 +217,15 @@ void lcl_mergeProps( PropertyMapPtr pToFill, PropertyMapPtr pToAdd, TblStyleTyp for ( unsigned i = 0 ; i != sizeof(pPropsToCheck) / sizeof(PropertyIds); i++ ) { PropertyIds nId = pPropsToCheck[i]; - PropertyMap::iterator pIt = pToAdd->find(nId); + boost::optional<PropertyMap::Property> pProp = pToAdd->getProperty(nId); - if ( pIt != pToAdd->end( ) ) + if ( pProp ) { - PropertyMap::iterator pDestIt = pToFill->find(nId); - if ( pRemoveInside[i] ) { // Remove the insideH and insideV depending on the cell pos PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER; - pDestIt = pToFill->find(nInsideProp); - if ( pDestIt != pToFill->end( ) ) - pToFill->erase( pDestIt ); + pToFill->Erase(nInsideProp); } } } @@ -792,12 +784,12 @@ void StyleSheetTable::lcl_sprm(Sprm & rSprm) { // The current style is the default paragraph style. PropertyMapPtr pProperties = m_pImpl->m_pCurrentEntry->pProperties; - if (pProperties->find(PROP_CHAR_HEIGHT) != pProperties->end() && m_pImpl->m_pDefaultParaProps->find(PROP_CHAR_HEIGHT) == m_pImpl->m_pDefaultParaProps->end()) + if (pProperties->isSet(PROP_CHAR_HEIGHT) && !m_pImpl->m_pDefaultParaProps->isSet(PROP_CHAR_HEIGHT)) { // We provide a character height value, but a document-level default wasn't set. if (m_pImpl->m_xTextDefaults.is()) { - m_pImpl->m_xTextDefaults->setPropertyValue("CharHeight", pProperties->operator[](PROP_CHAR_HEIGHT).getValue()); + m_pImpl->m_xTextDefaults->setPropertyValue("CharHeight", pProperties->getProperty(PROP_CHAR_HEIGHT)->second); } } } @@ -1536,7 +1528,7 @@ void StyleSheetTable::applyDefaults(bool bParaProperties) m_pImpl->m_rDMapper.GetTextFactory()->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY_THROW ); } - if( bParaProperties && m_pImpl->m_pDefaultParaProps.get() && m_pImpl->m_pDefaultParaProps->size()) + if( bParaProperties && m_pImpl->m_pDefaultParaProps.get()) { uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultParaProps->GetPropertyValues(); for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i ) @@ -1551,7 +1543,7 @@ void StyleSheetTable::applyDefaults(bool bParaProperties) } } } - if( !bParaProperties && m_pImpl->m_pDefaultCharProps.get() && m_pImpl->m_pDefaultCharProps->size()) + if( !bParaProperties && m_pImpl->m_pDefaultCharProps.get()) { uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultCharProps->GetPropertyValues(); for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i ) |