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

Generated by: LCOV version 1.10