xref: /trunk/main/svx/source/unodraw/unoctabl.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <unotools/pathoptions.hxx>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/container/XNameContainer.hpp>
33 #include <cppuhelper/implbase2.hxx>
34 
35 #include "../customshapes/EnhancedCustomShapeEngine.hxx"
36 
37 #include <svx/xtable.hxx>
38 #include "svx/unoshcol.hxx"
39 #include "recoveryui.hxx"
40 #include "svx/xmlgrhlp.hxx"
41 #include "tbunocontroller.hxx"
42 #include "tbunosearchcontrollers.hxx"
43 
44 using namespace ::com::sun::star;
45 using namespace ::rtl;
46 using namespace ::cppu;
47 
48 class SvxUnoColorTable : public WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >
49 {
50 private:
51     XColorTable*    pTable;
52 
53 public:
54     SvxUnoColorTable() throw();
55     virtual ~SvxUnoColorTable() throw();
56 
57     // XServiceInfo
58     virtual OUString SAL_CALL getImplementationName(  ) throw( uno::RuntimeException );
59     virtual sal_Bool SAL_CALL supportsService( const  OUString& ServiceName ) throw( uno::RuntimeException);
60     virtual uno::Sequence<  OUString > SAL_CALL getSupportedServiceNames(  ) throw( uno::RuntimeException);
61 
62     static OUString getImplementationName_Static() throw()
63     {
64         return OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.SvxUnoColorTable"));
65     }
66 
67     static uno::Sequence< OUString >  getSupportedServiceNames_Static(void) throw();
68 
69     // XNameContainer
70     virtual void SAL_CALL insertByName( const  OUString& aName, const  uno::Any& aElement ) throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException);
71     virtual void SAL_CALL removeByName( const  OUString& Name ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
72 
73     // XNameReplace
74     virtual void SAL_CALL replaceByName( const  OUString& aName, const  uno::Any& aElement ) throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
75 
76     // XNameAccess
77     virtual uno::Any SAL_CALL getByName( const  OUString& aName ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
78 
79     virtual uno::Sequence<  OUString > SAL_CALL getElementNames(  ) throw( uno::RuntimeException);
80 
81     virtual sal_Bool SAL_CALL hasByName( const  OUString& aName ) throw( uno::RuntimeException);
82 
83     // XElementAccess
84     virtual uno::Type SAL_CALL getElementType(  ) throw( uno::RuntimeException);
85     virtual sal_Bool SAL_CALL hasElements(  ) throw( uno::RuntimeException);
86 };
87 
88 SvxUnoColorTable::SvxUnoColorTable() throw()
89 {
90     pTable = new XColorTable( SvtPathOptions().GetPalettePath() );
91 }
92 
93 SvxUnoColorTable::~SvxUnoColorTable() throw()
94 {
95     delete pTable;
96 }
97 
98 sal_Bool SAL_CALL SvxUnoColorTable::supportsService( const  OUString& ServiceName ) throw(uno::RuntimeException)
99 {
100     uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
101     const OUString * pArray = aSNL.getConstArray();
102 
103     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
104         if( pArray[i] == ServiceName )
105             return sal_True;
106 
107     return sal_False;
108 }
109 
110 OUString SAL_CALL SvxUnoColorTable::getImplementationName() throw( uno::RuntimeException )
111 {
112     return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoColorTable") );
113 }
114 
115 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getSupportedServiceNames(  )
116     throw( uno::RuntimeException )
117 {
118     return getSupportedServiceNames_Static();
119 }
120 
121 uno::Sequence< OUString > SvxUnoColorTable::getSupportedServiceNames_Static(void) throw()
122 {
123     uno::Sequence< OUString > aSNS( 1 );
124     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ColorTable" ));
125     return aSNS;
126 }
127 
128 // XNameContainer
129 void SAL_CALL SvxUnoColorTable::insertByName( const OUString& aName, const uno::Any& aElement )
130     throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
131 {
132     if( hasByName( aName ) )
133         throw container::ElementExistException();
134 
135     sal_Int32 nColor = 0;
136     if( !(aElement >>= nColor) )
137         throw lang::IllegalArgumentException();
138 
139     if( pTable )
140     {
141         XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName  );
142         pTable->Insert( pTable->Count(), pEntry );
143     }
144 }
145 
146 void SAL_CALL SvxUnoColorTable::removeByName( const OUString& Name )
147     throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
148 {
149     long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( Name ) : -1;
150     if( nIndex == -1 )
151         throw container::NoSuchElementException();
152 
153     pTable->Remove( nIndex );
154 }
155 
156 // XNameReplace
157 void SAL_CALL SvxUnoColorTable::replaceByName( const OUString& aName, const uno::Any& aElement )
158     throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
159 {
160     sal_Int32 nColor = 0;
161     if( !(aElement >>= nColor) )
162         throw lang::IllegalArgumentException();
163 
164     long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( aName ) : -1;
165     if( nIndex == -1  )
166         throw container::NoSuchElementException();
167 
168     XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName );
169     delete pTable->Replace( nIndex, pEntry );
170 }
171 
172 // XNameAccess
173 uno::Any SAL_CALL SvxUnoColorTable::getByName( const  OUString& aName )
174     throw( container::NoSuchElementException,  lang::WrappedTargetException, uno::RuntimeException)
175 {
176     long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( aName ) : -1;
177     if( nIndex == -1 )
178         throw container::NoSuchElementException();
179 
180     XColorEntry* pEntry = ((XColorTable*)pTable)->GetColor( nIndex );
181     return uno::Any( (sal_Int32) pEntry->GetColor().GetRGBColor() );
182 }
183 
184 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getElementNames(  )
185     throw( uno::RuntimeException )
186 {
187     const long nCount = pTable ? pTable->Count() : 0;
188 
189     uno::Sequence< OUString > aSeq( nCount );
190     OUString* pStrings = aSeq.getArray();
191 
192     for( long nIndex = 0; nIndex < nCount; nIndex++ )
193     {
194         XColorEntry* pEntry = pTable->GetColor( (long)nIndex );
195         pStrings[nIndex] = pEntry->GetName();
196     }
197 
198     return aSeq;
199 }
200 
201 sal_Bool SAL_CALL SvxUnoColorTable::hasByName( const OUString& aName )
202     throw( uno::RuntimeException )
203 {
204     long nIndex = pTable ? ((XPropertyTable*)pTable)->Get( aName ) : -1;
205     return nIndex != -1;
206 }
207 
208 // XElementAccess
209 uno::Type SAL_CALL SvxUnoColorTable::getElementType(  )
210     throw( uno::RuntimeException )
211 {
212     return ::getCppuType((const sal_Int32*)0);
213 }
214 
215 sal_Bool SAL_CALL SvxUnoColorTable::hasElements(  )
216     throw( uno::RuntimeException )
217 {
218     return pTable && pTable->Count() != 0;
219 }
220 
221 /**
222  * Create a colortable
223  */
224 uno::Reference< uno::XInterface > SAL_CALL SvxUnoColorTable_createInstance(const uno::Reference< lang::XMultiServiceFactory > & ) throw(uno::Exception)
225 {
226     return *new SvxUnoColorTable();
227 }
228 uno::Reference< uno::XInterface > SAL_CALL create_EnhancedCustomShapeEngine( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) throw(uno::Exception)
229 {
230     return *new EnhancedCustomShapeEngine( rxFact );
231 }
232 
233 //
234 // export this service
235 //
236 
237 #include "UnoGraphicExporter.hxx"
238 #include "unogalthemeprovider.hxx"
239 #include <com/sun/star/registry/XRegistryKey.hpp>
240 #include "sal/types.h"
241 #include "osl/diagnose.h"
242 #include "cppuhelper/factory.hxx"
243 #include "uno/lbnames.h"
244 #include <svx/sdr/primitive2d/primitiveFactory2d.hxx>
245 
246 /*
247 namespace svx
248 {
249 extern OUString SAL_CALL ExtrusionDepthController_getImplementationName();
250 extern uno::Reference< uno::XInterface > SAL_CALL ExtrusionDepthController_createInstance(const uno::Reference< lang::XMultiServiceFactory > &)  throw( uno::RuntimeException );
251 extern uno::Sequence< OUString > SAL_CALL ExtrusionDepthController_getSupportedServiceNames() throw( uno::RuntimeException );
252 }
253 */
254 
255 extern "C"
256 {
257 
258 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment (
259     const sal_Char ** ppEnvTypeName, uno_Environment ** )
260 {
261     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
262 }
263 
264 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory (
265     const sal_Char * pImplName, void * pServiceManager, void *  )
266 {
267     void * pRet = 0;
268     if( pServiceManager  )
269     {
270         uno::Reference< lang::XSingleServiceFactory > xFactory;
271 
272         if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxUnoColorTable" ) == 0 )
273         {
274             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
275                 SvxUnoColorTable::getImplementationName_Static(),
276                 SvxUnoColorTable_createInstance,
277                 SvxUnoColorTable::getSupportedServiceNames_Static() );
278         }
279         else if ( rtl_str_compare( pImplName, "com.sun.star.drawing.EnhancedCustomShapeEngine" ) == 0 )
280         {
281             xFactory = createSingleFactory( reinterpret_cast< NMSP_LANG::XMultiServiceFactory* >( pServiceManager ),
282                 EnhancedCustomShapeEngine_getImplementationName(),
283                 create_EnhancedCustomShapeEngine,
284                 EnhancedCustomShapeEngine_getSupportedServiceNames() );
285         }
286         else if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxShapeCollection" ) == 0 )
287         {
288             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
289                 SvxShapeCollection::getImplementationName_Static(),
290                 SvxShapeCollection_createInstance,
291                 SvxShapeCollection::getSupportedServiceNames_Static() );
292         }
293         else if( svx::RecoveryUI::st_getImplementationName().equalsAscii( pImplName ) )
294         {
295             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
296                 svx::RecoveryUI::st_getImplementationName(),
297                 svx::RecoveryUI::st_createInstance,
298                 svx::RecoveryUI::st_getSupportedServiceNames() );
299         }
300         else if( svx::GraphicExporter_getImplementationName().equalsAscii( pImplName ) )
301         {
302             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
303                 svx::GraphicExporter_getImplementationName(),
304                 svx::GraphicExporter_createInstance,
305                 svx::GraphicExporter_getSupportedServiceNames() );
306         }
307         else if ( svx::FontHeightToolBoxControl::getImplementationName_Static().equalsAscii( pImplName ) )
308         {
309             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
310                 svx::FontHeightToolBoxControl::getImplementationName_Static(),
311                 svx::FontHeightToolBoxControl_createInstance,
312                 svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() );
313         }
314         else if ( svx::FindTextToolbarController::getImplementationName_Static().equalsAscii( pImplName ) )
315         {
316             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
317                 svx::FindTextToolbarController::getImplementationName_Static(),
318                 svx::FindTextToolbarController_createInstance,
319                 svx::FindTextToolbarController::getSupportedServiceNames_Static() );
320         }
321         else if ( svx::DownSearchToolboxController::getImplementationName_Static().equalsAscii( pImplName ) )
322         {
323             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
324                 svx::DownSearchToolboxController::getImplementationName_Static(),
325                 svx::DownSearchToolboxController_createInstance,
326                 svx::DownSearchToolboxController::getSupportedServiceNames_Static() );
327         }
328         else if ( svx::UpSearchToolboxController::getImplementationName_Static().equalsAscii( pImplName ) )
329         {
330             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
331                 svx::UpSearchToolboxController::getImplementationName_Static(),
332                 svx::UpSearchToolboxController_createInstance,
333                 svx::UpSearchToolboxController::getSupportedServiceNames_Static() );
334         }
335         else if ( svx::FindbarDispatcher::getImplementationName_Static().equalsAscii( pImplName ) )
336         {
337             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
338                 svx::FindbarDispatcher::getImplementationName_Static(),
339                 svx::FindbarDispatcher_createInstance,
340                 svx::FindbarDispatcher::getSupportedServiceNames_Static() );
341         }
342         else if( ::unogallery::GalleryThemeProvider_getImplementationName().equalsAscii( pImplName ) )
343         {
344             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
345                 ::unogallery::GalleryThemeProvider_getImplementationName(),
346                 ::unogallery::GalleryThemeProvider_createInstance,
347                 ::unogallery::GalleryThemeProvider_getSupportedServiceNames() );
348         }
349         else if( drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static().equalsAscii( pImplName ) )
350         {
351             // XPrimitiveFactory2D
352             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
353                 drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static(),
354                 drawinglayer::primitive2d::XPrimitiveFactory2DProvider_createInstance,
355                 drawinglayer::primitive2d::PrimitiveFactory2D::getSupportedServiceNames_Static() );
356         }
357         else if( ::svx::SvXMLGraphicImportHelper_getImplementationName().equalsAscii( pImplName ) )
358         {
359             xFactory = ::cppu::createSingleFactory(
360                 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
361                 ::svx::SvXMLGraphicImportHelper_getImplementationName(),
362                 ::svx::SvXMLGraphicImportHelper_createInstance,
363                 ::svx::SvXMLGraphicImportHelper_getSupportedServiceNames() );
364         }
365         else if( ::svx::SvXMLGraphicExportHelper_getImplementationName().equalsAscii( pImplName ) )
366         {
367             xFactory = ::cppu::createSingleFactory(
368                 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
369                 ::svx::SvXMLGraphicExportHelper_getImplementationName(),
370                 ::svx::SvXMLGraphicExportHelper_createInstance,
371                 ::svx::SvXMLGraphicExportHelper_getSupportedServiceNames() );
372         }
373 /*
374         else if( ::svx::ExtrusionDepthController_getImplementationName().equalsAscii( pImplName ) )
375         {
376             xFactory = ::cppu::createSingleFactory(
377                 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
378                 ::svx::ExtrusionDepthController_getImplementationName(),
379                 ::svx::ExtrusionDepthController_createInstance,
380                 ::svx::ExtrusionDepthController_getSupportedServiceNames() );
381         }
382 */
383         if( xFactory.is())
384         {
385             xFactory->acquire();
386             pRet = xFactory.get();
387         }
388     }
389 
390     return pRet;
391 }
392 
393 }
394