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 
32 #include <DefaultShapesPanel.hxx>
33 #if HAVE_FEATURE_AVMEDIA
35 #endif
36 #include <GalleryControl.hxx>
37 #include "EmptyPanel.hxx"
39 #include <sfx2/templdlg.hxx>
41 #include <vcl/window.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  VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
107  if ( ! xParentWindow.is() || pParentWindow==nullptr)
108  throw RuntimeException(
109  "PanelFactory::createUIElement called without ParentWindow",
110  nullptr);
111  if ( ! xFrame.is())
112  throw RuntimeException(
113  "PanelFactory::createUIElement called without Frame",
114  nullptr);
115  if (pBindings == nullptr)
116  throw RuntimeException(
117  "PanelFactory::createUIElement called without SfxBindings",
118  nullptr);
119 
120  VclPtr<vcl::Window> pControl;
121  ui::LayoutSize aLayoutSize (-1,-1,-1);
122 
123  if (rsResourceURL.endsWith("/TextPropertyPanel"))
124  {
125  pControl = TextPropertyPanel::Create(pParentWindow, xFrame);
126  }
127  else if (rsResourceURL.endsWith("/StylesPropertyPanel"))
128  {
129  pControl = StylesPropertyPanel::Create(pParentWindow, xFrame);
130  }
131  else if (rsResourceURL.endsWith("/ParaPropertyPanel"))
132  {
133  pControl = ParaPropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
134  }
135  else if (rsResourceURL.endsWith("/ListsPropertyPanel"))
136  {
137  pControl = ListsPropertyPanel::Create(pParentWindow, xFrame);
138  }
139  else if (rsResourceURL.endsWith("/AreaPropertyPanel"))
140  {
141  pControl = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
142  }
143  else if (rsResourceURL.endsWith("/ShadowPropertyPanel"))
144  {
145  pControl = ShadowPropertyPanel::Create(pParentWindow, xFrame, pBindings);
146  }
147  else if (rsResourceURL.endsWith("/EffectPropertyPanel"))
148  {
149  pControl = EffectPropertyPanel::Create(pParentWindow, xFrame, pBindings);
150  }
151  else if (rsResourceURL.endsWith("/GraphicPropertyPanel"))
152  {
153  pControl = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings);
154  }
155  else if (rsResourceURL.endsWith("/LinePropertyPanel"))
156  {
157  pControl = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings);
158  }
159  else if (rsResourceURL.endsWith("/PosSizePropertyPanel"))
160  {
161  pControl = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
162  }
163  else if (rsResourceURL.endsWith("/DefaultShapesPanel"))
164  {
165  pControl = DefaultShapesPanel::Create(pParentWindow, xFrame);
166  }
167 #if HAVE_FEATURE_AVMEDIA
168  else if (rsResourceURL.endsWith("/MediaPlaybackPanel"))
169  {
170  pControl = MediaPlaybackPanel::Create(pParentWindow, xFrame, pBindings);
171  }
172 #endif
173  else if (rsResourceURL.endsWith("/GalleryPanel"))
174  {
175  pControl.reset(VclPtr<GalleryControl>::Create(pParentWindow));
176  aLayoutSize = ui::LayoutSize(300,-1,400);
177  }
178  else if (rsResourceURL.endsWith("/StyleListPanel"))
179  {
180  pControl.reset(VclPtr<SfxTemplatePanelControl>::Create(pBindings, pParentWindow));
181  aLayoutSize = ui::LayoutSize(0,-1,-1);
182  }
183  else if (rsResourceURL.endsWith("/EmptyPanel"))
184  {
185  pControl.reset(VclPtr<EmptyPanel>::Create(pParentWindow));
186  aLayoutSize = ui::LayoutSize(20,-1, 50);
187  }
188 
189  if (pControl)
190  {
192  rsResourceURL,
193  xFrame,
194  pControl,
195  aLayoutSize);
196  }
197  else
198  return Reference<ui::XUIElement>();
199 }
200 
201 }
202 
203 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
205  css::uno::XComponentContext *,
206  css::uno::Sequence<css::uno::Any> const &)
207 {
208  return cppu::acquire(new PanelFactory);
209 }
210 
211 /* 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
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
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, vcl::Window *pControl, 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
void reset(vcl::Window *pBody)