Line data Source code
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 "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 "CustomAnimationPanel.hxx"
29 : #include "NavigatorWrapper.hxx"
30 : #include "SlideTransitionPanel.hxx"
31 : #include "TableDesignPanel.hxx"
32 :
33 : #include <sfx2/viewfrm.hxx>
34 : #include <sfx2/sidebar/SidebarPanelBase.hxx>
35 : #include <comphelper/namedvaluecollection.hxx>
36 : #include <vcl/window.hxx>
37 : #include <toolkit/helper/vclunohelper.hxx>
38 :
39 : using namespace css;
40 : using namespace cssu;
41 : using namespace ::sd::framework;
42 : using ::rtl::OUString;
43 :
44 : namespace sd { namespace sidebar {
45 :
46 : namespace {
47 : /** Note that these names have to be identical to (the tail of)
48 : the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
49 : for the TaskPanelFactory.
50 : */
51 : const static char* gsResourceNameCustomAnimations = "/CustomAnimations";
52 : const static char* gsResourceNameLayouts = "/Layouts";
53 : const static char* gsResourceNameAllMasterPages = "/AllMasterPages";
54 : const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages";
55 : const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages";
56 : const static char* gsResourceNameSlideTransitions = "/SlideTransitions";
57 : const static char* gsResourceNameTableDesign = "/TableDesign";
58 : const static char* gsResourceNameNavigator = "/NavigatorPanel";
59 : }
60 :
61 0 : Reference<lang::XEventListener> mxControllerDisposeListener;
62 :
63 :
64 :
65 : // ----- Service functions ----------------------------------------------------
66 :
67 0 : Reference<XInterface> SAL_CALL PanelFactory_createInstance (
68 : const Reference<XComponentContext>& rxContext)
69 : {
70 0 : return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext)));
71 : }
72 :
73 :
74 :
75 :
76 0 : ::rtl::OUString PanelFactory_getImplementationName (void) throw(RuntimeException)
77 : {
78 0 : return OUString("org.openoffice.comp.Draw.framework.PanelFactory");
79 : }
80 :
81 :
82 :
83 :
84 0 : Sequence<rtl::OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void)
85 : throw (RuntimeException)
86 : {
87 0 : static const ::rtl::OUString sServiceName("com.sun.star.drawing.framework.PanelFactory");
88 0 : return Sequence<rtl::OUString>(&sServiceName, 1);
89 : }
90 :
91 :
92 :
93 :
94 : //----- PanelFactory --------------------------------------------------------
95 :
96 0 : PanelFactory::PanelFactory(
97 : const css::uno::Reference<css::uno::XComponentContext>& /*rxContext*/)
98 0 : : PanelFactoryInterfaceBase(m_aMutex)
99 : {
100 0 : }
101 :
102 :
103 :
104 :
105 0 : PanelFactory::~PanelFactory (void)
106 : {
107 0 : }
108 :
109 :
110 :
111 :
112 0 : void SAL_CALL PanelFactory::disposing (void)
113 : {
114 0 : }
115 :
116 :
117 :
118 :
119 : // XUIElementFactory
120 :
121 0 : Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
122 : const ::rtl::OUString& rsUIElementResourceURL,
123 : const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
124 : throw(
125 : css::container::NoSuchElementException,
126 : css::lang::IllegalArgumentException,
127 : cssu::RuntimeException, std::exception)
128 : {
129 : // Process arguments.
130 0 : const ::comphelper::NamedValueCollection aArguments (rArguments);
131 0 : Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
132 0 : Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
133 0 : Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
134 :
135 : // Throw exceptions when the arguments are not as expected.
136 0 : ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
137 0 : if ( ! xParentWindow.is() || pParentWindow==NULL)
138 : throw RuntimeException(
139 : OUString("PanelFactory::createUIElement called without ParentWindow"),
140 0 : NULL);
141 0 : if ( ! xFrame.is())
142 : throw RuntimeException(
143 : OUString("PanelFactory::createUIElement called without XFrame"),
144 0 : NULL);
145 :
146 : // Tunnel through the controller to obtain a ViewShellBase.
147 0 : ViewShellBase* pBase = NULL;
148 0 : Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
149 0 : if (xTunnel.is())
150 : {
151 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
152 0 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
153 0 : if (pController != NULL)
154 0 : pBase = pController->GetViewShellBase();
155 : }
156 0 : if (pBase == NULL)
157 0 : throw RuntimeException("can not get ViewShellBase for frame", NULL);
158 :
159 : // Get bindings from given arguments.
160 0 : const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
161 0 : SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
162 :
163 : // Create a framework view.
164 0 : ::Window* pControl = NULL;
165 0 : css::ui::LayoutSize aLayoutSize (-1,-1,-1);
166 :
167 : #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t))
168 0 : if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations))
169 0 : pControl = new CustomAnimationPanel(pParentWindow, *pBase, xFrame);
170 0 : else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts))
171 0 : pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar);
172 0 : else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages))
173 0 : pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
174 0 : else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages))
175 0 : pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
176 0 : else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages))
177 0 : pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
178 0 : else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions))
179 0 : pControl = new SlideTransitionPanel(pParentWindow, *pBase, xFrame);
180 0 : else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign))
181 0 : pControl = new TableDesignPanel(pParentWindow, *pBase);
182 0 : else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator))
183 0 : pControl = new NavigatorWrapper(pParentWindow, *pBase, pBindings);
184 : #undef EndsWith
185 :
186 0 : if (pControl == NULL)
187 0 : throw lang::IllegalArgumentException();
188 :
189 : // Create a wrapper around the control that implements the
190 : // necessary UNO interfaces.
191 : return sfx2::sidebar::SidebarPanelBase::Create(
192 : rsUIElementResourceURL,
193 : xFrame,
194 : pControl,
195 0 : aLayoutSize);
196 : }
197 :
198 :
199 :
200 :
201 0 : } } // end of namespace sd::sidebar
202 :
203 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|