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