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 
33 #include <DefaultShapesPanel.hxx>
34 #if HAVE_FEATURE_AVMEDIA
36 #endif
37 #include <GalleryControl.hxx>
38 #include "EmptyPanel.hxx"
40 #include <sfx2/templdlg.hxx>
41 #include <vcl/weldutils.hxx>
43 #include <cppuhelper/basemutex.hxx>
44 #include <cppuhelper/compbase.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>
50 
51 using namespace css;
52 using namespace css::uno;
53 using namespace svx::sidebar;
54 
55 
56 namespace {
57 
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"
61 */
62 
63 typedef ::cppu::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo >
65 
66 class PanelFactory
67  : private ::cppu::BaseMutex,
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  { return "org.apache.openoffice.comp.svx.sidebar.PanelFactory"; }
82 
83  sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
84  { return cppu::supportsService(this, ServiceName); }
85 
86  css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
87  { return {"com.sun.star.ui.UIElementFactory"}; }
88 };
89 
90 PanelFactory::PanelFactory()
91  : PanelFactoryInterfaceBase(m_aMutex)
92 {
93 }
94 
95 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
96  const OUString& rsResourceURL,
97  const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
98 {
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);
105 
106  weld::Widget* pParent(nullptr);
107  if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
108  pParent = pTunnel->getWidget();
109 
110  if (!pParent)
111  throw RuntimeException(
112  "PanelFactory::createUIElement called without ParentWindow",
113  nullptr);
114  if ( ! xFrame.is())
115  throw RuntimeException(
116  "PanelFactory::createUIElement called without Frame",
117  nullptr);
118  if (pBindings == nullptr)
119  throw RuntimeException(
120  "PanelFactory::createUIElement called without SfxBindings",
121  nullptr);
122 
123  std::unique_ptr<PanelLayout> xControl;
124  ui::LayoutSize aLayoutSize (-1,-1,-1);
125 
126  if (rsResourceURL.endsWith("/TextPropertyPanel"))
127  {
128  xControl = TextPropertyPanel::Create(pParent, xFrame);
129  }
130  else if (rsResourceURL.endsWith("/StylesPropertyPanel"))
131  {
132  xControl = StylesPropertyPanel::Create(pParent, xFrame);
133  }
134  else if (rsResourceURL.endsWith("/ParaPropertyPanel"))
135  {
136  xControl = ParaPropertyPanel::Create(pParent, xFrame, pBindings, xSidebar);
137  }
138  else if (rsResourceURL.endsWith("/ListsPropertyPanel"))
139  {
140  xControl = ListsPropertyPanel::Create(pParent, xFrame);
141  }
142  else if (rsResourceURL.endsWith("/AreaPropertyPanel"))
143  {
144  xControl = AreaPropertyPanel::Create(pParent, xFrame, pBindings);
145  }
146  else if (rsResourceURL.endsWith("/FontworkPropertyPanel"))
147  {
148  xControl = FontworkPropertyPanel::Create(pParent, xFrame);
149  }
150  else if (rsResourceURL.endsWith("/ShadowPropertyPanel"))
151  {
152  xControl = ShadowPropertyPanel::Create(pParent, pBindings);
153  }
154  else if (rsResourceURL.endsWith("/EffectPropertyPanel"))
155  {
156  xControl = EffectPropertyPanel::Create(pParent, pBindings);
157  }
158  else if (rsResourceURL.endsWith("/GraphicPropertyPanel"))
159  {
160  xControl = GraphicPropertyPanel::Create(pParent, pBindings);
161  }
162  else if (rsResourceURL.endsWith("/LinePropertyPanel"))
163  {
164  xControl = LinePropertyPanel::Create(pParent, xFrame, pBindings);
165  }
166  else if (rsResourceURL.endsWith("/PosSizePropertyPanel"))
167  {
168  xControl = PosSizePropertyPanel::Create(pParent, xFrame, pBindings, xSidebar);
169  }
170  else if (rsResourceURL.endsWith("/DefaultShapesPanel"))
171  {
172  xControl = DefaultShapesPanel::Create(pParent, xFrame);
173  }
174 #if HAVE_FEATURE_AVMEDIA
175  else if (rsResourceURL.endsWith("/MediaPlaybackPanel"))
176  {
177  xControl = MediaPlaybackPanel::Create(pParent, pBindings);
178  }
179 #endif
180  else if (rsResourceURL.endsWith("/GalleryPanel"))
181  {
182  xControl = std::make_unique<GalleryControl>(pParent);
183  aLayoutSize = ui::LayoutSize(300,-1,400);
184  }
185  else if (rsResourceURL.endsWith("/StyleListPanel"))
186  {
187  xControl = std::make_unique<SfxTemplatePanelControl>(pBindings, pParent);
188  aLayoutSize = ui::LayoutSize(0,-1,-1);
189  }
190  else if (rsResourceURL.endsWith("/EmptyPanel"))
191  {
192  xControl = std::make_unique<EmptyPanel>(pParent);
193  aLayoutSize = ui::LayoutSize(20,-1, 50);
194  }
195 
196  if (xControl)
197  {
199  rsResourceURL,
200  xFrame,
201  std::move(xControl),
202  aLayoutSize);
203  }
204  else
205  return Reference<ui::XUIElement>();
206 }
207 
208 }
209 
210 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
212  css::uno::XComponentContext *,
213  css::uno::Sequence<css::uno::Any> const &)
214 {
215  return cppu::acquire(new PanelFactory);
216 }
217 
218 /* 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 &)
osl::Mutex m_aMutex
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)
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