LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - ToolBarModule.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 72 73 98.6 %
Date: 2015-06-13 12:38:46 Functions: 10 10 100.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 "ToolBarModule.hxx"
      21             : #include "ViewShellBase.hxx"
      22             : #include "DrawController.hxx"
      23             : #include "framework/FrameworkHelper.hxx"
      24             : #include "framework/ConfigurationController.hxx"
      25             : 
      26             : using namespace ::com::sun::star;
      27             : using namespace ::com::sun::star::uno;
      28             : using namespace ::com::sun::star::drawing::framework;
      29             : 
      30             : using ::sd::framework::FrameworkHelper;
      31             : 
      32             : namespace {
      33             :     static const sal_Int32 gnConfigurationUpdateStartEvent(0);
      34             :     static const sal_Int32 gnConfigurationUpdateEndEvent(1);
      35             :     static const sal_Int32 gnResourceActivationRequestEvent(2);
      36             :     static const sal_Int32 gnResourceDeactivationRequestEvent(3);
      37             : }
      38             : 
      39             : namespace sd { namespace framework {
      40             : 
      41             : //===== ToolBarModule =========================================================
      42             : 
      43         127 : ToolBarModule::ToolBarModule (
      44             :     const Reference<frame::XController>& rxController)
      45             :     : ToolBarModuleInterfaceBase(m_aMutex),
      46             :       mxConfigurationController(),
      47             :       mpBase(NULL),
      48             :       mpToolBarManagerLock(),
      49         127 :       mbMainViewSwitchUpdatePending(false)
      50             : {
      51             :     // Tunnel through the controller to obtain a ViewShellBase.
      52         127 :     Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
      53         127 :     if (xTunnel.is())
      54             :     {
      55             :         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
      56         127 :             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
      57         127 :         if (pController != NULL)
      58         127 :             mpBase = pController->GetViewShellBase();
      59             :     }
      60             : 
      61         254 :     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
      62         127 :     if (xControllerManager.is())
      63             :     {
      64         127 :         mxConfigurationController = xControllerManager->getConfigurationController();
      65         127 :         if (mxConfigurationController.is())
      66             :         {
      67         127 :             mxConfigurationController->addConfigurationChangeListener(
      68             :                 this,
      69             :                 FrameworkHelper::msConfigurationUpdateStartEvent,
      70         127 :                 makeAny(gnConfigurationUpdateStartEvent));
      71         127 :             mxConfigurationController->addConfigurationChangeListener(
      72             :                 this,
      73             :                 FrameworkHelper::msConfigurationUpdateEndEvent,
      74         127 :                 makeAny(gnConfigurationUpdateEndEvent));
      75         127 :             mxConfigurationController->addConfigurationChangeListener(
      76             :                 this,
      77             :                 FrameworkHelper::msResourceActivationRequestEvent,
      78         127 :                 makeAny(gnResourceActivationRequestEvent));
      79         127 :             mxConfigurationController->addConfigurationChangeListener(
      80             :                 this,
      81             :                 FrameworkHelper::msResourceDeactivationRequestEvent,
      82         127 :                 makeAny(gnResourceDeactivationRequestEvent));
      83             :         }
      84         127 :     }
      85         127 : }
      86             : 
      87         254 : ToolBarModule::~ToolBarModule()
      88             : {
      89         254 : }
      90             : 
      91         127 : void SAL_CALL ToolBarModule::disposing()
      92             : {
      93         127 :     if (mxConfigurationController.is())
      94           0 :         mxConfigurationController->removeConfigurationChangeListener(this);
      95             : 
      96         127 :     mxConfigurationController = NULL;
      97         127 : }
      98             : 
      99        1988 : void SAL_CALL ToolBarModule::notifyConfigurationChange (
     100             :     const ConfigurationChangeEvent& rEvent)
     101             :     throw (RuntimeException, std::exception)
     102             : {
     103        1988 :     if (mxConfigurationController.is())
     104             :     {
     105        1988 :         sal_Int32 nEventType = 0;
     106        1988 :         rEvent.UserData >>= nEventType;
     107        1988 :         switch (nEventType)
     108             :         {
     109             :             case gnConfigurationUpdateStartEvent:
     110         355 :                 HandleUpdateStart();
     111         355 :                 break;
     112             : 
     113             :             case gnConfigurationUpdateEndEvent:
     114         355 :                 HandleUpdateEnd();
     115         355 :                 break;
     116             : 
     117             :             case gnResourceActivationRequestEvent:
     118             :             case gnResourceDeactivationRequestEvent:
     119             :                 // Remember the request for the activation or deactivation
     120             :                 // of the center pane view.  When that happens then on end
     121             :                 // of the next configuration update the set of visible tool
     122             :                 // bars will be updated.
     123        1278 :                 if ( ! mbMainViewSwitchUpdatePending)
     124        2169 :                     if (rEvent.ResourceId->getResourceURL().match(
     125        2892 :                         FrameworkHelper::msViewURLPrefix)
     126        2637 :                         && rEvent.ResourceId->isBoundToURL(
     127         468 :                             FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     128             :                     {
     129         260 :                         mbMainViewSwitchUpdatePending = true;
     130             :                     }
     131        1278 :                 break;
     132             :         }
     133             :     }
     134        1988 : }
     135             : 
     136         355 : void ToolBarModule::HandleUpdateStart()
     137             : {
     138             :     // Lock the ToolBarManager and tell it to lock the ViewShellManager as
     139             :     // well.  This way the ToolBarManager can optimize the releasing of
     140             :     // locks and arranging of updates of both tool bars and the view shell
     141             :     // stack.
     142         355 :     if (mpBase != NULL)
     143             :     {
     144         355 :         ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
     145         355 :         mpToolBarManagerLock.reset(new ToolBarManager::UpdateLock(pToolBarManager));
     146         355 :         pToolBarManager->LockViewShellManager();
     147             :     }
     148         355 : }
     149             : 
     150         355 : void ToolBarModule::HandleUpdateEnd()
     151             : {
     152         355 :     if (mbMainViewSwitchUpdatePending)
     153             :     {
     154         260 :         mbMainViewSwitchUpdatePending = false;
     155             :         // Update the set of visible tool bars and deactivate those that are
     156             :         // no longer visible.  This is done before the old view shell is
     157             :         // destroyed in order to avoid unnecessary updates of those tool
     158             :         // bars.
     159         260 :         ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
     160             :         ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper (
     161         520 :             FrameworkHelper::Instance(*mpBase));
     162             :         ViewShell* pViewShell
     163         260 :             = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
     164         260 :         if (pViewShell != NULL)
     165             :         {
     166         133 :             pToolBarManager->MainViewShellChanged(*pViewShell);
     167             :             pToolBarManager->SelectionHasChanged(
     168             :                 *pViewShell,
     169         133 :                 *pViewShell->GetView());
     170         133 :             pToolBarManager->PreUpdate();
     171             :         }
     172             :         else
     173             :         {
     174         127 :             pToolBarManager->MainViewShellChanged(ViewShell::ST_NONE);
     175         127 :             pToolBarManager->PreUpdate();
     176         260 :         }
     177             :     }
     178             : 
     179             :     // Releasing the update lock of the ToolBarManager  will let the
     180             :     // ToolBarManager with the help of the ViewShellManager take care of
     181             :     // updating tool bars and view shell with the minimal amount of
     182             :     // shell stack modifications and tool bar updates.
     183         355 :     mpToolBarManagerLock.reset();
     184         355 : }
     185             : 
     186         254 : void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent)
     187             :     throw (RuntimeException, std::exception)
     188             : {
     189         508 :     if (mxConfigurationController.is()
     190         254 :         && rEvent.Source == mxConfigurationController)
     191             :     {
     192             :         // Without the configuration controller this class can do nothing.
     193         127 :         mxConfigurationController = NULL;
     194         127 :         dispose();
     195             :     }
     196         254 : }
     197             : 
     198          66 : } } // end of namespace sd::framework
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11