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 SFX_SIDEBAR_TOOLBOX_HXX
23 #define SFX_SIDEBAR_TOOLBOX_HXX
24 
25 #include "sfx2/dllapi.h"
26 #include "vcl/toolbox.hxx"
27 #include <com/sun/star/frame/XDispatch.hpp>
28 #include <com/sun/star/frame/XFrame.hpp>
29 #include <com/sun/star/frame/XToolbarController.hpp>
30 #include <com/sun/star/util/URL.hpp>
31 #include <map>
32 
33 namespace css = ::com::sun::star;
34 namespace cssu = ::com::sun::star::uno;
35 
36 namespace sfx2 { namespace sidebar {
37 
38 /** The sidebar tool box has two responsibilities:
39     1. Coordinated location, size, and other states with its parent
40        background window.
41     2. Create and handle tool bar controller for its items.
42 */
43 class SFX2_DLLPUBLIC SidebarToolBox
44     : public ToolBox
45 {
46 public:
47     /** Create a new tool box.
48         When a valid XFrame is given then the tool box will handle its
49         buttons and drop-downs.  Otherwise the caller has to do that.
50     */
51     SidebarToolBox (
52         Window* pParentWindow,
53         const ResId& rResId,
54         const cssu::Reference<css::frame::XFrame>& rxFrame);
55     SidebarToolBox (
56         Window* pParentWindow);
57     virtual ~SidebarToolBox (void);
58 
59     void SetBorderWindow (const Window* pBorderWindow);
60     virtual void Paint (const Rectangle& rRect);
61 
62     virtual Point GetPosPixel (void) const;
63     virtual void SetPosSizePixel (
64         long nX,
65         long nY,
66         long nWidth,
67         long nHeight,
68         sal_uInt16 nFlags);
69     virtual long Notify (NotifyEvent& rEvent);
70 
71     cssu::Reference<css::frame::XToolbarController> GetControllerForItemId (
72         const sal_uInt16 nItemId) const;
73     sal_uInt16 GetItemIdForSubToolbarName (
74         const ::rtl::OUString& rsCOmmandName) const;
75 
76     void SetController (
77         const sal_uInt16 nItemId,
78         const cssu::Reference<css::frame::XToolbarController>& rxController,
79         const ::rtl::OUString& rsCommandName);
80 
81 private:
82     bool mbParentIsBorder;
83     Image maItemSeparator;
84     class ItemDescriptor
85     {
86     public:
87         cssu::Reference<css::frame::XToolbarController> mxController;
88         css::util::URL maURL;
89         rtl::OUString msCurrentCommand;
90     };
91     typedef ::std::map<sal_uInt16, ItemDescriptor> ControllerContainer;
92     ControllerContainer maControllers;
93     bool mbAreHandlersRegistered;
94 
95     DECL_LINK(DropDownClickHandler, ToolBox*);
96     DECL_LINK(ClickHandler, ToolBox*);
97     DECL_LINK(DoubleClickHandler, ToolBox*);
98     DECL_LINK(SelectHandler, ToolBox*);
99     DECL_LINK(Activate, ToolBox*);
100     DECL_LINK(Deactivate, ToolBox*);
101 
102     using ToolBox::Activate;
103     using ToolBox::Deactivate;
104     using DockingWindow::SetPosSizePixel;
105 
106     void CreateController (
107         const sal_uInt16 nItemId,
108         const cssu::Reference<css::frame::XFrame>& rxFrame,
109         const sal_Int32 nItemWidth = 0);
110     void UpdateIcons (
111         const cssu::Reference<css::frame::XFrame>& rxFrame);
112     void RegisterHandlers (void);
113 };
114 
115 
116 } } // end of namespace sfx2::sidebar
117 
118 #endif
119