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