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