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 #include "IContextChangeReceiver.hxx"
27 
28 #include <cppuhelper/compbase4.hxx>
29 #include <cppuhelper/basemutex.hxx>
30 
31 #include <com/sun/star/frame/XController.hpp>
32 #include <com/sun/star/ui/XContextChangeEventListener.hpp>
33 #include <com/sun/star/ui/XUIElement.hpp>
34 #include <com/sun/star/ui/XToolPanel.hpp>
35 #include <com/sun/star/ui/XSidebarPanel.hpp>
36 
37 #include <boost/noncopyable.hpp>
38 #include <boost/function.hpp>
39 
40 
41 namespace css = ::com::sun::star;
42 namespace cssu = ::com::sun::star::uno;
43 
44 
45 class Window;
46 
47 namespace sfx2 { namespace sidebar {
48 
49 namespace
50 {
51     typedef ::cppu::WeakComponentImplHelper4 <
52         css::ui::XContextChangeEventListener,
53         css::ui::XUIElement,
54         css::ui::XToolPanel,
55         css::ui::XSidebarPanel
56         > SidebarPanelBaseInterfaceBase;
57 }
58 
59 /** Base class for sidebar panels that provides some convenience
60     functionality.
61 */
62 class SFX2_DLLPUBLIC SidebarPanelBase
63     : private ::boost::noncopyable,
64       private ::cppu::BaseMutex,
65       public SidebarPanelBaseInterfaceBase
66 {
67 public:
68     static cssu::Reference<css::ui::XUIElement> Create (
69         const ::rtl::OUString& rsResourceURL,
70         const cssu::Reference<css::frame::XFrame>& rxFrame,
71         Window* pControl,
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 
105 protected:
106     cssu::Reference<css::frame::XFrame> mxFrame;
107 
108     SidebarPanelBase (
109         const ::rtl::OUString& rsResourceURL,
110         const cssu::Reference<css::frame::XFrame>& rxFrame,
111         Window* pWindow,
112         const css::ui::LayoutSize& rLayoutSize);
113     virtual ~SidebarPanelBase (void);
114 
115     virtual void SAL_CALL disposing (void)
116         throw (cssu::RuntimeException);
117 
118     void SetControl (::Window* pControl);
119     ::Window* GetControl (void) const;
120 
121 private:
122     Window* mpControl;
123     const ::rtl::OUString msResourceURL;
124     const css::ui::LayoutSize maLayoutSize;
125 };
126 
127 } } // end of namespace sfx2::sidebar
128 
129 #endif
130