Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / sidebar / Chart2PanelFactory.cxx
blob005aff6ebd5cb8cf00749e71dcb30f351e8896fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "Chart2PanelFactory.hxx"
22 #include <sfx2/sidebar/SidebarPanelBase.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <vcl/window.hxx>
25 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
26 #include <cppuhelper/exc_hlp.hxx>
27 #include <comphelper/namedvaluecollection.hxx>
28 #include <cppuhelper/supportsservice.hxx>
30 #include "ChartElementsPanel.hxx"
31 #include "ChartSeriesPanel.hxx"
32 #include <ChartController.hxx>
33 #include "ChartAxisPanel.hxx"
34 #include "ChartErrorBarPanel.hxx"
35 #include "ChartAreaPanel.hxx"
36 #include "ChartLinePanel.hxx"
38 using namespace css::uno;
40 namespace chart { namespace sidebar {
42 ChartPanelFactory::ChartPanelFactory()
43 : PanelFactoryInterfaceBase(m_aMutex)
47 ChartPanelFactory::~ChartPanelFactory()
51 Reference<css::ui::XUIElement> SAL_CALL ChartPanelFactory::createUIElement (
52 const OUString& rsResourceURL,
53 const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
55 Reference<css::ui::XUIElement> xElement;
57 try
59 const ::comphelper::NamedValueCollection aArguments (rArguments);
60 Reference<css::frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<css::frame::XFrame>()));
61 Reference<css::awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<css::awt::XWindow>()));
62 Reference<css::frame::XController> xController (aArguments.getOrDefault("Controller", Reference<css::frame::XController>()));
64 VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
65 if ( ! xParentWindow.is() || pParentWindow==nullptr)
66 throw RuntimeException(
67 "PanelFactory::createUIElement called without ParentWindow",
68 nullptr);
69 if ( ! xFrame.is())
70 throw RuntimeException(
71 "PanelFactory::createUIElement called without Frame",
72 nullptr);
73 if (!xController.is())
74 throw RuntimeException(
75 "ChartPanelFactory::createUIElement called without Controller",
76 nullptr);
78 ChartController* pController = dynamic_cast<ChartController*>(xController.get());
79 if (!pController)
80 throw RuntimeException(
81 "ChartPanelFactory::createUIElement called without valid ChartController",
82 nullptr);
84 VclPtr<vcl::Window> pPanel;
85 if (rsResourceURL.endsWith("/ElementsPanel"))
86 pPanel = ChartElementsPanel::Create( pParentWindow, xFrame, pController );
87 else if (rsResourceURL.endsWith("/SeriesPanel"))
88 pPanel = ChartSeriesPanel::Create(pParentWindow, xFrame, pController);
89 else if (rsResourceURL.endsWith("/AxisPanel"))
90 pPanel = ChartAxisPanel::Create(pParentWindow, xFrame, pController);
91 else if (rsResourceURL.endsWith("/ErrorBarPanel"))
92 pPanel = ChartErrorBarPanel::Create(pParentWindow, xFrame, pController);
93 else if (rsResourceURL.endsWith("/AreaPanel"))
94 pPanel = ChartAreaPanel::Create(pParentWindow, xFrame, pController);
95 else if (rsResourceURL.endsWith("/LinePanel"))
96 pPanel = ChartLinePanel::Create(pParentWindow, xFrame, pController);
98 if (pPanel)
99 xElement = sfx2::sidebar::SidebarPanelBase::Create(
100 rsResourceURL,
101 xFrame,
102 pPanel,
103 css::ui::LayoutSize(-1,-1,-1));
105 catch (const css::uno::RuntimeException &)
107 throw;
109 catch (const css::uno::Exception&)
111 css::uno::Any anyEx = cppu::getCaughtException();
112 throw css::lang::WrappedTargetRuntimeException(
113 "ChartPanelFactory::createUIElement exception",
114 nullptr, anyEx );
117 return xElement;
120 OUString ChartPanelFactory::getImplementationName()
122 return "org.libreoffice.comp.chart2.sidebar.ChartPanelFactory";
125 sal_Bool ChartPanelFactory::supportsService(OUString const & ServiceName)
127 return cppu::supportsService(this, ServiceName);
130 css::uno::Sequence<OUString> ChartPanelFactory::getSupportedServiceNames()
132 return { "com.sun.star.ui.UIElementFactory" };
135 } } // end of namespace chart::sidebar
137 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
138 org_libreoffice_comp_chart2_sidebar_ChartPanelFactory(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
140 return cppu::acquire(new ::chart::sidebar::ChartPanelFactory());
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */