| 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 "Chart2PanelFactory.hxx" |
| 21 |
|
| 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> |
| 28 |
|
| 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" |
| 37 |
#include "ChartColorsPanel.hxx" |
| 38 |
|
| 39 |
using namespace css::uno; |
| 40 |
|
| 41 |
namespace chart::sidebar { |
| 42 |
|
| 43 |
ChartPanelFactory::ChartPanelFactory() |
| 44 |
{ |
| 45 |
} |
| 46 |
|
| 47 |
ChartPanelFactory::~ChartPanelFactory() |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
Reference<css::ui::XUIElement> SAL_CALL ChartPanelFactory::createUIElement ( |
| 52 |
const OUString& rsResourceURL, |
| 53 |
const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments) |
| 54 |
{ |
| 55 |
Reference<css::ui::XUIElement> xElement; |
| 56 |
|
| 57 |
try |
| 58 |
{ |
| 59 |
const ::comphelper::NamedValueCollection aArguments (rArguments); |
| 60 |
Reference<css::frame::XFrame> xFrame(sfx2::sidebar::GetFrame(aArguments)); |
| 61 |
Reference<css::awt::XWindow> xParentWindow (aArguments.getOrDefault(u"ParentWindow"_ustr, Reference<css::awt::XWindow>())); |
| 62 |
Reference<css::frame::XController> xController (aArguments.getOrDefault(u"Controller"_ustr, Reference<css::frame::XController>())); |
| 63 |
|
| 64 |
weld::Widget* pParent(nullptr); |
| 65 |
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get())) |
| 66 |
pParent = pTunnel->getWidget(); |
| 67 |
|
| 68 |
if (!pParent) |
| 69 |
throw RuntimeException( |
| 70 |
u"PanelFactory::createUIElement called without ParentWindow"_ustr, |
| 71 |
nullptr); |
| 72 |
if ( ! xFrame.is()) |
| 73 |
throw RuntimeException( |
| 74 |
u"PanelFactory::createUIElement called without Frame"_ustr, |
| 75 |
nullptr); |
| 76 |
if (!xController.is()) |
| 77 |
throw RuntimeException( |
| 78 |
u"ChartPanelFactory::createUIElement called without Controller"_ustr, |
| 79 |
nullptr); |
| 80 |
|
| 81 |
ChartController* pController = dynamic_cast<ChartController*>(xController.get()); |
| 82 |
if (!pController) |
| 83 |
throw RuntimeException( |
| 84 |
u"ChartPanelFactory::createUIElement called without valid ChartController"_ustr, |
| 85 |
nullptr); |
| 86 |
|
| 87 |
std::unique_ptr<PanelLayout> xPanel; |
| 88 |
if (rsResourceURL.endsWith("/ElementsPanel")) |
| 89 |
xPanel = ChartElementsPanel::Create( pParent, pController ); |
| 90 |
else if (rsResourceURL.endsWith("/TypePanel")) |
| 91 |
xPanel = std::make_unique<ChartTypePanel>(pParent, pController); |
| 92 |
else if (rsResourceURL.endsWith("/SeriesPanel")) |
| 93 |
xPanel = ChartSeriesPanel::Create(pParent, pController); |
| 94 |
else if (rsResourceURL.endsWith("/AxisPanel")) |
| 95 |
xPanel = ChartAxisPanel::Create(pParent, pController); |
| 96 |
else if (rsResourceURL.endsWith("/ErrorBarPanel")) |
| 97 |
xPanel = ChartErrorBarPanel::Create(pParent, pController); |
| 98 |
else if (rsResourceURL.endsWith("/AreaPanel")) |
| 99 |
xPanel = ChartAreaPanel::Create(pParent, xFrame, pController); |
| 100 |
else if (rsResourceURL.endsWith("/LinePanel")) |
| 101 |
xPanel = ChartLinePanel::Create(pParent, xFrame, pController); |
| 102 |
else if (rsResourceURL.endsWith("/ColorsPanel")) |
| 103 |
xPanel = ChartColorsPanel::Create(pParent, xFrame, pController); |
| 104 |
|
| 105 |
if (xPanel) |
| 106 |
xElement = sfx2::sidebar::SidebarPanelBase::Create( |
| 107 |
rsResourceURL, |
| 108 |
xFrame, |
| 109 |
std::move(xPanel), |
| 110 |
css::ui::LayoutSize(-1,-1,-1)); |
| 111 |
} |
| 112 |
catch (const css::uno::RuntimeException &) |
| 113 |
{ |
| 114 |
throw; |
| 115 |
} |
| 116 |
catch (const css::uno::Exception&) |
| 117 |
{ |
| 118 |
css::uno::Any anyEx = cppu::getCaughtException(); |
| 119 |
throw css::lang::WrappedTargetRuntimeException( |
| 120 |
u"ChartPanelFactory::createUIElement exception"_ustr, |
| 121 |
nullptr, anyEx ); |
| 122 |
} |
| 123 |
|
| 124 |
return xElement; |
| 125 |
} |
| 126 |
|
| 127 |
OUString ChartPanelFactory::getImplementationName() |
| 128 |
{ |
| 129 |
return u"org.libreoffice.comp.chart2.sidebar.ChartPanelFactory"_ustr; |
| 130 |
} |
| 131 |
|
| 132 |
sal_Bool ChartPanelFactory::supportsService(OUString const & ServiceName) |
| 133 |
{ |
| 134 |
return cppu::supportsService(this, ServiceName); |
| 135 |
} |
| 136 |
|
| 137 |
css::uno::Sequence<OUString> ChartPanelFactory::getSupportedServiceNames() |
| 138 |
{ |
| 139 |
return { u"com.sun.star.ui.UIElementFactory"_ustr }; |
| 140 |
} |
| 141 |
|
| 142 |
} // end of namespace chart::sidebar |
| 143 |
|
| 144 |
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
| 145 |
org_libreoffice_comp_chart2_sidebar_ChartPanelFactory(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &) |
| 146 |
{ |
| 147 |
return cppu::acquire(new ::chart::sidebar::ChartPanelFactory()); |
| 148 |
} |
| 149 |
|
| 150 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |