LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ContextChangeBroadcaster.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 37 40 92.5 %
Date: 2014-11-03 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 <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 css::uno;
      30             : 
      31             : namespace sfx2 { namespace sidebar {
      32             : 
      33             : 
      34       40337 : ContextChangeBroadcaster::ContextChangeBroadcaster (void)
      35             :     : msContextName(),
      36       40337 :       mbIsBroadcasterEnabled(true)
      37             : {
      38       40337 : }
      39             : 
      40             : 
      41             : 
      42       39751 : ContextChangeBroadcaster::~ContextChangeBroadcaster (void)
      43             : {
      44       39751 : }
      45             : 
      46             : 
      47             : 
      48             : 
      49        6588 : void ContextChangeBroadcaster::Initialize (const ::rtl::OUString& rsContextName)
      50             : {
      51        6588 :     msContextName = rsContextName;
      52        6588 : }
      53             : 
      54             : 
      55             : 
      56             : 
      57       32282 : void ContextChangeBroadcaster::Activate (const css::uno::Reference<css::frame::XFrame>& rxFrame)
      58             : {
      59       32282 :     if (msContextName.getLength() > 0)
      60        5630 :         BroadcastContextChange(rxFrame, GetModuleName(rxFrame), msContextName);
      61       32282 : }
      62             : 
      63             : 
      64             : 
      65             : 
      66       21991 : void ContextChangeBroadcaster::Deactivate (const css::uno::Reference<css::frame::XFrame>& rxFrame)
      67             : {
      68       21991 :     if (msContextName.getLength() > 0)
      69             :     {
      70             :         BroadcastContextChange(
      71             :             rxFrame,
      72             :             GetModuleName(rxFrame),
      73        6518 :             EnumContext::GetContextName(EnumContext::Context_Default));
      74             :     }
      75       21991 : }
      76             : 
      77             : 
      78             : 
      79             : 
      80        1776 : bool ContextChangeBroadcaster::SetBroadcasterEnabled (const bool bIsEnabled)
      81             : {
      82        1776 :     const bool bWasEnabled (mbIsBroadcasterEnabled);
      83        1776 :     mbIsBroadcasterEnabled = bIsEnabled;
      84        1776 :     return bWasEnabled;
      85             : }
      86             : 
      87             : 
      88             : 
      89             : 
      90       12148 : void ContextChangeBroadcaster::BroadcastContextChange (
      91             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
      92             :     const ::rtl::OUString& rsModuleName,
      93             :     const ::rtl::OUString& rsContextName)
      94             : {
      95       12148 :     if ( ! mbIsBroadcasterEnabled)
      96        7282 :         return;
      97             : 
      98       11260 :     if (rsContextName.getLength() == 0)
      99           0 :         return;
     100             : 
     101       11260 :     if ( ! rxFrame.is() || ! rxFrame->getController().is())
     102             :     {
     103             :         // Frame is (probably) being deleted.  Broadcasting context
     104             :         // changes is not necessary anymore.
     105        5506 :         return;
     106             :     }
     107             : 
     108             :     const css::ui::ContextChangeEventObject aEvent(
     109        5754 :         rxFrame->getController(),
     110             :         rsModuleName,
     111        5754 :         rsContextName);
     112             : 
     113             :     css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
     114             :         css::ui::ContextChangeEventMultiplexer::get(
     115       11508 :             ::comphelper::getProcessComponentContext()));
     116        5754 :     if (xMultiplexer.is())
     117       11508 :         xMultiplexer->broadcastContextChangeEvent(aEvent, rxFrame->getController());
     118             : }
     119             : 
     120             : 
     121             : 
     122             : 
     123       12148 : OUString ContextChangeBroadcaster::GetModuleName (const css::uno::Reference<css::frame::XFrame>& rxFrame)
     124             : {
     125       12148 :     if ( ! rxFrame.is() || ! rxFrame->getController().is())
     126        6142 :         return OUString();
     127             :     try
     128             :     {
     129        6006 :         const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext() );
     130       12012 :         const Reference<frame::XModuleManager> xModuleManager  = frame::ModuleManager::create( xContext );
     131       12012 :         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