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