LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - StyleSheetTable.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 719 0.0 %
Date: 2014-04-14 Functions: 0 43 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #include <resourcemodel/ResourceModelHelper.hxx>
      20             : #include <StyleSheetTable.hxx>
      21             : #include <dmapper/DomainMapper.hxx>
      22             : #include <NumberingManager.hxx>
      23             : #include <ConversionHelper.hxx>
      24             : #include <TblStylePrHandler.hxx>
      25             : #include <BorderHandler.hxx>
      26             : #include <LatentStyleHandler.hxx>
      27             : #include <ooxml/resourceids.hxx>
      28             : #include <vector>
      29             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      30             : #include <com/sun/star/beans/XPropertyState.hpp>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include <com/sun/star/container/XNameContainer.hpp>
      33             : #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
      34             : #include <com/sun/star/text/XTextDocument.hpp>
      35             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      36             : #include <com/sun/star/style/XStyle.hpp>
      37             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      38             : #include <com/sun/star/text/WritingMode.hpp>
      39             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      40             : #include <map>
      41             : #include <stdio.h>
      42             : #include <rtl/ustrbuf.hxx>
      43             : #include <comphelper/string.hxx>
      44             : 
      45             : #include <dmapperLoggers.hxx>
      46             : 
      47             : using namespace ::com::sun::star;
      48             : namespace writerfilter {
      49             : namespace dmapper
      50             : {
      51             : 
      52             : typedef ::std::map< OUString, OUString> StringPairMap_t;
      53             : 
      54             : 
      55             : 
      56           0 : StyleSheetEntry::StyleSheetEntry() :
      57             :         sStyleIdentifierI()
      58             :         ,sStyleIdentifierD()
      59             :         ,bIsDefaultStyle(false)
      60             :         ,bInvalidHeight(false)
      61             :         ,bHasUPE(false)
      62             :         ,nStyleTypeCode(STYLE_TYPE_UNKNOWN)
      63             :         ,sBaseStyleIdentifier()
      64             :         ,sNextStyleIdentifier()
      65           0 :         ,pProperties(new StyleSheetPropertyMap)
      66           0 :         ,bAutoRedefine(false)
      67             : {
      68           0 : }
      69             : 
      70           0 : StyleSheetEntry::~StyleSheetEntry()
      71             : {
      72           0 : }
      73             : 
      74           0 : TableStyleSheetEntry::TableStyleSheetEntry( StyleSheetEntry& rEntry, StyleSheetTable* pStyles ):
      75             :     StyleSheetEntry( ),
      76           0 :     m_pStyleSheet( pStyles )
      77             : {
      78             : 
      79           0 :     bIsDefaultStyle = rEntry.bIsDefaultStyle;
      80           0 :     bInvalidHeight = rEntry.bInvalidHeight;
      81           0 :     bHasUPE = rEntry.bHasUPE;
      82           0 :     nStyleTypeCode = STYLE_TYPE_TABLE;
      83           0 :     sBaseStyleIdentifier = rEntry.sBaseStyleIdentifier;
      84           0 :     sNextStyleIdentifier = rEntry.sNextStyleIdentifier;
      85           0 :     sStyleName = rEntry.sStyleName;
      86           0 :     sStyleName1 = rEntry.sStyleName1;
      87           0 :     sStyleIdentifierI = rEntry.sStyleIdentifierI;
      88           0 :     sStyleIdentifierD = rEntry.sStyleIdentifierD;
      89             : 
      90           0 :     m_nColBandSize = 1;
      91           0 :     m_nRowBandSize = 1;
      92           0 : }
      93             : 
      94           0 : TableStyleSheetEntry::~TableStyleSheetEntry( )
      95             : {
      96           0 :     m_pStyleSheet = NULL;
      97           0 : }
      98             : 
      99           0 : void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, PropertyMapPtr pProps )
     100             : {
     101             :     static const TblStyleType pTypesToFix[] =
     102             :     {
     103             :         TBL_STYLE_FIRSTROW,
     104             :         TBL_STYLE_LASTROW,
     105             :         TBL_STYLE_FIRSTCOL,
     106             :         TBL_STYLE_LASTCOL
     107             :     };
     108             : 
     109             :     static const PropertyIds pPropsToCheck[] =
     110             :     {
     111             :         PROP_BOTTOM_BORDER,
     112             :         PROP_TOP_BORDER,
     113             :         PROP_RIGHT_BORDER,
     114             :         PROP_LEFT_BORDER
     115             :     };
     116             : 
     117           0 :     int i = 0;
     118           0 :     while ( i < 4 )
     119             :     {
     120           0 :         if ( nType == pTypesToFix[i] )
     121             :         {
     122           0 :             PropertyIds nChecked = pPropsToCheck[i];
     123           0 :             PropertyMap::iterator pCheckedIt = pProps->find(nChecked);
     124             : 
     125           0 :             PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
     126           0 :             PropertyMap::iterator pInsideIt = pProps->find(nInsideProp);
     127             : 
     128           0 :             bool bHasChecked = pCheckedIt != pProps->end( );
     129           0 :             bool bHasInside = pInsideIt != pProps->end( );
     130             : 
     131           0 :             if ( bHasChecked && bHasInside )
     132             :             {
     133             :                 // In this case, remove the inside border
     134           0 :                 pProps->erase( pInsideIt );
     135             :             }
     136             : 
     137           0 :             i = 4; // Stop looping stupidly
     138             :         }
     139           0 :         i++;
     140             :     }
     141             : 
     142             :     // Append the tblStylePr
     143           0 :     m_aStyles[nType] = pProps;
     144           0 : }
     145             : 
     146           0 : PropertyMapPtr TableStyleSheetEntry::GetProperties( sal_Int32 nMask, StyleSheetEntryDequePtr pStack )
     147             : {
     148           0 :     PropertyMapPtr pProps( new PropertyMap );
     149             : 
     150             :     // First get the parent properties
     151           0 :     StyleSheetEntryPtr pEntry = m_pStyleSheet->FindParentStyleSheet( sBaseStyleIdentifier );
     152             : 
     153           0 :     if ( pEntry.get( ) )
     154             :     {
     155           0 :         if (pStack.get() == NULL)
     156           0 :             pStack.reset(new StyleSheetEntryDeque());
     157             : 
     158           0 :         StyleSheetEntryDeque::const_iterator aIt = find(pStack->begin(), pStack->end(), pEntry);
     159             : 
     160           0 :         if (aIt != pStack->end())
     161             :         {
     162           0 :             pStack->push_back(pEntry);
     163             : 
     164           0 :         TableStyleSheetEntry* pParent = static_cast<TableStyleSheetEntry *>( pEntry.get( ) );
     165           0 :             pProps->InsertProps(pParent->GetProperties(nMask));
     166             : 
     167           0 :             pStack->pop_back();
     168             :     }
     169             :     }
     170             : 
     171             :     // And finally get the mask ones
     172           0 :     pProps->InsertProps(GetLocalPropertiesFromMask(nMask));
     173             : 
     174           0 :     return pProps;
     175             : }
     176             : 
     177           0 : beans::PropertyValues StyleSheetEntry::GetInteropGrabBagSeq()
     178             : {
     179           0 :     uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
     180           0 :     beans::PropertyValue* pSeq = aSeq.getArray();
     181           0 :     for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
     182           0 :         *pSeq++ = *i;
     183             : 
     184           0 :     return aSeq;
     185             : }
     186             : 
     187           0 : beans::PropertyValue StyleSheetEntry::GetInteropGrabBag()
     188             : {
     189           0 :     beans::PropertyValue aRet;
     190           0 :     aRet.Name = sStyleIdentifierI;
     191             : 
     192           0 :     beans::PropertyValues aSeq = GetInteropGrabBagSeq();;
     193           0 :     aRet.Value = uno::makeAny(aSeq);
     194           0 :     return aRet;
     195             : }
     196             : 
     197           0 : void StyleSheetEntry::AppendInteropGrabBag(beans::PropertyValue aValue)
     198             : {
     199           0 :     m_aInteropGrabBag.push_back(aValue);
     200           0 : }
     201             : 
     202           0 : void lcl_mergeProps( PropertyMapPtr pToFill,  PropertyMapPtr pToAdd, TblStyleType nStyleId )
     203             : {
     204             :     static const PropertyIds pPropsToCheck[] =
     205             :     {
     206             :         PROP_BOTTOM_BORDER,
     207             :         PROP_TOP_BORDER,
     208             :         PROP_RIGHT_BORDER,
     209             :         PROP_LEFT_BORDER,
     210             :     };
     211             : 
     212             :     bool pRemoveInside[] =
     213             :     {
     214           0 :         ( nStyleId == TBL_STYLE_FIRSTROW ),
     215           0 :         ( nStyleId == TBL_STYLE_LASTROW ),
     216           0 :         ( nStyleId == TBL_STYLE_LASTCOL ),
     217           0 :         ( nStyleId == TBL_STYLE_FIRSTCOL )
     218           0 :     };
     219             : 
     220           0 :     for ( unsigned i = 0 ; i != sizeof(pPropsToCheck) / sizeof(PropertyIds); i++ )
     221             :     {
     222           0 :         PropertyIds nId = pPropsToCheck[i];
     223           0 :         PropertyMap::iterator pIt = pToAdd->find(nId);
     224             : 
     225           0 :         if ( pIt != pToAdd->end( ) )
     226             :         {
     227           0 :             PropertyMap::iterator pDestIt = pToFill->find(nId);
     228             : 
     229           0 :             if ( pRemoveInside[i] )
     230             :             {
     231             :                 // Remove the insideH and insideV depending on the cell pos
     232           0 :                 PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
     233           0 :                 pDestIt = pToFill->find(nInsideProp);
     234           0 :                 if ( pDestIt != pToFill->end( ) )
     235           0 :                     pToFill->erase( pDestIt );
     236             :             }
     237             :         }
     238             :     }
     239             : 
     240           0 :     pToFill->InsertProps(pToAdd);
     241           0 : }
     242             : 
     243           0 : PropertyMapPtr TableStyleSheetEntry::GetLocalPropertiesFromMask( sal_Int32 nMask )
     244             : {
     245             :     // Order from right to left
     246             :     struct TblStyleTypeAndMask {
     247             :         sal_Int32       mask;
     248             :         TblStyleType    type;
     249             :     };
     250             : 
     251             :     static const TblStyleTypeAndMask aOrderedStyleTable[] =
     252             :     {
     253             :         { 0x010, TBL_STYLE_BAND2HORZ },
     254             :         { 0x020, TBL_STYLE_BAND1HORZ },
     255             :         { 0x040, TBL_STYLE_BAND2VERT },
     256             :         { 0x080, TBL_STYLE_BAND1VERT },
     257             :         { 0x100, TBL_STYLE_LASTCOL  },
     258             :         { 0x200, TBL_STYLE_FIRSTCOL },
     259             :         { 0x400, TBL_STYLE_LASTROW  },
     260             :         { 0x800, TBL_STYLE_FIRSTROW },
     261             :         { 0x001, TBL_STYLE_SWCELL },
     262             :         { 0x002, TBL_STYLE_SECELL },
     263             :         { 0x004, TBL_STYLE_NWCELL },
     264             :         { 0x008, TBL_STYLE_NECELL }
     265             :     };
     266             : 
     267             :     // Get the properties applying according to the mask
     268           0 :     PropertyMapPtr pProps( new PropertyMap( ) );
     269           0 :     for (size_t i = 0; i < sizeof(aOrderedStyleTable)/sizeof(aOrderedStyleTable[0]); ++i)
     270             :     {
     271           0 :         TblStylePrs::iterator pIt = m_aStyles.find( aOrderedStyleTable[ i ].type );
     272           0 :         if ( ( nMask & aOrderedStyleTable[ i ].mask ) && ( pIt != m_aStyles.end( ) ) )
     273           0 :             lcl_mergeProps( pProps, pIt->second, aOrderedStyleTable[ i ].type );
     274             :     }
     275           0 :     return pProps;
     276             : }
     277             : 
     278             : 
     279             : 
     280           0 : struct ListCharStylePropertyMap_t
     281             : {
     282             :     OUString         sCharStyleName;
     283             :     PropertyValueVector_t   aPropertyValues;
     284             : 
     285           0 :     ListCharStylePropertyMap_t(const OUString& rCharStyleName, const PropertyValueVector_t& rPropertyValues):
     286             :         sCharStyleName( rCharStyleName ),
     287           0 :         aPropertyValues( rPropertyValues )
     288           0 :         {}
     289             : };
     290             : typedef std::vector< ListCharStylePropertyMap_t > ListCharStylePropertyVector_t;
     291             : 
     292             : 
     293           0 : struct StyleSheetTable_Impl
     294             : {
     295             :     DomainMapper&                           m_rDMapper;
     296             :     uno::Reference< text::XTextDocument>    m_xTextDocument;
     297             :     uno::Reference< beans::XPropertySet>    m_xTextDefaults;
     298             :     std::vector< StyleSheetEntryPtr >       m_aStyleSheetEntries;
     299             :     StyleSheetEntryPtr                      m_pCurrentEntry;
     300             :     PropertyMapPtr                          m_pDefaultParaProps, m_pDefaultCharProps;
     301             :     PropertyMapPtr                          m_pCurrentProps;
     302             :     StringPairMap_t                         m_aStyleNameMap;
     303             :     ListCharStylePropertyVector_t           m_aListCharStylePropertyVector;
     304             :     bool                                    m_bIsNewDoc;
     305             : 
     306             :     StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc);
     307             : 
     308             :     OUString HasListCharStyle( const PropertyValueVector_t& rCharProperties );
     309             : 
     310             :     /// Appends the given key-value pair to the list of latent style properties of the current entry.
     311             :     void AppendLatentStyleProperty(const OUString& aName, Value& rValue);
     312             : };
     313             : 
     314             : 
     315           0 : StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc ) :
     316             :             m_rDMapper( rDMapper ),
     317             :             m_xTextDocument( xTextDocument ),
     318             :             m_pCurrentEntry(),
     319           0 :             m_pDefaultParaProps(new PropertyMap),
     320           0 :             m_pDefaultCharProps(new PropertyMap),
     321           0 :             m_bIsNewDoc(bIsNewDoc)
     322             : {
     323             :     //set font height default to 10pt
     324           0 :     uno::Any aVal = uno::makeAny( double(10.) );
     325           0 :     m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT, aVal );
     326           0 :     m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_ASIAN, aVal );
     327           0 :     m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_COMPLEX, aVal );
     328           0 : }
     329             : 
     330             : 
     331           0 : OUString StyleSheetTable_Impl::HasListCharStyle( const PropertyValueVector_t& rPropValues )
     332             : {
     333           0 :     OUString sRet;
     334           0 :     ListCharStylePropertyVector_t::const_iterator aListVectorIter = m_aListCharStylePropertyVector.begin();
     335           0 :     while( aListVectorIter != m_aListCharStylePropertyVector.end() )
     336             :     {
     337             :         //if size is identical
     338           0 :         if( aListVectorIter->aPropertyValues.size() == rPropValues.size() )
     339             :         {
     340           0 :             bool bBreak = false;
     341             :             //then search for all contained properties
     342           0 :             PropertyValueVector_t::const_iterator aList1Iter = rPropValues.begin();
     343           0 :             while( aList1Iter != rPropValues.end() && !bBreak)
     344             :             {
     345             :                 //find the property
     346           0 :                 bool bElementFound = false;
     347           0 :                 PropertyValueVector_t::const_iterator aList2Iter = aListVectorIter->aPropertyValues.begin();
     348           0 :                 while( aList2Iter != aListVectorIter->aPropertyValues.end() && !bBreak )
     349             :                 {
     350           0 :                     if( aList2Iter->Name == aList1Iter->Name )
     351             :                     {
     352           0 :                         bElementFound = true;
     353           0 :                         if( aList2Iter->Value != aList1Iter->Value )
     354           0 :                             bBreak = true;
     355           0 :                         break;
     356             :                     }
     357           0 :                     ++aList2Iter;
     358             :                 }
     359             :                 //set break flag if property hasn't been found
     360           0 :                 if(!bElementFound )
     361             :                 {
     362           0 :                     bBreak = true;
     363           0 :                     break;
     364             :                 }
     365           0 :                 ++aList1Iter;
     366             :             }
     367           0 :             if( !bBreak )
     368           0 :                 return aListVectorIter->sCharStyleName;
     369             :         }
     370           0 :         ++aListVectorIter;
     371             :     }
     372           0 :     return sRet;
     373             : }
     374             : 
     375           0 : void StyleSheetTable_Impl::AppendLatentStyleProperty(const OUString& aName, Value& rValue)
     376             : {
     377           0 :     beans::PropertyValue aValue;
     378           0 :     aValue.Name = aName;
     379           0 :     aValue.Value <<= rValue.getString();
     380           0 :     m_pCurrentEntry->aLatentStyles.push_back(aValue);
     381           0 : }
     382             : 
     383             : 
     384           0 : StyleSheetTable::StyleSheetTable(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc)
     385             : : LoggedProperties(dmapper_logger, "StyleSheetTable")
     386             : , LoggedTable(dmapper_logger, "StyleSheetTable")
     387           0 : , m_pImpl( new StyleSheetTable_Impl(rDMapper, xTextDocument, bIsNewDoc) )
     388             : {
     389           0 : }
     390             : 
     391             : 
     392           0 : StyleSheetTable::~StyleSheetTable()
     393             : {
     394           0 :     delete m_pImpl;
     395           0 : }
     396             : 
     397           0 : PropertyMapPtr StyleSheetTable::GetDefaultCharProps()
     398             : {
     399           0 :     return m_pImpl->m_pDefaultCharProps;
     400             : }
     401             : 
     402           0 : void StyleSheetTable::lcl_attribute(Id Name, Value & val)
     403             : {
     404             :     OSL_ENSURE( m_pImpl->m_pCurrentEntry, "current entry has to be set here");
     405           0 :     if(!m_pImpl->m_pCurrentEntry)
     406           0 :         return ;
     407           0 :     int nIntValue = val.getInt();
     408             :     (void)nIntValue;
     409           0 :     OUString sValue = val.getString();
     410             : 
     411             :     // The default type is paragraph, and it needs to be processed first,
     412             :     // because the NS_ooxml::LN_CT_Style_type handling may set m_pImpl->m_pCurrentEntry
     413             :     // to point to a different object.
     414           0 :     if( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_UNKNOWN )
     415             :     {
     416           0 :         if( Name != NS_ooxml::LN_CT_Style_type )
     417           0 :             m_pImpl->m_pCurrentEntry->nStyleTypeCode = STYLE_TYPE_PARA;
     418             :     }
     419           0 :     switch(Name)
     420             :     {
     421             :         case NS_ooxml::LN_CT_Style_type:
     422             :         {
     423             :             SAL_WARN_IF( m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN,
     424             :                 "writerfilter", "Style type needs to be processed first" );
     425           0 :             StyleType nType = ( StyleType ) nIntValue;
     426           0 :             if ( nType == STYLE_TYPE_TABLE )
     427             :             {
     428           0 :                 StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry;
     429           0 :                 TableStyleSheetEntryPtr pTableEntry( new TableStyleSheetEntry( *pEntry.get( ), this ) );
     430           0 :                 m_pImpl->m_pCurrentEntry = pTableEntry;
     431             :             }
     432             :             else
     433           0 :                 m_pImpl->m_pCurrentEntry->nStyleTypeCode = (StyleType)nIntValue;
     434             :         }
     435           0 :         break;
     436             :         case NS_ooxml::LN_CT_Style_default:
     437           0 :             m_pImpl->m_pCurrentEntry->bIsDefaultStyle = (nIntValue != 0);
     438           0 :             if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
     439             :             {
     440           0 :                 beans::PropertyValue aValue;
     441           0 :                 aValue.Name = "default";
     442           0 :                 aValue.Value = uno::makeAny(sal_Bool(m_pImpl->m_pCurrentEntry->bIsDefaultStyle));
     443           0 :                 m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue);
     444             :             }
     445           0 :         break;
     446             :         case NS_ooxml::LN_CT_Style_customStyle:
     447           0 :             if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
     448             :             {
     449           0 :                 beans::PropertyValue aValue;
     450           0 :                 aValue.Name = "customStyle";
     451           0 :                 aValue.Value = uno::makeAny(sal_Bool(nIntValue != 0));
     452           0 :                 m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue);
     453             :             }
     454           0 :         break;
     455             :         case NS_ooxml::LN_CT_Style_styleId:
     456           0 :             m_pImpl->m_pCurrentEntry->sStyleIdentifierI = sValue;
     457           0 :             m_pImpl->m_pCurrentEntry->sStyleIdentifierD = sValue;
     458           0 :             if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
     459             :             {
     460           0 :                 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
     461           0 :                 beans::PropertyValue aValue;
     462           0 :                 aValue.Name = "styleId";
     463           0 :                 aValue.Value = uno::makeAny(sValue);
     464           0 :                 pTableEntry->AppendInteropGrabBag(aValue);
     465             :             }
     466           0 :         break;
     467             :         case NS_ooxml::LN_CT_TblWidth_w:
     468           0 :             if (StyleSheetPropertyMap* pMap = dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() ))
     469           0 :                 pMap->SetCT_TblWidth_w( nIntValue );
     470           0 :         break;
     471             :         case NS_ooxml::LN_CT_TblWidth_type:
     472           0 :             if (StyleSheetPropertyMap* pMap = dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() ))
     473           0 :                 pMap->SetCT_TblWidth_type( nIntValue );
     474           0 :         break;
     475             :         case NS_ooxml::LN_CT_LatentStyles_defQFormat:
     476           0 :             m_pImpl->AppendLatentStyleProperty("defQFormat", val);
     477           0 :         break;
     478             :         case NS_ooxml::LN_CT_LatentStyles_defUnhideWhenUsed:
     479           0 :             m_pImpl->AppendLatentStyleProperty("defUnhideWhenUsed", val);
     480           0 :         break;
     481             :         case NS_ooxml::LN_CT_LatentStyles_defSemiHidden:
     482           0 :             m_pImpl->AppendLatentStyleProperty("defSemiHidden", val);
     483           0 :         break;
     484             :         case NS_ooxml::LN_CT_LatentStyles_count:
     485           0 :             m_pImpl->AppendLatentStyleProperty("count", val);
     486           0 :         break;
     487             :         case NS_ooxml::LN_CT_LatentStyles_defUIPriority:
     488           0 :             m_pImpl->AppendLatentStyleProperty("defUIPriority", val);
     489           0 :         break;
     490             :         case NS_ooxml::LN_CT_LatentStyles_defLockedState:
     491           0 :             m_pImpl->AppendLatentStyleProperty("defLockedState", val);
     492           0 :         break;
     493             :         default:
     494             :         {
     495             : #ifdef DEBUG_DOMAINMAPPER
     496             :             dmapper_logger->element("unhandled");
     497             : #endif
     498             :         }
     499           0 :         break;
     500           0 :     }
     501             : }
     502             : 
     503             : 
     504           0 : void StyleSheetTable::lcl_sprm(Sprm & rSprm)
     505             : {
     506           0 :     sal_uInt32 nSprmId = rSprm.getId();
     507           0 :     Value::Pointer_t pValue = rSprm.getValue();
     508           0 :     sal_Int32 nIntValue = pValue.get() ? pValue->getInt() : 0;
     509             :     (void)nIntValue;
     510           0 :     OUString sStringValue = pValue.get() ? pValue->getString() : OUString();
     511             : 
     512           0 :     switch(nSprmId)
     513             :     {
     514             :         case NS_ooxml::LN_CT_Style_name:
     515             :             //this is only a UI name!
     516           0 :             m_pImpl->m_pCurrentEntry->sStyleName = sStringValue;
     517           0 :             m_pImpl->m_pCurrentEntry->sStyleName1 = sStringValue;
     518           0 :             if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
     519             :             {
     520           0 :                 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
     521           0 :                 beans::PropertyValue aValue;
     522           0 :                 aValue.Name = "name";
     523           0 :                 aValue.Value = uno::makeAny(sStringValue);
     524           0 :                 pTableEntry->AppendInteropGrabBag(aValue);
     525             :             }
     526           0 :             break;
     527             :         case NS_ooxml::LN_CT_Style_basedOn:
     528           0 :             m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier = sStringValue;
     529           0 :             if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
     530             :             {
     531           0 :                 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
     532           0 :                 beans::PropertyValue aValue;
     533           0 :                 aValue.Name = "basedOn";
     534           0 :                 aValue.Value = uno::makeAny(sStringValue);
     535           0 :                 pTableEntry->AppendInteropGrabBag(aValue);
     536             :             }
     537           0 :             break;
     538             :         case NS_ooxml::LN_CT_Style_next:
     539           0 :             m_pImpl->m_pCurrentEntry->sNextStyleIdentifier = sStringValue;
     540           0 :             break;
     541             :         case NS_ooxml::LN_CT_Style_aliases:
     542             :         case NS_ooxml::LN_CT_Style_hidden:
     543             :         case NS_ooxml::LN_CT_Style_personal:
     544             :         case NS_ooxml::LN_CT_Style_personalCompose:
     545             :         case NS_ooxml::LN_CT_Style_personalReply:
     546           0 :         break;
     547             :         case NS_ooxml::LN_CT_Style_autoRedefine:
     548           0 :         m_pImpl->m_pCurrentEntry->bAutoRedefine = nIntValue;
     549           0 :         break;
     550             :         case NS_ooxml::LN_CT_Style_tcPr:
     551             :         {
     552           0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     553           0 :             if( pProperties.get() && m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
     554             :             {
     555           0 :                 TblStylePrHandlerPtr pTblStylePrHandler(new TblStylePrHandler(m_pImpl->m_rDMapper));
     556           0 :                 pProperties->resolve(*pTblStylePrHandler);
     557           0 :                 StyleSheetEntry* pEntry = m_pImpl->m_pCurrentEntry.get();
     558           0 :                 TableStyleSheetEntry* pTableEntry = dynamic_cast<TableStyleSheetEntry*>(pEntry);
     559           0 :                 pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tcPr"));
     560           0 :             }
     561             :         }
     562           0 :         break;
     563             :         case NS_ooxml::LN_CT_Style_trPr:
     564           0 :         break;
     565             :         case NS_ooxml::LN_CT_Style_rsid:
     566             :         case NS_ooxml::LN_CT_Style_qFormat:
     567             :         case NS_ooxml::LN_CT_Style_semiHidden:
     568             :         case NS_ooxml::LN_CT_Style_unhideWhenUsed:
     569             :         case NS_ooxml::LN_CT_Style_uiPriority:
     570             :         case NS_ooxml::LN_CT_Style_link:
     571             :         case NS_ooxml::LN_CT_Style_locked:
     572           0 :             if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
     573             :             {
     574           0 :                 StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry;
     575           0 :                 beans::PropertyValue aValue;
     576           0 :                 switch (nSprmId)
     577             :                 {
     578             :                 case NS_ooxml::LN_CT_Style_rsid:
     579             :                 {
     580             :                     // We want the rsid as a hex string, but always with the length of 8.
     581           0 :                     OUStringBuffer aBuf = OUString::number(nIntValue, 16);
     582           0 :                     OUStringBuffer aStr;
     583           0 :                     comphelper::string::padToLength(aStr, 8 - aBuf.getLength(), '0');
     584           0 :                     aStr.append(aBuf.getStr());
     585             : 
     586           0 :                     aValue.Name = "rsid";
     587           0 :                     aValue.Value = uno::makeAny(aStr.makeStringAndClear());
     588             :                 }
     589           0 :                 break;
     590             :                 case NS_ooxml::LN_CT_Style_qFormat:
     591           0 :                     aValue.Name = "qFormat";
     592           0 :                 break;
     593             :                 case NS_ooxml::LN_CT_Style_semiHidden:
     594           0 :                     aValue.Name = "semiHidden";
     595           0 :                 break;
     596             :                 case NS_ooxml::LN_CT_Style_unhideWhenUsed:
     597           0 :                     aValue.Name = "unhideWhenUsed";
     598           0 :                 break;
     599             :                 case NS_ooxml::LN_CT_Style_uiPriority:
     600             :                 {
     601           0 :                     aValue.Name = "uiPriority";
     602           0 :                     aValue.Value = uno::makeAny(OUString::number(nIntValue));
     603             :                 }
     604           0 :                 break;
     605             :                 case NS_ooxml::LN_CT_Style_link:
     606             :                 {
     607           0 :                     aValue.Name = "link";
     608           0 :                     aValue.Value = uno::makeAny(sStringValue);
     609             :                 }
     610           0 :                 break;
     611             :                 case NS_ooxml::LN_CT_Style_locked:
     612           0 :                     aValue.Name = "locked";
     613           0 :                 break;
     614             :                 }
     615           0 :                 pEntry->AppendInteropGrabBag(aValue);
     616             :             }
     617           0 :         break;
     618             :         case NS_ooxml::LN_CT_Style_tblPr: //contains table properties
     619             :         case NS_ooxml::LN_CT_Style_tblStylePr: //contains  to table properties
     620             :         case NS_ooxml::LN_CT_TblPrBase_tblInd: //table properties - at least width value and type
     621             :         case NS_ooxml::LN_EG_RPrBase_rFonts: //table fonts
     622             :         {
     623           0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     624           0 :             if( pProperties.get())
     625             :             {
     626           0 :                 TblStylePrHandlerPtr pTblStylePrHandler( new TblStylePrHandler( m_pImpl->m_rDMapper ) );
     627           0 :                 pProperties->resolve( *pTblStylePrHandler );
     628             : 
     629             :                 // Add the properties to the table style
     630           0 :                 TblStyleType nType = pTblStylePrHandler->getType( );
     631           0 :                 PropertyMapPtr pProps = pTblStylePrHandler->getProperties( );
     632           0 :                 StyleSheetEntry *  pEntry = m_pImpl->m_pCurrentEntry.get();
     633             : 
     634           0 :                 TableStyleSheetEntry * pTableEntry = dynamic_cast<TableStyleSheetEntry*>( pEntry );
     635           0 :                 if (nType == TBL_STYLE_UNKNOWN)
     636             :                 {
     637           0 :                     pEntry->pProperties->InsertProps(pProps);
     638             :                 }
     639             :                 else
     640             :                 {
     641           0 :                     if (pTableEntry != NULL)
     642           0 :                         pTableEntry->AddTblStylePr( nType, pProps );
     643             :                 }
     644             : 
     645           0 :                 if (nSprmId == NS_ooxml::LN_CT_Style_tblPr)
     646             :                 {
     647           0 :                     if (pTableEntry != NULL)
     648           0 :                         pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblPr"));
     649             :                 }
     650           0 :                 else if (nSprmId == NS_ooxml::LN_CT_Style_tblStylePr)
     651             :                 {
     652           0 :                     pTblStylePrHandler->appendInteropGrabBag("type", pTblStylePrHandler->getTypeString());
     653           0 :                     if (pTableEntry != NULL)
     654           0 :                         pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblStylePr"));
     655           0 :                 }
     656             :             }
     657           0 :             break;
     658             :         }
     659             :         case NS_ooxml::LN_CT_PPrDefault_pPr:
     660             :         case NS_ooxml::LN_CT_DocDefaults_pPrDefault:
     661           0 :             m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultParaProps );
     662           0 :             resourcemodel::resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
     663           0 :             m_pImpl->m_rDMapper.PopStyleSheetProperties();
     664           0 :             applyDefaults( true );
     665           0 :         break;
     666             :         case NS_ooxml::LN_CT_RPrDefault_rPr:
     667             :         case NS_ooxml::LN_CT_DocDefaults_rPrDefault:
     668           0 :             m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultCharProps );
     669           0 :             resourcemodel::resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
     670           0 :             m_pImpl->m_rDMapper.PopStyleSheetProperties();
     671           0 :             applyDefaults( false );
     672           0 :         break;
     673             :         case NS_ooxml::LN_CT_TblPrBase_jc:     //table alignment - row properties!
     674           0 :              m_pImpl->m_pCurrentEntry->pProperties->Insert( PROP_HORI_ORIENT,
     675           0 :                 uno::makeAny( ConversionHelper::convertTableJustification( nIntValue )));
     676           0 :         break;
     677             :         case NS_ooxml::LN_CT_TrPrBase_jc:     //table alignment - row properties!
     678           0 :             if (StyleSheetPropertyMap* pMap = dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() ))
     679           0 :                 pMap->SetCT_TrPrBase_jc(nIntValue);
     680           0 :         break;
     681             :         case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
     682             :         {
     683           0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     684           0 :             if( pProperties.get())
     685             :             {
     686           0 :                 BorderHandlerPtr pBorderHandler( new BorderHandler(m_pImpl->m_rDMapper.IsOOXMLImport()) );
     687           0 :                 pProperties->resolve(*pBorderHandler);
     688           0 :                 m_pImpl->m_pCurrentEntry->pProperties->InsertProps(
     689           0 :                         pBorderHandler->getProperties());
     690           0 :             }
     691             :         }
     692           0 :         break;
     693             :         case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize:
     694             :         case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize:
     695             :         {
     696           0 :             StyleSheetEntry* pEntry = m_pImpl->m_pCurrentEntry.get( );
     697           0 :             TableStyleSheetEntry *pTEntry = static_cast<TableStyleSheetEntry*>( pEntry );
     698           0 :             if ( pTEntry )
     699             :             {
     700           0 :                 if ( nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize )
     701           0 :                     pTEntry->m_nRowBandSize = nIntValue;
     702             :                 else
     703           0 :                     pTEntry->m_nColBandSize = nIntValue;
     704             :             }
     705             :         }
     706           0 :         break;
     707             :         case NS_ooxml::LN_CT_TblPrBase_tblCellMar:
     708             :             //no cell margins in styles
     709           0 :         break;
     710             :         case NS_ooxml::LN_CT_LatentStyles_lsdException:
     711             :         {
     712           0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     713           0 :             if (pProperties.get())
     714             :             {
     715           0 :                 LatentStyleHandlerPtr pLatentStyleHandler(new LatentStyleHandler());
     716           0 :                 pProperties->resolve(*pLatentStyleHandler);
     717           0 :                 beans::PropertyValue aValue;
     718           0 :                 aValue.Name = "lsdException";
     719           0 :                 aValue.Value = uno::makeAny(pLatentStyleHandler->getAttributes());
     720           0 :                 m_pImpl->m_pCurrentEntry->aLsdExceptions.push_back(aValue);
     721           0 :             }
     722             :         }
     723           0 :         break;
     724             :         case NS_ooxml::LN_CT_Style_pPr:
     725             :             // no break
     726             :         case NS_ooxml::LN_CT_Style_rPr:
     727             :             // no break
     728             :         default:
     729             :             {
     730           0 :                 if (!m_pImpl->m_pCurrentEntry)
     731           0 :                     break;
     732             : 
     733           0 :                 TablePropertiesHandlerPtr pTblHandler( new TablePropertiesHandler( true ) );
     734           0 :                 pTblHandler->SetProperties( m_pImpl->m_pCurrentEntry->pProperties );
     735           0 :                 if ( !pTblHandler->sprm( rSprm ) )
     736             :                 {
     737           0 :                     m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
     738             : 
     739           0 :                     PropertyMapPtr pProps(new PropertyMap());
     740           0 :                     bool bTableStyleRunProps = m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE && nSprmId == NS_ooxml::LN_CT_Style_rPr;
     741           0 :                     if (bTableStyleRunProps)
     742           0 :                         m_pImpl->m_rDMapper.setInTableStyleRunProps(true);
     743           0 :                     if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
     744             :                     {
     745           0 :                         if (nSprmId == NS_ooxml::LN_CT_Style_pPr)
     746           0 :                             m_pImpl->m_rDMapper.enableInteropGrabBag("pPr");
     747           0 :                         else if (nSprmId == NS_ooxml::LN_CT_Style_rPr)
     748           0 :                             m_pImpl->m_rDMapper.enableInteropGrabBag("rPr");
     749             :                     }
     750           0 :                     m_pImpl->m_rDMapper.sprmWithProps( rSprm, pProps );
     751           0 :                     if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
     752             :                     {
     753           0 :                         if (nSprmId == NS_ooxml::LN_CT_Style_pPr || nSprmId == NS_ooxml::LN_CT_Style_rPr)
     754             :                         {
     755           0 :                             TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
     756           0 :                             pTableEntry->AppendInteropGrabBag(m_pImpl->m_rDMapper.getInteropGrabBag());
     757             :                         }
     758             :                     }
     759           0 :                     if (bTableStyleRunProps)
     760           0 :                         m_pImpl->m_rDMapper.setInTableStyleRunProps(false);
     761             : 
     762           0 :                     m_pImpl->m_pCurrentEntry->pProperties->InsertProps(pProps);
     763             : 
     764           0 :                     m_pImpl->m_rDMapper.PopStyleSheetProperties( );
     765             : 
     766           0 :                     if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_PARA && m_pImpl->m_pCurrentEntry->bIsDefaultStyle)
     767             :                     {
     768             :                         // The current style is the default paragraph style.
     769           0 :                         PropertyMapPtr pProperties = m_pImpl->m_pCurrentEntry->pProperties;
     770           0 :                         if (pProperties->find(PROP_CHAR_HEIGHT) != pProperties->end() && m_pImpl->m_pDefaultParaProps->find(PROP_CHAR_HEIGHT) == m_pImpl->m_pDefaultParaProps->end())
     771             :                         {
     772             :                             // We provide a character height value, but a document-level default wasn't set.
     773           0 :                             if (m_pImpl->m_xTextDefaults.is())
     774             :                             {
     775           0 :                                 m_pImpl->m_xTextDefaults->setPropertyValue("CharHeight", pProperties->operator[](PROP_CHAR_HEIGHT).getValue());
     776             :                             }
     777           0 :                         }
     778           0 :                     }
     779           0 :                 }
     780             :             }
     781           0 :             break;
     782           0 : }
     783           0 : }
     784             : 
     785             : 
     786           0 : void StyleSheetTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
     787             : {
     788             :     //create a new style entry
     789             :     OSL_ENSURE( !m_pImpl->m_pCurrentEntry, "current entry has to be NULL here");
     790           0 :     StyleSheetEntryPtr pNewEntry( new StyleSheetEntry );
     791           0 :     m_pImpl->m_pCurrentEntry = pNewEntry;
     792           0 :     m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
     793           0 :     ref->resolve(*this);
     794             :     //append it to the table
     795           0 :     m_pImpl->m_rDMapper.PopStyleSheetProperties();
     796           0 :     if( !m_pImpl->m_rDMapper.IsOOXMLImport() || !m_pImpl->m_pCurrentEntry->sStyleName.isEmpty())
     797             :     {
     798           0 :         m_pImpl->m_pCurrentEntry->sConvertedStyleName = ConvertStyleName( m_pImpl->m_pCurrentEntry->sStyleName );
     799           0 :         m_pImpl->m_aStyleSheetEntries.push_back( m_pImpl->m_pCurrentEntry );
     800             :     }
     801             :     else
     802             :     {
     803             :         //TODO: this entry contains the default settings - they have to be added to the settings
     804             :     }
     805             : 
     806           0 :     if (!m_pImpl->m_pCurrentEntry->aLatentStyles.empty())
     807             :     {
     808             :         // We have latent styles for this entry, then process them.
     809           0 :         std::vector<beans::PropertyValue>& rLatentStyles = m_pImpl->m_pCurrentEntry->aLatentStyles;
     810             : 
     811           0 :         if (!m_pImpl->m_pCurrentEntry->aLsdExceptions.empty())
     812             :         {
     813           0 :             std::vector<beans::PropertyValue>& rLsdExceptions = m_pImpl->m_pCurrentEntry->aLsdExceptions;
     814           0 :             uno::Sequence<beans::PropertyValue> aLsdExceptions(rLsdExceptions.size());
     815           0 :             beans::PropertyValue* pLsdExceptions = aLsdExceptions.getArray();
     816           0 :             for (std::vector<beans::PropertyValue>::iterator i = rLsdExceptions.begin(); i != rLsdExceptions.end(); ++i)
     817           0 :                 *pLsdExceptions++ = *i;
     818             : 
     819           0 :             beans::PropertyValue aValue;
     820           0 :             aValue.Name = "lsdExceptions";
     821           0 :             aValue.Value = uno::makeAny(aLsdExceptions);
     822           0 :             rLatentStyles.push_back(aValue);
     823             :         }
     824             : 
     825           0 :         uno::Sequence<beans::PropertyValue> aLatentStyles(rLatentStyles.size());
     826           0 :         beans::PropertyValue* pLatentStyles = aLatentStyles.getArray();
     827           0 :         for (std::vector<beans::PropertyValue>::iterator i = rLatentStyles.begin(); i != rLatentStyles.end(); ++i)
     828           0 :             *pLatentStyles++ = *i;
     829             : 
     830             :         // We can put all latent style info directly to the document interop
     831             :         // grab bag, as we can be sure that only a single style entry has
     832             :         // latent style info.
     833           0 :         uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY);
     834           0 :         uno::Sequence<beans::PropertyValue> aGrabBag;
     835           0 :         xPropertySet->getPropertyValue("InteropGrabBag") >>= aGrabBag;
     836           0 :         sal_Int32 nLength = aGrabBag.getLength();
     837           0 :         aGrabBag.realloc(nLength + 1);
     838           0 :         aGrabBag[nLength].Name = "latentStyles";
     839           0 :         aGrabBag[nLength].Value = uno::makeAny(aLatentStyles);
     840           0 :         xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(aGrabBag));
     841             :     }
     842             : 
     843           0 :     StyleSheetEntryPtr pEmptyEntry;
     844           0 :     m_pImpl->m_pCurrentEntry = pEmptyEntry;
     845           0 : }
     846             : /*-------------------------------------------------------------------------
     847             :     sorting helper
     848             :   -----------------------------------------------------------------------*/
     849             : typedef std::vector< beans::PropertyValue > _PropValVector;
     850           0 : class PropValVector : public _PropValVector
     851             : {
     852             : public:
     853           0 :     PropValVector(){}
     854             : 
     855             :     void    Insert( beans::PropertyValue aVal );
     856             :     uno::Sequence< uno::Any > getValues();
     857             :     uno::Sequence< OUString > getNames();
     858             : };
     859           0 : void    PropValVector::Insert( beans::PropertyValue aVal )
     860             : {
     861           0 :     _PropValVector::iterator aIt = begin();
     862           0 :     while(aIt != end())
     863             :     {
     864           0 :         if(aIt->Name > aVal.Name)
     865             :         {
     866           0 :             insert( aIt, aVal );
     867           0 :             return;
     868             :         }
     869           0 :         ++aIt;
     870             :     }
     871           0 :     push_back( aVal );
     872             : }
     873           0 : uno::Sequence< uno::Any > PropValVector::getValues()
     874             : {
     875           0 :     uno::Sequence< uno::Any > aRet( size() );
     876           0 :     uno::Any* pValues = aRet.getArray();
     877           0 :     sal_Int32 nVal = 0;
     878           0 :     _PropValVector::iterator aIt = begin();
     879           0 :     while(aIt != end())
     880             :     {
     881           0 :         pValues[nVal++] = aIt->Value;
     882           0 :         ++aIt;
     883             :     }
     884           0 :     return aRet;
     885             : }
     886           0 : uno::Sequence< OUString > PropValVector::getNames()
     887             : {
     888           0 :     uno::Sequence< OUString > aRet( size() );
     889           0 :     OUString* pNames = aRet.getArray();
     890           0 :     sal_Int32 nVal = 0;
     891           0 :     _PropValVector::iterator aIt = begin();
     892           0 :     while(aIt != end())
     893             :     {
     894           0 :         pNames[nVal++] = aIt->Name;
     895           0 :         ++aIt;
     896             :     }
     897           0 :     return aRet;
     898             : }
     899             : 
     900             : 
     901           0 : void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable )
     902             : {
     903             :     try
     904             :     {
     905           0 :         uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
     906           0 :         uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
     907           0 :         uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
     908           0 :         uno::Reference<container::XNameContainer> xCharStyles;
     909           0 :         uno::Reference<container::XNameContainer> xParaStyles;
     910           0 :         uno::Reference<container::XNameContainer> xNumberingStyles;
     911             : 
     912           0 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     913           0 :         xStyleFamilies->getByName(rPropNameSupplier.GetName( PROP_CHARACTER_STYLES )) >>= xCharStyles;
     914           0 :         xStyleFamilies->getByName(rPropNameSupplier.GetName( PROP_PARAGRAPH_STYLES )) >>= xParaStyles;
     915           0 :         xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles;
     916           0 :         if(xCharStyles.is() && xParaStyles.is())
     917             :         {
     918           0 :             std::vector<beans::PropertyValue> aTableStylesVec;
     919           0 :             std::vector< StyleSheetEntryPtr >::iterator aIt = m_pImpl->m_aStyleSheetEntries.begin();
     920           0 :             while( aIt != m_pImpl->m_aStyleSheetEntries.end() )
     921             :             {
     922           0 :                 StyleSheetEntryPtr pEntry = *aIt;
     923           0 :                 if( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR || pEntry->nStyleTypeCode == STYLE_TYPE_PARA || pEntry->nStyleTypeCode == STYLE_TYPE_LIST )
     924             :                 {
     925           0 :                     bool bParaStyle = pEntry->nStyleTypeCode == STYLE_TYPE_PARA;
     926           0 :                     bool bListStyle = pEntry->nStyleTypeCode == STYLE_TYPE_LIST;
     927           0 :                     bool bInsert = false;
     928           0 :                     uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : (bListStyle ? xNumberingStyles : xCharStyles);
     929           0 :                     uno::Reference< style::XStyle > xStyle;
     930           0 :                     OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName );
     931             : 
     932           0 :                     if(xStyles->hasByName( sConvertedStyleName ))
     933             :                     {
     934             :                         // When pasting, don't update existing styles.
     935           0 :                         if (!m_pImpl->m_bIsNewDoc)
     936             :                         {
     937           0 :                             ++aIt;
     938           0 :                             continue;
     939             :                         }
     940           0 :                         xStyles->getByName( sConvertedStyleName ) >>= xStyle;
     941             :                     }
     942             :                     else
     943             :                     {
     944           0 :                         bInsert = true;
     945           0 :                         xStyle = uno::Reference< style::XStyle >(xDocFactory->createInstance(
     946             :                                     bParaStyle ?
     947             :                                         rPropNameSupplier.GetName( PROP_SERVICE_PARA_STYLE ) :
     948           0 :                                         (bListStyle ? OUString("com.sun.star.style.NumberingStyle") : rPropNameSupplier.GetName( PROP_SERVICE_CHAR_STYLE ))),
     949           0 :                                         uno::UNO_QUERY_THROW);
     950             : 
     951             :                         // Numbering styles have to be inserted early, as e.g. the NumberingRules property is only available after insertion.
     952           0 :                         if (bListStyle)
     953             :                         {
     954           0 :                             xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle ) );
     955           0 :                             xStyle.set(xStyles->getByName(sConvertedStyleName), uno::UNO_QUERY_THROW);
     956             : 
     957           0 :                             StyleSheetPropertyMap* pPropertyMap = dynamic_cast<StyleSheetPropertyMap*>(pEntry->pProperties.get());
     958           0 :                             if (pPropertyMap && pPropertyMap->GetListId() == -1)
     959             :                             {
     960             :                                 // No properties? Word default is 'none', Writer one is 'arabic', handle this.
     961           0 :                                 uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW);
     962           0 :                                 uno::Reference<container::XIndexReplace> xNumberingRules;
     963           0 :                                 xPropertySet->getPropertyValue("NumberingRules") >>= xNumberingRules;
     964           0 :                                 uno::Reference<container::XIndexAccess> xIndexAccess(xNumberingRules, uno::UNO_QUERY_THROW);
     965           0 :                                 for (sal_Int32 i = 0; i < xIndexAccess->getCount(); ++i)
     966             :                                 {
     967           0 :                                     uno::Sequence< beans::PropertyValue > aLvlProps(1);
     968           0 :                                     aLvlProps[0].Name = "NumberingType";
     969           0 :                                     aLvlProps[0].Value <<= style::NumberingType::NUMBER_NONE;
     970           0 :                                     xNumberingRules->replaceByIndex(i, uno::makeAny(aLvlProps));
     971           0 :                                     xPropertySet->setPropertyValue("NumberingRules", uno::makeAny(xNumberingRules));
     972           0 :                                 }
     973             :                             }
     974             :                         }
     975             :                     }
     976           0 :                     if( !pEntry->sBaseStyleIdentifier.isEmpty() )
     977             :                     {
     978             :                         try
     979             :                         {
     980             :                             //TODO: Handle cases where a paragraph <> character style relation is needed
     981           0 :                             StyleSheetEntryPtr pParent = FindStyleSheetByISTD( pEntry->sBaseStyleIdentifier );
     982             :                             // Writer core doesn't support numbering styles having a parent style, it seems
     983           0 :                             if (pParent.get() != NULL && !bListStyle)
     984           0 :                                 xStyle->setParentStyle(ConvertStyleName( pParent->sStyleName ));
     985             :                         }
     986           0 :                         catch( const uno::RuntimeException& )
     987             :                         {
     988             :                             OSL_FAIL( "Styles parent could not be set");
     989             :                         }
     990             :                     }
     991           0 :                     else if( bParaStyle )
     992             :                     {
     993             :                         //now it's time to set the default parameters - for paragraph styles
     994             :                         //Fonts: Western first entry in font table
     995             :                         //CJK: second entry
     996             :                         //CTL: third entry, if it exists
     997             : 
     998           0 :                         sal_uInt32 nFontCount = rFontTable->size();
     999           0 :                         if( !m_pImpl->m_rDMapper.IsOOXMLImport() && nFontCount > 2 )
    1000             :                         {
    1001           0 :                             uno::Any aTwoHundredFortyTwip = uno::makeAny(12.);
    1002             : 
    1003             :                             // font size to 240 twip (12 pts) for all if not set
    1004           0 :                             pEntry->pProperties->Insert(PROP_CHAR_HEIGHT, aTwoHundredFortyTwip, false);
    1005             : 
    1006             :                             // western font not already set -> apply first font
    1007           0 :                             const FontEntry::Pointer_t pWesternFontEntry(rFontTable->getFontEntry( 0 ));
    1008           0 :                             OUString sWesternFontName = pWesternFontEntry->sFontName;
    1009           0 :                             pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sWesternFontName ), false);
    1010             : 
    1011             :                             // CJK  ... apply second font
    1012           0 :                             const FontEntry::Pointer_t pCJKFontEntry(rFontTable->getFontEntry( 2 ));
    1013           0 :                             pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( pCJKFontEntry->sFontName ), false);
    1014           0 :                             pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_ASIAN, aTwoHundredFortyTwip, false);
    1015             : 
    1016             :                             // CTL  ... apply third font, if available
    1017           0 :                             if( nFontCount > 3 )
    1018             :                             {
    1019           0 :                                 const FontEntry::Pointer_t pCTLFontEntry(rFontTable->getFontEntry( 3 ));
    1020           0 :                                 pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_COMPLEX, uno::makeAny( pCTLFontEntry->sFontName ), false);
    1021           0 :                                 pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_COMPLEX, aTwoHundredFortyTwip, false);
    1022           0 :                             }
    1023             :                         }
    1024             : 
    1025             :                         // Widow/Orphan -> set both to two if not already set
    1026           0 :                         uno::Any aTwo = uno::makeAny(sal_Int8(2));
    1027           0 :                         pEntry->pProperties->Insert(PROP_PARA_WIDOWS, aTwo, false);
    1028           0 :                         pEntry->pProperties->Insert(PROP_PARA_ORPHANS, aTwo, false);
    1029             : 
    1030             :                         // Left-to-right direction if not already set
    1031           0 :                         pEntry->pProperties->Insert(PROP_WRITING_MODE, uno::makeAny( sal_Int16(text::WritingMode_LR_TB) ), false);
    1032             :                         // Left aligment if not already set
    1033           0 :                         pEntry->pProperties->Insert(PROP_PARA_ADJUST, uno::makeAny( sal_Int16(style::ParagraphAdjust_LEFT) ), false);
    1034             :                     }
    1035             : 
    1036           0 :                     uno::Sequence< beans::PropertyValue > aPropValues = pEntry->pProperties->GetPropertyValues();
    1037           0 :                     bool bAddFollowStyle = false;
    1038           0 :                     if(bParaStyle && !pEntry->sNextStyleIdentifier.isEmpty() )
    1039             :                     {
    1040           0 :                         bAddFollowStyle = true;
    1041             :                     }
    1042             : 
    1043             :                     // remove Left/RightMargin values from TOX heading styles
    1044           0 :                     if( bParaStyle )
    1045             :                     {
    1046             :                         // Set the outline levels
    1047           0 :                         const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : 0);
    1048           0 :                         if ( pStyleSheetProperties )
    1049             :                         {
    1050           0 :                             aPropValues.realloc( aPropValues.getLength( ) + 1 );
    1051             : 
    1052             :                             beans::PropertyValue aLvlVal( rPropNameSupplier.GetName( PROP_OUTLINE_LEVEL ), 0,
    1053           0 :                                     uno::makeAny( sal_Int16( pStyleSheetProperties->GetOutlineLevel( ) + 1 ) ),
    1054           0 :                                     beans::PropertyState_DIRECT_VALUE );
    1055           0 :                             aPropValues[ aPropValues.getLength( ) - 1 ] = aLvlVal;
    1056             :                         }
    1057             : 
    1058           0 :                         uno::Reference< beans::XPropertyState >xState( xStyle, uno::UNO_QUERY_THROW );
    1059           0 :                         if( sConvertedStyleName == "Contents Heading" ||
    1060           0 :                             sConvertedStyleName == "User Index Heading" ||
    1061           0 :                             sConvertedStyleName == "Index Heading" )
    1062             :                         {
    1063             :                             //left margin is set to NULL by default
    1064           0 :                             uno::Reference< beans::XPropertyState >xState1( xStyle, uno::UNO_QUERY_THROW );
    1065           0 :                             xState1->setPropertyToDefault(rPropNameSupplier.GetName( PROP_PARA_LEFT_MARGIN ));
    1066             :                         }
    1067           0 :                         else if ( sConvertedStyleName == "Text body" )
    1068           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_PARA_BOTTOM_MARGIN ));
    1069           0 :                         else if( sConvertedStyleName == "Heading 1" ||
    1070           0 :                                 sConvertedStyleName == "Heading 2" ||
    1071           0 :                                 sConvertedStyleName == "Heading 3" ||
    1072           0 :                                 sConvertedStyleName == "Heading 4" ||
    1073           0 :                                 sConvertedStyleName == "Heading 5" ||
    1074           0 :                                 sConvertedStyleName == "Heading 6" ||
    1075           0 :                                 sConvertedStyleName == "Heading 7" ||
    1076           0 :                                 sConvertedStyleName == "Heading 8" ||
    1077           0 :                                 sConvertedStyleName == "Heading 9" )
    1078             :                         {
    1079           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT ));
    1080           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT_ASIAN ));
    1081           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT_COMPLEX ));
    1082           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE ));
    1083           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE_ASIAN ));
    1084           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE_COMPLEX ));
    1085           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT        ));
    1086           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT_ASIAN  ));
    1087           0 :                             xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT_COMPLEX));
    1088             :                         }
    1089           0 :                         else if (sConvertedStyleName == "Title" || sConvertedStyleName == "Subtitle")
    1090             :                         {
    1091             :                             //set the default adjust for ParaStyle Title and Subtitle to left
    1092             :                             try
    1093             :                             {
    1094           0 :                                 uno::Reference< beans::XPropertySet > xProp( xStyle, uno::UNO_QUERY );
    1095           0 :                                 if( xProp.is() )
    1096             :                                 {
    1097           0 :                                     uno::Any aMSDefaultVal = uno::makeAny( (sal_Int16)style::ParagraphAdjust_LEFT );
    1098           0 :                                     xProp->setPropertyValue( rPropNameSupplier.GetName( PROP_PARA_ADJUST), aMSDefaultVal );
    1099           0 :                                 }
    1100             :                             }
    1101           0 :                             catch(...)
    1102             :                             {
    1103             :                                 OSL_ENSURE( false, "Default ParaAdjust style property could not be set");
    1104             :                             }
    1105           0 :                         }
    1106             :                     }
    1107             : 
    1108           0 :                     if(bAddFollowStyle || aPropValues.getLength())
    1109             :                     {
    1110           0 :                         PropValVector aSortedPropVals;
    1111           0 :                         for( sal_Int32 nProp = 0; nProp < aPropValues.getLength(); ++nProp)
    1112             :                         {
    1113             :                             // Don't add the style name properties
    1114           0 :                             bool bIsParaStyleName = aPropValues[nProp].Name == "ParaStyleName";
    1115           0 :                             bool bIsCharStyleName = aPropValues[nProp].Name == "CharStyleName";
    1116           0 :                             if ( !bIsParaStyleName && !bIsCharStyleName )
    1117             :                             {
    1118           0 :                                 aSortedPropVals.Insert( aPropValues[nProp] );
    1119             :                             }
    1120             :                         }
    1121           0 :                         if(bAddFollowStyle)
    1122             :                         {
    1123             :                             //find the name of the Next style
    1124           0 :                             std::vector< StyleSheetEntryPtr >::iterator it = m_pImpl->m_aStyleSheetEntries.begin();
    1125           0 :                             for (; it != m_pImpl->m_aStyleSheetEntries.end(); ++it)
    1126             :                             {
    1127           0 :                                 if (!(*it)->sStyleName.isEmpty() && (*it)->sStyleIdentifierD == pEntry->sNextStyleIdentifier)
    1128             :                                 {
    1129           0 :                                     beans::PropertyValue aNew;
    1130           0 :                                     aNew.Name = "FollowStyle";
    1131           0 :                                     aNew.Value = uno::makeAny(ConvertStyleName((*it)->sStyleIdentifierD));
    1132           0 :                                     aSortedPropVals.Insert(aNew);
    1133           0 :                                     break;
    1134             :                                 }
    1135             :                             }
    1136             :                         }
    1137             : 
    1138             :                         try
    1139             :                         {
    1140           0 :                             uno::Reference< beans::XMultiPropertySet > xMultiPropertySet( xStyle, uno::UNO_QUERY_THROW);
    1141           0 :                             xMultiPropertySet->setPropertyValues( aSortedPropVals.getNames(), aSortedPropVals.getValues() );
    1142             :                         }
    1143           0 :                         catch( const lang::WrappedTargetException& rWrapped)
    1144             :                         {
    1145             :                             (void) rWrapped;
    1146           0 :                             OString aMessage("Some style properties could not be set");
    1147             : #if OSL_DEBUG_LEVEL > 0
    1148             :                             beans::UnknownPropertyException aUnknownPropertyException;
    1149             : 
    1150             :                             if( rWrapped.TargetException >>= aUnknownPropertyException )
    1151             :                             {
    1152             :                                 aMessage += ": ";
    1153             :                                 OString sTemp;
    1154             :                                 aUnknownPropertyException.Message.convertToString(&sTemp, RTL_TEXTENCODING_ASCII_US, 0 );
    1155             :                                 aMessage += sTemp;
    1156             :                             }
    1157             : #endif
    1158           0 :                             SAL_WARN("writerfilter", aMessage.getStr());
    1159             :                         }
    1160           0 :                         catch( const uno::Exception& rEx)
    1161             :                         {
    1162             :                             (void) rEx;
    1163             :                             OSL_FAIL( "Some style properties could not be set");
    1164           0 :                         }
    1165             :                     }
    1166             :                     // Numbering style got inserted earlier.
    1167           0 :                     if(bInsert && !bListStyle)
    1168             :                     {
    1169           0 :                         xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle) );
    1170             :                     }
    1171             : 
    1172           0 :                     beans::PropertyValues aGrabBag = pEntry->GetInteropGrabBagSeq();
    1173           0 :                     uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY);
    1174           0 :                     if (aGrabBag.hasElements())
    1175             :                     {
    1176           0 :                         xPropertySet->setPropertyValue("StyleInteropGrabBag", uno::makeAny(aGrabBag));
    1177             :                     }
    1178             : 
    1179           0 :                     if (pEntry->bAutoRedefine)
    1180           0 :                         xPropertySet->setPropertyValue("IsAutoUpdate", uno::makeAny(sal_True));
    1181             :                 }
    1182           0 :                 else if(pEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
    1183             :                 {
    1184             :                     // If this is a table style, save its contents as-is for roundtrip purposes.
    1185           0 :                     TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(pEntry.get());
    1186           0 :                     aTableStylesVec.push_back(pTableEntry->GetInteropGrabBag());
    1187             :                 }
    1188           0 :                 ++aIt;
    1189           0 :             }
    1190             : 
    1191           0 :             if (!aTableStylesVec.empty())
    1192             :             {
    1193             :                 // If we had any table styles, add a new document-level InteropGrabBag entry for them.
    1194           0 :                 uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY);
    1195           0 :                 uno::Sequence<beans::PropertyValue> aGrabBag;
    1196           0 :                 xPropertySet->getPropertyValue("InteropGrabBag") >>= aGrabBag;
    1197           0 :                 sal_Int32 nLength = aGrabBag.getLength();
    1198           0 :                 aGrabBag.realloc(nLength + 1);
    1199           0 :                 aGrabBag[nLength].Name = "tableStyles";
    1200             : 
    1201           0 :                 uno::Sequence<beans::PropertyValue> aTableStyles(aTableStylesVec.size());
    1202           0 :                 beans::PropertyValue* pTableStyles = aTableStyles.getArray();
    1203           0 :                 for (std::vector<beans::PropertyValue>::iterator i = aTableStylesVec.begin(); i != aTableStylesVec.end(); ++i)
    1204           0 :                     *pTableStyles++ = *i;
    1205             : 
    1206           0 :                 aGrabBag[nLength].Value = uno::makeAny(aTableStyles);
    1207           0 :                 xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(aGrabBag));
    1208           0 :             }
    1209           0 :         }
    1210             :     }
    1211           0 :     catch( const uno::Exception& rException )
    1212             :     {
    1213             :         SAL_WARN("writerfilter", "Styles could not be imported completely: " << rException.Message);
    1214             :     }
    1215           0 : }
    1216             : 
    1217             : 
    1218           0 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByISTD(const OUString& sIndex)
    1219             : {
    1220           0 :     StyleSheetEntryPtr pRet;
    1221           0 :     for( sal_uInt32 nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
    1222             :     {
    1223           0 :         if( m_pImpl->m_aStyleSheetEntries[nPos]->sStyleIdentifierD == sIndex)
    1224             :         {
    1225           0 :             pRet = m_pImpl->m_aStyleSheetEntries[nPos];
    1226           0 :             break;
    1227             :         }
    1228             :     }
    1229           0 :     return pRet;
    1230             : }
    1231             : 
    1232             : 
    1233           0 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByStyleName(const OUString& sIndex)
    1234             : {
    1235           0 :     StyleSheetEntryPtr pRet;
    1236           0 :     for( sal_uInt32 nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
    1237             :     {
    1238           0 :         if( m_pImpl->m_aStyleSheetEntries[nPos]->sStyleName == sIndex)
    1239             :         {
    1240           0 :             pRet = m_pImpl->m_aStyleSheetEntries[nPos];
    1241           0 :             break;
    1242             :         }
    1243             :     }
    1244           0 :     return pRet;
    1245             : }
    1246             : 
    1247             : 
    1248           0 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByConvertedStyleName(const OUString& sIndex)
    1249             : {
    1250           0 :     StyleSheetEntryPtr pRet;
    1251           0 :     for( sal_uInt32 nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
    1252             :     {
    1253           0 :         if( m_pImpl->m_aStyleSheetEntries[nPos]->sConvertedStyleName == sIndex)
    1254             :         {
    1255           0 :             pRet = m_pImpl->m_aStyleSheetEntries[nPos];
    1256           0 :             break;
    1257             :         }
    1258             :     }
    1259           0 :     return pRet;
    1260             : }
    1261             : 
    1262             : 
    1263           0 : const StyleSheetEntryPtr StyleSheetTable::FindDefaultParaStyle()
    1264             : {
    1265           0 :     StyleSheetEntryPtr pRet;
    1266           0 :     for (size_t i = 0; i < m_pImpl->m_aStyleSheetEntries.size(); ++i)
    1267             :     {
    1268           0 :         StyleSheetEntryPtr pEntry = m_pImpl->m_aStyleSheetEntries[i];
    1269           0 :         if (pEntry->bIsDefaultStyle && pEntry->nStyleTypeCode == STYLE_TYPE_PARA)
    1270             :         {
    1271           0 :             pRet = pEntry;
    1272           0 :             break;
    1273             :         }
    1274           0 :     }
    1275           0 :     return pRet;
    1276             : }
    1277             : 
    1278           0 : const StyleSheetEntryPtr StyleSheetTable::FindParentStyleSheet(const OUString& _sBaseStyle)
    1279             : {
    1280           0 :     if( _sBaseStyle.isEmpty() )
    1281             :     {
    1282           0 :         StyleSheetEntryPtr pEmptyPtr;
    1283           0 :         return pEmptyPtr;
    1284             :     }
    1285           0 :     OUString sBaseStyle = _sBaseStyle;
    1286           0 :     if( m_pImpl->m_pCurrentEntry)
    1287           0 :         sBaseStyle = m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier;
    1288             : 
    1289           0 :     return FindStyleSheetByISTD( sBaseStyle );
    1290             : }
    1291             : 
    1292             : 
    1293             : static const sal_Char* const aStyleNamePairs[] =
    1294             : {
    1295             :     "Normal",                     "Standard",
    1296             :     "heading 1",                  "Heading 1",
    1297             :     "heading 2",                  "Heading 2",
    1298             :     "heading 3",                  "Heading 3",
    1299             :     "heading 4",                  "Heading 4",
    1300             :     "heading 5",                  "Heading 5",
    1301             :     "heading 6",                  "Heading 6",
    1302             :     "heading 7",                  "Heading 7",
    1303             :     "heading 8",                  "Heading 8",
    1304             :     "heading 9",                  "Heading 9",
    1305             :     "Heading1",                   "Heading 1",
    1306             :     "Heading2",                   "Heading 2",
    1307             :     "Heading3",                   "Heading 3",
    1308             :     "Heading4",                   "Heading 4",
    1309             :     "Heading5",                   "Heading 5",
    1310             :     "Heading6",                   "Heading 6",
    1311             :     "Heading7",                   "Heading 7",
    1312             :     "Heading8",                   "Heading 8",
    1313             :     "Heading9",                   "Heading 9",
    1314             :     "Heading 1",                  "Heading 1",
    1315             :     "Heading 2",                  "Heading 2",
    1316             :     "Heading 3",                  "Heading 3",
    1317             :     "Heading 4",                  "Heading 4",
    1318             :     "Heading 5",                  "Heading 5",
    1319             :     "Heading 6",                  "Heading 6",
    1320             :     "Heading 7",                  "Heading 7",
    1321             :     "Heading 8",                  "Heading 8",
    1322             :     "Heading 9",                  "Heading 9",
    1323             :     "Index 1",                   "Index 1",
    1324             :     "Index 2",                   "Index 2",
    1325             :     "Index 3",                   "Index 3",
    1326             :     "Index 4",                   "",
    1327             :     "Index 5",                   "",
    1328             :     "Index 6",                   "",
    1329             :     "Index 7",                   "",
    1330             :     "Index 8",                   "",
    1331             :     "Index 9",                   "",
    1332             :     "TOC 1",                     "Contents 1",
    1333             :     "TOC 2",                     "Contents 2",
    1334             :     "TOC 3",                     "Contents 3",
    1335             :     "TOC 4",                     "Contents 4",
    1336             :     "TOC 5",                     "Contents 5",
    1337             :     "TOC 6",                     "Contents 6",
    1338             :     "TOC 7",                     "Contents 7",
    1339             :     "TOC 8",                     "Contents 8",
    1340             :     "TOC 9",                     "Contents 9",
    1341             :     "TOC Heading",               "Contents Heading",
    1342             :     "TOCHeading",                "Contents Heading",
    1343             :     "toc 1",                     "Contents 1",
    1344             :     "toc 2",                     "Contents 2",
    1345             :     "toc 3",                     "Contents 3",
    1346             :     "toc 4",                     "Contents 4",
    1347             :     "toc 5",                     "Contents 5",
    1348             :     "toc 6",                     "Contents 6",
    1349             :     "toc 7",                     "Contents 7",
    1350             :     "toc 8",                     "Contents 8",
    1351             :     "toc 9",                     "Contents 9",
    1352             :     "TOC1",                     "Contents 1",
    1353             :     "TOC2",                     "Contents 2",
    1354             :     "TOC3",                     "Contents 3",
    1355             :     "TOC4",                     "Contents 4",
    1356             :     "TOC5",                     "Contents 5",
    1357             :     "TOC6",                     "Contents 6",
    1358             :     "TOC7",                     "Contents 7",
    1359             :     "TOC8",                     "Contents 8",
    1360             :     "TOC9",                     "Contents 9",
    1361             :     "Normal Indent",             "",
    1362             :     "Footnote Text",             "Footnote",
    1363             :     "Annotation Text",           "",
    1364             :     "Header",                    "Header",
    1365             :     "header",                    "Header",
    1366             :     "Footer",                    "Footer",
    1367             :     "footer",                    "Footer",
    1368             :     "Index Heading",             "Index Heading",
    1369             :     "Caption",                   "",
    1370             :     "Table of Figures",          "",
    1371             :     "Envelope Address",          "Addressee",
    1372             :     "Envelope Return",           "Sender",
    1373             :     "Footnote Reference",        "Footnote anchor",
    1374             :     "Annotation Reference",      "",
    1375             :     "Line Number",               "Line numbering",
    1376             :     "Page Number",               "Page Number",
    1377             :     "Endnote Reference",         "Endnote anchor",
    1378             :     "Endnote Text",              "Endnote Symbol",
    1379             :     "Table of Authorities",      "",
    1380             :     "Macro Text",                "",
    1381             :     "TOA Heading",               "",
    1382             :     "List",                      "List",
    1383             :     "List 2",                    "",
    1384             :     "List 3",                    "",
    1385             :     "List 4",                    "",
    1386             :     "List 5",                    "",
    1387             :     "List Bullet",               "",
    1388             :     "List Bullet 2",             "",
    1389             :     "List Bullet 3",             "",
    1390             :     "List Bullet 4",             "",
    1391             :     "List Bullet 5",             "",
    1392             :     "List Number",               "",
    1393             :     "List Number 2",             "",
    1394             :     "List Number 3",             "",
    1395             :     "List Number 4",             "",
    1396             :     "List Number 5",             "",
    1397             :     "Title",                     "Title",
    1398             :     "Closing",                   "",
    1399             :     "Signature",                 "Signature",
    1400             :     "Default Paragraph Font",    "",
    1401             :     "DefaultParagraphFont",      "Default Paragraph Font",
    1402             :     "Body Text",                 "Text body",
    1403             :     "BodyText",                  "Text body",
    1404             :     "BodyTextIndentItalic",     "Text body indent italic",
    1405             :     "Body Text Indent",          "Text body indent",
    1406             :     "BodyTextIndent",           "Text body indent",
    1407             :     "BodyTextIndent2",          "Text body indent2",
    1408             :     "List Continue",             "",
    1409             :     "List Continue 2",           "",
    1410             :     "List Continue 3",           "",
    1411             :     "List Continue 4",           "",
    1412             :     "List Continue 5",           "",
    1413             :     "Message Header",            "",
    1414             :     "Subtitle",                  "Subtitle",
    1415             :     "Salutation",                "",
    1416             :     "Date",                      "",
    1417             :     "Body Text First Indent",    "Body Text Indent",
    1418             :     "Body Text First Indent 2",  "",
    1419             :     "Note Heading",              "",
    1420             :     "Body Text 2",               "",
    1421             :     "Body Text 3",               "",
    1422             :     "Body Text Indent 2",        "",
    1423             :     "Body Text Indent 3",        "",
    1424             :     "Block Text",                "",
    1425             :     "Hyperlink",                 "Internet link",
    1426             :     "Followed Hyperlink",        "Visited Internet Link",
    1427             :     "Emphasis",                  "Emphasis",
    1428             :     "Document Map",              "",
    1429             :     "Plain Text",                "",
    1430             :     "NoList",                   "No List",
    1431             :     "AbstractHeading",          "Abstract Heading",
    1432             :     "AbstractBody",             "Abstract Body",
    1433             :     "PageNumber",               "page number"
    1434             :     "TableNormal",              "Normal Table",
    1435             :     "DocumentMap",              "Document Map"
    1436             : };
    1437             : 
    1438             : 
    1439           0 : OUString StyleSheetTable::ConvertStyleName( const OUString& rWWName, bool bExtendedSearch)
    1440             : {
    1441           0 :     OUString sRet( rWWName );
    1442           0 :     if( bExtendedSearch )
    1443             :     {
    1444             :         //search for the rWWName in the IdentifierD of the existing styles and convert the sStyleName member
    1445           0 :         std::vector< StyleSheetEntryPtr >::iterator aIt = m_pImpl->m_aStyleSheetEntries.begin();
    1446             :         //TODO: performance issue - put styles list into a map sorted by it's sStyleIdentifierD members
    1447           0 :         while( aIt != m_pImpl->m_aStyleSheetEntries.end() )
    1448             :         {
    1449           0 :             if( rWWName == ( *aIt )->sStyleIdentifierD )
    1450           0 :                 sRet = ( *aIt )->sStyleName;
    1451           0 :             ++aIt;
    1452             :         }
    1453             :     }
    1454           0 :     if(!m_pImpl->m_aStyleNameMap.size())
    1455             :     {
    1456           0 :         for( sal_uInt32 nPair = 0; nPair < sizeof(aStyleNamePairs) / sizeof( sal_Char*) / 2; ++nPair)
    1457             :         {
    1458             :                 m_pImpl->m_aStyleNameMap.insert( StringPairMap_t::value_type(
    1459           0 :                     OUString::createFromAscii(aStyleNamePairs[2 * nPair]),
    1460           0 :                     OUString::createFromAscii(aStyleNamePairs[2 * nPair + 1]) ));
    1461             :         }
    1462             :     }
    1463           0 :     StringPairMap_t::iterator aIt = m_pImpl->m_aStyleNameMap.find( sRet );
    1464           0 :     if(aIt != m_pImpl->m_aStyleNameMap.end() && !aIt->second.isEmpty())
    1465           0 :         sRet = aIt->second;
    1466           0 :     return sRet;
    1467             : }
    1468             : 
    1469           0 : OUString StyleSheetTable::GetStyleIdFromIndex(const sal_uInt32 sti)
    1470             : {
    1471           0 :     OUString sRet;
    1472           0 :     if (sti >= (sizeof(aStyleNamePairs) / sizeof( sal_Char*) / 2))
    1473           0 :         sRet = OUString();
    1474             :     else
    1475           0 :         sRet = OUString::createFromAscii(aStyleNamePairs[2 * sti]);
    1476           0 :     return sRet;
    1477             : }
    1478             : 
    1479           0 : void StyleSheetTable::applyDefaults(bool bParaProperties)
    1480             : {
    1481             :     try{
    1482           0 :         if(!m_pImpl->m_xTextDefaults.is())
    1483             :         {
    1484           0 :             m_pImpl->m_xTextDefaults = uno::Reference< beans::XPropertySet>(
    1485           0 :                 m_pImpl->m_rDMapper.GetTextFactory()->createInstance("com.sun.star.text.Defaults"),
    1486           0 :                 uno::UNO_QUERY_THROW );
    1487             :         }
    1488           0 :         if( bParaProperties && m_pImpl->m_pDefaultParaProps.get() && m_pImpl->m_pDefaultParaProps->size())
    1489             :         {
    1490           0 :             uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultParaProps->GetPropertyValues();
    1491           0 :             for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i )
    1492             :             {
    1493             :                 try
    1494             :                 {
    1495           0 :                     m_pImpl->m_xTextDefaults->setPropertyValue( aPropValues[i].Name, aPropValues[i].Value );
    1496             :                 }
    1497           0 :                 catch( const uno::Exception& )
    1498             :                 {
    1499             :                     OSL_FAIL( "setPropertyValue exception");
    1500             :                 }
    1501           0 :             }
    1502             :         }
    1503           0 :         if( !bParaProperties && m_pImpl->m_pDefaultCharProps.get() && m_pImpl->m_pDefaultCharProps->size())
    1504             :         {
    1505           0 :             uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultCharProps->GetPropertyValues();
    1506           0 :             for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i )
    1507             :             {
    1508             :                 try
    1509             :                 {
    1510           0 :                     m_pImpl->m_xTextDefaults->setPropertyValue( aPropValues[i].Name, aPropValues[i].Value );
    1511             :                 }
    1512           0 :                 catch( const uno::Exception& )
    1513             :                 {
    1514             :                     OSL_FAIL( "setPropertyValue exception");
    1515             :                 }
    1516           0 :             }
    1517             :         }
    1518             :     }
    1519           0 :     catch( const uno::Exception& )
    1520             :     {
    1521             :     }
    1522           0 : }
    1523             : 
    1524             : 
    1525           0 : OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProperties )
    1526             : {
    1527             :     //find out if any of the styles already has the required properties then return its name
    1528           0 :     OUString sListLabel = m_pImpl->HasListCharStyle(rCharProperties);
    1529           0 :     if( !sListLabel.isEmpty() )
    1530           0 :         return sListLabel;
    1531           0 :     const char cListLabel[] = "ListLabel ";
    1532           0 :     uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
    1533           0 :     uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
    1534           0 :     uno::Reference<container::XNameContainer> xCharStyles;
    1535           0 :     xStyleFamilies->getByName("CharacterStyles") >>= xCharStyles;
    1536             :     //search for all character styles with the name sListLabel + <index>
    1537           0 :     sal_Int32 nStyleFound = 0;
    1538           0 :     uno::Sequence< OUString > aStyleNames = xCharStyles->getElementNames();
    1539           0 :     const OUString* pStyleNames = aStyleNames.getConstArray();
    1540           0 :     for( sal_Int32 nStyle = 0; nStyle < aStyleNames.getLength(); ++nStyle )
    1541             :     {
    1542           0 :         if( pStyleNames[nStyle].matchAsciiL( cListLabel, sizeof( cListLabel ) - 1  ))
    1543             :         {
    1544           0 :             OUString sSuffix = pStyleNames[nStyle].copy( sizeof( cListLabel ) - 1 );
    1545           0 :             sal_Int32 nSuffix = sSuffix.toInt32();
    1546           0 :             if( nSuffix > 0 )
    1547             :             {
    1548           0 :                 if( nSuffix > nStyleFound )
    1549           0 :                     nStyleFound = nSuffix;
    1550           0 :             }
    1551             :         }
    1552             :     }
    1553           0 :     sListLabel = OUString::createFromAscii( cListLabel );
    1554           0 :     sListLabel += OUString::number( ++nStyleFound );
    1555             :     //create a new one otherwise
    1556           0 :     uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
    1557           0 :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    1558             :     try
    1559             :     {
    1560           0 :         uno::Reference< style::XStyle > xStyle( xDocFactory->createInstance(
    1561           0 :             rPropNameSupplier.GetName( PROP_SERVICE_CHAR_STYLE )), uno::UNO_QUERY_THROW);
    1562           0 :         uno::Reference< beans::XPropertySet > xStyleProps(xStyle, uno::UNO_QUERY_THROW );
    1563           0 :         PropertyValueVector_t::const_iterator aCharPropIter = rCharProperties.begin();
    1564           0 :         while( aCharPropIter != rCharProperties.end())
    1565             :         {
    1566             :             try
    1567             :             {
    1568           0 :                 xStyleProps->setPropertyValue( aCharPropIter->Name, aCharPropIter->Value );
    1569             :             }
    1570           0 :             catch( const uno::Exception& rEx )
    1571             :             {
    1572             :                 (void)rEx;
    1573             :                 OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue");
    1574             :             }
    1575           0 :             ++aCharPropIter;
    1576             :         }
    1577           0 :         xCharStyles->insertByName( sListLabel, uno::makeAny( xStyle) );
    1578           0 :         m_pImpl->m_aListCharStylePropertyVector.push_back( ListCharStylePropertyMap_t( sListLabel, rCharProperties ));
    1579             :     }
    1580           0 :     catch( const uno::Exception& rEx )
    1581             :     {
    1582             :         (void)rEx;
    1583             :         OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle");
    1584             :     }
    1585             : 
    1586           0 :     return sListLabel;
    1587             : }
    1588             : 
    1589             : }//namespace dmapper
    1590             : }//namespace writerfilter
    1591             : 
    1592             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10