LCOV - code coverage report
Current view: top level - framework/source/dispatch - startmoduledispatcher.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 51 0.0 %
Date: 2015-06-13 12:38:46 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             :     : m_xContext         (rxContext                         )
      54             :     , m_xOwner           (xFrame                        )
      55           0 :     , m_lStatusListener  (m_mutex)
      56             : {
      57           0 : }
      58             : 
      59           0 : StartModuleDispatcher::~StartModuleDispatcher()
      60             : {
      61           0 : }
      62             : 
      63           0 : void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL&                                  aURL      ,
      64             :                                               const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
      65             :     throw(css::uno::RuntimeException, std::exception)
      66             : {
      67           0 :     dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
      68           0 : }
      69             : 
      70           0 : void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL&                                             aURL      ,
      71             :                                                               const css::uno::Sequence< css::beans::PropertyValue >&            /*lArguments*/,
      72             :                                                               const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
      73             :     throw(css::uno::RuntimeException, std::exception)
      74             : {
      75           0 :     ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
      76           0 :     if ( aURL.Complete == CMD_UNO_SHOWSTARTMODULE )
      77             :     {
      78           0 :         nResult = css::frame::DispatchResultState::FAILURE;
      79           0 :         if (implts_isBackingModePossible ())
      80             :         {
      81           0 :             if (implts_establishBackingMode ())
      82           0 :                 nResult = css::frame::DispatchResultState::SUCCESS;
      83             :         }
      84             :     }
      85             : 
      86           0 :     implts_notifyResultListener(xListener, nResult, css::uno::Any());
      87           0 : }
      88             : 
      89           0 : css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
      90             :     throw(css::uno::RuntimeException, std::exception)
      91             : {
      92           0 :     return css::uno::Sequence< ::sal_Int16 >();
      93             : }
      94             : 
      95           0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
      96             :     throw(css::uno::RuntimeException, std::exception)
      97             : {
      98           0 :     return css::uno::Sequence< css::frame::DispatchInformation >();
      99             : }
     100             : 
     101           0 : void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     102             :                                                        const css::util::URL&                                     /*aURL*/     )
     103             :     throw(css::uno::RuntimeException, std::exception)
     104             : {
     105           0 : }
     106             : 
     107           0 : void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     108             :                                                           const css::util::URL&                                     /*aURL*/     )
     109             :     throw(css::uno::RuntimeException, std::exception)
     110             : {
     111           0 : }
     112             : 
     113           0 : bool StartModuleDispatcher::implts_isBackingModePossible()
     114             : {
     115           0 :     if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::STARTMODULE))
     116           0 :         return false;
     117             : 
     118             :     css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
     119           0 :         css::frame::Desktop::create( m_xContext ), css::uno::UNO_QUERY);
     120             : 
     121             :     FrameListAnalyzer aCheck(
     122             :         xDesktop,
     123             :         css::uno::Reference< css::frame::XFrame >(),
     124           0 :         FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
     125             : 
     126           0 :     bool  bIsPossible    = false;
     127           0 :     ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength ();
     128             : 
     129           0 :     if (
     130           0 :         ( ! aCheck.m_xBackingComponent.is ()) &&
     131             :         (   nVisibleFrames < 1              )
     132             :        )
     133             :     {
     134           0 :         bIsPossible = true;
     135             :     }
     136             : 
     137           0 :     return bIsPossible;
     138             : }
     139             : 
     140           0 : bool StartModuleDispatcher::implts_establishBackingMode()
     141             : {
     142           0 :     css::uno::Reference< css::frame::XDesktop2> xDesktop       = css::frame::Desktop::create( m_xContext );
     143           0 :     css::uno::Reference< css::frame::XFrame > xFrame           = xDesktop->findFrame(SPECIALTARGET_BLANK, 0);
     144           0 :     css::uno::Reference< css::awt::XWindow  > xContainerWindow = xFrame->getContainerWindow();
     145             : 
     146           0 :     css::uno::Reference< css::frame::XController > xStartModule = css::frame::StartModule::createWithParentWindow(m_xContext, xContainerWindow);
     147           0 :     css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
     148           0 :     xFrame->setComponent(xComponentWindow, xStartModule);
     149           0 :     xStartModule->attachFrame(xFrame);
     150           0 :     xContainerWindow->setVisible(sal_True);
     151             : 
     152           0 :     return true;
     153             : }
     154             : 
     155           0 : void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
     156             :                                                               ::sal_Int16                                                 nState   ,
     157             :                                                         const css::uno::Any&                                              aResult  )
     158             : {
     159           0 :     if ( ! xListener.is())
     160           0 :         return;
     161             : 
     162             :     css::frame::DispatchResultEvent aEvent(
     163             :         css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
     164             :         nState,
     165           0 :         aResult);
     166             : 
     167           0 :     xListener->dispatchFinished(aEvent);
     168             : }
     169             : 
     170             : } // namespace framework
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11