1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unotools/pathoptions.hxx>
21 #include <com/sun/star/lang/XServiceInfo.hpp>
22 #include <com/sun/star/container/XNameContainer.hpp>
23 #include <cppuhelper/implbase2.hxx>
25 #include "../customshapes/EnhancedCustomShapeEngine.hxx"
27 #include <svx/xtable.hxx>
28 #include "svx/unoshcol.hxx"
29 #include "recoveryui.hxx"
30 #include "svx/xmlgrhlp.hxx"
31 #include "tbunocontroller.hxx"
32 #include "tbunosearchcontrollers.hxx"
34 using namespace ::com::sun::star
;
35 using namespace ::rtl
;
36 using namespace ::cppu
;
38 class SvxUnoColorTable
: public WeakImplHelper2
< container::XNameContainer
, lang::XServiceInfo
>
44 SvxUnoColorTable() throw();
45 virtual ~SvxUnoColorTable() throw();
48 virtual OUString SAL_CALL
getImplementationName() throw( uno::RuntimeException
);
49 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw( uno::RuntimeException
);
50 virtual uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw( uno::RuntimeException
);
52 static OUString
getImplementationName_Static() throw()
54 return OUString("com.sun.star.drawing.SvxUnoColorTable");
57 static uno::Sequence
< OUString
> getSupportedServiceNames_Static(void) throw();
60 virtual void SAL_CALL
insertByName( const OUString
& aName
, const uno::Any
& aElement
) throw( lang::IllegalArgumentException
, container::ElementExistException
, lang::WrappedTargetException
, uno::RuntimeException
);
61 virtual void SAL_CALL
removeByName( const OUString
& Name
) throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
);
64 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const uno::Any
& aElement
) throw( lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
);
67 virtual uno::Any SAL_CALL
getByName( const OUString
& aName
) throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
);
69 virtual uno::Sequence
< OUString
> SAL_CALL
getElementNames() throw( uno::RuntimeException
);
71 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) throw( uno::RuntimeException
);
74 virtual uno::Type SAL_CALL
getElementType() throw( uno::RuntimeException
);
75 virtual sal_Bool SAL_CALL
hasElements() throw( uno::RuntimeException
);
78 SvxUnoColorTable::SvxUnoColorTable() throw()
80 pList
= XPropertyList::CreatePropertyList( XCOLOR_LIST
, SvtPathOptions().GetPalettePath() )->AsColorList();
83 SvxUnoColorTable::~SvxUnoColorTable() throw()
87 sal_Bool SAL_CALL
SvxUnoColorTable::supportsService( const OUString
& ServiceName
) throw(uno::RuntimeException
)
89 uno::Sequence
< OUString
> aSNL( getSupportedServiceNames() );
90 const OUString
* pArray
= aSNL
.getConstArray();
92 for( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
93 if( pArray
[i
] == ServiceName
)
99 OUString SAL_CALL
SvxUnoColorTable::getImplementationName() throw( uno::RuntimeException
)
101 return OUString("SvxUnoColorTable");
104 uno::Sequence
< OUString
> SAL_CALL
SvxUnoColorTable::getSupportedServiceNames()
105 throw( uno::RuntimeException
)
107 return getSupportedServiceNames_Static();
110 uno::Sequence
< OUString
> SvxUnoColorTable::getSupportedServiceNames_Static(void) throw()
112 uno::Sequence
< OUString
> aSNS( 1 );
113 aSNS
.getArray()[0] = OUString("com.sun.star.drawing.ColorTable" );
118 void SAL_CALL
SvxUnoColorTable::insertByName( const OUString
& aName
, const uno::Any
& aElement
)
119 throw( lang::IllegalArgumentException
, container::ElementExistException
, lang::WrappedTargetException
, uno::RuntimeException
)
121 if( hasByName( aName
) )
122 throw container::ElementExistException();
124 sal_Int32 nColor
= 0;
125 if( !(aElement
>>= nColor
) )
126 throw lang::IllegalArgumentException();
130 XColorEntry
* pEntry
= new XColorEntry( Color( (ColorData
)nColor
), aName
);
131 pList
->Insert( pEntry
, pList
->Count() );
135 void SAL_CALL
SvxUnoColorTable::removeByName( const OUString
& Name
)
136 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
138 long nIndex
= pList
.is() ? pList
->Get( Name
) : -1;
140 throw container::NoSuchElementException();
142 pList
->Remove( nIndex
);
146 void SAL_CALL
SvxUnoColorTable::replaceByName( const OUString
& aName
, const uno::Any
& aElement
)
147 throw( lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
149 sal_Int32 nColor
= 0;
150 if( !(aElement
>>= nColor
) )
151 throw lang::IllegalArgumentException();
153 long nIndex
= pList
.is() ? pList
->Get( aName
) : -1;
155 throw container::NoSuchElementException();
157 XColorEntry
* pEntry
= new XColorEntry( Color( (ColorData
)nColor
), aName
);
158 delete pList
->Replace( nIndex
, pEntry
);
162 uno::Any SAL_CALL
SvxUnoColorTable::getByName( const OUString
& aName
)
163 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
165 long nIndex
= pList
.is() ? pList
->Get( aName
) : -1;
167 throw container::NoSuchElementException();
169 XColorEntry
* pEntry
= pList
->GetColor( nIndex
);
170 return uno::Any( (sal_Int32
) pEntry
->GetColor().GetRGBColor() );
173 uno::Sequence
< OUString
> SAL_CALL
SvxUnoColorTable::getElementNames()
174 throw( uno::RuntimeException
)
176 const long nCount
= pList
.is() ? pList
->Count() : 0;
178 uno::Sequence
< OUString
> aSeq( nCount
);
179 OUString
* pStrings
= aSeq
.getArray();
181 for( long nIndex
= 0; nIndex
< nCount
; nIndex
++ )
183 XColorEntry
* pEntry
= pList
->GetColor( (long)nIndex
);
184 pStrings
[nIndex
] = pEntry
->GetName();
190 sal_Bool SAL_CALL
SvxUnoColorTable::hasByName( const OUString
& aName
)
191 throw( uno::RuntimeException
)
193 long nIndex
= pList
.is() ? pList
->Get( aName
) : -1;
198 uno::Type SAL_CALL
SvxUnoColorTable::getElementType()
199 throw( uno::RuntimeException
)
201 return ::getCppuType((const sal_Int32
*)0);
204 sal_Bool SAL_CALL
SvxUnoColorTable::hasElements()
205 throw( uno::RuntimeException
)
207 return pList
.is() && pList
->Count() != 0;
211 * Create a colortable
213 uno::Reference
< uno::XInterface
> SAL_CALL
SvxUnoColorTable_createInstance(const uno::Reference
< lang::XMultiServiceFactory
> & ) throw(uno::Exception
)
215 return *new SvxUnoColorTable();
217 uno::Reference
< uno::XInterface
> SAL_CALL
create_EnhancedCustomShapeEngine( const uno::Reference
< lang::XMultiServiceFactory
>& rxFact
) throw(uno::Exception
)
219 return *new EnhancedCustomShapeEngine( rxFact
);
223 // export this service
226 #include "UnoGraphicExporter.hxx"
227 #include "unogalthemeprovider.hxx"
228 #include <com/sun/star/registry/XRegistryKey.hpp>
229 #include "sal/types.h"
230 #include "osl/diagnose.h"
231 #include "cppuhelper/factory.hxx"
232 #include "uno/lbnames.h"
233 #include <svx/sdr/primitive2d/primitiveFactory2d.hxx>
234 #include "sidebar/PanelFactory.hxx"
240 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
svx_component_getFactory (
241 const sal_Char
* pImplName
, void * pServiceManager
, void * )
244 if( pServiceManager
)
246 uno::Reference
< lang::XSingleServiceFactory
> xFactory
;
248 if( rtl_str_compare( pImplName
, "com.sun.star.drawing.SvxUnoColorTable" ) == 0 )
250 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
251 SvxUnoColorTable::getImplementationName_Static(),
252 SvxUnoColorTable_createInstance
,
253 SvxUnoColorTable::getSupportedServiceNames_Static() );
255 else if ( rtl_str_compare( pImplName
, "com.sun.star.drawing.EnhancedCustomShapeEngine" ) == 0 )
257 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
258 EnhancedCustomShapeEngine_getImplementationName(),
259 create_EnhancedCustomShapeEngine
,
260 EnhancedCustomShapeEngine_getSupportedServiceNames() );
262 else if( rtl_str_compare( pImplName
, "com.sun.star.drawing.SvxShapeCollection" ) == 0 )
264 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
265 SvxShapeCollection::getImplementationName_Static(),
266 SvxShapeCollection_createInstance
,
267 SvxShapeCollection::getSupportedServiceNames_Static() );
269 else if( svx::RecoveryUI::st_getImplementationName().equalsAscii( pImplName
) )
271 xFactory
= ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
272 svx::RecoveryUI::st_getImplementationName(),
273 svx::RecoveryUI::st_createInstance
,
274 svx::RecoveryUI::st_getSupportedServiceNames() );
276 else if( svx::GraphicExporter_getImplementationName().equalsAscii( pImplName
) )
278 xFactory
= ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
279 svx::GraphicExporter_getImplementationName(),
280 svx::GraphicExporter_createInstance
,
281 svx::GraphicExporter_getSupportedServiceNames() );
283 else if ( svx::FontHeightToolBoxControl::getImplementationName_Static().equalsAscii( pImplName
) )
285 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
286 svx::FontHeightToolBoxControl::getImplementationName_Static(),
287 svx::FontHeightToolBoxControl_createInstance
,
288 svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() );
290 else if ( svx::FindTextToolbarController::getImplementationName_Static().equalsAscii( pImplName
) )
292 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
293 svx::FindTextToolbarController::getImplementationName_Static(),
294 svx::FindTextToolbarController_createInstance
,
295 svx::FindTextToolbarController::getSupportedServiceNames_Static() );
297 else if ( svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::DOWN
).equalsAscii( pImplName
) )
299 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
300 svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::DOWN
),
301 svx::DownSearchToolboxController_createInstance
,
302 svx::UpDownSearchToolboxController::getSupportedServiceNames_Static() );
304 else if ( svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::UP
).equalsAscii( pImplName
) )
306 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
307 svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::UP
),
308 svx::UpSearchToolboxController_createInstance
,
309 svx::UpDownSearchToolboxController::getSupportedServiceNames_Static() );
311 else if ( svx::MatchCaseToolboxController::getImplementationName_Static().equalsAscii( pImplName
) )
313 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
314 svx::MatchCaseToolboxController::getImplementationName_Static(),
315 svx::MatchCaseToolboxController_createInstance
,
316 svx::MatchCaseToolboxController::getSupportedServiceNames_Static() );
318 else if ( svx::ExitSearchToolboxController::getImplementationName_Static().equalsAscii( pImplName
) )
320 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
321 svx::ExitSearchToolboxController::getImplementationName_Static(),
322 svx::ExitFindbarToolboxController_createInstance
,
323 svx::ExitSearchToolboxController::getSupportedServiceNames_Static() );
325 else if ( svx::FindbarDispatcher::getImplementationName_Static().equalsAscii( pImplName
) )
327 xFactory
= createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
328 svx::FindbarDispatcher::getImplementationName_Static(),
329 svx::FindbarDispatcher_createInstance
,
330 svx::FindbarDispatcher::getSupportedServiceNames_Static() );
332 else if( ::unogallery::GalleryThemeProvider_getImplementationName().equalsAscii( pImplName
) )
334 xFactory
= ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
335 ::unogallery::GalleryThemeProvider_getImplementationName(),
336 ::unogallery::GalleryThemeProvider_createInstance
,
337 ::unogallery::GalleryThemeProvider_getSupportedServiceNames() );
339 else if( drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static().equalsAscii( pImplName
) )
341 // XPrimitiveFactory2D
342 xFactory
= ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
343 drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static(),
344 drawinglayer::primitive2d::XPrimitiveFactory2DProvider_createInstance
,
345 drawinglayer::primitive2d::PrimitiveFactory2D::getSupportedServiceNames_Static() );
347 else if( ::svx::SvXMLGraphicImportHelper_getImplementationName().equalsAscii( pImplName
) )
349 xFactory
= ::cppu::createSingleFactory(
350 reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
351 ::svx::SvXMLGraphicImportHelper_getImplementationName(),
352 ::svx::SvXMLGraphicImportHelper_createInstance
,
353 ::svx::SvXMLGraphicImportHelper_getSupportedServiceNames() );
355 else if( ::svx::SvXMLGraphicExportHelper_getImplementationName().equalsAscii( pImplName
) )
357 xFactory
= ::cppu::createSingleFactory(
358 reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
359 ::svx::SvXMLGraphicExportHelper_getImplementationName(),
360 ::svx::SvXMLGraphicExportHelper_createInstance
,
361 ::svx::SvXMLGraphicExportHelper_getSupportedServiceNames() );
363 else if (::svx::sidebar::PanelFactory::getImplementationName().equalsAscii(pImplName
))
365 xFactory
= ::cppu::createSingleFactory(
366 reinterpret_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
367 ::svx::sidebar::PanelFactory::getImplementationName(),
368 ::svx::sidebar::PanelFactory::createInstance
,
369 ::svx::sidebar::PanelFactory::getSupportedServiceNames());
375 pRet
= xFactory
.get();
384 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */