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_PANEL_BASE_HXX
23 #define SFX_SIDEBAR_PANEL_BASE_HXX
24 
25 #include "EnumContext.hxx"
26 
27 #include <cppuhelper/compbase4.hxx>
28 #include <cppuhelper/basemutex.hxx>
29 
30 #include <com/sun/star/frame/XController.hpp>
31 #include <com/sun/star/ui/XContextChangeEventListener.hpp>
32 #include <com/sun/star/ui/XUIElement.hpp>
33 #include <com/sun/star/ui/XToolPanel.hpp>
34 #include <com/sun/star/ui/XSidebarPanel.hpp>
35 
36 #include <boost/noncopyable.hpp>
37 #include <boost/function.hpp>
38 
39 
40 namespace css = ::com::sun::star;
41 namespace cssu = ::com::sun::star::uno;
42 
43 
44 class Window;
45 
46 namespace sfx2 { namespace sidebar {
47 
48 namespace
49 {
50     typedef ::cppu::WeakComponentImplHelper4 <
51         css::ui::XContextChangeEventListener,
52         css::ui::XUIElement,
53         css::ui::XToolPanel,
54         css::ui::XSidebarPanel
55         > SidebarPanelBaseInterfaceBase;
56 }
57 
58 /** Base class for sidebar panels that provides some convenience
59     functionality.
60 */
61 class SFX2_DLLPUBLIC SidebarPanelBase
62     : private ::boost::noncopyable,
63       private ::cppu::BaseMutex,
64       public SidebarPanelBaseInterfaceBase
65 {
66 public:
67     class ContextChangeReceiverInterface
68     {
69       public:
70         virtual void HandleContextChange (
71             const EnumContext aContext) = 0;
72     };
73 
74     static cssu::Reference<css::ui::XUIElement> Create (
75         const ::rtl::OUString& rsResourceURL,
76         const cssu::Reference<css::frame::XFrame>& rxFrame,
77         Window* mpWindow,
78         const ::boost::function<void(void)>& rMenuProvider);
79 
80     // XContextChangeEventListener
81     virtual void SAL_CALL notifyContextChangeEvent (
82         const css::ui::ContextChangeEventObject& rEvent)
83         throw (cssu::RuntimeException);
84 
85     // XEventListener
86     virtual void SAL_CALL disposing (
87         const css::lang::EventObject& rEvent)
88         throw (cssu::RuntimeException);
89 
90     // XUIElement
91     virtual cssu::Reference<css::frame::XFrame> SAL_CALL getFrame (void)
92         throw(cssu::RuntimeException);
93     virtual ::rtl::OUString SAL_CALL getResourceURL (void)
94         throw(cssu::RuntimeException);
95     virtual sal_Int16 SAL_CALL getType (void)
96         throw(cssu::RuntimeException);
97     virtual cssu::Reference<cssu::XInterface> SAL_CALL getRealInterface (void)
98         throw(cssu::RuntimeException);
99 
100     // XToolPanel
101     virtual cssu::Reference<css::accessibility::XAccessible> SAL_CALL createAccessible (
102         const cssu::Reference<css::accessibility::XAccessible>& rxParentAccessible)
103         throw(cssu::RuntimeException);
104     virtual cssu::Reference<css::awt::XWindow> SAL_CALL getWindow (void)
105         throw(cssu::RuntimeException);
106 
107     // XSidebarPanel
108     virtual css::ui::LayoutSize SAL_CALL getHeightForWidth (sal_Int32 nWidth)
109         throw(cssu::RuntimeException);
110     virtual void SAL_CALL showMenu (void)
111         throw(cssu::RuntimeException);
112     /** Always return <TRUE/> in the assumption that the panel
113         descriptor in the registry has this covered.
114         If a panel needs finer control then it has to overload this
115         method.
116     */
117     virtual sal_Bool SAL_CALL isContextSupported (
118         const ::rtl::OUString& rsApplicationName,
119         const ::rtl::OUString& rsContextName)
120         throw(cssu::RuntimeException);
121 
122 protected:
123     cssu::Reference<css::frame::XFrame> mxFrame;
124 
125     SidebarPanelBase (
126         const ::rtl::OUString& rsResourceURL,
127         const cssu::Reference<css::frame::XFrame>& rxFrame,
128         Window* pWindow,
129         const ::boost::function<void(void)>& rMenuProvider);
130     virtual ~SidebarPanelBase (void);
131 
132     virtual void SAL_CALL disposing (void)
133         throw (cssu::RuntimeException);
134 
135     void SetControl (::Window* pControl);
136     ::Window* GetControl (void) const;
137 
138 private:
139     Window* mpControl;
140     const ::rtl::OUString msResourceURL;
141     const ::boost::function<void(void)> maMenuProvider;
142 };
143 
144 } } // end of namespace sfx2::sidebar
145 
146 #endif
147