xref: /trunk/main/svx/source/unodraw/unoctabl.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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     XColorListSharedPtr     maTable;
48 
49 public:
50     SvxUnoColorTable() throw();
51     virtual ~SvxUnoColorTable() throw();
52 
53     // XServiceInfo
54     virtual OUString SAL_CALL getImplementationName(  );
55     virtual sal_Bool SAL_CALL supportsService( const  OUString& ServiceName );
56     virtual uno::Sequence<  OUString > SAL_CALL getSupportedServiceNames(  );
57 
getImplementationName_Static()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 );
67     virtual void SAL_CALL removeByName( const  OUString& Name );
68 
69     // XNameReplace
70     virtual void SAL_CALL replaceByName( const  OUString& aName, const  uno::Any& aElement );
71 
72     // XNameAccess
73     virtual uno::Any SAL_CALL getByName( const  OUString& aName );
74 
75     virtual uno::Sequence<  OUString > SAL_CALL getElementNames(  );
76 
77     virtual sal_Bool SAL_CALL hasByName( const  OUString& aName );
78 
79     // XElementAccess
80     virtual uno::Type SAL_CALL getElementType(  );
81     virtual sal_Bool SAL_CALL hasElements(  );
82 };
83 
SvxUnoColorTable()84 SvxUnoColorTable::SvxUnoColorTable() throw()
85 :   maTable(XPropertyListFactory::CreateSharedXColorList(SvtPathOptions().GetPalettePath()))
86 {
87 }
88 
~SvxUnoColorTable()89 SvxUnoColorTable::~SvxUnoColorTable() throw()
90 {
91 }
92 
supportsService(const OUString & ServiceName)93 sal_Bool SAL_CALL SvxUnoColorTable::supportsService( const  OUString& ServiceName )
94 {
95     uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
96     const OUString * pArray = aSNL.getConstArray();
97 
98     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
99         if( pArray[i] == ServiceName )
100             return sal_True;
101 
102     return sal_False;
103 }
104 
getImplementationName()105 OUString SAL_CALL SvxUnoColorTable::getImplementationName()
106 {
107     return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoColorTable") );
108 }
109 
getSupportedServiceNames()110 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getSupportedServiceNames(  )
111 {
112     return getSupportedServiceNames_Static();
113 }
114 
getSupportedServiceNames_Static(void)115 uno::Sequence< OUString > SvxUnoColorTable::getSupportedServiceNames_Static(void) throw()
116 {
117     uno::Sequence< OUString > aSNS( 1 );
118     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ColorTable" ));
119     return aSNS;
120 }
121 
122 // XNameContainer
insertByName(const OUString & aName,const uno::Any & aElement)123 void SAL_CALL SvxUnoColorTable::insertByName( const OUString& aName, const uno::Any& aElement )
124 {
125     if( hasByName( aName ) )
126         throw container::ElementExistException();
127 
128     sal_Int32 nColor = 0;
129     if( !(aElement >>= nColor) )
130         throw lang::IllegalArgumentException();
131 
132     XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName  );
133     maTable->Insert( pEntry, maTable->Count() );
134 }
135 
removeByName(const OUString & Name)136 void SAL_CALL SvxUnoColorTable::removeByName( const OUString& Name )
137 {
138     long nIndex = maTable->GetIndex(Name);
139     if( nIndex == -1 )
140         throw container::NoSuchElementException();
141 
142     maTable->Remove( nIndex );
143 }
144 
145 // XNameReplace
replaceByName(const OUString & aName,const uno::Any & aElement)146 void SAL_CALL SvxUnoColorTable::replaceByName( const OUString& aName, const uno::Any& aElement )
147 {
148     sal_Int32 nColor = 0;
149     if( !(aElement >>= nColor) )
150         throw lang::IllegalArgumentException();
151 
152     long nIndex = maTable->GetIndex(aName);
153     if( nIndex == -1  )
154         throw container::NoSuchElementException();
155 
156     XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName );
157     delete maTable->Replace( pEntry, nIndex );
158 }
159 
160 // XNameAccess
getByName(const OUString & aName)161 uno::Any SAL_CALL SvxUnoColorTable::getByName( const  OUString& aName )
162 {
163     long nIndex = maTable->GetIndex(aName);
164     if( nIndex == -1 )
165         throw container::NoSuchElementException();
166 
167     XColorEntry* pEntry = maTable->GetColor( nIndex );
168     return uno::Any( (sal_Int32) pEntry->GetColor().GetRGBColor() );
169 }
170 
getElementNames()171 uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getElementNames(  )
172 {
173     const long nCount = maTable->Count();
174 
175     uno::Sequence< OUString > aSeq( nCount );
176     OUString* pStrings = aSeq.getArray();
177 
178     for( long nIndex = 0; nIndex < nCount; nIndex++ )
179     {
180         XColorEntry* pEntry = maTable->GetColor( (long)nIndex );
181         pStrings[nIndex] = pEntry->GetName();
182     }
183 
184     return aSeq;
185 }
186 
hasByName(const OUString & aName)187 sal_Bool SAL_CALL SvxUnoColorTable::hasByName( const OUString& aName )
188 {
189     long nIndex = maTable->GetIndex( aName );
190     return nIndex != -1;
191 }
192 
193 // XElementAccess
getElementType()194 uno::Type SAL_CALL SvxUnoColorTable::getElementType(  )
195 {
196     return ::getCppuType((const sal_Int32*)0);
197 }
198 
hasElements()199 sal_Bool SAL_CALL SvxUnoColorTable::hasElements(  )
200 {
201     return maTable->Count() != 0;
202 }
203 
204 /**
205  * Create a colortable
206  */
SvxUnoColorTable_createInstance(const uno::Reference<lang::XMultiServiceFactory> &)207 uno::Reference< uno::XInterface > SAL_CALL SvxUnoColorTable_createInstance(const uno::Reference< lang::XMultiServiceFactory > & )
208 {
209     return *new SvxUnoColorTable();
210 }
create_EnhancedCustomShapeEngine(const uno::Reference<lang::XMultiServiceFactory> & rxFact)211 uno::Reference< uno::XInterface > SAL_CALL create_EnhancedCustomShapeEngine( const uno::Reference< lang::XMultiServiceFactory >& rxFact )
212 {
213     return *new EnhancedCustomShapeEngine( rxFact );
214 }
215 
216 //
217 // export this service
218 //
219 
220 #include "UnoGraphicExporter.hxx"
221 #include "unogalthemeprovider.hxx"
222 #include <com/sun/star/registry/XRegistryKey.hpp>
223 #include "sal/types.h"
224 #include "osl/diagnose.h"
225 #include "cppuhelper/factory.hxx"
226 #include "uno/lbnames.h"
227 #include <svx/sdr/primitive2d/primitiveFactory2d.hxx>
228 #include "sidebar/PanelFactory.hxx"
229 
230 
231 /*
232 namespace svx
233 {
234 extern OUString SAL_CALL ExtrusionDepthController_getImplementationName();
235 extern uno::Reference< uno::XInterface > SAL_CALL ExtrusionDepthController_createInstance(const uno::Reference< lang::XMultiServiceFactory > &)  throw( uno::RuntimeException );
236 extern uno::Sequence< OUString > SAL_CALL ExtrusionDepthController_getSupportedServiceNames() throw( uno::RuntimeException );
237 }
238 */
239 
240 extern "C"
241 {
242 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)243 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment (
244     const sal_Char ** ppEnvTypeName, uno_Environment ** )
245 {
246     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
247 }
248 
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)249 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory (
250     const sal_Char * pImplName, void * pServiceManager, void *  )
251 {
252     void * pRet = 0;
253     if( pServiceManager  )
254     {
255         uno::Reference< lang::XSingleServiceFactory > xFactory;
256 
257         if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxUnoColorTable" ) == 0 )
258         {
259             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
260                 SvxUnoColorTable::getImplementationName_Static(),
261                 SvxUnoColorTable_createInstance,
262                 SvxUnoColorTable::getSupportedServiceNames_Static() );
263         }
264         else if ( rtl_str_compare( pImplName, "com.sun.star.drawing.EnhancedCustomShapeEngine" ) == 0 )
265         {
266             xFactory = createSingleFactory( reinterpret_cast< NMSP_LANG::XMultiServiceFactory* >( pServiceManager ),
267                 EnhancedCustomShapeEngine_getImplementationName(),
268                 create_EnhancedCustomShapeEngine,
269                 EnhancedCustomShapeEngine_getSupportedServiceNames() );
270         }
271         else if( rtl_str_compare( pImplName, "com.sun.star.drawing.SvxShapeCollection" ) == 0 )
272         {
273             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
274                 SvxShapeCollection::getImplementationName_Static(),
275                 SvxShapeCollection_createInstance,
276                 SvxShapeCollection::getSupportedServiceNames_Static() );
277         }
278         else if( svx::RecoveryUI::st_getImplementationName().equalsAscii( pImplName ) )
279         {
280             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
281                 svx::RecoveryUI::st_getImplementationName(),
282                 svx::RecoveryUI::st_createInstance,
283                 svx::RecoveryUI::st_getSupportedServiceNames() );
284         }
285         else if( svx::GraphicExporter_getImplementationName().equalsAscii( pImplName ) )
286         {
287             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
288                 svx::GraphicExporter_getImplementationName(),
289                 svx::GraphicExporter_createInstance,
290                 svx::GraphicExporter_getSupportedServiceNames() );
291         }
292         else if ( svx::FontHeightToolBoxControl::getImplementationName_Static().equalsAscii( pImplName ) )
293         {
294             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
295                 svx::FontHeightToolBoxControl::getImplementationName_Static(),
296                 svx::FontHeightToolBoxControl_createInstance,
297                 svx::FontHeightToolBoxControl::getSupportedServiceNames_Static() );
298         }
299         else if ( svx::FindTextToolbarController::getImplementationName_Static().equalsAscii( pImplName ) )
300         {
301             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
302                 svx::FindTextToolbarController::getImplementationName_Static(),
303                 svx::FindTextToolbarController_createInstance,
304                 svx::FindTextToolbarController::getSupportedServiceNames_Static() );
305         }
306         else if ( svx::DownSearchToolboxController::getImplementationName_Static().equalsAscii( pImplName ) )
307         {
308             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
309                 svx::DownSearchToolboxController::getImplementationName_Static(),
310                 svx::DownSearchToolboxController_createInstance,
311                 svx::DownSearchToolboxController::getSupportedServiceNames_Static() );
312         }
313         else if ( svx::UpSearchToolboxController::getImplementationName_Static().equalsAscii( pImplName ) )
314         {
315             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
316                 svx::UpSearchToolboxController::getImplementationName_Static(),
317                 svx::UpSearchToolboxController_createInstance,
318                 svx::UpSearchToolboxController::getSupportedServiceNames_Static() );
319         }
320         else if ( svx::FindbarDispatcher::getImplementationName_Static().equalsAscii( pImplName ) )
321         {
322             xFactory = createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
323                 svx::FindbarDispatcher::getImplementationName_Static(),
324                 svx::FindbarDispatcher_createInstance,
325                 svx::FindbarDispatcher::getSupportedServiceNames_Static() );
326         }
327         else if( ::unogallery::GalleryThemeProvider_getImplementationName().equalsAscii( pImplName ) )
328         {
329             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
330                 ::unogallery::GalleryThemeProvider_getImplementationName(),
331                 ::unogallery::GalleryThemeProvider_createInstance,
332                 ::unogallery::GalleryThemeProvider_getSupportedServiceNames() );
333         }
334         else if( drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static().equalsAscii( pImplName ) )
335         {
336             // XPrimitiveFactory2D
337             xFactory = ::cppu::createSingleFactory( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
338                 drawinglayer::primitive2d::PrimitiveFactory2D::getImplementationName_Static(),
339                 drawinglayer::primitive2d::XPrimitiveFactory2DProvider_createInstance,
340                 drawinglayer::primitive2d::PrimitiveFactory2D::getSupportedServiceNames_Static() );
341         }
342         else if( ::svx::SvXMLGraphicImportHelper_getImplementationName().equalsAscii( pImplName ) )
343         {
344             xFactory = ::cppu::createSingleFactory(
345                 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
346                 ::svx::SvXMLGraphicImportHelper_getImplementationName(),
347                 ::svx::SvXMLGraphicImportHelper_createInstance,
348                 ::svx::SvXMLGraphicImportHelper_getSupportedServiceNames() );
349         }
350         else if( ::svx::SvXMLGraphicExportHelper_getImplementationName().equalsAscii( pImplName ) )
351         {
352             xFactory = ::cppu::createSingleFactory(
353                 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
354                 ::svx::SvXMLGraphicExportHelper_getImplementationName(),
355                 ::svx::SvXMLGraphicExportHelper_createInstance,
356                 ::svx::SvXMLGraphicExportHelper_getSupportedServiceNames() );
357         }
358         else if (::svx::sidebar::PanelFactory::getImplementationName().equalsAscii(pImplName))
359         {
360             xFactory = ::cppu::createSingleFactory(
361                 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
362                 ::svx::sidebar::PanelFactory::getImplementationName(),
363                 ::svx::sidebar::PanelFactory::createInstance,
364                 ::svx::sidebar::PanelFactory::getSupportedServiceNames());
365         }
366 
367         if( xFactory.is())
368         {
369             xFactory->acquire();
370             pRet = xFactory.get();
371         }
372     }
373 
374     return pRet;
375 }
376 
377 }
378