bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / sidebar / PanelFactory.cxx
blob4750ee9494d26ff4449a25676f3c3abfe73a86cf
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 <facreg.hxx>
22 #include <framework/Pane.hxx>
23 #include <ViewShellBase.hxx>
24 #include <DrawController.hxx>
25 #include "LayoutMenu.hxx"
26 #include "CurrentMasterPagesSelector.hxx"
27 #include "RecentMasterPagesSelector.hxx"
28 #include "AllMasterPagesSelector.hxx"
29 #include "CustomAnimationPanel.hxx"
30 #include "NavigatorWrapper.hxx"
31 #include "SlideTransitionPanel.hxx"
32 #include "TableDesignPanel.hxx"
33 #include "SlideBackground.hxx"
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/sidebar/SidebarPanelBase.hxx>
37 #include <comphelper/namedvaluecollection.hxx>
38 #include <vcl/window.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
41 using namespace css;
42 using namespace css::uno;
43 using namespace ::sd::framework;
45 namespace sd { namespace sidebar {
47 static Reference<lang::XEventListener> mxControllerDisposeListener;
49 //----- PanelFactory --------------------------------------------------------
51 PanelFactory::PanelFactory()
52 : PanelFactoryInterfaceBase(m_aMutex)
56 PanelFactory::~PanelFactory()
60 void SAL_CALL PanelFactory::disposing()
64 // XUIElementFactory
66 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
67 const OUString& rsUIElementResourceURL,
68 const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
70 // Process arguments.
71 const ::comphelper::NamedValueCollection aArguments (rArguments);
72 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
73 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
74 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
76 // Throw exceptions when the arguments are not as expected.
77 VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
78 if ( ! xParentWindow.is() || !pParentWindow)
79 throw RuntimeException(
80 "PanelFactory::createUIElement called without ParentWindow");
81 if ( ! xFrame.is())
82 throw RuntimeException(
83 "PanelFactory::createUIElement called without XFrame");
85 // Tunnel through the controller to obtain a ViewShellBase.
86 ViewShellBase* pBase = nullptr;
87 Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
88 if (xTunnel.is())
90 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
91 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
92 if (pController != nullptr)
93 pBase = pController->GetViewShellBase();
95 if (pBase == nullptr)
96 throw RuntimeException("can not get ViewShellBase for frame");
98 // Get bindings from given arguments.
99 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
100 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
102 // Create a framework view.
103 VclPtr<vcl::Window> pControl;
104 css::ui::LayoutSize aLayoutSize (-1,-1,-1);
106 /** Note that these names have to be identical to (the tail of)
107 the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
108 for the TaskPanelFactory.
110 if (rsUIElementResourceURL.endsWith("/CustomAnimations"))
111 pControl = VclPtr<CustomAnimationPanel>::Create(pParentWindow, *pBase, xFrame);
112 else if (rsUIElementResourceURL.endsWith("/Layouts"))
113 pControl = VclPtr<LayoutMenu>::Create(pParentWindow, *pBase, xSidebar);
114 else if (rsUIElementResourceURL.endsWith("/AllMasterPages"))
115 pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
116 else if (rsUIElementResourceURL.endsWith("/RecentMasterPages"))
117 pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
118 else if (rsUIElementResourceURL.endsWith("/UsedMasterPages"))
119 pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
120 else if (rsUIElementResourceURL.endsWith("/SlideTransitions"))
121 pControl = VclPtr<SlideTransitionPanel>::Create(pParentWindow, *pBase, xFrame);
122 else if (rsUIElementResourceURL.endsWith("/TableDesign"))
123 pControl = VclPtr<TableDesignPanel>::Create(pParentWindow, *pBase);
124 else if (rsUIElementResourceURL.endsWith("/NavigatorPanel"))
125 pControl = VclPtr<NavigatorWrapper>::Create(pParentWindow, *pBase, pBindings);
126 else if (rsUIElementResourceURL.endsWith("/SlideBackgroundPanel"))
127 pControl = VclPtr<SlideBackground>::Create(pParentWindow, *pBase, xFrame, pBindings);
129 if (!pControl)
130 throw lang::IllegalArgumentException();
132 // Create a wrapper around the control that implements the
133 // necessary UNO interfaces.
134 return sfx2::sidebar::SidebarPanelBase::Create(
135 rsUIElementResourceURL,
136 xFrame,
137 pControl,
138 aLayoutSize);
141 } } // end of namespace sd::sidebar
144 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
145 org_openoffice_comp_Draw_framework_PanelFactory_get_implementation(css::uno::XComponentContext* /*context*/,
146 css::uno::Sequence<css::uno::Any> const &)
148 return cppu::acquire(new sd::sidebar::PanelFactory);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */