LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ChartFrameloader.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 68 84 81.0 %
Date: 2015-06-13 12:38:46 Functions: 10 12 83.3 %
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 "ChartFrameloader.hxx"
      21             : #include "servicenames.hxx"
      22             : #include "MediaDescriptorHelper.hxx"
      23             : #include "macros.hxx"
      24             : #include <unotools/mediadescriptor.hxx>
      25             : #include <cppuhelper/supportsservice.hxx>
      26             : #include <com/sun/star/document/XImporter.hpp>
      27             : #include <com/sun/star/document/XFilter.hpp>
      28             : #include <com/sun/star/frame/XLoadable.hpp>
      29             : 
      30             : namespace chart
      31             : {
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35          19 : ChartFrameLoader::ChartFrameLoader(
      36             :         uno::Reference<uno::XComponentContext> const & xContext)
      37          19 :         : m_bCancelRequired( false )
      38             : {
      39          19 :     m_xCC = xContext;
      40          19 :     m_oCancelFinished.reset();
      41          19 : }
      42             : 
      43          38 : ChartFrameLoader::~ChartFrameLoader()
      44             : {
      45          38 : }
      46             : 
      47          33 : bool ChartFrameLoader::impl_checkCancel()
      48             : {
      49          33 :     if(m_bCancelRequired)
      50             :     {
      51           0 :         m_oCancelFinished.set();
      52           0 :         return true;
      53             :     }
      54          33 :     return false;
      55             : }
      56             : 
      57             : // lang::XServiceInfo
      58             : 
      59           1 : OUString SAL_CALL ChartFrameLoader::getImplementationName()
      60             :     throw( css::uno::RuntimeException, std::exception )
      61             : {
      62           1 :     return getImplementationName_Static();
      63             : }
      64             : 
      65           1 : OUString ChartFrameLoader::getImplementationName_Static()
      66             : {
      67           1 :     return OUString(CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME);
      68             : }
      69             : 
      70           0 : sal_Bool SAL_CALL ChartFrameLoader::supportsService( const OUString& rServiceName )
      71             :     throw( css::uno::RuntimeException, std::exception )
      72             : {
      73           0 :     return cppu::supportsService(this, rServiceName);
      74             : }
      75             : 
      76           1 : css::uno::Sequence< OUString > SAL_CALL ChartFrameLoader::getSupportedServiceNames()
      77             :     throw( css::uno::RuntimeException, std::exception )
      78             : {
      79           1 :     return getSupportedServiceNames_Static();
      80             : }
      81             : 
      82           1 : uno::Sequence< OUString > ChartFrameLoader::getSupportedServiceNames_Static()
      83             : {
      84           1 :     uno::Sequence< OUString > aSNS( 1 );
      85           1 :     aSNS.getArray()[ 0 ] = CHART_FRAMELOADER_SERVICE_NAME;
      86           1 :     return aSNS;
      87             : }
      88             : 
      89             : // frame::XFrameLoader
      90             : 
      91          17 : sal_Bool SAL_CALL ChartFrameLoader::load( const uno::Sequence< beans::PropertyValue >& rMediaDescriptor, const uno::Reference<frame::XFrame >& xFrame )
      92             :     throw (uno::RuntimeException, std::exception)
      93             : {
      94             :     //@todo ? need to add as terminate listener to desktop?
      95             : 
      96          17 :     uno::Reference< frame::XModel >         xModel;
      97          17 :     bool bHaveLoadedModel = false;
      98             : 
      99          34 :     utl::MediaDescriptor aMediaDescriptor(rMediaDescriptor);
     100             :     {
     101          17 :         utl::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( utl::MediaDescriptor::PROP_MODEL()));
     102          17 :         if( aIt != aMediaDescriptor.end())
     103             :         {
     104           1 :             xModel.set( (*aIt).second.get< uno::Reference< frame::XModel > >());
     105           1 :             bHaveLoadedModel = true;
     106             :         }
     107             :     }
     108             : 
     109             :     //create and initialize the model
     110          17 :     if( ! xModel.is())
     111             :     {
     112             :         //@todo?? load mechanism to cancel during loading of document
     113             :         xModel.set(
     114          32 :                 m_xCC->getServiceManager()->createInstanceWithContext(
     115          16 :                 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME, m_xCC )
     116          16 :                 , uno::UNO_QUERY );
     117             : 
     118          16 :         if( impl_checkCancel() )
     119           0 :             return sal_False;
     120             :     }
     121             : 
     122             :     //create the controller(+XWindow)
     123          34 :     uno::Reference< frame::XController >    xController = NULL;
     124          34 :     uno::Reference< awt::XWindow >          xComponentWindow = NULL;
     125             :     {
     126          34 :         xController = uno::Reference< frame::XController >(
     127          34 :             m_xCC->getServiceManager()->createInstanceWithContext(
     128          17 :             CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME,m_xCC )
     129          17 :             , uno::UNO_QUERY );
     130             : 
     131             :         //!!!it is a special characteristic of the example application
     132             :         //that the controller simultaniously provides the XWindow controller functionality
     133          34 :         xComponentWindow =
     134          17 :                       uno::Reference< awt::XWindow >( xController, uno::UNO_QUERY );
     135             : 
     136          17 :         if( impl_checkCancel() )
     137           0 :             return sal_False;
     138             :     }
     139             : 
     140             :     //connect frame, controller and model one to each other:
     141          17 :     if(xController.is()&&xModel.is())
     142             :     {
     143          17 :         xModel->connectController(xController);
     144          17 :         xModel->setCurrentController(xController);
     145          17 :         xController->attachModel(xModel);
     146          17 :         if(xFrame.is())
     147          17 :             xFrame->setComponent(xComponentWindow,xController);
     148             :         //creates the view and menu
     149             :         //for correct menu creation the initialized component must be already set into the frame
     150          17 :         xController->attachFrame(xFrame);
     151             :     }
     152             : 
     153             :     // call initNew() or load() at XLoadable
     154          17 :     if(!bHaveLoadedModel)
     155             :         try
     156             :         {
     157          16 :             utl::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( utl::MediaDescriptor::PROP_URL()));
     158          16 :             if( aIt != aMediaDescriptor.end())
     159             :             {
     160          16 :                 OUString aURL( (*aIt).second.get< OUString >());
     161          16 :                 if( aURL.startsWith( "private:factory/schart" ) )
     162             :                 {
     163             :                     // create new file
     164          13 :                     uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
     165          13 :                     xLoadable->initNew();
     166             :                 }
     167             :                 else
     168             :                 {
     169           3 :                     aMediaDescriptor.addInputStream();
     170           3 :                     uno::Sequence< beans::PropertyValue > aCompleteMediaDescriptor;
     171           3 :                     aMediaDescriptor >> aCompleteMediaDescriptor;
     172           6 :                     apphelper::MediaDescriptorHelper aMDHelper( aCompleteMediaDescriptor );
     173             : 
     174             :                     // load file
     175             :                     // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
     176           6 :                     uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
     177           3 :                     xLoadable->load( aCompleteMediaDescriptor );
     178             : 
     179             :                     //resize standalone files to get correct size:
     180           3 :                     if( xComponentWindow.is() && aMDHelper.ISSET_FilterName && aMDHelper.FilterName == "StarChart 5.0" )
     181             :                     {
     182           0 :                         awt::Rectangle aRect( xComponentWindow->getPosSize() );
     183           0 :                         sal_Int16 nFlags=0;
     184           0 :                         xComponentWindow->setPosSize( aRect.X, aRect.Y, aRect.Width, aRect.Height, nFlags );
     185           3 :                     }
     186          16 :                 }
     187             :             }
     188             :         }
     189           0 :         catch( const uno::Exception & ex )
     190             :         {
     191             :             ASSERT_EXCEPTION( ex );
     192             :         }
     193             : 
     194          34 :     return sal_True;
     195             : }
     196             : 
     197           0 : void SAL_CALL ChartFrameLoader::cancel()
     198             :     throw (uno::RuntimeException, std::exception)
     199             : {
     200           0 :     m_oCancelFinished.reset();
     201           0 :     m_bCancelRequired = true;
     202           0 :     m_oCancelFinished.wait();
     203           0 :     m_bCancelRequired = false;
     204           0 : }
     205             : 
     206             : } //namespace chart
     207             : 
     208             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     209          19 : com_sun_star_comp_chart2_ChartFrameLoader_get_implementation(css::uno::XComponentContext *context,
     210             :                                                              css::uno::Sequence<css::uno::Any> const &)
     211             : {
     212          19 :     return cppu::acquire(new chart::ChartFrameLoader(context));
     213             : }
     214             : 
     215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11