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

Generated by: LCOV version 1.10