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