LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ControllerItem.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 75 0.0 %
Date: 2014-04-14 Functions: 0 21 0.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             : #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 cssu;
      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           0 :         FrameActionListener (
      51             :             sfx2::sidebar::ControllerItem& rControllerItem,
      52             :             const Reference<frame::XFrame>& rxFrame)
      53             :             : FrameActionListenerInterfaceBase(m_aMutex),
      54             :               mrControllerItem(rControllerItem),
      55           0 :               mxFrame(rxFrame)
      56             :         {
      57           0 :             if (mxFrame.is())
      58           0 :                 mxFrame->addFrameActionListener(this);
      59           0 :         }
      60           0 :         virtual ~FrameActionListener (void)
      61           0 :         {
      62           0 :         }
      63           0 :         virtual void SAL_CALL disposing (void) SAL_OVERRIDE
      64             :         {
      65           0 :             if (mxFrame.is())
      66           0 :                 mxFrame->removeFrameActionListener(this);
      67           0 :         }
      68           0 :         virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
      69             :             throw (cssu::RuntimeException, std::exception) SAL_OVERRIDE
      70             :         {
      71             :             (void)rEvent;
      72           0 :             mrControllerItem.ResetFrame();
      73           0 :             mxFrame = NULL;
      74           0 :         }
      75           0 :         virtual void SAL_CALL frameAction (const css::frame::FrameActionEvent& rEvent)
      76             :             throw (cssu::RuntimeException, std::exception) SAL_OVERRIDE
      77             :         {
      78           0 :             if (rEvent.Action == frame::FrameAction_CONTEXT_CHANGED)
      79           0 :                 mrControllerItem.NotifyFrameContextChange();
      80           0 :         }
      81             : 
      82             :     private:
      83             :         sfx2::sidebar::ControllerItem& mrControllerItem;
      84             :         Reference<frame::XFrame> mxFrame;
      85             :     };
      86             : }
      87             : 
      88             : namespace sfx2 { namespace sidebar {
      89             : 
      90           0 : 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           0 :       msCommandName()
      99             : {
     100           0 : }
     101             : 
     102             : 
     103             : 
     104             : 
     105           0 : 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           0 :       mxFrameActionListener(new FrameActionListener(*this, mxFrame)),
     115           0 :       msCommandName(rsCommandName)
     116             : {
     117           0 : }
     118             : 
     119             : 
     120             : 
     121             : 
     122           0 : ControllerItem::~ControllerItem (void)
     123             : {
     124           0 :     if (mxFrameActionListener.is())
     125           0 :         mxFrameActionListener->dispose();
     126           0 : }
     127             : 
     128             : 
     129             : 
     130             : 
     131           0 : void ControllerItem::StateChanged (
     132             :     sal_uInt16 nSID,
     133             :     SfxItemState eState,
     134             :     const SfxPoolItem* pState)
     135             : {
     136           0 :     mrItemUpdateReceiver.NotifyItemUpdate(nSID, eState, pState, IsEnabled(eState));
     137           0 : }
     138             : 
     139             : 
     140             : 
     141             : 
     142           0 : bool ControllerItem::IsEnabled (SfxItemState eState) const
     143             : {
     144           0 :     if (eState == SFX_ITEM_DISABLED)
     145           0 :         return false;
     146           0 :     else if ( ! SvtCommandOptions().HasEntries(SvtCommandOptions::CMDOPTION_DISABLED))
     147             :     {
     148             :         // There are no disabled commands.
     149           0 :         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           0 : ::rtl::OUString ControllerItem::GetLabel (void) const
     196             : {
     197           0 :     return CommandInfoProvider::Instance().GetLabelForCommand(
     198           0 :         ".uno:" + msCommandName,
     199           0 :         mxFrame);
     200             : }
     201             : 
     202             : 
     203             : 
     204             : 
     205           0 : ::rtl::OUString ControllerItem::GetHelpText (void) const
     206             : {
     207           0 :     Help* pHelp = Application::GetHelp();
     208           0 :     if (pHelp != NULL)
     209             :     {
     210           0 :         if (msCommandName.getLength() > 0)
     211             :         {
     212           0 :             const ::rtl::OUString sHelp (pHelp->GetHelpText(".uno:" + msCommandName, NULL));
     213           0 :             return sHelp;
     214             :         }
     215             :     }
     216           0 :     return ::rtl::OUString();
     217             : }
     218             : 
     219             : 
     220             : 
     221             : 
     222           0 : Image ControllerItem::GetIcon (void) const
     223             : {
     224           0 :     return GetImage(mxFrame, ".uno:" + msCommandName, false);
     225             : }
     226             : 
     227             : 
     228             : 
     229             : 
     230           0 : ControllerItem::ItemUpdateReceiverInterface::~ItemUpdateReceiverInterface()
     231             : {
     232           0 : }
     233             : 
     234             : 
     235           0 : void ControllerItem::SetupToolBoxItem (ToolBox& rToolBox, const sal_uInt16 nIndex)
     236             : {
     237           0 :     rToolBox.SetQuickHelpText(nIndex, GetLabel());
     238           0 :     rToolBox.SetHelpText(nIndex, GetHelpText());
     239           0 :     rToolBox.SetItemImage(nIndex, GetIcon());
     240           0 : }
     241             : 
     242             : 
     243             : } } // end of namespace sfx2::sidebar
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10