LibreOffice Module starmath (master) 1
SmPanelFactory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <sal/config.h>
21
22#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
23#include <com/sun/star/ui/XUIElementFactory.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
25
30#include <vcl/weldutils.hxx>
31
32#include "SmElementsPanel.hxx"
33#include "SmPropertiesPanel.hxx"
34
35namespace
36{
39
40class SmPanelFactory final : public PanelFactoryInterfaceBase
41{
42public:
43 SmPanelFactory() = default;
44
45 SmPanelFactory(const SmPanelFactory&) = delete;
46 const SmPanelFactory& operator=(const SmPanelFactory&) = delete;
47
48 // XUIElementFactory
49 css::uno::Reference<css::ui::XUIElement> SAL_CALL
50 createUIElement(const OUString& ResourceURL,
51 const css::uno::Sequence<css::beans::PropertyValue>& Arguments) override;
52
53 // XServiceInfo
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;
57};
58
59css::uno::Reference<css::ui::XUIElement> SAL_CALL SmPanelFactory::createUIElement(
60 const OUString& ResourceURL, const css::uno::Sequence<css::beans::PropertyValue>& Arguments)
61{
62 try
63 {
65 auto xFrame(aArguments.getOrDefault("Frame", css::uno::Reference<css::frame::XFrame>()));
66 auto xParentWindow(
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);
70
71 weld::Widget* pParent(nullptr);
72 if (auto pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
73 pParent = pTunnel->getWidget();
74
75 if (!pParent)
76 throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no ParentWindow");
77 if (!xFrame)
78 throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no Frame");
79 if (!pBindings)
80 throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no SfxBindings");
81
82 std::unique_ptr<PanelLayout> pPanel;
83 css::ui::LayoutSize aLayoutSize{ -1, -1, -1 };
84 if (ResourceURL.endsWith("/MathPropertiesPanel"))
85 {
86 pPanel = sm::sidebar::SmPropertiesPanel::Create(*pParent, xFrame);
87 }
88 else if (ResourceURL.endsWith("/MathElementsPanel"))
89 {
90 pPanel = sm::sidebar::SmElementsPanel::Create(*pParent, *pBindings);
91 aLayoutSize = { 300, -1, -1 };
92 }
93
94 if (pPanel)
95 return sfx2::sidebar::SidebarPanelBase::Create(ResourceURL, xFrame, std::move(pPanel),
96 aLayoutSize);
97 }
98 catch (const css::uno::RuntimeException&)
99 {
100 throw;
101 }
102 catch (const css::uno::Exception&)
103 {
104 css::uno::Any anyEx = cppu::getCaughtException();
105 throw css::lang::WrappedTargetRuntimeException("SmPanelFactory::createUIElement exception",
106 nullptr, anyEx);
107 }
108
109 return {};
110}
111
112OUString SmPanelFactory::getImplementationName()
113{
114 return "org.libreoffice.comp.Math.sidebar.SmPanelFactory";
115}
116
117sal_Bool SmPanelFactory::supportsService(OUString const& ServiceName)
118{
119 return cppu::supportsService(this, ServiceName);
120}
121
122css::uno::Sequence<OUString> SmPanelFactory::getSupportedServiceNames()
123{
124 return { "com.sun.star.ui.UIElementFactory" };
125}
126
127} // end of unnamed namespace
128
129extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
131 css::uno::Sequence<css::uno::Any> const&)
132{
133 return cppu::acquire(new SmPanelFactory);
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_libreoffice_comp_Math_sidebar_SmPanelFactory(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static css::uno::Reference< css::ui::XUIElement > Create(const OUString &rsResourceURL, const css::uno::Reference< css::frame::XFrame > &rxFrame, std::unique_ptr< PanelLayout > xControl, const css::ui::LayoutSize &rLayoutSize)
static std::unique_ptr< PanelLayout > Create(weld::Widget &rParent, const SfxBindings &rBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget &rParent, const css::uno::Reference< css::frame::XFrame > &xFrame)
Sequence< PropertyValue > aArguments
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
Reference< XFrame > xFrame
unsigned char sal_Bool