LCOV - code coverage report
Current view: top level - framework/source/dispatch - startmoduledispatcher.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 51 0.0 %
Date: 2014-04-14 Functions: 0 12 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 <dispatch/startmoduledispatcher.hxx>
      21             : 
      22             : #include <pattern/frame.hxx>
      23             : #include <framework/framelistanalyzer.hxx>
      24             : #include <dispatchcommands.h>
      25             : #include <targets.h>
      26             : #include <services.h>
      27             : #include <general.h>
      28             : 
      29             : #include <com/sun/star/frame/Desktop.hpp>
      30             : #include <com/sun/star/frame/XController.hpp>
      31             : #include <com/sun/star/frame/CommandGroup.hpp>
      32             : #include <com/sun/star/frame/StartModule.hpp>
      33             : #include <com/sun/star/awt/XTopWindow.hpp>
      34             : #include "com/sun/star/beans/XFastPropertySet.hpp"
      35             : #include <com/sun/star/frame/XModuleManager.hpp>
      36             : 
      37             : #include <toolkit/helper/vclunohelper.hxx>
      38             : #include <vcl/window.hxx>
      39             : #include <vcl/svapp.hxx>
      40             : #include <osl/mutex.hxx>
      41             : #include <unotools/moduleoptions.hxx>
      42             : #include <comphelper/processfactory.hxx>
      43             : 
      44             : namespace framework{
      45             : 
      46             : #ifdef fpf
      47             :     #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
      48             : #endif
      49             : namespace fpf = ::framework::pattern::frame;
      50             : 
      51           0 : StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference< css::uno::XComponentContext >&     rxContext,
      52             :                                              const css::uno::Reference< css::frame::XFrame >&              xFrame ,
      53             :                                              const OUString&                                        sTarget)
      54             :     : m_xContext         (rxContext                         )
      55             :     , m_xOwner           (xFrame                        )
      56             :     , m_sDispatchTarget  (sTarget                       )
      57           0 :     , m_lStatusListener  (m_mutex)
      58             : {
      59           0 : }
      60             : 
      61           0 : StartModuleDispatcher::~StartModuleDispatcher()
      62             : {
      63           0 : }
      64             : 
      65           0 : void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL&                                  aURL      ,
      66             :                                               const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
      67             :     throw(css::uno::RuntimeException, std::exception)
      68             : {
      69           0 :     dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
      70           0 : }
      71             : 
      72           0 : void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL&                                             aURL      ,
      73             :                                                               const css::uno::Sequence< css::beans::PropertyValue >&            /*lArguments*/,
      74             :                                                               const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
      75             :     throw(css::uno::RuntimeException, std::exception)
      76             : {
      77           0 :     ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
      78           0 :     if ( aURL.Complete == CMD_UNO_SHOWSTARTMODULE )
      79             :     {
      80           0 :         nResult = css::frame::DispatchResultState::FAILURE;
      81           0 :         if (implts_isBackingModePossible ())
      82             :         {
      83           0 :             if (implts_establishBackingMode ())
      84           0 :                 nResult = css::frame::DispatchResultState::SUCCESS;
      85             :         }
      86             :     }
      87             : 
      88           0 :     implts_notifyResultListener(xListener, nResult, css::uno::Any());
      89           0 : }
      90             : 
      91           0 : css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
      92             :     throw(css::uno::RuntimeException, std::exception)
      93             : {
      94           0 :     return css::uno::Sequence< ::sal_Int16 >();
      95             : }
      96             : 
      97           0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
      98             :     throw(css::uno::RuntimeException, std::exception)
      99             : {
     100           0 :     return css::uno::Sequence< css::frame::DispatchInformation >();
     101             : }
     102             : 
     103           0 : void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     104             :                                                        const css::util::URL&                                     /*aURL*/     )
     105             :     throw(css::uno::RuntimeException, std::exception)
     106             : {
     107           0 : }
     108             : 
     109           0 : void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     110             :                                                           const css::util::URL&                                     /*aURL*/     )
     111             :     throw(css::uno::RuntimeException, std::exception)
     112             : {
     113           0 : }
     114             : 
     115           0 : bool StartModuleDispatcher::implts_isBackingModePossible()
     116             : {
     117           0 :     if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE))
     118           0 :         return false;
     119             : 
     120             :     css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
     121           0 :         css::frame::Desktop::create( m_xContext ), css::uno::UNO_QUERY);
     122             : 
     123             :     FrameListAnalyzer aCheck(
     124             :         xDesktop,
     125             :         css::uno::Reference< css::frame::XFrame >(),
     126           0 :         FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
     127             : 
     128           0 :     bool  bIsPossible    = false;
     129           0 :     ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength ();
     130             : 
     131           0 :     if (
     132           0 :         ( ! aCheck.m_xBackingComponent.is ()) &&
     133             :         (   nVisibleFrames < 1              )
     134             :        )
     135             :     {
     136           0 :         bIsPossible = true;
     137             :     }
     138             : 
     139           0 :     return bIsPossible;
     140             : }
     141             : 
     142           0 : bool StartModuleDispatcher::implts_establishBackingMode()
     143             : {
     144           0 :     css::uno::Reference< css::frame::XDesktop2> xDesktop       = css::frame::Desktop::create( m_xContext );
     145           0 :     css::uno::Reference< css::frame::XFrame > xFrame           = xDesktop->findFrame(SPECIALTARGET_BLANK, 0);
     146           0 :     css::uno::Reference< css::awt::XWindow  > xContainerWindow = xFrame->getContainerWindow();
     147             : 
     148           0 :     css::uno::Reference< css::frame::XController > xStartModule = css::frame::StartModule::createWithParentWindow(m_xContext, xContainerWindow);
     149           0 :     css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
     150           0 :     xFrame->setComponent(xComponentWindow, xStartModule);
     151           0 :     xStartModule->attachFrame(xFrame);
     152           0 :     xContainerWindow->setVisible(sal_True);
     153             : 
     154           0 :     return true;
     155             : }
     156             : 
     157           0 : void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
     158             :                                                               ::sal_Int16                                                 nState   ,
     159             :                                                         const css::uno::Any&                                              aResult  )
     160             : {
     161           0 :     if ( ! xListener.is())
     162           0 :         return;
     163             : 
     164             :     css::frame::DispatchResultEvent aEvent(
     165             :         css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
     166             :         nState,
     167           0 :         aResult);
     168             : 
     169           0 :     xListener->dispatchFinished(aEvent);
     170             : }
     171             : 
     172             : } // namespace framework
     173             : 
     174             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10