xref: /core/sc/source/ui/sidebar/ScPanelFactory.cxx (revision 83d0b6bd)
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 "ScPanelFactory.hxx"
21 
22 #include "AlignmentPropertyPanel.hxx"
23 #include "CellAppearancePropertyPanel.hxx"
24 #include "NumberFormatPropertyPanel.hxx"
25 #include <navipi.hxx>
26 #include <dwfunctr.hxx>
27 
28 #include <sfx2/sidebar/SidebarPanelBase.hxx>
29 #include <vcl/weldutils.hxx>
30 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
31 #include <comphelper/namedvaluecollection.hxx>
32 #include <cppuhelper/exc_hlp.hxx>
33 #include <cppuhelper/supportsservice.hxx>
34 
35 using namespace css;
36 using namespace css::uno;
37 
38 namespace sc::sidebar {
39 
ScPanelFactory()40 ScPanelFactory::ScPanelFactory()
41 {
42 }
43 
~ScPanelFactory()44 ScPanelFactory::~ScPanelFactory()
45 {
46 }
47 
createUIElement(const OUString & rsResourceURL,const::css::uno::Sequence<css::beans::PropertyValue> & rArguments)48 Reference<ui::XUIElement> SAL_CALL ScPanelFactory::createUIElement (
49     const OUString& rsResourceURL,
50     const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
51 {
52     Reference<ui::XUIElement> xElement;
53 
54     try
55     {
56         const ::comphelper::NamedValueCollection aArguments (rArguments);
57         Reference<frame::XFrame> xFrame (aArguments.getOrDefault(u"Frame"_ustr, Reference<frame::XFrame>()));
58         Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault(u"ParentWindow"_ustr, Reference<awt::XWindow>()));
59         const sal_uInt64 nBindingsValue (aArguments.getOrDefault(u"SfxBindings"_ustr, sal_uInt64(0)));
60         SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
61 
62         weld::Widget* pParent(nullptr);
63         if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
64             pParent = pTunnel->getWidget();
65 
66         if (!pParent)
67             throw RuntimeException(
68                 u"PanelFactory::createUIElement called without ParentWindow"_ustr,
69                 nullptr);
70         if ( ! xFrame.is())
71             throw RuntimeException(
72                 u"PanelFactory::createUIElement called without Frame"_ustr,
73                 nullptr);
74         if (pBindings == nullptr)
75             throw RuntimeException(
76                 u"PanelFactory::createUIElement called without SfxBindings"_ustr,
77                 nullptr);
78 
79         sal_Int32 nMinimumSize = -1;
80         std::unique_ptr<PanelLayout> xPanel;
81         if (rsResourceURL.endsWith("/AlignmentPropertyPanel"))
82             xPanel = AlignmentPropertyPanel::Create( pParent, xFrame, pBindings );
83         else if (rsResourceURL.endsWith("/CellAppearancePropertyPanel"))
84             xPanel = CellAppearancePropertyPanel::Create( pParent, xFrame, pBindings );
85         else if (rsResourceURL.endsWith("/NumberFormatPropertyPanel"))
86             xPanel = NumberFormatPropertyPanel::Create( pParent, xFrame, pBindings );
87         else if (rsResourceURL.endsWith("/NavigatorPanel"))
88         {
89             xPanel = std::make_unique<ScNavigatorDlg>(pBindings, pParent, nullptr);
90             nMinimumSize = 0;
91         }
92         else if (rsResourceURL.endsWith("/FunctionsPanel"))
93         {
94             xPanel = std::make_unique<ScFunctionWin>(pParent);
95             nMinimumSize = 0;
96         }
97 
98         if (xPanel)
99             xElement = sfx2::sidebar::SidebarPanelBase::Create(
100                 rsResourceURL,
101                 xFrame,
102                 std::move(xPanel),
103                 ui::LayoutSize(nMinimumSize,-1,-1));
104     }
105     catch (const uno::RuntimeException &)
106     {
107         throw;
108     }
109     catch (const uno::Exception&)
110     {
111         css::uno::Any anyEx = cppu::getCaughtException();
112         throw lang::WrappedTargetRuntimeException(
113             u"ScPanelFactory::createUIElement exception"_ustr,
114             nullptr, anyEx);
115     }
116 
117     return xElement;
118 }
119 
getImplementationName()120 OUString ScPanelFactory::getImplementationName()
121 {
122     return u"org.apache.openoffice.comp.sc.sidebar.ScPanelFactory"_ustr;
123 }
124 
supportsService(OUString const & ServiceName)125 sal_Bool ScPanelFactory::supportsService(OUString const & ServiceName)
126 {
127     return cppu::supportsService(this, ServiceName);
128 }
129 
getSupportedServiceNames()130 css::uno::Sequence<OUString> ScPanelFactory::getSupportedServiceNames()
131 {
132     return { u"com.sun.star.ui.UIElementFactory"_ustr };
133 }
134 
135 } // end of namespace sc::sidebar
136 
137 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
ScPanelFactory_get_implementation(css::uno::XComponentContext *,css::uno::Sequence<css::uno::Any> const &)138 ScPanelFactory_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
139 {
140     return cppu::acquire(new sc::sidebar::ScPanelFactory());
141 }
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
144