LCOV - code coverage report
Current view: top level - sd/source/filter/xml - sdtransform.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 154 0.6 %
Date: 2014-11-03 Functions: 2 19 10.5 %
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             : 
      20             : #include <svl/style.hxx>
      21             : #include <svl/itemset.hxx>
      22             : #include <svl/itempool.hxx>
      23             : #include <svl/whiter.hxx>
      24             : 
      25             : #include <svx/svdoutl.hxx>
      26             : #include <editeng/xmlcnitm.hxx>
      27             : #include <svx/svdotext.hxx>
      28             : #include <svx/svdogrp.hxx>
      29             : #include <editeng/eeitem.hxx>
      30             : #include <editeng/lrspitem.hxx>
      31             : #include <editeng/numitem.hxx>
      32             : 
      33             : #include "drawdoc.hxx"
      34             : #include "glob.hxx"
      35             : #include "sdtransform.hxx"
      36             : 
      37             : using namespace ::com::sun::star::style;
      38             : 
      39           0 : class SdTransformOOo2xDocument
      40             : {
      41             : public:
      42             :     SdTransformOOo2xDocument( SdDrawDocument& rDocument );
      43             : 
      44             :     void transform();
      45             : 
      46             :     void transformMasterPages();
      47             :     void transformDrawPages();
      48             : 
      49             :     void transformStyles();
      50             :     void transformStyles( SfxStyleFamily eFam );
      51             :     void transformStyle( SfxStyleSheetBase& rSheet );
      52             : 
      53             :     void transformShapes( SdrObjList& rShapes );
      54             :     void transformShape( SdrObject& rObj );
      55             : 
      56             :     void transformTextShape( SdrTextObj& rTextShape );
      57             : 
      58             :     bool getBulletState( const SfxItemSet& rSet, SfxStyleSheetBase* pSheet, bool& rState );
      59             :     bool getBulletState( const SfxItemSet& rSet, sal_uInt16 nWhich, bool& rState );
      60             : 
      61             :     bool transformItemSet( SfxItemSet& rSet, bool bNumbering );
      62             : 
      63             :     bool removeAlienAttributes( SfxItemSet& rSet );
      64             :     bool removeAlienAttributes( SfxItemSet& rSet, sal_uInt16 nWhich );
      65             : 
      66             :     SdDrawDocument& mrDocument;
      67             :     SdrOutliner& mrOutliner;
      68             :     const OUString msEnableNumbering;
      69             :     const OUString msTextNamespace;
      70             :     const OUString msTrue;
      71             : };
      72             : 
      73             : /** transforms the given model from OOo 2.x to OOo 3.x. This maps
      74             :     the deprecated EE_PARA_BULLETSTATE and clears the EE_PARA_LRSPACE
      75             :     if used together with a EE_PARA_NUMBULLET */
      76           0 : void TransformOOo2xDocument( SdDrawDocument* pDocument )
      77             : {
      78           0 :     if( pDocument )
      79             :     {
      80           0 :         SdTransformOOo2xDocument aTransformer( *pDocument );
      81           0 :         aTransformer.transform();
      82             :     }
      83           0 : }
      84             : 
      85           0 : SdTransformOOo2xDocument::SdTransformOOo2xDocument( SdDrawDocument& rDocument )
      86             : : mrDocument( rDocument )
      87           0 : , mrOutliner( rDocument.GetDrawOutliner() )
      88             : , msEnableNumbering( "enable-numbering" )
      89             : , msTextNamespace( "urn:oasis:names:tc:opendocument:xmlns:text:1.0" )
      90           0 : , msTrue( "true" )
      91             : {
      92           0 : }
      93             : 
      94           0 : void SdTransformOOo2xDocument::transform()
      95             : {
      96           0 :     transformMasterPages();
      97           0 :     transformDrawPages();
      98           0 :     transformStyles();
      99           0 : }
     100             : 
     101           0 : void SdTransformOOo2xDocument::transformMasterPages()
     102             : {
     103           0 :     sal_uInt16 nMasterPageCount = mrDocument.GetMasterPageCount();
     104           0 :     for( sal_uInt16 nMasterPage = 0; nMasterPage < nMasterPageCount; nMasterPage++ )
     105             :     {
     106           0 :         SdrObjList* pPage = mrDocument.GetMasterPage( nMasterPage );
     107           0 :         if( pPage )
     108           0 :             transformShapes( *pPage );
     109             :     }
     110           0 : }
     111             : 
     112           0 : void SdTransformOOo2xDocument::transformDrawPages()
     113             : {
     114           0 :     sal_uInt16 nPageCount = mrDocument.GetPageCount();
     115           0 :     for( sal_uInt16 nPage = 0; nPage < nPageCount; nPage++ )
     116             :     {
     117           0 :         SdrObjList* pPage = mrDocument.GetPage( nPage );
     118           0 :         if( pPage )
     119           0 :             transformShapes( *pPage );
     120             :     }
     121           0 : }
     122             : 
     123           0 : void SdTransformOOo2xDocument::transformStyles()
     124             : {
     125           0 :     transformStyles( SD_STYLE_FAMILY_GRAPHICS );
     126           0 :     transformStyles( SD_STYLE_FAMILY_MASTERPAGE );
     127           0 : }
     128             : 
     129           0 : void SdTransformOOo2xDocument::transformStyles( SfxStyleFamily eFam )
     130             : {
     131             : 
     132           0 :     rtl::Reference< SfxStyleSheetBasePool > xStyleSheetPool( mrDocument.GetStyleSheetPool() );
     133             : 
     134           0 :     SfxStyleSheetIterator aIter( xStyleSheetPool.get(), eFam );
     135             : 
     136           0 :     SfxStyleSheetBase* pSheet = aIter.First();
     137           0 :     while( pSheet )
     138             :     {
     139           0 :         transformStyle( *pSheet );
     140           0 :         pSheet = aIter.Next();
     141           0 :     }
     142           0 : }
     143             : 
     144           0 : void SdTransformOOo2xDocument::transformStyle( SfxStyleSheetBase& rSheet )
     145             : {
     146           0 :     SfxItemSet& rSet = rSheet.GetItemSet();
     147             : 
     148           0 :     bool bState = false;
     149           0 :     getBulletState( rSheet.GetItemSet(), rSheet.GetPool().Find( rSheet.GetParent(), rSheet.GetFamily() ), bState );
     150             : 
     151           0 :     transformItemSet( rSet, bState );
     152           0 :     removeAlienAttributes( rSet );
     153           0 : }
     154             : 
     155           0 : void SdTransformOOo2xDocument::transformShapes( SdrObjList& rShapes )
     156             : {
     157           0 :     const size_t nShapeCount = rShapes.GetObjCount();
     158           0 :     for( size_t nShape = 0; nShape < nShapeCount; ++nShape )
     159             :     {
     160           0 :         SdrObject* pObj = rShapes.GetObj( nShape );
     161           0 :         if( pObj )
     162           0 :             transformShape( *pObj );
     163             :     }
     164           0 : }
     165             : 
     166           0 : void SdTransformOOo2xDocument::transformShape( SdrObject& rObj )
     167             : {
     168           0 :     SdrTextObj* pTextShape = dynamic_cast< SdrTextObj* >( &rObj );
     169           0 :     if( pTextShape )
     170             :     {
     171           0 :         transformTextShape( *pTextShape );
     172           0 :         return;
     173             :     }
     174             : 
     175           0 :     SdrObjGroup* pGroupShape = dynamic_cast< SdrObjGroup* >( &rObj );
     176           0 :     if( pGroupShape )
     177             :     {
     178           0 :         SdrObjList* pObjList = pGroupShape->GetSubList();
     179           0 :         if( pObjList )
     180           0 :             transformShapes( *pObjList );
     181           0 :         return;
     182             :     }
     183             : }
     184             : 
     185           0 : void SdTransformOOo2xDocument::transformTextShape( SdrTextObj& rTextShape )
     186             : {
     187             : 
     188           0 :     if(!rTextShape.IsEmptyPresObj())
     189             :     {
     190           0 :         OutlinerParaObject* pOPO = rTextShape.GetOutlinerParaObject();
     191           0 :         if (pOPO)
     192             :         {
     193           0 :             mrOutliner.SetText( *pOPO );
     194             : 
     195           0 :             sal_Int32 nCount = mrOutliner.GetParagraphCount();
     196             : 
     197           0 :             bool bChange = false;
     198             : 
     199           0 :             for(sal_Int32 nPara = 0; nPara < nCount; nPara++)
     200             :             {
     201           0 :                 SfxItemSet aParaSet( mrOutliner.GetParaAttribs( nPara ) );
     202             : 
     203           0 :                 bool bItemChange = false;
     204             : 
     205           0 :                 bool bState = false;
     206           0 :                 const sal_Int16 nDepth = mrOutliner.GetDepth( nPara );
     207           0 :                 if( (nDepth != -1) && (!getBulletState( aParaSet, mrOutliner.GetStyleSheet( nPara ), bState ) || !bState) )
     208             :                 {
     209             :                     // disable bullet if text::enable-bullet="false" is found
     210           0 :                     if( (nDepth > 0 ) && (rTextShape.GetObjInventor()  == SdrInventor) && (rTextShape.GetObjIdentifier() == OBJ_OUTLINETEXT) )
     211             :                     {
     212             :                         // for outline object and level > 0 burn in the style sheet because it will be changed to "outline 1"
     213           0 :                         SfxStyleSheet* pStyleSheet = mrOutliner.GetStyleSheet( nPara );
     214             : 
     215           0 :                         if( pStyleSheet )
     216             :                         {
     217             :                             // optimize me: only put items hard into paragraph that are not equal to "outline 1" style!
     218           0 :                             SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
     219             : 
     220           0 :                             SfxWhichIter aIter(aParaSet);
     221           0 :                             sal_uInt16 nWhich(aIter.FirstWhich());
     222             : 
     223             :                             // now set all none hard attributes from the style
     224           0 :                             while(nWhich)
     225             :                             {
     226           0 :                                 if(SfxItemState::SET != aParaSet.GetItemState(nWhich, true))
     227             :                                 {
     228           0 :                                     aParaSet.Put(rStyleSet.Get(nWhich));
     229           0 :                                     bItemChange = true;
     230             :                                 }
     231             : 
     232           0 :                                 nWhich = aIter.NextWhich();
     233           0 :                             }
     234             :                         }
     235             :                     }
     236             : 
     237           0 :                     mrOutliner.SetDepth( mrOutliner.GetParagraph( nPara ), -1 );
     238             : 
     239           0 :                     bChange = true;
     240             :                 }
     241             : 
     242           0 :                 bItemChange |= transformItemSet( aParaSet, bState );
     243             : 
     244           0 :                 bItemChange |= removeAlienAttributes( aParaSet );
     245             : 
     246           0 :                 if( bItemChange )
     247             :                 {
     248           0 :                     mrOutliner.SetParaAttribs( nPara, aParaSet );
     249           0 :                     bChange = true;
     250             :                 }
     251           0 :             }
     252             : 
     253           0 :             if( bChange )
     254           0 :                 rTextShape.SetOutlinerParaObject(mrOutliner.CreateParaObject());
     255             : 
     256           0 :             mrOutliner.Clear();
     257             :         }
     258             :     }
     259           0 : }
     260             : 
     261           0 : bool SdTransformOOo2xDocument::getBulletState( const SfxItemSet& rSet, SfxStyleSheetBase* pSheet, bool& rState )
     262             : {
     263           0 :     if( getBulletState( rSet, EE_PARA_XMLATTRIBS, rState ) )
     264           0 :         return true;
     265             : 
     266           0 :     if( getBulletState( rSet, SDRATTR_XMLATTRIBUTES, rState ) )
     267           0 :         return true;
     268             : 
     269           0 :     if( pSheet && getBulletState( pSheet->GetItemSet(), pSheet->GetPool().Find( pSheet->GetParent(), pSheet->GetFamily() ), rState ) )
     270           0 :         return true;
     271             : 
     272           0 :     return false;
     273             : }
     274             : 
     275           0 : bool SdTransformOOo2xDocument::getBulletState( const SfxItemSet& rSet, sal_uInt16 nWhich, bool& rState )
     276             : {
     277           0 :     if( (rSet.GetItemState( nWhich ) == SfxItemState::SET) )
     278             :     {
     279           0 :         const SvXMLAttrContainerItem& rAttr = *static_cast< const SvXMLAttrContainerItem* >( rSet.GetItem( nWhich ) );
     280             : 
     281           0 :         const sal_uInt16 nCount = rAttr.GetAttrCount();
     282           0 :         for( sal_uInt16 nItem = 0; nItem < nCount; nItem++ )
     283             :         {
     284           0 :             if( ( rAttr.GetAttrLName( nItem ) == msEnableNumbering ) && ( rAttr.GetAttrNamespace( nItem ) == msTextNamespace ) )
     285             :             {
     286           0 :                 const OUString sValue( rAttr.GetAttrValue( nItem ) );
     287           0 :                 rState = sValue.equals(msTrue);
     288           0 :                 return true;
     289             :             }
     290             :         }
     291             :     }
     292             : 
     293           0 :     return false;
     294             : }
     295             : 
     296           0 : bool SdTransformOOo2xDocument::transformItemSet( SfxItemSet& rSet, bool bNumbering )
     297             : {
     298           0 :     bool bRet = false;
     299           0 :     if( bNumbering )
     300             :     {
     301           0 :         SvxLRSpaceItem aItem( *static_cast<const SvxLRSpaceItem*>(rSet.GetItem( EE_PARA_LRSPACE )) );
     302           0 :         if( (aItem.GetLeft() != 0) || (aItem.GetTxtFirstLineOfst() != 0) )
     303             :         {
     304           0 :             aItem.SetLeftValue( 0 );
     305           0 :             aItem.SetTxtFirstLineOfst( 0 );
     306           0 :             rSet.Put( aItem );
     307           0 :             bRet = true;
     308           0 :         }
     309             :     }
     310             : 
     311           0 :     return bRet;
     312             : }
     313             : 
     314           0 : bool SdTransformOOo2xDocument::removeAlienAttributes( SfxItemSet& rSet )
     315             : {
     316           0 :     bool b = removeAlienAttributes( rSet, EE_PARA_XMLATTRIBS );
     317           0 :     b |= removeAlienAttributes( rSet, SDRATTR_XMLATTRIBUTES );
     318           0 :     return b;
     319             : }
     320             : 
     321           0 : bool SdTransformOOo2xDocument::removeAlienAttributes( SfxItemSet& rSet, sal_uInt16 nWhich )
     322             : {
     323           0 :     if( (rSet.GetItemState( nWhich ) == SfxItemState::SET) )
     324             :     {
     325           0 :         const SvXMLAttrContainerItem& rAttr = *static_cast< const SvXMLAttrContainerItem* >( rSet.GetItem( nWhich ) );
     326             : 
     327           0 :         const sal_uInt16 nCount = rAttr.GetAttrCount();
     328           0 :         for( sal_uInt16 nItem = 0; nItem < nCount; nItem++ )
     329             :         {
     330           0 :             if( ( rAttr.GetAttrLName( nItem ) == msEnableNumbering ) && ( rAttr.GetAttrNamespace( nItem ) == msTextNamespace ) )
     331             :             {
     332           0 :                 if( nCount == 1 )
     333             :                 {
     334           0 :                     rSet.ClearItem( nWhich );
     335             :                 }
     336             :                 else
     337             :                 {
     338           0 :                     SvXMLAttrContainerItem aNewItem( nWhich );
     339             : 
     340           0 :                     const sal_uInt16 nFound = nItem;
     341           0 :                     for( nItem = 0; nItem < nCount; nItem++ )
     342             :                     {
     343           0 :                         if( nItem != nFound )
     344           0 :                             aNewItem.AddAttr( rAttr.GetAttrPrefix(nItem),rAttr.GetAttrNamespace(nItem), rAttr.GetAttrLName(nItem), rAttr.GetAttrValue(nItem ) );
     345             :                     }
     346             : 
     347           0 :                     rSet.Put( aNewItem );
     348             :                 }
     349           0 :                 return true;
     350             :             }
     351             :         }
     352             :     }
     353           0 :     return false;
     354         114 : }
     355             : 
     356             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10