17a32b0c8SAndre Fischer /**************************************************************
27a32b0c8SAndre Fischer  *
37a32b0c8SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
47a32b0c8SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
57a32b0c8SAndre Fischer  * distributed with this work for additional information
67a32b0c8SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
77a32b0c8SAndre Fischer  * to you under the Apache License, Version 2.0 (the
87a32b0c8SAndre Fischer  * "License"); you may not use this file except in compliance
97a32b0c8SAndre Fischer  * with the License.  You may obtain a copy of the License at
107a32b0c8SAndre Fischer  *
117a32b0c8SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
127a32b0c8SAndre Fischer  *
137a32b0c8SAndre Fischer  * Unless required by applicable law or agreed to in writing,
147a32b0c8SAndre Fischer  * software distributed under the License is distributed on an
157a32b0c8SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
167a32b0c8SAndre Fischer  * KIND, either express or implied.  See the License for the
177a32b0c8SAndre Fischer  * specific language governing permissions and limitations
187a32b0c8SAndre Fischer  * under the License.
197a32b0c8SAndre Fischer  *
207a32b0c8SAndre Fischer  *************************************************************/
217a32b0c8SAndre Fischer 
227a32b0c8SAndre Fischer #include "precompiled_sd.hxx"
237a32b0c8SAndre Fischer 
247a32b0c8SAndre Fischer #include "SidebarFactory.hxx"
257a32b0c8SAndre Fischer #include "framework/Pane.hxx"
267a32b0c8SAndre Fischer #include "ViewShellBase.hxx"
27*02c50d82SAndre Fischer #include "DrawController.hxx"
28*02c50d82SAndre Fischer #include "LayoutMenu.hxx"
29*02c50d82SAndre Fischer #include "CurrentMasterPagesSelector.hxx"
30*02c50d82SAndre Fischer #include "RecentMasterPagesSelector.hxx"
31*02c50d82SAndre Fischer #include "AllMasterPagesSelector.hxx"
32*02c50d82SAndre Fischer #include "CustomAnimationPanel.hxx"
33*02c50d82SAndre Fischer #include "TableDesignPanel.hxx"
34*02c50d82SAndre Fischer #include "SlideTransitionPanel.hxx"
357a32b0c8SAndre Fischer 
367a32b0c8SAndre Fischer #include <sfx2/viewfrm.hxx>
37*02c50d82SAndre Fischer #include <sfx2/sidebar/SidebarPanelBase.hxx>
387a32b0c8SAndre Fischer #include <comphelper/namedvaluecollection.hxx>
397a32b0c8SAndre Fischer #include <vcl/window.hxx>
407a32b0c8SAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
417a32b0c8SAndre Fischer 
427a32b0c8SAndre Fischer using namespace css;
437a32b0c8SAndre Fischer using namespace cssu;
447a32b0c8SAndre Fischer using namespace ::sd::framework;
457a32b0c8SAndre Fischer using ::rtl::OUString;
467a32b0c8SAndre Fischer 
477a32b0c8SAndre Fischer #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
487a32b0c8SAndre Fischer 
497a32b0c8SAndre Fischer namespace sd { namespace sidebar {
507a32b0c8SAndre Fischer 
517a32b0c8SAndre Fischer namespace {
527a32b0c8SAndre Fischer     /** Note that these names have to be identical to (the tail of)
537a32b0c8SAndre Fischer         the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
547a32b0c8SAndre Fischer         for the TaskPanelFactory.
557a32b0c8SAndre Fischer     */
567a32b0c8SAndre Fischer     const static char* gsResourceNameCustomAnimations = "/CustomAnimations";
577a32b0c8SAndre Fischer     const static char* gsResourceNameLayouts = "/Layouts";
587a32b0c8SAndre Fischer     const static char* gsResourceNameAllMasterPages = "/AllMasterPages";
597a32b0c8SAndre Fischer     const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages";
607a32b0c8SAndre Fischer     const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages";
617a32b0c8SAndre Fischer     const static char* gsResourceNameSlideTransitions = "/SlideTransitions";
627a32b0c8SAndre Fischer     const static char* gsResourceNameTableDesign = "/TableDesign";
637a32b0c8SAndre Fischer }
647a32b0c8SAndre Fischer 
657a32b0c8SAndre Fischer Reference<lang::XEventListener> mxControllerDisposeListener;
667a32b0c8SAndre Fischer 
677a32b0c8SAndre Fischer 
687a32b0c8SAndre Fischer 
697a32b0c8SAndre Fischer // ----- Service functions ----------------------------------------------------
707a32b0c8SAndre Fischer 
SidebarFactory_createInstance(const Reference<XComponentContext> & rxContext)717a32b0c8SAndre Fischer Reference<XInterface> SAL_CALL SidebarFactory_createInstance (
727a32b0c8SAndre Fischer     const Reference<XComponentContext>& rxContext)
737a32b0c8SAndre Fischer {
747a32b0c8SAndre Fischer     return Reference<XInterface>(static_cast<XWeak*>(new SidebarFactory(rxContext)));
757a32b0c8SAndre Fischer }
767a32b0c8SAndre Fischer 
777a32b0c8SAndre Fischer 
787a32b0c8SAndre Fischer 
797a32b0c8SAndre Fischer 
SidebarFactory_getImplementationName(void)807a32b0c8SAndre Fischer ::rtl::OUString SidebarFactory_getImplementationName (void) throw(RuntimeException)
817a32b0c8SAndre Fischer {
827a32b0c8SAndre Fischer     return ::rtl::OUString(
837a32b0c8SAndre Fischer         RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.SidebarFactory"));
847a32b0c8SAndre Fischer }
857a32b0c8SAndre Fischer 
867a32b0c8SAndre Fischer 
877a32b0c8SAndre Fischer 
887a32b0c8SAndre Fischer 
SidebarFactory_getSupportedServiceNames(void)897a32b0c8SAndre Fischer Sequence<rtl::OUString> SAL_CALL SidebarFactory_getSupportedServiceNames (void)
907a32b0c8SAndre Fischer     throw (RuntimeException)
917a32b0c8SAndre Fischer {
927a32b0c8SAndre Fischer 	static const ::rtl::OUString sServiceName(
937a32b0c8SAndre Fischer         ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.SidebarFactory"));
947a32b0c8SAndre Fischer 	return Sequence<rtl::OUString>(&sServiceName, 1);
957a32b0c8SAndre Fischer }
967a32b0c8SAndre Fischer 
977a32b0c8SAndre Fischer 
987a32b0c8SAndre Fischer 
997a32b0c8SAndre Fischer 
1007a32b0c8SAndre Fischer //----- SidebarFactory --------------------------------------------------------
1017a32b0c8SAndre Fischer 
SidebarFactory(const css::uno::Reference<css::uno::XComponentContext> & rxContext)1027a32b0c8SAndre Fischer SidebarFactory::SidebarFactory(
1037a32b0c8SAndre Fischer         const css::uno::Reference<css::uno::XComponentContext>& rxContext)
104*02c50d82SAndre Fischer     : SidebarFactoryInterfaceBase(m_aMutex)
1057a32b0c8SAndre Fischer {
1067a32b0c8SAndre Fischer }
1077a32b0c8SAndre Fischer 
1087a32b0c8SAndre Fischer 
1097a32b0c8SAndre Fischer 
1107a32b0c8SAndre Fischer 
~SidebarFactory(void)1117a32b0c8SAndre Fischer SidebarFactory::~SidebarFactory (void)
1127a32b0c8SAndre Fischer {
1137a32b0c8SAndre Fischer }
1147a32b0c8SAndre Fischer 
1157a32b0c8SAndre Fischer 
1167a32b0c8SAndre Fischer 
1177a32b0c8SAndre Fischer 
disposing(void)1187a32b0c8SAndre Fischer void SAL_CALL SidebarFactory::disposing (void)
1197a32b0c8SAndre Fischer {
1207a32b0c8SAndre Fischer }
1217a32b0c8SAndre Fischer 
1227a32b0c8SAndre Fischer 
1237a32b0c8SAndre Fischer 
1247a32b0c8SAndre Fischer 
1257a32b0c8SAndre Fischer // XInitialization
1267a32b0c8SAndre Fischer 
initialize(const Sequence<Any> & aArguments)1277a32b0c8SAndre Fischer void SAL_CALL SidebarFactory::initialize (const Sequence<Any>& aArguments)
1287a32b0c8SAndre Fischer     throw (Exception, RuntimeException)
1297a32b0c8SAndre Fischer {
1307a32b0c8SAndre Fischer }
1317a32b0c8SAndre Fischer 
1327a32b0c8SAndre Fischer 
1337a32b0c8SAndre Fischer 
1347a32b0c8SAndre Fischer 
1357a32b0c8SAndre Fischer // XUIElementFactory
1367a32b0c8SAndre Fischer 
createUIElement(const::rtl::OUString & rsUIElementResourceURL,const::cssu::Sequence<css::beans::PropertyValue> & rArguments)1377a32b0c8SAndre Fischer Reference<ui::XUIElement> SAL_CALL SidebarFactory::createUIElement (
1387a32b0c8SAndre Fischer     const ::rtl::OUString& rsUIElementResourceURL,
1397a32b0c8SAndre Fischer     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
1407a32b0c8SAndre Fischer     throw(
1417a32b0c8SAndre Fischer         css::container::NoSuchElementException,
1427a32b0c8SAndre Fischer         css::lang::IllegalArgumentException,
1437a32b0c8SAndre Fischer         cssu::RuntimeException)
1447a32b0c8SAndre Fischer {
1457a32b0c8SAndre Fischer     // Process arguments.
1467a32b0c8SAndre Fischer     const ::comphelper::NamedValueCollection aArguments (rArguments);
1477a32b0c8SAndre Fischer     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
1487a32b0c8SAndre Fischer     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
1497a32b0c8SAndre Fischer     Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
1507a32b0c8SAndre Fischer 
1517a32b0c8SAndre Fischer     // Throw exceptions when the arguments are not as expected.
1527a32b0c8SAndre Fischer     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
1537a32b0c8SAndre Fischer     if ( ! xParentWindow.is() || pParentWindow==NULL)
1547a32b0c8SAndre Fischer         throw RuntimeException(
1557a32b0c8SAndre Fischer             A2S("SidebarFactory::createUIElement called without ParentWindow"),
1567a32b0c8SAndre Fischer             NULL);
1577a32b0c8SAndre Fischer     if ( ! xFrame.is())
1587a32b0c8SAndre Fischer         throw RuntimeException(
1597a32b0c8SAndre Fischer             A2S("SidebarFactory::createUIElement called without XFrame"),
1607a32b0c8SAndre Fischer             NULL);
1617a32b0c8SAndre Fischer 
162*02c50d82SAndre Fischer     // Tunnel through the controller to obtain a ViewShellBase.
163*02c50d82SAndre Fischer     ViewShellBase* pBase = NULL;
164*02c50d82SAndre Fischer     Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
165*02c50d82SAndre Fischer     if (xTunnel.is())
166*02c50d82SAndre Fischer     {
167*02c50d82SAndre Fischer         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
168*02c50d82SAndre Fischer             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
169*02c50d82SAndre Fischer         if (pController != NULL)
170*02c50d82SAndre Fischer             pBase = pController->GetViewShellBase();
171*02c50d82SAndre Fischer     }
172*02c50d82SAndre Fischer     if (pBase == NULL)
173*02c50d82SAndre Fischer         throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL);
1747a32b0c8SAndre Fischer 
1757a32b0c8SAndre Fischer     // Create a framework view.
176*02c50d82SAndre Fischer     ::Window* pControl = NULL;
177*02c50d82SAndre Fischer 
1787a32b0c8SAndre Fischer #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t))
1797a32b0c8SAndre Fischer     if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations))
180*02c50d82SAndre Fischer         pControl = new CustomAnimationPanel(pParentWindow, *pBase);
1817a32b0c8SAndre Fischer     else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts))
182*02c50d82SAndre Fischer         pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar);
1837a32b0c8SAndre Fischer     else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages))
184*02c50d82SAndre Fischer         pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
1857a32b0c8SAndre Fischer     else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages))
186*02c50d82SAndre Fischer         pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
1877a32b0c8SAndre Fischer     else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages))
188*02c50d82SAndre Fischer         pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
1897a32b0c8SAndre Fischer     else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions))
190*02c50d82SAndre Fischer         pControl = new SlideTransitionPanel(pParentWindow, *pBase);
1917a32b0c8SAndre Fischer     else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign))
192*02c50d82SAndre Fischer         pControl = new TableDesignPanel(pParentWindow, *pBase);
1937a32b0c8SAndre Fischer #undef EndsWith
194*02c50d82SAndre Fischer 
195*02c50d82SAndre Fischer     if (pControl == NULL)
1967a32b0c8SAndre Fischer         throw lang::IllegalArgumentException();
1977a32b0c8SAndre Fischer 
1987a32b0c8SAndre Fischer     // Create a wrapper around pane and view and return it as
1997a32b0c8SAndre Fischer     // XUIElement.
2007a32b0c8SAndre Fischer     Reference<ui::XUIElement> xUIElement;
2017a32b0c8SAndre Fischer     try
2027a32b0c8SAndre Fischer     {
203*02c50d82SAndre Fischer         xUIElement.set(
204*02c50d82SAndre Fischer             sfx2::sidebar::SidebarPanelBase::Create(
2057a32b0c8SAndre Fischer                 rsUIElementResourceURL,
2067a32b0c8SAndre Fischer                 xFrame,
207*02c50d82SAndre Fischer                 pControl,
208*02c50d82SAndre Fischer                 ui::LayoutSize(-1,-1,-1)));
2097a32b0c8SAndre Fischer     }
2107a32b0c8SAndre Fischer     catch(Exception& rException)
2117a32b0c8SAndre Fischer     {
2127a32b0c8SAndre Fischer         // Creation of XUIElement failed. mxUIElement remains empty.
2137a32b0c8SAndre Fischer     }
2147a32b0c8SAndre Fischer 
2157a32b0c8SAndre Fischer     Reference<lang::XComponent> xComponent (xUIElement, UNO_QUERY);
2167a32b0c8SAndre Fischer     if (xComponent.is())
2177a32b0c8SAndre Fischer         xComponent->addEventListener(this);
2187a32b0c8SAndre Fischer 
2197a32b0c8SAndre Fischer     return xUIElement;
2207a32b0c8SAndre Fischer }
2217a32b0c8SAndre Fischer 
2227a32b0c8SAndre Fischer 
2237a32b0c8SAndre Fischer 
2247a32b0c8SAndre Fischer 
disposing(const::css::lang::EventObject & rEvent)2257a32b0c8SAndre Fischer void SAL_CALL SidebarFactory::disposing (const ::css::lang::EventObject& rEvent)
2267a32b0c8SAndre Fischer     throw(cssu::RuntimeException)
2277a32b0c8SAndre Fischer {
2287a32b0c8SAndre Fischer     /*
2297a32b0c8SAndre Fischer     if (mpImplementation
2307a32b0c8SAndre Fischer         && rEvent.Source == mpImplementation->mxUIElement)
2317a32b0c8SAndre Fischer     {
2327a32b0c8SAndre Fischer         mpImplementation->mxUIElement.clear();
2337a32b0c8SAndre Fischer     }
2347a32b0c8SAndre Fischer     */
2357a32b0c8SAndre Fischer }
2367a32b0c8SAndre Fischer 
2377a32b0c8SAndre Fischer 
2387a32b0c8SAndre Fischer 
2397a32b0c8SAndre Fischer 
2407a32b0c8SAndre Fischer } } // end of namespace sd::sidebar
241