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