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_sw.hxx" 23 24 #include "SwPanelFactory.hxx" 25 26 #include <PagePropertyPanel.hxx> 27 28 #include <sfx2/sidebar/SidebarPanelBase.hxx> 29 #include <sfx2/sfxbasecontroller.hxx> 30 #include <toolkit/helper/vclunohelper.hxx> 31 #include <vcl/window.hxx> 32 #include <rtl/ref.hxx> 33 #include <comphelper/namedvaluecollection.hxx> 34 35 #include <boost/bind.hpp> 36 37 38 using namespace css; 39 using namespace cssu; 40 using ::rtl::OUString; 41 42 43 namespace sw { namespace sidebar { 44 45 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 46 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.sw.sidebar.SwPanelFactory" 47 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory" 48 49 50 ::rtl::OUString SAL_CALL SwPanelFactory::getImplementationName (void) 51 { 52 return A2S(IMPLEMENTATION_NAME); 53 } 54 55 56 cssu::Reference<cssu::XInterface> SAL_CALL SwPanelFactory::createInstance( 57 const uno::Reference<lang::XMultiServiceFactory>& ) 58 { 59 ::rtl::Reference<SwPanelFactory> pPanelFactory (new SwPanelFactory()); 60 cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY); 61 return xService; 62 } 63 64 65 cssu::Sequence<OUString> SAL_CALL SwPanelFactory::getSupportedServiceNames (void) 66 { 67 cssu::Sequence<OUString> aServiceNames (1); 68 aServiceNames[0] = A2S(SERVICE_NAME); 69 return aServiceNames; 70 71 } 72 73 74 SwPanelFactory::SwPanelFactory (void) 75 : PanelFactoryInterfaceBase(m_aMutex) 76 { 77 } 78 79 80 SwPanelFactory::~SwPanelFactory (void) 81 { 82 } 83 84 85 Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement ( 86 const ::rtl::OUString& rsResourceURL, 87 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) 88 throw( 89 container::NoSuchElementException, 90 lang::IllegalArgumentException, 91 RuntimeException) 92 { 93 Reference<ui::XUIElement> xElement; 94 95 const ::comphelper::NamedValueCollection aArguments (rArguments); 96 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); 97 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); 98 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); 99 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); 100 101 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 102 if ( ! xParentWindow.is() || pParentWindow==NULL) 103 throw RuntimeException( 104 A2S("PanelFactory::createUIElement called without ParentWindow"), 105 NULL); 106 if ( ! xFrame.is()) 107 throw RuntimeException( 108 A2S("PanelFactory::createUIElement called without Frame"), 109 NULL); 110 if (pBindings == NULL) 111 throw RuntimeException( 112 A2S("PanelFactory::createUIElement called without SfxBindings"), 113 NULL); 114 115 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s)) 116 if (DoesResourceEndWith("/PagePropertyPanel")) 117 { 118 PagePropertyPanel* pPanel = PagePropertyPanel::Create( pParentWindow, pBindings ); 119 xElement = sfx2::sidebar::SidebarPanelBase::Create( 120 rsResourceURL, 121 xFrame, 122 pPanel, 123 ui::LayoutSize(-1,-1,-1)); 124 } 125 #undef DoesResourceEndWith 126 127 return xElement; 128 } 129 130 } } // end of namespace sw::sidebar 131 132 // eof 133