1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "effect/TextEffectPropertyPanel.hxx"
31 #include "graphic/GraphicPropertyPanel.hxx"
32 #include "line/LinePropertyPanel.hxx"
33 #include "possize/PosSizePropertyPanel.hxx"
34 #include "textcolumns/TextColumnsPropertyPanel.hxx"
35 #include <DefaultShapesPanel.hxx>
36 #if HAVE_FEATURE_AVMEDIA
37 #include "media/MediaPlaybackPanel.hxx"
39 #include <GalleryControl.hxx>
40 #include "EmptyPanel.hxx"
41 #include <sfx2/sidebar/SidebarPanelBase.hxx>
42 #include <sfx2/templdlg.hxx>
43 #include <vcl/weldutils.hxx>
44 #include <comphelper/namedvaluecollection.hxx>
45 #include <comphelper/compbase.hxx>
46 #include <cppuhelper/supportsservice.hxx>
47 #include <com/sun/star/lang/XServiceInfo.hpp>
48 #include <com/sun/star/ui/XSidebar.hpp>
49 #include <com/sun/star/ui/XUIElementFactory.hpp>
50 #include <com/sun/star/uno/XComponentContext.hpp>
53 using namespace css::uno
;
54 using namespace svx::sidebar
;
59 /* Why this is not used ? Doesn't it need to inherit from XServiceInfo ?
60 constexpr OUStringLiteral IMPLEMENTATION_NAME = u"org.apache.openoffice.comp.svx.sidebar.PanelFactory";
61 constexpr OUStringLiteral SERVICE_NAME = u"com.sun.star.ui.UIElementFactory";
64 typedef comphelper::WeakComponentImplHelper
< css::ui::XUIElementFactory
, css::lang::XServiceInfo
>
65 PanelFactoryInterfaceBase
;
68 : public PanelFactoryInterfaceBase
72 PanelFactory(const PanelFactory
&) = delete;
73 PanelFactory
& operator=(const PanelFactory
&) = delete;
76 css::uno::Reference
<css::ui::XUIElement
> SAL_CALL
createUIElement (
77 const OUString
& rsResourceURL
,
78 const ::css::uno::Sequence
<css::beans::PropertyValue
>& rArguments
) override
;
80 OUString SAL_CALL
getImplementationName() override
81 { return u
"org.apache.openoffice.comp.svx.sidebar.PanelFactory"_ustr
; }
83 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
84 { return cppu::supportsService(this, ServiceName
); }
86 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
87 { return {u
"com.sun.star.ui.UIElementFactory"_ustr
}; }
90 PanelFactory::PanelFactory()
94 Reference
<ui::XUIElement
> SAL_CALL
PanelFactory::createUIElement (
95 const OUString
& rsResourceURL
,
96 const ::css::uno::Sequence
<css::beans::PropertyValue
>& rArguments
)
98 const ::comphelper::NamedValueCollection
aArguments (rArguments
);
99 Reference
<frame::XFrame
> xFrame (aArguments
.getOrDefault(u
"Frame"_ustr
, Reference
<frame::XFrame
>()));
100 Reference
<awt::XWindow
> xParentWindow (aArguments
.getOrDefault(u
"ParentWindow"_ustr
, Reference
<awt::XWindow
>()));
101 Reference
<ui::XSidebar
> xSidebar (aArguments
.getOrDefault(u
"Sidebar"_ustr
, Reference
<ui::XSidebar
>()));
102 const sal_uInt64
nBindingsValue (aArguments
.getOrDefault(u
"SfxBindings"_ustr
, sal_uInt64(0)));
103 SfxBindings
* pBindings
= reinterpret_cast<SfxBindings
*>(nBindingsValue
);
105 weld::Widget
* pParent(nullptr);
106 if (weld::TransportAsXWindow
* pTunnel
= dynamic_cast<weld::TransportAsXWindow
*>(xParentWindow
.get()))
107 pParent
= pTunnel
->getWidget();
110 throw RuntimeException(
111 u
"PanelFactory::createUIElement called without ParentWindow"_ustr
,
114 throw RuntimeException(
115 u
"PanelFactory::createUIElement called without Frame"_ustr
,
117 if (pBindings
== nullptr)
118 throw RuntimeException(
119 u
"PanelFactory::createUIElement called without SfxBindings"_ustr
,
122 std::unique_ptr
<PanelLayout
> xControl
;
123 ui::LayoutSize
aLayoutSize (-1,-1,-1);
125 if (rsResourceURL
.endsWith("/TextPropertyPanel"))
127 xControl
= TextPropertyPanel::Create(pParent
, xFrame
);
129 else if (rsResourceURL
.endsWith("/StylesPropertyPanel"))
131 xControl
= StylesPropertyPanel::Create(pParent
, xFrame
);
133 else if (rsResourceURL
.endsWith("/ParaPropertyPanel"))
135 xControl
= ParaPropertyPanel::Create(pParent
, xFrame
, pBindings
, xSidebar
);
137 else if (rsResourceURL
.endsWith("/ListsPropertyPanel"))
139 xControl
= ListsPropertyPanel::Create(pParent
, xFrame
);
141 else if (rsResourceURL
.endsWith("/AreaPropertyPanel"))
143 xControl
= AreaPropertyPanel::Create(pParent
, xFrame
, pBindings
);
145 else if (rsResourceURL
.endsWith("/FontworkPropertyPanel"))
147 xControl
= FontworkPropertyPanel::Create(pParent
, xFrame
);
149 else if (rsResourceURL
.endsWith("/ShadowPropertyPanel"))
151 xControl
= ShadowPropertyPanel::Create(pParent
, pBindings
);
153 else if (rsResourceURL
.endsWith("/EffectPropertyPanel"))
155 xControl
= EffectPropertyPanel::Create(pParent
, pBindings
);
157 else if (rsResourceURL
.endsWith("/TextEffectPropertyPanel"))
159 xControl
= TextEffectPropertyPanel::Create(pParent
, pBindings
);
161 else if (rsResourceURL
.endsWith("/GraphicPropertyPanel"))
163 xControl
= GraphicPropertyPanel::Create(pParent
, pBindings
);
165 else if (rsResourceURL
.endsWith("/LinePropertyPanel"))
167 xControl
= LinePropertyPanel::Create(pParent
, xFrame
, pBindings
);
169 else if (rsResourceURL
.endsWith("/PosSizePropertyPanel"))
171 xControl
= PosSizePropertyPanel::Create(pParent
, xFrame
, pBindings
, xSidebar
);
173 else if (rsResourceURL
.endsWith("/DefaultShapesPanel"))
175 xControl
= DefaultShapesPanel::Create(pParent
, xFrame
);
177 #if HAVE_FEATURE_AVMEDIA
178 else if (rsResourceURL
.endsWith("/MediaPlaybackPanel"))
180 xControl
= MediaPlaybackPanel::Create(pParent
, pBindings
);
183 else if (rsResourceURL
.endsWith("/GalleryPanel"))
185 xControl
= std::make_unique
<GalleryControl
>(pParent
);
186 aLayoutSize
= ui::LayoutSize(300,-1,400);
188 else if (rsResourceURL
.endsWith("/StyleListPanel"))
190 xControl
= std::make_unique
<SfxTemplatePanelControl
>(pBindings
, pParent
);
191 aLayoutSize
= ui::LayoutSize(0,-1,-1);
193 else if (rsResourceURL
.endsWith("/EmptyPanel"))
195 xControl
= std::make_unique
<EmptyPanel
>(pParent
);
196 aLayoutSize
= ui::LayoutSize(20,-1, 50);
198 else if (rsResourceURL
.endsWith("/TextColumnsPropertyPanel"))
200 xControl
= TextColumnsPropertyPanel::Create(pParent
, pBindings
);
205 return sfx2::sidebar::SidebarPanelBase::Create(
212 return Reference
<ui::XUIElement
>();
217 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
218 org_apache_openoffice_comp_svx_sidebar_PanelFactory_get_implementation(
219 css::uno::XComponentContext
*,
220 css::uno::Sequence
<css::uno::Any
> const &)
222 return cppu::acquire(new PanelFactory
);
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */