LCOV - code coverage report
Current view: top level - svx/source/sidebar - ContextChangeEventMultiplexer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 17 17 100.0 %
Date: 2014-11-03 Functions: 3 3 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 "svx/sidebar/ContextChangeEventMultiplexer.hxx"
      21             : 
      22             : #include <com/sun/star/ui/ContextChangeEventObject.hpp>
      23             : #include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp>
      24             : #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
      25             : #include <com/sun/star/frame/ModuleManager.hpp>
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <sfx2/viewsh.hxx>
      28             : #include <tools/diagnose_ex.h>
      29             : 
      30             : using namespace css;
      31             : using namespace css::uno;
      32             : 
      33             : 
      34        1614 : void ContextChangeEventMultiplexer::NotifyContextChange (
      35             :     const css::uno::Reference<css::frame::XController>& rxController,
      36             :     const ::sfx2::sidebar::EnumContext::Context eContext)
      37             : {
      38        1614 :     if (rxController.is() && rxController->getFrame().is())
      39             :     {
      40             :         const css::ui::ContextChangeEventObject aEvent(
      41             :             rxController,
      42        1402 :             GetModuleName(rxController->getFrame()),
      43        2804 :             ::sfx2::sidebar::EnumContext::GetContextName(eContext));
      44             : 
      45             :         css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
      46             :             css::ui::ContextChangeEventMultiplexer::get(
      47        2804 :                 ::comphelper::getProcessComponentContext()));
      48        1402 :         if (xMultiplexer.is())
      49        2804 :             xMultiplexer->broadcastContextChangeEvent(aEvent, rxController);
      50             :     }
      51        1614 : }
      52             : 
      53             : 
      54             : 
      55             : 
      56         614 : void ContextChangeEventMultiplexer::NotifyContextChange (
      57             :     SfxViewShell* pViewShell,
      58             :     const ::sfx2::sidebar::EnumContext::Context eContext)
      59             : {
      60         614 :     if (pViewShell != NULL)
      61         614 :         NotifyContextChange(pViewShell->GetController(), eContext);
      62         614 : }
      63             : 
      64             : 
      65             : 
      66             : 
      67        1402 : ::rtl::OUString ContextChangeEventMultiplexer::GetModuleName (
      68             :     const css::uno::Reference<css::frame::XFrame>& rxFrame)
      69             : {
      70             :     try
      71             :     {
      72             :         const Reference<frame::XModuleManager> xModuleManager =
      73        1402 :             frame::ModuleManager::create( comphelper::getProcessComponentContext() );
      74        1614 :         return xModuleManager->identify(rxFrame);
      75             :     }
      76         212 :     catch (const Exception&)
      77             :     {
      78             :         // An exception typically means that a context change is notified
      79             :         // during initialization or destruction of a view.
      80             :         // Ignore it.
      81             :     }
      82             :     return ::sfx2::sidebar::EnumContext::GetApplicationName(
      83         212 :         ::sfx2::sidebar::EnumContext::Application_None);
      84             : }
      85             : 
      86             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10