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

Generated by: LCOV version 1.10