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

Generated by: LCOV version 1.10