Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / sidebar / Chart2PanelFactory.cxx
blob081322b0940874bf7664b42b26b6f3b0536e33b6
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 <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
24 #include <cppuhelper/exc_hlp.hxx>
25 #include <comphelper/namedvaluecollection.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <vcl/weldutils.hxx>
29 #include "ChartElementsPanel.hxx"
30 #include "ChartTypePanel.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::sidebar {
42 ChartPanelFactory::ChartPanelFactory()
46 ChartPanelFactory::~ChartPanelFactory()
50 Reference<css::ui::XUIElement> SAL_CALL ChartPanelFactory::createUIElement (
51 const OUString& rsResourceURL,
52 const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
54 Reference<css::ui::XUIElement> xElement;
56 try
58 const ::comphelper::NamedValueCollection aArguments (rArguments);
59 Reference<css::frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<css::frame::XFrame>()));
60 Reference<css::awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<css::awt::XWindow>()));
61 Reference<css::frame::XController> xController (aArguments.getOrDefault("Controller", Reference<css::frame::XController>()));
63 weld::Widget* pParent(nullptr);
64 if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
65 pParent = pTunnel->getWidget();
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 (!xController.is())
76 throw RuntimeException(
77 "ChartPanelFactory::createUIElement called without Controller",
78 nullptr);
80 ChartController* pController = dynamic_cast<ChartController*>(xController.get());
81 if (!pController)
82 throw RuntimeException(
83 "ChartPanelFactory::createUIElement called without valid ChartController",
84 nullptr);
86 std::unique_ptr<PanelLayout> xPanel;
87 if (rsResourceURL.endsWith("/ElementsPanel"))
88 xPanel = ChartElementsPanel::Create( pParent, pController );
89 else if (rsResourceURL.endsWith("/TypePanel"))
90 xPanel = std::make_unique<ChartTypePanel>(pParent, pController);
91 else if (rsResourceURL.endsWith("/SeriesPanel"))
92 xPanel = ChartSeriesPanel::Create(pParent, pController);
93 else if (rsResourceURL.endsWith("/AxisPanel"))
94 xPanel = ChartAxisPanel::Create(pParent, pController);
95 else if (rsResourceURL.endsWith("/ErrorBarPanel"))
96 xPanel = ChartErrorBarPanel::Create(pParent, pController);
97 else if (rsResourceURL.endsWith("/AreaPanel"))
98 xPanel = ChartAreaPanel::Create(pParent, xFrame, pController);
99 else if (rsResourceURL.endsWith("/LinePanel"))
100 xPanel = ChartLinePanel::Create(pParent, xFrame, pController);
102 if (xPanel)
103 xElement = sfx2::sidebar::SidebarPanelBase::Create(
104 rsResourceURL,
105 xFrame,
106 std::move(xPanel),
107 css::ui::LayoutSize(-1,-1,-1));
109 catch (const css::uno::RuntimeException &)
111 throw;
113 catch (const css::uno::Exception&)
115 css::uno::Any anyEx = cppu::getCaughtException();
116 throw css::lang::WrappedTargetRuntimeException(
117 "ChartPanelFactory::createUIElement exception",
118 nullptr, anyEx );
121 return xElement;
124 OUString ChartPanelFactory::getImplementationName()
126 return "org.libreoffice.comp.chart2.sidebar.ChartPanelFactory";
129 sal_Bool ChartPanelFactory::supportsService(OUString const & ServiceName)
131 return cppu::supportsService(this, ServiceName);
134 css::uno::Sequence<OUString> ChartPanelFactory::getSupportedServiceNames()
136 return { "com.sun.star.ui.UIElementFactory" };
139 } // end of namespace chart::sidebar
141 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
142 org_libreoffice_comp_chart2_sidebar_ChartPanelFactory(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
144 return cppu::acquire(new ::chart::sidebar::ChartPanelFactory());
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */