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(RTL_CONSTASCII_USTRINGPARAM("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( RTL_CONSTASCII_USTRINGPARAM("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( RTL_CONSTASCII_USTRINGPARAM("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->Get( 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->Get( 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->Get( 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->Get( 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 0 : uno::Reference< uno::XInterface > SAL_CALL create_EnhancedCustomShapeEngine( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) throw(uno::Exception)
218 : {
219 0 : 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 :
235 : extern "C"
236 : {
237 :
238 0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL svx_component_getFactory (
239 : const sal_Char * pImplName, void * pServiceManager, void * )
240 : {
241 0 : void * pRet = 0;
242 0 : if( pServiceManager )
243 : {
244 0 : uno::Reference< lang::XSingleServiceFactory > xFactory;
245 :
246 0 : if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxUnoColorTable" ) == 0 )
247 : {
248 : xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
249 : SvxUnoColorTable::getImplementationName_Static(),
250 : SvxUnoColorTable_createInstance,
251 0 : SvxUnoColorTable::getSupportedServiceNames_Static() );
252 : }
253 0 : else if ( rtl_str_compare( pImplName, "com.sun.star.drawing.EnhancedCustomShapeEngine" ) == 0 )
254 : {
255 : xFactory = createSingleFactory( reinterpret_cast< NMSP_LANG::XMultiServiceFactory* >( pServiceManager ),
256 : EnhancedCustomShapeEngine_getImplementationName(),
257 : create_EnhancedCustomShapeEngine,
258 0 : EnhancedCustomShapeEngine_getSupportedServiceNames() );
259 : }
260 0 : else if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxShapeCollection" ) == 0 )
261 : {
262 : xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
263 : SvxShapeCollection::getImplementationName_Static(),
264 : SvxShapeCollection_createInstance,
265 0 : SvxShapeCollection::getSupportedServiceNames_Static() );
266 : }
267 0 : else if( svx::RecoveryUI::st_getImplementationName().equalsAscii( pImplName ) )
268 : {
269 : xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
270 : svx::RecoveryUI::st_getImplementationName(),
271 : svx::RecoveryUI::st_createInstance,
272 0 : svx::RecoveryUI::st_getSupportedServiceNames() );
273 : }
274 0 : else if( svx::GraphicExporter_getImplementationName().equalsAscii( pImplName ) )
275 : {
276 : xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
277 : svx::GraphicExporter_getImplementationName(),
278 : svx::GraphicExporter_createInstance,
279 0 : svx::GraphicExporter_getSupportedServiceNames() );
280 : }
281 0 : else if ( svx::FontHeightToolBoxControl::getImplementationName_Static().equalsAscii( pImplName ) )
282 : {
283 : xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
284 : svx::FontHeightToolBoxControl::getImplementationName_Static(),
285 : svx::FontHeightToolBoxControl_createInstance,
286 0 : svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() );
287 : }
288 0 : else if ( svx::FindTextToolbarController::getImplementationName_Static().equalsAscii( pImplName ) )
289 : {
290 : xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
291 : svx::FindTextToolbarController::getImplementationName_Static(),
292 : svx::FindTextToolbarController_createInstance,
293 0 : svx::FindTextToolbarController::getSupportedServiceNames_Static() );
294 : }
295 0 : else if ( svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::DOWN ).equalsAscii( pImplName ) )
296 : {
297 : xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
298 : svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::DOWN ),
299 : svx::DownSearchToolboxController_createInstance,
300 0 : svx::UpDownSearchToolboxController::getSupportedServiceNames_Static() );
301 : }
302 0 : else if ( svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::UP ).equalsAscii( pImplName ) )
303 : {
304 : xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
305 : svx::UpDownSearchToolboxController::getImplementationName_Static( svx::UpDownSearchToolboxController::UP ),
306 : svx::UpSearchToolboxController_createInstance,
307 0 : svx::UpDownSearchToolboxController::getSupportedServiceNames_Static() );
308 : }
309 0 : else if ( svx::FindbarDispatcher::getImplementationName_Static().equalsAscii( pImplName ) )
310 : {
311 : xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
312 : svx::FindbarDispatcher::getImplementationName_Static(),
313 : svx::FindbarDispatcher_createInstance,
314 0 : svx::FindbarDispatcher::getSupportedServiceNames_Static() );
315 : }
316 0 : else if( ::unogallery::GalleryThemeProvider_getImplementationName().equalsAscii( pImplName ) )
317 : {
318 : xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
319 : ::unogallery::GalleryThemeProvider_getImplementationName(),
320 : ::unogallery::GalleryThemeProvider_createInstance,
321 0 : ::unogallery::GalleryThemeProvider_getSupportedServiceNames() );
322 : }
323 0 : else if( drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static().equalsAscii( pImplName ) )
324 : {
325 : // XPrimitiveFactory2D
326 : xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
327 : drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static(),
328 : drawinglayer::primitive2d::XPrimitiveFactory2DProvider_createInstance,
329 0 : drawinglayer::primitive2d::PrimitiveFactory2D::getSupportedServiceNames_Static() );
330 : }
331 0 : else if( ::svx::SvXMLGraphicImportHelper_getImplementationName().equalsAscii( pImplName ) )
332 : {
333 : xFactory = ::cppu::createSingleFactory(
334 : reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
335 : ::svx::SvXMLGraphicImportHelper_getImplementationName(),
336 : ::svx::SvXMLGraphicImportHelper_createInstance,
337 0 : ::svx::SvXMLGraphicImportHelper_getSupportedServiceNames() );
338 : }
339 0 : else if( ::svx::SvXMLGraphicExportHelper_getImplementationName().equalsAscii( pImplName ) )
340 : {
341 : xFactory = ::cppu::createSingleFactory(
342 : reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
343 : ::svx::SvXMLGraphicExportHelper_getImplementationName(),
344 : ::svx::SvXMLGraphicExportHelper_createInstance,
345 0 : ::svx::SvXMLGraphicExportHelper_getSupportedServiceNames() );
346 : }
347 0 : if( xFactory.is())
348 : {
349 0 : xFactory->acquire();
350 0 : pRet = xFactory.get();
351 0 : }
352 : }
353 :
354 0 : return pRet;
355 : }
356 :
357 : }
358 :
359 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|