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 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 #include <unotools/pathoptions.hxx> 27 #include <com/sun/star/lang/XServiceInfo.hpp> 28 #include <com/sun/star/container/XNameContainer.hpp> 29 #include <cppuhelper/implbase2.hxx> 30 31 #include "../customshapes/EnhancedCustomShapeEngine.hxx" 32 33 #include <svx/xtable.hxx> 34 #include "svx/unoshcol.hxx" 35 #include "recoveryui.hxx" 36 #include "svx/xmlgrhlp.hxx" 37 #include "tbunocontroller.hxx" 38 #include "tbunosearchcontrollers.hxx" 39 40 using namespace ::com::sun::star; 41 using namespace ::rtl; 42 using namespace ::cppu; 43 44 class SvxUnoColorTable : public WeakImplHelper2< container::XNameContainer, lang::XServiceInfo > 45 { 46 private: 47 XColorListSharedPtr maTable; 48 49 public: 50 SvxUnoColorTable() throw(); 51 virtual ~SvxUnoColorTable() throw(); 52 53 // XServiceInfo 54 virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException ); 55 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( uno::RuntimeException); 56 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException); 57 58 static OUString getImplementationName_Static() throw() 59 { 60 return OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.SvxUnoColorTable")); 61 } 62 63 static uno::Sequence< OUString > getSupportedServiceNames_Static(void) throw(); 64 65 // XNameContainer 66 virtual void SAL_CALL insertByName( const OUString& aName, const uno::Any& aElement ) throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException); 67 virtual void SAL_CALL removeByName( const OUString& Name ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); 68 69 // XNameReplace 70 virtual void SAL_CALL replaceByName( const OUString& aName, const uno::Any& aElement ) throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); 71 72 // XNameAccess 73 virtual uno::Any SAL_CALL getByName( const OUString& aName ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); 74 75 virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) throw( uno::RuntimeException); 76 77 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw( uno::RuntimeException); 78 79 // XElementAccess 80 virtual uno::Type SAL_CALL getElementType( ) throw( uno::RuntimeException); 81 virtual sal_Bool SAL_CALL hasElements( ) throw( uno::RuntimeException); 82 }; 83 84 SvxUnoColorTable::SvxUnoColorTable() throw() 85 : maTable(XPropertyListFactory::CreateSharedXColorList(SvtPathOptions().GetPalettePath())) 86 { 87 } 88 89 SvxUnoColorTable::~SvxUnoColorTable() throw() 90 { 91 } 92 93 sal_Bool SAL_CALL SvxUnoColorTable::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException) 94 { 95 uno::Sequence< OUString > aSNL( getSupportedServiceNames() ); 96 const OUString * pArray = aSNL.getConstArray(); 97 98 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 99 if( pArray[i] == ServiceName ) 100 return sal_True; 101 102 return sal_False; 103 } 104 105 OUString SAL_CALL SvxUnoColorTable::getImplementationName() throw( uno::RuntimeException ) 106 { 107 return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoColorTable") ); 108 } 109 110 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getSupportedServiceNames( ) 111 throw( uno::RuntimeException ) 112 { 113 return getSupportedServiceNames_Static(); 114 } 115 116 uno::Sequence< OUString > SvxUnoColorTable::getSupportedServiceNames_Static(void) throw() 117 { 118 uno::Sequence< OUString > aSNS( 1 ); 119 aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ColorTable" )); 120 return aSNS; 121 } 122 123 // XNameContainer 124 void SAL_CALL SvxUnoColorTable::insertByName( const OUString& aName, const uno::Any& aElement ) 125 throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException ) 126 { 127 if( hasByName( aName ) ) 128 throw container::ElementExistException(); 129 130 sal_Int32 nColor = 0; 131 if( !(aElement >>= nColor) ) 132 throw lang::IllegalArgumentException(); 133 134 XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName ); 135 maTable->Insert( pEntry, maTable->Count() ); 136 } 137 138 void SAL_CALL SvxUnoColorTable::removeByName( const OUString& Name ) 139 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 140 { 141 long nIndex = maTable->GetIndex(Name); 142 if( nIndex == -1 ) 143 throw container::NoSuchElementException(); 144 145 maTable->Remove( nIndex ); 146 } 147 148 // XNameReplace 149 void SAL_CALL SvxUnoColorTable::replaceByName( const OUString& aName, const uno::Any& aElement ) 150 throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 151 { 152 sal_Int32 nColor = 0; 153 if( !(aElement >>= nColor) ) 154 throw lang::IllegalArgumentException(); 155 156 long nIndex = maTable->GetIndex(aName); 157 if( nIndex == -1 ) 158 throw container::NoSuchElementException(); 159 160 XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName ); 161 delete maTable->Replace( pEntry, nIndex ); 162 } 163 164 // XNameAccess 165 uno::Any SAL_CALL SvxUnoColorTable::getByName( const OUString& aName ) 166 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 167 { 168 long nIndex = maTable->GetIndex(aName); 169 if( nIndex == -1 ) 170 throw container::NoSuchElementException(); 171 172 XColorEntry* pEntry = maTable->GetColor( nIndex ); 173 return uno::Any( (sal_Int32) pEntry->GetColor().GetRGBColor() ); 174 } 175 176 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getElementNames( ) 177 throw( uno::RuntimeException ) 178 { 179 const long nCount = maTable->Count(); 180 181 uno::Sequence< OUString > aSeq( nCount ); 182 OUString* pStrings = aSeq.getArray(); 183 184 for( long nIndex = 0; nIndex < nCount; nIndex++ ) 185 { 186 XColorEntry* pEntry = maTable->GetColor( (long)nIndex ); 187 pStrings[nIndex] = pEntry->GetName(); 188 } 189 190 return aSeq; 191 } 192 193 sal_Bool SAL_CALL SvxUnoColorTable::hasByName( const OUString& aName ) 194 throw( uno::RuntimeException ) 195 { 196 long nIndex = maTable->GetIndex( aName ); 197 return nIndex != -1; 198 } 199 200 // XElementAccess 201 uno::Type SAL_CALL SvxUnoColorTable::getElementType( ) 202 throw( uno::RuntimeException ) 203 { 204 return ::getCppuType((const sal_Int32*)0); 205 } 206 207 sal_Bool SAL_CALL SvxUnoColorTable::hasElements( ) 208 throw( uno::RuntimeException ) 209 { 210 return maTable->Count() != 0; 211 } 212 213 /** 214 * Create a colortable 215 */ 216 uno::Reference< uno::XInterface > SAL_CALL SvxUnoColorTable_createInstance(const uno::Reference< lang::XMultiServiceFactory > & ) throw(uno::Exception) 217 { 218 return *new SvxUnoColorTable(); 219 } 220 uno::Reference< uno::XInterface > SAL_CALL create_EnhancedCustomShapeEngine( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) throw(uno::Exception) 221 { 222 return *new EnhancedCustomShapeEngine( rxFact ); 223 } 224 225 // 226 // export this service 227 // 228 229 #include "UnoGraphicExporter.hxx" 230 #include "unogalthemeprovider.hxx" 231 #include <com/sun/star/registry/XRegistryKey.hpp> 232 #include "sal/types.h" 233 #include "osl/diagnose.h" 234 #include "cppuhelper/factory.hxx" 235 #include "uno/lbnames.h" 236 #include <svx/sdr/primitive2d/primitiveFactory2d.hxx> 237 #include "sidebar/PanelFactory.hxx" 238 239 240 /* 241 namespace svx 242 { 243 extern OUString SAL_CALL ExtrusionDepthController_getImplementationName(); 244 extern uno::Reference< uno::XInterface > SAL_CALL ExtrusionDepthController_createInstance(const uno::Reference< lang::XMultiServiceFactory > &) throw( uno::RuntimeException ); 245 extern uno::Sequence< OUString > SAL_CALL ExtrusionDepthController_getSupportedServiceNames() throw( uno::RuntimeException ); 246 } 247 */ 248 249 extern "C" 250 { 251 252 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment ( 253 const sal_Char ** ppEnvTypeName, uno_Environment ** ) 254 { 255 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 256 } 257 258 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory ( 259 const sal_Char * pImplName, void * pServiceManager, void * ) 260 { 261 void * pRet = 0; 262 if( pServiceManager ) 263 { 264 uno::Reference< lang::XSingleServiceFactory > xFactory; 265 266 if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxUnoColorTable" ) == 0 ) 267 { 268 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 269 SvxUnoColorTable::getImplementationName_Static(), 270 SvxUnoColorTable_createInstance, 271 SvxUnoColorTable::getSupportedServiceNames_Static() ); 272 } 273 else if ( rtl_str_compare( pImplName, "com.sun.star.drawing.EnhancedCustomShapeEngine" ) == 0 ) 274 { 275 xFactory = createSingleFactory( reinterpret_cast< NMSP_LANG::XMultiServiceFactory* >( pServiceManager ), 276 EnhancedCustomShapeEngine_getImplementationName(), 277 create_EnhancedCustomShapeEngine, 278 EnhancedCustomShapeEngine_getSupportedServiceNames() ); 279 } 280 else if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxShapeCollection" ) == 0 ) 281 { 282 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 283 SvxShapeCollection::getImplementationName_Static(), 284 SvxShapeCollection_createInstance, 285 SvxShapeCollection::getSupportedServiceNames_Static() ); 286 } 287 else if( svx::RecoveryUI::st_getImplementationName().equalsAscii( pImplName ) ) 288 { 289 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 290 svx::RecoveryUI::st_getImplementationName(), 291 svx::RecoveryUI::st_createInstance, 292 svx::RecoveryUI::st_getSupportedServiceNames() ); 293 } 294 else if( svx::GraphicExporter_getImplementationName().equalsAscii( pImplName ) ) 295 { 296 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 297 svx::GraphicExporter_getImplementationName(), 298 svx::GraphicExporter_createInstance, 299 svx::GraphicExporter_getSupportedServiceNames() ); 300 } 301 else if ( svx::FontHeightToolBoxControl::getImplementationName_Static().equalsAscii( pImplName ) ) 302 { 303 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 304 svx::FontHeightToolBoxControl::getImplementationName_Static(), 305 svx::FontHeightToolBoxControl_createInstance, 306 svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() ); 307 } 308 else if ( svx::FindTextToolbarController::getImplementationName_Static().equalsAscii( pImplName ) ) 309 { 310 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 311 svx::FindTextToolbarController::getImplementationName_Static(), 312 svx::FindTextToolbarController_createInstance, 313 svx::FindTextToolbarController::getSupportedServiceNames_Static() ); 314 } 315 else if ( svx::DownSearchToolboxController::getImplementationName_Static().equalsAscii( pImplName ) ) 316 { 317 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 318 svx::DownSearchToolboxController::getImplementationName_Static(), 319 svx::DownSearchToolboxController_createInstance, 320 svx::DownSearchToolboxController::getSupportedServiceNames_Static() ); 321 } 322 else if ( svx::UpSearchToolboxController::getImplementationName_Static().equalsAscii( pImplName ) ) 323 { 324 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 325 svx::UpSearchToolboxController::getImplementationName_Static(), 326 svx::UpSearchToolboxController_createInstance, 327 svx::UpSearchToolboxController::getSupportedServiceNames_Static() ); 328 } 329 else if ( svx::FindbarDispatcher::getImplementationName_Static().equalsAscii( pImplName ) ) 330 { 331 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 332 svx::FindbarDispatcher::getImplementationName_Static(), 333 svx::FindbarDispatcher_createInstance, 334 svx::FindbarDispatcher::getSupportedServiceNames_Static() ); 335 } 336 else if( ::unogallery::GalleryThemeProvider_getImplementationName().equalsAscii( pImplName ) ) 337 { 338 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 339 ::unogallery::GalleryThemeProvider_getImplementationName(), 340 ::unogallery::GalleryThemeProvider_createInstance, 341 ::unogallery::GalleryThemeProvider_getSupportedServiceNames() ); 342 } 343 else if( drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static().equalsAscii( pImplName ) ) 344 { 345 // XPrimitiveFactory2D 346 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 347 drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static(), 348 drawinglayer::primitive2d::XPrimitiveFactory2DProvider_createInstance, 349 drawinglayer::primitive2d::PrimitiveFactory2D::getSupportedServiceNames_Static() ); 350 } 351 else if( ::svx::SvXMLGraphicImportHelper_getImplementationName().equalsAscii( pImplName ) ) 352 { 353 xFactory = ::cppu::createSingleFactory( 354 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 355 ::svx::SvXMLGraphicImportHelper_getImplementationName(), 356 ::svx::SvXMLGraphicImportHelper_createInstance, 357 ::svx::SvXMLGraphicImportHelper_getSupportedServiceNames() ); 358 } 359 else if( ::svx::SvXMLGraphicExportHelper_getImplementationName().equalsAscii( pImplName ) ) 360 { 361 xFactory = ::cppu::createSingleFactory( 362 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ), 363 ::svx::SvXMLGraphicExportHelper_getImplementationName(), 364 ::svx::SvXMLGraphicExportHelper_createInstance, 365 ::svx::SvXMLGraphicExportHelper_getSupportedServiceNames() ); 366 } 367 else if (::svx::sidebar::PanelFactory::getImplementationName().equalsAscii(pImplName)) 368 { 369 xFactory = ::cppu::createSingleFactory( 370 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), 371 ::svx::sidebar::PanelFactory::getImplementationName(), 372 ::svx::sidebar::PanelFactory::createInstance, 373 ::svx::sidebar::PanelFactory::getSupportedServiceNames()); 374 } 375 376 if( xFactory.is()) 377 { 378 xFactory->acquire(); 379 pRet = xFactory.get(); 380 } 381 } 382 383 return pRet; 384 } 385 386 } 387