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