Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sidebar / PanelFactory.cxx
blobf55575d1ab97ca6624dfc5d3ba008156257ac27a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include "text/TextPropertyPanel.hxx"
23 #include "styles/StylesPropertyPanel.hxx"
24 #include "paragraph/ParaPropertyPanel.hxx"
25 #include "lists/ListsPropertyPanel.hxx"
26 #include "area/AreaPropertyPanel.hxx"
27 #include "fontwork/FontworkPropertyPanel.hxx"
28 #include "shadow/ShadowPropertyPanel.hxx"
29 #include "effect/EffectPropertyPanel.hxx"
30 #include "graphic/GraphicPropertyPanel.hxx"
31 #include "line/LinePropertyPanel.hxx"
32 #include "possize/PosSizePropertyPanel.hxx"
33 #include "textcolumns/TextColumnsPropertyPanel.hxx"
34 #include <DefaultShapesPanel.hxx>
35 #if HAVE_FEATURE_AVMEDIA
36 #include "media/MediaPlaybackPanel.hxx"
37 #endif
38 #include <GalleryControl.hxx>
39 #include "EmptyPanel.hxx"
40 #include <sfx2/sidebar/SidebarPanelBase.hxx>
41 #include <sfx2/templdlg.hxx>
42 #include <vcl/weldutils.hxx>
43 #include <comphelper/namedvaluecollection.hxx>
44 #include <comphelper/compbase.hxx>
45 #include <cppuhelper/supportsservice.hxx>
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/ui/XSidebar.hpp>
48 #include <com/sun/star/ui/XUIElementFactory.hpp>
49 #include <com/sun/star/uno/XComponentContext.hpp>
51 using namespace css;
52 using namespace css::uno;
53 using namespace svx::sidebar;
56 namespace {
58 /* Why this is not used ? Doesn't it need to inherit from XServiceInfo ?
59 constexpr OUStringLiteral IMPLEMENTATION_NAME = u"org.apache.openoffice.comp.svx.sidebar.PanelFactory";
60 constexpr OUStringLiteral SERVICE_NAME = u"com.sun.star.ui.UIElementFactory";
63 typedef comphelper::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo >
64 PanelFactoryInterfaceBase;
66 class PanelFactory
67 : public PanelFactoryInterfaceBase
69 public:
70 PanelFactory();
71 PanelFactory(const PanelFactory&) = delete;
72 PanelFactory& operator=(const PanelFactory&) = delete;
74 // XUIElementFactory
75 css::uno::Reference<css::ui::XUIElement> SAL_CALL createUIElement (
76 const OUString& rsResourceURL,
77 const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments) override;
79 OUString SAL_CALL getImplementationName() override
80 { return "org.apache.openoffice.comp.svx.sidebar.PanelFactory"; }
82 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
83 { return cppu::supportsService(this, ServiceName); }
85 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
86 { return {"com.sun.star.ui.UIElementFactory"}; }
89 PanelFactory::PanelFactory()
93 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
94 const OUString& rsResourceURL,
95 const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
97 const ::comphelper::NamedValueCollection aArguments (rArguments);
98 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
99 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
100 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
101 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
102 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
104 weld::Widget* pParent(nullptr);
105 if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
106 pParent = pTunnel->getWidget();
108 if (!pParent)
109 throw RuntimeException(
110 "PanelFactory::createUIElement called without ParentWindow",
111 nullptr);
112 if ( ! xFrame.is())
113 throw RuntimeException(
114 "PanelFactory::createUIElement called without Frame",
115 nullptr);
116 if (pBindings == nullptr)
117 throw RuntimeException(
118 "PanelFactory::createUIElement called without SfxBindings",
119 nullptr);
121 std::unique_ptr<PanelLayout> xControl;
122 ui::LayoutSize aLayoutSize (-1,-1,-1);
124 if (rsResourceURL.endsWith("/TextPropertyPanel"))
126 xControl = TextPropertyPanel::Create(pParent, xFrame);
128 else if (rsResourceURL.endsWith("/StylesPropertyPanel"))
130 xControl = StylesPropertyPanel::Create(pParent, xFrame);
132 else if (rsResourceURL.endsWith("/ParaPropertyPanel"))
134 xControl = ParaPropertyPanel::Create(pParent, xFrame, pBindings, xSidebar);
136 else if (rsResourceURL.endsWith("/ListsPropertyPanel"))
138 xControl = ListsPropertyPanel::Create(pParent, xFrame);
140 else if (rsResourceURL.endsWith("/AreaPropertyPanel"))
142 xControl = AreaPropertyPanel::Create(pParent, xFrame, pBindings);
144 else if (rsResourceURL.endsWith("/FontworkPropertyPanel"))
146 xControl = FontworkPropertyPanel::Create(pParent, xFrame);
148 else if (rsResourceURL.endsWith("/ShadowPropertyPanel"))
150 xControl = ShadowPropertyPanel::Create(pParent, pBindings);
152 else if (rsResourceURL.endsWith("/EffectPropertyPanel"))
154 xControl = EffectPropertyPanel::Create(pParent, pBindings);
156 else if (rsResourceURL.endsWith("/GraphicPropertyPanel"))
158 xControl = GraphicPropertyPanel::Create(pParent, pBindings);
160 else if (rsResourceURL.endsWith("/LinePropertyPanel"))
162 xControl = LinePropertyPanel::Create(pParent, xFrame, pBindings);
164 else if (rsResourceURL.endsWith("/PosSizePropertyPanel"))
166 xControl = PosSizePropertyPanel::Create(pParent, xFrame, pBindings, xSidebar);
168 else if (rsResourceURL.endsWith("/DefaultShapesPanel"))
170 xControl = DefaultShapesPanel::Create(pParent, xFrame);
172 #if HAVE_FEATURE_AVMEDIA
173 else if (rsResourceURL.endsWith("/MediaPlaybackPanel"))
175 xControl = MediaPlaybackPanel::Create(pParent, pBindings);
177 #endif
178 else if (rsResourceURL.endsWith("/GalleryPanel"))
180 xControl = std::make_unique<GalleryControl>(pParent);
181 aLayoutSize = ui::LayoutSize(300,-1,400);
183 else if (rsResourceURL.endsWith("/StyleListPanel"))
185 xControl = std::make_unique<SfxTemplatePanelControl>(pBindings, pParent);
186 aLayoutSize = ui::LayoutSize(0,-1,-1);
188 else if (rsResourceURL.endsWith("/EmptyPanel"))
190 xControl = std::make_unique<EmptyPanel>(pParent);
191 aLayoutSize = ui::LayoutSize(20,-1, 50);
193 else if (rsResourceURL.endsWith("/TextColumnsPropertyPanel"))
195 xControl = TextColumnsPropertyPanel::Create(pParent, pBindings);
198 if (xControl)
200 return sfx2::sidebar::SidebarPanelBase::Create(
201 rsResourceURL,
202 xFrame,
203 std::move(xControl),
204 aLayoutSize);
206 else
207 return Reference<ui::XUIElement>();
212 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
213 org_apache_openoffice_comp_svx_sidebar_PanelFactory_get_implementation(
214 css::uno::XComponentContext *,
215 css::uno::Sequence<css::uno::Any> const &)
217 return cppu::acquire(new PanelFactory);
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */