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

Generated by: LCOV version 1.10