1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include "precompiled_sd.hxx"
23
24 #include "PanelFactory.hxx"
25 #include "framework/Pane.hxx"
26 #include "ViewShellBase.hxx"
27 #include "DrawController.hxx"
28 #include "LayoutMenu.hxx"
29 #include "CurrentMasterPagesSelector.hxx"
30 #include "RecentMasterPagesSelector.hxx"
31 #include "AllMasterPagesSelector.hxx"
32 #include "CustomAnimationPanel.hxx"
33 #include "SlideTransitionPanel.hxx"
34 #include "NavigatorWrapper.hxx"
35
36 #include <sfx2/viewfrm.hxx>
37 #include <sfx2/sidebar/SidebarPanelBase.hxx>
38 #include <comphelper/namedvaluecollection.hxx>
39 #include <vcl/window.hxx>
40 #include <toolkit/helper/vclunohelper.hxx>
41
42 using namespace css;
43 using namespace cssu;
44 using namespace ::sd::framework;
45 using ::rtl::OUString;
46
47 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
48
49 namespace sd {
50 extern ::Window * createTableDesignPanel (::Window* pParent, ViewShellBase& rBase);
51 }
52
53 namespace sd { namespace sidebar {
54
55 namespace {
56 /** Note that these names have to be identical to (the tail of)
57 the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
58 for the TaskPanelFactory.
59 */
60 const static char* gsResourceNameCustomAnimations = "/CustomAnimations";
61 const static char* gsResourceNameLayouts = "/Layouts";
62 const static char* gsResourceNameAllMasterPages = "/AllMasterPages";
63 const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages";
64 const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages";
65 const static char* gsResourceNameSlideTransitions = "/SlideTransitions";
66 const static char* gsResourceNameTableDesign = "/TableDesign";
67 const static char* gsResourceNameNavigator = "/NavigatorPanel";
68 }
69
70 Reference<lang::XEventListener> mxControllerDisposeListener;
71
72
73
74 // ----- Service functions ----------------------------------------------------
75
PanelFactory_createInstance(const Reference<XComponentContext> & rxContext)76 Reference<XInterface> SAL_CALL PanelFactory_createInstance (
77 const Reference<XComponentContext>& rxContext)
78 {
79 return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext)));
80 }
81
82
83
84
PanelFactory_getImplementationName(void)85 ::rtl::OUString PanelFactory_getImplementationName (void) throw(RuntimeException)
86 {
87 return ::rtl::OUString(
88 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.PanelFactory"));
89 }
90
91
92
93
PanelFactory_getSupportedServiceNames(void)94 Sequence<rtl::OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void)
95 throw (RuntimeException)
96 {
97 static const ::rtl::OUString sServiceName(
98 ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.PanelFactory"));
99 return Sequence<rtl::OUString>(&sServiceName, 1);
100 }
101
102
103
104
105 //----- PanelFactory --------------------------------------------------------
106
PanelFactory(const css::uno::Reference<css::uno::XComponentContext> & rxContext)107 PanelFactory::PanelFactory(
108 const css::uno::Reference<css::uno::XComponentContext>& rxContext)
109 : PanelFactoryInterfaceBase(m_aMutex)
110 {
111 }
112
113
114
115
~PanelFactory(void)116 PanelFactory::~PanelFactory (void)
117 {
118 }
119
120
121
122
disposing(void)123 void SAL_CALL PanelFactory::disposing (void)
124 {
125 }
126
127
128
129
130 // XUIElementFactory
131
createUIElement(const::rtl::OUString & rsUIElementResourceURL,const::cssu::Sequence<css::beans::PropertyValue> & rArguments)132 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
133 const ::rtl::OUString& rsUIElementResourceURL,
134 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
135 throw(
136 css::container::NoSuchElementException,
137 css::lang::IllegalArgumentException,
138 cssu::RuntimeException)
139 {
140 // Process arguments.
141 const ::comphelper::NamedValueCollection aArguments (rArguments);
142 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
143 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
144 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
145
146 // Throw exceptions when the arguments are not as expected.
147 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
148 if ( ! xParentWindow.is() || pParentWindow==NULL)
149 throw RuntimeException(
150 A2S("PanelFactory::createUIElement called without ParentWindow"),
151 NULL);
152 if ( ! xFrame.is())
153 throw RuntimeException(
154 A2S("PanelFactory::createUIElement called without XFrame"),
155 NULL);
156
157 // Tunnel through the controller to obtain a ViewShellBase.
158 ViewShellBase* pBase = NULL;
159 Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
160 if (xTunnel.is())
161 {
162 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
163 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
164 if (pController != NULL)
165 pBase = pController->GetViewShellBase();
166 }
167 if (pBase == NULL)
168 throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL);
169
170 // Get bindings from given arguments.
171 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
172 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
173
174 // Create a framework view.
175 ::Window* pControl = NULL;
176 css::ui::LayoutSize aLayoutSize (-1,-1,-1);
177
178 #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t))
179 if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations))
180 pControl = new CustomAnimationPanel(pParentWindow, *pBase);
181 else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts))
182 pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar);
183 else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages))
184 pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
185 else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages))
186 pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
187 else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages))
188 pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
189 else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions))
190 pControl = new SlideTransitionPanel(pParentWindow, *pBase);
191 else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign))
192 pControl = createTableDesignPanel(pParentWindow, *pBase);
193 else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator))
194 pControl = new NavigatorWrapper(pParentWindow, *pBase, pBindings);
195 #undef EndsWith
196
197 if (pControl == NULL)
198 throw lang::IllegalArgumentException();
199
200 // Create a wrapper around the control that implements the
201 // necessary UNO interfaces.
202 return sfx2::sidebar::SidebarPanelBase::Create(
203 rsUIElementResourceURL,
204 xFrame,
205 pControl,
206 aLayoutSize);
207 }
208
209
210
211
212 } } // end of namespace sd::sidebar
213