LCOV - code coverage report
Current view: top level - libreoffice/framework/source/dispatch - startmoduledispatcher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-12-17 Functions: 0 17 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             : 
      21             : #include <dispatch/startmoduledispatcher.hxx>
      22             : 
      23             : #include <pattern/frame.hxx>
      24             : #include <threadhelp/readguard.hxx>
      25             : #include <threadhelp/writeguard.hxx>
      26             : #include <framework/framelistanalyzer.hxx>
      27             : #include <dispatchcommands.h>
      28             : #include <targets.h>
      29             : #include <services.h>
      30             : #include <general.h>
      31             : 
      32             : #include <com/sun/star/frame/XDesktop.hpp>
      33             : #include <com/sun/star/frame/XController.hpp>
      34             : #include <com/sun/star/frame/CommandGroup.hpp>
      35             : #include <com/sun/star/awt/XTopWindow.hpp>
      36             : #include "com/sun/star/beans/XFastPropertySet.hpp"
      37             : #include <com/sun/star/frame/XModuleManager.hpp>
      38             : 
      39             : #include <toolkit/helper/vclunohelper.hxx>
      40             : #include <vcl/window.hxx>
      41             : #include <vcl/svapp.hxx>
      42             : #include <osl/mutex.hxx>
      43             : #include <unotools/moduleoptions.hxx>
      44             : 
      45             : 
      46             : namespace framework{
      47             : 
      48             : #ifdef fpf
      49             :     #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
      50             : #endif
      51             : namespace fpf = ::framework::pattern::frame;
      52             : 
      53             : 
      54           0 : DEFINE_XINTERFACE_4(StartModuleDispatcher                                     ,
      55             :                     OWeakObject                                               ,
      56             :                     DIRECT_INTERFACE(css::lang::XTypeProvider                ),
      57             :                     DIRECT_INTERFACE(css::frame::XNotifyingDispatch          ),
      58             :                     DIRECT_INTERFACE(css::frame::XDispatch                   ),
      59             :                     DIRECT_INTERFACE(css::frame::XDispatchInformationProvider))
      60             : 
      61             : // Note: XStatusListener is an implementation detail. Hide it for scripting!
      62           0 : DEFINE_XTYPEPROVIDER_4(StartModuleDispatcher                   ,
      63             :                        css::lang::XTypeProvider                ,
      64             :                        css::frame::XDispatchInformationProvider,
      65             :                        css::frame::XNotifyingDispatch          ,
      66             :                        css::frame::XDispatch                   )
      67             : 
      68             : //-----------------------------------------------
      69           0 : StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR  ,
      70             :                                              const css::uno::Reference< css::frame::XFrame >&              xFrame ,
      71             :                                              const ::rtl::OUString&                                        sTarget)
      72           0 :     : ThreadHelpBase     (&Application::GetSolarMutex() )
      73             :     , ::cppu::OWeakObject(                              )
      74             :     , m_xSMGR            (xSMGR                         )
      75             :     , m_xOwner           (xFrame                        )
      76             :     , m_sDispatchTarget  (sTarget                       )
      77           0 :     , m_lStatusListener  (m_aLock.getShareableOslMutex())
      78             : {
      79           0 : }
      80             : 
      81             : //-----------------------------------------------
      82           0 : StartModuleDispatcher::~StartModuleDispatcher()
      83             : {
      84           0 : }
      85             : 
      86             : //-----------------------------------------------
      87           0 : void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL&                                  aURL      ,
      88             :                                               const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
      89             :     throw(css::uno::RuntimeException)
      90             : {
      91           0 :     dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
      92           0 : }
      93             : 
      94             : //-----------------------------------------------
      95           0 : void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL&                                             aURL      ,
      96             :                                                               const css::uno::Sequence< css::beans::PropertyValue >&            /*lArguments*/,
      97             :                                                               const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
      98             :     throw(css::uno::RuntimeException)
      99             : {
     100           0 :     ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
     101           0 :     if ( aURL.Complete == CMD_UNO_SHOWSTARTMODULE )
     102             :     {
     103           0 :         nResult = css::frame::DispatchResultState::FAILURE;
     104           0 :         if (implts_isBackingModePossible ())
     105             :         {
     106           0 :             if (implts_establishBackingMode ())
     107           0 :                 nResult = css::frame::DispatchResultState::SUCCESS;
     108             :         }
     109             :     }
     110             : 
     111           0 :     implts_notifyResultListener(xListener, nResult, css::uno::Any());
     112           0 : }
     113             : 
     114             : //-----------------------------------------------
     115           0 : css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
     116             :     throw(css::uno::RuntimeException)
     117             : {
     118           0 :     return css::uno::Sequence< ::sal_Int16 >();
     119             : }
     120             : 
     121             : //-----------------------------------------------
     122           0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
     123             :     throw(css::uno::RuntimeException)
     124             : {
     125           0 :     return css::uno::Sequence< css::frame::DispatchInformation >();
     126             : }
     127             : 
     128             : //-----------------------------------------------
     129           0 : void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     130             :                                                        const css::util::URL&                                     /*aURL*/     )
     131             :     throw(css::uno::RuntimeException)
     132             : {
     133           0 : }
     134             : 
     135             : //-----------------------------------------------
     136           0 : void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     137             :                                                           const css::util::URL&                                     /*aURL*/     )
     138             :     throw(css::uno::RuntimeException)
     139             : {
     140           0 : }
     141             : 
     142             : //-----------------------------------------------
     143           0 : ::sal_Bool StartModuleDispatcher::implts_isBackingModePossible ()
     144             : {
     145           0 :     if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE))
     146           0 :         return sal_False;
     147             : 
     148             :     // SAFE -> ----------------------------------
     149           0 :     ReadGuard aReadLock(m_aLock);
     150           0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
     151           0 :     aReadLock.unlock();
     152             :     // <- SAFE ----------------------------------
     153             : 
     154             :     css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
     155           0 :         xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY);
     156             : 
     157             :     FrameListAnalyzer aCheck(
     158             :         xDesktop,
     159             :         css::uno::Reference< css::frame::XFrame >(),
     160           0 :         FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
     161             : 
     162           0 :     ::sal_Bool  bIsPossible    = sal_False;
     163           0 :     ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength ();
     164             : 
     165           0 :     if (
     166           0 :         ( ! aCheck.m_xBackingComponent.is ()) &&
     167             :         (   nVisibleFrames < 1              )
     168             :        )
     169             :     {
     170           0 :         bIsPossible = sal_True;
     171             :     }
     172             : 
     173           0 :     return bIsPossible;
     174             : }
     175             : 
     176             : //-----------------------------------------------
     177           0 : ::sal_Bool StartModuleDispatcher::implts_establishBackingMode()
     178             : {
     179             :     // SAFE -> ----------------------------------
     180           0 :     ReadGuard aReadLock(m_aLock);
     181           0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     182           0 :     aReadLock.unlock();
     183             :     // <- SAFE ----------------------------------
     184             : 
     185           0 :     css::uno::Reference< css::frame::XFrame > xDesktop         (xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY);
     186           0 :     css::uno::Reference< css::frame::XFrame > xFrame           = xDesktop->findFrame (SPECIALTARGET_BLANK, 0);
     187           0 :     css::uno::Reference< css::awt::XWindow  > xContainerWindow = xFrame->getContainerWindow ();
     188             : 
     189           0 :     css::uno::Sequence< css::uno::Any > lArgs(1);
     190           0 :     lArgs[0] <<= xContainerWindow;
     191             : 
     192             :     css::uno::Reference< css::frame::XController > xStartModule(
     193           0 :         xSMGR->createInstanceWithArguments(SERVICENAME_STARTMODULE, lArgs),
     194           0 :         css::uno::UNO_QUERY_THROW);
     195             : 
     196           0 :     css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
     197           0 :     xFrame->setComponent(xComponentWindow, xStartModule);
     198           0 :     xStartModule->attachFrame(xFrame);
     199           0 :     xContainerWindow->setVisible(sal_True);
     200             : 
     201           0 :     return sal_True;
     202             : }
     203             : 
     204             : //-----------------------------------------------
     205           0 : void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
     206             :                                                               ::sal_Int16                                                 nState   ,
     207             :                                                         const css::uno::Any&                                              aResult  )
     208             : {
     209           0 :     if ( ! xListener.is())
     210           0 :         return;
     211             : 
     212             :     css::frame::DispatchResultEvent aEvent(
     213             :         css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
     214             :         nState,
     215           0 :         aResult);
     216             : 
     217           0 :     xListener->dispatchFinished(aEvent);
     218             : }
     219             : 
     220             : } // namespace framework
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10