162024513SAndre Fischer /************************************************************** 262024513SAndre Fischer * 362024513SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 462024513SAndre Fischer * or more contributor license agreements. See the NOTICE file 562024513SAndre Fischer * distributed with this work for additional information 662024513SAndre Fischer * regarding copyright ownership. The ASF licenses this file 762024513SAndre Fischer * to you under the Apache License, Version 2.0 (the 862024513SAndre Fischer * "License"); you may not use this file except in compliance 962024513SAndre Fischer * with the License. You may obtain a copy of the License at 1062024513SAndre Fischer * 1162024513SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 1262024513SAndre Fischer * 1362024513SAndre Fischer * Unless required by applicable law or agreed to in writing, 1462024513SAndre Fischer * software distributed under the License is distributed on an 1562024513SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1662024513SAndre Fischer * KIND, either express or implied. See the License for the 1762024513SAndre Fischer * specific language governing permissions and limitations 1862024513SAndre Fischer * under the License. 1962024513SAndre Fischer * 2062024513SAndre Fischer *************************************************************/ 2162024513SAndre Fischer 2262024513SAndre Fischer #include "precompiled_sd.hxx" 2362024513SAndre Fischer 2462024513SAndre Fischer #include "PanelFactory.hxx" 2562024513SAndre Fischer #include "framework/Pane.hxx" 2662024513SAndre Fischer #include "ViewShellBase.hxx" 2762024513SAndre Fischer #include "DrawController.hxx" 2862024513SAndre Fischer #include "LayoutMenu.hxx" 2962024513SAndre Fischer #include "CurrentMasterPagesSelector.hxx" 3062024513SAndre Fischer #include "RecentMasterPagesSelector.hxx" 3162024513SAndre Fischer #include "AllMasterPagesSelector.hxx" 3262024513SAndre Fischer #include "CustomAnimationPanel.hxx" 3362024513SAndre Fischer #include "TableDesignPanel.hxx" 3462024513SAndre Fischer #include "SlideTransitionPanel.hxx" 3562024513SAndre Fischer #include "NavigatorWrapper.hxx" 3662024513SAndre Fischer 3762024513SAndre Fischer #include <sfx2/viewfrm.hxx> 3862024513SAndre Fischer #include <sfx2/sidebar/SidebarPanelBase.hxx> 3962024513SAndre Fischer #include <comphelper/namedvaluecollection.hxx> 4062024513SAndre Fischer #include <vcl/window.hxx> 4162024513SAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 4262024513SAndre Fischer 4362024513SAndre Fischer using namespace css; 4462024513SAndre Fischer using namespace cssu; 4562024513SAndre Fischer using namespace ::sd::framework; 4662024513SAndre Fischer using ::rtl::OUString; 4762024513SAndre Fischer 4862024513SAndre Fischer #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 4962024513SAndre Fischer 5062024513SAndre Fischer namespace sd { namespace sidebar { 5162024513SAndre Fischer 5262024513SAndre Fischer namespace { 5362024513SAndre Fischer /** Note that these names have to be identical to (the tail of) 5462024513SAndre Fischer the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu 5562024513SAndre Fischer for the TaskPanelFactory. 5662024513SAndre Fischer */ 5762024513SAndre Fischer const static char* gsResourceNameCustomAnimations = "/CustomAnimations"; 5862024513SAndre Fischer const static char* gsResourceNameLayouts = "/Layouts"; 5962024513SAndre Fischer const static char* gsResourceNameAllMasterPages = "/AllMasterPages"; 6062024513SAndre Fischer const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages"; 6162024513SAndre Fischer const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages"; 6262024513SAndre Fischer const static char* gsResourceNameSlideTransitions = "/SlideTransitions"; 6362024513SAndre Fischer const static char* gsResourceNameTableDesign = "/TableDesign"; 64*3c226292SAndre Fischer const static char* gsResourceNameNavigator = "/NavigatorPanel"; 6562024513SAndre Fischer } 6662024513SAndre Fischer 6762024513SAndre Fischer Reference<lang::XEventListener> mxControllerDisposeListener; 6862024513SAndre Fischer 6962024513SAndre Fischer 7062024513SAndre Fischer 7162024513SAndre Fischer // ----- Service functions ---------------------------------------------------- 7262024513SAndre Fischer 7362024513SAndre Fischer Reference<XInterface> SAL_CALL PanelFactory_createInstance ( 7462024513SAndre Fischer const Reference<XComponentContext>& rxContext) 7562024513SAndre Fischer { 7662024513SAndre Fischer return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext))); 7762024513SAndre Fischer } 7862024513SAndre Fischer 7962024513SAndre Fischer 8062024513SAndre Fischer 8162024513SAndre Fischer 8262024513SAndre Fischer ::rtl::OUString PanelFactory_getImplementationName (void) throw(RuntimeException) 8362024513SAndre Fischer { 8462024513SAndre Fischer return ::rtl::OUString( 8562024513SAndre Fischer RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.PanelFactory")); 8662024513SAndre Fischer } 8762024513SAndre Fischer 8862024513SAndre Fischer 8962024513SAndre Fischer 9062024513SAndre Fischer 9162024513SAndre Fischer Sequence<rtl::OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void) 9262024513SAndre Fischer throw (RuntimeException) 9362024513SAndre Fischer { 9462024513SAndre Fischer static const ::rtl::OUString sServiceName( 9562024513SAndre Fischer ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.PanelFactory")); 9662024513SAndre Fischer return Sequence<rtl::OUString>(&sServiceName, 1); 9762024513SAndre Fischer } 9862024513SAndre Fischer 9962024513SAndre Fischer 10062024513SAndre Fischer 10162024513SAndre Fischer 10262024513SAndre Fischer //----- PanelFactory -------------------------------------------------------- 10362024513SAndre Fischer 10462024513SAndre Fischer PanelFactory::PanelFactory( 10562024513SAndre Fischer const css::uno::Reference<css::uno::XComponentContext>& rxContext) 10662024513SAndre Fischer : PanelFactoryInterfaceBase(m_aMutex) 10762024513SAndre Fischer { 10862024513SAndre Fischer } 10962024513SAndre Fischer 11062024513SAndre Fischer 11162024513SAndre Fischer 11262024513SAndre Fischer 11362024513SAndre Fischer PanelFactory::~PanelFactory (void) 11462024513SAndre Fischer { 11562024513SAndre Fischer } 11662024513SAndre Fischer 11762024513SAndre Fischer 11862024513SAndre Fischer 11962024513SAndre Fischer 12062024513SAndre Fischer void SAL_CALL PanelFactory::disposing (void) 12162024513SAndre Fischer { 12262024513SAndre Fischer } 12362024513SAndre Fischer 12462024513SAndre Fischer 12562024513SAndre Fischer 12662024513SAndre Fischer 12762024513SAndre Fischer // XUIElementFactory 12862024513SAndre Fischer 12962024513SAndre Fischer Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( 13062024513SAndre Fischer const ::rtl::OUString& rsUIElementResourceURL, 13162024513SAndre Fischer const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) 13262024513SAndre Fischer throw( 13362024513SAndre Fischer css::container::NoSuchElementException, 13462024513SAndre Fischer css::lang::IllegalArgumentException, 13562024513SAndre Fischer cssu::RuntimeException) 13662024513SAndre Fischer { 13762024513SAndre Fischer // Process arguments. 13862024513SAndre Fischer const ::comphelper::NamedValueCollection aArguments (rArguments); 13962024513SAndre Fischer Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); 14062024513SAndre Fischer Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); 14162024513SAndre Fischer Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>())); 14262024513SAndre Fischer 14362024513SAndre Fischer // Throw exceptions when the arguments are not as expected. 14462024513SAndre Fischer ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 14562024513SAndre Fischer if ( ! xParentWindow.is() || pParentWindow==NULL) 14662024513SAndre Fischer throw RuntimeException( 14762024513SAndre Fischer A2S("PanelFactory::createUIElement called without ParentWindow"), 14862024513SAndre Fischer NULL); 14962024513SAndre Fischer if ( ! xFrame.is()) 15062024513SAndre Fischer throw RuntimeException( 15162024513SAndre Fischer A2S("PanelFactory::createUIElement called without XFrame"), 15262024513SAndre Fischer NULL); 15362024513SAndre Fischer 15462024513SAndre Fischer // Tunnel through the controller to obtain a ViewShellBase. 15562024513SAndre Fischer ViewShellBase* pBase = NULL; 15662024513SAndre Fischer Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY); 15762024513SAndre Fischer if (xTunnel.is()) 15862024513SAndre Fischer { 15962024513SAndre Fischer ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 16062024513SAndre Fischer xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 16162024513SAndre Fischer if (pController != NULL) 16262024513SAndre Fischer pBase = pController->GetViewShellBase(); 16362024513SAndre Fischer } 16462024513SAndre Fischer if (pBase == NULL) 16562024513SAndre Fischer throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL); 16662024513SAndre Fischer 16762024513SAndre Fischer // Get bindings from given arguments. 16862024513SAndre Fischer const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); 16962024513SAndre Fischer SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); 17062024513SAndre Fischer 17162024513SAndre Fischer // Create a framework view. 17262024513SAndre Fischer ::Window* pControl = NULL; 17362024513SAndre Fischer 17462024513SAndre Fischer #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t)) 17562024513SAndre Fischer if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations)) 17662024513SAndre Fischer pControl = new CustomAnimationPanel(pParentWindow, *pBase); 17762024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts)) 17862024513SAndre Fischer pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar); 17962024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages)) 18062024513SAndre Fischer pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 18162024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages)) 18262024513SAndre Fischer pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 18362024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages)) 18462024513SAndre Fischer pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 18562024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions)) 18662024513SAndre Fischer pControl = new SlideTransitionPanel(pParentWindow, *pBase); 18762024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign)) 18862024513SAndre Fischer pControl = new TableDesignPanel(pParentWindow, *pBase); 18962024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator)) 19062024513SAndre Fischer pControl = new NavigatorWrapper(pParentWindow, *pBase, pBindings); 19162024513SAndre Fischer #undef EndsWith 19262024513SAndre Fischer 19362024513SAndre Fischer if (pControl == NULL) 19462024513SAndre Fischer throw lang::IllegalArgumentException(); 19562024513SAndre Fischer 19662024513SAndre Fischer // Create a wrapper around the control that implements the 19762024513SAndre Fischer // necessary UNO interfaces. 19862024513SAndre Fischer return sfx2::sidebar::SidebarPanelBase::Create( 19962024513SAndre Fischer rsUIElementResourceURL, 20062024513SAndre Fischer xFrame, 20162024513SAndre Fischer pControl, 20262024513SAndre Fischer ui::LayoutSize(-1,-1,-1)); 20362024513SAndre Fischer } 20462024513SAndre Fischer 20562024513SAndre Fischer 20662024513SAndre Fischer 20762024513SAndre Fischer 20862024513SAndre Fischer } } // end of namespace sd::sidebar 209