LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ControllerItem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 54 76 71.1 %
Date: 2014-11-03 Functions: 17 23 73.9 %
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 <sfx2/sidebar/ControllerItem.hxx>
      20             : 
      21             : #include <sfx2/msgpool.hxx>
      22             : #include <sfx2/viewsh.hxx>
      23             : #include <sfx2/imagemgr.hxx>
      24             : #include <sfx2/bindings.hxx>
      25             : #include <unotools/cmdoptions.hxx>
      26             : #include <sfx2/sidebar/CommandInfoProvider.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include <vcl/toolbox.hxx>
      29             : #include <vcl/help.hxx>
      30             : 
      31             : #include <com/sun/star/frame/XFrame.hpp>
      32             : #include <com/sun/star/frame/XFrameActionListener.hpp>
      33             : 
      34             : 
      35             : using namespace css;
      36             : using namespace css::uno;
      37             : 
      38             : 
      39             : namespace
      40             : {
      41             :     typedef ::cppu::WeakComponentImplHelper1 <
      42             :         css::frame::XFrameActionListener
      43             :         > FrameActionListenerInterfaceBase;
      44             : 
      45             :     class FrameActionListener
      46             :         : public ::cppu::BaseMutex,
      47             :           public FrameActionListenerInterfaceBase
      48             :     {
      49             :     public:
      50        6642 :         FrameActionListener (
      51             :             sfx2::sidebar::ControllerItem& rControllerItem,
      52             :             const Reference<frame::XFrame>& rxFrame)
      53             :             : FrameActionListenerInterfaceBase(m_aMutex),
      54             :               mrControllerItem(rControllerItem),
      55        6642 :               mxFrame(rxFrame)
      56             :         {
      57        6642 :             if (mxFrame.is())
      58        6642 :                 mxFrame->addFrameActionListener(this);
      59        6642 :         }
      60       13284 :         virtual ~FrameActionListener (void)
      61        6642 :         {
      62       13284 :         }
      63        6642 :         virtual void SAL_CALL disposing (void) SAL_OVERRIDE
      64             :         {
      65        6642 :             if (mxFrame.is())
      66        6642 :                 mxFrame->removeFrameActionListener(this);
      67        6642 :         }
      68           0 :         virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
      69             :             throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      70             :         {
      71             :             (void)rEvent;
      72           0 :             mrControllerItem.ResetFrame();
      73           0 :             mxFrame = NULL;
      74           0 :         }
      75       20304 :         virtual void SAL_CALL frameAction (const css::frame::FrameActionEvent& rEvent)
      76             :             throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      77             :         {
      78       20304 :             if (rEvent.Action == frame::FrameAction_CONTEXT_CHANGED)
      79           0 :                 mrControllerItem.NotifyFrameContextChange();
      80       20304 :         }
      81             : 
      82             :     private:
      83             :         sfx2::sidebar::ControllerItem& mrControllerItem;
      84             :         Reference<frame::XFrame> mxFrame;
      85             :     };
      86             : }
      87             : 
      88             : namespace sfx2 { namespace sidebar {
      89             : 
      90        8880 : ControllerItem::ControllerItem (
      91             :     const sal_uInt16 nSlotId,
      92             :     SfxBindings &rBindings,
      93             :     ItemUpdateReceiverInterface& rItemUpdateReceiver)
      94             :     : SfxControllerItem(nSlotId, rBindings),
      95             :       mrItemUpdateReceiver(rItemUpdateReceiver),
      96             :       mxFrame(),
      97             :       mxFrameActionListener(),
      98        8880 :       msCommandName()
      99             : {
     100        8880 : }
     101             : 
     102             : 
     103             : 
     104             : 
     105        6642 : ControllerItem::ControllerItem (
     106             :     const sal_uInt16 nSlotId,
     107             :     SfxBindings &rBindings,
     108             :     ItemUpdateReceiverInterface& rItemUpdateReceiver,
     109             :     const ::rtl::OUString& rsCommandName,
     110             :     const Reference<frame::XFrame>& rxFrame)
     111             :     : SfxControllerItem(nSlotId, rBindings),
     112             :       mrItemUpdateReceiver(rItemUpdateReceiver),
     113             :       mxFrame(rxFrame),
     114        6642 :       mxFrameActionListener(new FrameActionListener(*this, mxFrame)),
     115       13284 :       msCommandName(rsCommandName)
     116             : {
     117        6642 : }
     118             : 
     119             : 
     120             : 
     121             : 
     122       31044 : ControllerItem::~ControllerItem (void)
     123             : {
     124       15522 :     if (mxFrameActionListener.is())
     125        6642 :         mxFrameActionListener->dispose();
     126       15522 : }
     127             : 
     128             : 
     129             : 
     130             : 
     131        6018 : void ControllerItem::StateChanged (
     132             :     sal_uInt16 nSID,
     133             :     SfxItemState eState,
     134             :     const SfxPoolItem* pState)
     135             : {
     136        6018 :     mrItemUpdateReceiver.NotifyItemUpdate(nSID, eState, pState, IsEnabled(eState));
     137        6018 : }
     138             : 
     139             : 
     140             : 
     141             : 
     142        6018 : bool ControllerItem::IsEnabled (SfxItemState eState) const
     143             : {
     144        6018 :     if (eState == SfxItemState::DISABLED)
     145         352 :         return false;
     146        5666 :     else if ( ! SvtCommandOptions().HasEntries(SvtCommandOptions::CMDOPTION_DISABLED))
     147             :     {
     148             :         // There are no disabled commands.
     149        5666 :         return true;
     150             :     }
     151           0 :     else if (msCommandName.getLength() == 0)
     152             :     {
     153             :         // We were not given a command name at construction and can
     154             :         // not check the state now.  Assume the best and return true.
     155           0 :         return true;
     156             :     }
     157           0 :     else if (SvtCommandOptions().Lookup(SvtCommandOptions::CMDOPTION_DISABLED, msCommandName))
     158             :     {
     159             :         // The command is part of a list of disabled commands.
     160           0 :         return false;
     161             :     }
     162             :     else
     163           0 :         return true;
     164             : }
     165             : 
     166             : 
     167             : 
     168             : 
     169           0 : void ControllerItem::RequestUpdate (void)
     170             : {
     171           0 :     SfxPoolItem* pState = NULL;
     172           0 :     const SfxItemState eState (GetBindings().QueryState(GetId(), pState));
     173           0 :     mrItemUpdateReceiver.NotifyItemUpdate(GetId(), eState, pState, IsEnabled(eState));
     174           0 : }
     175             : 
     176             : 
     177             : 
     178             : 
     179           0 : void ControllerItem::NotifyFrameContextChange (void)
     180             : {
     181           0 :     RequestUpdate();
     182           0 : }
     183             : 
     184             : 
     185             : 
     186             : 
     187           0 : void ControllerItem::ResetFrame (void)
     188             : {
     189           0 :     mxFrame = NULL;
     190           0 : }
     191             : 
     192             : 
     193             : 
     194             : 
     195        1476 : ::rtl::OUString ControllerItem::GetLabel (void) const
     196             : {
     197        1476 :     return CommandInfoProvider::Instance().GetLabelForCommand(
     198        2952 :         ".uno:" + msCommandName,
     199        5904 :         mxFrame);
     200             : }
     201             : 
     202             : 
     203             : 
     204             : 
     205        1476 : ::rtl::OUString ControllerItem::GetHelpText (void) const
     206             : {
     207        1476 :     Help* pHelp = Application::GetHelp();
     208        1476 :     if (pHelp != NULL)
     209             :     {
     210        1476 :         if (msCommandName.getLength() > 0)
     211             :         {
     212        1476 :             const ::rtl::OUString sHelp (pHelp->GetHelpText(".uno:" + msCommandName, NULL));
     213        1476 :             return sHelp;
     214             :         }
     215             :     }
     216           0 :     return ::rtl::OUString();
     217             : }
     218             : 
     219             : 
     220             : 
     221             : 
     222        5904 : Image ControllerItem::GetIcon (void) const
     223             : {
     224        5904 :     return GetImage(mxFrame, ".uno:" + msCommandName, false);
     225             : }
     226             : 
     227             : 
     228             : 
     229             : 
     230        2218 : ControllerItem::ItemUpdateReceiverInterface::~ItemUpdateReceiverInterface()
     231             : {
     232        2218 : }
     233             : 
     234             : 
     235        1476 : void ControllerItem::SetupToolBoxItem (ToolBox& rToolBox, const sal_uInt16 nIndex)
     236             : {
     237        1476 :     rToolBox.SetQuickHelpText(nIndex, GetLabel());
     238        1476 :     rToolBox.SetHelpText(nIndex, GetHelpText());
     239        1476 :     rToolBox.SetItemImage(nIndex, GetIcon());
     240        1476 : }
     241             : 
     242             : 
     243         951 : } } // end of namespace sfx2::sidebar
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10