xref: /trunk/main/sw/source/ui/sidebar/SwPanelFactory.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 {
93     Reference<ui::XUIElement> xElement;
94 
95     const ::comphelper::NamedValueCollection aArguments (rArguments);
96     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
97     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
98     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
99     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
100 
101     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
102     if ( ! xParentWindow.is() || pParentWindow==NULL)
103         throw RuntimeException(
104             A2S("PanelFactory::createUIElement called without ParentWindow"),
105             NULL);
106     if ( ! xFrame.is())
107         throw RuntimeException(
108             A2S("PanelFactory::createUIElement called without Frame"),
109             NULL);
110     if (pBindings == NULL)
111         throw RuntimeException(
112             A2S("PanelFactory::createUIElement called without SfxBindings"),
113             NULL);
114 
115 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
116     if (DoesResourceEndWith("/PagePropertyPanel"))
117     {
118         PagePropertyPanel* pPanel = PagePropertyPanel::Create( pParentWindow, xFrame, pBindings );
119         xElement = sfx2::sidebar::SidebarPanelBase::Create(
120             rsResourceURL,
121             xFrame,
122             pPanel,
123             ui::LayoutSize(-1,-1,-1));
124     }
125     else if (DoesResourceEndWith("/WrapPropertyPanel"))
126     {
127         WrapPropertyPanel* pPanel = WrapPropertyPanel::Create( pParentWindow, xFrame, pBindings );
128         xElement = sfx2::sidebar::SidebarPanelBase::Create(
129             rsResourceURL,
130             xFrame,
131             pPanel,
132             ui::LayoutSize(-1,-1,-1));
133     }
134     else if (DoesResourceEndWith("/NavigatorPanel"))
135     {
136         Window* pPanel = new SwNavigationPI(pBindings, NULL, pParentWindow);
137         xElement = sfx2::sidebar::SidebarPanelBase::Create(
138             rsResourceURL,
139             xFrame,
140             pPanel,
141             ui::LayoutSize(0,-1,-1));
142     }
143 #undef DoesResourceEndWith
144 
145     return xElement;
146 }
147 
148 } } // end of namespace sw::sidebar
149 
150 /* vim: set noet sw=4 ts=4: */
151