LCOV - code coverage report
Current view: top level - sw/source/core/fields - ddetbl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 2 83 2.4 %
Date: 2014-11-03 Functions: 3 15 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 <comphelper/string.hxx>
      21             : #include <frmfmt.hxx>
      22             : #include <doc.hxx>
      23             : #include <IDocumentSettingAccess.hxx>
      24             : #include <IDocumentFieldsAccess.hxx>
      25             : #include <IDocumentLayoutAccess.hxx>
      26             : #include <index.hxx>
      27             : #include <ndtxt.hxx>
      28             : #include <swtable.hxx>
      29             : #include <swddetbl.hxx>
      30             : #include <ddefld.hxx>
      31             : #include <ndindex.hxx>
      32             : #include <fldupde.hxx>
      33             : #include <swtblfmt.hxx>
      34             : #include <fieldhint.hxx>
      35             : 
      36         488 : TYPEINIT1( SwDDETable, SwTable );
      37             : 
      38             : /// Ctor moves all lines/boxes from a SwTable into itself.
      39             : /// Afterwards the SwTable is empty and must be deleted.
      40           0 : SwDDETable::SwDDETable( SwTable& rTable, SwDDEFieldType* pDDEType, bool bUpdate )
      41           0 :     : SwTable( rTable ), aDepend( this, pDDEType )
      42             : {
      43             :     // copy the table data
      44           0 :     m_TabSortContentBoxes.insert(rTable.GetTabSortBoxes());
      45           0 :     rTable.GetTabSortBoxes().clear();
      46             : 
      47           0 :     aLines.insert( aLines.begin(),
      48           0 :                    rTable.GetTabLines().begin(), rTable.GetTabLines().end() ); // move lines
      49           0 :     rTable.GetTabLines().clear();
      50             : 
      51           0 :     if( !aLines.empty() )
      52             :     {
      53           0 :         const SwNode& rNd = *GetTabSortBoxes()[0]->GetSttNd();
      54           0 :         if( rNd.GetNodes().IsDocNodes() )
      55             :         {
      56           0 :             pDDEType->IncRefCnt();
      57             : 
      58             :             // update box content only if update flag is set (false in import)
      59           0 :             if (bUpdate)
      60           0 :                 ChangeContent();
      61             :         }
      62             :     }
      63           0 : }
      64             : 
      65           0 : SwDDETable::~SwDDETable()
      66             : {
      67           0 :     SwDDEFieldType* pFldTyp = (SwDDEFieldType*)aDepend.GetRegisteredIn();
      68           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
      69           0 :     if( !pDoc->IsInDtor() && !aLines.empty() &&
      70           0 :         GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
      71           0 :         pFldTyp->DecRefCnt();
      72             : 
      73             :     // If it is the last dependent of the "deleted field" than delete it finally
      74           0 :     if( pFldTyp->IsDeleted() && pFldTyp->IsLastDepend() )
      75             :     {
      76           0 :         pFldTyp->Remove( &aDepend );
      77           0 :         delete pFldTyp;
      78             :     }
      79           0 : }
      80             : 
      81           0 : void SwDDETable::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
      82             : {
      83           0 :     if( pNew && RES_UPDATEDDETBL == pNew->Which() )
      84           0 :         ChangeContent();
      85             :     else
      86           0 :         SwTable::Modify( pOld, pNew );
      87           0 : }
      88             : 
      89           0 : void SwDDETable::SwClientNotify( const SwModify&, const SfxHint& rHint )
      90             : {
      91           0 :     const SwFieldHint* pHint = dynamic_cast<const SwFieldHint*>( &rHint );
      92           0 :     if ( pHint )
      93             :         // replace DDETable by real table
      94           0 :         NoDDETable();
      95           0 : }
      96             : 
      97           0 : void SwDDETable::ChangeContent()
      98             : {
      99             :     OSL_ENSURE( GetFrmFmt(), "No FrameFormat" );
     100             : 
     101             :     // Is this the correct NodesArray? (because of UNDO)
     102           0 :     if( aLines.empty() )
     103           0 :         return;
     104             :     OSL_ENSURE( !GetTabSortBoxes().empty(), "Table without content?" );
     105           0 :     if( !GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
     106           0 :         return;
     107             : 
     108             :     // access to DDEFldType
     109           0 :     SwDDEFieldType* pDDEType = (SwDDEFieldType*)aDepend.GetRegisteredIn();
     110             : 
     111           0 :     OUString aExpand = comphelper::string::remove(pDDEType->GetExpansion(), '\r');
     112             : 
     113           0 :     for( sal_uInt16 n = 0; n < aLines.size(); ++n )
     114             :     {
     115           0 :         OUString aLine = aExpand.getToken( n, '\n' );
     116           0 :         SwTableLine* pLine = aLines[ n ];
     117           0 :         for( sal_uInt16 i = 0; i < pLine->GetTabBoxes().size(); ++i )
     118             :         {
     119           0 :             SwTableBox* pBox = pLine->GetTabBoxes()[ i ];
     120             :             OSL_ENSURE( pBox->GetSttIdx(), "no content box" );
     121           0 :             SwNodeIndex aNdIdx( *pBox->GetSttNd(), 1 );
     122           0 :             SwTxtNode* pTxtNode = aNdIdx.GetNode().GetTxtNode();
     123             :             OSL_ENSURE( pTxtNode, "No Node" );
     124           0 :             SwIndex aCntIdx( pTxtNode, 0 );
     125           0 :             pTxtNode->EraseText( aCntIdx );
     126           0 :             pTxtNode->InsertText( aLine.getToken( i, '\t' ), aCntIdx );
     127             : 
     128           0 :             SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)pBox->GetFrmFmt();
     129           0 :             pBoxFmt->LockModify();
     130           0 :             pBoxFmt->ResetFmtAttr( RES_BOXATR_VALUE );
     131           0 :             pBoxFmt->UnlockModify();
     132           0 :         }
     133           0 :     }
     134             : 
     135           0 :     const IDocumentSettingAccess* pIDSA = GetFrmFmt()->getIDocumentSettingAccess();
     136           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
     137           0 :     if( AUTOUPD_FIELD_AND_CHARTS == pIDSA->getFieldUpdateFlags(true) )
     138           0 :         pDoc->getIDocumentFieldsAccess().SetFieldsDirty( true, NULL, 0 );
     139             : }
     140             : 
     141           0 : SwDDEFieldType* SwDDETable::GetDDEFldType()
     142             : {
     143           0 :     return (SwDDEFieldType*)aDepend.GetRegisteredIn();
     144             : }
     145             : 
     146           0 : bool SwDDETable::NoDDETable()
     147             : {
     148             :     // search table node
     149             :     OSL_ENSURE( GetFrmFmt(), "No FrameFormat" );
     150           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
     151             : 
     152             :     // Is this the correct NodesArray? (because of UNDO)
     153           0 :     if( aLines.empty() )
     154           0 :         return false;
     155             :     OSL_ENSURE( !GetTabSortBoxes().empty(), "Table without content?" );
     156           0 :     SwNode* pNd = (SwNode*)GetTabSortBoxes()[0]->GetSttNd();
     157           0 :     if( !pNd->GetNodes().IsDocNodes() )
     158           0 :         return false;
     159             : 
     160           0 :     SwTableNode* pTblNd = pNd->FindTableNode();
     161             :     OSL_ENSURE( pTblNd, "Where is the table?");
     162             : 
     163           0 :     SwTable* pNewTbl = new SwTable( *this );
     164             : 
     165             :     // copy the table data
     166           0 :     pNewTbl->GetTabSortBoxes().insert( GetTabSortBoxes() ); // move content boxes
     167           0 :     GetTabSortBoxes().clear();
     168             : 
     169           0 :     pNewTbl->GetTabLines().insert( pNewTbl->GetTabLines().begin(),
     170           0 :                                    GetTabLines().begin(), GetTabLines().end() ); // move lines
     171           0 :     GetTabLines().clear();
     172             : 
     173           0 :     if( pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() )
     174           0 :         ((SwDDEFieldType*)aDepend.GetRegisteredIn())->DecRefCnt();
     175             : 
     176           0 :     pTblNd->SetNewTable( pNewTbl );       // replace table
     177             : 
     178           0 :     return true;
     179         270 : }
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10