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     static cssu::Reference<css::ui::XUIElement> Create (
68         const ::rtl::OUString& rsResourceURL,
69         const cssu::Reference<css::frame::XFrame>& rxFrame,
70         Window* mpWindow,
71         const ::boost::function<void(void)>& rMenuProvider,
72         const css::ui::LayoutSize& rLayoutSize);
73 
74     // XContextChangeEventListener
75     virtual void SAL_CALL notifyContextChangeEvent (
76         const css::ui::ContextChangeEventObject& rEvent)
77         throw (cssu::RuntimeException);
78 
79     // XEventListener
80     virtual void SAL_CALL disposing (
81         const css::lang::EventObject& rEvent)
82         throw (cssu::RuntimeException);
83 
84     // XUIElement
85     virtual cssu::Reference<css::frame::XFrame> SAL_CALL getFrame (void)
86         throw(cssu::RuntimeException);
87     virtual ::rtl::OUString SAL_CALL getResourceURL (void)
88         throw(cssu::RuntimeException);
89     virtual sal_Int16 SAL_CALL getType (void)
90         throw(cssu::RuntimeException);
91     virtual cssu::Reference<cssu::XInterface> SAL_CALL getRealInterface (void)
92         throw(cssu::RuntimeException);
93 
94     // XToolPanel
95     virtual cssu::Reference<css::accessibility::XAccessible> SAL_CALL createAccessible (
96         const cssu::Reference<css::accessibility::XAccessible>& rxParentAccessible)
97         throw(cssu::RuntimeException);
98     virtual cssu::Reference<css::awt::XWindow> SAL_CALL getWindow (void)
99         throw(cssu::RuntimeException);
100 
101     // XSidebarPanel
102     virtual css::ui::LayoutSize SAL_CALL getHeightForWidth (sal_Int32 nWidth)
103         throw(cssu::RuntimeException);
104     virtual void SAL_CALL showMenu (void)
105         throw(cssu::RuntimeException);
106     /** Always return <TRUE/> in the assumption that the panel
107         descriptor in the registry has this covered.
108         If a panel needs finer control then it has to overload this
109         method.
110     */
111     virtual sal_Bool SAL_CALL isContextSupported (
112         const ::rtl::OUString& rsApplicationName,
113         const ::rtl::OUString& rsContextName)
114         throw(cssu::RuntimeException);
115 
116 protected:
117     cssu::Reference<css::frame::XFrame> mxFrame;
118 
119     SidebarPanelBase (
120         const ::rtl::OUString& rsResourceURL,
121         const cssu::Reference<css::frame::XFrame>& rxFrame,
122         Window* pWindow,
123         const ::boost::function<void(void)>& rMenuProvider,
124         const css::ui::LayoutSize& rLayoutSize);
125     virtual ~SidebarPanelBase (void);
126 
127     virtual void SAL_CALL disposing (void)
128         throw (cssu::RuntimeException);
129 
130     void SetControl (::Window* pControl);
131     ::Window* GetControl (void) const;
132 
133 private:
134     Window* mpControl;
135     const ::rtl::OUString msResourceURL;
136     const ::boost::function<void(void)> maMenuProvider;
137     const css::ui::LayoutSize maLayoutSize;
138 };
139 
140 } } // end of namespace sfx2::sidebar
141 
142 #endif
143