cid#1640468 Dereference after null check
[LibreOffice.git] / sd / source / ui / sidebar / PanelFactory.cxx
blob175ea84e6beb5ef3381c6ccd4382c19c1134a9c2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "PanelFactory.hxx"
21 #include <framework/Pane.hxx>
22 #include <ViewShellBase.hxx>
23 #include <DrawController.hxx>
24 #include "LayoutMenu.hxx"
25 #include "CurrentMasterPagesSelector.hxx"
26 #include "RecentMasterPagesSelector.hxx"
27 #include "AllMasterPagesSelector.hxx"
28 #include <CustomAnimationPane.hxx>
29 #include "NavigatorWrapper.hxx"
30 #include <SlideTransitionPane.hxx>
31 #include <TableDesignPane.hxx>
32 #include "SlideBackground.hxx"
34 #include <sfx2/sidebar/SidebarPanelBase.hxx>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <comphelper/namedvaluecollection.hxx>
37 #include <comphelper/servicehelper.hxx>
38 #include <cppuhelper/supportsservice.hxx>
39 #include <vcl/weldutils.hxx>
41 using namespace css;
42 using namespace css::uno;
44 namespace sd::sidebar {
46 //----- PanelFactory --------------------------------------------------------
48 PanelFactory::PanelFactory()
52 PanelFactory::~PanelFactory()
56 // XUIElementFactory
58 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
59 const OUString& rsUIElementResourceURL,
60 const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
62 // Process arguments.
63 const ::comphelper::NamedValueCollection aArguments (rArguments);
64 Reference<frame::XFrame> xFrame (aArguments.getOrDefault(u"Frame"_ustr, Reference<frame::XFrame>()));
65 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault(u"ParentWindow"_ustr, Reference<awt::XWindow>()));
66 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault(u"Sidebar"_ustr, Reference<ui::XSidebar>()));
68 // Throw exceptions when the arguments are not as expected.
69 weld::Widget* pParent(nullptr);
70 if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
71 pParent = pTunnel->getWidget();
73 if (!pParent)
74 throw RuntimeException(
75 u"PanelFactory::createUIElement called without ParentWindow"_ustr);
76 if ( ! xFrame.is())
77 throw RuntimeException(
78 u"PanelFactory::createUIElement called without XFrame"_ustr);
80 // Tunnel through the controller to obtain a ViewShellBase.
81 ViewShellBase* pBase = nullptr;
82 rtl::Reference<sd::DrawController> pController = dynamic_cast<sd::DrawController*>(xFrame->getController().get());
83 if (pController != nullptr)
84 pBase = pController->GetViewShellBase();
85 if (pBase == nullptr)
86 throw RuntimeException(u"can not get ViewShellBase for frame"_ustr);
88 // Get bindings from given arguments.
89 const sal_uInt64 nBindingsValue (aArguments.getOrDefault(u"SfxBindings"_ustr, sal_uInt64(0)));
90 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
92 // Create a framework view.
93 std::unique_ptr<PanelLayout> xControl;
94 css::ui::LayoutSize aLayoutSize (-1,-1,-1);
96 /** Note that these names have to be identical to (the tail of)
97 the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
98 for the TaskPanelFactory.
100 if (rsUIElementResourceURL.endsWith("/CustomAnimations"))
101 xControl = std::make_unique<CustomAnimationPane>(pParent, *pBase);
102 else if (rsUIElementResourceURL.endsWith("/Layouts"))
103 xControl = std::make_unique<LayoutMenu>(pParent, *pBase, xSidebar);
104 else if (rsUIElementResourceURL.endsWith("/AllMasterPages"))
105 xControl = AllMasterPagesSelector::Create(pParent, *pBase, xSidebar);
106 else if (rsUIElementResourceURL.endsWith("/RecentMasterPages"))
107 xControl = RecentMasterPagesSelector::Create(pParent, *pBase, xSidebar);
108 else if (rsUIElementResourceURL.endsWith("/UsedMasterPages"))
109 xControl = CurrentMasterPagesSelector::Create(pParent, *pBase, xSidebar);
110 else if (rsUIElementResourceURL.endsWith("/SlideTransitions"))
111 xControl = std::make_unique<SlideTransitionPane>(pParent, *pBase);
112 else if (rsUIElementResourceURL.endsWith("/TableDesign"))
113 xControl = std::make_unique<TableDesignPane>(pParent, *pBase);
114 else if (rsUIElementResourceURL.endsWith("/NavigatorPanel"))
115 xControl = std::make_unique<NavigatorWrapper>(pParent, *pBase, pBindings);
116 else if (rsUIElementResourceURL.endsWith("/SlideBackgroundPanel"))
117 xControl = std::make_unique<SlideBackground>(pParent, *pBase, xFrame, pBindings);
119 if (!xControl)
120 throw lang::IllegalArgumentException();
122 // Create a wrapper around the control that implements the
123 // necessary UNO interfaces.
124 return sfx2::sidebar::SidebarPanelBase::Create(
125 rsUIElementResourceURL,
126 xFrame,
127 std::move(xControl),
128 aLayoutSize);
131 OUString PanelFactory::getImplementationName() {
132 return u"org.openoffice.comp.Draw.framework.PanelFactory"_ustr;
135 sal_Bool PanelFactory::supportsService(OUString const & ServiceName) {
136 return cppu::supportsService(this, ServiceName);
139 css::uno::Sequence<OUString> PanelFactory::getSupportedServiceNames() {
140 return {u"com.sun.star.drawing.framework.PanelFactory"_ustr};
143 } // end of namespace sd::sidebar
146 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
147 org_openoffice_comp_Draw_framework_PanelFactory_get_implementation(css::uno::XComponentContext* /*context*/,
148 css::uno::Sequence<css::uno::Any> const &)
150 return cppu::acquire(new sd::sidebar::PanelFactory);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */