1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef SVX_SIDEBAR_CONTROLLER_ITEM_HXX
23 #define SVX_SIDEBAR_CONTROLLER_ITEM_HXX
24 
25 #include <sfx2/ctrlitem.hxx>
26 
27 #include <cppuhelper/compbase1.hxx>
28 #include <cppuhelper/basemutex.hxx>
29 #include <unotools/cmdoptions.hxx>
30 #include <vcl/image.hxx>
31 
32 #include <com/sun/star/frame/XFrame.hpp>
33 
34 #include <boost/function.hpp>
35 
36 
37 namespace css = ::com::sun::star;
38 namespace cssu = ::com::sun::star::uno;
39 
40 class SfxViewFrame;
41 class ToolBox;
42 
43 
44 namespace sfx2 { namespace sidebar {
45 
46 /** The sfx2::sidebar::ControllerItem is a wrapper around the
47     SfxControllerItem that becomes necessary to allow objects (think
48     sidebar panels) to receive state changes without having one
49     SfxControllerItem per supported item as base class (which is not
50     possible in C++ anyway).
51 
52     It also gives access to the label and icon of a slot/command.
53 */
54 class SFX2_DLLPUBLIC ControllerItem
55     : public SfxControllerItem
56 {
57 public:
58     class ItemUpdateReceiverInterface
59     {
60     public:
61         virtual void NotifyItemUpdate(
62             const sal_uInt16 nSId,
63             const SfxItemState eState,
64             const SfxPoolItem* pState,
65             const bool bIsEnabled) = 0;
66     };
67 
68     /** This is the preferred constructor that allows the created
69         controller item to return non-empty values for GetLable() and
70         GetIcon() calls.
71     */
72     ControllerItem (
73         const sal_uInt16 nSlotId,
74         SfxBindings &rBindings,
75         ItemUpdateReceiverInterface& rItemUpdateReceiver,
76         const ::rtl::OUString& rsCommandName,
77         const cssu::Reference<css::frame::XFrame>& rxFrame);
78 
79     /** This is the simpler constructor variant that still exists for
80         compatibility resons.  Note that GetLabel() and GetIcon() will
81         return empty strings/images.
82     */
83     ControllerItem (
84         const sal_uInt16 nId,
85         SfxBindings &rBindings,
86         ItemUpdateReceiverInterface& rItemUpdateReceiver);
87 
88     virtual ~ControllerItem (void);
89 
90     /** Returns </TRUE> when the slot/command has not been disabled.
91         Changes of this state are notified via the
92         ItemUpdateReceiverInterface::NotifyContextChang() method.
93     */
94     bool IsEnabled (const SfxItemState eState) const;
95 
96     /** Force the controller item to call its NotifyItemUpdate
97         callback with up-to-date data.
98     */
99     void RequestUpdate (void);
100 
101     /** Return the label for the command.  It contains the keyboard
102         accelerator when one exists.
103     */
104     ::rtl::OUString GetLabel (void) const;
105 
106     /** Return the extended help text for the command.
107         Returns an empty string when the UNO command name is not available.
108     */
109     ::rtl::OUString GetHelpText (void) const;
110 
111     /** Return the icon for the command.  Uses the system high contrast mode state.
112     */
113     Image GetIcon (void) const;
114 
115     /** Return the icon for the command.  Allows the user to override
116         the high contrast mode state.
117     */
118     Image GetIcon (const bool bIsHighContrastMode) const;
119 
120     /** Convenience method for setting all relevant properties for the
121         slot/command represented by the called object at the given tool
122         box.
123     */
124     void SetupToolBoxItem (ToolBox& rToolBox, const sal_uInt16 nIndex);
125 
126     /** Do not call.  Used by local class only.  Should be a member of
127         a local and hidden interface.
128     */
129     void NotifyFrameContextChange (void);
130     /** Do not call.  Used by local class only.  Should be a member of
131         a local and hidden interface.
132     */
133     void ResetFrame (void);
134 
135 protected:
136     virtual void StateChanged (sal_uInt16 nSId, SfxItemState eState, const SfxPoolItem* pState);
137 
138 private:
139     ItemUpdateReceiverInterface& mrItemUpdateReceiver;
140     cssu::Reference<css::frame::XFrame> mxFrame;
141     cssu::Reference<css::lang::XComponent> mxFrameActionListener;
142     const ::rtl::OUString msCommandName;
143 
144     void SetupCommandURL (const sal_Char* sCommandName);
145 };
146 
147 } } // end of namespace sfx2::sidebar
148 
149 #endif
150