LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/main - ChartFrameloader.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 74 1.4 %
Date: 2012-12-27 Functions: 1 11 9.1 %
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           0 : ChartFrameLoader::ChartFrameLoader(
      37             :         uno::Reference<uno::XComponentContext> const & xContext)
      38           0 :         : m_bCancelRequired( sal_False )
      39             : {
      40           0 :     m_xCC = xContext;
      41           0 :     m_oCancelFinished.reset();
      42           0 : }
      43             : 
      44           0 : ChartFrameLoader::~ChartFrameLoader()
      45             : {
      46           0 : }
      47             : 
      48           0 :     sal_Bool ChartFrameLoader
      49             : ::impl_checkCancel()
      50             : {
      51           0 :     if(m_bCancelRequired)
      52             :     {
      53           0 :         m_oCancelFinished.set();
      54           0 :         return sal_True;
      55             :     }
      56           0 :     return sal_False;
      57             : }
      58             : 
      59             : //-----------------------------------------------------------------
      60             : // lang::XServiceInfo
      61             : //-----------------------------------------------------------------
      62             : 
      63           1 : APPHELPER_XSERVICEINFO_IMPL(ChartFrameLoader,CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME)
      64             : 
      65           0 :     uno::Sequence< rtl::OUString > ChartFrameLoader
      66             : ::getSupportedServiceNames_Static()
      67             : {
      68           0 :     uno::Sequence< rtl::OUString > aSNS( 1 );
      69           0 :     aSNS.getArray()[ 0 ] = CHART_FRAMELOADER_SERVICE_NAME;
      70           0 :     return aSNS;
      71             : }
      72             : 
      73             : //-----------------------------------------------------------------
      74             : // frame::XFrameLoader
      75             : //-----------------------------------------------------------------
      76             : 
      77           0 :     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           0 :     uno::Reference< frame::XModel >         xModel;
      85           0 :     bool bHaveLoadedModel = false;
      86             : 
      87           0 :     comphelper::MediaDescriptor aMediaDescriptor(rMediaDescriptor);
      88             :     {
      89           0 :         comphelper::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( aMediaDescriptor.PROP_MODEL()));
      90           0 :         if( aIt != aMediaDescriptor.end())
      91             :         {
      92           0 :             xModel.set( (*aIt).second.get< uno::Reference< frame::XModel > >());
      93           0 :             bHaveLoadedModel = true;
      94             :         }
      95             :     }
      96             : 
      97             :     //create and initialize the model
      98           0 :     if( ! xModel.is())
      99             :     {
     100             :         //@todo?? load mechanism to cancel during loading of document
     101             :         xModel.set(
     102           0 :                 m_xCC->getServiceManager()->createInstanceWithContext(
     103           0 :                 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME, m_xCC )
     104           0 :                 , uno::UNO_QUERY );
     105             : 
     106           0 :         if( impl_checkCancel() )
     107           0 :             return sal_False;
     108             :     }
     109             : 
     110             :     //create the controller(+XWindow)
     111           0 :     uno::Reference< frame::XController >    xController = NULL;
     112           0 :     uno::Reference< awt::XWindow >          xComponentWindow = NULL;
     113             :     {
     114             :         xController = uno::Reference< frame::XController >(
     115           0 :             m_xCC->getServiceManager()->createInstanceWithContext(
     116           0 :             CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME,m_xCC )
     117           0 :             , 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             :         xComponentWindow =
     122           0 :                       uno::Reference< awt::XWindow >( xController, uno::UNO_QUERY );
     123             : 
     124           0 :         if( impl_checkCancel() )
     125           0 :             return sal_False;
     126             :     }
     127             : 
     128             : 
     129             :     //connect frame, controller and model one to each other:
     130           0 :     if(xController.is()&&xModel.is())
     131             :     {
     132           0 :         xModel->connectController(xController);
     133           0 :         xModel->setCurrentController(xController);
     134           0 :         xController->attachModel(xModel);
     135           0 :         if(xFrame.is())
     136           0 :             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           0 :         xController->attachFrame(xFrame);
     140             :     }
     141             : 
     142             :     // call initNew() or load() at XLoadable
     143           0 :     if(!bHaveLoadedModel)
     144             :     try
     145             :     {
     146           0 :         comphelper::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( aMediaDescriptor.PROP_URL()));
     147           0 :         if( aIt != aMediaDescriptor.end())
     148             :         {
     149           0 :             ::rtl::OUString aURL( (*aIt).second.get< ::rtl::OUString >());
     150           0 :             if( aURL.matchAsciiL(
     151           0 :                 RTL_CONSTASCII_STRINGPARAM( "private:factory/schart" )))
     152             :             {
     153             :                 // create new file
     154           0 :                 uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
     155           0 :                 xLoadable->initNew();
     156             :             }
     157             :             else
     158             :             {
     159           0 :                 aMediaDescriptor.addInputStream();
     160           0 :                 uno::Sequence< beans::PropertyValue > aCompleteMediaDescriptor;
     161           0 :                 aMediaDescriptor >> aCompleteMediaDescriptor;
     162           0 :                 apphelper::MediaDescriptorHelper aMDHelper( aCompleteMediaDescriptor );
     163             : 
     164             :                 // load file
     165             :                 // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
     166           0 :                 uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
     167           0 :                 xLoadable->load( aCompleteMediaDescriptor );
     168             : 
     169             :                 //resize standalone files to get correct size:
     170           0 :                 if( xComponentWindow.is() && aMDHelper.ISSET_FilterName && aMDHelper.FilterName.equals( C2U("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           0 :                 }
     176           0 :             }
     177             :         }
     178             :     }
     179           0 :     catch( const uno::Exception & ex )
     180             :     {
     181             :         ASSERT_EXCEPTION( ex );
     182             :     }
     183             : 
     184           0 :     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