LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - ShellStackGuard.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 42 52 80.8 %
Date: 2014-11-03 Functions: 9 11 81.8 %
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 "ShellStackGuard.hxx"
      21             : 
      22             : #include "framework/ConfigurationController.hxx"
      23             : #include "framework/FrameworkHelper.hxx"
      24             : 
      25             : #include "DrawController.hxx"
      26             : #include "ViewShellBase.hxx"
      27             : #include <sfx2/printer.hxx>
      28             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      29             : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::drawing::framework;
      34             : 
      35             : using ::sd::framework::FrameworkHelper;
      36             : 
      37             : namespace sd { namespace framework {
      38             : 
      39             : //===== CenterViewFocusModule ====================================================
      40             : 
      41          52 : ShellStackGuard::ShellStackGuard (Reference<frame::XController>& rxController)
      42             :     : ShellStackGuardInterfaceBase(m_aMutex),
      43             :       mxConfigurationController(),
      44             :       mpBase(NULL),
      45             :       mpUpdateLock(),
      46          52 :       maPrinterPollingTimer()
      47             : {
      48          52 :     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
      49          52 :     if (xControllerManager.is())
      50             :     {
      51          52 :         mxConfigurationController = xControllerManager->getConfigurationController();
      52             : 
      53             :         // Tunnel through the controller to obtain a ViewShellBase.
      54          52 :         Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
      55          52 :         if (xTunnel.is())
      56             :         {
      57             :             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
      58          52 :                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
      59          52 :             if (pController != NULL)
      60          52 :                 mpBase = pController->GetViewShellBase();
      61          52 :         }
      62             :     }
      63             : 
      64          52 :     if (mxConfigurationController.is())
      65             :     {
      66             :         // Listen for update starts so that the following update can be
      67             :         // prevented in case of a printing printer.
      68          52 :         mxConfigurationController->addConfigurationChangeListener(
      69             :             this,
      70             :             FrameworkHelper::msConfigurationUpdateStartEvent,
      71          52 :             Any());
      72             : 
      73             :         // Prepare the printer polling.
      74          52 :         maPrinterPollingTimer.SetTimeoutHdl(LINK(this,ShellStackGuard,TimeoutHandler));
      75          52 :         maPrinterPollingTimer.SetTimeout(300);
      76          52 :     }
      77          52 : }
      78             : 
      79         104 : ShellStackGuard::~ShellStackGuard (void)
      80             : {
      81         104 : }
      82             : 
      83          52 : void SAL_CALL ShellStackGuard::disposing (void)
      84             : {
      85          52 :     if (mxConfigurationController.is())
      86           0 :         mxConfigurationController->removeConfigurationChangeListener(this);
      87             : 
      88          52 :     mxConfigurationController = NULL;
      89          52 :     mpBase = NULL;
      90          52 : }
      91             : 
      92         162 : void SAL_CALL ShellStackGuard::notifyConfigurationChange (
      93             :     const ConfigurationChangeEvent& rEvent)
      94             :     throw (RuntimeException, std::exception)
      95             : {
      96         162 :     if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateStartEvent))
      97             :     {
      98         162 :         if (mpUpdateLock.get() == NULL && IsPrinting())
      99             :         {
     100             :             // Prevent configuration updates while the printer is printing.
     101           0 :             mpUpdateLock.reset(new ConfigurationController::Lock(mxConfigurationController));
     102             : 
     103             :             // Start polling for the printer having finished printing.
     104           0 :             maPrinterPollingTimer.Start();
     105             :         }
     106             :     }
     107         162 : }
     108             : 
     109          52 : void SAL_CALL ShellStackGuard::disposing (
     110             :     const lang::EventObject& rEvent)
     111             :     throw (RuntimeException, std::exception)
     112             : {
     113          52 :     if (mxConfigurationController.is())
     114          52 :         if (rEvent.Source == mxConfigurationController)
     115             :         {
     116          52 :             mxConfigurationController = NULL;
     117          52 :             mpBase = NULL;
     118             :         }
     119          52 : }
     120             : 
     121           0 : IMPL_LINK(ShellStackGuard, TimeoutHandler, Timer*, pTimer)
     122             : {
     123             : #ifdef DEBUG
     124             :     OSL_ASSERT(pTimer==&maPrinterPollingTimer);
     125             : #else
     126             :     (void)pTimer;
     127             : #endif
     128           0 :     if (mpUpdateLock.get() != NULL)
     129             :     {
     130           0 :         if ( ! IsPrinting())
     131             :         {
     132             :             // Printing finished.  Release the update lock.
     133           0 :             mpUpdateLock.reset();
     134             :         }
     135             :         else
     136             :         {
     137             :             // Wait long for the printing to finish.
     138           0 :             maPrinterPollingTimer.Start();
     139             :         }
     140             :     }
     141             : 
     142           0 :     return 0;
     143             : }
     144             : 
     145         162 : bool ShellStackGuard::IsPrinting (void) const
     146             : {
     147         162 :     if (mpBase != NULL)
     148             :     {
     149         162 :         SfxPrinter* pPrinter = mpBase->GetPrinter();
     150         162 :         if (pPrinter != NULL
     151         162 :             && pPrinter->IsPrinting())
     152             :         {
     153           0 :             return true;
     154             :         }
     155             :     }
     156             : 
     157         162 :     return false;
     158             : }
     159             : 
     160         114 : } } // end of namespace sd::framework
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10