LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ContextChangeBroadcaster.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 37 40 92.5 %
Date: 2014-04-11 Functions: 8 8 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             : #include <sfx2/sidebar/ContextChangeBroadcaster.hxx>
      20             : #include <sfx2/sidebar/EnumContext.hxx>
      21             : #include <com/sun/star/ui/ContextChangeEventObject.hpp>
      22             : #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
      23             : #include <com/sun/star/frame/ModuleManager.hpp>
      24             : #include <comphelper/processfactory.hxx>
      25             : 
      26             : 
      27             : using ::rtl::OUString;
      28             : using namespace css;
      29             : using namespace cssu;
      30             : 
      31             : namespace sfx2 { namespace sidebar {
      32             : 
      33             : 
      34       15456 : ContextChangeBroadcaster::ContextChangeBroadcaster (void)
      35             :     : msContextName(),
      36       15456 :       mbIsBroadcasterEnabled(true)
      37             : {
      38       15456 : }
      39             : 
      40             : 
      41             : 
      42       14988 : ContextChangeBroadcaster::~ContextChangeBroadcaster (void)
      43             : {
      44       14988 : }
      45             : 
      46             : 
      47             : 
      48             : 
      49        2436 : void ContextChangeBroadcaster::Initialize (const ::rtl::OUString& rsContextName)
      50             : {
      51        2436 :     msContextName = rsContextName;
      52        2436 : }
      53             : 
      54             : 
      55             : 
      56             : 
      57       12043 : void ContextChangeBroadcaster::Activate (const cssu::Reference<css::frame::XFrame>& rxFrame)
      58             : {
      59       12043 :     if (msContextName.getLength() > 0)
      60        2107 :         BroadcastContextChange(rxFrame, GetModuleName(rxFrame), msContextName);
      61       12043 : }
      62             : 
      63             : 
      64             : 
      65             : 
      66        6456 : void ContextChangeBroadcaster::Deactivate (const cssu::Reference<css::frame::XFrame>& rxFrame)
      67             : {
      68        6456 :     if (msContextName.getLength() > 0)
      69             :     {
      70             :         BroadcastContextChange(
      71             :             rxFrame,
      72             :             GetModuleName(rxFrame),
      73        2438 :             EnumContext::GetContextName(EnumContext::Context_Default));
      74             :     }
      75        6456 : }
      76             : 
      77             : 
      78             : 
      79             : 
      80         666 : bool ContextChangeBroadcaster::SetBroadcasterEnabled (const bool bIsEnabled)
      81             : {
      82         666 :     const bool bWasEnabled (mbIsBroadcasterEnabled);
      83         666 :     mbIsBroadcasterEnabled = bIsEnabled;
      84         666 :     return bWasEnabled;
      85             : }
      86             : 
      87             : 
      88             : 
      89             : 
      90        4545 : void ContextChangeBroadcaster::BroadcastContextChange (
      91             :     const cssu::Reference<css::frame::XFrame>& rxFrame,
      92             :     const ::rtl::OUString& rsModuleName,
      93             :     const ::rtl::OUString& rsContextName)
      94             : {
      95        4545 :     if ( ! mbIsBroadcasterEnabled)
      96        2709 :         return;
      97             : 
      98        4212 :     if (rsContextName.getLength() == 0)
      99           0 :         return;
     100             : 
     101        4212 :     if ( ! rxFrame.is() || ! rxFrame->getController().is())
     102             :     {
     103             :         // Frame is (probably) being deleted.  Broadcasting context
     104             :         // changes is not necessary anymore.
     105        2043 :         return;
     106             :     }
     107             : 
     108             :     const css::ui::ContextChangeEventObject aEvent(
     109        2169 :         rxFrame->getController(),
     110             :         rsModuleName,
     111        2169 :         rsContextName);
     112             : 
     113             :     cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
     114             :         css::ui::ContextChangeEventMultiplexer::get(
     115        4338 :             ::comphelper::getProcessComponentContext()));
     116        2169 :     if (xMultiplexer.is())
     117        4338 :         xMultiplexer->broadcastContextChangeEvent(aEvent, rxFrame->getController());
     118             : }
     119             : 
     120             : 
     121             : 
     122             : 
     123        4545 : OUString ContextChangeBroadcaster::GetModuleName (const cssu::Reference<css::frame::XFrame>& rxFrame)
     124             : {
     125        4545 :     if ( ! rxFrame.is() || ! rxFrame->getController().is())
     126        2250 :         return OUString();
     127             :     try
     128             :     {
     129        2295 :         const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext() );
     130        4590 :         const Reference<frame::XModuleManager> xModuleManager  = frame::ModuleManager::create( xContext );
     131        4590 :         return xModuleManager->identify(rxFrame);
     132             :     }
     133           0 :     catch (const Exception&)
     134             :     {
     135             :         OSL_ENSURE(false, "can not determine module name");
     136             :     }
     137           0 :     return OUString();
     138             : }
     139             : 
     140             : 
     141             : 
     142             : } } // end of namespace ::sd::sidebar
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10