LCOV - code coverage report
Current view: top level - sw/source/core/doc - docchart.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 14 81 17.3 %
Date: 2015-06-13 12:38:46 Functions: 4 8 50.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 <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 :     GetFrameFormat()->GetDoc()->UpdateCharts( GetFrameFormat()->GetName() );
      47           0 : }
      48             : 
      49           0 : bool SwTable::IsTableComplexForChart( const OUString& rSelection ) const
      50             : {
      51             :     const SwTableBox* pSttBox, *pEndBox;
      52           0 :     if( 2 < rSelection.getLength() )
      53             :     {
      54           0 :         const sal_Int32 nSeparator {rSelection.indexOf( ':' )};
      55             :         OSL_ENSURE( -1 != nSeparator, "no valid selection" );
      56             : 
      57             :         // Remove brackets at the beginning and from the end
      58           0 :         const sal_Int32 nOffset {'<' == rSelection[0] ? 1 : 0};
      59           0 :         const sal_Int32 nLength {'>' == rSelection[ rSelection.getLength()-1 ]
      60           0 :             ? rSelection.getLength()-1 : rSelection.getLength()};
      61             : 
      62           0 :         pSttBox = GetTableBox(rSelection.copy( nOffset, nSeparator - nOffset ));
      63           0 :         pEndBox = GetTableBox(rSelection.copy( nSeparator+1, nLength - (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 SwFrameFormats& rTableFormats = *GetTableFrameFormats();
      94           0 :         for( size_t n = 0; n < rTableFormats.size(); ++n )
      95             :         {
      96             :             SwTable* pTmpTable;
      97             :             const SwTableNode* pTableNd;
      98           0 :             const SwFrameFormat* pFormat = rTableFormats[ n ];
      99             : 
     100           0 :             if( 0 != ( pTmpTable = SwTable::FindTable( pFormat ) ) &&
     101           0 :                 0 != ( pTableNd = pTmpTable->GetTableNode() ) &&
     102           0 :                 pTableNd->GetNodes().IsDocNodes() )
     103             :             {
     104           0 :                 _UpdateCharts( *pTmpTable, *pVSh );
     105             :             }
     106             :         }
     107             :     }
     108           0 : }
     109             : 
     110          10 : void SwDoc::_UpdateCharts( const SwTable& rTable, SwViewShell const & rVSh ) const
     111             : {
     112          10 :     OUString aName( rTable.GetFrameFormat()->GetName() );
     113             :     SwStartNode *pStNd;
     114          20 :     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
     115          20 :     while( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
     116             :     {
     117           0 :         ++aIdx;
     118             :         SwOLENode *pONd;
     119           0 :         if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
     120           0 :             aName == pONd->GetChartTableName() &&
     121           0 :             pONd->getLayoutFrm( rVSh.GetLayout() ) )
     122             :         {
     123           0 :             SwChartDataProvider *pPCD = getIDocumentChartDataProviderAccess().GetChartDataProvider();
     124           0 :             if (pPCD)
     125           0 :                 pPCD->InvalidateTable( &rTable );
     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          10 :     }
     131          10 : }
     132             : 
     133          12 : void SwDoc::UpdateCharts( const OUString &rName ) const
     134             : {
     135          12 :     SwTable* pTmpTable = SwTable::FindTable( FindTableFormatByName( rName ) );
     136          12 :     if( pTmpTable )
     137             :     {
     138          12 :         SwViewShell const * pVSh = getIDocumentLayoutAccess().GetCurrentViewShell();
     139             : 
     140          12 :         if( pVSh )
     141          10 :             _UpdateCharts( *pTmpTable, *pVSh );
     142             :     }
     143          12 : }
     144             : 
     145           0 : void SwDoc::SetTableName( SwFrameFormat& rTableFormat, const OUString &rNewName )
     146             : {
     147           0 :     const OUString aOldName( rTableFormat.GetName() );
     148             : 
     149           0 :     bool bNameFound = rNewName.isEmpty();
     150           0 :     if( !bNameFound )
     151             :     {
     152           0 :         const SwFrameFormats& rTable = *GetTableFrameFormats();
     153           0 :         for( size_t i = rTable.size(); i; )
     154             :         {
     155             :             const SwFrameFormat* pFormat;
     156           0 :             if( !( pFormat = rTable[ --i ] )->IsDefault() &&
     157           0 :                 pFormat->GetName() == rNewName && IsUsed( *pFormat ) )
     158             :             {
     159           0 :                 bNameFound = true;
     160           0 :                 break;
     161             :             }
     162             :         }
     163             :     }
     164             : 
     165           0 :     if( !bNameFound )
     166           0 :         rTableFormat.SetName( rNewName, true );
     167             :     else
     168           0 :         rTableFormat.SetName( GetUniqueTableName(), true );
     169             : 
     170             :     SwStartNode *pStNd;
     171           0 :     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
     172           0 :     while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
     173             :     {
     174           0 :         ++aIdx;
     175           0 :         SwOLENode *pNd = aIdx.GetNode().GetOLENode();
     176           0 :         if( pNd && aOldName == pNd->GetChartTableName() )
     177             :         {
     178           0 :             pNd->SetChartTableName( rNewName );
     179             : 
     180           0 :             SwTable* pTable = SwTable::FindTable( &rTableFormat );
     181           0 :             SwChartDataProvider *pPCD = getIDocumentChartDataProviderAccess().GetChartDataProvider();
     182           0 :             if (pPCD)
     183           0 :                 pPCD->InvalidateTable( pTable );
     184             :             // following this the framework will now take care of repainting
     185             :             // the chart or it's replacement image...
     186             :         }
     187           0 :         aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
     188             :     }
     189           0 :     getIDocumentState().SetModified();
     190         177 : }
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11