LCOV - code coverage report
Current view: top level - chart2/source/view/main - DrawModelWrapper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 109 180 60.6 %
Date: 2014-04-11 Functions: 14 28 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 "chartview/DrawModelWrapper.hxx"
      21             : #include "macros.hxx"
      22             : #include "AbstractShapeFactory.hxx"
      23             : #include "ChartItemPool.hxx"
      24             : #include "ObjectIdentifier.hxx"
      25             : #include <svx/unomodel.hxx>
      26             : #include <svl/itempool.hxx>
      27             : // header for class SfxBoolItem
      28             : #include <svl/eitem.hxx>
      29             : // header for define EE_PARA_HYPHENATE
      30             : #include <editeng/eeitem.hxx>
      31             : // header for class Svx3DPercentDiagonalItem
      32             : #include <svx/svx3ditems.hxx>
      33             : // header for class SvtPathOptions
      34             : #include <unotools/pathoptions.hxx>
      35             : // header E3dObjFactory
      36             : #include <svx/objfac3d.hxx>
      37             : // header for class SdrObjList
      38             : #include <svx/svdpage.hxx>
      39             : // header for SvxUnoXDashTable_createInstance
      40             : #include <svx/XPropertyTable.hxx>
      41             : // header for class XDashList
      42             : #include <svx/xtable.hxx>
      43             : // header for class SdrOutliner
      44             : #include <svx/svdoutl.hxx>
      45             : // header for class LinguMgr
      46             : #include <editeng/unolingu.hxx>
      47             : // header for class Application
      48             : #include <vcl/svapp.hxx>
      49             : // header for class VirtualDevice
      50             : #include <vcl/virdev.hxx>
      51             : 
      52             : #include <com/sun/star/container/XChild.hpp>
      53             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      54             : 
      55             : #include <sfx2/objsh.hxx>
      56             : #include <com/sun/star/linguistic2/XHyphenator.hpp>
      57             : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
      58             : 
      59             : using namespace ::com::sun::star;
      60             : 
      61             : namespace
      62             : {
      63             : // this code is copied from sfx2/source/doc/objembed.cxx
      64           0 : SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
      65             : {
      66           0 :     SfxObjectShell* pResult = NULL;
      67             : 
      68             :     try
      69             :     {
      70           0 :         uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
      71           0 :         if ( xChildModel.is() )
      72             :         {
      73           0 :             uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
      74           0 :             if ( xParentTunnel.is() )
      75             :             {
      76           0 :                 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
      77             :                 pResult = reinterpret_cast< SfxObjectShell * >(
      78           0 :                     xParentTunnel->getSomething( uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
      79           0 :             }
      80           0 :         }
      81             :     }
      82           0 :     catch( const uno::Exception& )
      83             :     {
      84             :         // TODO: error handling
      85             :     }
      86             : 
      87           0 :     return pResult;
      88             : }
      89             : 
      90             : // this code is copied from sfx2/source/doc/objembed.cxx.  It is a workaround to
      91             : // get the reference device (e.g. printer) fromthe parent document
      92           0 : OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
      93             : {
      94           0 :     SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
      95           0 :     if ( pParent )
      96           0 :         return pParent->GetDocumentRefDev();
      97           0 :     return NULL;
      98             : }
      99             : 
     100             : } // anonymous namespace
     101             : 
     102             : namespace chart
     103             : {
     104             : 
     105         217 : DrawModelWrapper::DrawModelWrapper( const uno::Reference<uno::XComponentContext>& /*xContext*/ )
     106         434 :         : SdrModel( SvtPathOptions().GetPalettePath(), NULL, NULL, false, false )
     107             :         , m_pChartItemPool(0)
     108             :         , m_xMainDrawPage(0)
     109         434 :         , m_xHiddenDrawPage(0)
     110             : {
     111         217 :     m_pChartItemPool = ChartItemPool::CreateChartItemPool();
     112             : 
     113         217 :     SetScaleUnit(MAP_100TH_MM);
     114         217 :     SetScaleFraction(Fraction(1, 1));
     115         217 :     SetDefaultFontHeight(423);     // 12pt
     116             : 
     117         217 :     SfxItemPool* pMasterPool = &GetItemPool();
     118         217 :     pMasterPool->SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
     119         217 :     pMasterPool->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) );
     120         217 :     pMasterPool->SetPoolDefaultItem(Svx3DPercentDiagonalItem (5));
     121             : 
     122         217 :     SfxItemPool* pPool = pMasterPool;
     123             :     // append chart pool to end of pool chain
     124             :     for (;;)
     125             :     {
     126         434 :         SfxItemPool* pSecondary = pPool->GetSecondaryPool();
     127         434 :         if (!pSecondary)
     128         217 :             break;
     129             : 
     130         217 :         pPool = pSecondary;
     131         217 :     }
     132         217 :     pPool->SetSecondaryPool(m_pChartItemPool);
     133         217 :     pMasterPool->FreezeIdRanges();
     134             : 
     135             :     //this factory needs to be created before first use of 3D scenes once upon an office runtime
     136             :     //@todo in future this should be done by drawing engine itself on demand
     137             :     static bool b3dFactoryInitialized = false;
     138         217 :     if(!b3dFactoryInitialized)
     139             :     {
     140          14 :         E3dObjFactory aObjFactory;
     141          14 :         b3dFactoryInitialized = true;
     142             :     }
     143             : 
     144             :     //Hyphenyation and spellchecking
     145         217 :     SdrOutliner& rOutliner = GetDrawOutliner();
     146             :     try
     147             :     {
     148         217 :         uno::Reference< linguistic2::XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
     149         217 :         if( xHyphenator.is() )
     150         217 :             rOutliner.SetHyphenator( xHyphenator );
     151             : 
     152         434 :         uno::Reference< linguistic2::XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
     153         217 :         if ( xSpellChecker.is() )
     154         434 :             rOutliner.SetSpeller( xSpellChecker );
     155             :     }
     156           0 :     catch(...)
     157             :     {
     158             :         OSL_FAIL("Can't get Hyphenator or SpellChecker for chart");
     159             :     }
     160             : 
     161             :     //ref device for font rendering
     162         217 :     OutputDevice* pDefaultDevice = rOutliner.GetRefDevice();
     163         217 :     if( !pDefaultDevice )
     164           0 :         pDefaultDevice = Application::GetDefaultDevice();
     165         217 :     m_pRefDevice.reset(new VirtualDevice(*pDefaultDevice));
     166         217 :     MapMode aMapMode = m_pRefDevice->GetMapMode();
     167         217 :     aMapMode.SetMapUnit(MAP_100TH_MM);
     168         217 :     m_pRefDevice->SetMapMode(aMapMode);
     169         217 :     SetRefDevice(m_pRefDevice.get());
     170         217 :     rOutliner.SetRefDevice(m_pRefDevice.get());
     171         217 : }
     172             : 
     173         330 : DrawModelWrapper::~DrawModelWrapper()
     174             : {
     175             :     //remove m_pChartItemPool from pool chain
     176         110 :     if(m_pChartItemPool)
     177             :     {
     178         110 :         SfxItemPool* pPool = &GetItemPool();
     179             :         for (;;)
     180             :         {
     181         220 :             SfxItemPool* pSecondary = pPool->GetSecondaryPool();
     182         220 :             if(pSecondary == m_pChartItemPool)
     183             :             {
     184         110 :                 pPool->SetSecondaryPool (NULL);
     185         110 :                 break;
     186             :             }
     187         110 :             pPool = pSecondary;
     188         110 :         }
     189         110 :         SfxItemPool::Free(m_pChartItemPool);
     190             :     }
     191         220 : }
     192             : 
     193         217 : uno::Reference< uno::XInterface > DrawModelWrapper
     194             : ::createUnoModel()
     195             : {
     196         217 :     uno::Reference< lang::XComponent > xComponent = new SvxUnoDrawingModel( this ); //tell Andreas Schluens if SvxUnoDrawingModel is not needed anymore -> remove export from svx to avoid link problems in writer
     197         217 :     return uno::Reference< uno::XInterface >::query( xComponent );
     198             : }
     199             : 
     200        1548 : uno::Reference< frame::XModel > DrawModelWrapper::getUnoModel()
     201             : {
     202        1548 :     uno::Reference< uno::XInterface > xI = this->SdrModel::getUnoModel();
     203        1548 :     return uno::Reference<frame::XModel>::query( xI );
     204             : }
     205             : 
     206        3834 : SdrModel& DrawModelWrapper::getSdrModel()
     207             : {
     208        3834 :     return *this;
     209             : }
     210             : 
     211         217 : uno::Reference< lang::XMultiServiceFactory > DrawModelWrapper::getShapeFactory()
     212             : {
     213         217 :     uno::Reference< lang::XMultiServiceFactory > xShapeFactory( this->getUnoModel(), uno::UNO_QUERY );
     214         217 :     return xShapeFactory;
     215             : }
     216             : 
     217         858 : uno::Reference< drawing::XDrawPage > DrawModelWrapper::getMainDrawPage()
     218             : {
     219             :     //create draw page:
     220         858 :     if( !m_xMainDrawPage.is() )
     221             :     {
     222         217 :         uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( this->getUnoModel(), uno::UNO_QUERY );
     223         217 :         if( xDrawPagesSuplier.is() )
     224             :         {
     225         217 :             uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () );
     226         217 :             if( xDrawPages->getCount()>1 )
     227             :             {
     228           0 :                 uno::Any aPage = xDrawPages->getByIndex( 0 ) ;
     229           0 :                 aPage >>= m_xMainDrawPage;
     230             :             }
     231         217 :             if(!m_xMainDrawPage.is())
     232             :             {
     233         217 :                 m_xMainDrawPage = xDrawPages->insertNewByIndex( 0 );
     234         217 :             }
     235         217 :         }
     236             :     }
     237             :     //ensure that additional shapes are in front of the chart objects so create the chart root before
     238             :     // let us disable this call for now
     239             :     // TODO:moggi
     240             :     // AbstractShapeFactory::getOrCreateShapeFactory(this->getShapeFactory())->getOrCreateChartRootShape( m_xMainDrawPage );
     241         858 :     return m_xMainDrawPage;
     242             : }
     243           0 : uno::Reference< drawing::XDrawPage > DrawModelWrapper::getHiddenDrawPage()
     244             : {
     245           0 :     if( !m_xHiddenDrawPage.is() )
     246             :     {
     247           0 :         uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( this->getUnoModel(), uno::UNO_QUERY );
     248           0 :         if( xDrawPagesSuplier.is() )
     249             :         {
     250           0 :             uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () );
     251           0 :             if( xDrawPages->getCount()>1 )
     252             :             {
     253           0 :                 uno::Any aPage = xDrawPages->getByIndex( 1 ) ;
     254           0 :                 aPage >>= m_xHiddenDrawPage;
     255             :             }
     256             : 
     257           0 :             if(!m_xHiddenDrawPage.is())
     258             :             {
     259           0 :                 if( xDrawPages->getCount()==0 )
     260           0 :                     m_xMainDrawPage = xDrawPages->insertNewByIndex( 0 );
     261           0 :                 m_xHiddenDrawPage = xDrawPages->insertNewByIndex( 1 );
     262           0 :             }
     263           0 :         }
     264             :     }
     265           0 :     return m_xHiddenDrawPage;
     266             : }
     267         710 : void DrawModelWrapper::clearMainDrawPage()
     268             : {
     269             :     //uno::Reference<drawing::XShapes> xChartRoot( m_xMainDrawPage, uno::UNO_QUERY );
     270         710 :     uno::Reference<drawing::XShapes> xChartRoot( AbstractShapeFactory::getChartRootShape( m_xMainDrawPage ) );
     271         710 :     if( xChartRoot.is() )
     272             :     {
     273         545 :         sal_Int32 nSubCount = xChartRoot->getCount();
     274         545 :         uno::Reference< drawing::XShape > xShape;
     275        3147 :         for( sal_Int32 nS = nSubCount; nS--; )
     276             :         {
     277        2057 :             if( xChartRoot->getByIndex( nS ) >>= xShape )
     278        2057 :                 xChartRoot->remove( xShape );
     279         545 :         }
     280         710 :     }
     281         710 : }
     282             : 
     283         464 : uno::Reference< drawing::XShapes > DrawModelWrapper::getChartRootShape(
     284             :     const uno::Reference< drawing::XDrawPage>& xDrawPage )
     285             : {
     286         464 :     return AbstractShapeFactory::getChartRootShape( xDrawPage );
     287             : }
     288             : 
     289         557 : void DrawModelWrapper::lockControllers()
     290             : {
     291         557 :     uno::Reference< frame::XModel > xDrawModel( this->getUnoModel() );
     292         557 :     if( xDrawModel.is())
     293         557 :         xDrawModel->lockControllers();
     294         557 : }
     295         557 : void DrawModelWrapper::unlockControllers()
     296             : {
     297         557 :     uno::Reference< frame::XModel > xDrawModel( this->getUnoModel() );
     298         557 :     if( xDrawModel.is())
     299         557 :         xDrawModel->unlockControllers();
     300         557 : }
     301             : 
     302           0 : void DrawModelWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
     303             : {
     304           0 :     OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
     305           0 :     if( pParentRefDev )
     306             :     {
     307           0 :         SetRefDevice( pParentRefDev );
     308             :     }
     309           0 : }
     310             : 
     311           0 : OutputDevice* DrawModelWrapper::getReferenceDevice() const
     312             : {
     313           0 :     return SdrModel::GetRefDevice();
     314             : }
     315             : 
     316        1126 : SfxItemPool& DrawModelWrapper::GetItemPool()
     317             : {
     318        1126 :     return this->SdrModel::GetItemPool();
     319             : }
     320           0 : const SfxItemPool& DrawModelWrapper::GetItemPool() const
     321             : {
     322           0 :     return this->SdrModel::GetItemPool();
     323             : }
     324           0 : XColorListRef DrawModelWrapper::GetColorList() const
     325             : {
     326           0 :     return this->SdrModel::GetColorList();
     327             : }
     328           0 : XDashListRef DrawModelWrapper::GetDashList() const
     329             : {
     330           0 :     return this->SdrModel::GetDashList();
     331             : }
     332           0 : XLineEndListRef DrawModelWrapper::GetLineEndList() const
     333             : {
     334           0 :     return this->SdrModel::GetLineEndList();
     335             : }
     336           0 : XGradientListRef DrawModelWrapper::GetGradientList() const
     337             : {
     338           0 :     return this->SdrModel::GetGradientList();
     339             : }
     340           0 : XHatchListRef DrawModelWrapper::GetHatchList() const
     341             : {
     342           0 :     return this->SdrModel::GetHatchList();
     343             : }
     344           0 : XBitmapListRef DrawModelWrapper::GetBitmapList() const
     345             : {
     346           0 :     return this->SdrModel::GetBitmapList();
     347             : }
     348             : 
     349           0 : SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rName )
     350             : {
     351           0 :     if( rName.isEmpty() )
     352           0 :         return 0;
     353           0 :     return getNamedSdrObject( rName, GetPage(0) );
     354             : }
     355             : 
     356        6060 : SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rObjectCID, SdrObjList* pSearchList )
     357             : {
     358        6060 :     if(!pSearchList || rObjectCID.isEmpty())
     359        3025 :         return 0;
     360        3035 :     sal_uLong nCount = pSearchList->GetObjCount();
     361        7590 :     for( sal_uLong nN=0; nN<nCount; nN++  )
     362             :     {
     363        5830 :         SdrObject* pObj = pSearchList->GetObj(nN);
     364        5830 :         if(!pObj)
     365           0 :             continue;
     366        5830 :         if( ObjectIdentifier::areIdenticalObjects( rObjectCID, pObj->GetName() ) )
     367         457 :             return pObj;
     368        5373 :         pObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() );
     369        5373 :         if(pObj)
     370         818 :             return pObj;
     371             :     }
     372        1760 :     return 0;
     373             : }
     374             : 
     375           0 : bool DrawModelWrapper::removeShape( const uno::Reference< drawing::XShape >& xShape )
     376             : {
     377           0 :     uno::Reference< container::XChild > xChild( xShape, uno::UNO_QUERY );
     378           0 :     if( xChild.is() )
     379             :     {
     380           0 :         uno::Reference<drawing::XShapes> xShapes( xChild->getParent(), uno::UNO_QUERY );
     381           0 :         if( xShapes.is() )
     382             :         {
     383           0 :             xShapes->remove(xShape);
     384           0 :             return true;
     385           0 :         }
     386             :     }
     387           0 :     return false;
     388             : }
     389             : 
     390             : } //namespace chart
     391             : 
     392             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10