1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/sfxbasecontroller.hxx>
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <vcl/window.hxx>
26 #include <rtl/ref.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
29 #include <comphelper/namedvaluecollection.hxx>
30 #include <cppuhelper/supportsservice.hxx>
32 #include "ChartElementsPanel.hxx"
33 #include "ChartSeriesPanel.hxx"
34 #include <ChartController.hxx>
35 #include "ChartAxisPanel.hxx"
36 #include "ChartErrorBarPanel.hxx"
37 #include "ChartAreaPanel.hxx"
38 #include "ChartLinePanel.hxx"
40 using namespace css::uno
;
41 using ::rtl::OUString
;
43 namespace chart
{ namespace sidebar
{
45 ChartPanelFactory::ChartPanelFactory()
46 : PanelFactoryInterfaceBase(m_aMutex
)
50 ChartPanelFactory::~ChartPanelFactory()
54 Reference
<css::ui::XUIElement
> SAL_CALL
ChartPanelFactory::createUIElement (
55 const ::rtl::OUString
& rsResourceURL
,
56 const ::css::uno::Sequence
<css::beans::PropertyValue
>& rArguments
)
58 Reference
<css::ui::XUIElement
> xElement
;
62 const ::comphelper::NamedValueCollection
aArguments (rArguments
);
63 Reference
<css::frame::XFrame
> xFrame (aArguments
.getOrDefault("Frame", Reference
<css::frame::XFrame
>()));
64 Reference
<css::awt::XWindow
> xParentWindow (aArguments
.getOrDefault("ParentWindow", Reference
<css::awt::XWindow
>()));
65 Reference
<css::frame::XController
> xController (aArguments
.getOrDefault("Controller", Reference
<css::frame::XController
>()));
67 VclPtr
<vcl::Window
> pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
68 if ( ! xParentWindow
.is() || pParentWindow
==nullptr)
69 throw RuntimeException(
70 "PanelFactory::createUIElement called without ParentWindow",
73 throw RuntimeException(
74 "PanelFactory::createUIElement called without Frame",
76 if (!xController
.is())
77 throw RuntimeException(
78 "ChartPanelFactory::createUIElement called without Controller",
81 ChartController
* pController
= dynamic_cast<ChartController
*>(xController
.get());
83 throw RuntimeException(
84 "ChartPanelFactory::createUIElement called without valid ChartController",
87 VclPtr
<vcl::Window
> pPanel
;
88 if (rsResourceURL
.endsWith("/ElementsPanel"))
89 pPanel
= ChartElementsPanel::Create( pParentWindow
, xFrame
, pController
);
90 else if (rsResourceURL
.endsWith("/SeriesPanel"))
91 pPanel
= ChartSeriesPanel::Create(pParentWindow
, xFrame
, pController
);
92 else if (rsResourceURL
.endsWith("/AxisPanel"))
93 pPanel
= ChartAxisPanel::Create(pParentWindow
, xFrame
, pController
);
94 else if (rsResourceURL
.endsWith("/ErrorBarPanel"))
95 pPanel
= ChartErrorBarPanel::Create(pParentWindow
, xFrame
, pController
);
96 else if (rsResourceURL
.endsWith("/AreaPanel"))
97 pPanel
= ChartAreaPanel::Create(pParentWindow
, xFrame
, pController
);
98 else if (rsResourceURL
.endsWith("/LinePanel"))
99 pPanel
= ChartLinePanel::Create(pParentWindow
, xFrame
, pController
);
102 xElement
= sfx2::sidebar::SidebarPanelBase::Create(
106 css::ui::LayoutSize(-1,-1,-1));
108 catch (const css::uno::RuntimeException
&)
112 catch (const css::uno::Exception
& e
)
114 throw css::lang::WrappedTargetRuntimeException(
115 "ChartPanelFactory::createUIElement exception",
116 nullptr, css::uno::Any(e
));
122 OUString
ChartPanelFactory::getImplementationName()
124 return OUString("org.libreoffice.comp.chart2.sidebar.ChartPanelFactory");
127 sal_Bool
ChartPanelFactory::supportsService(OUString
const & ServiceName
)
129 return cppu::supportsService(this, ServiceName
);
132 css::uno::Sequence
<OUString
> ChartPanelFactory::getSupportedServiceNames()
134 return { "com.sun.star.ui.UIElementFactory" };
137 } } // end of namespace chart::sidebar
139 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
140 org_libreoffice_comp_chart2_sidebar_ChartPanelFactory(css::uno::XComponentContext
*, css::uno::Sequence
<css::uno::Any
> const &)
142 return cppu::acquire(new ::chart::sidebar::ChartPanelFactory());
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */