tdf#164420 Fix unselected Check/Radio buttons not following themes in GTK
[LibreOffice.git] / starmath / source / SmPanelFactory.cxx
blob833530ace90d3d89d9aa2dc5576aa60065e74116
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.
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"
35 namespace
37 typedef comphelper::WeakComponentImplHelper<css::ui::XUIElementFactory, css::lang::XServiceInfo>
38 PanelFactoryInterfaceBase;
40 class SmPanelFactory final : public PanelFactoryInterfaceBase
42 public:
43 SmPanelFactory() = default;
45 SmPanelFactory(const SmPanelFactory&) = delete;
46 const SmPanelFactory& operator=(const SmPanelFactory&) = delete;
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;
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;
59 css::uno::Reference<css::ui::XUIElement> SAL_CALL SmPanelFactory::createUIElement(
60 const OUString& ResourceURL, const css::uno::Sequence<css::beans::PropertyValue>& Arguments)
62 try
64 const comphelper::NamedValueCollection aArguments(Arguments);
65 auto xFrame(
66 aArguments.getOrDefault(u"Frame"_ustr, css::uno::Reference<css::frame::XFrame>()));
67 auto xParentWindow(aArguments.getOrDefault(u"ParentWindow"_ustr,
68 css::uno::Reference<css::awt::XWindow>()));
69 const sal_uInt64 nBindingsValue(
70 aArguments.getOrDefault(u"SfxBindings"_ustr, sal_uInt64(0)));
71 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
73 weld::Widget* pParent(nullptr);
74 if (auto pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
75 pParent = pTunnel->getWidget();
77 if (!pParent)
78 throw css::uno::RuntimeException(
79 u"SmPanelFactory::createUIElement: no ParentWindow"_ustr);
80 if (!xFrame)
81 throw css::uno::RuntimeException(u"SmPanelFactory::createUIElement: no Frame"_ustr);
82 if (!pBindings)
83 throw css::uno::RuntimeException(
84 u"SmPanelFactory::createUIElement: no SfxBindings"_ustr);
86 std::unique_ptr<PanelLayout> pPanel;
87 css::ui::LayoutSize aLayoutSize{ -1, -1, -1 };
88 if (ResourceURL.endsWith("/MathPropertiesPanel"))
90 pPanel = sm::sidebar::SmPropertiesPanel::Create(*pParent, xFrame);
92 else if (ResourceURL.endsWith("/MathElementsPanel"))
94 pPanel = sm::sidebar::SmElementsPanel::Create(*pParent, *pBindings);
95 aLayoutSize = { 300, -1, -1 };
98 if (pPanel)
99 return sfx2::sidebar::SidebarPanelBase::Create(ResourceURL, xFrame, std::move(pPanel),
100 aLayoutSize);
102 catch (const css::uno::RuntimeException&)
104 throw;
106 catch (const css::uno::Exception&)
108 css::uno::Any anyEx = cppu::getCaughtException();
109 throw css::lang::WrappedTargetRuntimeException(
110 u"SmPanelFactory::createUIElement exception"_ustr, nullptr, anyEx);
113 return {};
116 OUString SmPanelFactory::getImplementationName()
118 return u"org.libreoffice.comp.Math.sidebar.SmPanelFactory"_ustr;
121 sal_Bool SmPanelFactory::supportsService(OUString const& ServiceName)
123 return cppu::supportsService(this, ServiceName);
126 css::uno::Sequence<OUString> SmPanelFactory::getSupportedServiceNames()
128 return { u"com.sun.star.ui.UIElementFactory"_ustr };
131 } // end of unnamed namespace
133 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
134 org_libreoffice_comp_Math_sidebar_SmPanelFactory(css::uno::XComponentContext*,
135 css::uno::Sequence<css::uno::Any> const&)
137 return cppu::acquire(new SmPanelFactory);
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */