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 "sidebar/PanelFactory.hxx" 23 24 #include <text/TextPropertyPanel.hxx> 25 #include <geometry/AreaPropertyPanel.hxx> 26 #include <geometry/LinePropertyPanel.hxx> 27 #include <geometry/TransformationPropertyPanel.hxx> 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 svx { namespace sidebar { 44 45 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 46 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory" 47 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory" 48 49 50 ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void) 51 { 52 return A2S(IMPLEMENTATION_NAME); 53 } 54 55 56 57 58 cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance ( 59 const uno::Reference<lang::XMultiServiceFactory>& rxFactory) 60 { 61 (void)rxFactory; 62 63 ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory()); 64 cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY); 65 return xService; 66 } 67 68 69 70 71 cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void) 72 { 73 cssu::Sequence<OUString> aServiceNames (1); 74 aServiceNames[0] = A2S(SERVICE_NAME); 75 return aServiceNames; 76 77 } 78 79 80 81 82 PanelFactory::PanelFactory (void) 83 : PanelFactoryInterfaceBase(m_aMutex) 84 { 85 } 86 87 88 89 90 PanelFactory::~PanelFactory (void) 91 { 92 } 93 94 95 96 97 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( 98 const ::rtl::OUString& rsResourceURL, 99 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) 100 throw( 101 container::NoSuchElementException, 102 lang::IllegalArgumentException, 103 RuntimeException) 104 { 105 Reference<ui::XUIElement> xElement; 106 107 const ::comphelper::NamedValueCollection aArguments (rArguments); 108 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); 109 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); 110 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); 111 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); 112 113 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 114 if ( ! xParentWindow.is() || pParentWindow==NULL) 115 throw RuntimeException( 116 A2S("PanelFactory::createUIElement called without ParentWindow"), 117 NULL); 118 if ( ! xFrame.is()) 119 throw RuntimeException( 120 A2S("PanelFactory::createUIElement called without Frame"), 121 NULL); 122 if (pBindings == NULL) 123 throw RuntimeException( 124 A2S("PanelFactory::createUIElement called without SfxBindings"), 125 NULL); 126 127 if (rsResourceURL.endsWithAsciiL("/TextPropertyPanel", strlen("/TextPropertyPanel"))) 128 { 129 TextPropertyPanel* pPanel = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings); 130 xElement = sfx2::sidebar::SidebarPanelBase::Create( 131 rsResourceURL, 132 xFrame, 133 pPanel, 134 ::boost::bind(&TextPropertyPanel::ShowMenu, pPanel)); 135 } 136 else if (rsResourceURL.endsWithAsciiL("/AreaPropertyPanel", strlen("/AreaPropertyPanel"))) 137 { 138 AreaPropertyPanel* pPanel = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings); 139 xElement = sfx2::sidebar::SidebarPanelBase::Create( 140 rsResourceURL, 141 xFrame, 142 pPanel, 143 ::boost::function<void(void)>()); 144 } 145 else if (rsResourceURL.endsWithAsciiL("/LinePropertyPanel", strlen("/LinePropertyPanel"))) 146 { 147 LinePropertyPanel* pPanel = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings); 148 xElement = sfx2::sidebar::SidebarPanelBase::Create( 149 rsResourceURL, 150 xFrame, 151 pPanel, 152 ::boost::function<void(void)>()); 153 } 154 else if (rsResourceURL.endsWithAsciiL("/TransformationPropertyPanel", strlen("/TransformationPropertyPanel"))) 155 { 156 LinePropertyPanel* pPanel = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings); 157 xElement = sfx2::sidebar::SidebarPanelBase::Create( 158 rsResourceURL, 159 xFrame, 160 pPanel, 161 ::boost::function<void(void)>()); 162 } 163 164 return xElement; 165 } 166 167 } } // end of namespace svx::sidebar 168 169 // eof 170