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