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

Generated by: LCOV version 1.10