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