LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - ResourceManager.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 83 88 94.3 %
Date: 2015-06-13 12:38:46 Functions: 14 16 87.5 %
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 "ResourceManager.hxx"
      21             : 
      22             : #include "framework/FrameworkHelper.hxx"
      23             : #include "framework/ConfigurationController.hxx"
      24             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      25             : 
      26             : #include <set>
      27             : 
      28             : using namespace css;
      29             : using namespace css::uno;
      30             : using namespace css::drawing::framework;
      31             : 
      32             : using ::sd::framework::FrameworkHelper;
      33             : 
      34             : namespace {
      35             :     static const sal_Int32 ResourceActivationRequestEvent = 0;
      36             :     static const sal_Int32 ResourceDeactivationRequestEvent = 1;
      37             : }
      38             : 
      39             : namespace sd { namespace framework {
      40             : 
      41         168 : class ResourceManager::MainViewContainer
      42             :     : public ::std::set<OUString>
      43             : {
      44             : public:
      45         168 :     MainViewContainer() {}
      46             : };
      47             : 
      48             : //===== ResourceManager =======================================================
      49             : 
      50         168 : ResourceManager::ResourceManager (
      51             :     const Reference<frame::XController>& rxController,
      52             :     const Reference<XResourceId>& rxResourceId)
      53             :     : ResourceManagerInterfaceBase(MutexOwner::maMutex),
      54             :       mxConfigurationController(),
      55           0 :       mpActiveMainViewContainer(new MainViewContainer()),
      56             :       mxResourceId(rxResourceId),
      57             :       mxMainViewAnchorId(FrameworkHelper::CreateResourceId(
      58             :           FrameworkHelper::msCenterPaneURL)),
      59         168 :       msCurrentMainViewURL()
      60             : {
      61         168 :     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
      62         168 :     if (xControllerManager.is())
      63             :     {
      64         168 :         mxConfigurationController = xControllerManager->getConfigurationController();
      65             : 
      66         168 :         if (mxConfigurationController.is())
      67             :         {
      68             :             uno::Reference<lang::XComponent> const xComppnent(
      69         168 :                     mxConfigurationController, UNO_QUERY_THROW);
      70         168 :             xComppnent->addEventListener(this);
      71         168 :             mxConfigurationController->addConfigurationChangeListener(
      72             :                 this,
      73             :                 FrameworkHelper::msResourceActivationRequestEvent,
      74         168 :                 makeAny(ResourceActivationRequestEvent));
      75         168 :             mxConfigurationController->addConfigurationChangeListener(
      76             :                 this,
      77             :                 FrameworkHelper::msResourceDeactivationRequestEvent,
      78         168 :                 makeAny(ResourceDeactivationRequestEvent));
      79             :         }
      80         168 :     }
      81         168 : }
      82             : 
      83         168 : ResourceManager::~ResourceManager()
      84             : {
      85         168 : }
      86             : 
      87         671 : void ResourceManager::AddActiveMainView (
      88             :     const OUString& rsMainViewURL)
      89             : {
      90         671 :     mpActiveMainViewContainer->insert(rsMainViewURL);
      91         671 : }
      92             : 
      93         967 : bool ResourceManager::IsResourceActive (
      94             :     const OUString& rsMainViewURL)
      95             : {
      96         967 :     return (mpActiveMainViewContainer->find(rsMainViewURL) != mpActiveMainViewContainer->end());
      97             : }
      98             : 
      99           0 : void ResourceManager::SaveResourceState()
     100             : {
     101           0 : }
     102             : 
     103         168 : void SAL_CALL ResourceManager::disposing()
     104             : {
     105         168 :     if (mxConfigurationController.is())
     106             :     {
     107           0 :         mxConfigurationController->removeConfigurationChangeListener(this);
     108           0 :         mxConfigurationController = NULL;
     109             :     }
     110         168 : }
     111             : 
     112        1868 : void SAL_CALL ResourceManager::notifyConfigurationChange (
     113             :     const ConfigurationChangeEvent& rEvent)
     114             :     throw (RuntimeException, std::exception)
     115             : {
     116             :     OSL_ASSERT(rEvent.ResourceId.is());
     117             : 
     118        1868 :     sal_Int32 nEventType = 0;
     119        1868 :     rEvent.UserData >>= nEventType;
     120        1868 :     switch (nEventType)
     121             :     {
     122             :         case ResourceActivationRequestEvent:
     123        1868 :             if (rEvent.ResourceId->isBoundToURL(
     124             :                 FrameworkHelper::msCenterPaneURL,
     125         934 :                 AnchorBindingMode_DIRECT))
     126             :             {
     127             :                 // A resource directly bound to the center pane has been
     128             :                 // requested.
     129         786 :                 if (rEvent.ResourceId->getResourceTypePrefix().equals(
     130         524 :                     FrameworkHelper::msViewURLPrefix))
     131             :                 {
     132             :                     // The requested resource is a view.  Show or hide the
     133             :                     // resource managed by this ResourceManager accordingly.
     134             :                     HandleMainViewSwitch(
     135         180 :                         rEvent.ResourceId->getResourceURL(),
     136             :                         rEvent.Configuration,
     137         360 :                         true);
     138             :                 }
     139             :             }
     140         672 :             else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
     141             :             {
     142             :                 // The resource managed by this ResourceManager has been
     143             :                 // explicitly been requested (maybe by us).  Remember this
     144             :                 // setting.
     145         169 :                 HandleResourceRequest(true, rEvent.Configuration);
     146             :             }
     147         934 :             break;
     148             : 
     149             :         case ResourceDeactivationRequestEvent:
     150         934 :             if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
     151             :             {
     152             :                 HandleMainViewSwitch(
     153             :                     OUString(),
     154             :                     rEvent.Configuration,
     155         168 :                     false);
     156             :             }
     157         766 :             else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
     158             :             {
     159             :                 // The resource managed by this ResourceManager has been
     160             :                 // explicitly been requested to be hidden (maybe by us).
     161             :                 // Remember this setting.
     162         169 :                 HandleResourceRequest(false, rEvent.Configuration);
     163             :             }
     164         934 :             break;
     165             :     }
     166        1868 : }
     167             : 
     168         348 : void ResourceManager::UpdateForMainViewShell()
     169             : {
     170         348 :     if (mxConfigurationController.is())
     171             :     {
     172         180 :         ConfigurationController::Lock aLock (mxConfigurationController);
     173             : 
     174         540 :         if (mpActiveMainViewContainer->find(msCurrentMainViewURL)
     175         540 :                != mpActiveMainViewContainer->end())
     176             :         {
     177             :             // Activate resource.
     178         177 :             mxConfigurationController->requestResourceActivation(
     179         177 :                 mxResourceId->getAnchor(),
     180         354 :                 ResourceActivationMode_ADD);
     181         177 :             mxConfigurationController->requestResourceActivation(
     182             :                 mxResourceId,
     183         177 :                 ResourceActivationMode_REPLACE);
     184             :         }
     185             :         else
     186             :         {
     187           3 :             mxConfigurationController->requestResourceDeactivation(mxResourceId);
     188         180 :         }
     189             :     }
     190         348 : }
     191             : 
     192         348 : void ResourceManager::HandleMainViewSwitch (
     193             :     const OUString& rsViewURL,
     194             :     const Reference<XConfiguration>& rxConfiguration,
     195             :     const bool bIsActivated)
     196             : {
     197             :     (void)rxConfiguration;
     198         348 :     if (bIsActivated)
     199         180 :         msCurrentMainViewURL = rsViewURL;
     200             :     else
     201         168 :         msCurrentMainViewURL.clear();
     202         348 :     UpdateForMainViewShell();
     203         348 : }
     204             : 
     205         338 : void ResourceManager::HandleResourceRequest(
     206             :     bool bActivation,
     207             :     const Reference<XConfiguration>& rxConfiguration)
     208             : {
     209         338 :     Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
     210             :         FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
     211             :         FrameworkHelper::msViewURLPrefix,
     212         338 :         AnchorBindingMode_DIRECT);
     213         338 :     if (aCenterViews.getLength() == 1)
     214             :     {
     215         338 :         if (bActivation)
     216             :         {
     217         169 :             mpActiveMainViewContainer->insert(aCenterViews[0]->getResourceURL());
     218             :         }
     219             :         else
     220             :         {
     221             :             MainViewContainer::iterator iElement (
     222         169 :                 mpActiveMainViewContainer->find(aCenterViews[0]->getResourceURL()));
     223         169 :             if (iElement != mpActiveMainViewContainer->end())
     224         167 :                 mpActiveMainViewContainer->erase(iElement);
     225             :         }
     226         338 :     }
     227         338 : }
     228             : 
     229         422 : void SAL_CALL ResourceManager::disposing (
     230             :     const lang::EventObject& rEvent)
     231             :     throw (RuntimeException, std::exception)
     232             : {
     233         844 :     if (mxConfigurationController.is()
     234         422 :         && rEvent.Source == mxConfigurationController)
     235             :     {
     236         168 :         SaveResourceState();
     237             :         // Without the configuration controller this class can do nothing.
     238         168 :         mxConfigurationController = NULL;
     239         168 :         dispose();
     240             :     }
     241         422 : }
     242             : 
     243          66 : } } // end of namespace sd::framework
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11