LCOV - code coverage report
Current view: top level - xmloff/source/text - txtsecte.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 71 91.5 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 97 184 52.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <xmloff/txtparae.hxx>
      31                 :            : #include <rtl/ustring.hxx>
      32                 :            : #include <rtl/ustrbuf.hxx>
      33                 :            : 
      34                 :            : #include <vector>
      35                 :            : 
      36                 :            : 
      37                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      38                 :            : #include <com/sun/star/container/XIndexReplace.hpp>
      39                 :            : 
      40                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      41                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      42                 :            : #include <com/sun/star/beans/PropertyValues.hpp>
      43                 :            : #include <com/sun/star/beans/PropertyState.hpp>
      44                 :            : #include <com/sun/star/text/XText.hpp>
      45                 :            : #include <com/sun/star/text/XTextSection.hpp>
      46                 :            : #include <com/sun/star/text/SectionFileLink.hpp>
      47                 :            : #include <com/sun/star/container/XNamed.hpp>
      48                 :            : #include <com/sun/star/text/XDocumentIndex.hpp>
      49                 :            : #include "xmloff/xmlnmspe.hxx"
      50                 :            : #include <xmloff/families.hxx>
      51                 :            : #include <xmloff/xmluconv.hxx>
      52                 :            : #include <xmloff/nmspmap.hxx>
      53                 :            : #include <xmloff/xmlexp.hxx>
      54                 :            : #include <xmloff/xmltkmap.hxx>
      55                 :            : #include "XMLTextNumRuleInfo.hxx"
      56                 :            : #include "XMLSectionExport.hxx"
      57                 :            : #include "XMLRedlineExport.hxx"
      58                 :            : #include "MultiPropertySetHelper.hxx"
      59                 :            : 
      60                 :            : using namespace ::com::sun::star;
      61                 :            : using namespace ::com::sun::star::text;
      62                 :            : using namespace ::com::sun::star::uno;
      63                 :            : using namespace ::std;
      64                 :            : 
      65                 :            : using ::rtl::OUString;
      66                 :            : using ::rtl::OUStringBuffer;
      67                 :            : using ::com::sun::star::beans::XPropertySet;
      68                 :            : using ::com::sun::star::beans::PropertyValue;
      69                 :            : using ::com::sun::star::beans::PropertyValues;
      70                 :            : using ::com::sun::star::beans::PropertyState;
      71                 :            : using ::com::sun::star::container::XIndexReplace;
      72                 :            : using ::com::sun::star::container::XNamed;
      73                 :            : using ::com::sun::star::lang::XServiceInfo;
      74                 :            : 
      75                 :        146 : void XMLTextParagraphExport::exportListAndSectionChange(
      76                 :            :     Reference<XTextSection> & rPrevSection,
      77                 :            :     const Reference<XTextContent> & rNextSectionContent,
      78                 :            :     const XMLTextNumRuleInfo& rPrevRule,
      79                 :            :     const XMLTextNumRuleInfo& rNextRule,
      80                 :            :     sal_Bool bAutoStyles)
      81                 :            : {
      82                 :        146 :     Reference<XTextSection> xNextSection;
      83                 :            : 
      84                 :            :     // first: get current XTextSection
      85         [ +  - ]:        146 :     Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
      86         [ +  - ]:        146 :     if (xPropSet.is())
      87                 :            :     {
      88 [ +  - ][ +  - ]:        146 :         if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
         [ +  - ][ +  - ]
                 [ -  + ]
      89                 :            :         {
      90 [ #  # ][ #  # ]:          0 :             xPropSet->getPropertyValue(sTextSection) >>= xNextSection;
                 [ #  # ]
      91                 :            :         }
      92                 :            :         // else: no current section
      93                 :            :     }
      94                 :            : 
      95                 :            :     exportListAndSectionChange(rPrevSection, xNextSection,
      96         [ +  - ]:        146 :                                rPrevRule, rNextRule, bAutoStyles);
      97                 :        146 : }
      98                 :            : 
      99                 :        244 : void XMLTextParagraphExport::exportListAndSectionChange(
     100                 :            :     Reference<XTextSection> & rPrevSection,
     101                 :            :     MultiPropertySetHelper& rPropSetHelper,
     102                 :            :     sal_Int16 nTextSectionId,
     103                 :            :     const Reference<XTextContent> & rNextSectionContent,
     104                 :            :     const XMLTextNumRuleInfo& rPrevRule,
     105                 :            :     const XMLTextNumRuleInfo& rNextRule,
     106                 :            :     sal_Bool bAutoStyles)
     107                 :            : {
     108                 :        244 :     Reference<XTextSection> xNextSection;
     109                 :            : 
     110                 :            :     // first: get current XTextSection
     111         [ +  - ]:        244 :     Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
     112         [ +  - ]:        244 :     if (xPropSet.is())
     113                 :            :     {
     114 [ +  - ][ +  + ]:        244 :         if( !rPropSetHelper.checkedProperties() )
     115 [ +  - ][ +  - ]:         88 :             rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
                 [ +  - ]
     116         [ +  + ]:        244 :         if( rPropSetHelper.hasProperty( nTextSectionId ))
     117                 :            :         {
     118                 :            :             xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
     119 [ +  - ][ +  - ]:        177 :                 sal_True ), uno::UNO_QUERY);
     120                 :            :         }
     121                 :            :         // else: no current section
     122                 :            :     }
     123                 :            : 
     124                 :            :     exportListAndSectionChange(rPrevSection, xNextSection,
     125         [ +  - ]:        244 :                                rPrevRule, rNextRule, bAutoStyles);
     126                 :        244 : }
     127                 :            : 
     128                 :        478 : void XMLTextParagraphExport::exportListAndSectionChange(
     129                 :            :     Reference<XTextSection> & rPrevSection,
     130                 :            :     const Reference<XTextSection> & rNextSection,
     131                 :            :     const XMLTextNumRuleInfo& rPrevRule,
     132                 :            :     const XMLTextNumRuleInfo& rNextRule,
     133                 :            :     sal_Bool bAutoStyles)
     134                 :            : {
     135                 :            :     // old != new? -> maybe we have to start or end a new section
     136         [ +  + ]:        478 :     if (rPrevSection != rNextSection)
     137                 :            :     {
     138                 :            :         // a new section started, or an old one gets closed!
     139                 :            : 
     140                 :            :         // close old list
     141         [ +  - ]:         34 :         XMLTextNumRuleInfo aEmptyNumRuleInfo;
     142         [ +  - ]:         34 :         if ( !bAutoStyles )
     143         [ +  - ]:         34 :             exportListChange(rPrevRule, aEmptyNumRuleInfo);
     144                 :            : 
     145                 :            :         // Build stacks of old and new sections
     146                 :            :         // Sections on top of mute sections should not be on the stack
     147         [ +  - ]:         34 :         vector< Reference<XTextSection> > aOldStack;
     148                 :         34 :         Reference<XTextSection> aCurrent(rPrevSection);
     149         [ +  + ]:         66 :         while(aCurrent.is())
     150                 :            :         {
     151                 :            :             // if we have a mute section, ignore all its children
     152                 :            :             // (all previous ones)
     153 [ +  - ][ -  + ]:         32 :             if (pSectionExport->IsMuteSection(aCurrent))
     154                 :          0 :                 aOldStack.clear();
     155                 :            : 
     156         [ +  - ]:         32 :             aOldStack.push_back(aCurrent);
     157 [ +  - ][ +  - ]:         32 :             aCurrent.set(aCurrent->getParentSection());
                 [ +  - ]
     158                 :            :         }
     159                 :            : 
     160         [ +  - ]:         34 :         vector< Reference<XTextSection> > aNewStack;
     161         [ +  - ]:         34 :         aCurrent.set(rNextSection);
     162                 :         34 :         sal_Bool bMute = sal_False;
     163         [ +  + ]:         66 :         while(aCurrent.is())
     164                 :            :         {
     165                 :            :             // if we have a mute section, ignore all its children
     166                 :            :             // (all previous ones)
     167 [ +  - ][ -  + ]:         32 :             if (pSectionExport->IsMuteSection(aCurrent))
     168                 :            :             {
     169                 :          0 :                 aNewStack.clear();
     170                 :          0 :                 bMute = sal_True;
     171                 :            :             }
     172                 :            : 
     173         [ +  - ]:         32 :             aNewStack.push_back(aCurrent);
     174 [ +  - ][ +  - ]:         32 :             aCurrent.set(aCurrent->getParentSection());
                 [ +  - ]
     175                 :            :         }
     176                 :            : 
     177                 :            :         // compare the two stacks
     178                 :            :         vector<Reference<XTextSection> > ::reverse_iterator aOld =
     179                 :         34 :             aOldStack.rbegin();
     180                 :            :         vector<Reference<XTextSection> > ::reverse_iterator aNew =
     181                 :         34 :             aNewStack.rbegin();
     182                 :            :         // compare bottom sections and skip equal section
     183 [ +  - ][ +  + ]:         88 :         while ( (aOld != aOldStack.rend()) &&
         [ +  + ][ -  + ]
                 [ +  - ]
           [ -  +  #  # ]
     184 [ +  - ][ +  + ]:         52 :                 (aNew != aNewStack.rend()) &&
                 [ #  # ]
     185 [ +  - ][ +  - ]:          2 :                 (*aOld) == (*aNew) )
                 [ +  - ]
     186                 :            :         {
     187         [ #  # ]:          0 :             ++aOld;
     188         [ #  # ]:          0 :             ++aNew;
     189                 :            :         }
     190                 :            : 
     191                 :            :         // close all elements of aOld ...
     192                 :            :         // (order: newest to oldest)
     193 [ +  - ][ +  + ]:         34 :         if (aOld != aOldStack.rend())
     194                 :            :         {
     195                 :            :             vector<Reference<XTextSection> > ::iterator aOldForward(
     196                 :         18 :                 aOldStack.begin());
     197 [ +  - ][ +  - ]:         64 :             while ((aOldForward != aOldStack.end()) &&
         [ +  + ][ +  - ]
           [ +  +  #  # ]
     198 [ +  - ][ +  - ]:         32 :                    (*aOldForward != *aOld))
     199                 :            :             {
     200 [ +  - ][ +  - ]:         14 :                 if ( !bAutoStyles && (NULL != pRedlineExport) )
     201                 :         14 :                     pRedlineExport->ExportStartOrEndRedline(*aOldForward,
     202         [ +  - ]:         14 :                                                                 sal_False);
     203         [ +  - ]:         14 :                 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
     204                 :         14 :                 ++aOldForward;
     205                 :            :             }
     206 [ +  - ][ +  - ]:         18 :             if (aOldForward != aOldStack.end())
     207                 :            :             {
     208 [ +  - ][ +  - ]:         18 :                 if ( !bAutoStyles && (NULL != pRedlineExport) )
     209                 :         18 :                     pRedlineExport->ExportStartOrEndRedline(*aOldForward,
     210         [ +  - ]:         18 :                                                             sal_False);
     211         [ +  - ]:         18 :                 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
     212                 :            :             }
     213                 :            :         }
     214                 :            : 
     215                 :            :         // ...then open all of aNew
     216                 :            :         // (order: oldest to newest)
     217 [ +  - ][ +  + ]:         66 :         while (aNew != aNewStack.rend())
     218                 :            :         {
     219 [ +  - ][ +  - ]:         32 :             if ( !bAutoStyles && (NULL != pRedlineExport) )
     220 [ +  - ][ +  - ]:         32 :                 pRedlineExport->ExportStartOrEndRedline(*aNew, sal_True);
     221 [ +  - ][ +  - ]:         32 :             pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
     222         [ +  - ]:         32 :             ++aNew;
     223                 :            :         }
     224                 :            : 
     225                 :            :         // start new list
     226 [ +  - ][ +  - ]:         34 :         if ( !bAutoStyles && !bMute )
     227 [ +  - ][ +  - ]:         34 :             exportListChange(aEmptyNumRuleInfo, rNextRule);
     228                 :            :     }
     229                 :            :     else
     230                 :            :     {
     231                 :            :         // list change, if sections have not changed
     232         [ +  + ]:        444 :         if ( !bAutoStyles )
     233                 :        298 :             exportListChange(rPrevRule, rNextRule);
     234                 :            :     }
     235                 :            : 
     236                 :            :     // save old section (old numRule gets saved in calling method)
     237                 :        478 :     rPrevSection.set(rNextSection);
     238                 :        478 : }
     239                 :            : 
     240                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10