update credits
[LibreOffice.git] / sw / source / ui / sidebar / SwPanelFactory.cxx
blobc03178316bac4aeb577f6645287eddfbb7b42db6
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "SwPanelFactory.hxx"
21 #include <PagePropertyPanel.hxx>
22 #include <WrapPropertyPanel.hxx>
23 #include <navipi.hxx>
25 #include <sfx2/sidebar/SidebarPanelBase.hxx>
26 #include <sfx2/sfxbasecontroller.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <vcl/window.hxx>
29 #include <rtl/ref.hxx>
30 #include <comphelper/namedvaluecollection.hxx>
32 #include <boost/bind.hpp>
35 using namespace css;
36 using namespace cssu;
37 using ::rtl::OUString;
40 namespace sw { namespace sidebar {
42 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
43 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.sw.sidebar.SwPanelFactory"
44 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
47 ::rtl::OUString SAL_CALL SwPanelFactory::getImplementationName (void)
49 return A2S(IMPLEMENTATION_NAME);
53 cssu::Reference<cssu::XInterface> SAL_CALL SwPanelFactory::createInstance(
54 const uno::Reference<lang::XMultiServiceFactory>& )
56 ::rtl::Reference<SwPanelFactory> pPanelFactory (new SwPanelFactory());
57 cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
58 return xService;
62 cssu::Sequence<OUString> SAL_CALL SwPanelFactory::getSupportedServiceNames (void)
64 cssu::Sequence<OUString> aServiceNames (1);
65 aServiceNames[0] = A2S(SERVICE_NAME);
66 return aServiceNames;
71 SwPanelFactory::SwPanelFactory (void)
72 : PanelFactoryInterfaceBase(m_aMutex)
77 SwPanelFactory::~SwPanelFactory (void)
82 Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
83 const ::rtl::OUString& rsResourceURL,
84 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
85 throw(
86 container::NoSuchElementException,
87 lang::IllegalArgumentException,
88 RuntimeException)
90 Reference<ui::XUIElement> xElement;
92 const ::comphelper::NamedValueCollection aArguments (rArguments);
93 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
94 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
95 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
96 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
98 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
99 if ( ! xParentWindow.is() || pParentWindow==NULL)
100 throw RuntimeException(
101 A2S("PanelFactory::createUIElement called without ParentWindow"),
102 NULL);
103 if ( ! xFrame.is())
104 throw RuntimeException(
105 A2S("PanelFactory::createUIElement called without Frame"),
106 NULL);
107 if (pBindings == NULL)
108 throw RuntimeException(
109 A2S("PanelFactory::createUIElement called without SfxBindings"),
110 NULL);
112 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
113 if (DoesResourceEndWith("/PagePropertyPanel"))
115 PagePropertyPanel* pPanel = PagePropertyPanel::Create( pParentWindow, xFrame, pBindings );
116 xElement = sfx2::sidebar::SidebarPanelBase::Create(
117 rsResourceURL,
118 xFrame,
119 pPanel,
120 ui::LayoutSize(-1,-1,-1));
122 else if (DoesResourceEndWith("/WrapPropertyPanel"))
124 WrapPropertyPanel* pPanel = WrapPropertyPanel::Create( pParentWindow, xFrame, pBindings );
125 xElement = sfx2::sidebar::SidebarPanelBase::Create(
126 rsResourceURL,
127 xFrame,
128 pPanel,
129 ui::LayoutSize(-1,-1,-1));
131 else if (DoesResourceEndWith("/NavigatorPanel"))
133 Window* pPanel = new SwNavigationPI(pBindings, NULL, pParentWindow);
134 xElement = sfx2::sidebar::SidebarPanelBase::Create(
135 rsResourceURL,
136 xFrame,
137 pPanel,
138 ui::LayoutSize(0,-1,-1));
140 #undef DoesResourceEndWith
142 return xElement;
145 } } // end of namespace sw::sidebar
147 // eof