LCOV - code coverage report
Current view: top level - sw/source/core/fields - fldlst.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 69 1.4 %
Date: 2015-06-13 12:38:46 Functions: 2 10 20.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             : #include <calbck.hxx>
      21             : #include "editsh.hxx"
      22             : #include "doc.hxx"
      23             : #include <IDocumentFieldsAccess.hxx>
      24             : #include <docary.hxx>
      25             : #include <fmtfld.hxx>
      26             : #include <txtfld.hxx>
      27             : #include "edimp.hxx"
      28             : #include "expfld.hxx"
      29             : #include "pam.hxx"
      30             : #include "docfld.hxx"
      31             : #include "ndtxt.hxx"
      32             : 
      33             : // sort input values
      34             : 
      35           0 : SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
      36           0 :     : pSh(pShell)
      37             : {
      38             :     // create sorted list of all  input fields
      39           0 :     pSrtLst = new _SetGetExpFields();
      40             : 
      41           0 :     const SwFieldTypes& rFieldTypes = *pSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
      42           0 :     const size_t nSize = rFieldTypes.size();
      43             : 
      44             :     // iterate over all types
      45           0 :     for(size_t i=0; i < nSize; ++i)
      46             :     {
      47           0 :         SwFieldType* pFieldType = rFieldTypes[ i ];
      48           0 :         const sal_uInt16 nType = pFieldType->Which();
      49             : 
      50           0 :         if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType || RES_DROPDOWN == nType )
      51             :         {
      52           0 :             SwIterator<SwFormatField,SwFieldType> aIter( *pFieldType );
      53           0 :             for( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
      54             :             {
      55           0 :                 const SwTextField* pTextField = pFormatField->GetTextField();
      56             : 
      57             :                 // only process InputFields, interactive SetExpFields and DropDown fields
      58           0 :                 if( !pTextField || ( RES_SETEXPFLD == nType &&
      59           0 :                     !static_cast<SwSetExpField*>(pFormatField->GetField())->GetInputFlag()))
      60           0 :                     continue;
      61             : 
      62           0 :                 const SwTextNode& rTextNode = pTextField->GetTextNode();
      63           0 :                 if( rTextNode.GetNodes().IsDocNodes() )
      64             :                 {
      65           0 :                     if( bBuildTmpLst )
      66             :                     {
      67           0 :                         aTmpLst.insert( pTextField );
      68             :                     }
      69             :                     else
      70             :                     {
      71           0 :                         SwNodeIndex aIdx( rTextNode );
      72           0 :                         _SetGetExpField* pNew = new _SetGetExpField(aIdx, pTextField );
      73           0 :                         pSrtLst->insert( pNew );
      74             :                     }
      75             :                 }
      76           0 :             }
      77             :         }
      78             :     }
      79           0 : }
      80             : 
      81           0 : SwInputFieldList::~SwInputFieldList()
      82             : {
      83           0 :     delete pSrtLst;
      84           0 : }
      85             : 
      86           0 : size_t SwInputFieldList::Count() const
      87             : {
      88           0 :     return pSrtLst->size();
      89             : }
      90             : 
      91             : // get field from list in sorted order
      92           0 : SwField* SwInputFieldList::GetField(size_t nId)
      93             : {
      94           0 :     const SwTextField* pTextField = (*pSrtLst)[ nId ]->GetTextField();
      95             :     OSL_ENSURE( pTextField, "no TextField" );
      96           0 :     return const_cast<SwField*>(pTextField->GetFormatField().GetField());
      97             : }
      98             : 
      99             : /// save cursor
     100           0 : void SwInputFieldList::PushCrsr()
     101             : {
     102           0 :     pSh->Push();
     103           0 :     pSh->ClearMark();
     104           0 : }
     105             : 
     106             : /// get cursor
     107           0 : void SwInputFieldList::PopCrsr()
     108             : {
     109           0 :     pSh->Pop(false);
     110           0 : }
     111             : 
     112             : /// go to position of a field
     113           0 : void SwInputFieldList::GotoFieldPos(size_t nId)
     114             : {
     115           0 :     pSh->StartAllAction();
     116           0 :     (*pSrtLst)[ nId ]->GetPosOfContent( *pSh->GetCrsr()->GetPoint() );
     117           0 :     pSh->EndAllAction();
     118           0 : }
     119             : 
     120             : /** Compare TmpLst with current fields.
     121             :  *
     122             :  * All new ones are added to SortList so that they can be updated.
     123             :  * For text blocks: update only input fields.
     124             :  *
     125             :  * @return true if not empty
     126             :  */
     127           0 : bool SwInputFieldList::BuildSortLst()
     128             : {
     129           0 :     const SwFieldTypes& rFieldTypes = *pSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
     130           0 :     const size_t nSize = rFieldTypes.size();
     131             : 
     132             :     // iterate over all types
     133           0 :     for( size_t i = 0; i < nSize; ++i )
     134             :     {
     135           0 :         SwFieldType* pFieldType = rFieldTypes[ i ];
     136           0 :         const sal_uInt16 nType = pFieldType->Which();
     137             : 
     138           0 :         if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType )
     139             :         {
     140           0 :             SwIterator<SwFormatField,SwFieldType> aIter( *pFieldType );
     141           0 :             for( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
     142             :             {
     143           0 :                 const SwTextField* pTextField = pFormatField->GetTextField();
     144             : 
     145             :                 //  process only InputFields and interactive SetExpFields
     146           0 :                 if( !pTextField || ( RES_SETEXPFLD == nType &&
     147           0 :                     !static_cast<SwSetExpField*>(pFormatField->GetField())->GetInputFlag()))
     148           0 :                     continue;
     149             : 
     150           0 :                 const SwTextNode& rTextNode = pTextField->GetTextNode();
     151           0 :                 if( rTextNode.GetNodes().IsDocNodes() )
     152             :                 {
     153             :                     // not in TempList, thus add to SortList
     154           0 :                     std::set<const SwTextField*>::iterator it = aTmpLst.find( pTextField );
     155           0 :                     if( aTmpLst.end() == it )
     156             :                     {
     157           0 :                         SwNodeIndex aIdx( rTextNode );
     158           0 :                         _SetGetExpField* pNew = new _SetGetExpField(aIdx, pTextField );
     159           0 :                         pSrtLst->insert( pNew );
     160             :                     }
     161             :                     else
     162           0 :                         aTmpLst.erase( it );
     163             :                 }
     164           0 :             }
     165             :         }
     166             :     }
     167             : 
     168             :     // the pointers are not needed anymore
     169           0 :     aTmpLst.clear();
     170           0 :     return !pSrtLst->empty();
     171         177 : }
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11