LCOV - code coverage report
Current view: top level - sw/source/core/fields - chpfld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 112 2.7 %
Date: 2012-08-25 Functions: 1 9 11.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 104 0.0 %

           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                 :            : #include <com/sun/star/text/ChapterFormat.hpp>
      30                 :            : #include <doc.hxx>
      31                 :            : #include <frame.hxx>        // SwChapterFieldType::ChangeExpansion()
      32                 :            : #include <pam.hxx>          // fuer GetBodyTxtNode
      33                 :            : #include <ndtxt.hxx>
      34                 :            : #include <chpfld.hxx>
      35                 :            : #include <expfld.hxx>       // fuer GetBodyTxtNode
      36                 :            : #include <unofldmid.h>
      37                 :            : #include <numrule.hxx>
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : 
      41                 :            : /*--------------------------------------------------------------------
      42                 :            :     Beschreibung: SwChapterFieldType
      43                 :            :  --------------------------------------------------------------------*/
      44                 :            : 
      45                 :            : 
      46                 :       1549 : SwChapterFieldType::SwChapterFieldType()
      47                 :       1549 :     : SwFieldType( RES_CHAPTERFLD )
      48                 :            : {
      49                 :       1549 : }
      50                 :            : 
      51                 :            : 
      52                 :          0 : SwFieldType* SwChapterFieldType::Copy() const
      53                 :            : {
      54         [ #  # ]:          0 :     return new SwChapterFieldType();
      55                 :            : }
      56                 :            : 
      57                 :            : 
      58                 :            : /*--------------------------------------------------------------------
      59                 :            :     Beschreibung: Kapittelfeld
      60                 :            :  --------------------------------------------------------------------*/
      61                 :            : 
      62                 :            : 
      63                 :          0 : SwChapterField::SwChapterField(SwChapterFieldType* pTyp, sal_uInt32 nFmt)
      64 [ #  # ][ #  # ]:          0 :     : SwField(pTyp, nFmt), nLevel( 0 )
         [ #  # ][ #  # ]
      65                 :          0 : {}
      66                 :            : 
      67                 :            : 
      68                 :          0 : String SwChapterField::Expand() const
      69                 :            : {
      70                 :          0 :     String sStr( sNumber );
      71   [ #  #  #  # ]:          0 :     switch( GetFormat() )
      72                 :            :     {
      73         [ #  # ]:          0 :         case CF_TITLE:      sStr = sTitle;  break;
      74                 :            : 
      75                 :            :         case CF_NUMBER:
      76         [ #  # ]:          0 :         case CF_NUM_TITLE:  sStr.Insert( sPre, 0 );
      77         [ #  # ]:          0 :                             sStr += sPost;
      78         [ #  # ]:          0 :                             if( CF_NUM_TITLE == GetFormat() )
      79         [ #  # ]:          0 :                                 sStr += sTitle;
      80                 :          0 :                             break;
      81                 :            : 
      82         [ #  # ]:          0 :         case CF_NUM_NOPREPST_TITLE: sStr += sTitle; break;
      83                 :            :     }
      84                 :          0 :     return sStr;
      85                 :            : }
      86                 :            : 
      87                 :            : 
      88                 :          0 : SwField* SwChapterField::Copy() const
      89                 :            : {
      90                 :            :     SwChapterField *pTmp =
      91         [ #  # ]:          0 :         new SwChapterField((SwChapterFieldType*)GetTyp(), GetFormat());
      92                 :          0 :     pTmp->nLevel = nLevel;
      93                 :          0 :     pTmp->sTitle = sTitle;
      94                 :          0 :     pTmp->sNumber = sNumber;
      95                 :          0 :     pTmp->sPost = sPost;
      96                 :          0 :     pTmp->sPre = sPre;
      97                 :            : 
      98                 :          0 :     return pTmp;
      99                 :            : }
     100                 :            : 
     101                 :            : // #i53420#
     102                 :          0 : void SwChapterField::ChangeExpansion(const SwFrm* pFrm,
     103                 :            :                                       const SwCntntNode* pCntntNode,
     104                 :            :                                       sal_Bool bSrchNum )
     105                 :            : {
     106                 :            :     OSL_ENSURE( pFrm, "in welchem Frame stehe ich denn?" );
     107                 :          0 :     SwDoc* pDoc = (SwDoc*)pCntntNode->GetDoc();
     108                 :            : 
     109         [ #  # ]:          0 :     const SwTxtNode* pTxtNode = dynamic_cast<const SwTxtNode*>(pCntntNode);
     110 [ #  # ][ #  # ]:          0 :     if ( !pTxtNode || !pFrm->IsInDocBody() )
                 [ #  # ]
     111                 :            :     {
     112 [ #  # ][ #  # ]:          0 :         SwPosition aDummyPos( pDoc->GetNodes().GetEndOfContent() );
     113 [ #  # ][ #  # ]:          0 :         pTxtNode = GetBodyTxtNode( *pDoc, aDummyPos, *pFrm );
     114                 :            :     }
     115                 :            : 
     116         [ #  # ]:          0 :     if ( pTxtNode )
     117                 :            :     {
     118                 :          0 :         ChangeExpansion( *pTxtNode, bSrchNum );
     119                 :            :     }
     120                 :          0 : }
     121                 :            : 
     122                 :          0 : void SwChapterField::ChangeExpansion(const SwTxtNode &rTxtNd, sal_Bool bSrchNum)
     123                 :            : {
     124                 :          0 :     SwDoc* pDoc = (SwDoc*)rTxtNd.GetDoc();
     125                 :          0 :     const SwTxtNode *pTxtNd = rTxtNd.FindOutlineNodeOfLevel( nLevel );
     126         [ #  # ]:          0 :     if( pTxtNd )
     127                 :            :     {
     128         [ #  # ]:          0 :         if( bSrchNum )
     129                 :            :         {
     130                 :          0 :             const SwTxtNode* pONd = pTxtNd;
     131                 :          0 :             do {
     132 [ #  # ][ #  # ]:          0 :                 if( pONd && pONd->GetTxtColl() )
                 [ #  # ]
     133                 :            :                 {
     134                 :          0 :                     sal_uInt8 nPrevLvl = nLevel;
     135                 :            : 
     136                 :            :                     OSL_ENSURE( pONd->GetAttrOutlineLevel() >= 0 && pONd->GetAttrOutlineLevel() <= MAXLEVEL,
     137                 :            :                             "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect -> please inform OD." );
     138                 :          0 :                     nLevel = static_cast<sal_uInt8>(pONd->GetAttrOutlineLevel());
     139                 :            : 
     140         [ #  # ]:          0 :                     if( nPrevLvl < nLevel )
     141                 :          0 :                         nLevel = nPrevLvl;
     142         [ #  # ]:          0 :                     else if( SVX_NUM_NUMBER_NONE != pDoc->GetOutlineNumRule()
     143                 :          0 :                             ->Get( nLevel ).GetNumberingType() )
     144                 :            :                     {
     145                 :          0 :                         pTxtNd = pONd;
     146                 :          0 :                         break;
     147                 :            :                     }
     148                 :            : 
     149         [ #  # ]:          0 :                     if( !nLevel-- )
     150                 :          0 :                         break;
     151                 :          0 :                     pONd = pTxtNd->FindOutlineNodeOfLevel( nLevel );
     152                 :            :                 }
     153                 :            :                 else
     154                 :          0 :                     break;
     155                 :            :             } while( sal_True );
     156                 :            :         }
     157                 :            : 
     158                 :            :         // nur die Nummer besorgen, ohne Pre-/Post-fixstrings
     159                 :            : 
     160         [ #  # ]:          0 :         if ( pTxtNd->IsOutline() )
     161                 :            :         {
     162                 :            :             // correction of refactoring done by cws swnumtree:
     163                 :            :             // retrieve numbering string without prefix and suffix strings
     164                 :            :             // as stated in the above german comment.
     165         [ #  # ]:          0 :             sNumber = pTxtNd->GetNumString( false );
     166                 :            : 
     167                 :          0 :             SwNumRule* pRule( pTxtNd->GetNumRule() );
     168 [ #  # ][ #  # ]:          0 :             if ( pTxtNd->IsCountedInList() && pRule )
                 [ #  # ]
     169                 :            :             {
     170                 :          0 :                 const SwNumFmt& rNFmt = pRule->Get( static_cast<sal_uInt16>(pTxtNd->GetActualListLevel()) );
     171                 :          0 :                 sPost = rNFmt.GetSuffix();
     172                 :          0 :                 sPre = rNFmt.GetPrefix();
     173                 :            :             }
     174                 :            :             else
     175                 :          0 :                 sPost = aEmptyStr, sPre = aEmptyStr;
     176                 :            :         }
     177                 :            :         else
     178                 :            :         {
     179                 :          0 :             sPost = aEmptyStr;
     180                 :          0 :             sPre = aEmptyStr;
     181         [ #  # ]:          0 :             sNumber = String("??", RTL_TEXTENCODING_ASCII_US);
     182                 :            :         }
     183                 :            : 
     184         [ #  # ]:          0 :         sTitle = pTxtNd->GetExpandTxt();
     185                 :            : 
     186         [ #  # ]:          0 :         for( xub_StrLen i = 0; i < sTitle.Len(); ++i )
     187         [ #  # ]:          0 :             if( ' ' > sTitle.GetChar( i ) )
     188                 :          0 :                 sTitle.Erase( i--, 1 );
     189                 :            :     }
     190                 :            :     else
     191                 :            :     {
     192                 :          0 :         sNumber = aEmptyStr;
     193                 :          0 :         sTitle = aEmptyStr;
     194                 :          0 :         sPost = aEmptyStr;
     195                 :          0 :         sPre = aEmptyStr;
     196                 :            :     }
     197                 :          0 : }
     198                 :            : 
     199                 :          0 : bool SwChapterField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     200                 :            : {
     201      [ #  #  # ]:          0 :     switch( nWhichId )
     202                 :            :     {
     203                 :            :     case FIELD_PROP_BYTE1:
     204         [ #  # ]:          0 :         rAny <<= (sal_Int8)nLevel;
     205                 :          0 :         break;
     206                 :            : 
     207                 :            :     case FIELD_PROP_USHORT1:
     208                 :            :         {
     209                 :            :             sal_Int16 nRet;
     210   [ #  #  #  #  :          0 :             switch( GetFormat() )
                      # ]
     211                 :            :             {
     212                 :          0 :                 case CF_NUMBER: nRet = text::ChapterFormat::NUMBER; break;
     213                 :          0 :                 case CF_TITLE:  nRet = text::ChapterFormat::NAME; break;
     214                 :            :                 case CF_NUMBER_NOPREPST:
     215                 :          0 :                     nRet = text::ChapterFormat::DIGIT;
     216                 :          0 :                 break;
     217                 :            :                 case CF_NUM_NOPREPST_TITLE:
     218                 :          0 :                     nRet = text::ChapterFormat::NO_PREFIX_SUFFIX;
     219                 :          0 :                 break;
     220                 :            :                 case CF_NUM_TITLE:
     221                 :          0 :                 default:        nRet = text::ChapterFormat::NAME_NUMBER;
     222                 :            :             }
     223         [ #  # ]:          0 :             rAny <<= nRet;
     224                 :            :         }
     225                 :          0 :         break;
     226                 :            : 
     227                 :            :     default:
     228                 :            :         OSL_FAIL("illegal property");
     229                 :            :     }
     230                 :          0 :     return true;
     231                 :            : }
     232                 :            : 
     233                 :          0 : bool SwChapterField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     234                 :            : {
     235                 :          0 :     sal_Bool bRet = sal_True;
     236      [ #  #  # ]:          0 :     switch( nWhichId )
     237                 :            :     {
     238                 :            :     case FIELD_PROP_BYTE1:
     239                 :            :     {
     240                 :          0 :         sal_Int8 nTmp = 0;
     241                 :          0 :         rAny >>= nTmp;
     242 [ #  # ][ #  # ]:          0 :         if(nTmp >= 0 && nTmp < MAXLEVEL)
     243                 :          0 :             nLevel = nTmp;
     244                 :            :         else
     245                 :          0 :             bRet = false;
     246                 :            :         break;
     247                 :            :     }
     248                 :            : 
     249                 :            :     case FIELD_PROP_USHORT1:
     250                 :            :         {
     251                 :          0 :             sal_Int16 nVal = 0;
     252                 :          0 :             rAny >>= nVal;
     253   [ #  #  #  #  :          0 :             switch( nVal )
                      # ]
     254                 :            :             {
     255                 :          0 :                 case text::ChapterFormat::NAME: SetFormat(CF_TITLE); break;
     256                 :          0 :                 case text::ChapterFormat::NUMBER:  SetFormat(CF_NUMBER); break;
     257                 :            :                 case text::ChapterFormat::NO_PREFIX_SUFFIX:
     258                 :          0 :                             SetFormat(CF_NUM_NOPREPST_TITLE);
     259                 :          0 :                 break;
     260                 :            :                 case text::ChapterFormat::DIGIT:
     261                 :          0 :                         SetFormat(CF_NUMBER_NOPREPST);
     262                 :          0 :                 break;
     263                 :            : 
     264                 :          0 :                 default:        SetFormat(CF_NUM_TITLE);
     265                 :            :             }
     266                 :            :         }
     267                 :          0 :         break;
     268                 :            : 
     269                 :            :     default:
     270                 :            :         OSL_FAIL("illegal property");
     271                 :          0 :                 bRet = false;
     272                 :            :     }
     273                 :          0 :     return bRet;
     274                 :            : }
     275                 :            : 
     276                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10