LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - ToolBarModule.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 72 98.6 %
Date: 2012-08-25 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 79 144 54.9 %

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

Generated by: LCOV version 1.10