/src/libreoffice/svx/source/sidebar/PanelFactory.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <config_features.h> |
21 | | |
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" |
38 | | #endif |
39 | | #include <GalleryControl.hxx> |
40 | | #include "EmptyPanel.hxx" |
41 | | #include <sfx2/sidebar/SidebarPanelBase.hxx> |
42 | | #include <sfx2/templdlg.hxx> |
43 | | #include <vcl/weld/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> |
51 | | |
52 | | using namespace css; |
53 | | using namespace css::uno; |
54 | | using namespace svx::sidebar; |
55 | | |
56 | | |
57 | | namespace { |
58 | | |
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"; |
62 | | */ |
63 | | |
64 | | typedef comphelper::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo > |
65 | | PanelFactoryInterfaceBase; |
66 | | |
67 | | class PanelFactory |
68 | | : public PanelFactoryInterfaceBase |
69 | | { |
70 | | public: |
71 | | PanelFactory(); |
72 | | PanelFactory(const PanelFactory&) = delete; |
73 | | PanelFactory& operator=(const PanelFactory&) = delete; |
74 | | |
75 | | // XUIElementFactory |
76 | | css::uno::Reference<css::ui::XUIElement> SAL_CALL createUIElement ( |
77 | | const OUString& rsResourceURL, |
78 | | const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments) override; |
79 | | |
80 | | OUString SAL_CALL getImplementationName() override |
81 | 0 | { return u"org.apache.openoffice.comp.svx.sidebar.PanelFactory"_ustr; } |
82 | | |
83 | | sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override |
84 | 0 | { return cppu::supportsService(this, ServiceName); } |
85 | | |
86 | | css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override |
87 | 0 | { return {u"com.sun.star.ui.UIElementFactory"_ustr}; } |
88 | | }; |
89 | | |
90 | | PanelFactory::PanelFactory() |
91 | 0 | { |
92 | 0 | } |
93 | | |
94 | | Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( |
95 | | const OUString& rsResourceURL, |
96 | | const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments) |
97 | 0 | { |
98 | 0 | const ::comphelper::NamedValueCollection aArguments (rArguments); |
99 | 0 | Reference<frame::XFrame> xFrame(sfx2::sidebar::GetFrame(aArguments)); |
100 | 0 | Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault(u"ParentWindow"_ustr, Reference<awt::XWindow>())); |
101 | 0 | Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault(u"Sidebar"_ustr, Reference<ui::XSidebar>())); |
102 | 0 | const sal_uInt64 nBindingsValue (aArguments.getOrDefault(u"SfxBindings"_ustr, sal_uInt64(0))); |
103 | 0 | SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); |
104 | |
|
105 | 0 | weld::Widget* pParent(nullptr); |
106 | 0 | if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get())) |
107 | 0 | pParent = pTunnel->getWidget(); |
108 | |
|
109 | 0 | if (!pParent) |
110 | 0 | throw RuntimeException( |
111 | 0 | u"PanelFactory::createUIElement called without ParentWindow"_ustr, |
112 | 0 | nullptr); |
113 | 0 | if ( ! xFrame.is()) |
114 | 0 | throw RuntimeException( |
115 | 0 | u"PanelFactory::createUIElement called without Frame"_ustr, |
116 | 0 | nullptr); |
117 | 0 | if (pBindings == nullptr) |
118 | 0 | throw RuntimeException( |
119 | 0 | u"PanelFactory::createUIElement called without SfxBindings"_ustr, |
120 | 0 | nullptr); |
121 | | |
122 | 0 | std::unique_ptr<PanelLayout> xControl; |
123 | 0 | ui::LayoutSize aLayoutSize (-1,-1,-1); |
124 | |
|
125 | 0 | if (rsResourceURL.endsWith("/TextPropertyPanel")) |
126 | 0 | { |
127 | 0 | xControl = TextPropertyPanel::Create(pParent, xFrame); |
128 | 0 | } |
129 | 0 | else if (rsResourceURL.endsWith("/StylesPropertyPanel")) |
130 | 0 | { |
131 | 0 | xControl = StylesPropertyPanel::Create(pParent, xFrame); |
132 | 0 | } |
133 | 0 | else if (rsResourceURL.endsWith("/ParaPropertyPanel")) |
134 | 0 | { |
135 | 0 | xControl = ParaPropertyPanel::Create(pParent, xFrame, pBindings, xSidebar); |
136 | 0 | } |
137 | 0 | else if (rsResourceURL.endsWith("/ListsPropertyPanel")) |
138 | 0 | { |
139 | 0 | xControl = ListsPropertyPanel::Create(pParent, xFrame); |
140 | 0 | } |
141 | 0 | else if (rsResourceURL.endsWith("/AreaPropertyPanel")) |
142 | 0 | { |
143 | 0 | xControl = AreaPropertyPanel::Create(pParent, xFrame, pBindings); |
144 | 0 | } |
145 | 0 | else if (rsResourceURL.endsWith("/FontworkPropertyPanel")) |
146 | 0 | { |
147 | 0 | xControl = FontworkPropertyPanel::Create(pParent, xFrame); |
148 | 0 | } |
149 | 0 | else if (rsResourceURL.endsWith("/ShadowPropertyPanel")) |
150 | 0 | { |
151 | 0 | xControl = ShadowPropertyPanel::Create(pParent, pBindings); |
152 | 0 | } |
153 | 0 | else if (rsResourceURL.endsWith("/EffectPropertyPanel")) |
154 | 0 | { |
155 | 0 | xControl = EffectPropertyPanel::Create(pParent, pBindings); |
156 | 0 | } |
157 | 0 | else if (rsResourceURL.endsWith("/TextEffectPropertyPanel")) |
158 | 0 | { |
159 | 0 | xControl = TextEffectPropertyPanel::Create(pParent, pBindings); |
160 | 0 | } |
161 | 0 | else if (rsResourceURL.endsWith("/GraphicPropertyPanel")) |
162 | 0 | { |
163 | 0 | xControl = GraphicPropertyPanel::Create(pParent, pBindings); |
164 | 0 | } |
165 | 0 | else if (rsResourceURL.endsWith("/LinePropertyPanel")) |
166 | 0 | { |
167 | 0 | xControl = LinePropertyPanel::Create(pParent, xFrame, pBindings); |
168 | 0 | } |
169 | 0 | else if (rsResourceURL.endsWith("/PosSizePropertyPanel")) |
170 | 0 | { |
171 | 0 | xControl = PosSizePropertyPanel::Create(pParent, xFrame, pBindings, xSidebar); |
172 | 0 | } |
173 | 0 | else if (rsResourceURL.endsWith("/DefaultShapesPanel")) |
174 | 0 | { |
175 | 0 | xControl = DefaultShapesPanel::Create(pParent, xFrame); |
176 | 0 | } |
177 | 0 | #if HAVE_FEATURE_AVMEDIA |
178 | 0 | else if (rsResourceURL.endsWith("/MediaPlaybackPanel")) |
179 | 0 | { |
180 | 0 | xControl = MediaPlaybackPanel::Create(pParent, pBindings); |
181 | 0 | } |
182 | 0 | #endif |
183 | 0 | else if (rsResourceURL.endsWith("/GalleryPanel")) |
184 | 0 | { |
185 | 0 | xControl = std::make_unique<GalleryControl>(pParent); |
186 | 0 | aLayoutSize = ui::LayoutSize(300,-1,400); |
187 | 0 | } |
188 | 0 | else if (rsResourceURL.endsWith("/StyleListPanel")) |
189 | 0 | { |
190 | 0 | xControl = std::make_unique<SfxTemplatePanelControl>(pBindings, pParent); |
191 | 0 | aLayoutSize = ui::LayoutSize(0,-1,-1); |
192 | 0 | } |
193 | 0 | else if (rsResourceURL.endsWith("/EmptyPanel")) |
194 | 0 | { |
195 | 0 | xControl = std::make_unique<EmptyPanel>(pParent); |
196 | 0 | aLayoutSize = ui::LayoutSize(20,-1, 50); |
197 | 0 | } |
198 | 0 | else if (rsResourceURL.endsWith("/TextColumnsPropertyPanel")) |
199 | 0 | { |
200 | 0 | xControl = TextColumnsPropertyPanel::Create(pParent, pBindings); |
201 | 0 | } |
202 | |
|
203 | 0 | if (xControl) |
204 | 0 | { |
205 | 0 | return sfx2::sidebar::SidebarPanelBase::Create( |
206 | 0 | rsResourceURL, |
207 | 0 | xFrame, |
208 | 0 | std::move(xControl), |
209 | 0 | aLayoutSize); |
210 | 0 | } |
211 | 0 | else |
212 | 0 | return Reference<ui::XUIElement>(); |
213 | 0 | } |
214 | | |
215 | | } |
216 | | |
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 &) |
221 | 0 | { |
222 | 0 | return cppu::acquire(new PanelFactory); |
223 | 0 | } |
224 | | |
225 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |