LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ChartFrameloader.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 61 75 81.3 %
Date: 2014-04-11 Functions: 7 11 63.6 %
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          18 : ChartFrameLoader::ChartFrameLoader(
      35             :         uno::Reference<uno::XComponentContext> const & xContext)
      36          18 :         : m_bCancelRequired( sal_False )
      37             : {
      38          18 :     m_xCC = xContext;
      39          18 :     m_oCancelFinished.reset();
      40          18 : }
      41             : 
      42          36 : ChartFrameLoader::~ChartFrameLoader()
      43             : {
      44          36 : }
      45             : 
      46          33 :     sal_Bool ChartFrameLoader
      47             : ::impl_checkCancel()
      48             : {
      49          33 :     if(m_bCancelRequired)
      50             :     {
      51           0 :         m_oCancelFinished.set();
      52           0 :         return sal_True;
      53             :     }
      54          33 :     return sal_False;
      55             : }
      56             : 
      57             : // lang::XServiceInfo
      58             : 
      59          23 : APPHELPER_XSERVICEINFO_IMPL(ChartFrameLoader,CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME)
      60             : 
      61           3 :     uno::Sequence< OUString > ChartFrameLoader
      62             : ::getSupportedServiceNames_Static()
      63             : {
      64           3 :     uno::Sequence< OUString > aSNS( 1 );
      65           3 :     aSNS.getArray()[ 0 ] = CHART_FRAMELOADER_SERVICE_NAME;
      66           3 :     return aSNS;
      67             : }
      68             : 
      69             : // frame::XFrameLoader
      70             : 
      71          17 :     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          17 :     uno::Reference< frame::XModel >         xModel;
      79          17 :     bool bHaveLoadedModel = false;
      80             : 
      81          34 :     utl::MediaDescriptor aMediaDescriptor(rMediaDescriptor);
      82             :     {
      83          17 :         utl::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( aMediaDescriptor.PROP_MODEL()));
      84          17 :         if( aIt != aMediaDescriptor.end())
      85             :         {
      86           1 :             xModel.set( (*aIt).second.get< uno::Reference< frame::XModel > >());
      87           1 :             bHaveLoadedModel = true;
      88             :         }
      89             :     }
      90             : 
      91             :     //create and initialize the model
      92          17 :     if( ! xModel.is())
      93             :     {
      94             :         //@todo?? load mechanism to cancel during loading of document
      95             :         xModel.set(
      96          32 :                 m_xCC->getServiceManager()->createInstanceWithContext(
      97          16 :                 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME, m_xCC )
      98          16 :                 , uno::UNO_QUERY );
      99             : 
     100          16 :         if( impl_checkCancel() )
     101           0 :             return sal_False;
     102             :     }
     103             : 
     104             :     //create the controller(+XWindow)
     105          34 :     uno::Reference< frame::XController >    xController = NULL;
     106          34 :     uno::Reference< awt::XWindow >          xComponentWindow = NULL;
     107             :     {
     108          34 :         xController = uno::Reference< frame::XController >(
     109          34 :             m_xCC->getServiceManager()->createInstanceWithContext(
     110          17 :             CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME,m_xCC )
     111          17 :             , 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          34 :         xComponentWindow =
     116          17 :                       uno::Reference< awt::XWindow >( xController, uno::UNO_QUERY );
     117             : 
     118          17 :         if( impl_checkCancel() )
     119           0 :             return sal_False;
     120             :     }
     121             : 
     122             :     //connect frame, controller and model one to each other:
     123          17 :     if(xController.is()&&xModel.is())
     124             :     {
     125          17 :         xModel->connectController(xController);
     126          17 :         xModel->setCurrentController(xController);
     127          17 :         xController->attachModel(xModel);
     128          17 :         if(xFrame.is())
     129          17 :             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          17 :         xController->attachFrame(xFrame);
     133             :     }
     134             : 
     135             :     // call initNew() or load() at XLoadable
     136          17 :     if(!bHaveLoadedModel)
     137             :         try
     138             :         {
     139          16 :             utl::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( aMediaDescriptor.PROP_URL()));
     140          16 :             if( aIt != aMediaDescriptor.end())
     141             :             {
     142          16 :                 OUString aURL( (*aIt).second.get< OUString >());
     143          16 :                 if( aURL.startsWith( "private:factory/schart" ) )
     144             :                 {
     145             :                     // create new file
     146          13 :                     uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
     147          13 :                     xLoadable->initNew();
     148             :                 }
     149             :                 else
     150             :                 {
     151           3 :                     aMediaDescriptor.addInputStream();
     152           3 :                     uno::Sequence< beans::PropertyValue > aCompleteMediaDescriptor;
     153           3 :                     aMediaDescriptor >> aCompleteMediaDescriptor;
     154           6 :                     apphelper::MediaDescriptorHelper aMDHelper( aCompleteMediaDescriptor );
     155             : 
     156             :                     // load file
     157             :                     // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
     158           6 :                     uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
     159           3 :                     xLoadable->load( aCompleteMediaDescriptor );
     160             : 
     161             :                     //resize standalone files to get correct size:
     162           3 :                     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           3 :                     }
     168          16 :                 }
     169             :             }
     170             :         }
     171           0 :         catch( const uno::Exception & ex )
     172             :         {
     173             :             ASSERT_EXCEPTION( ex );
     174             :         }
     175             : 
     176          34 :     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 = sal_True;
     184           0 :     m_oCancelFinished.wait();
     185           0 :     m_bCancelRequired = sal_False;
     186           0 : }
     187             : 
     188             : } //namespace chart
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10