xref: /AOO41X/main/svx/source/sidebar/PanelFactory.cxx (revision 02c50d825b93d3e4e3bd9073db30bd7615e748eb)
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 #include "sidebar/PanelFactory.hxx"
23 
24 #include "text/TextPropertyPanel.hxx"
25 #include "geometry/AreaPropertyPanel.hxx"
26 #include "geometry/GraphicPropertyPanel.hxx"
27 #include "geometry/LinePropertyPanel.hxx"
28 #include "geometry/TransformationPropertyPanel.hxx"
29 #include "gallery/GalleryControl.hxx"
30 #include <sfx2/sidebar/SidebarPanelBase.hxx>
31 #include <sfx2/sfxbasecontroller.hxx>
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <vcl/window.hxx>
34 #include <rtl/ref.hxx>
35 #include <comphelper/namedvaluecollection.hxx>
36 
37 
38 #include <boost/bind.hpp>
39 
40 
41 using namespace css;
42 using namespace cssu;
43 using ::rtl::OUString;
44 
45 
46 namespace svx { namespace sidebar {
47 
48 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
49 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
50 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
51 
52 
53 ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void)
54 {
55     return A2S(IMPLEMENTATION_NAME);
56 }
57 
58 
59 
60 
61 cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance (
62     const uno::Reference<lang::XMultiServiceFactory>& rxFactory)
63 {
64     (void)rxFactory;
65 
66     ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory());
67     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
68     return xService;
69 }
70 
71 
72 
73 
74 cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void)
75 {
76     cssu::Sequence<OUString> aServiceNames (1);
77     aServiceNames[0] = A2S(SERVICE_NAME);
78     return aServiceNames;
79 
80 }
81 
82 
83 
84 
85 PanelFactory::PanelFactory (void)
86     : PanelFactoryInterfaceBase(m_aMutex)
87 {
88 }
89 
90 
91 
92 
93 PanelFactory::~PanelFactory (void)
94 {
95 }
96 
97 
98 
99 
100 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
101     const ::rtl::OUString& rsResourceURL,
102     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
103     throw(
104         container::NoSuchElementException,
105         lang::IllegalArgumentException,
106         RuntimeException)
107 {
108     Reference<ui::XUIElement> xElement;
109 
110     const ::comphelper::NamedValueCollection aArguments (rArguments);
111     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
112     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
113     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
114     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
115 
116     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
117     if ( ! xParentWindow.is() || pParentWindow==NULL)
118         throw RuntimeException(
119             A2S("PanelFactory::createUIElement called without ParentWindow"),
120             NULL);
121     if ( ! xFrame.is())
122         throw RuntimeException(
123             A2S("PanelFactory::createUIElement called without Frame"),
124             NULL);
125     if (pBindings == NULL)
126         throw RuntimeException(
127             A2S("PanelFactory::createUIElement called without SfxBindings"),
128             NULL);
129 
130 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
131     if (DoesResourceEndWith("/TextPropertyPanel"))
132     {
133         TextPropertyPanel* pPanel = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings);
134         xElement = sfx2::sidebar::SidebarPanelBase::Create(
135             rsResourceURL,
136             xFrame,
137             pPanel,
138             ::boost::bind(&TextPropertyPanel::ShowMenu, pPanel),
139             ui::LayoutSize(-1,-1,-1));
140     }
141     else if (DoesResourceEndWith("/AreaPropertyPanel"))
142     {
143         AreaPropertyPanel* pPanel = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
144         xElement = sfx2::sidebar::SidebarPanelBase::Create(
145             rsResourceURL,
146             xFrame,
147             pPanel,
148             ::boost::bind(&AreaPropertyPanel::ShowMenu, pPanel),
149             ui::LayoutSize(-1,-1,-1));
150     }
151     else if (DoesResourceEndWith("/GraphicPropertyPanel"))
152     {
153         GraphicPropertyPanel* pPanel = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings);
154         xElement = sfx2::sidebar::SidebarPanelBase::Create(
155             rsResourceURL,
156             xFrame,
157             pPanel,
158             ::boost::function<void(void)>(),
159             ui::LayoutSize(-1,-1,-1));
160     }
161     else if (DoesResourceEndWith("/LinePropertyPanel"))
162     {
163         LinePropertyPanel* pPanel = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings);
164         xElement = sfx2::sidebar::SidebarPanelBase::Create(
165             rsResourceURL,
166             xFrame,
167             pPanel,
168             ::boost::bind(&LinePropertyPanel::ShowMenu, pPanel),
169             ui::LayoutSize(-1,-1,-1));
170     }
171     else if (DoesResourceEndWith("/TransformationPropertyPanel"))
172     {
173         TransformationPropertyPanel* pPanel = TransformationPropertyPanel::Create(pParentWindow, xFrame, pBindings);
174         xElement = sfx2::sidebar::SidebarPanelBase::Create(
175             rsResourceURL,
176             xFrame,
177             pPanel,
178             ::boost::bind(&TransformationPropertyPanel::ShowMenu, pPanel),
179             ui::LayoutSize(-1,-1,-1));
180     }
181     else if (DoesResourceEndWith("/GalleryPanel"))
182     {
183         GalleryControl* pGalleryControl = new GalleryControl(
184             pBindings,
185             pParentWindow);
186         xElement = sfx2::sidebar::SidebarPanelBase::Create(
187             rsResourceURL,
188             xFrame,
189             pGalleryControl,
190             ::boost::function<void(void)>(),
191             ui::LayoutSize(300,-1,400));
192     }
193 #undef DoesResourceEndWith
194 
195     return xElement;
196 }
197 
198 } } // end of namespace svx::sidebar
199 
200 // eof
201