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 "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"
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 <cppuhelper/basemutex.hxx>
45 #include <cppuhelper/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 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
61 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
64 typedef ::cppu::WeakComponentImplHelper
< css::ui::XUIElementFactory
, css::lang::XServiceInfo
>
65 PanelFactoryInterfaceBase
;
68 : private ::cppu::BaseMutex
,
69 public PanelFactoryInterfaceBase
73 PanelFactory(const PanelFactory
&) = delete;
74 PanelFactory
& operator=(const PanelFactory
&) = delete;
77 css::uno::Reference
<css::ui::XUIElement
> SAL_CALL
createUIElement (
78 const OUString
& rsResourceURL
,
79 const ::css::uno::Sequence
<css::beans::PropertyValue
>& rArguments
) override
;
81 OUString SAL_CALL
getImplementationName() override
82 { return "org.apache.openoffice.comp.svx.sidebar.PanelFactory"; }
84 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
85 { return cppu::supportsService(this, ServiceName
); }
87 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
88 { return {"com.sun.star.ui.UIElementFactory"}; }
91 PanelFactory::PanelFactory()
92 : PanelFactoryInterfaceBase(m_aMutex
)
96 Reference
<ui::XUIElement
> SAL_CALL
PanelFactory::createUIElement (
97 const OUString
& rsResourceURL
,
98 const ::css::uno::Sequence
<css::beans::PropertyValue
>& rArguments
)
100 const ::comphelper::NamedValueCollection
aArguments (rArguments
);
101 Reference
<frame::XFrame
> xFrame (aArguments
.getOrDefault("Frame", Reference
<frame::XFrame
>()));
102 Reference
<awt::XWindow
> xParentWindow (aArguments
.getOrDefault("ParentWindow", Reference
<awt::XWindow
>()));
103 Reference
<ui::XSidebar
> xSidebar (aArguments
.getOrDefault("Sidebar", Reference
<ui::XSidebar
>()));
104 const sal_uInt64
nBindingsValue (aArguments
.getOrDefault("SfxBindings", sal_uInt64(0)));
105 SfxBindings
* pBindings
= reinterpret_cast<SfxBindings
*>(nBindingsValue
);
107 weld::Widget
* pParent(nullptr);
108 if (weld::TransportAsXWindow
* pTunnel
= dynamic_cast<weld::TransportAsXWindow
*>(xParentWindow
.get()))
109 pParent
= pTunnel
->getWidget();
112 throw RuntimeException(
113 "PanelFactory::createUIElement called without ParentWindow",
116 throw RuntimeException(
117 "PanelFactory::createUIElement called without Frame",
119 if (pBindings
== nullptr)
120 throw RuntimeException(
121 "PanelFactory::createUIElement called without SfxBindings",
124 std::unique_ptr
<PanelLayout
> xControl
;
125 ui::LayoutSize
aLayoutSize (-1,-1,-1);
127 if (rsResourceURL
.endsWith("/TextPropertyPanel"))
129 xControl
= TextPropertyPanel::Create(pParent
, xFrame
);
131 else if (rsResourceURL
.endsWith("/StylesPropertyPanel"))
133 xControl
= StylesPropertyPanel::Create(pParent
, xFrame
);
135 else if (rsResourceURL
.endsWith("/ParaPropertyPanel"))
137 xControl
= ParaPropertyPanel::Create(pParent
, xFrame
, pBindings
, xSidebar
);
139 else if (rsResourceURL
.endsWith("/ListsPropertyPanel"))
141 xControl
= ListsPropertyPanel::Create(pParent
, xFrame
);
143 else if (rsResourceURL
.endsWith("/AreaPropertyPanel"))
145 xControl
= AreaPropertyPanel::Create(pParent
, xFrame
, pBindings
);
147 else if (rsResourceURL
.endsWith("/FontworkPropertyPanel"))
149 xControl
= FontworkPropertyPanel::Create(pParent
, xFrame
);
151 else if (rsResourceURL
.endsWith("/ShadowPropertyPanel"))
153 xControl
= ShadowPropertyPanel::Create(pParent
, pBindings
);
155 else if (rsResourceURL
.endsWith("/EffectPropertyPanel"))
157 xControl
= EffectPropertyPanel::Create(pParent
, pBindings
);
159 else if (rsResourceURL
.endsWith("/GraphicPropertyPanel"))
161 xControl
= GraphicPropertyPanel::Create(pParent
, pBindings
);
163 else if (rsResourceURL
.endsWith("/LinePropertyPanel"))
165 xControl
= LinePropertyPanel::Create(pParent
, xFrame
, pBindings
);
167 else if (rsResourceURL
.endsWith("/PosSizePropertyPanel"))
169 xControl
= PosSizePropertyPanel::Create(pParent
, xFrame
, pBindings
, xSidebar
);
171 else if (rsResourceURL
.endsWith("/DefaultShapesPanel"))
173 xControl
= DefaultShapesPanel::Create(pParent
, xFrame
);
175 #if HAVE_FEATURE_AVMEDIA
176 else if (rsResourceURL
.endsWith("/MediaPlaybackPanel"))
178 xControl
= MediaPlaybackPanel::Create(pParent
, pBindings
);
181 else if (rsResourceURL
.endsWith("/GalleryPanel"))
183 xControl
= std::make_unique
<GalleryControl
>(pParent
);
184 aLayoutSize
= ui::LayoutSize(300,-1,400);
186 else if (rsResourceURL
.endsWith("/StyleListPanel"))
188 xControl
= std::make_unique
<SfxTemplatePanelControl
>(pBindings
, pParent
);
189 aLayoutSize
= ui::LayoutSize(0,-1,-1);
191 else if (rsResourceURL
.endsWith("/EmptyPanel"))
193 xControl
= std::make_unique
<EmptyPanel
>(pParent
);
194 aLayoutSize
= ui::LayoutSize(20,-1, 50);
196 else if (rsResourceURL
.endsWith("/TextColumnsPropertyPanel"))
198 xControl
= TextColumnsPropertyPanel::Create(pParent
, pBindings
);
203 return sfx2::sidebar::SidebarPanelBase::Create(
210 return Reference
<ui::XUIElement
>();
215 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
216 org_apache_openoffice_comp_svx_sidebar_PanelFactory_get_implementation(
217 css::uno::XComponentContext
*,
218 css::uno::Sequence
<css::uno::Any
> const &)
220 return cppu::acquire(new PanelFactory
);
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */