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