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

Generated by: LCOV version 1.10