1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SFX2_SIDEBAR_CONTROLLERITEM_HXX
20 #define INCLUDED_SFX2_SIDEBAR_CONTROLLERITEM_HXX
22 #include <sfx2/ctrlitem.hxx>
24 #include <cppuhelper/compbase1.hxx>
25 #include <cppuhelper/basemutex.hxx>
26 #include <unotools/cmdoptions.hxx>
27 #include <vcl/image.hxx>
29 #include <com/sun/star/frame/XFrame.hpp>
31 #include <boost/function.hpp>
33 namespace cssu
= ::com::sun::star::uno
;
39 namespace sfx2
{ namespace sidebar
{
41 /** The sfx2::sidebar::ControllerItem is a wrapper around the
42 SfxControllerItem that becomes necessary to allow objects (think
43 sidebar panels) to receive state changes without having one
44 SfxControllerItem per supported item as base class (which is not
45 possible in C++ anyway).
47 It also gives access to the label and icon of a slot/command.
49 class SFX2_DLLPUBLIC ControllerItem
50 : public SfxControllerItem
53 class SFX2_DLLPUBLIC ItemUpdateReceiverInterface
56 virtual void NotifyItemUpdate(
57 const sal_uInt16 nSId
,
58 const SfxItemState eState
,
59 const SfxPoolItem
* pState
,
60 const bool bIsEnabled
) = 0;
61 virtual ~ItemUpdateReceiverInterface();
64 /** This is the preferred constructor that allows the created
65 controller item to return non-empty values for GetLable() and
69 const sal_uInt16 nSlotId
,
70 SfxBindings
&rBindings
,
71 ItemUpdateReceiverInterface
& rItemUpdateReceiver
,
72 const ::rtl::OUString
& rsCommandName
,
73 const cssu::Reference
<css::frame::XFrame
>& rxFrame
);
75 /** This is the simpler constructor variant that still exists for
76 compatibility resons. Note that GetLabel() and GetIcon() will
77 return empty strings/images.
81 SfxBindings
&rBindings
,
82 ItemUpdateReceiverInterface
& rItemUpdateReceiver
);
84 virtual ~ControllerItem();
86 /** Returns </TRUE> when the slot/command has not been disabled.
87 Changes of this state are notified via the
88 ItemUpdateReceiverInterface::NotifyContextChang() method.
90 bool IsEnabled (const SfxItemState eState
) const;
92 /** Force the controller item to call its NotifyItemUpdate
93 callback with up-to-date data.
95 void RequestUpdate (void);
97 /** Return the label for the command. It contains the keyboard
98 accelerator when one exists.
100 ::rtl::OUString
GetLabel (void) const;
102 /** Return the extended help text for the command.
103 Returns an empty string when the UNO command name is not available.
105 ::rtl::OUString
GetHelpText (void) const;
107 /** Return the icon for the command.
109 Image
GetIcon (void) const;
111 /** Convenience method for setting all relevant properties for the
112 slot/command represented by the called object at the given tool
115 void SetupToolBoxItem (ToolBox
& rToolBox
, const sal_uInt16 nIndex
);
117 /** Do not call. Used by local class only. Should be a member of
118 a local and hidden interface.
120 void NotifyFrameContextChange (void);
121 /** Do not call. Used by local class only. Should be a member of
122 a local and hidden interface.
124 void ResetFrame (void);
128 virtual void StateChanged (sal_uInt16 nSId
, SfxItemState eState
, const SfxPoolItem
* pState
);
131 ItemUpdateReceiverInterface
& mrItemUpdateReceiver
;
132 cssu::Reference
<css::frame::XFrame
> mxFrame
;
133 cssu::Reference
<css::lang::XComponent
> mxFrameActionListener
;
134 const ::rtl::OUString msCommandName
;
136 void SetupCommandURL (const sal_Char
* sCommandName
);
139 } } // end of namespace sfx2::sidebar
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */