LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - ResourceManager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 82 88 93.2 %
Date: 2014-11-03 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         264 : class ResourceManager::MainViewContainer
      42             :     : public ::std::set<OUString>
      43             : {
      44             : public:
      45         264 :     MainViewContainer (void) {}
      46             : };
      47             : 
      48             : //===== ResourceManager =======================================================
      49             : 
      50         264 : 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         264 :       msCurrentMainViewURL()
      60             : {
      61         264 :     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
      62         264 :     if (xControllerManager.is())
      63             :     {
      64         264 :         mxConfigurationController = xControllerManager->getConfigurationController();
      65             : 
      66         264 :         if (mxConfigurationController.is())
      67             :         {
      68             :             uno::Reference<lang::XComponent> const xComppnent(
      69         264 :                     mxConfigurationController, UNO_QUERY_THROW);
      70         264 :             xComppnent->addEventListener(this);
      71         264 :             mxConfigurationController->addConfigurationChangeListener(
      72             :                 this,
      73             :                 FrameworkHelper::msResourceActivationRequestEvent,
      74         264 :                 makeAny(ResourceActivationRequestEvent));
      75         264 :             mxConfigurationController->addConfigurationChangeListener(
      76             :                 this,
      77             :                 FrameworkHelper::msResourceDeactivationRequestEvent,
      78         264 :                 makeAny(ResourceDeactivationRequestEvent));
      79             :         }
      80         264 :     }
      81         264 : }
      82             : 
      83         264 : ResourceManager::~ResourceManager (void)
      84             : {
      85         264 : }
      86             : 
      87        1056 : void ResourceManager::AddActiveMainView (
      88             :     const OUString& rsMainViewURL)
      89             : {
      90        1056 :     mpActiveMainViewContainer->insert(rsMainViewURL);
      91        1056 : }
      92             : 
      93        1532 : bool ResourceManager::IsResourceActive (
      94             :     const OUString& rsMainViewURL)
      95             : {
      96        1532 :     return (mpActiveMainViewContainer->find(rsMainViewURL) != mpActiveMainViewContainer->end());
      97             : }
      98             : 
      99           0 : void ResourceManager::SaveResourceState (void)
     100             : {
     101           0 : }
     102             : 
     103         264 : void SAL_CALL ResourceManager::disposing (void)
     104             : {
     105         264 :     if (mxConfigurationController.is())
     106             :     {
     107           0 :         mxConfigurationController->removeConfigurationChangeListener(this);
     108           0 :         mxConfigurationController = NULL;
     109             :     }
     110         264 : }
     111             : 
     112        2736 : void SAL_CALL ResourceManager::notifyConfigurationChange (
     113             :     const ConfigurationChangeEvent& rEvent)
     114             :     throw (RuntimeException, std::exception)
     115             : {
     116             :     OSL_ASSERT(rEvent.ResourceId.is());
     117             : 
     118        2736 :     sal_Int32 nEventType = 0;
     119        2736 :     rEvent.UserData >>= nEventType;
     120        2736 :     switch (nEventType)
     121             :     {
     122             :         case ResourceActivationRequestEvent:
     123        2736 :             if (rEvent.ResourceId->isBoundToURL(
     124             :                 FrameworkHelper::msCenterPaneURL,
     125        1368 :                 AnchorBindingMode_DIRECT))
     126             :             {
     127             :                 // A resource directly bound to the center pane has been
     128             :                 // requested.
     129        1104 :                 if (rEvent.ResourceId->getResourceTypePrefix().equals(
     130         736 :                     FrameworkHelper::msViewURLPrefix))
     131             :                 {
     132             :                     // The requested resource is a view.  Show or hide the
     133             :                     // resource managed by this ResourceManager accordingly.
     134             :                     HandleMainViewSwitch(
     135         264 :                         rEvent.ResourceId->getResourceURL(),
     136             :                         rEvent.Configuration,
     137         528 :                         true);
     138             :                 }
     139             :             }
     140        1000 :             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         264 :                 HandleResourceRequest(true, rEvent.Configuration);
     146             :             }
     147        1368 :             break;
     148             : 
     149             :         case ResourceDeactivationRequestEvent:
     150        1368 :             if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
     151             :             {
     152             :                 HandleMainViewSwitch(
     153             :                     OUString(),
     154             :                     rEvent.Configuration,
     155         264 :                     false);
     156             :             }
     157        1104 :             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         264 :                 HandleResourceRequest(false, rEvent.Configuration);
     163             :             }
     164        1368 :             break;
     165             :     }
     166        2736 : }
     167             : 
     168         528 : void ResourceManager::UpdateForMainViewShell (void)
     169             : {
     170         528 :     if (mxConfigurationController.is())
     171             :     {
     172         264 :         ConfigurationController::Lock aLock (mxConfigurationController);
     173             : 
     174         792 :         if (mpActiveMainViewContainer->find(msCurrentMainViewURL)
     175         792 :                != mpActiveMainViewContainer->end())
     176             :         {
     177             :             // Activate resource.
     178         264 :             mxConfigurationController->requestResourceActivation(
     179         264 :                 mxResourceId->getAnchor(),
     180         528 :                 ResourceActivationMode_ADD);
     181         264 :             mxConfigurationController->requestResourceActivation(
     182             :                 mxResourceId,
     183         264 :                 ResourceActivationMode_REPLACE);
     184             :         }
     185             :         else
     186             :         {
     187           0 :             mxConfigurationController->requestResourceDeactivation(mxResourceId);
     188         264 :         }
     189             :     }
     190         528 : }
     191             : 
     192         528 : void ResourceManager::HandleMainViewSwitch (
     193             :     const OUString& rsViewURL,
     194             :     const Reference<XConfiguration>& rxConfiguration,
     195             :     const bool bIsActivated)
     196             : {
     197             :     (void)rxConfiguration;
     198         528 :     if (bIsActivated)
     199         264 :         msCurrentMainViewURL = rsViewURL;
     200             :     else
     201         264 :         msCurrentMainViewURL = OUString();
     202         528 :     UpdateForMainViewShell();
     203         528 : }
     204             : 
     205         528 : void ResourceManager::HandleResourceRequest(
     206             :     bool bActivation,
     207             :     const Reference<XConfiguration>& rxConfiguration)
     208             : {
     209         528 :     Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
     210             :         FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
     211             :         FrameworkHelper::msViewURLPrefix,
     212         528 :         AnchorBindingMode_DIRECT);
     213         528 :     if (aCenterViews.getLength() == 1)
     214             :     {
     215         528 :         if (bActivation)
     216             :         {
     217         264 :             mpActiveMainViewContainer->insert(aCenterViews[0]->getResourceURL());
     218             :         }
     219             :         else
     220             :         {
     221             :             MainViewContainer::iterator iElement (
     222         264 :                 mpActiveMainViewContainer->find(aCenterViews[0]->getResourceURL()));
     223         264 :             if (iElement != mpActiveMainViewContainer->end())
     224         264 :                 mpActiveMainViewContainer->erase(iElement);
     225             :         }
     226         528 :     }
     227         528 : }
     228             : 
     229         688 : void SAL_CALL ResourceManager::disposing (
     230             :     const lang::EventObject& rEvent)
     231             :     throw (RuntimeException, std::exception)
     232             : {
     233        1376 :     if (mxConfigurationController.is()
     234         688 :         && rEvent.Source == mxConfigurationController)
     235             :     {
     236         264 :         SaveResourceState();
     237             :         // Without the configuration controller this class can do nothing.
     238         264 :         mxConfigurationController = NULL;
     239         264 :         dispose();
     240             :     }
     241         688 : }
     242             : 
     243         114 : } } // end of namespace sd::framework
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10