LCOV - code coverage report
Current view: top level - sw/source/core/doc - docchart.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 110 0.0 %
Date: 2014-04-14 Functions: 0 9 0.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 <com/sun/star/frame/XModel.hpp>
      21             : 
      22             : #include <com/sun/star/chart2/XChartDocument.hpp>
      23             : 
      24             : #include <float.h>
      25             : #include <hintids.hxx>
      26             : #include <vcl/window.hxx>
      27             : #include <doc.hxx>
      28             : #include <docary.hxx>
      29             : #include <ndindex.hxx>
      30             : #include <swtable.hxx>
      31             : #include <ndtxt.hxx>
      32             : #include <calc.hxx>
      33             : #include <frmfmt.hxx>
      34             : #include <cellfml.hxx>
      35             : #include <viewsh.hxx>
      36             : #include <ndole.hxx>
      37             : #include <calbck.hxx>
      38             : #include <cntfrm.hxx>
      39             : #include <swtblfmt.hxx>
      40             : #include <tblsel.hxx>
      41             : #include <cellatr.hxx>
      42             : #include <osl/mutex.hxx>
      43             : #include <vcl/svapp.hxx>
      44             : 
      45             : #include <unochart.hxx>
      46             : 
      47             : using namespace com::sun::star;
      48             : using namespace com::sun::star::uno;
      49             : 
      50           0 : void SwTable::UpdateCharts() const
      51             : {
      52           0 :     GetFrmFmt()->GetDoc()->UpdateCharts( GetFrmFmt()->GetName() );
      53           0 : }
      54             : 
      55           0 : bool SwTable::IsTblComplexForChart( const OUString& rSelection ) const
      56             : {
      57             :     const SwTableBox* pSttBox, *pEndBox;
      58           0 :     if( 2 < rSelection.getLength() )
      59             :     {
      60             :         // Remove brackets at the beginning and from the end
      61           0 :         OUString sBox( rSelection );
      62           0 :         if( '<' == sBox[0] ) sBox = sBox.copy( 0, 1 );
      63           0 :         if( '>' == sBox[ sBox.getLength()-1  ] ) sBox = sBox.copy( 0, sBox.getLength()-1 );
      64             : 
      65           0 :         sal_Int32 nSeparator = sBox.indexOf( ':' );
      66             :         OSL_ENSURE( -1 != nSeparator, "no valid selection" );
      67             : 
      68           0 :         pSttBox = GetTblBox( sBox.copy( 0, nSeparator ));
      69           0 :         pEndBox = GetTblBox( sBox.copy( nSeparator+1 ));
      70             :     }
      71             :     else
      72             :     {
      73           0 :         const SwTableLines* pLns = &GetTabLines();
      74           0 :         pSttBox = (*pLns)[ 0 ]->GetTabBoxes().front();
      75           0 :         while( !pSttBox->GetSttNd() )
      76             :             // Until the Content Box!
      77           0 :             pSttBox = pSttBox->GetTabLines().front()->GetTabBoxes().front();
      78             : 
      79           0 :         const SwTableBoxes* pBoxes = &pLns->back()->GetTabBoxes();
      80           0 :         pEndBox = pBoxes->back();
      81           0 :         while( !pEndBox->GetSttNd() )
      82             :         {
      83             :             // Until the Content Box!
      84           0 :             pLns = &pEndBox->GetTabLines();
      85           0 :             pBoxes = &pLns->back()->GetTabBoxes();
      86           0 :             pEndBox = pBoxes->back();
      87             :         }
      88             :     }
      89             : 
      90           0 :     return !pSttBox || !pEndBox || !::ChkChartSel( *pSttBox->GetSttNd(),
      91           0 :                                         *pEndBox->GetSttNd() );
      92             : }
      93             : 
      94           0 : void SwDoc::DoUpdateAllCharts()
      95             : {
      96             :     SwViewShell* pVSh;
      97           0 :     GetEditShell( &pVSh );
      98           0 :     if( pVSh )
      99             :     {
     100           0 :         const SwFrmFmts& rTblFmts = *GetTblFrmFmts();
     101           0 :         for( sal_uInt16 n = 0; n < rTblFmts.size(); ++n )
     102             :         {
     103             :             SwTable* pTmpTbl;
     104             :             const SwTableNode* pTblNd;
     105           0 :             SwFrmFmt* pFmt = rTblFmts[ n ];
     106             : 
     107           0 :             if( 0 != ( pTmpTbl = SwTable::FindTable( pFmt ) ) &&
     108           0 :                 0 != ( pTblNd = pTmpTbl->GetTableNode() ) &&
     109           0 :                 pTblNd->GetNodes().IsDocNodes() )
     110             :             {
     111           0 :                 _UpdateCharts( *pTmpTbl, *pVSh );
     112             :             }
     113             :         }
     114             :     }
     115           0 : }
     116             : 
     117           0 : void SwDoc::_UpdateCharts( const SwTable& rTbl, SwViewShell& rVSh ) const
     118             : {
     119           0 :     OUString aName( rTbl.GetFrmFmt()->GetName() );
     120             :     SwOLENode *pONd;
     121             :     SwStartNode *pStNd;
     122           0 :     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
     123           0 :     while( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
     124             :     {
     125           0 :         ++aIdx;
     126           0 :         if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
     127           0 :             aName == pONd->GetChartTblName() &&
     128           0 :             pONd->getLayoutFrm( rVSh.GetLayout() ) )
     129             :         {
     130           0 :             SwChartDataProvider *pPCD = GetChartDataProvider();
     131           0 :             if (pPCD)
     132           0 :                 pPCD->InvalidateTable( &rTbl );
     133             :             // following this the framework will now take care of repainting
     134             :             // the chart or it's replacement image...
     135             :         }
     136           0 :         aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
     137           0 :     }
     138           0 : }
     139             : 
     140           0 : void SwDoc::UpdateCharts( const OUString &rName ) const
     141             : {
     142           0 :     SwTable* pTmpTbl = SwTable::FindTable( FindTblFmtByName( rName ) );
     143           0 :     if( pTmpTbl )
     144             :     {
     145             :         SwViewShell* pVSh;
     146           0 :         GetEditShell( &pVSh );
     147             : 
     148           0 :         if( pVSh )
     149           0 :             _UpdateCharts( *pTmpTbl, *pVSh );
     150             :     }
     151           0 : }
     152             : 
     153           0 : void SwDoc::SetTableName( SwFrmFmt& rTblFmt, const OUString &rNewName )
     154             : {
     155           0 :     const OUString aOldName( rTblFmt.GetName() );
     156             : 
     157           0 :     bool bNameFound = rNewName.isEmpty();
     158           0 :     if( !bNameFound )
     159             :     {
     160             :         SwFrmFmt* pFmt;
     161           0 :         const SwFrmFmts& rTbl = *GetTblFrmFmts();
     162           0 :         for( sal_uInt16 i = rTbl.size(); i; )
     163           0 :             if( !( pFmt = rTbl[ --i ] )->IsDefault() &&
     164           0 :                 pFmt->GetName() == rNewName && IsUsed( *pFmt ) )
     165             :             {
     166           0 :                 bNameFound = true;
     167           0 :                 break;
     168             :             }
     169             :     }
     170             : 
     171           0 :     if( !bNameFound )
     172           0 :         rTblFmt.SetName( rNewName, sal_True );
     173             :     else
     174           0 :         rTblFmt.SetName( GetUniqueTblName(), sal_True );
     175             : 
     176             :     SwStartNode *pStNd;
     177           0 :     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
     178           0 :     while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
     179             :     {
     180           0 :         ++aIdx;
     181           0 :         SwOLENode *pNd = aIdx.GetNode().GetOLENode();
     182           0 :         if( pNd && aOldName == pNd->GetChartTblName() )
     183             :         {
     184           0 :             pNd->SetChartTblName( rNewName );
     185             : 
     186             :             SwViewShell* pVSh;
     187           0 :             GetEditShell( &pVSh );
     188             : 
     189           0 :             SwTable* pTable = SwTable::FindTable( &rTblFmt );
     190           0 :             SwChartDataProvider *pPCD = GetChartDataProvider();
     191           0 :             if (pPCD)
     192           0 :                 pPCD->InvalidateTable( pTable );
     193             :             // following this the framework will now take care of repainting
     194             :             // the chart or it's replacement image...
     195             :         }
     196           0 :         aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
     197             :     }
     198           0 :     SetModified();
     199           0 : }
     200             : 
     201           0 : SwChartDataProvider * SwDoc::GetChartDataProvider( bool bCreate ) const
     202             : {
     203             :     // since there must be only one instance of this object per document
     204             :     // we need a mutex here
     205           0 :     SolarMutexGuard aGuard;
     206             : 
     207           0 :     if (bCreate && !maChartDataProviderImplRef.get())
     208             :     {
     209           0 :         maChartDataProviderImplRef = comphelper::ImplementationReference< SwChartDataProvider
     210           0 :             , chart2::data::XDataProvider >( new SwChartDataProvider( this ) );
     211             :     }
     212           0 :     return maChartDataProviderImplRef.get();
     213             : }
     214             : 
     215           0 : void SwDoc::CreateChartInternalDataProviders( const SwTable *pTable )
     216             : {
     217           0 :     if (pTable)
     218             :     {
     219           0 :         OUString aName( pTable->GetFrmFmt()->GetName() );
     220             :         SwOLENode *pONd;
     221             :         SwStartNode *pStNd;
     222           0 :         SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
     223           0 :         while (0 != (pStNd = aIdx.GetNode().GetStartNode()))
     224             :         {
     225           0 :             ++aIdx;
     226           0 :             if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
     227           0 :                 aName == pONd->GetChartTblName() /* OLE node is chart? */ &&
     228           0 :                 0 != (pONd->getLayoutFrm( GetCurrentLayout() )) /* chart frame is not hidden */ )
     229             :             {
     230           0 :                 uno::Reference < embed::XEmbeddedObject > xIP = pONd->GetOLEObj().GetOleRef();
     231           0 :                 if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
     232             :                 {
     233           0 :                     uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
     234           0 :                     if (xChart.is())
     235           0 :                         xChart->createInternalDataProvider( sal_True );
     236             : 
     237             :                     // there may be more than one chart for each table thus we need to continue the loop...
     238           0 :                 }
     239             :             }
     240           0 :             aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
     241           0 :         }
     242             :     }
     243           0 : }
     244             : 
     245           0 : SwChartLockController_Helper & SwDoc::GetChartControllerHelper()
     246             : {
     247           0 :     if (!mpChartControllerHelper)
     248             :     {
     249           0 :         mpChartControllerHelper = new SwChartLockController_Helper( this );
     250             :     }
     251           0 :     return *mpChartControllerHelper;
     252             : }
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10