LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - ToolBarModule.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 72 73 98.6 %
Date: 2014-11-03 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         212 : ToolBarModule::ToolBarModule (
      44             :     const Reference<frame::XController>& rxController)
      45             :     : ToolBarModuleInterfaceBase(m_aMutex),
      46             :       mxConfigurationController(),
      47             :       mpBase(NULL),
      48             :       mpToolBarManagerLock(),
      49         212 :       mbMainViewSwitchUpdatePending(false)
      50             : {
      51             :     // Tunnel through the controller to obtain a ViewShellBase.
      52         212 :     Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
      53         212 :     if (xTunnel.is())
      54             :     {
      55             :         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
      56         212 :             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
      57         212 :         if (pController != NULL)
      58         212 :             mpBase = pController->GetViewShellBase();
      59             :     }
      60             : 
      61         424 :     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
      62         212 :     if (xControllerManager.is())
      63             :     {
      64         212 :         mxConfigurationController = xControllerManager->getConfigurationController();
      65         212 :         if (mxConfigurationController.is())
      66             :         {
      67         212 :             mxConfigurationController->addConfigurationChangeListener(
      68             :                 this,
      69             :                 FrameworkHelper::msConfigurationUpdateStartEvent,
      70         212 :                 makeAny(gnConfigurationUpdateStartEvent));
      71         212 :             mxConfigurationController->addConfigurationChangeListener(
      72             :                 this,
      73             :                 FrameworkHelper::msConfigurationUpdateEndEvent,
      74         212 :                 makeAny(gnConfigurationUpdateEndEvent));
      75         212 :             mxConfigurationController->addConfigurationChangeListener(
      76             :                 this,
      77             :                 FrameworkHelper::msResourceActivationRequestEvent,
      78         212 :                 makeAny(gnResourceActivationRequestEvent));
      79         212 :             mxConfigurationController->addConfigurationChangeListener(
      80             :                 this,
      81             :                 FrameworkHelper::msResourceDeactivationRequestEvent,
      82         212 :                 makeAny(gnResourceDeactivationRequestEvent));
      83             :         }
      84         212 :     }
      85         212 : }
      86             : 
      87         424 : ToolBarModule::~ToolBarModule (void)
      88             : {
      89         424 : }
      90             : 
      91         212 : void SAL_CALL ToolBarModule::disposing (void)
      92             : {
      93         212 :     if (mxConfigurationController.is())
      94           0 :         mxConfigurationController->removeConfigurationChangeListener(this);
      95             : 
      96         212 :     mxConfigurationController = NULL;
      97         212 : }
      98             : 
      99        3176 : void SAL_CALL ToolBarModule::notifyConfigurationChange (
     100             :     const ConfigurationChangeEvent& rEvent)
     101             :     throw (RuntimeException, std::exception)
     102             : {
     103        3176 :     if (mxConfigurationController.is())
     104             :     {
     105        3176 :         sal_Int32 nEventType = 0;
     106        3176 :         rEvent.UserData >>= nEventType;
     107        3176 :         switch (nEventType)
     108             :         {
     109             :             case gnConfigurationUpdateStartEvent:
     110         584 :                 HandleUpdateStart();
     111         584 :                 break;
     112             : 
     113             :             case gnConfigurationUpdateEndEvent:
     114         584 :                 HandleUpdateEnd();
     115         584 :                 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        2008 :                 if ( ! mbMainViewSwitchUpdatePending)
     124        3492 :                     if (rEvent.ResourceId->getResourceURL().match(
     125        4656 :                         FrameworkHelper::msViewURLPrefix)
     126        4232 :                         && rEvent.ResourceId->isBoundToURL(
     127         740 :                             FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     128             :                     {
     129         424 :                         mbMainViewSwitchUpdatePending = true;
     130             :                     }
     131        2008 :                 break;
     132             :         }
     133             :     }
     134        3176 : }
     135             : 
     136         584 : void ToolBarModule::HandleUpdateStart (void)
     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         584 :     if (mpBase != NULL)
     143             :     {
     144         584 :         ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
     145         584 :         mpToolBarManagerLock.reset(new ToolBarManager::UpdateLock(pToolBarManager));
     146         584 :         pToolBarManager->LockViewShellManager();
     147             :     }
     148         584 : }
     149             : 
     150         584 : void ToolBarModule::HandleUpdateEnd (void)
     151             : {
     152         584 :     if (mbMainViewSwitchUpdatePending)
     153             :     {
     154         424 :         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         424 :         ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
     160             :         ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper (
     161         848 :             FrameworkHelper::Instance(*mpBase));
     162             :         ViewShell* pViewShell
     163         424 :             = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
     164         424 :         if (pViewShell != NULL)
     165             :         {
     166         212 :             pToolBarManager->MainViewShellChanged(*pViewShell);
     167             :             pToolBarManager->SelectionHasChanged(
     168             :                 *pViewShell,
     169         212 :                 *pViewShell->GetView());
     170         212 :             pToolBarManager->PreUpdate();
     171             :         }
     172             :         else
     173             :         {
     174         212 :             pToolBarManager->MainViewShellChanged(ViewShell::ST_NONE);
     175         212 :             pToolBarManager->PreUpdate();
     176         424 :         }
     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         584 :     mpToolBarManagerLock.reset();
     184         584 : }
     185             : 
     186         424 : void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent)
     187             :     throw (RuntimeException, std::exception)
     188             : {
     189         848 :     if (mxConfigurationController.is()
     190         424 :         && rEvent.Source == mxConfigurationController)
     191             :     {
     192             :         // Without the configuration controller this class can do nothing.
     193         212 :         mxConfigurationController = NULL;
     194         212 :         dispose();
     195             :     }
     196         424 : }
     197             : 
     198         114 : } } // end of namespace sd::framework
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10