bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / sidebar / PanelFactory.cxx
blob3adab6c29a0c19046cb072a3a82a192599b66e09
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"
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/sidebar/SidebarPanelBase.hxx>
36 #include <comphelper/namedvaluecollection.hxx>
37 #include <vcl/window.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
40 using namespace css;
41 using namespace css::uno;
42 using namespace ::sd::framework;
43 using ::rtl::OUString;
45 namespace sd { namespace sidebar {
47 namespace {
48 /** Note that these names have to be identical to (the tail of)
49 the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
50 for the TaskPanelFactory.
52 const static char* gsResourceNameCustomAnimations = "/CustomAnimations";
53 const static char* gsResourceNameLayouts = "/Layouts";
54 const static char* gsResourceNameAllMasterPages = "/AllMasterPages";
55 const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages";
56 const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages";
57 const static char* gsResourceNameSlideTransitions = "/SlideTransitions";
58 const static char* gsResourceNameTableDesign = "/TableDesign";
59 const static char* gsResourceNameNavigator = "/NavigatorPanel";
62 Reference<lang::XEventListener> mxControllerDisposeListener;
64 //----- PanelFactory --------------------------------------------------------
66 PanelFactory::PanelFactory(
67 const css::uno::Reference<css::uno::XComponentContext>& /*rxContext*/)
68 : PanelFactoryInterfaceBase(m_aMutex)
72 PanelFactory::~PanelFactory()
76 void SAL_CALL PanelFactory::disposing()
80 // XUIElementFactory
82 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
83 const ::rtl::OUString& rsUIElementResourceURL,
84 const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
85 throw(
86 css::container::NoSuchElementException,
87 css::lang::IllegalArgumentException,
88 css::uno::RuntimeException, std::exception)
90 // Process arguments.
91 const ::comphelper::NamedValueCollection aArguments (rArguments);
92 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
93 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
94 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
96 // Throw exceptions when the arguments are not as expected.
97 vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
98 if ( ! xParentWindow.is() || pParentWindow==NULL)
99 throw RuntimeException(
100 "PanelFactory::createUIElement called without ParentWindow");
101 if ( ! xFrame.is())
102 throw RuntimeException(
103 "PanelFactory::createUIElement called without XFrame");
105 // Tunnel through the controller to obtain a ViewShellBase.
106 ViewShellBase* pBase = NULL;
107 Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
108 if (xTunnel.is())
110 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
111 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
112 if (pController != NULL)
113 pBase = pController->GetViewShellBase();
115 if (pBase == NULL)
116 throw RuntimeException("can not get ViewShellBase for frame");
118 // Get bindings from given arguments.
119 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
120 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
122 // Create a framework view.
123 VclPtr<vcl::Window> pControl;
124 css::ui::LayoutSize aLayoutSize (-1,-1,-1);
126 #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t))
127 if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations))
128 pControl = VclPtr<CustomAnimationPanel>::Create(pParentWindow, *pBase, xFrame);
129 else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts))
130 pControl = VclPtr<LayoutMenu>::Create(pParentWindow, *pBase, xSidebar);
131 else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages))
132 pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
133 else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages))
134 pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
135 else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages))
136 pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
137 else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions))
138 pControl = VclPtr<SlideTransitionPanel>::Create(pParentWindow, *pBase, xFrame);
139 else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign))
140 pControl = VclPtr<TableDesignPanel>::Create(pParentWindow, *pBase);
141 else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator))
142 pControl = VclPtr<NavigatorWrapper>::Create(pParentWindow, *pBase, pBindings);
143 #undef EndsWith
145 if (!pControl)
146 throw lang::IllegalArgumentException();
148 // Create a wrapper around the control that implements the
149 // necessary UNO interfaces.
150 return sfx2::sidebar::SidebarPanelBase::Create(
151 rsUIElementResourceURL,
152 xFrame,
153 pControl,
154 aLayoutSize);
157 } } // end of namespace sd::sidebar
160 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
161 org_openoffice_comp_Draw_framework_PanelFactory_get_implementation(::com::sun::star::uno::XComponentContext* context,
162 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
164 return cppu::acquire(new sd::sidebar::PanelFactory(context));
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */