1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <sal/config.h>
22 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
23 #include <com/sun/star/ui/XUIElementFactory.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <cppuhelper/exc_hlp.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <comphelper/namedvaluecollection.hxx>
29 #include <sfx2/sidebar/SidebarPanelBase.hxx>
30 #include <vcl/weldutils.hxx>
32 #include "SmElementsPanel.hxx"
33 #include "SmPropertiesPanel.hxx"
37 typedef comphelper::WeakComponentImplHelper
<css::ui::XUIElementFactory
, css::lang::XServiceInfo
>
38 PanelFactoryInterfaceBase
;
40 class SmPanelFactory final
: public PanelFactoryInterfaceBase
43 SmPanelFactory() = default;
45 SmPanelFactory(const SmPanelFactory
&) = delete;
46 const SmPanelFactory
& operator=(const SmPanelFactory
&) = delete;
49 css::uno::Reference
<css::ui::XUIElement
> SAL_CALL
50 createUIElement(const OUString
& ResourceURL
,
51 const css::uno::Sequence
<css::beans::PropertyValue
>& Arguments
) override
;
54 OUString SAL_CALL
getImplementationName() override
;
55 sal_Bool SAL_CALL
supportsService(OUString
const& ServiceName
) override
;
56 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
59 css::uno::Reference
<css::ui::XUIElement
> SAL_CALL
SmPanelFactory::createUIElement(
60 const OUString
& ResourceURL
, const css::uno::Sequence
<css::beans::PropertyValue
>& Arguments
)
64 const comphelper::NamedValueCollection
aArguments(Arguments
);
65 auto xFrame(aArguments
.getOrDefault("Frame", css::uno::Reference
<css::frame::XFrame
>()));
67 aArguments
.getOrDefault("ParentWindow", css::uno::Reference
<css::awt::XWindow
>()));
68 const sal_uInt64
nBindingsValue(aArguments
.getOrDefault("SfxBindings", sal_uInt64(0)));
69 SfxBindings
* pBindings
= reinterpret_cast<SfxBindings
*>(nBindingsValue
);
71 weld::Widget
* pParent(nullptr);
72 if (auto pTunnel
= dynamic_cast<weld::TransportAsXWindow
*>(xParentWindow
.get()))
73 pParent
= pTunnel
->getWidget();
76 throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no ParentWindow");
78 throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no Frame");
80 throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no SfxBindings");
82 std::unique_ptr
<PanelLayout
> pPanel
;
83 css::ui::LayoutSize aLayoutSize
{ -1, -1, -1 };
84 if (ResourceURL
.endsWith("/MathPropertiesPanel"))
86 pPanel
= sm::sidebar::SmPropertiesPanel::Create(*pParent
, xFrame
);
88 else if (ResourceURL
.endsWith("/MathElementsPanel"))
90 pPanel
= sm::sidebar::SmElementsPanel::Create(*pParent
, *pBindings
);
91 aLayoutSize
= { 300, -1, -1 };
95 return sfx2::sidebar::SidebarPanelBase::Create(ResourceURL
, xFrame
, std::move(pPanel
),
98 catch (const css::uno::RuntimeException
&)
102 catch (const css::uno::Exception
&)
104 css::uno::Any anyEx
= cppu::getCaughtException();
105 throw css::lang::WrappedTargetRuntimeException("SmPanelFactory::createUIElement exception",
112 OUString
SmPanelFactory::getImplementationName()
114 return "org.libreoffice.comp.Math.sidebar.SmPanelFactory";
117 sal_Bool
SmPanelFactory::supportsService(OUString
const& ServiceName
)
119 return cppu::supportsService(this, ServiceName
);
122 css::uno::Sequence
<OUString
> SmPanelFactory::getSupportedServiceNames()
124 return { "com.sun.star.ui.UIElementFactory" };
127 } // end of unnamed namespace
129 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
130 org_libreoffice_comp_Math_sidebar_SmPanelFactory(css::uno::XComponentContext
*,
131 css::uno::Sequence
<css::uno::Any
> const&)
133 return cppu::acquire(new SmPanelFactory
);
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */