LibreOffice Module sw (master)  1
SwPanelFactory.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 <com/sun/star/ui/XUIElementFactory.hpp>
21 
22 #include "ThemePanel.hxx"
23 #include "StylePresetsPanel.hxx"
24 #include "PageStylesPanel.hxx"
25 #include "PageFormatPanel.hxx"
26 #include "PageHeaderPanel.hxx"
27 #include "PageFooterPanel.hxx"
28 #include "WrapPropertyPanel.hxx"
30 #include "TableEditPanel.hxx"
31 #include <navipi.hxx>
32 #include <redlndlg.hxx>
33 
35 #include <vcl/weldutils.hxx>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <cppuhelper/compbase.hxx>
40 #include <cppuhelper/basemutex.hxx>
42 
43 
44 using namespace css;
45 using namespace css::uno;
46 
47 namespace {
48 
49 typedef ::cppu::WeakComponentImplHelper <
50  css::ui::XUIElementFactory, css::lang::XServiceInfo
52 
53 class SwPanelFactory
54  : private ::cppu::BaseMutex
55  , public PanelFactoryInterfaceBase
56 {
57 private:
58  SwPanelFactory(SwPanelFactory const&) = delete;
59  SwPanelFactory& operator=(SwPanelFactory const&) = delete;
60 
61 public:
62  SwPanelFactory();
63 
64  // XUIElementFactory
65  css::uno::Reference<css::ui::XUIElement> SAL_CALL createUIElement(
66  const OUString& rsResourceURL,
67  const css::uno::Sequence<css::beans::PropertyValue>& rArguments) override;
68 
69  OUString SAL_CALL getImplementationName() override
70  { return "org.apache.openoffice.comp.sw.sidebar.SwPanelFactory"; }
71 
72  sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
73  { return cppu::supportsService(this, ServiceName); }
74 
75  css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
76  { return {"com.sun.star.ui.UIElementFactory"}; }
77 };
78 
79 SwPanelFactory::SwPanelFactory()
80  : PanelFactoryInterfaceBase(m_aMutex)
81 {
82 }
83 
84 Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
85  const OUString& rsResourceURL,
86  const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
87 {
88  Reference<ui::XUIElement> xElement;
89 
90  const ::comphelper::NamedValueCollection aArguments (rArguments);
91  Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
92  Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
93  const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
94  SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
95 
96  weld::Widget* pParent(nullptr);
97  if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
98  pParent = pTunnel->getWidget();
99 
100  if (!pParent)
101  throw RuntimeException(
102  "PanelFactory::createUIElement called without ParentWindow",
103  nullptr);
104  if ( ! xFrame.is())
105  throw RuntimeException(
106  "PanelFactory::createUIElement called without Frame",
107  nullptr);
108  if (pBindings == nullptr)
109  throw RuntimeException(
110  "PanelFactory::createUIElement called without SfxBindings",
111  nullptr);
112 
113  if(rsResourceURL.endsWith("/PageStylesPanel"))
114  {
115  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::PageStylesPanel::Create( pParent, pBindings );
117  rsResourceURL,
118  xFrame,
119  std::move(xPanel),
120  ui::LayoutSize(-1,-1,-1));
121  }
122  else if(rsResourceURL.endsWith("/PageFormatPanel"))
123  {
124  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::PageFormatPanel::Create( pParent, pBindings );
126  rsResourceURL,
127  xFrame,
128  std::move(xPanel),
129  ui::LayoutSize(-1,-1,-1));
130  }
131  else if(rsResourceURL.endsWith("/PageHeaderPanel"))
132  {
133  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::PageHeaderPanel::Create( pParent, pBindings );
135  rsResourceURL,
136  xFrame,
137  std::move(xPanel),
138  ui::LayoutSize(-1,-1,-1));
139  }
140  else if(rsResourceURL.endsWith("/PageFooterPanel"))
141  {
142  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::PageFooterPanel::Create( pParent, pBindings );
144  rsResourceURL,
145  xFrame,
146  std::move(xPanel),
147  ui::LayoutSize(-1,-1,-1));
148  }
149  else if (rsResourceURL.endsWith("/WrapPropertyPanel"))
150  {
151  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::WrapPropertyPanel::Create( pParent, xFrame, pBindings );
153  rsResourceURL,
154  xFrame,
155  std::move(xPanel),
156  ui::LayoutSize(-1,-1,-1));
157  }
158  else if (rsResourceURL.endsWith("/NavigatorPanel"))
159  {
160  std::unique_ptr<PanelLayout> xPanel = SwNavigationPI::Create( pParent, xFrame, pBindings );
162  rsResourceURL,
163  xFrame,
164  std::move(xPanel),
165  ui::LayoutSize(0,-1,-1));
166  }
167  else if (rsResourceURL.endsWith("/ManageChangesPanel"))
168  {
169  auto xPanel = std::make_unique<SwRedlineAcceptPanel>(pParent);
171  rsResourceURL,
172  xFrame,
173  std::move(xPanel),
174  ui::LayoutSize(-1,-1,-1));
175  }
176  else if (rsResourceURL.endsWith("/WriterInspectorTextPanel"))
177  {
178  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::WriterInspectorTextPanel::Create(pParent);
180  rsResourceURL,
181  xFrame,
182  std::move(xPanel),
183  ui::LayoutSize(0,-1,-1));
184  }
185  else if (rsResourceURL.endsWith("/StylePresetsPanel"))
186  {
187  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::StylePresetsPanel::Create(pParent);
189  rsResourceURL, xFrame, std::move(xPanel), ui::LayoutSize(-1,-1,-1));
190  }
191  else if (rsResourceURL.endsWith("/ThemePanel"))
192  {
193  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::ThemePanel::Create(pParent);
195  rsResourceURL, xFrame, std::move(xPanel), ui::LayoutSize(-1,-1,-1));
196  }
197  else if (rsResourceURL.endsWith("/TableEditPanel"))
198  {
199  std::unique_ptr<PanelLayout> xPanel = sw::sidebar::TableEditPanel::Create(pParent, xFrame, pBindings );
201  rsResourceURL, xFrame, std::move(xPanel), ui::LayoutSize(-1,-1,-1));
202  }
203 
204  return xElement;
205 }
206 
207 }
208 
209 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
211  css::uno::XComponentContext *,
212  css::uno::Sequence<css::uno::Any> const &)
213 {
214  return cppu::acquire(new SwPanelFactory());
215 }
216 
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame, SfxBindings *pBindings)
Definition: navipi.cxx:468
Reference< XFrame > xFrame
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent)
Definition: ThemePanel.cxx:424
Sequence< PropertyValue > aArguments
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::mutex m_aMutex
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_apache_openoffice_comp_sw_sidebar_SwPanelFactory_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
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)
::cppu::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo > PanelFactoryInterfaceBase
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent)
unsigned char sal_Bool
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)