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