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 "area/AreaPropertyPanel.hxx" 26 #include "graphic/GraphicPropertyPanel.hxx" 27 #include "line/LinePropertyPanel.hxx" 28 #include "possize/PosSizePropertyPanel.hxx" 29 #include "gallery/GalleryControl.hxx" 30 #include "ColorPanel.hxx" 31 #include <sfx2/sidebar/SidebarPanelBase.hxx> 32 #include <sfx2/sfxbasecontroller.hxx> 33 #include <toolkit/helper/vclunohelper.hxx> 34 #include <vcl/window.hxx> 35 #include <rtl/ref.hxx> 36 #include <comphelper/namedvaluecollection.hxx> 37 38 39 #include <boost/bind.hpp> 40 41 42 using namespace css; 43 using namespace cssu; 44 using ::rtl::OUString; 45 46 47 namespace svx { namespace sidebar { 48 49 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 50 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory" 51 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory" 52 53 54 ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void) 55 { 56 return A2S(IMPLEMENTATION_NAME); 57 } 58 59 60 61 62 cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance ( 63 const uno::Reference<lang::XMultiServiceFactory>& rxFactory) 64 { 65 (void)rxFactory; 66 67 ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory()); 68 cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY); 69 return xService; 70 } 71 72 73 74 75 cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void) 76 { 77 cssu::Sequence<OUString> aServiceNames (1); 78 aServiceNames[0] = A2S(SERVICE_NAME); 79 return aServiceNames; 80 81 } 82 83 84 85 86 PanelFactory::PanelFactory (void) 87 : PanelFactoryInterfaceBase(m_aMutex) 88 { 89 } 90 91 92 93 94 PanelFactory::~PanelFactory (void) 95 { 96 } 97 98 99 100 101 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( 102 const ::rtl::OUString& rsResourceURL, 103 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) 104 throw( 105 container::NoSuchElementException, 106 lang::IllegalArgumentException, 107 RuntimeException) 108 { 109 Reference<ui::XUIElement> xElement; 110 111 const ::comphelper::NamedValueCollection aArguments (rArguments); 112 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); 113 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); 114 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); 115 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); 116 117 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 118 if ( ! xParentWindow.is() || pParentWindow==NULL) 119 throw RuntimeException( 120 A2S("PanelFactory::createUIElement called without ParentWindow"), 121 NULL); 122 if ( ! xFrame.is()) 123 throw RuntimeException( 124 A2S("PanelFactory::createUIElement called without Frame"), 125 NULL); 126 if (pBindings == NULL) 127 throw RuntimeException( 128 A2S("PanelFactory::createUIElement called without SfxBindings"), 129 NULL); 130 131 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s)) 132 if (DoesResourceEndWith("/TextPropertyPanel")) 133 { 134 TextPropertyPanel* pPanel = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings); 135 xElement = sfx2::sidebar::SidebarPanelBase::Create( 136 rsResourceURL, 137 xFrame, 138 pPanel, 139 ::boost::bind(&TextPropertyPanel::ShowMenu, pPanel), 140 ui::LayoutSize(-1,-1,-1)); 141 } 142 else if (DoesResourceEndWith("/AreaPropertyPanel")) 143 { 144 AreaPropertyPanel* pPanel = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings); 145 xElement = sfx2::sidebar::SidebarPanelBase::Create( 146 rsResourceURL, 147 xFrame, 148 pPanel, 149 ::boost::bind(&AreaPropertyPanel::ShowMenu, pPanel), 150 ui::LayoutSize(-1,-1,-1)); 151 } 152 else if (DoesResourceEndWith("/GraphicPropertyPanel")) 153 { 154 GraphicPropertyPanel* pPanel = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings); 155 xElement = sfx2::sidebar::SidebarPanelBase::Create( 156 rsResourceURL, 157 xFrame, 158 pPanel, 159 ::boost::function<void(void)>(), 160 ui::LayoutSize(-1,-1,-1)); 161 } 162 else if (DoesResourceEndWith("/LinePropertyPanel")) 163 { 164 LinePropertyPanel* pPanel = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings); 165 xElement = sfx2::sidebar::SidebarPanelBase::Create( 166 rsResourceURL, 167 xFrame, 168 pPanel, 169 ::boost::bind(&LinePropertyPanel::ShowMenu, pPanel), 170 ui::LayoutSize(-1,-1,-1)); 171 } 172 else if (DoesResourceEndWith("/PosSizePropertyPanel")) 173 { 174 PosSizePropertyPanel* pPanel = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings); 175 xElement = sfx2::sidebar::SidebarPanelBase::Create( 176 rsResourceURL, 177 xFrame, 178 pPanel, 179 ::boost::bind(&PosSizePropertyPanel::ShowMenu, pPanel), 180 ui::LayoutSize(-1,-1,-1)); 181 } 182 else if (DoesResourceEndWith("/GalleryPanel")) 183 { 184 GalleryControl* pGalleryControl = new GalleryControl( 185 pBindings, 186 pParentWindow); 187 xElement = sfx2::sidebar::SidebarPanelBase::Create( 188 rsResourceURL, 189 xFrame, 190 pGalleryControl, 191 ::boost::function<void(void)>(), 192 ui::LayoutSize(300,-1,400)); 193 } 194 else if (DoesResourceEndWith("/Debug_ColorPanel")) 195 { 196 ColorPanel* pColorPanel = new ColorPanel( 197 pParentWindow); 198 xElement = sfx2::sidebar::SidebarPanelBase::Create( 199 rsResourceURL, 200 xFrame, 201 pColorPanel, 202 ::boost::function<void(void)>(), 203 ui::LayoutSize(300,-1,400)); 204 } 205 #undef DoesResourceEndWith 206 207 return xElement; 208 } 209 210 } } // end of namespace svx::sidebar 211 212 // eof 213