1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoctabl.cxx,v $
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
>
56 SvxUnoColorTable() throw();
57 virtual ~SvxUnoColorTable() throw();
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();
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
);
76 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const uno::Any
& aElement
) throw( lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
);
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
);
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()
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
)
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" ));
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();
138 if( !(aElement
>>= nColor
) )
139 throw lang::IllegalArgumentException();
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;
153 throw container::NoSuchElementException();
155 pTable
->Remove( nIndex
);
159 void SAL_CALL
SvxUnoColorTable::replaceByName( const OUString
& aName
, const uno::Any
& aElement
)
160 throw( lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
163 if( !(aElement
>>= nColor
) )
164 throw lang::IllegalArgumentException();
166 long nIndex
= pTable
? ((XPropertyTable
*)pTable
)->Get( aName
) : -1;
168 throw container::NoSuchElementException();
170 XColorEntry
* pEntry
= new XColorEntry( Color( (ColorData
)nColor
), aName
);
171 delete pTable
->Replace( nIndex
, pEntry
);
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;
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();
203 sal_Bool SAL_CALL
SvxUnoColorTable::hasByName( const OUString
& aName
)
204 throw( uno::RuntimeException
)
206 long nIndex
= pTable
? ((XPropertyTable
*)pTable
)->Get( aName
) : -1;
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
240 #include "UnoGraphicExporter.hxx"
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>
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
)
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() );
286 writeInfo( pKey
, svx::GraphicExporter_getImplementationName(), svx::GraphicExporter_getSupportedServiceNames() );
288 writeInfo( pKey
, svx::FontHeightToolBoxControl::getImplementationName_Static(), svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() );
289 writeInfo( pKey
, ::unogallery::GalleryThemeProvider_getImplementationName(),::unogallery::GalleryThemeProvider_getSupportedServiceNames() );
291 // XPrimitiveFactory2D
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!" );
308 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory (
309 const sal_Char
* pImplName
, void * pServiceManager
, void * )
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() );
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() );
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() );
395 pRet
= xFactory
.get();