LibreOffice Module sc (master)  1
ScPanelFactory.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 "ScPanelFactory.hxx"
21 
25 #include <navipi.hxx>
26 #include <dwfunctr.hxx>
27 
29 #include <vcl/weldutils.hxx>
30 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
32 #include <cppuhelper/exc_hlp.hxx>
34 
35 using namespace css;
36 using namespace css::uno;
37 
38 namespace sc::sidebar {
39 
40 ScPanelFactory::ScPanelFactory()
42 {
43 }
44 
46 {
47 }
48 
49 Reference<ui::XUIElement> SAL_CALL ScPanelFactory::createUIElement (
50  const OUString& rsResourceURL,
51  const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
52 {
53  Reference<ui::XUIElement> xElement;
54 
55  try
56  {
57  const ::comphelper::NamedValueCollection aArguments (rArguments);
58  Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
59  Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
60  const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
61  SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
62 
63  weld::Widget* pParent(nullptr);
64  if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
65  pParent = pTunnel->getWidget();
66 
67  if (!pParent)
68  throw RuntimeException(
69  "PanelFactory::createUIElement called without ParentWindow",
70  nullptr);
71  if ( ! xFrame.is())
72  throw RuntimeException(
73  "PanelFactory::createUIElement called without Frame",
74  nullptr);
75  if (pBindings == nullptr)
76  throw RuntimeException(
77  "PanelFactory::createUIElement called without SfxBindings",
78  nullptr);
79 
80  sal_Int32 nMinimumSize = -1;
81  std::unique_ptr<PanelLayout> xPanel;
82  if (rsResourceURL.endsWith("/AlignmentPropertyPanel"))
83  xPanel = AlignmentPropertyPanel::Create( pParent, xFrame, pBindings );
84  else if (rsResourceURL.endsWith("/CellAppearancePropertyPanel"))
85  xPanel = CellAppearancePropertyPanel::Create( pParent, xFrame, pBindings );
86  else if (rsResourceURL.endsWith("/NumberFormatPropertyPanel"))
87  xPanel = NumberFormatPropertyPanel::Create( pParent, xFrame, pBindings );
88  else if (rsResourceURL.endsWith("/NavigatorPanel"))
89  {
90  xPanel = std::make_unique<ScNavigatorDlg>(pBindings, pParent, nullptr);
91  nMinimumSize = 0;
92  }
93  else if (rsResourceURL.endsWith("/FunctionsPanel"))
94  {
95  xPanel = std::make_unique<ScFunctionWin>(pParent);
96  nMinimumSize = 0;
97  }
98 
99  if (xPanel)
101  rsResourceURL,
102  xFrame,
103  std::move(xPanel),
104  ui::LayoutSize(nMinimumSize,-1,-1));
105  }
106  catch (const uno::RuntimeException &)
107  {
108  throw;
109  }
110  catch (const uno::Exception&)
111  {
112  css::uno::Any anyEx = cppu::getCaughtException();
113  throw lang::WrappedTargetRuntimeException(
114  "ScPanelFactory::createUIElement exception",
115  nullptr, anyEx);
116  }
117 
118  return xElement;
119 }
120 
122 {
123  return "org.apache.openoffice.comp.sc.sidebar.ScPanelFactory";
124 }
125 
126 sal_Bool ScPanelFactory::supportsService(OUString const & ServiceName)
127 {
128  return cppu::supportsService(this, ServiceName);
129 }
130 
131 css::uno::Sequence<OUString> ScPanelFactory::getSupportedServiceNames()
132 {
133  return { "com.sun.star.ui.UIElementFactory" };
134 }
135 
136 } // end of namespace sc::sidebar
137 
138 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
139 ScPanelFactory_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
140 {
141  return cppu::acquire(new sc::sidebar::ScPanelFactory());
142 }
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ScPanelFactory_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Reference< XFrame > xFrame
OUString SAL_CALL getImplementationName() override
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
Sequence< PropertyValue > aArguments
Any SAL_CALL getCaughtException()
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, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
virtual ~ScPanelFactory() override
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)
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
::cppu::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo > PanelFactoryInterfaceBase
unsigned char sal_Bool
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
css::uno::Reference< css::ui::XUIElement > SAL_CALL createUIElement(const OUString &rsResourceURL, const ::css::uno::Sequence< css::beans::PropertyValue > &rArguments) override