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 SD_SIDEBAR_FACTORY_HXX
23 #define SD_SIDEBAR_FACTORY_HXX
24 
25 #include <cppuhelper/compbase4.hxx>
26 #include <cppuhelper/basemutex.hxx>
27 #include <rtl/ref.hxx>
28 #include "framework/Pane.hxx"
29 
30 #include <com/sun/star/ui/XUIElementFactory.hpp>
31 #include <com/sun/star/drawing/framework/XResourceFactory.hpp>
32 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 
36 #include <map>
37 #include <boost/noncopyable.hpp>
38 #include <boost/shared_ptr.hpp>
39 
40 
41 namespace css = ::com::sun::star;
42 namespace cssu = ::com::sun::star::uno;
43 namespace cssdf = ::com::sun::star::drawing::framework;
44 
45 
46 namespace sd {
47     class ViewShellBase;
48 }
49 
50 namespace sd { namespace sidebar {
51 
52 namespace
53 {
54     typedef ::cppu::WeakComponentImplHelper4 <
55         css::lang::XInitialization,
56         css::ui::XUIElementFactory,
57         cssdf::XResourceFactory,
58         css::lang::XEventListener
59         > SidebarFactoryInterfaceBase;
60 }
61 
62 
63 /** This factory creates both XUIElements (for sidebar panels) and
64     a drawing framework pane.
65 
66     The drawing framework pane is a container for the SidebarViewShell
67     which is necessary to run the legacy implementations of the task
68     pane panels.
69 
70     Control and information flow is like this:
71 
72     When one of the old task panels is requested to be displayed in
73     the sidebar this factory is called for
74     XUIElementFactory::createUIElement().
75     One of the arguments, the window, is then exported into the
76     drawing framework as pane.  After this the drawing framework is
77     used to create the SidebarViewShell (once known as
78     TaskPaneViewShell or ToolPanelViewShell) and the requested panel.
79 */
80 class SidebarFactory
81     : private ::boost::noncopyable,
82       private ::cppu::BaseMutex,
83       public SidebarFactoryInterfaceBase
84 {
85 public:
86     static ::rtl::OUString SAL_CALL getImplementationName (void);
87     static cssu::Reference<cssu::XInterface> SAL_CALL createInstance (
88         const cssu::Reference<css::lang::XMultiServiceFactory>& rxFactory);
89     static cssu::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames (void);
90 
91     SidebarFactory (const cssu::Reference<cssu::XComponentContext>& rxContext);
92     virtual ~SidebarFactory (void);
93 
94     virtual void SAL_CALL disposing (void);
95 
96 
97     // XInitialization
98 
99     virtual void SAL_CALL initialize(
100         const css::uno::Sequence<css::uno::Any>& aArguments)
101         throw (css::uno::Exception, css::uno::RuntimeException);
102 
103 
104     // XUIElementFactory
105 
106     cssu::Reference<css::ui::XUIElement> SAL_CALL createUIElement (
107         const ::rtl::OUString& rsResourceURL,
108         const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
109         throw(
110             css::container::NoSuchElementException,
111             css::lang::IllegalArgumentException,
112             cssu::RuntimeException);
113 
114 
115     // XResourceFactory
116 
117     virtual css::uno::Reference<cssdf::XResource>
118         SAL_CALL createResource (
119             const css::uno::Reference<cssdf::XResourceId>& rxPaneId)
120         throw (css::uno::RuntimeException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException);
121     virtual void SAL_CALL
122         releaseResource (
123             const css::uno::Reference<cssdf::XResource>& rxPane)
124         throw (css::uno::RuntimeException);
125 
126 
127     // XEventListener
128 
129     virtual void SAL_CALL disposing (const ::css::lang::EventObject& rEvent)
130         throw(cssu::RuntimeException);
131 
132 private:
133     /** Due to the fact that this class is a factory for both
134         XUIElement and XResource objects, there are different
135         instantiations for the same XController although only one
136         would be really necessary.  This map makes sure that the
137         different object have access to the same information.
138     */
139     class Implementation;
140     typedef ::boost::shared_ptr<Implementation> SharedImplementation;
141     typedef ::std::map<cssu::Reference<css::frame::XController>,SharedImplementation>
142         ControllerToImplementationMap;
143     static ControllerToImplementationMap maControllerToImplementationMap;
144     SharedImplementation mpImplementation;
145 
146     static SharedImplementation GetImplementationForController (
147         const cssu::Reference<css::frame::XController>& rxController);
148 };
149 
150 
151 } } // end of namespace sd::sidebar
152 
153 #endif
154