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

Generated by: LCOV version 1.10