1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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>
42 using namespace css::uno
;
43 using namespace ::sd::framework
;
44 using ::rtl::OUString
;
46 namespace sd
{ namespace sidebar
{
48 static Reference
<lang::XEventListener
> mxControllerDisposeListener
;
50 //----- PanelFactory --------------------------------------------------------
52 PanelFactory::PanelFactory()
53 : PanelFactoryInterfaceBase(m_aMutex
)
57 PanelFactory::~PanelFactory()
61 void SAL_CALL
PanelFactory::disposing()
67 Reference
<ui::XUIElement
> SAL_CALL
PanelFactory::createUIElement (
68 const ::rtl::OUString
& rsUIElementResourceURL
,
69 const css::uno::Sequence
<css::beans::PropertyValue
>& rArguments
)
72 const ::comphelper::NamedValueCollection
aArguments (rArguments
);
73 Reference
<frame::XFrame
> xFrame (aArguments
.getOrDefault("Frame", Reference
<frame::XFrame
>()));
74 Reference
<awt::XWindow
> xParentWindow (aArguments
.getOrDefault("ParentWindow", Reference
<awt::XWindow
>()));
75 Reference
<ui::XSidebar
> xSidebar (aArguments
.getOrDefault("Sidebar", Reference
<ui::XSidebar
>()));
77 // Throw exceptions when the arguments are not as expected.
78 VclPtr
<vcl::Window
> pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
79 if ( ! xParentWindow
.is() || !pParentWindow
)
80 throw RuntimeException(
81 "PanelFactory::createUIElement called without ParentWindow");
83 throw RuntimeException(
84 "PanelFactory::createUIElement called without XFrame");
86 // Tunnel through the controller to obtain a ViewShellBase.
87 ViewShellBase
* pBase
= nullptr;
88 Reference
<lang::XUnoTunnel
> xTunnel (xFrame
->getController(), UNO_QUERY
);
91 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
92 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
93 if (pController
!= nullptr)
94 pBase
= pController
->GetViewShellBase();
97 throw RuntimeException("can not get ViewShellBase for frame");
99 // Get bindings from given arguments.
100 const sal_uInt64
nBindingsValue (aArguments
.getOrDefault("SfxBindings", sal_uInt64(0)));
101 SfxBindings
* pBindings
= reinterpret_cast<SfxBindings
*>(nBindingsValue
);
103 // Create a framework view.
104 VclPtr
<vcl::Window
> pControl
;
105 css::ui::LayoutSize
aLayoutSize (-1,-1,-1);
107 /** Note that these names have to be identical to (the tail of)
108 the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
109 for the TaskPanelFactory.
111 if (rsUIElementResourceURL
.endsWith("/CustomAnimations"))
112 pControl
= VclPtr
<CustomAnimationPanel
>::Create(pParentWindow
, *pBase
, xFrame
);
113 else if (rsUIElementResourceURL
.endsWith("/Layouts"))
114 pControl
= VclPtr
<LayoutMenu
>::Create(pParentWindow
, *pBase
, xSidebar
);
115 else if (rsUIElementResourceURL
.endsWith("/AllMasterPages"))
116 pControl
= AllMasterPagesSelector::Create(pParentWindow
, *pBase
, xSidebar
);
117 else if (rsUIElementResourceURL
.endsWith("/RecentMasterPages"))
118 pControl
= RecentMasterPagesSelector::Create(pParentWindow
, *pBase
, xSidebar
);
119 else if (rsUIElementResourceURL
.endsWith("/UsedMasterPages"))
120 pControl
= CurrentMasterPagesSelector::Create(pParentWindow
, *pBase
, xSidebar
);
121 else if (rsUIElementResourceURL
.endsWith("/SlideTransitions"))
122 pControl
= VclPtr
<SlideTransitionPanel
>::Create(pParentWindow
, *pBase
, xFrame
);
123 else if (rsUIElementResourceURL
.endsWith("/TableDesign"))
124 pControl
= VclPtr
<TableDesignPanel
>::Create(pParentWindow
, *pBase
);
125 else if (rsUIElementResourceURL
.endsWith("/NavigatorPanel"))
126 pControl
= VclPtr
<NavigatorWrapper
>::Create(pParentWindow
, *pBase
, pBindings
);
127 else if (rsUIElementResourceURL
.endsWith("/SlideBackgroundPanel"))
128 pControl
= VclPtr
<SlideBackground
>::Create(pParentWindow
, *pBase
, xFrame
, pBindings
);
131 throw lang::IllegalArgumentException();
133 // Create a wrapper around the control that implements the
134 // necessary UNO interfaces.
135 return sfx2::sidebar::SidebarPanelBase::Create(
136 rsUIElementResourceURL
,
142 } } // end of namespace sd::sidebar
145 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
146 org_openoffice_comp_Draw_framework_PanelFactory_get_implementation(css::uno::XComponentContext
* /*context*/,
147 css::uno::Sequence
<css::uno::Any
> const &)
149 return cppu::acquire(new sd::sidebar::PanelFactory
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */