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 "shadow/ShadowPropertyPanel.hxx"
28 #include "effect/EffectPropertyPanel.hxx"
29 #include "graphic/GraphicPropertyPanel.hxx"
30 #include "line/LinePropertyPanel.hxx"
31 #include "possize/PosSizePropertyPanel.hxx"
32 #include <DefaultShapesPanel.hxx>
33 #if HAVE_FEATURE_AVMEDIA
34 #include "media/MediaPlaybackPanel.hxx"
36 #include <GalleryControl.hxx>
37 #include "EmptyPanel.hxx"
38 #include <sfx2/sidebar/SidebarPanelBase.hxx>
39 #include <sfx2/templdlg.hxx>
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <vcl/window.hxx>
42 #include <comphelper/namedvaluecollection.hxx>
43 #include <cppuhelper/basemutex.hxx>
44 #include <cppuhelper/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>
52 using namespace css::uno
;
53 using namespace svx::sidebar
;
58 /* Why this is not used ? Doesn't it need to inherit from XServiceInfo ?
59 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
60 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
63 typedef ::cppu::WeakComponentImplHelper
< css::ui::XUIElementFactory
, css::lang::XServiceInfo
>
64 PanelFactoryInterfaceBase
;
67 : private ::cppu::BaseMutex
,
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 "org.apache.openoffice.comp.svx.sidebar.PanelFactory"; }
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 {"com.sun.star.ui.UIElementFactory"}; }
90 PanelFactory::PanelFactory()
91 : PanelFactoryInterfaceBase(m_aMutex
)
95 Reference
<ui::XUIElement
> SAL_CALL
PanelFactory::createUIElement (
96 const OUString
& rsResourceURL
,
97 const ::css::uno::Sequence
<css::beans::PropertyValue
>& rArguments
)
99 const ::comphelper::NamedValueCollection
aArguments (rArguments
);
100 Reference
<frame::XFrame
> xFrame (aArguments
.getOrDefault("Frame", Reference
<frame::XFrame
>()));
101 Reference
<awt::XWindow
> xParentWindow (aArguments
.getOrDefault("ParentWindow", Reference
<awt::XWindow
>()));
102 Reference
<ui::XSidebar
> xSidebar (aArguments
.getOrDefault("Sidebar", Reference
<ui::XSidebar
>()));
103 const sal_uInt64
nBindingsValue (aArguments
.getOrDefault("SfxBindings", sal_uInt64(0)));
104 SfxBindings
* pBindings
= reinterpret_cast<SfxBindings
*>(nBindingsValue
);
106 VclPtr
<vcl::Window
> pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
107 if ( ! xParentWindow
.is() || pParentWindow
==nullptr)
108 throw RuntimeException(
109 "PanelFactory::createUIElement called without ParentWindow",
112 throw RuntimeException(
113 "PanelFactory::createUIElement called without Frame",
115 if (pBindings
== nullptr)
116 throw RuntimeException(
117 "PanelFactory::createUIElement called without SfxBindings",
120 VclPtr
<vcl::Window
> pControl
;
121 ui::LayoutSize
aLayoutSize (-1,-1,-1);
123 if (rsResourceURL
.endsWith("/TextPropertyPanel"))
125 pControl
= TextPropertyPanel::Create(pParentWindow
, xFrame
);
127 else if (rsResourceURL
.endsWith("/StylesPropertyPanel"))
129 pControl
= StylesPropertyPanel::Create(pParentWindow
, xFrame
);
131 else if (rsResourceURL
.endsWith("/ParaPropertyPanel"))
133 pControl
= ParaPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
, xSidebar
);
135 else if (rsResourceURL
.endsWith("/ListsPropertyPanel"))
137 pControl
= ListsPropertyPanel::Create(pParentWindow
, xFrame
);
139 else if (rsResourceURL
.endsWith("/AreaPropertyPanel"))
141 pControl
= AreaPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
143 else if (rsResourceURL
.endsWith("/ShadowPropertyPanel"))
145 pControl
= ShadowPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
147 else if (rsResourceURL
.endsWith("/EffectPropertyPanel"))
149 pControl
= EffectPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
151 else if (rsResourceURL
.endsWith("/GraphicPropertyPanel"))
153 pControl
= GraphicPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
155 else if (rsResourceURL
.endsWith("/LinePropertyPanel"))
157 pControl
= LinePropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
159 else if (rsResourceURL
.endsWith("/PosSizePropertyPanel"))
161 pControl
= PosSizePropertyPanel::Create(pParentWindow
, xFrame
, pBindings
, xSidebar
);
163 else if (rsResourceURL
.endsWith("/DefaultShapesPanel"))
165 pControl
= DefaultShapesPanel::Create(pParentWindow
, xFrame
);
167 #if HAVE_FEATURE_AVMEDIA
168 else if (rsResourceURL
.endsWith("/MediaPlaybackPanel"))
170 pControl
= MediaPlaybackPanel::Create(pParentWindow
, xFrame
, pBindings
);
173 else if (rsResourceURL
.endsWith("/GalleryPanel"))
175 pControl
.reset(VclPtr
<GalleryControl
>::Create(pParentWindow
));
176 aLayoutSize
= ui::LayoutSize(300,-1,400);
178 else if (rsResourceURL
.endsWith("/StyleListPanel"))
180 pControl
.reset(VclPtr
<SfxTemplatePanelControl
>::Create(pBindings
, pParentWindow
));
181 aLayoutSize
= ui::LayoutSize(0,-1,-1);
183 else if (rsResourceURL
.endsWith("/EmptyPanel"))
185 pControl
.reset(VclPtr
<EmptyPanel
>::Create(pParentWindow
));
186 aLayoutSize
= ui::LayoutSize(20,-1, 50);
191 return sfx2::sidebar::SidebarPanelBase::Create(
198 return Reference
<ui::XUIElement
>();
203 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
204 org_apache_openoffice_comp_svx_sidebar_PanelFactory_get_implementation(
205 css::uno::XComponentContext
*,
206 css::uno::Sequence
<css::uno::Any
> const &)
208 return cppu::acquire(new PanelFactory
);
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */