LCOV - code coverage report
Current view: top level - svx/source/sidebar - ContextChangeEventMultiplexer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 17 17 100.0 %
Date: 2014-04-11 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * This file incorporates work covered by the following license notice:
       9             :  *
      10             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      11             :  *   contributor license agreements. See the NOTICE file distributed
      12             :  *   with this work for additional information regarding copyright
      13             :  *   ownership. The ASF licenses this file to you under the Apache
      14             :  *   License, Version 2.0 (the "License"); you may not use this file
      15             :  *   except in compliance with the License. You may obtain a copy of
      16             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      17             :  */
      18             : 
      19             : #include "svx/sidebar/ContextChangeEventMultiplexer.hxx"
      20             : 
      21             : #include <com/sun/star/ui/ContextChangeEventObject.hpp>
      22             : #include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp>
      23             : #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
      24             : #include <com/sun/star/frame/ModuleManager.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <sfx2/viewsh.hxx>
      27             : #include <tools/diagnose_ex.h>
      28             : 
      29             : using namespace css;
      30             : using namespace cssu;
      31             : 
      32             : 
      33         616 : void ContextChangeEventMultiplexer::NotifyContextChange (
      34             :     const cssu::Reference<css::frame::XController>& rxController,
      35             :     const ::sfx2::sidebar::EnumContext::Context eContext)
      36             : {
      37         616 :     if (rxController.is() && rxController->getFrame().is())
      38             :     {
      39             :         const css::ui::ContextChangeEventObject aEvent(
      40             :             rxController,
      41         547 :             GetModuleName(rxController->getFrame()),
      42        1094 :             ::sfx2::sidebar::EnumContext::GetContextName(eContext));
      43             : 
      44             :         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
      45             :             css::ui::ContextChangeEventMultiplexer::get(
      46        1094 :                 ::comphelper::getProcessComponentContext()));
      47         547 :         if (xMultiplexer.is())
      48        1094 :             xMultiplexer->broadcastContextChangeEvent(aEvent, rxController);
      49             :     }
      50         616 : }
      51             : 
      52             : 
      53             : 
      54             : 
      55         239 : void ContextChangeEventMultiplexer::NotifyContextChange (
      56             :     SfxViewShell* pViewShell,
      57             :     const ::sfx2::sidebar::EnumContext::Context eContext)
      58             : {
      59         239 :     if (pViewShell != NULL)
      60         239 :         NotifyContextChange(pViewShell->GetController(), eContext);
      61         239 : }
      62             : 
      63             : 
      64             : 
      65             : 
      66         547 : ::rtl::OUString ContextChangeEventMultiplexer::GetModuleName (
      67             :     const cssu::Reference<css::frame::XFrame>& rxFrame)
      68             : {
      69             :     try
      70             :     {
      71             :         const Reference<frame::XModuleManager> xModuleManager =
      72         547 :             frame::ModuleManager::create( comphelper::getProcessComponentContext() );
      73         616 :         return xModuleManager->identify(rxFrame);
      74             :     }
      75          69 :     catch (const Exception&)
      76             :     {
      77             :         // An exception typically means that a context change is notified
      78             :         // during initialization or destruction of a view.
      79             :         // Ignore it.
      80             :     }
      81             :     return ::sfx2::sidebar::EnumContext::GetApplicationName(
      82          69 :         ::sfx2::sidebar::EnumContext::Application_None);
      83             : }

Generated by: LCOV version 1.10