LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/text - txtsecte.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 71 33.8 %
Date: 2012-12-27 Functions: 3 3 100.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             : 
      20             : 
      21             : #include <xmloff/txtparae.hxx>
      22             : #include <rtl/ustring.hxx>
      23             : #include <rtl/ustrbuf.hxx>
      24             : 
      25             : #include <vector>
      26             : 
      27             : 
      28             : #include <com/sun/star/lang/XServiceInfo.hpp>
      29             : #include <com/sun/star/container/XIndexReplace.hpp>
      30             : 
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : #include <com/sun/star/beans/PropertyValue.hpp>
      33             : #include <com/sun/star/beans/PropertyValues.hpp>
      34             : #include <com/sun/star/beans/PropertyState.hpp>
      35             : #include <com/sun/star/text/XText.hpp>
      36             : #include <com/sun/star/text/XTextSection.hpp>
      37             : #include <com/sun/star/text/SectionFileLink.hpp>
      38             : #include <com/sun/star/container/XNamed.hpp>
      39             : #include <com/sun/star/text/XDocumentIndex.hpp>
      40             : #include "xmloff/xmlnmspe.hxx"
      41             : #include <xmloff/families.hxx>
      42             : #include <xmloff/xmluconv.hxx>
      43             : #include <xmloff/nmspmap.hxx>
      44             : #include <xmloff/xmlexp.hxx>
      45             : #include <xmloff/xmltkmap.hxx>
      46             : #include "XMLTextNumRuleInfo.hxx"
      47             : #include "XMLSectionExport.hxx"
      48             : #include "XMLRedlineExport.hxx"
      49             : #include "MultiPropertySetHelper.hxx"
      50             : 
      51             : using namespace ::com::sun::star;
      52             : using namespace ::com::sun::star::text;
      53             : using namespace ::com::sun::star::uno;
      54             : using namespace ::std;
      55             : 
      56             : using ::rtl::OUString;
      57             : using ::rtl::OUStringBuffer;
      58             : using ::com::sun::star::beans::XPropertySet;
      59             : using ::com::sun::star::beans::PropertyValue;
      60             : using ::com::sun::star::beans::PropertyValues;
      61             : using ::com::sun::star::beans::PropertyState;
      62             : using ::com::sun::star::container::XIndexReplace;
      63             : using ::com::sun::star::container::XNamed;
      64             : using ::com::sun::star::lang::XServiceInfo;
      65             : 
      66          62 : void XMLTextParagraphExport::exportListAndSectionChange(
      67             :     Reference<XTextSection> & rPrevSection,
      68             :     const Reference<XTextContent> & rNextSectionContent,
      69             :     const XMLTextNumRuleInfo& rPrevRule,
      70             :     const XMLTextNumRuleInfo& rNextRule,
      71             :     sal_Bool bAutoStyles)
      72             : {
      73          62 :     Reference<XTextSection> xNextSection;
      74             : 
      75             :     // first: get current XTextSection
      76          62 :     Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
      77          62 :     if (xPropSet.is())
      78             :     {
      79          62 :         if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
      80             :         {
      81          12 :             xPropSet->getPropertyValue(sTextSection) >>= xNextSection;
      82             :         }
      83             :         // else: no current section
      84             :     }
      85             : 
      86             :     exportListAndSectionChange(rPrevSection, xNextSection,
      87          62 :                                rPrevRule, rNextRule, bAutoStyles);
      88          62 : }
      89             : 
      90          30 : void XMLTextParagraphExport::exportListAndSectionChange(
      91             :     Reference<XTextSection> & rPrevSection,
      92             :     MultiPropertySetHelper& rPropSetHelper,
      93             :     sal_Int16 nTextSectionId,
      94             :     const Reference<XTextContent> & rNextSectionContent,
      95             :     const XMLTextNumRuleInfo& rPrevRule,
      96             :     const XMLTextNumRuleInfo& rNextRule,
      97             :     sal_Bool bAutoStyles)
      98             : {
      99          30 :     Reference<XTextSection> xNextSection;
     100             : 
     101             :     // first: get current XTextSection
     102          30 :     Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
     103          30 :     if (xPropSet.is())
     104             :     {
     105          30 :         if( !rPropSetHelper.checkedProperties() )
     106          25 :             rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
     107          30 :         if( rPropSetHelper.hasProperty( nTextSectionId ))
     108             :         {
     109             :             xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
     110          19 :                 sal_True ), uno::UNO_QUERY);
     111             :         }
     112             :         // else: no current section
     113             :     }
     114             : 
     115             :     exportListAndSectionChange(rPrevSection, xNextSection,
     116          30 :                                rPrevRule, rNextRule, bAutoStyles);
     117          30 : }
     118             : 
     119         117 : void XMLTextParagraphExport::exportListAndSectionChange(
     120             :     Reference<XTextSection> & rPrevSection,
     121             :     const Reference<XTextSection> & rNextSection,
     122             :     const XMLTextNumRuleInfo& rPrevRule,
     123             :     const XMLTextNumRuleInfo& rNextRule,
     124             :     sal_Bool bAutoStyles)
     125             : {
     126             :     // old != new? -> maybe we have to start or end a new section
     127         117 :     if (rPrevSection != rNextSection)
     128             :     {
     129             :         // a new section started, or an old one gets closed!
     130             : 
     131             :         // close old list
     132           0 :         XMLTextNumRuleInfo aEmptyNumRuleInfo;
     133           0 :         if ( !bAutoStyles )
     134           0 :             exportListChange(rPrevRule, aEmptyNumRuleInfo);
     135             : 
     136             :         // Build stacks of old and new sections
     137             :         // Sections on top of mute sections should not be on the stack
     138           0 :         vector< Reference<XTextSection> > aOldStack;
     139           0 :         Reference<XTextSection> aCurrent(rPrevSection);
     140           0 :         while(aCurrent.is())
     141             :         {
     142             :             // if we have a mute section, ignore all its children
     143             :             // (all previous ones)
     144           0 :             if (pSectionExport->IsMuteSection(aCurrent))
     145           0 :                 aOldStack.clear();
     146             : 
     147           0 :             aOldStack.push_back(aCurrent);
     148           0 :             aCurrent.set(aCurrent->getParentSection());
     149             :         }
     150             : 
     151           0 :         vector< Reference<XTextSection> > aNewStack;
     152           0 :         aCurrent.set(rNextSection);
     153           0 :         sal_Bool bMute = sal_False;
     154           0 :         while(aCurrent.is())
     155             :         {
     156             :             // if we have a mute section, ignore all its children
     157             :             // (all previous ones)
     158           0 :             if (pSectionExport->IsMuteSection(aCurrent))
     159             :             {
     160           0 :                 aNewStack.clear();
     161           0 :                 bMute = sal_True;
     162             :             }
     163             : 
     164           0 :             aNewStack.push_back(aCurrent);
     165           0 :             aCurrent.set(aCurrent->getParentSection());
     166             :         }
     167             : 
     168             :         // compare the two stacks
     169             :         vector<Reference<XTextSection> > ::reverse_iterator aOld =
     170           0 :             aOldStack.rbegin();
     171             :         vector<Reference<XTextSection> > ::reverse_iterator aNew =
     172           0 :             aNewStack.rbegin();
     173             :         // compare bottom sections and skip equal section
     174           0 :         while ( (aOld != aOldStack.rend()) &&
     175           0 :                 (aNew != aNewStack.rend()) &&
     176           0 :                 (*aOld) == (*aNew) )
     177             :         {
     178           0 :             ++aOld;
     179           0 :             ++aNew;
     180             :         }
     181             : 
     182             :         // close all elements of aOld ...
     183             :         // (order: newest to oldest)
     184           0 :         if (aOld != aOldStack.rend())
     185             :         {
     186             :             vector<Reference<XTextSection> > ::iterator aOldForward(
     187           0 :                 aOldStack.begin());
     188           0 :             while ((aOldForward != aOldStack.end()) &&
     189           0 :                    (*aOldForward != *aOld))
     190             :             {
     191           0 :                 if ( !bAutoStyles && (NULL != pRedlineExport) )
     192           0 :                     pRedlineExport->ExportStartOrEndRedline(*aOldForward,
     193           0 :                                                                 sal_False);
     194           0 :                 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
     195           0 :                 ++aOldForward;
     196             :             }
     197           0 :             if (aOldForward != aOldStack.end())
     198             :             {
     199           0 :                 if ( !bAutoStyles && (NULL != pRedlineExport) )
     200           0 :                     pRedlineExport->ExportStartOrEndRedline(*aOldForward,
     201           0 :                                                             sal_False);
     202           0 :                 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
     203             :             }
     204             :         }
     205             : 
     206             :         // ...then open all of aNew
     207             :         // (order: oldest to newest)
     208           0 :         while (aNew != aNewStack.rend())
     209             :         {
     210           0 :             if ( !bAutoStyles && (NULL != pRedlineExport) )
     211           0 :                 pRedlineExport->ExportStartOrEndRedline(*aNew, sal_True);
     212           0 :             pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
     213           0 :             ++aNew;
     214             :         }
     215             : 
     216             :         // start new list
     217           0 :         if ( !bAutoStyles && !bMute )
     218           0 :             exportListChange(aEmptyNumRuleInfo, rNextRule);
     219             :     }
     220             :     else
     221             :     {
     222             :         // list change, if sections have not changed
     223         117 :         if ( !bAutoStyles )
     224          55 :             exportListChange(rPrevRule, rNextRule);
     225             :     }
     226             : 
     227             :     // save old section (old numRule gets saved in calling method)
     228         117 :     rPrevSection.set(rNextSection);
     229         117 : }
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10