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