LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - CenterViewFocusModule.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 62 63 98.4 %
Date: 2014-11-03 Functions: 9 9 100.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             : #include "CenterViewFocusModule.hxx"
      21             : 
      22             : #include "framework/ConfigurationController.hxx"
      23             : #include "framework/FrameworkHelper.hxx"
      24             : #include "framework/ViewShellWrapper.hxx"
      25             : 
      26             : #include "DrawController.hxx"
      27             : #include "ViewShellBase.hxx"
      28             : #include "ViewShellManager.hxx"
      29             : #include "strings.hrc"
      30             : #include "sdresid.hxx"
      31             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      32             : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
      33             : 
      34             : #include <toolkit/awt/vclxdevice.hxx>
      35             : #include <sfx2/viewfrm.hxx>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::drawing::framework;
      40             : 
      41             : using ::sd::framework::FrameworkHelper;
      42             : 
      43             : namespace sd { namespace framework {
      44             : 
      45             : //===== CenterViewFocusModule ====================================================
      46             : 
      47         212 : CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController)
      48             :     : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex),
      49             :       mbValid(false),
      50             :       mxConfigurationController(),
      51             :       mpBase(NULL),
      52         212 :       mbNewViewCreated(false)
      53             : {
      54         212 :     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
      55         212 :     if (xControllerManager.is())
      56             :     {
      57         212 :         mxConfigurationController = xControllerManager->getConfigurationController();
      58             : 
      59             :         // Tunnel through the controller to obtain a ViewShellBase.
      60         212 :         Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
      61         212 :         if (xTunnel.is())
      62             :         {
      63             :             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
      64         212 :                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
      65         212 :             if (pController != NULL)
      66         212 :                 mpBase = pController->GetViewShellBase();
      67             :         }
      68             : 
      69             :         // Check, if all required objects do exist.
      70         212 :         if (mxConfigurationController.is() && mpBase!=NULL)
      71             :         {
      72         212 :             mbValid = true;
      73         212 :         }
      74             :     }
      75             : 
      76         212 :     if (mbValid)
      77             :     {
      78         212 :         mxConfigurationController->addConfigurationChangeListener(
      79             :             this,
      80             :             FrameworkHelper::msConfigurationUpdateEndEvent,
      81         212 :             Any());
      82         212 :         mxConfigurationController->addConfigurationChangeListener(
      83             :             this,
      84             :             FrameworkHelper::msResourceActivationEvent,
      85         212 :             Any());
      86         212 :     }
      87         212 : }
      88             : 
      89         424 : CenterViewFocusModule::~CenterViewFocusModule (void)
      90             : {
      91         424 : }
      92             : 
      93         212 : void SAL_CALL CenterViewFocusModule::disposing (void)
      94             : {
      95         212 :     if (mxConfigurationController.is())
      96           0 :         mxConfigurationController->removeConfigurationChangeListener(this);
      97             : 
      98         212 :     mbValid = false;
      99         212 :     mxConfigurationController = NULL;
     100         212 :     mpBase = NULL;
     101         212 : }
     102             : 
     103        1524 : void SAL_CALL CenterViewFocusModule::notifyConfigurationChange (
     104             :     const ConfigurationChangeEvent& rEvent)
     105             :     throw (RuntimeException, std::exception)
     106             : {
     107        1524 :     if (mbValid)
     108             :     {
     109        1524 :         if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent))
     110             :         {
     111         584 :             HandleNewView(rEvent.Configuration);
     112             :         }
     113         940 :         else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent))
     114             :         {
     115         940 :             if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
     116         338 :                 mbNewViewCreated = true;
     117             :         }
     118             :     }
     119        1524 : }
     120             : 
     121         584 : void CenterViewFocusModule::HandleNewView (
     122             :     const Reference<XConfiguration>& rxConfiguration)
     123             : {
     124         584 :     if (mbNewViewCreated)
     125             :     {
     126         338 :         mbNewViewCreated = false;
     127             :         // Make the center pane the active one.  Tunnel through the
     128             :         // controller to obtain a ViewShell pointer.
     129             : 
     130         338 :         Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
     131             :             FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
     132             :             FrameworkHelper::msViewURLPrefix,
     133         338 :             AnchorBindingMode_DIRECT));
     134         676 :         Reference<XView> xView;
     135         338 :         if (xViewIds.getLength() > 0)
     136         676 :             xView = Reference<XView>(
     137         676 :                 mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
     138         676 :         Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY);
     139         338 :         if (xTunnel.is() && mpBase!=NULL)
     140             :         {
     141             :             ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>(
     142         338 :                 xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId()));
     143         338 :             if (pViewShellWrapper != NULL)
     144             :             {
     145         338 :                 ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
     146         338 :                 if (pViewShell.get() != NULL)
     147         338 :                     mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
     148             :             }
     149         338 :         }
     150             :     }
     151         584 : }
     152             : 
     153         424 : void SAL_CALL CenterViewFocusModule::disposing (
     154             :     const lang::EventObject& rEvent)
     155             :     throw (RuntimeException, std::exception)
     156             : {
     157         424 :     if (mxConfigurationController.is())
     158         212 :         if (rEvent.Source == mxConfigurationController)
     159             :         {
     160         212 :             mbValid = false;
     161         212 :             mxConfigurationController = NULL;
     162         212 :             mpBase = NULL;
     163             :         }
     164         424 : }
     165             : 
     166         114 : } } // end of namespace sd::framework
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10