LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/fields - ddetbl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 79 1.3 %
Date: 2012-12-27 Functions: 1 13 7.7 %
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             : 
      21             : #include <comphelper/string.hxx>
      22             : #include <frmfmt.hxx>
      23             : #include <doc.hxx>
      24             : #include <index.hxx>
      25             : #include <ndtxt.hxx>
      26             : #include <swtable.hxx>
      27             : #include <swddetbl.hxx>
      28             : #include <ddefld.hxx>           // fuer den FieldType
      29             : #include <ndindex.hxx>
      30             : #include <fldupde.hxx>
      31             : #include <swtblfmt.hxx>
      32             : #include <fieldhint.hxx>
      33             : 
      34           2 : TYPEINIT1( SwDDETable, SwTable );
      35             : 
      36             :     // Constructor movet alle Lines/Boxen aus der SwTable zu sich.
      37             :     // Die SwTable ist danach Leer und muss geloescht werden.
      38           0 : SwDDETable::SwDDETable( SwTable& rTable, SwDDEFieldType* pDDEType,
      39             :                         sal_Bool bUpdate )
      40           0 :     : SwTable( rTable ), aDepend( this, pDDEType )
      41             : {
      42             :     // Kopiere/move die Daten der Tabelle
      43           0 :     m_TabSortContentBoxes.insert(rTable.GetTabSortBoxes());
      44           0 :     rTable.GetTabSortBoxes().clear();
      45             : 
      46             :     aLines.insert( aLines.begin(),
      47           0 :                    rTable.GetTabLines().begin(), rTable.GetTabLines().end() ); // move die Lines
      48           0 :     rTable.GetTabLines().clear();
      49             : 
      50           0 :     if( !aLines.empty() )
      51             :     {
      52           0 :         const SwNode& rNd = *GetTabSortBoxes()[0]->GetSttNd();
      53           0 :         if( rNd.GetNodes().IsDocNodes() )
      54             :         {
      55             :             // mba: swclient refactoring - this code shouldn't have done anything!
      56             :             // the ModifyLock Flag is evaluated in SwModify only, though it was accessible via SwClient
      57             :             // This has been fixed now
      58             : //          aDepend.LockModify();
      59           0 :             pDDEType->IncRefCnt();
      60             : //          aDepend.UnlockModify();
      61             : 
      62             :             // Setzen der Werte in die einzelnen Boxen
      63             :             // update box content only if update flag is set (false in import)
      64           0 :             if (bUpdate)
      65           0 :                 ChangeContent();
      66             :         }
      67             :     }
      68           0 : }
      69             : 
      70           0 : SwDDETable::~SwDDETable()
      71             : {
      72           0 :     SwDDEFieldType* pFldTyp = (SwDDEFieldType*)aDepend.GetRegisteredIn();
      73           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
      74           0 :     if( !pDoc->IsInDtor() && !aLines.empty() &&
      75           0 :         GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
      76           0 :         pFldTyp->DecRefCnt();
      77             : 
      78             :     // sind wir der letzte Abhaengige vom "geloeschten Feld" dann loesche dieses
      79           0 :     if( pFldTyp->IsDeleted() && pFldTyp->IsLastDepend() )
      80             :     {
      81           0 :         pFldTyp->Remove( &aDepend );
      82           0 :         delete pFldTyp;
      83             :     }
      84           0 : }
      85             : 
      86           0 : void SwDDETable::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
      87             : {
      88           0 :     if( pNew && RES_UPDATEDDETBL == pNew->Which() )
      89           0 :         ChangeContent();
      90             :     else
      91           0 :         SwTable::Modify( pOld, pNew );
      92           0 : }
      93             : 
      94           0 : void SwDDETable::SwClientNotify( const SwModify&, const SfxHint& rHint )
      95             : {
      96           0 :     const SwFieldHint* pHint = dynamic_cast<const SwFieldHint*>( &rHint );
      97           0 :     if ( pHint )
      98             :         // replace DDETable by real table
      99           0 :         NoDDETable();
     100           0 : }
     101             : 
     102           0 : void SwDDETable::ChangeContent()
     103             : {
     104             :     OSL_ENSURE( GetFrmFmt(), "Kein FrameFormat" );
     105             : 
     106             :     // Stehen wir im richtigen NodesArray (Wegen UNDO)
     107           0 :     if( aLines.empty() )
     108             :         return;
     109             :     OSL_ENSURE( !GetTabSortBoxes().empty(), "Tabelle ohne Inhalt?" );
     110           0 :     if( !GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
     111             :         return;
     112             : 
     113             :     // zugriff auf den DDEFldType
     114           0 :     SwDDEFieldType* pDDEType = (SwDDEFieldType*)aDepend.GetRegisteredIn();
     115             : 
     116           0 :     String aExpand = comphelper::string::remove(pDDEType->GetExpansion(), '\r');
     117             : 
     118           0 :     for( sal_uInt16 n = 0; n < aLines.size(); ++n )
     119             :     {
     120           0 :         String aLine = aExpand.GetToken( n, '\n' );
     121           0 :         SwTableLine* pLine = aLines[ n ];
     122           0 :         for( sal_uInt16 i = 0; i < pLine->GetTabBoxes().size(); ++i )
     123             :         {
     124           0 :             SwTableBox* pBox = pLine->GetTabBoxes()[ i ];
     125             :             OSL_ENSURE( pBox->GetSttIdx(), "keine InhaltsBox" );
     126           0 :             SwNodeIndex aNdIdx( *pBox->GetSttNd(), 1 );
     127           0 :             SwTxtNode* pTxtNode = aNdIdx.GetNode().GetTxtNode();
     128             :             OSL_ENSURE( pTxtNode, "Kein Node" );
     129           0 :             SwIndex aCntIdx( pTxtNode, 0 );
     130           0 :             pTxtNode->EraseText( aCntIdx );
     131           0 :             pTxtNode->InsertText( aLine.GetToken( i, '\t' ), aCntIdx );
     132             : 
     133           0 :             SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)pBox->GetFrmFmt();
     134           0 :             pBoxFmt->LockModify();
     135           0 :             pBoxFmt->ResetFmtAttr( RES_BOXATR_VALUE );
     136           0 :             pBoxFmt->UnlockModify();
     137           0 :         }
     138           0 :     }
     139             : 
     140           0 :     const IDocumentSettingAccess* pIDSA = GetFrmFmt()->getIDocumentSettingAccess();
     141           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
     142           0 :     if( AUTOUPD_FIELD_AND_CHARTS == pIDSA->getFieldUpdateFlags(true) )
     143           0 :         pDoc->SetFieldsDirty( true, NULL, 0 );
     144             : }
     145             : 
     146           0 : SwDDEFieldType* SwDDETable::GetDDEFldType()
     147             : {
     148           0 :     return (SwDDEFieldType*)aDepend.GetRegisteredIn();
     149             : }
     150             : 
     151           0 : sal_Bool SwDDETable::NoDDETable()
     152             : {
     153             :     // suche den TabellenNode
     154             :     OSL_ENSURE( GetFrmFmt(), "Kein FrameFormat" );
     155           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
     156             : 
     157             :     // Stehen wir im richtigen NodesArray (Wegen UNDO)
     158           0 :     if( aLines.empty() )
     159           0 :         return sal_False;
     160             :     OSL_ENSURE( !GetTabSortBoxes().empty(), "Tabelle ohne Inhalt?" );
     161           0 :     SwNode* pNd = (SwNode*)GetTabSortBoxes()[0]->GetSttNd();
     162           0 :     if( !pNd->GetNodes().IsDocNodes() )
     163           0 :         return sal_False;
     164             : 
     165           0 :     SwTableNode* pTblNd = pNd->FindTableNode();
     166             :     OSL_ENSURE( pTblNd, "wo steht denn die Tabelle ?");
     167             : 
     168           0 :     SwTable* pNewTbl = new SwTable( *this );
     169             : 
     170             :     // Kopiere/move die Daten der Tabelle
     171           0 :     pNewTbl->GetTabSortBoxes().insert( GetTabSortBoxes() ); // move die Inh. Boxen
     172           0 :     GetTabSortBoxes().clear();
     173             : 
     174           0 :     pNewTbl->GetTabLines().insert( pNewTbl->GetTabLines().begin(),
     175           0 :                                    GetTabLines().begin(), GetTabLines().end() ); // move die Lines
     176           0 :     GetTabLines().clear();
     177             : 
     178           0 :     if( pDoc->GetCurrentViewShell() )   //swmod 071108//swmod 071225
     179           0 :         ((SwDDEFieldType*)aDepend.GetRegisteredIn())->DecRefCnt();
     180             : 
     181           0 :     pTblNd->SetNewTable( pNewTbl );       // setze die Tabelle
     182             : 
     183           0 :     return sal_True;
     184             : }
     185             : 
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10