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