LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/model/main - ChartModel_Persistence.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 87 338 25.7 %
Date: 2012-12-27 Functions: 8 34 23.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             : 
      21             : #include "ChartModel.hxx"
      22             : #include "MediaDescriptorHelper.hxx"
      23             : #include "ChartDebugTrace.hxx"
      24             : #include "macros.hxx"
      25             : #include "ChartViewHelper.hxx"
      26             : #include "ChartModelHelper.hxx"
      27             : #include "AxisHelper.hxx"
      28             : #include "ThreeDHelper.hxx"
      29             : 
      30             : #include <com/sun/star/chart2/LegendPosition.hpp>
      31             : #include <com/sun/star/container/XNameAccess.hpp>
      32             : #include <com/sun/star/document/XExporter.hpp>
      33             : #include <com/sun/star/document/XImporter.hpp>
      34             : #include <com/sun/star/document/XFilter.hpp>
      35             : #include <com/sun/star/drawing/FillStyle.hpp>
      36             : #include <com/sun/star/drawing/LineStyle.hpp>
      37             : #include <com/sun/star/drawing/ProjectionMode.hpp>
      38             : #include <com/sun/star/embed/ElementModes.hpp>
      39             : #include <com/sun/star/embed/XStorage.hpp>
      40             : #include <com/sun/star/embed/StorageFactory.hpp>
      41             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      42             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      43             : #include <com/sun/star/uno/XComponentContext.hpp>
      44             : #include <com/sun/star/io/TempFile.hpp>
      45             : #include <com/sun/star/io/XSeekable.hpp>
      46             : 
      47             : #include <ucbhelper/content.hxx>
      48             : #include <unotools/ucbstreamhelper.hxx>
      49             : #include <vcl/cvtgrf.hxx>
      50             : #include <comphelper/processfactory.hxx>
      51             : #include <comphelper/storagehelper.hxx>
      52             : #include <vcl/svapp.hxx>
      53             : 
      54             : #include <algorithm>
      55             : #include <functional>
      56             : 
      57             : using namespace ::com::sun::star;
      58             : 
      59             : using ::com::sun::star::uno::Reference;
      60             : using ::com::sun::star::uno::Sequence;
      61             : using ::rtl::OUString;
      62             : using ::osl::MutexGuard;
      63             : 
      64             : namespace
      65             : {
      66           0 : struct lcl_PropNameEquals : public ::std::unary_function< beans::PropertyValue, bool >
      67             : {
      68           0 :     lcl_PropNameEquals( const OUString & rStrToCompareWith ) :
      69           0 :             m_aStr( rStrToCompareWith )
      70           0 :     {}
      71           0 :     bool operator() ( const beans::PropertyValue & rProp )
      72             :     {
      73           0 :         return rProp.Name.equals( m_aStr );
      74             :     }
      75             : private:
      76             :     OUString m_aStr;
      77             : };
      78             : 
      79             : template< typename T >
      80           0 : T lcl_getProperty(
      81             :     const Sequence< beans::PropertyValue > & rMediaDescriptor,
      82             :     const OUString & rPropName )
      83             : {
      84           0 :     T aResult;
      85           0 :     if( rMediaDescriptor.getLength())
      86             :     {
      87           0 :         OUString aPropName( rPropName );
      88           0 :         const beans::PropertyValue * pIt = rMediaDescriptor.getConstArray();
      89           0 :         const beans::PropertyValue * pEndIt = pIt +  + rMediaDescriptor.getLength();
      90           0 :         pIt = ::std::find_if( pIt, pEndIt, lcl_PropNameEquals( aPropName ));
      91           0 :         if( pIt != pEndIt )
      92           0 :             (*pIt).Value >>= aResult;
      93             :     }
      94           0 :     return aResult;
      95             : }
      96             : 
      97           0 : void lcl_addStorageToMediaDescriptor(
      98             :     Sequence< beans::PropertyValue > & rOutMD,
      99             :     const Reference< embed::XStorage > & xStorage )
     100             : {
     101           0 :     rOutMD.realloc( rOutMD.getLength() + 1 );
     102           0 :     rOutMD[rOutMD.getLength() - 1] = beans::PropertyValue(
     103           0 :         C2U("Storage"), -1, uno::makeAny( xStorage ), beans::PropertyState_DIRECT_VALUE );
     104           0 : }
     105             : 
     106           0 : Reference< embed::XStorage > lcl_createStorage(
     107             :     const OUString & rURL,
     108             :     const Reference< uno::XComponentContext > & xContext,
     109             :     const Sequence< beans::PropertyValue > & rMediaDescriptor )
     110             : {
     111             :     // create new storage
     112           0 :     Reference< embed::XStorage > xStorage;
     113           0 :     if( !xContext.is())
     114           0 :         return xStorage;
     115             : 
     116             :     try
     117             :     {
     118             :         Reference< io::XStream > xStream(
     119             :             ::ucbhelper::Content( rURL, Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext()).openStream(),
     120           0 :             uno::UNO_QUERY );
     121             : 
     122           0 :         Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create( xContext ) );
     123           0 :         Sequence< uno::Any > aStorageArgs( 3 );
     124           0 :         aStorageArgs[0] <<= xStream;
     125           0 :         aStorageArgs[1] <<= embed::ElementModes::READWRITE;
     126           0 :         aStorageArgs[2] <<= rMediaDescriptor;
     127             :         xStorage.set(
     128           0 :             xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW );
     129           0 :         OSL_ENSURE( xStorage.is(), "No Storage" );
     130             :     }
     131           0 :     catch( const ::com::sun::star::ucb::ContentCreationException & rEx )
     132             :     {
     133             :         ASSERT_EXCEPTION( rEx );
     134             :     }
     135             : 
     136           0 :     return xStorage;
     137             : }
     138             : 
     139             : } // anonymous namespace
     140             : 
     141             : namespace chart
     142             : {
     143             : 
     144           0 : Reference< document::XFilter > ChartModel::impl_createFilter(
     145             :     const Sequence< beans::PropertyValue > & rMediaDescriptor )
     146             : {
     147           0 :     Reference< document::XFilter > xFilter;
     148             : 
     149             :     // find FilterName in MediaDescriptor
     150             :     OUString aFilterName(
     151           0 :         lcl_getProperty< OUString >( rMediaDescriptor, OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ))));
     152             : 
     153             :     // if FilterName was found, get Filter from factory
     154           0 :     if( !aFilterName.isEmpty() )
     155             :     {
     156             :         try
     157             :         {
     158             :             Reference< container::XNameAccess > xFilterFact(
     159           0 :                 m_xContext->getServiceManager()->createInstanceWithContext(
     160           0 :                     C2U( "com.sun.star.document.FilterFactory" ), m_xContext ),
     161           0 :                 uno::UNO_QUERY_THROW );
     162           0 :             uno::Any aFilterProps( xFilterFact->getByName( aFilterName ));
     163           0 :             Sequence< beans::PropertyValue > aProps;
     164             : 
     165           0 :             if( aFilterProps.hasValue() &&
     166           0 :                 (aFilterProps >>= aProps))
     167             :             {
     168             :                 OUString aFilterServiceName(
     169           0 :                     lcl_getProperty< OUString >( aProps, OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterService" ))));
     170             : 
     171           0 :                 if( !aFilterServiceName.isEmpty())
     172             :                 {
     173             :                     xFilter.set(
     174           0 :                         m_xContext->getServiceManager()->createInstanceWithContext(
     175           0 :                             aFilterServiceName, m_xContext ), uno::UNO_QUERY_THROW );
     176             :                     OSL_TRACE( "Filter found for service %s", U2C( aFilterServiceName ));
     177           0 :                 }
     178           0 :             }
     179             :         }
     180           0 :         catch( const uno::Exception & ex )
     181             :         {
     182             :             ASSERT_EXCEPTION( ex );
     183             :         }
     184             :         OSL_ENSURE( xFilter.is(), "Filter not found via factory" );
     185             :     }
     186             : 
     187             :     // fall-back: create XML-Filter
     188           0 :     if( ! xFilter.is())
     189             :     {
     190             :         OSL_TRACE( "No FilterName passed in MediaDescriptor" );
     191             :         xFilter.set(
     192           0 :             m_xContext->getServiceManager()->createInstanceWithContext(
     193           0 :                 C2U("com.sun.star.comp.chart2.XMLFilter"), m_xContext ),
     194           0 :             uno::UNO_QUERY_THROW );
     195             :     }
     196             : 
     197           0 :     return xFilter;
     198             : }
     199             : 
     200             : //-----------------------------------------------------------------
     201             : // frame::XStorable2
     202             : //-----------------------------------------------------------------
     203             : 
     204           0 : void SAL_CALL ChartModel::storeSelf( const Sequence< beans::PropertyValue >& rMediaDescriptor )
     205             :     throw (lang::IllegalArgumentException,
     206             :            io::IOException,
     207             :            uno::RuntimeException)
     208             : {
     209             :     // only some parameters are allowed (see also SfxBaseModel)
     210             :     // "VersionComment", "Author", "InteractionHandler", "StatusIndicator"
     211             :     // However, they are ignored here.  They would become interesting when
     212             :     // charts support a standalone format again.
     213           0 :     impl_store( rMediaDescriptor, m_xStorage );
     214           0 : }
     215             : 
     216             : //-----------------------------------------------------------------
     217             : // frame::XStorable (base of XStorable2)
     218             : //-----------------------------------------------------------------
     219           0 : sal_Bool SAL_CALL ChartModel::hasLocation()
     220             :     throw(uno::RuntimeException)
     221             : {
     222             :     //@todo guard
     223           0 :     return !m_aResource.isEmpty();
     224             : }
     225             : 
     226           0 : ::rtl::OUString SAL_CALL ChartModel::getLocation()
     227             :     throw(uno::RuntimeException)
     228             : {
     229           0 :     return impl_g_getLocation();
     230             : }
     231             : 
     232           0 : sal_Bool SAL_CALL ChartModel::isReadonly()
     233             :     throw(uno::RuntimeException)
     234             : {
     235             :     //@todo guard
     236           0 :     return m_bReadOnly;
     237             : }
     238             : 
     239           0 : void SAL_CALL ChartModel::store()
     240             :     throw(io::IOException,
     241             :           uno::RuntimeException)
     242             : {
     243           0 :     apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
     244           0 :     if(!aGuard.startApiCall(sal_True)) //start LongLastingCall
     245           0 :         return; //behave passive if already disposed or closed or throw exception @todo?
     246             : 
     247           0 :     ::rtl::OUString aLocation = m_aResource;
     248             : 
     249           0 :     if( aLocation.isEmpty() )
     250           0 :         throw io::IOException( C2U( "no location specified" ), static_cast< ::cppu::OWeakObject* >(this));
     251             :     //@todo check whether aLocation is something like private:factory...
     252           0 :     if( m_bReadOnly )
     253           0 :         throw io::IOException( C2U( "document is read only" ), static_cast< ::cppu::OWeakObject* >(this));
     254             : 
     255           0 :     aGuard.clear();
     256             : 
     257             :     // store
     258           0 :     impl_store( m_aMediaDescriptor, m_xStorage );
     259             : }
     260             : 
     261           0 : void SAL_CALL ChartModel::storeAsURL(
     262             :     const ::rtl::OUString& rURL,
     263             :     const uno::Sequence< beans::PropertyValue >& rMediaDescriptor )
     264             :     throw(io::IOException, uno::RuntimeException)
     265             : {
     266           0 :     apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
     267           0 :     if(!aGuard.startApiCall(sal_True)) //start LongLastingCall
     268           0 :         return; //behave passive if already disposed or closed or throw exception @todo?
     269             : 
     270           0 :     apphelper::MediaDescriptorHelper aMediaDescriptorHelper(rMediaDescriptor);
     271             :     uno::Sequence< beans::PropertyValue > aReducedMediaDescriptor(
     272           0 :         aMediaDescriptorHelper.getReducedForModel() );
     273             : 
     274           0 :     m_bReadOnly = sal_False;
     275           0 :     aGuard.clear();
     276             : 
     277             :     // create new storage
     278           0 :     Reference< embed::XStorage > xStorage( lcl_createStorage( rURL, m_xContext, aReducedMediaDescriptor ));
     279             : 
     280           0 :     if( xStorage.is())
     281             :     {
     282           0 :         impl_store( aReducedMediaDescriptor, xStorage );
     283           0 :         attachResource( rURL, aReducedMediaDescriptor );
     284           0 :     }
     285             : }
     286             : 
     287           0 : void SAL_CALL ChartModel::storeToURL(
     288             :     const ::rtl::OUString& rURL,
     289             :     const uno::Sequence< beans::PropertyValue >& rMediaDescriptor )
     290             :     throw(io::IOException,
     291             :           uno::RuntimeException)
     292             : {
     293           0 :     apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
     294           0 :     if(!aGuard.startApiCall(sal_True)) //start LongLastingCall
     295           0 :         return; //behave passive if already disposed or closed or throw exception @todo?
     296             :     //do not change the internal state of the document here
     297             :     //...
     298             : 
     299           0 :     aGuard.clear();
     300             : 
     301           0 :     apphelper::MediaDescriptorHelper aMediaDescriptorHelper(rMediaDescriptor);
     302             :     uno::Sequence< beans::PropertyValue > aReducedMediaDescriptor(
     303           0 :         aMediaDescriptorHelper.getReducedForModel() );
     304             : 
     305           0 :     if ( rURL == "private:stream" )
     306             :     {
     307             :         try
     308             :         {
     309           0 :             if( m_xContext.is() && aMediaDescriptorHelper.ISSET_OutputStream )
     310             :             {
     311             :                 Reference< io::XStream > xStream(
     312           0 :                     io::TempFile::create(m_xContext), uno::UNO_QUERY_THROW );
     313           0 :                 Reference< io::XInputStream > xInputStream( xStream->getInputStream());
     314             : 
     315             :                 Reference< embed::XStorage > xStorage(
     316           0 :                     ::comphelper::OStorageHelper::GetStorageFromStream( xStream, embed::ElementModes::READWRITE, m_xContext ));
     317           0 :                 if( xStorage.is())
     318             :                 {
     319           0 :                     impl_store( aReducedMediaDescriptor, xStorage );
     320             : 
     321           0 :                     Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY_THROW );
     322           0 :                     xSeekable->seek( 0 );
     323           0 :                     ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, aMediaDescriptorHelper.OutputStream );
     324           0 :                 }
     325             :             }
     326             :         }
     327           0 :         catch( const uno::Exception & ex )
     328             :         {
     329             :             ASSERT_EXCEPTION( ex );
     330             :         }
     331             :     }
     332             :     else
     333             :     {
     334             :         // create new storage
     335           0 :         Reference< embed::XStorage > xStorage( lcl_createStorage( rURL, m_xContext, aReducedMediaDescriptor ));
     336             : 
     337           0 :         if( xStorage.is())
     338           0 :             impl_store( aReducedMediaDescriptor, xStorage );
     339           0 :     }
     340             : }
     341             : 
     342           0 : void ChartModel::impl_store(
     343             :     const Sequence< beans::PropertyValue >& rMediaDescriptor,
     344             :     const Reference< embed::XStorage > & xStorage )
     345             : {
     346           0 :     Reference< document::XFilter > xFilter( impl_createFilter( rMediaDescriptor));
     347           0 :     if( xFilter.is() && xStorage.is())
     348             :     {
     349           0 :         Sequence< beans::PropertyValue > aMD( rMediaDescriptor );
     350           0 :         lcl_addStorageToMediaDescriptor( aMD, xStorage );
     351             :         try
     352             :         {
     353           0 :             Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY_THROW );
     354           0 :             xExporter->setSourceDocument( Reference< lang::XComponent >( this ));
     355           0 :             xFilter->filter( aMD );
     356             :         }
     357           0 :         catch( const uno::Exception & ex )
     358             :         {
     359             :             ASSERT_EXCEPTION( ex );
     360           0 :         }
     361             :     }
     362             :     else
     363             :     {
     364             :         OSL_FAIL( "No filter" );
     365             :     }
     366             : 
     367           0 :     setModified( sal_False );
     368             : 
     369             :     //#i66865#
     370             :     //for data change notification during chart is not loaded:
     371             :     //notify parent data provider after saving thus the parent document can store
     372             :     //the ranges for which a load and update of the chart will be necessary
     373           0 :     Reference< beans::XPropertySet > xPropSet( m_xParent, uno::UNO_QUERY );
     374           0 :     if ( !hasInternalDataProvider() && xPropSet.is() )
     375             :     {
     376           0 :         apphelper::MediaDescriptorHelper aMDHelper(rMediaDescriptor);
     377             :         try
     378             :         {
     379           0 :             xPropSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "SavedObject" )),
     380           0 :                 uno::makeAny( aMDHelper.HierarchicalDocumentName ) );
     381             :         }
     382           0 :         catch ( const uno::Exception& )
     383             :         {
     384           0 :         }
     385           0 :     }
     386           0 : }
     387             : 
     388             : //-----------------------------------------------------------------
     389             : // frame::XLoadable
     390             : //-----------------------------------------------------------------
     391          41 : void SAL_CALL ChartModel::initNew()
     392             :     throw (frame::DoubleInitializationException,
     393             :            io::IOException,
     394             :            uno::Exception,
     395             :            uno::RuntimeException)
     396             : {
     397          41 :     lockControllers();
     398          41 :     createInternalDataProvider( sal_False );
     399             :     try
     400             :     {
     401             :         // create default chart
     402          41 :         Reference< chart2::XChartTypeTemplate > xTemplate( impl_createDefaultChartTypeTemplate() );
     403          41 :         if( xTemplate.is())
     404             :         {
     405             :             try
     406             :             {
     407          41 :                 Reference< chart2::data::XDataSource > xDataSource( impl_createDefaultData() );
     408          41 :                 Sequence< beans::PropertyValue > aParam;
     409             : 
     410          41 :                 bool bSupportsCategories = xTemplate->supportsCategories();
     411          41 :                 if( bSupportsCategories )
     412             :                 {
     413          41 :                     aParam.realloc( 1 );
     414          41 :                     aParam[0] = beans::PropertyValue( C2U("HasCategories"), -1, uno::makeAny( true ),
     415          82 :                                                       beans::PropertyState_DIRECT_VALUE );
     416             :                 }
     417             : 
     418          41 :                 Reference< chart2::XDiagram > xDiagram( xTemplate->createDiagramByDataSource( xDataSource, aParam ) );
     419             : 
     420          41 :                 setFirstDiagram( xDiagram );
     421             : 
     422          41 :                 bool bIsRTL = Application::GetSettings().GetLayoutRTL();
     423             :                 //reverse x axis for rtl charts
     424          41 :                 if( bIsRTL )
     425           0 :                     AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) );
     426             : 
     427             :                 // create and attach legend
     428             :                 Reference< chart2::XLegend > xLegend(
     429          82 :                     m_xContext->getServiceManager()->createInstanceWithContext(
     430          41 :                         C2U( "com.sun.star.chart2.Legend" ), m_xContext ), uno::UNO_QUERY_THROW );
     431          41 :                 Reference< beans::XPropertySet > xLegendProperties( xLegend, uno::UNO_QUERY );
     432          41 :                 if( xLegendProperties.is() )
     433             :                 {
     434          41 :                     xLegendProperties->setPropertyValue( C2U( "FillStyle" ), uno::makeAny( drawing::FillStyle_NONE ));
     435          41 :                     xLegendProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_NONE ));
     436          41 :                     xLegendProperties->setPropertyValue( C2U( "LineColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ));  // gray30
     437          41 :                     xLegendProperties->setPropertyValue( C2U( "FillColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10
     438             : 
     439          41 :                     if( bIsRTL )
     440           0 :                         xLegendProperties->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( chart2::LegendPosition_LINE_START ));
     441             :                 }
     442          41 :                 if(xDiagram.is())
     443          41 :                     xDiagram->setLegend( xLegend );
     444             : 
     445             :                 // set simple 3D look
     446          41 :                 Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY );
     447          41 :                 if( xDiagramProperties.is() )
     448             :                 {
     449          41 :                     xDiagramProperties->setPropertyValue( C2U("RightAngledAxes"), uno::makeAny( sal_True ));
     450          41 :                     xDiagramProperties->setPropertyValue( C2U("D3DScenePerspective"), uno::makeAny( drawing::ProjectionMode_PARALLEL ));
     451          41 :                     ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
     452             :                 }
     453             : 
     454             :                 //set some new 'defaults' for wall and floor
     455          41 :                 if( xDiagram.is() )
     456             :                 {
     457          41 :                     Reference< beans::XPropertySet > xWall( xDiagram->getWall() );
     458          41 :                     if( xWall.is() )
     459             :                     {
     460          41 :                         xWall->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_SOLID ) );
     461          41 :                         xWall->setPropertyValue( C2U( "FillStyle" ), uno::makeAny( drawing::FillStyle_NONE ) );
     462          41 :                         xWall->setPropertyValue( C2U( "LineColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30
     463          41 :                         xWall->setPropertyValue( C2U( "FillColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10
     464             :                     }
     465          41 :                     Reference< beans::XPropertySet > xFloor( xDiagram->getFloor() );
     466          41 :                     if( xFloor.is() )
     467             :                     {
     468          41 :                         xFloor->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
     469          41 :                         xFloor->setPropertyValue( C2U( "FillStyle" ), uno::makeAny( drawing::FillStyle_SOLID ) );
     470          41 :                         xFloor->setPropertyValue( C2U( "LineColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30
     471          41 :                         xFloor->setPropertyValue( C2U( "FillColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xcccccc ) ) ); // gray20
     472          41 :                     }
     473             : 
     474          41 :                 }
     475             :             }
     476           0 :             catch( const uno::Exception & ex )
     477             :             {
     478             :                 ASSERT_EXCEPTION( ex );
     479             :             }
     480             :         }
     481          41 :         ChartModelHelper::setIncludeHiddenCells( false, this );
     482             :     }
     483           0 :     catch( const uno::Exception & ex )
     484             :     {
     485             :         ASSERT_EXCEPTION( ex );
     486             :     }
     487          41 :     setModified( sal_False );
     488          41 :     unlockControllers();
     489             : 
     490             : #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
     491             :     OSL_TRACE( "ChartModel::initNew: Showing ChartDocument structure" );
     492             :     OSL_TRACE( "----------------------------------------------------" );
     493             :     ::chart::debug::ChartDebugTraceDocument( Reference< chart2::XChartDocument >( this ));
     494             : #endif
     495          41 : }
     496             : 
     497           0 : void SAL_CALL ChartModel::load(
     498             :     const Sequence< beans::PropertyValue >& rMediaDescriptor )
     499             :     throw (frame::DoubleInitializationException,
     500             :            io::IOException,
     501             :            uno::Exception,
     502             :            uno::RuntimeException)
     503             : {
     504           0 :     Reference< embed::XStorage > xStorage;
     505           0 :     OUString aURL;
     506             :     try
     507             :     {
     508           0 :         apphelper::MediaDescriptorHelper aMDHelper( rMediaDescriptor );
     509           0 :         if( aMDHelper.ISSET_Storage )
     510             :         {
     511           0 :             xStorage = aMDHelper.Storage;
     512             :         }
     513           0 :         else if( aMDHelper.ISSET_Stream ||
     514             :                  aMDHelper.ISSET_InputStream )
     515             :         {
     516           0 :             if( aMDHelper.ISSET_FilterName &&
     517           0 :                 (aMDHelper.FilterName.equals( C2U("StarChart 5.0")) ||
     518           0 :                  aMDHelper.FilterName.equals( C2U("StarChart 4.0")) ||
     519           0 :                  aMDHelper.FilterName.equals( C2U("StarChart 3.0")) ))
     520             :             {
     521           0 :                 attachResource( aMDHelper.URL, rMediaDescriptor );
     522           0 :                 impl_load( rMediaDescriptor, 0 ); // cannot create a storage from binary streams, but I do not need the storage here anyhow
     523           0 :                 m_bReadOnly = sal_True;
     524           0 :                 return;
     525             :             }
     526             : 
     527           0 :             Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create(m_xContext) );
     528             : 
     529           0 :             if( aMDHelper.ISSET_Stream )
     530             :             {
     531             :                 // convert XStream to XStorage via the storage factory
     532           0 :                 Sequence< uno::Any > aStorageArgs( 2 );
     533           0 :                 aStorageArgs[0] <<= aMDHelper.Stream;
     534             :                 // todo: check if stream is read-only
     535           0 :                 aStorageArgs[1] <<= (embed::ElementModes::READ); //WRITE | embed::ElementModes::NOCREATE);
     536             : 
     537           0 :                 xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ),
     538           0 :                     uno::UNO_QUERY_THROW );
     539             :             }
     540             :             else
     541             :             {
     542             :                 OSL_ASSERT( aMDHelper.ISSET_InputStream );
     543             :                 // convert XInputStream to XStorage via the storage factory
     544           0 :                 Sequence< uno::Any > aStorageArgs( 2 );
     545           0 :                 aStorageArgs[0] <<= aMDHelper.InputStream;
     546           0 :                 aStorageArgs[1] <<= (embed::ElementModes::READ);
     547             : 
     548           0 :                 xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ),
     549           0 :                     uno::UNO_QUERY_THROW );
     550           0 :             }
     551             :         }
     552             : 
     553           0 :         if( aMDHelper.ISSET_URL )
     554           0 :             aURL = aMDHelper.URL;
     555             :     }
     556           0 :     catch( const uno::Exception & ex )
     557             :     {
     558             :         ASSERT_EXCEPTION( ex );
     559             :     }
     560             : 
     561           0 :     if( xStorage.is())
     562             :     {
     563           0 :         attachResource( aURL, rMediaDescriptor );
     564           0 :         impl_load( rMediaDescriptor, xStorage );
     565           0 :     }
     566             : }
     567             : 
     568           0 : void ChartModel::impl_load(
     569             :     const Sequence< beans::PropertyValue >& rMediaDescriptor,
     570             :     const Reference< embed::XStorage >& xStorage )
     571             : {
     572             :     {
     573           0 :         MutexGuard aGuard( m_aModelMutex );
     574           0 :         m_nInLoad++;
     575             :     }
     576             : 
     577           0 :     Reference< document::XFilter > xFilter( impl_createFilter( rMediaDescriptor ));
     578             : 
     579           0 :     if( xFilter.is())
     580             :     {
     581           0 :         Reference< document::XImporter > xImporter( xFilter, uno::UNO_QUERY_THROW );
     582           0 :         xImporter->setTargetDocument( this );
     583           0 :         Sequence< beans::PropertyValue > aMD( rMediaDescriptor );
     584           0 :         lcl_addStorageToMediaDescriptor( aMD, xStorage );
     585             : 
     586           0 :         xFilter->filter( aMD );
     587           0 :         xFilter.clear();
     588             :     }
     589             :     else
     590             :     {
     591             :         OSL_FAIL( "loadFromStorage cannot create filter" );
     592             :     }
     593             : 
     594           0 :     if( xStorage.is() )
     595           0 :         impl_loadGraphics( xStorage );
     596             : 
     597           0 :     setModified( sal_False );
     598             : 
     599             :     // switchToStorage without notifying listeners (which shouldn't exist at
     600             :     // this time, anyway)
     601           0 :     m_xStorage = xStorage;
     602             : 
     603             :     {
     604           0 :         MutexGuard aGuard( m_aModelMutex );
     605           0 :         m_nInLoad--;
     606           0 :     }
     607           0 : }
     608             : 
     609           0 : void ChartModel::impl_loadGraphics(
     610             :     const Reference< embed::XStorage >& xStorage )
     611             : {
     612             :     try
     613             :     {
     614             :         const Reference< embed::XStorage >& xGraphicsStorage(
     615           0 :             xStorage->openStorageElement( C2U( "Pictures" ),
     616           0 :                                           embed::ElementModes::READ ) );
     617             : 
     618           0 :         if( xGraphicsStorage.is() )
     619             :         {
     620             :             const uno::Sequence< ::rtl::OUString > aElementNames(
     621           0 :                 xGraphicsStorage->getElementNames() );
     622             : 
     623           0 :             for( int i = 0; i < aElementNames.getLength(); ++i )
     624             :             {
     625           0 :                 if( xGraphicsStorage->isStreamElement( aElementNames[ i ] ) )
     626             :                 {
     627             :                     uno::Reference< io::XStream > xElementStream(
     628           0 :                         xGraphicsStorage->openStreamElement(
     629           0 :                             aElementNames[ i ],
     630           0 :                             embed::ElementModes::READ ) );
     631             : 
     632           0 :                     if( xElementStream.is() )
     633             :                     {
     634             :                         std::auto_ptr< SvStream > apIStm(
     635             :                             ::utl::UcbStreamHelper::CreateStream(
     636           0 :                                 xElementStream, true ) );
     637             : 
     638           0 :                         if( apIStm.get() )
     639             :                         {
     640           0 :                             Graphic aGraphic;
     641             : 
     642           0 :                             if( !GraphicConverter::Import(
     643           0 :                                     *apIStm.get(),
     644           0 :                                     aGraphic ) )
     645             :                             {
     646           0 :                                 m_aGraphicObjectVector.push_back( aGraphic );
     647           0 :                             }
     648           0 :                         }
     649           0 :                     }
     650             :                 }
     651           0 :             }
     652           0 :         }
     653             :     }
     654           0 :     catch ( const uno::Exception& )
     655             :     {
     656             :     }
     657           0 : }
     658             : 
     659             : //-----------------------------------------------------------------
     660             : // util::XModifiable
     661             : //-----------------------------------------------------------------
     662         122 : void SAL_CALL ChartModel::impl_notifyModifiedListeners()
     663             :     throw( uno::RuntimeException)
     664             : {
     665             :     {
     666         122 :         MutexGuard aGuard( m_aModelMutex );
     667         122 :         m_bUpdateNotificationsPending = false;
     668             :     }
     669             : 
     670             :     //always notify the view first!
     671         122 :     ChartViewHelper::setViewToDirtyState( this );
     672             : 
     673             :     ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer
     674         122 :         .getContainer( ::getCppuType((const uno::Reference< util::XModifyListener >*)0) );
     675         122 :     if( pIC )
     676             :     {
     677          81 :         lang::EventObject aEvent( static_cast< lang::XComponent*>(this) );
     678          81 :         ::cppu::OInterfaceIteratorHelper aIt( *pIC );
     679         363 :         while( aIt.hasMoreElements() )
     680             :         {
     681         201 :             uno::Reference< util::XModifyListener > xListener( aIt.next(), uno::UNO_QUERY );
     682         201 :             if( xListener.is() )
     683         201 :                 xListener->modified( aEvent );
     684         282 :         }
     685             :     }
     686         122 : }
     687             : 
     688           9 : sal_Bool SAL_CALL ChartModel::isModified()
     689             :     throw(uno::RuntimeException)
     690             : {
     691             :     //@todo guard
     692           9 :     return m_bModified;
     693             : }
     694             : 
     695        1722 : void SAL_CALL ChartModel::setModified( sal_Bool bModified )
     696             :     throw(beans::PropertyVetoException,
     697             :           uno::RuntimeException)
     698             : {
     699        1722 :     apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
     700        1722 :     if(!aGuard.startApiCall())//@todo ? is this a long lasting call??
     701             :         return; //behave passive if already disposed or closed or throw exception @todo?
     702        1722 :     m_bModified = bModified;
     703             : 
     704        1722 :     if( m_nControllerLockCount > 0 )
     705             :     {
     706        1722 :         m_bUpdateNotificationsPending = true;
     707             :         return;//don't call listeners if controllers are locked
     708             :     }
     709           0 :     aGuard.clear();
     710             : 
     711           0 :     if(bModified)
     712           0 :         impl_notifyModifiedListeners();
     713             : }
     714             : 
     715             : //-----------------------------------------------------------------
     716             : // util::XModifyBroadcaster (base of XModifiable)
     717             : //-----------------------------------------------------------------
     718         164 : void SAL_CALL ChartModel::addModifyListener(
     719             :     const uno::Reference< util::XModifyListener >& xListener )
     720             :     throw(uno::RuntimeException)
     721             : {
     722         164 :     if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
     723         164 :         return; //behave passive if already disposed or closed
     724             : 
     725             :     m_aLifeTimeManager.m_aListenerContainer.addInterface(
     726         164 :         ::getCppuType((const uno::Reference< util::XModifyListener >*)0), xListener );
     727             : }
     728             : 
     729          82 : void SAL_CALL ChartModel::removeModifyListener(
     730             :     const uno::Reference< util::XModifyListener >& xListener )
     731             :     throw(uno::RuntimeException)
     732             : {
     733          82 :     if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
     734          82 :         return; //behave passive if already disposed or closed
     735             : 
     736             :     m_aLifeTimeManager.m_aListenerContainer.removeInterface(
     737          82 :         ::getCppuType((const uno::Reference< util::XModifyListener >*)0), xListener );
     738             : }
     739             : 
     740             : //-----------------------------------------------------------------
     741             : // util::XModifyListener
     742             : //-----------------------------------------------------------------
     743        1417 : void SAL_CALL ChartModel::modified( const lang::EventObject& )
     744             :     throw (uno::RuntimeException)
     745             : {
     746        1417 :     if( m_nInLoad == 0 )
     747        1417 :         setModified( sal_True );
     748        1417 : }
     749             : 
     750             : //-----------------------------------------------------------------
     751             : // lang::XEventListener (base of util::XModifyListener)
     752             : //-----------------------------------------------------------------
     753          62 : void SAL_CALL ChartModel::disposing( const lang::EventObject& )
     754             :     throw (uno::RuntimeException)
     755             : {
     756             :     // child was disposed -- should not happen from outside
     757          62 : }
     758             : 
     759             : 
     760             : //-----------------------------------------------------------------
     761             : // document::XStorageBasedDocument
     762             : //-----------------------------------------------------------------
     763           0 : void SAL_CALL ChartModel::loadFromStorage(
     764             :     const Reference< embed::XStorage >& xStorage,
     765             :     const Sequence< beans::PropertyValue >& rMediaDescriptor )
     766             :     throw (lang::IllegalArgumentException,
     767             :            frame::DoubleInitializationException,
     768             :            io::IOException,
     769             :            uno::Exception,
     770             :            uno::RuntimeException)
     771             : {
     772           0 :     attachResource( OUString(), rMediaDescriptor );
     773           0 :     impl_load( rMediaDescriptor, xStorage );
     774           0 : }
     775             : 
     776           0 : void SAL_CALL ChartModel::storeToStorage(
     777             :     const Reference< embed::XStorage >& xStorage,
     778             :     const Sequence< beans::PropertyValue >& rMediaDescriptor )
     779             :     throw (lang::IllegalArgumentException,
     780             :            io::IOException,
     781             :            uno::Exception,
     782             :            uno::RuntimeException)
     783             : {
     784           0 :     impl_store( rMediaDescriptor, xStorage );
     785           0 : }
     786             : 
     787           0 : void SAL_CALL ChartModel::switchToStorage( const Reference< embed::XStorage >& xStorage )
     788             :     throw (lang::IllegalArgumentException,
     789             :            io::IOException,
     790             :            uno::Exception,
     791             :            uno::RuntimeException)
     792             : {
     793           0 :     m_xStorage = xStorage;
     794           0 :     impl_notifyStorageChangeListeners();
     795           0 : }
     796             : 
     797           0 : Reference< embed::XStorage > SAL_CALL ChartModel::getDocumentStorage()
     798             :     throw (io::IOException,
     799             :            uno::Exception,
     800             :            uno::RuntimeException)
     801             : {
     802           0 :     return m_xStorage;
     803             : }
     804             : 
     805           0 : void SAL_CALL ChartModel::impl_notifyStorageChangeListeners()
     806             :     throw( uno::RuntimeException)
     807             : {
     808             :     ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer
     809           0 :           .getContainer( ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0) );
     810           0 :     if( pIC )
     811             :     {
     812           0 :         ::cppu::OInterfaceIteratorHelper aIt( *pIC );
     813           0 :         while( aIt.hasMoreElements() )
     814             :         {
     815           0 :             uno::Reference< document::XStorageChangeListener > xListener( aIt.next(), uno::UNO_QUERY );
     816           0 :             if( xListener.is() )
     817           0 :                 xListener->notifyStorageChange( static_cast< ::cppu::OWeakObject* >( this ), m_xStorage );
     818           0 :         }
     819             :     }
     820           0 : }
     821             : 
     822           0 : void SAL_CALL ChartModel::addStorageChangeListener( const Reference< document::XStorageChangeListener >& xListener )
     823             :     throw (uno::RuntimeException)
     824             : {
     825           0 :     if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
     826           0 :         return; //behave passive if already disposed or closed
     827             : 
     828             :     m_aLifeTimeManager.m_aListenerContainer.addInterface(
     829           0 :         ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
     830             : }
     831             : 
     832           0 : void SAL_CALL ChartModel::removeStorageChangeListener( const Reference< document::XStorageChangeListener >& xListener )
     833             :     throw (uno::RuntimeException)
     834             : {
     835           0 :     if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
     836           0 :         return; //behave passive if already disposed or closed
     837             : 
     838             :     m_aLifeTimeManager.m_aListenerContainer.removeInterface(
     839           0 :         ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
     840             : }
     841             : 
     842             : } //  namespace chart
     843             : 
     844             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10