LCOV - code coverage report
Current view: top level - sw/source/uibase/config - uinums.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 137 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 21 9.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 <uinums.hxx>
      21             : 
      22             : #include <hintids.hxx>
      23             : #include <svl/urihelper.hxx>
      24             : #include <unotools/pathoptions.hxx>
      25             : #include <tools/stream.hxx>
      26             : #include <sfx2/docfile.hxx>
      27             : #include <svl/itemiter.hxx>
      28             : 
      29             : #include <tools/resid.hxx>
      30             : #include <swtypes.hxx>
      31             : #include <wrtsh.hxx>
      32             : #include <poolfmt.hxx>
      33             : #include <charfmt.hxx>
      34             : 
      35             : #include <unomid.h>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : #define CHAPTER_FILENAME "chapter.cfg"
      40             : 
      41             : /*
      42             :  Description:   Saving a rule
      43             :  Parameter:     rCopy -- the rule to save
      44             :                     nIdx -- position, where the rule is to be saved.
      45             :                         An old rule at that position will be overwritten.
      46             : */
      47             : 
      48           0 : SwChapterNumRules::SwChapterNumRules()
      49             : {
      50           0 :     Init();
      51           0 : }
      52             : 
      53           0 : void SwChapterNumRules::Save()
      54             : {
      55           0 :     INetURLObject aURL;
      56           0 :     SvtPathOptions aPathOpt;
      57           0 :     aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
      58           0 :     aURL.setFinalSlash();
      59           0 :     aURL.Append(CHAPTER_FILENAME);
      60             : 
      61           0 :     SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), StreamMode::WRITE );
      62           0 :     SvStream* pStream = aMedium.GetOutStream();
      63           0 :     bool bRet = (pStream && pStream->GetError() == 0);
      64           0 :     if (bRet)
      65             :     {
      66           0 :         sw::ExportStoredChapterNumberingRules(*this, *pStream,CHAPTER_FILENAME);
      67             : 
      68           0 :         pStream->Flush();
      69             : 
      70           0 :         aMedium.Commit();
      71           0 :     }
      72           0 : }
      73             : 
      74           0 : SwChapterNumRules::~SwChapterNumRules()
      75             : {
      76           0 :     for( sal_uInt16 i = 0; i < nMaxRules; ++i )
      77           0 :         delete pNumRules[i];
      78           0 : }
      79             : 
      80           0 : void  SwChapterNumRules::Init()
      81             : {
      82           0 :     for(sal_uInt16 i = 0; i < nMaxRules; ++i )
      83           0 :         pNumRules[i] = 0;
      84             : 
      85           0 :     OUString sNm(CHAPTER_FILENAME);
      86           0 :     SvtPathOptions aOpt;
      87           0 :     if( aOpt.SearchFile( sNm, SvtPathOptions::PATH_USERCONFIG ))
      88             :     {
      89           0 :         SfxMedium aStrm( sNm, STREAM_STD_READ );
      90           0 :         sw::ImportStoredChapterNumberingRules(*this, *aStrm.GetInStream(),
      91           0 :                 CHAPTER_FILENAME);
      92           0 :     }
      93           0 : }
      94             : 
      95           0 : void SwChapterNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex)
      96             : {
      97             :     assert(nIndex < nMaxRules);
      98             :     assert(!pNumRules[nIndex]);
      99           0 :     pNumRules[nIndex] = new SwNumRulesWithName;
     100           0 : }
     101             : 
     102           0 : void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx)
     103             : {
     104             :     assert(nIdx < nMaxRules);
     105           0 :     if( !pNumRules[nIdx] )
     106           0 :         pNumRules[nIdx] = new SwNumRulesWithName( rCopy );
     107             :     else
     108           0 :         *pNumRules[nIdx] = rCopy;
     109           0 :     Save(); // store it immediately
     110           0 : }
     111             : 
     112           0 : SwNumRulesWithName::SwNumRulesWithName( const SwNumRule &rCopy,
     113             :                                         const OUString &rName )
     114           0 :     : maName(rName)
     115             : {
     116           0 :     for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
     117             :     {
     118           0 :         const SwNumFormat* pFormat = rCopy.GetNumFormat( n );
     119           0 :         if( pFormat )
     120           0 :             aFormats[ n ] = new _SwNumFormatGlobal( *pFormat );
     121             :         else
     122           0 :             aFormats[ n ] = 0;
     123             :     }
     124           0 : }
     125             : 
     126           0 : SwNumRulesWithName::SwNumRulesWithName()
     127             : {
     128           0 :     memset(aFormats, 0, sizeof(aFormats));
     129           0 : }
     130             : 
     131           0 : SwNumRulesWithName::SwNumRulesWithName( const SwNumRulesWithName& rCopy )
     132             : {
     133           0 :     memset( aFormats, 0, sizeof( aFormats ));
     134           0 :     *this = rCopy;
     135           0 : }
     136             : 
     137           0 : SwNumRulesWithName::~SwNumRulesWithName()
     138             : {
     139           0 :     for( int n = 0; n < MAXLEVEL; ++n )
     140           0 :         delete aFormats[ n ];
     141           0 : }
     142             : 
     143           0 : const SwNumRulesWithName& SwNumRulesWithName::operator=(const SwNumRulesWithName &rCopy)
     144             : {
     145           0 :     if( this != &rCopy )
     146             :     {
     147           0 :         maName = rCopy.maName;
     148           0 :         for( int n = 0; n < MAXLEVEL; ++n )
     149             :         {
     150           0 :             delete aFormats[ n ];
     151             : 
     152           0 :             _SwNumFormatGlobal* pFormat = rCopy.aFormats[ n ];
     153           0 :             if( pFormat )
     154           0 :                 aFormats[ n ] = new _SwNumFormatGlobal( *pFormat );
     155             :             else
     156           0 :                 aFormats[ n ] = 0;
     157             :         }
     158             :     }
     159           0 :     return *this;
     160             : }
     161             : 
     162           0 : void SwNumRulesWithName::MakeNumRule( SwWrtShell& rSh, SwNumRule& rChg ) const
     163             : {
     164             :     // #i89178#
     165           0 :     rChg = SwNumRule( maName, numfunc::GetDefaultPositionAndSpaceMode() );
     166           0 :     rChg.SetAutoRule( false );
     167           0 :     for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
     168             :     {
     169           0 :         _SwNumFormatGlobal* pFormat = aFormats[ n ];
     170           0 :         if( 0 != pFormat)
     171             :         {
     172           0 :             SwNumFormat aNew;
     173           0 :             pFormat->ChgNumFormat( rSh, aNew );
     174           0 :             rChg.Set( n, aNew );
     175             :         }
     176             :     }
     177           0 : }
     178             : 
     179           0 : void SwNumRulesWithName::GetNumFormat(
     180             :     size_t const nIndex, SwNumFormat const*& rpNumFormat, OUString const*& rpName) const
     181             : {
     182           0 :     rpNumFormat = (aFormats[nIndex]) ? &aFormats[nIndex]->aFormat : 0;
     183           0 :     rpName = (aFormats[nIndex]) ? &aFormats[nIndex]->sCharFormatName : 0;
     184           0 : }
     185             : 
     186           0 : void SwNumRulesWithName::SetNumFormat(
     187             :         size_t const nIndex, SwNumFormat const& rNumFormat, OUString const& rName)
     188             : {
     189           0 :     delete aFormats[nIndex];
     190           0 :     aFormats[nIndex] = new _SwNumFormatGlobal(rNumFormat);
     191           0 :     aFormats[nIndex]->sCharFormatName = rName;
     192           0 :     aFormats[nIndex]->nCharPoolId = USHRT_MAX;
     193           0 :     aFormats[nIndex]->aItems.clear();
     194           0 : }
     195             : 
     196           0 : SwNumRulesWithName::_SwNumFormatGlobal::_SwNumFormatGlobal( const SwNumFormat& rFormat )
     197           0 :     : aFormat( rFormat ), nCharPoolId( USHRT_MAX )
     198             : {
     199             :     // relative gaps?????
     200             : 
     201           0 :     SwCharFormat* pFormat = rFormat.GetCharFormat();
     202           0 :     if( pFormat )
     203             :     {
     204           0 :         sCharFormatName = pFormat->GetName();
     205           0 :         nCharPoolId = pFormat->GetPoolFormatId();
     206           0 :         if( pFormat->GetAttrSet().Count() )
     207             :         {
     208           0 :             SfxItemIter aIter( pFormat->GetAttrSet() );
     209           0 :             const SfxPoolItem *pCurr = aIter.GetCurItem();
     210             :             while( true )
     211             :             {
     212           0 :                 aItems.push_back( pCurr->Clone() );
     213           0 :                 if( aIter.IsAtEnd() )
     214           0 :                     break;
     215           0 :                 pCurr = aIter.NextItem();
     216           0 :             }
     217             :         }
     218             : 
     219           0 :         aFormat.SetCharFormat( 0 );
     220             :     }
     221           0 : }
     222             : 
     223           0 : SwNumRulesWithName::_SwNumFormatGlobal::_SwNumFormatGlobal( const _SwNumFormatGlobal& rFormat )
     224             :     :
     225             :     aFormat( rFormat.aFormat ),
     226             :     sCharFormatName( rFormat.sCharFormatName ),
     227           0 :     nCharPoolId( rFormat.nCharPoolId )
     228             : {
     229           0 :     for( sal_uInt16 n = rFormat.aItems.size(); n; )
     230           0 :         aItems.push_back( rFormat.aItems[ --n ].Clone() );
     231           0 : }
     232             : 
     233           0 : SwNumRulesWithName::_SwNumFormatGlobal::~_SwNumFormatGlobal()
     234             : {
     235           0 : }
     236             : 
     237           0 : void SwNumRulesWithName::_SwNumFormatGlobal::ChgNumFormat( SwWrtShell& rSh,
     238             :                             SwNumFormat& rNew ) const
     239             : {
     240           0 :     SwCharFormat* pFormat = 0;
     241           0 :     if( !sCharFormatName.isEmpty() )
     242             :     {
     243             :         // at first, look for the name
     244           0 :         sal_uInt16 nArrLen = rSh.GetCharFormatCount();
     245           0 :         for( sal_uInt16 i = 1; i < nArrLen; ++i )
     246             :         {
     247           0 :             pFormat = &rSh.GetCharFormat( i );
     248           0 :             if (pFormat->GetName()==sCharFormatName)
     249             :                 // exists, so leave attributes as they are!
     250           0 :                 break;
     251           0 :             pFormat = 0;
     252             :         }
     253             : 
     254           0 :         if( !pFormat )
     255             :         {
     256           0 :             if( IsPoolUserFormat( nCharPoolId ) )
     257             :             {
     258           0 :                 pFormat = rSh.MakeCharFormat( sCharFormatName );
     259           0 :                 pFormat->SetAuto( false );
     260             :             }
     261             :             else
     262           0 :                 pFormat = rSh.GetCharFormatFromPool( nCharPoolId );
     263             : 
     264           0 :             if( !pFormat->HasWriterListeners() )       // set attributes
     265           0 :                 for( sal_uInt16 n = aItems.size(); n; )
     266           0 :                     pFormat->SetFormatAttr( aItems[ --n ] );
     267             :         }
     268             :     }
     269           0 :     const_cast<SwNumFormat&>(aFormat).SetCharFormat( pFormat );
     270           0 :     rNew = aFormat;
     271           0 :     if( pFormat )
     272           0 :         const_cast<SwNumFormat&>(aFormat).SetCharFormat( 0 );
     273         177 : }
     274             : 
     275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11