LCOV - code coverage report
Current view: top level - include/sfx2/sidebar - ControllerItem.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 1 100.0 %
Date: 2015-06-13 12:38:46 Functions: 1 1 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             : #ifndef INCLUDED_SFX2_SIDEBAR_CONTROLLERITEM_HXX
      20             : #define INCLUDED_SFX2_SIDEBAR_CONTROLLERITEM_HXX
      21             : 
      22             : #include <sfx2/ctrlitem.hxx>
      23             : 
      24             : #include <cppuhelper/compbase1.hxx>
      25             : #include <cppuhelper/basemutex.hxx>
      26             : #include <unotools/cmdoptions.hxx>
      27             : #include <vcl/image.hxx>
      28             : 
      29             : #include <com/sun/star/frame/XFrame.hpp>
      30             : 
      31             : #include <boost/function.hpp>
      32             : 
      33             : 
      34             : class SfxViewFrame;
      35             : class ToolBox;
      36             : 
      37             : 
      38             : namespace sfx2 { namespace sidebar {
      39             : 
      40             : /** The sfx2::sidebar::ControllerItem is a wrapper around the
      41             :     SfxControllerItem that becomes necessary to allow objects (think
      42             :     sidebar panels) to receive state changes without having one
      43             :     SfxControllerItem per supported item as base class (which is not
      44             :     possible in C++ anyway).
      45             : 
      46             :     It also gives access to the label and icon of a slot/command.
      47             : */
      48             : class SFX2_DLLPUBLIC ControllerItem
      49             :     : public SfxControllerItem
      50             : {
      51             : public:
      52        1620 :     class SFX2_DLLPUBLIC ItemUpdateReceiverInterface
      53             :     {
      54             :     public:
      55             :         virtual void NotifyItemUpdate(
      56             :             const sal_uInt16 nSId,
      57             :             const SfxItemState eState,
      58             :             const SfxPoolItem* pState,
      59             :             const bool bIsEnabled) = 0;
      60             :         virtual ~ItemUpdateReceiverInterface();
      61             :     };
      62             : 
      63             :     /** This is the preferred constructor that allows the created
      64             :         controller item to return non-empty values for GetLabel() and
      65             :         GetIcon() calls.
      66             :     */
      67             :     ControllerItem (
      68             :         const sal_uInt16 nSlotId,
      69             :         SfxBindings &rBindings,
      70             :         ItemUpdateReceiverInterface& rItemUpdateReceiver,
      71             :         const ::rtl::OUString& rsCommandName,
      72             :         const css::uno::Reference<css::frame::XFrame>& rxFrame);
      73             : 
      74             :     /** This is the simpler constructor variant that still exists for
      75             :         compatibility resons.  Note that GetLabel() and GetIcon() will
      76             :         return empty strings/images.
      77             :     */
      78             :     ControllerItem (
      79             :         const sal_uInt16 nId,
      80             :         SfxBindings &rBindings,
      81             :         ItemUpdateReceiverInterface& rItemUpdateReceiver);
      82             : 
      83             :     /// releases our action listener
      84             :     virtual void dispose() SAL_OVERRIDE;
      85             : 
      86             :     virtual ~ControllerItem();
      87             : 
      88             :     /** Returns </TRUE> when the slot/command has not been disabled.
      89             :         Changes of this state are notified via the
      90             :         ItemUpdateReceiverInterface::NotifyContextChang() method.
      91             :     */
      92             :     bool IsEnabled (const SfxItemState eState) const;
      93             : 
      94             :     /** Force the controller item to call its NotifyItemUpdate
      95             :         callback with up-to-date data.
      96             :     */
      97             :     void RequestUpdate();
      98             : 
      99             :     /** Return the label for the command.  It contains the keyboard
     100             :         accelerator when one exists.
     101             :     */
     102             :     ::rtl::OUString GetLabel() const;
     103             : 
     104             :     /** Return the extended help text for the command.
     105             :         Returns an empty string when the UNO command name is not available.
     106             :     */
     107             :     ::rtl::OUString GetHelpText() const;
     108             : 
     109             :     /** Return the icon for the command.
     110             :     */
     111             :     Image GetIcon() const;
     112             : 
     113             :     /** Convenience method for setting all relevant properties for the
     114             :         slot/command represented by the called object at the given tool
     115             :         box.
     116             :     */
     117             :     void SetupToolBoxItem (ToolBox& rToolBox, const sal_uInt16 nIndex);
     118             : 
     119             :     /** Do not call.  Used by local class only.  Should be a member of
     120             :         a local and hidden interface.
     121             :     */
     122             :     void NotifyFrameContextChange();
     123             :     /** Do not call.  Used by local class only.  Should be a member of
     124             :         a local and hidden interface.
     125             :     */
     126             :     void ResetFrame();
     127             : 
     128             : protected:
     129             : 
     130             :     virtual void StateChanged (sal_uInt16 nSId, SfxItemState eState, const SfxPoolItem* pState) SAL_OVERRIDE;
     131             : 
     132             : private:
     133             :     ItemUpdateReceiverInterface& mrItemUpdateReceiver;
     134             :     css::uno::Reference<css::frame::XFrame> mxFrame;
     135             :     css::uno::Reference<css::lang::XComponent> mxFrameActionListener;
     136             :     const ::rtl::OUString msCommandName;
     137             : 
     138             :     void SetupCommandURL (const sal_Char* sCommandName);
     139             : };
     140             : 
     141             : } } // end of namespace sfx2::sidebar
     142             : 
     143             : #endif
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11