LibreOffice Module svx (master)  1
PanelFactory.cxx
Go to the documentation of this file.
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 
34 #include <DefaultShapesPanel.hxx>
35 #if HAVE_FEATURE_AVMEDIA
37 #endif
38 #include <GalleryControl.hxx>
39 #include "EmptyPanel.hxx"
41 #include <sfx2/templdlg.hxx>
42 #include <vcl/weldutils.hxx>
44 #include <cppuhelper/basemutex.hxx>
45 #include <cppuhelper/compbase.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 ::cppu::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo >
66 
67 class PanelFactory
68  : private ::cppu::BaseMutex,
69  public PanelFactoryInterfaceBase
70 {
71 public:
72  PanelFactory();
73  PanelFactory(const PanelFactory&) = delete;
74  PanelFactory& operator=(const PanelFactory&) = delete;
75 
76  // XUIElementFactory
77  css::uno::Reference<css::ui::XUIElement> SAL_CALL createUIElement (
78  const OUString& rsResourceURL,
79  const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments) override;
80 
81  OUString SAL_CALL getImplementationName() override
82  { return "org.apache.openoffice.comp.svx.sidebar.PanelFactory"; }
83 
84  sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
85  { return cppu::supportsService(this, ServiceName); }
86 
87  css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
88  { return {"com.sun.star.ui.UIElementFactory"}; }
89 };
90 
91 PanelFactory::PanelFactory()
92  : PanelFactoryInterfaceBase(m_aMutex)
93 {
94 }
95 
96 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
97  const OUString& rsResourceURL,
98  const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
99 {
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);
106 
107  weld::Widget* pParent(nullptr);
108  if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
109  pParent = pTunnel->getWidget();
110 
111  if (!pParent)
112  throw RuntimeException(
113  "PanelFactory::createUIElement called without ParentWindow",
114  nullptr);
115  if ( ! xFrame.is())
116  throw RuntimeException(
117  "PanelFactory::createUIElement called without Frame",
118  nullptr);
119  if (pBindings == nullptr)
120  throw RuntimeException(
121  "PanelFactory::createUIElement called without SfxBindings",
122  nullptr);
123 
124  std::unique_ptr<PanelLayout> xControl;
125  ui::LayoutSize aLayoutSize (-1,-1,-1);
126 
127  if (rsResourceURL.endsWith("/TextPropertyPanel"))
128  {
129  xControl = TextPropertyPanel::Create(pParent, xFrame);
130  }
131  else if (rsResourceURL.endsWith("/StylesPropertyPanel"))
132  {
133  xControl = StylesPropertyPanel::Create(pParent, xFrame);
134  }
135  else if (rsResourceURL.endsWith("/ParaPropertyPanel"))
136  {
137  xControl = ParaPropertyPanel::Create(pParent, xFrame, pBindings, xSidebar);
138  }
139  else if (rsResourceURL.endsWith("/ListsPropertyPanel"))
140  {
141  xControl = ListsPropertyPanel::Create(pParent, xFrame);
142  }
143  else if (rsResourceURL.endsWith("/AreaPropertyPanel"))
144  {
145  xControl = AreaPropertyPanel::Create(pParent, xFrame, pBindings);
146  }
147  else if (rsResourceURL.endsWith("/FontworkPropertyPanel"))
148  {
149  xControl = FontworkPropertyPanel::Create(pParent, xFrame);
150  }
151  else if (rsResourceURL.endsWith("/ShadowPropertyPanel"))
152  {
153  xControl = ShadowPropertyPanel::Create(pParent, pBindings);
154  }
155  else if (rsResourceURL.endsWith("/EffectPropertyPanel"))
156  {
157  xControl = EffectPropertyPanel::Create(pParent, pBindings);
158  }
159  else if (rsResourceURL.endsWith("/GraphicPropertyPanel"))
160  {
161  xControl = GraphicPropertyPanel::Create(pParent, pBindings);
162  }
163  else if (rsResourceURL.endsWith("/LinePropertyPanel"))
164  {
165  xControl = LinePropertyPanel::Create(pParent, xFrame, pBindings);
166  }
167  else if (rsResourceURL.endsWith("/PosSizePropertyPanel"))
168  {
169  xControl = PosSizePropertyPanel::Create(pParent, xFrame, pBindings, xSidebar);
170  }
171  else if (rsResourceURL.endsWith("/DefaultShapesPanel"))
172  {
173  xControl = DefaultShapesPanel::Create(pParent, xFrame);
174  }
175 #if HAVE_FEATURE_AVMEDIA
176  else if (rsResourceURL.endsWith("/MediaPlaybackPanel"))
177  {
178  xControl = MediaPlaybackPanel::Create(pParent, pBindings);
179  }
180 #endif
181  else if (rsResourceURL.endsWith("/GalleryPanel"))
182  {
183  xControl = std::make_unique<GalleryControl>(pParent);
184  aLayoutSize = ui::LayoutSize(300,-1,400);
185  }
186  else if (rsResourceURL.endsWith("/StyleListPanel"))
187  {
188  xControl = std::make_unique<SfxTemplatePanelControl>(pBindings, pParent);
189  aLayoutSize = ui::LayoutSize(0,-1,-1);
190  }
191  else if (rsResourceURL.endsWith("/EmptyPanel"))
192  {
193  xControl = std::make_unique<EmptyPanel>(pParent);
194  aLayoutSize = ui::LayoutSize(20,-1, 50);
195  }
196  else if (rsResourceURL.endsWith("/TextColumnsPropertyPanel"))
197  {
198  xControl = TextColumnsPropertyPanel::Create(pParent, pBindings);
199  }
200 
201  if (xControl)
202  {
204  rsResourceURL,
205  xFrame,
206  std::move(xControl),
207  aLayoutSize);
208  }
209  else
210  return Reference<ui::XUIElement>();
211 }
212 
213 }
214 
215 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
217  css::uno::XComponentContext *,
218  css::uno::Sequence<css::uno::Any> const &)
219 {
220  return cppu::acquire(new PanelFactory);
221 }
222 
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_apache_openoffice_comp_svx_sidebar_PanelFactory_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Reference< XFrame > xFrame
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
Sequence< PropertyValue > aArguments
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::mutex m_aMutex
static css::uno::Reference< css::ui::XUIElement > Create(const OUString &rsResourceURL, const css::uno::Reference< css::frame::XFrame > &rxFrame, std::unique_ptr< PanelLayout > xControl, const css::ui::LayoutSize &rLayoutSize)
void Create(SvxOrientationItem &rItem, SvStream &rStrm, sal_uInt16)
Definition: legacyitem.cxx:34
::cppu::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo > PanelFactoryInterfaceBase
unsigned char sal_Bool