merge the formfield patch from ooo-build
[ooovba.git] / svx / source / unodraw / unoctabl.cxx
blob671d28e431e76e28a9890984ad57a0a300132f0a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoctabl.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svtools/pathoptions.hxx>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <cppuhelper/implbase2.hxx>
38 #include "../customshapes/EnhancedCustomShapeEngine.hxx"
40 #include <svx/xtable.hxx>
41 #include "unoshcol.hxx"
42 #include "recoveryui.hxx"
43 #include "xmlgrhlp.hxx"
44 #include "tbunocontroller.hxx"
46 using namespace ::com::sun::star;
47 using namespace ::rtl;
48 using namespace ::cppu;
50 class SvxUnoColorTable : public WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >
52 private:
53 XColorTable* pTable;
55 public:
56 SvxUnoColorTable() throw();
57 virtual ~SvxUnoColorTable() throw();
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException );
61 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( uno::RuntimeException);
62 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException);
64 static OUString getImplementationName_Static() throw()
66 return OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.SvxUnoColorTable"));
69 static uno::Sequence< OUString > getSupportedServiceNames_Static(void) throw();
71 // XNameContainer
72 virtual void SAL_CALL insertByName( const OUString& aName, const uno::Any& aElement ) throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException);
73 virtual void SAL_CALL removeByName( const OUString& Name ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
75 // XNameReplace
76 virtual void SAL_CALL replaceByName( const OUString& aName, const uno::Any& aElement ) throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
78 // XNameAccess
79 virtual uno::Any SAL_CALL getByName( const OUString& aName ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
81 virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) throw( uno::RuntimeException);
83 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw( uno::RuntimeException);
85 // XElementAccess
86 virtual uno::Type SAL_CALL getElementType( ) throw( uno::RuntimeException);
87 virtual sal_Bool SAL_CALL hasElements( ) throw( uno::RuntimeException);
90 SvxUnoColorTable::SvxUnoColorTable() throw()
92 pTable = new XColorTable( SvtPathOptions().GetPalettePath() );
95 SvxUnoColorTable::~SvxUnoColorTable() throw()
97 delete pTable;
100 sal_Bool SAL_CALL SvxUnoColorTable::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
102 uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
103 const OUString * pArray = aSNL.getConstArray();
105 for( INT32 i = 0; i < aSNL.getLength(); i++ )
106 if( pArray[i] == ServiceName )
107 return TRUE;
109 return FALSE;
112 OUString SAL_CALL SvxUnoColorTable::getImplementationName() throw( uno::RuntimeException )
114 return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoColorTable") );
117 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getSupportedServiceNames( )
118 throw( uno::RuntimeException )
120 return getSupportedServiceNames_Static();
123 uno::Sequence< OUString > SvxUnoColorTable::getSupportedServiceNames_Static(void) throw()
125 uno::Sequence< OUString > aSNS( 1 );
126 aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ColorTable" ));
127 return aSNS;
130 // XNameContainer
131 void SAL_CALL SvxUnoColorTable::insertByName( const OUString& aName, const uno::Any& aElement )
132 throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
134 if( hasByName( aName ) )
135 throw container::ElementExistException();
137 INT32 nColor = 0;
138 if( !(aElement >>= nColor) )
139 throw lang::IllegalArgumentException();
141 if( pTable )
143 XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName );
144 pTable->Insert( pTable->Count(), pEntry );
148 void SAL_CALL SvxUnoColorTable::removeByName( const OUString& Name )
149 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
151 long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( Name ) : -1;
152 if( nIndex == -1 )
153 throw container::NoSuchElementException();
155 pTable->Remove( nIndex );
158 // XNameReplace
159 void SAL_CALL SvxUnoColorTable::replaceByName( const OUString& aName, const uno::Any& aElement )
160 throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
162 INT32 nColor = 0;
163 if( !(aElement >>= nColor) )
164 throw lang::IllegalArgumentException();
166 long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( aName ) : -1;
167 if( nIndex == -1 )
168 throw container::NoSuchElementException();
170 XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName );
171 delete pTable->Replace( nIndex, pEntry );
174 // XNameAccess
175 uno::Any SAL_CALL SvxUnoColorTable::getByName( const OUString& aName )
176 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
178 long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( aName ) : -1;
179 if( nIndex == -1 )
180 throw container::NoSuchElementException();
182 XColorEntry* pEntry = ((XColorTable*)pTable)->GetColor( nIndex );
183 return uno::Any( (sal_Int32) pEntry->GetColor().GetRGBColor() );
186 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getElementNames( )
187 throw( uno::RuntimeException )
189 const long nCount = pTable ? pTable->Count() : 0;
191 uno::Sequence< OUString > aSeq( nCount );
192 OUString* pStrings = aSeq.getArray();
194 for( long nIndex = 0; nIndex < nCount; nIndex++ )
196 XColorEntry* pEntry = pTable->GetColor( (long)nIndex );
197 pStrings[nIndex] = pEntry->GetName();
200 return aSeq;
203 sal_Bool SAL_CALL SvxUnoColorTable::hasByName( const OUString& aName )
204 throw( uno::RuntimeException )
206 long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( aName ) : -1;
207 return nIndex != -1;
210 // XElementAccess
211 uno::Type SAL_CALL SvxUnoColorTable::getElementType( )
212 throw( uno::RuntimeException )
214 return ::getCppuType((const sal_Int32*)0);
217 sal_Bool SAL_CALL SvxUnoColorTable::hasElements( )
218 throw( uno::RuntimeException )
220 return pTable && pTable->Count() != 0;
224 * Create a colortable
226 uno::Reference< uno::XInterface > SAL_CALL SvxUnoColorTable_createInstance(const uno::Reference< lang::XMultiServiceFactory > & ) throw(uno::Exception)
228 return *new SvxUnoColorTable();
230 uno::Reference< uno::XInterface > SAL_CALL create_EnhancedCustomShapeEngine( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) throw(uno::Exception)
232 return *new EnhancedCustomShapeEngine( rxFact );
236 // export this service
239 #ifndef SVX_LIGHT
240 #include "UnoGraphicExporter.hxx"
241 #endif
242 #include "unogalthemeprovider.hxx"
243 #include <com/sun/star/registry/XRegistryKey.hpp>
244 #include "sal/types.h"
245 #include "osl/diagnose.h"
246 #include "cppuhelper/factory.hxx"
247 #include "uno/lbnames.h"
248 #include <svx/sdr/primitive2d/primitiveFactory2d.hxx>
250 extern "C"
253 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment (
254 const sal_Char ** ppEnvTypeName, uno_Environment ** )
256 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
259 static void writeInfo (
260 registry::XRegistryKey * pRegistryKey,
261 const OUString& rImplementationName,
262 const uno::Sequence< OUString >& rServices)
264 uno::Reference< registry::XRegistryKey > xNewKey(
265 pRegistryKey->createKey(
266 OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + rImplementationName + OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) ) );
268 for( sal_Int32 i = 0; i < rServices.getLength(); i++ )
269 xNewKey->createKey( rServices.getConstArray()[i]);
272 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo (
273 void * , void * pRegistryKey)
275 if( pRegistryKey )
279 registry::XRegistryKey *pKey = reinterpret_cast< registry::XRegistryKey * >( pRegistryKey );
281 writeInfo( pKey, SvxShapeCollection::getImplementationName_Static(), SvxShapeCollection::getSupportedServiceNames_Static() );
282 writeInfo( pKey, SvxUnoColorTable::getImplementationName_Static(), SvxUnoColorTable::getSupportedServiceNames_Static() );
283 writeInfo( pKey, EnhancedCustomShapeEngine_getImplementationName(), EnhancedCustomShapeEngine_getSupportedServiceNames() );
284 writeInfo( pKey, svx::RecoveryUI::st_getImplementationName(), svx::RecoveryUI::st_getSupportedServiceNames() );
285 #ifndef SVX_LIGHT
286 writeInfo( pKey, svx::GraphicExporter_getImplementationName(), svx::GraphicExporter_getSupportedServiceNames() );
287 #endif
288 writeInfo( pKey, svx::FontHeightToolBoxControl::getImplementationName_Static(), svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() );
289 writeInfo( pKey, ::unogallery::GalleryThemeProvider_getImplementationName(),::unogallery::GalleryThemeProvider_getSupportedServiceNames() );
291 // XPrimitiveFactory2D
292 writeInfo( pKey,
293 drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static(),
294 drawinglayer::primitive2d::PrimitiveFactory2D::getSupportedServiceNames_Static() );
296 writeInfo( pKey, ::svx::SvXMLGraphicImportHelper_getImplementationName(),::svx::SvXMLGraphicImportHelper_getSupportedServiceNames() );
297 writeInfo( pKey, ::svx::SvXMLGraphicExportHelper_getImplementationName(),::svx::SvXMLGraphicExportHelper_getSupportedServiceNames() );
299 catch (registry::InvalidRegistryException &)
301 OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
305 return sal_True;
308 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory (
309 const sal_Char * pImplName, void * pServiceManager, void * )
311 void * pRet = 0;
312 if( pServiceManager )
314 uno::Reference< lang::XSingleServiceFactory > xFactory;
316 if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxUnoColorTable" ) == 0 )
318 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
319 SvxUnoColorTable::getImplementationName_Static(),
320 SvxUnoColorTable_createInstance,
321 SvxUnoColorTable::getSupportedServiceNames_Static() );
323 else if ( rtl_str_compare( pImplName, "com.sun.star.drawing.EnhancedCustomShapeEngine" ) == 0 )
325 xFactory = createSingleFactory( reinterpret_cast< NMSP_LANG::XMultiServiceFactory* >( pServiceManager ),
326 EnhancedCustomShapeEngine_getImplementationName(),
327 create_EnhancedCustomShapeEngine,
328 EnhancedCustomShapeEngine_getSupportedServiceNames() );
330 else if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxShapeCollection" ) == 0 )
332 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
333 SvxShapeCollection::getImplementationName_Static(),
334 SvxShapeCollection_createInstance,
335 SvxShapeCollection::getSupportedServiceNames_Static() );
337 else if( svx::RecoveryUI::st_getImplementationName().equalsAscii( pImplName ) )
339 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
340 svx::RecoveryUI::st_getImplementationName(),
341 svx::RecoveryUI::st_createInstance,
342 svx::RecoveryUI::st_getSupportedServiceNames() );
344 #ifndef SVX_LIGHT
345 else if( svx::GraphicExporter_getImplementationName().equalsAscii( pImplName ) )
347 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
348 svx::GraphicExporter_getImplementationName(),
349 svx::GraphicExporter_createInstance,
350 svx::GraphicExporter_getSupportedServiceNames() );
352 #endif
353 else if ( svx::FontHeightToolBoxControl::getImplementationName_Static().equalsAscii( pImplName ) )
355 xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
356 svx::FontHeightToolBoxControl::getImplementationName_Static(),
357 svx::FontHeightToolBoxControl_createInstance,
358 svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() );
360 else if( ::unogallery::GalleryThemeProvider_getImplementationName().equalsAscii( pImplName ) )
362 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
363 ::unogallery::GalleryThemeProvider_getImplementationName(),
364 ::unogallery::GalleryThemeProvider_createInstance,
365 ::unogallery::GalleryThemeProvider_getSupportedServiceNames() );
367 else if( drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static().equalsAscii( pImplName ) )
369 // XPrimitiveFactory2D
370 xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
371 drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static(),
372 drawinglayer::primitive2d::XPrimitiveFactory2DProvider_createInstance,
373 drawinglayer::primitive2d::PrimitiveFactory2D::getSupportedServiceNames_Static() );
375 else if( ::svx::SvXMLGraphicImportHelper_getImplementationName().equalsAscii( pImplName ) )
377 xFactory = ::cppu::createSingleFactory(
378 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
379 ::svx::SvXMLGraphicImportHelper_getImplementationName(),
380 ::svx::SvXMLGraphicImportHelper_createInstance,
381 ::svx::SvXMLGraphicImportHelper_getSupportedServiceNames() );
383 else if( ::svx::SvXMLGraphicExportHelper_getImplementationName().equalsAscii( pImplName ) )
385 xFactory = ::cppu::createSingleFactory(
386 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
387 ::svx::SvXMLGraphicExportHelper_getImplementationName(),
388 ::svx::SvXMLGraphicExportHelper_createInstance,
389 ::svx::SvXMLGraphicExportHelper_getSupportedServiceNames() );
392 if( xFactory.is())
394 xFactory->acquire();
395 pRet = xFactory.get();
399 return pRet;