LCOV - code coverage report
Current view: top level - xmloff/source/text - txtlists.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 105 201 52.2 %
Date: 2012-08-25 Functions: 14 24 58.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 94 326 28.8 %

           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 <txtlists.hxx>
      31                 :            : 
      32                 :            : #include <tools/debug.hxx>
      33                 :            : #include <tools/date.hxx>
      34                 :            : #include <tools/time.hxx>
      35                 :            : 
      36                 :            : #include <xmloff/txtimp.hxx>
      37                 :            : #include <xmloff/xmlimp.hxx>
      38                 :            : #include <xmloff/xmlnumi.hxx>
      39                 :            : 
      40                 :            : #include <com/sun/star/style/XStyle.hpp>
      41                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      42                 :            : #include "XMLTextListItemContext.hxx"
      43                 :            : #include "XMLTextListBlockContext.hxx"
      44                 :            : #include "txtparai.hxx"
      45                 :            : 
      46                 :            : 
      47                 :            : using namespace ::com::sun::star;
      48                 :            : 
      49                 :            : 
      50                 :        659 : XMLTextListsHelper::XMLTextListsHelper()
      51                 :            :    :  mpProcessedLists( 0 ),
      52                 :            :       msLastProcessedListId(),
      53                 :            :       msListStyleOfLastProcessedList(),
      54                 :            :       // Inconsistent behavior regarding lists (#i92811#)
      55                 :            :       mpMapListIdToListStyleDefaultListId( 0 ),
      56                 :            :       mpContinuingLists( 0 ),
      57 [ +  - ][ +  - ]:        659 :       mpListStack( 0 )
         [ +  - ][ +  - ]
      58                 :            : {
      59                 :        659 : }
      60                 :            : 
      61                 :        659 : XMLTextListsHelper::~XMLTextListsHelper()
      62                 :            : {
      63         [ +  + ]:        659 :     if ( mpProcessedLists )
      64                 :            :     {
      65                 :        254 :         mpProcessedLists->clear();
      66         [ +  - ]:        254 :         delete mpProcessedLists;
      67                 :            :     }
      68                 :            :     // Inconsistent behavior regarding lists (#i92811#)#
      69         [ +  + ]:        659 :     if ( mpMapListIdToListStyleDefaultListId )
      70                 :            :     {
      71                 :          5 :         mpMapListIdToListStyleDefaultListId->clear();
      72         [ +  - ]:          5 :         delete mpMapListIdToListStyleDefaultListId;
      73                 :            :     }
      74         [ -  + ]:        659 :     if ( mpContinuingLists )
      75                 :            :     {
      76                 :          0 :         mpContinuingLists->clear();
      77         [ #  # ]:          0 :         delete mpContinuingLists;
      78                 :            :     }
      79         [ -  + ]:        659 :     if ( mpListStack )
      80                 :            :     {
      81                 :          0 :         mpListStack->clear();
      82         [ #  # ]:          0 :         delete mpListStack;
      83                 :            :     }
      84                 :        659 : }
      85                 :            : 
      86                 :        362 : void XMLTextListsHelper::PushListContext(
      87                 :            :     XMLTextListBlockContext *i_pListBlock)
      88                 :            : {
      89                 :            : //    fprintf(stderr, "PushListContext\n");
      90                 :            :     mListStack.push(::boost::make_tuple(i_pListBlock,
      91                 :            :         static_cast<XMLTextListItemContext*>(0),
      92 [ +  - ][ +  - ]:        362 :         static_cast<XMLNumberedParaContext*>(0)));
         [ +  - ][ +  - ]
      93                 :        362 : }
      94                 :            : 
      95                 :          0 : void XMLTextListsHelper::PushListContext(
      96                 :            :     XMLNumberedParaContext *i_pNumberedParagraph)
      97                 :            : {
      98                 :            : //    fprintf(stderr, "PushListContext(NP)\n");
      99                 :            :     mListStack.push(::boost::make_tuple(
     100                 :            :         static_cast<XMLTextListBlockContext*>(0),
     101 [ #  # ][ #  # ]:          0 :         static_cast<XMLTextListItemContext*>(0), i_pNumberedParagraph));
         [ #  # ][ #  # ]
     102                 :          0 : }
     103                 :            : 
     104                 :        362 : void XMLTextListsHelper::PopListContext()
     105                 :            : {
     106                 :            :     OSL_ENSURE(mListStack.size(),
     107                 :            :         "internal error: PopListContext: mListStack empty");
     108                 :            : //    fprintf(stderr, "PopListContext\n");
     109         [ +  - ]:        362 :     if ( !mListStack.empty())
     110                 :        362 :         mListStack.pop();
     111                 :        362 : }
     112                 :            : 
     113                 :       1733 : void XMLTextListsHelper::ListContextTop(
     114                 :            :     XMLTextListBlockContext*& o_pListBlockContext,
     115                 :            :     XMLTextListItemContext*& o_pListItemContext,
     116                 :            :     XMLNumberedParaContext*& o_pNumberedParagraphContext )
     117                 :            : {
     118         [ +  + ]:       1733 :     if ( !mListStack.empty() ) {
     119                 :            :         o_pListBlockContext =
     120                 :        404 :             static_cast<XMLTextListBlockContext*>(&mListStack.top().get<0>());
     121                 :            :         o_pListItemContext  =
     122                 :        404 :             static_cast<XMLTextListItemContext *>(&mListStack.top().get<1>());
     123                 :            :         o_pNumberedParagraphContext =
     124                 :        404 :             static_cast<XMLNumberedParaContext *>(&mListStack.top().get<2>());
     125                 :            :     }
     126                 :       1733 : }
     127                 :            : 
     128                 :        259 : void XMLTextListsHelper::SetListItem( XMLTextListItemContext *i_pListItem )
     129                 :            : {
     130                 :            :     // may be cleared by ListBlockContext for upper list...
     131                 :            :     if (i_pListItem) {
     132                 :            :         OSL_ENSURE(mListStack.size(),
     133                 :            :             "internal error: SetListItem: mListStack empty");
     134                 :            :         OSL_ENSURE(mListStack.top().get<0>(),
     135                 :            :             "internal error: SetListItem: mListStack has no ListBlock");
     136                 :            :         OSL_ENSURE(!mListStack.top().get<1>(),
     137                 :            :             "error: SetListItem: list item already exists");
     138                 :            :     }
     139         [ +  + ]:        259 :     if ( !mListStack.empty() ) {
     140                 :        244 :         mListStack.top().get<1>() = i_pListItem;
     141                 :            :     }
     142                 :        259 : }
     143                 :            : 
     144                 :            : // Handling for parameter <sListStyleDefaultListId> (#i92811#)
     145                 :        263 : void XMLTextListsHelper::KeepListAsProcessed( ::rtl::OUString sListId,
     146                 :            :                                               ::rtl::OUString sListStyleName,
     147                 :            :                                               ::rtl::OUString sContinueListId,
     148                 :            :                                               ::rtl::OUString sListStyleDefaultListId )
     149                 :            : {
     150 [ +  - ][ +  - ]:        263 :     if ( IsListProcessed( sListId ) )
     151                 :            :     {
     152                 :            :         DBG_ASSERT( false,
     153                 :            :                     "<XMLTextListsHelper::KeepListAsProcessed(..)> - list id already added" );
     154                 :        263 :         return;
     155                 :            :     }
     156                 :            : 
     157         [ +  + ]:        263 :     if ( mpProcessedLists == 0 )
     158                 :            :     {
     159 [ +  - ][ +  - ]:        254 :         mpProcessedLists = new tMapForLists();
     160                 :            :     }
     161                 :            : 
     162                 :            :     ::std::pair< ::rtl::OUString, ::rtl::OUString >
     163                 :        263 :                                 aListData( sListStyleName, sContinueListId );
     164         [ +  - ]:        263 :     (*mpProcessedLists)[ sListId ] = aListData;
     165                 :            : 
     166                 :        263 :     msLastProcessedListId = sListId;
     167                 :        263 :     msListStyleOfLastProcessedList = sListStyleName;
     168                 :            : 
     169                 :            :     // Inconsistent behavior regarding lists (#i92811#)
     170         [ +  + ]:        263 :     if ( !sListStyleDefaultListId.isEmpty())
     171                 :            :     {
     172         [ +  + ]:          9 :         if ( mpMapListIdToListStyleDefaultListId == 0 )
     173                 :            :         {
     174 [ +  - ][ +  - ]:          5 :             mpMapListIdToListStyleDefaultListId = new tMapForLists();
     175                 :            :         }
     176                 :            : 
     177         [ +  - ]:          9 :         if ( mpMapListIdToListStyleDefaultListId->find( sListStyleName ) ==
     178         [ +  - ]:          9 :                                 mpMapListIdToListStyleDefaultListId->end() )
     179                 :            :         {
     180                 :            :             ::std::pair< ::rtl::OUString, ::rtl::OUString >
     181                 :          9 :                                 aListIdMapData( sListId, sListStyleDefaultListId );
     182         [ +  - ]:          9 :             (*mpMapListIdToListStyleDefaultListId)[ sListStyleName ] =
     183                 :          9 :                                                                 aListIdMapData;
     184                 :            :         }
     185                 :        263 :     }
     186                 :            : }
     187                 :            : 
     188                 :        286 : sal_Bool XMLTextListsHelper::IsListProcessed( const ::rtl::OUString sListId ) const
     189                 :            : {
     190         [ +  + ]:        286 :     if ( mpProcessedLists == 0 )
     191                 :            :     {
     192                 :        254 :         return sal_False;
     193                 :            :     }
     194                 :            : 
     195         [ +  - ]:        286 :     return mpProcessedLists->find( sListId ) != mpProcessedLists->end();
     196                 :            : }
     197                 :            : 
     198                 :         63 : ::rtl::OUString XMLTextListsHelper::GetListStyleOfProcessedList(
     199                 :            :                                             const ::rtl::OUString sListId ) const
     200                 :            : {
     201         [ +  - ]:         63 :     if ( mpProcessedLists != 0 )
     202                 :            :     {
     203         [ +  - ]:         63 :         tMapForLists::const_iterator aIter = mpProcessedLists->find( sListId );
     204         [ +  - ]:         63 :         if ( aIter != mpProcessedLists->end() )
     205                 :            :         {
     206                 :         63 :             return (*aIter).second.first;
     207                 :            :         }
     208                 :            :     }
     209                 :            : 
     210                 :         63 :     return ::rtl::OUString();
     211                 :            : }
     212                 :            : 
     213                 :          0 : ::rtl::OUString XMLTextListsHelper::GetContinueListIdOfProcessedList(
     214                 :            :                                             const ::rtl::OUString sListId ) const
     215                 :            : {
     216         [ #  # ]:          0 :     if ( mpProcessedLists != 0 )
     217                 :            :     {
     218         [ #  # ]:          0 :         tMapForLists::const_iterator aIter = mpProcessedLists->find( sListId );
     219         [ #  # ]:          0 :         if ( aIter != mpProcessedLists->end() )
     220                 :            :         {
     221                 :          0 :             return (*aIter).second.second;
     222                 :            :         }
     223                 :            :     }
     224                 :            : 
     225                 :          0 :     return ::rtl::OUString();
     226                 :            : }
     227                 :            : 
     228                 :          4 : const ::rtl::OUString& XMLTextListsHelper::GetLastProcessedListId() const
     229                 :            : {
     230                 :          4 :     return msLastProcessedListId;
     231                 :            : }
     232                 :            : 
     233                 :          4 : const ::rtl::OUString& XMLTextListsHelper::GetListStyleOfLastProcessedList() const
     234                 :            : {
     235                 :          4 :     return msListStyleOfLastProcessedList;
     236                 :            : }
     237                 :            : 
     238                 :          0 : ::rtl::OUString XMLTextListsHelper::GenerateNewListId() const
     239                 :            : {
     240                 :            :     // Value of xml:id in element <text:list> has to be a valid ID type (#i92478#)
     241                 :          0 :     ::rtl::OUString sTmpStr( "list"  );
     242         [ #  # ]:          0 :     sal_Int64 n = Time( Time::SYSTEM ).GetTime();
     243         [ #  # ]:          0 :     n += Date( Date::SYSTEM ).GetDate();
     244                 :          0 :     n += rand();
     245                 :            :     // Value of xml:id in element <text:list> has to be a valid ID type (#i92478#)
     246                 :          0 :     sTmpStr += ::rtl::OUString::valueOf( n );
     247                 :            : 
     248                 :          0 :     ::rtl::OUString sNewListId( sTmpStr );
     249         [ #  # ]:          0 :     if ( mpProcessedLists != 0 )
     250                 :            :     {
     251                 :          0 :         long nHitCount = 0;
     252 [ #  # ][ #  # ]:          0 :         while ( mpProcessedLists->find( sNewListId ) != mpProcessedLists->end() )
     253                 :            :         {
     254                 :          0 :             ++nHitCount;
     255                 :          0 :             sNewListId = sTmpStr;
     256                 :          0 :             sNewListId += ::rtl::OUString::valueOf( nHitCount );
     257                 :            :         }
     258                 :            :     }
     259                 :            : 
     260                 :          0 :     return sNewListId;
     261                 :            : }
     262                 :            : 
     263                 :            : // Provide list id for a certain list block for import (#i92811#)
     264                 :         63 : ::rtl::OUString XMLTextListsHelper::GetListIdForListBlock( XMLTextListBlockContext& rListBlock )
     265                 :            : {
     266                 :         63 :     ::rtl::OUString sListBlockListId( rListBlock.GetContinueListId() );
     267         [ +  - ]:         63 :     if ( sListBlockListId.isEmpty() )
     268                 :            :     {
     269         [ +  - ]:         63 :         sListBlockListId = rListBlock.GetListId();
     270                 :            :     }
     271                 :            : 
     272         [ +  - ]:         63 :     if ( mpMapListIdToListStyleDefaultListId != 0 )
     273                 :            :     {
     274         [ +  - ]:         63 :         if ( !sListBlockListId.isEmpty() )
     275                 :            :         {
     276                 :            :             const ::rtl::OUString sListStyleName =
     277         [ +  - ]:         63 :                                 GetListStyleOfProcessedList( sListBlockListId );
     278                 :            : 
     279                 :            :             tMapForLists::const_iterator aIter =
     280         [ +  - ]:         63 :                     mpMapListIdToListStyleDefaultListId->find( sListStyleName );
     281         [ +  - ]:         63 :             if ( aIter != mpMapListIdToListStyleDefaultListId->end() )
     282                 :            :             {
     283         [ +  - ]:         63 :                 if ( (*aIter).second.first == sListBlockListId )
     284                 :            :                 {
     285                 :         63 :                     sListBlockListId = (*aIter).second.second;
     286                 :            :                 }
     287                 :         63 :             }
     288                 :            :         }
     289                 :            :     }
     290                 :            : 
     291                 :         63 :     return sListBlockListId;
     292                 :            : }
     293                 :            : 
     294                 :          0 : void XMLTextListsHelper::StoreLastContinuingList( ::rtl::OUString sListId,
     295                 :            :                                                   ::rtl::OUString sContinuingListId )
     296                 :            : {
     297         [ #  # ]:          0 :     if ( mpContinuingLists == 0 )
     298                 :            :     {
     299         [ #  # ]:          0 :         mpContinuingLists = new tMapForContinuingLists();
     300                 :            :     }
     301                 :            : 
     302                 :          0 :     (*mpContinuingLists)[ sListId ] = sContinuingListId;
     303                 :          0 : }
     304                 :            : 
     305                 :          0 : ::rtl::OUString XMLTextListsHelper::GetLastContinuingListId(
     306                 :            :                                                 ::rtl::OUString sListId ) const
     307                 :            : {
     308         [ #  # ]:          0 :     if ( mpContinuingLists != 0)
     309                 :            :     {
     310                 :            :         tMapForContinuingLists::const_iterator aIter =
     311         [ #  # ]:          0 :                                                 mpContinuingLists->find( sListId );
     312         [ #  # ]:          0 :         if ( aIter != mpContinuingLists->end() )
     313                 :            :         {
     314                 :          0 :             return (*aIter).second;
     315                 :            :         }
     316                 :            :     }
     317                 :            : 
     318                 :          0 :     return sListId;
     319                 :            : }
     320                 :            : 
     321                 :          0 : void XMLTextListsHelper::PushListOnStack( ::rtl::OUString sListId,
     322                 :            :                                           ::rtl::OUString sListStyleName )
     323                 :            : {
     324         [ #  # ]:          0 :     if ( mpListStack == 0 )
     325                 :            :     {
     326 [ #  # ][ #  # ]:          0 :         mpListStack = new tStackForLists();
     327                 :            :     }
     328                 :            :     ::std::pair< ::rtl::OUString, ::rtl::OUString >
     329                 :          0 :                                 aListData( sListId, sListStyleName );
     330         [ #  # ]:          0 :     mpListStack->push_back( aListData );
     331                 :          0 : }
     332                 :          0 : void XMLTextListsHelper::PopListFromStack()
     333                 :            : {
     334   [ #  #  #  # ]:          0 :     if ( mpListStack != 0 &&
                 [ #  # ]
     335                 :          0 :          mpListStack->size() > 0 )
     336                 :            :     {
     337                 :          0 :         mpListStack->pop_back();
     338                 :            :     }
     339                 :          0 : }
     340                 :            : 
     341                 :          0 : sal_Bool XMLTextListsHelper::EqualsToTopListStyleOnStack( const ::rtl::OUString sListId ) const
     342                 :            : {
     343                 :            :     return mpListStack != 0
     344                 :          0 :            ? sListId == mpListStack->back().second
     345         [ #  # ]:          0 :            : sal_False;
     346                 :            : }
     347                 :            : 
     348                 :            : ::rtl::OUString
     349                 :          0 : XMLTextListsHelper::GetNumberedParagraphListId(
     350                 :            :     const sal_uInt16 i_Level,
     351                 :            :     const ::rtl::OUString i_StyleName)
     352                 :            : {
     353                 :          0 :     if (i_StyleName.isEmpty()) {
     354                 :            :         OSL_FAIL("invalid numbered-paragraph: no style-name");
     355                 :            :     }
     356 [ #  # ][ #  #  :          0 :     if (!i_StyleName.isEmpty()
             #  #  #  # ]
     357                 :          0 :         && (i_Level < mLastNumberedParagraphs.size())
     358                 :          0 :         && (mLastNumberedParagraphs[i_Level].first == i_StyleName) )
     359                 :            :     {
     360                 :            :         OSL_ENSURE(!mLastNumberedParagraphs[i_Level].second.isEmpty(),
     361                 :            :             "internal error: numbered-paragraph style-name but no list-id?");
     362                 :          0 :         return mLastNumberedParagraphs[i_Level].second;
     363                 :            :     } else {
     364                 :          0 :         return GenerateNewListId();
     365                 :            :     }
     366                 :            : }
     367                 :            : 
     368                 :            : static void
     369                 :         50 : ClampLevel(uno::Reference<container::XIndexReplace> const& i_xNumRules,
     370                 :            :     sal_Int16 & io_rLevel)
     371                 :            : {
     372                 :            :     OSL_ENSURE(i_xNumRules.is(), "internal error: ClampLevel: NumRules null");
     373         [ +  - ]:         50 :     if (i_xNumRules.is()) {
     374                 :         50 :         const sal_Int32 nLevelCount( i_xNumRules->getCount() );
     375         [ -  + ]:         50 :         if ( io_rLevel >= nLevelCount ) {
     376                 :          0 :             io_rLevel = sal::static_int_cast< sal_Int16 >(nLevelCount-1);
     377                 :            :         }
     378                 :            :     }
     379                 :         50 : }
     380                 :            : 
     381                 :            : uno::Reference<container::XIndexReplace>
     382                 :          0 : XMLTextListsHelper::EnsureNumberedParagraph(
     383                 :            :     SvXMLImport & i_rImport,
     384                 :            :     const ::rtl::OUString i_ListId,
     385                 :            :     sal_Int16 & io_rLevel, const ::rtl::OUString i_StyleName)
     386                 :            : {
     387                 :            :     OSL_ENSURE(!i_ListId.isEmpty(), "invalid ListId");
     388                 :            :     OSL_ENSURE(io_rLevel >= 0, "invalid Level");
     389         [ #  # ]:          0 :     NumParaList_t & rNPList( mNPLists[i_ListId] );
     390                 :          0 :     const ::rtl::OUString none; // default
     391 [ #  # ][ #  # ]:          0 :     if ( rNPList.empty() && (0 != io_rLevel)) {
                 [ #  # ]
     392                 :            :         // create default list style for top level
     393                 :          0 :         sal_Int16 lev(0);
     394                 :            :         rNPList.push_back(::std::make_pair(none,
     395 [ #  # ][ #  # ]:          0 :             MakeNumRule(i_rImport, 0, none, none, lev) ));
         [ #  # ][ #  # ]
                 [ #  # ]
     396                 :            :     }
     397                 :            :     // create num rule first because this might clamp the level...
     398                 :          0 :     uno::Reference<container::XIndexReplace> xNumRules;
     399 [ #  # ][ #  # ]:          0 :     if ((0 == io_rLevel) || rNPList.empty() || !i_StyleName.isEmpty()) {
         [ #  # ][ #  # ]
     400                 :            :         // no parent to inherit from, or explicit style given => new numrules!
     401                 :            :         // index of parent: level - 1, but maybe that does not exist
     402                 :            :         const size_t parent( std::min(static_cast<size_t>(io_rLevel),
     403         [ #  # ]:          0 :             rNPList.size()) - 1 );
     404                 :            :         xNumRules = MakeNumRule(i_rImport,
     405                 :          0 :             io_rLevel > 0 ? rNPList[parent].second : 0,
     406                 :          0 :             io_rLevel > 0 ? rNPList[parent].first  : none,
     407 [ #  # ][ #  # ]:          0 :             i_StyleName, io_rLevel);
         [ #  # ][ #  # ]
                 [ #  # ]
     408                 :            :     } else {
     409                 :            :         // no style given, but has a parent => reuse parent numrules!
     410 [ #  # ][ #  # ]:          0 :         ClampLevel(rNPList.back().second, io_rLevel);
     411                 :            :     }
     412         [ #  # ]:          0 :     if (static_cast<sal_uInt16>(io_rLevel) + 1U > rNPList.size()) {
     413                 :            :         // new level: need to enlarge
     414         [ #  # ]:          0 :         for (size_t i = rNPList.size();
     415                 :            :                 i < static_cast<size_t>(io_rLevel); ++i)
     416                 :            :         {
     417 [ #  # ][ #  # ]:          0 :             NumParaList_t::value_type const rule(rNPList.back());
     418         [ #  # ]:          0 :             rNPList.push_back(rule);
     419         [ #  # ]:          0 :         }
     420 [ #  # ][ #  # ]:          0 :         NumParaList_t::value_type const rule(rNPList.back());
     421                 :          0 :         rNPList.push_back(xNumRules.is()
     422                 :            :             ? ::std::make_pair(i_StyleName, xNumRules)
     423 [ #  # ][ #  # ]:          0 :             : rule);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     424                 :            :     } else {
     425                 :            :         // old level: no need to enlarge; possibly shrink
     426         [ #  # ]:          0 :         if (xNumRules.is()) {
     427 [ #  # ][ #  # ]:          0 :             rNPList[io_rLevel] = std::make_pair(i_StyleName, xNumRules);
                 [ #  # ]
     428                 :            :         }
     429         [ #  # ]:          0 :         if (static_cast<sal_uInt16>(io_rLevel) + 1U < rNPList.size()) {
     430 [ #  # ][ #  # ]:          0 :             rNPList.erase(rNPList.begin() + io_rLevel + 1, rNPList.end());
                 [ #  # ]
     431                 :            :         }
     432                 :            :     }
     433                 :            :     // remember the list id
     434         [ #  # ]:          0 :     if (mLastNumberedParagraphs.size() <= static_cast<size_t>(io_rLevel)) {
     435         [ #  # ]:          0 :         mLastNumberedParagraphs.resize(io_rLevel+1);
     436                 :            :     }
     437                 :          0 :     mLastNumberedParagraphs[io_rLevel] = std::make_pair(i_StyleName, i_ListId);
     438         [ #  # ]:          0 :     return rNPList.back().second;
     439                 :            : }
     440                 :            : 
     441                 :            : /** extracted from the XMLTextListBlockContext constructor */
     442                 :            : uno::Reference<container::XIndexReplace>
     443                 :         50 : XMLTextListsHelper::MakeNumRule(
     444                 :            :     SvXMLImport & i_rImport,
     445                 :            :     const uno::Reference<container::XIndexReplace>& i_rNumRule,
     446                 :            :     const ::rtl::OUString i_ParentStyleName,
     447                 :            :     const ::rtl::OUString i_StyleName,
     448                 :            :     sal_Int16 & io_rLevel,
     449                 :            :     sal_Bool* o_pRestartNumbering,
     450                 :            :     sal_Bool* io_pSetDefaults)
     451                 :            : {
     452 [ +  + ][ +  - ]:         50 :     static ::rtl::OUString s_NumberingRules( "NumberingRules");
     453                 :         50 :     uno::Reference<container::XIndexReplace> xNumRules(i_rNumRule);
     454 [ +  + ][ +  + ]:         50 :     if ( !i_StyleName.isEmpty() && i_StyleName != i_ParentStyleName )
                 [ +  - ]
     455                 :            :     {
     456                 :            :         const ::rtl::OUString sDisplayStyleName(
     457                 :            :             i_rImport.GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
     458         [ +  - ]:         15 :                                              i_StyleName) );
     459                 :            :         const uno::Reference < container::XNameContainer >& rNumStyles(
     460 [ +  - ][ +  - ]:         15 :                             i_rImport.GetTextImport()->GetNumberingStyles() );
         [ +  - ][ +  - ]
     461 [ +  - ][ +  - ]:         15 :         if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
         [ +  - ][ +  + ]
                 [ +  + ]
     462                 :            :         {
     463                 :          7 :             uno::Reference < style::XStyle > xStyle;
     464 [ +  - ][ +  - ]:          7 :             uno::Any any = rNumStyles->getByName( sDisplayStyleName );
     465         [ +  - ]:          7 :             any >>= xStyle;
     466                 :            : 
     467                 :            :             uno::Reference< beans::XPropertySet > xPropSet( xStyle,
     468         [ +  - ]:          7 :                 uno::UNO_QUERY );
     469 [ +  - ][ +  - ]:          7 :             any = xPropSet->getPropertyValue(s_NumberingRules);
     470         [ +  - ]:          7 :             any >>= xNumRules;
     471                 :            :         }
     472                 :            :         else
     473                 :            :         {
     474                 :            :             const SvxXMLListStyleContext *pListStyle(
     475 [ +  - ][ +  - ]:          8 :                 i_rImport.GetTextImport()->FindAutoListStyle( i_StyleName ) );
         [ +  - ][ +  - ]
     476         [ +  - ]:          8 :             if( pListStyle )
     477                 :            :             {
     478         [ +  - ]:          8 :                 xNumRules = pListStyle->GetNumRules();
     479         [ +  + ]:          8 :                 if( !xNumRules.is() )
     480                 :            :                 {
     481         [ +  - ]:          4 :                     pListStyle->CreateAndInsertAuto();
     482         [ +  - ]:          4 :                     xNumRules = pListStyle->GetNumRules();
     483                 :            :                 }
     484                 :            :             }
     485                 :         15 :         }
     486                 :            :     }
     487                 :            : 
     488         [ +  - ]:         50 :     sal_Bool bSetDefaults(io_pSetDefaults ? *io_pSetDefaults : sal_False);
     489         [ -  + ]:         50 :     if ( !xNumRules.is() )
     490                 :            :     {
     491                 :            :         // If no style name has been specified for this style and for any
     492                 :            :         // parent or if no num rule with the specified name exists,
     493                 :            :         // create a new one.
     494                 :            : 
     495                 :            :         xNumRules =
     496 [ #  # ][ #  # ]:          0 :             SvxXMLListStyleContext::CreateNumRule( i_rImport.GetModel() );
     497                 :            :         DBG_ASSERT( xNumRules.is(), "got no numbering rule" );
     498         [ #  # ]:          0 :         if ( !xNumRules.is() )
     499                 :          0 :             return xNumRules;
     500                 :            : 
     501                 :            :         // Because it is a new num rule, numbering must not be restarted.
     502         [ #  # ]:          0 :         if (o_pRestartNumbering) *o_pRestartNumbering = sal_False;
     503                 :          0 :         bSetDefaults = sal_True;
     504         [ #  # ]:          0 :         if (io_pSetDefaults) *io_pSetDefaults = bSetDefaults;
     505                 :            :     }
     506                 :            : 
     507         [ +  - ]:         50 :     ClampLevel(xNumRules, io_rLevel);
     508                 :            : 
     509         [ -  + ]:         50 :     if ( bSetDefaults )
     510                 :            :     {
     511                 :            :         // Because there is no list style sheet for this style, a default
     512                 :            :         // format must be set for any level of this num rule.
     513                 :            :         SvxXMLListStyleContext::SetDefaultStyle( xNumRules, io_rLevel,
     514         [ #  # ]:          0 :             sal_False );
     515                 :            :     }
     516                 :            : 
     517                 :         50 :     return xNumRules;
     518                 :            : }
     519                 :            : 
     520                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10