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