LCOV - code coverage report
Current view: top level - sd/source/ui/framework/module - ViewTabBarModule.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 78 79 98.7 %
Date: 2014-11-03 Functions: 9 9 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 "ViewTabBarModule.hxx"
      21             : 
      22             : #include "framework/FrameworkHelper.hxx"
      23             : #include "framework/ConfigurationController.hxx"
      24             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      25             : #include <com/sun/star/drawing/framework/XTabBar.hpp>
      26             : 
      27             : #include "strings.hrc"
      28             : #include "sdresid.hxx"
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::drawing::framework;
      33             : 
      34             : using ::sd::framework::FrameworkHelper;
      35             : 
      36             : namespace {
      37             : 
      38             : static const sal_Int32 ResourceActivationRequestEvent = 0;
      39             : static const sal_Int32 ResourceDeactivationRequestEvent = 1;
      40             : static const sal_Int32 ResourceActivationEvent = 2;
      41             : 
      42             : }
      43             : 
      44             : namespace sd { namespace framework {
      45             : 
      46             : //===== ViewTabBarModule ==================================================
      47             : 
      48          52 : ViewTabBarModule::ViewTabBarModule (
      49             :     const Reference<frame::XController>& rxController,
      50             :     const Reference<XResourceId>& rxViewTabBarId)
      51             :     : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex),
      52             :       mxConfigurationController(),
      53          52 :       mxViewTabBarId(rxViewTabBarId)
      54             : {
      55          52 :     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
      56             : 
      57          52 :     if (xControllerManager.is())
      58             :     {
      59          52 :         mxConfigurationController = xControllerManager->getConfigurationController();
      60          52 :         if (mxConfigurationController.is())
      61             :         {
      62          52 :             mxConfigurationController->addConfigurationChangeListener(
      63             :                 this,
      64             :                 FrameworkHelper::msResourceActivationRequestEvent,
      65          52 :                 makeAny(ResourceActivationRequestEvent));
      66          52 :             mxConfigurationController->addConfigurationChangeListener(
      67             :                 this,
      68             :                 FrameworkHelper::msResourceDeactivationRequestEvent,
      69          52 :                 makeAny(ResourceDeactivationRequestEvent));
      70             : 
      71          52 :             UpdateViewTabBar(NULL);
      72          52 :             mxConfigurationController->addConfigurationChangeListener(
      73             :                 this,
      74             :                 FrameworkHelper::msResourceActivationEvent,
      75          52 :                 makeAny(ResourceActivationEvent));
      76             :         }
      77          52 :     }
      78          52 : }
      79             : 
      80         104 : ViewTabBarModule::~ViewTabBarModule (void)
      81             : {
      82         104 : }
      83             : 
      84         104 : void SAL_CALL ViewTabBarModule::disposing (void)
      85             : {
      86         104 :     if (mxConfigurationController.is())
      87           0 :         mxConfigurationController->removeConfigurationChangeListener(this);
      88             : 
      89         104 :     mxConfigurationController = NULL;
      90         104 : }
      91             : 
      92         984 : void SAL_CALL ViewTabBarModule::notifyConfigurationChange (
      93             :     const ConfigurationChangeEvent& rEvent)
      94             :     throw (RuntimeException, std::exception)
      95             : {
      96         984 :     if (mxConfigurationController.is())
      97             :     {
      98         984 :         sal_Int32 nEventType = 0;
      99         984 :         rEvent.UserData >>= nEventType;
     100         984 :         switch (nEventType)
     101             :         {
     102             :             case ResourceActivationRequestEvent:
     103         364 :                 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
     104             :                 {
     105          52 :                     mxConfigurationController->requestResourceActivation(
     106             :                         mxViewTabBarId,
     107          52 :                         ResourceActivationMode_ADD);
     108             :                 }
     109         364 :                 break;
     110             : 
     111             :             case ResourceDeactivationRequestEvent:
     112         364 :                 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
     113             :                 {
     114          52 :                     mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
     115             :                 }
     116         364 :                 break;
     117             : 
     118             :             case ResourceActivationEvent:
     119         256 :                 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
     120             :                 {
     121          52 :                     UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
     122             :                 }
     123             :         }
     124             :     }
     125         984 : }
     126             : 
     127         104 : void SAL_CALL ViewTabBarModule::disposing (
     128             :     const lang::EventObject& rEvent)
     129             :     throw (RuntimeException, std::exception)
     130             : {
     131         208 :     if (mxConfigurationController.is()
     132         104 :         && rEvent.Source == mxConfigurationController)
     133             :     {
     134             :         // Without the configuration controller this class can do nothing.
     135          52 :         mxConfigurationController = NULL;
     136          52 :         disposing();
     137             :     }
     138         104 : }
     139             : 
     140         104 : void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
     141             : {
     142         104 :     if (mxConfigurationController.is())
     143             :     {
     144         104 :         Reference<XTabBar> xBar (rxTabBar);
     145         104 :         if ( ! xBar.is())
     146         104 :             xBar = Reference<XTabBar>(
     147         104 :                 mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
     148             : 
     149         104 :         if (xBar.is())
     150             :         {
     151          52 :             TabBarButton aEmptyButton;
     152             : 
     153         104 :             Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
     154             : 
     155         104 :             TabBarButton aImpressViewButton;
     156         104 :             aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
     157             :                 FrameworkHelper::msImpressViewURL,
     158          52 :                 xAnchor);
     159          52 :             aImpressViewButton.ButtonLabel = SD_RESSTR(STR_DRAW_MODE);
     160          52 :             if ( ! xBar->hasTabBarButton(aImpressViewButton))
     161          52 :                 xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
     162             : 
     163         104 :             TabBarButton aOutlineViewButton;
     164         104 :             aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
     165             :                 FrameworkHelper::msOutlineViewURL,
     166          52 :                 xAnchor);
     167          52 :             aOutlineViewButton.ButtonLabel = SD_RESSTR(STR_OUTLINE_MODE);
     168          52 :             if ( ! xBar->hasTabBarButton(aOutlineViewButton))
     169          52 :                 xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
     170             : 
     171         104 :             TabBarButton aNotesViewButton;
     172         104 :             aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
     173             :                 FrameworkHelper::msNotesViewURL,
     174          52 :                 xAnchor);
     175          52 :             aNotesViewButton.ButtonLabel = SD_RESSTR(STR_NOTES_MODE);
     176          52 :             if ( ! xBar->hasTabBarButton(aNotesViewButton))
     177          52 :                 xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
     178             : 
     179         104 :             TabBarButton aHandoutViewButton;
     180         104 :             aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId(
     181             :                 FrameworkHelper::msHandoutViewURL,
     182          52 :                 xAnchor);
     183          52 :             aHandoutViewButton.ButtonLabel = SD_RESSTR(STR_HANDOUT_MODE);
     184          52 :             if ( ! xBar->hasTabBarButton(aHandoutViewButton))
     185         104 :                 xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton);
     186         104 :         }
     187             :     }
     188         104 : }
     189             : 
     190         114 : } } // end of namespace sd::framework
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10