LCOV - code coverage report
Current view: top level - sw/source/core/doc - docchart.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 81 33.3 %
Date: 2014-11-03 Functions: 5 8 62.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 <float.h>
      21             : #include <hintids.hxx>
      22             : #include <vcl/window.hxx>
      23             : #include <doc.hxx>
      24             : #include <IDocumentChartDataProviderAccess.hxx>
      25             : #include <IDocumentState.hxx>
      26             : #include <IDocumentLayoutAccess.hxx>
      27             : #include <docary.hxx>
      28             : #include <ndindex.hxx>
      29             : #include <swtable.hxx>
      30             : #include <ndtxt.hxx>
      31             : #include <calc.hxx>
      32             : #include <cellfml.hxx>
      33             : #include <viewsh.hxx>
      34             : #include <ndole.hxx>
      35             : #include <calbck.hxx>
      36             : #include <cntfrm.hxx>
      37             : #include <swtblfmt.hxx>
      38             : #include <tblsel.hxx>
      39             : #include <cellatr.hxx>
      40             : #include <osl/mutex.hxx>
      41             : 
      42             : #include <unochart.hxx>
      43             : 
      44           0 : void SwTable::UpdateCharts() const
      45             : {
      46           0 :     GetFrmFmt()->GetDoc()->UpdateCharts( GetFrmFmt()->GetName() );
      47           0 : }
      48             : 
      49           0 : bool SwTable::IsTblComplexForChart( const OUString& rSelection ) const
      50             : {
      51             :     const SwTableBox* pSttBox, *pEndBox;
      52           0 :     if( 2 < rSelection.getLength() )
      53             :     {
      54             :         // Remove brackets at the beginning and from the end
      55           0 :         OUString sBox( rSelection );
      56           0 :         if( '<' == sBox[0] ) sBox = sBox.copy( 0, 1 );
      57           0 :         if( '>' == sBox[ sBox.getLength()-1  ] ) sBox = sBox.copy( 0, sBox.getLength()-1 );
      58             : 
      59           0 :         sal_Int32 nSeparator = sBox.indexOf( ':' );
      60             :         OSL_ENSURE( -1 != nSeparator, "no valid selection" );
      61             : 
      62           0 :         pSttBox = GetTblBox( sBox.copy( 0, nSeparator ));
      63           0 :         pEndBox = GetTblBox( sBox.copy( nSeparator+1 ));
      64             :     }
      65             :     else
      66             :     {
      67           0 :         const SwTableLines* pLns = &GetTabLines();
      68           0 :         pSttBox = (*pLns)[ 0 ]->GetTabBoxes().front();
      69           0 :         while( !pSttBox->GetSttNd() )
      70             :             // Until the Content Box!
      71           0 :             pSttBox = pSttBox->GetTabLines().front()->GetTabBoxes().front();
      72             : 
      73           0 :         const SwTableBoxes* pBoxes = &pLns->back()->GetTabBoxes();
      74           0 :         pEndBox = pBoxes->back();
      75           0 :         while( !pEndBox->GetSttNd() )
      76             :         {
      77             :             // Until the Content Box!
      78           0 :             pLns = &pEndBox->GetTabLines();
      79           0 :             pBoxes = &pLns->back()->GetTabBoxes();
      80           0 :             pEndBox = pBoxes->back();
      81             :         }
      82             :     }
      83             : 
      84           0 :     return !pSttBox || !pEndBox || !::ChkChartSel( *pSttBox->GetSttNd(),
      85           0 :                                         *pEndBox->GetSttNd() );
      86             : }
      87             : 
      88           0 : void SwDoc::DoUpdateAllCharts()
      89             : {
      90           0 :     SwViewShell* pVSh = getIDocumentLayoutAccess().GetCurrentViewShell();
      91           0 :     if( pVSh )
      92             :     {
      93           0 :         const SwFrmFmts& rTblFmts = *GetTblFrmFmts();
      94           0 :         for( sal_uInt16 n = 0; n < rTblFmts.size(); ++n )
      95             :         {
      96             :             SwTable* pTmpTbl;
      97             :             const SwTableNode* pTblNd;
      98           0 :             SwFrmFmt* pFmt = rTblFmts[ n ];
      99             : 
     100           0 :             if( 0 != ( pTmpTbl = SwTable::FindTable( pFmt ) ) &&
     101           0 :                 0 != ( pTblNd = pTmpTbl->GetTableNode() ) &&
     102           0 :                 pTblNd->GetNodes().IsDocNodes() )
     103             :             {
     104           0 :                 _UpdateCharts( *pTmpTbl, *pVSh );
     105             :             }
     106             :         }
     107             :     }
     108           0 : }
     109             : 
     110          20 : void SwDoc::_UpdateCharts( const SwTable& rTbl, SwViewShell const & rVSh ) const
     111             : {
     112          20 :     OUString aName( rTbl.GetFrmFmt()->GetName() );
     113             :     SwOLENode *pONd;
     114             :     SwStartNode *pStNd;
     115          40 :     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
     116          40 :     while( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
     117             :     {
     118           0 :         ++aIdx;
     119           0 :         if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
     120           0 :             aName == pONd->GetChartTblName() &&
     121           0 :             pONd->getLayoutFrm( rVSh.GetLayout() ) )
     122             :         {
     123           0 :             SwChartDataProvider *pPCD = getIDocumentChartDataProviderAccess().GetChartDataProvider();
     124           0 :             if (pPCD)
     125           0 :                 pPCD->InvalidateTable( &rTbl );
     126             :             // following this the framework will now take care of repainting
     127             :             // the chart or it's replacement image...
     128             :         }
     129           0 :         aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
     130          20 :     }
     131          20 : }
     132             : 
     133          24 : void SwDoc::UpdateCharts( const OUString &rName ) const
     134             : {
     135          24 :     SwTable* pTmpTbl = SwTable::FindTable( FindTblFmtByName( rName ) );
     136          24 :     if( pTmpTbl )
     137             :     {
     138          24 :         SwViewShell const * pVSh = getIDocumentLayoutAccess().GetCurrentViewShell();
     139             : 
     140          24 :         if( pVSh )
     141          20 :             _UpdateCharts( *pTmpTbl, *pVSh );
     142             :     }
     143          24 : }
     144             : 
     145           4 : void SwDoc::SetTableName( SwFrmFmt& rTblFmt, const OUString &rNewName )
     146             : {
     147           4 :     const OUString aOldName( rTblFmt.GetName() );
     148             : 
     149           4 :     bool bNameFound = rNewName.isEmpty();
     150           4 :     if( !bNameFound )
     151             :     {
     152             :         SwFrmFmt* pFmt;
     153           4 :         const SwFrmFmts& rTbl = *GetTblFrmFmts();
     154          12 :         for( sal_uInt16 i = rTbl.size(); i; )
     155          24 :             if( !( pFmt = rTbl[ --i ] )->IsDefault() &&
     156          24 :                 pFmt->GetName() == rNewName && IsUsed( *pFmt ) )
     157             :             {
     158           0 :                 bNameFound = true;
     159           0 :                 break;
     160             :             }
     161             :     }
     162             : 
     163           4 :     if( !bNameFound )
     164           4 :         rTblFmt.SetName( rNewName, true );
     165             :     else
     166           0 :         rTblFmt.SetName( GetUniqueTblName(), true );
     167             : 
     168             :     SwStartNode *pStNd;
     169           8 :     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
     170           8 :     while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
     171             :     {
     172           0 :         ++aIdx;
     173           0 :         SwOLENode *pNd = aIdx.GetNode().GetOLENode();
     174           0 :         if( pNd && aOldName == pNd->GetChartTblName() )
     175             :         {
     176           0 :             pNd->SetChartTblName( rNewName );
     177             : 
     178           0 :             SwTable* pTable = SwTable::FindTable( &rTblFmt );
     179           0 :             SwChartDataProvider *pPCD = getIDocumentChartDataProviderAccess().GetChartDataProvider();
     180           0 :             if (pPCD)
     181           0 :                 pPCD->InvalidateTable( pTable );
     182             :             // following this the framework will now take care of repainting
     183             :             // the chart or it's replacement image...
     184             :         }
     185           0 :         aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
     186             :     }
     187           8 :     getIDocumentState().SetModified();
     188         274 : }
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10