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

Generated by: LCOV version 1.10