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

Generated by: LCOV version 1.10