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