xref: /aoo41x/main/sc/source/ui/unoobj/servuno.cxx (revision cdf0e10c)
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_sc.hxx"
30 
31 #include <tools/debug.hxx>
32 #include <svtools/unoimap.hxx>
33 #include <svx/unofill.hxx>
34 #include <editeng/unonrule.hxx>
35 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
36 
37 #include "servuno.hxx"
38 #include "unoguard.hxx"
39 #include "unonames.hxx"
40 #include "cellsuno.hxx"
41 #include "fielduno.hxx"
42 #include "styleuno.hxx"
43 #include "afmtuno.hxx"
44 #include "defltuno.hxx"
45 #include "drdefuno.hxx"
46 #include "docsh.hxx"
47 #include "drwlayer.hxx"
48 #include "confuno.hxx"
49 #include "shapeuno.hxx"
50 #include "cellvaluebinding.hxx"
51 #include "celllistsource.hxx"
52 #include "addruno.hxx"
53 #include "chart2uno.hxx"
54 #include "tokenuno.hxx"
55 
56 // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
57 #include <svx/xmleohlp.hxx>
58 #include <svx/xmlgrhlp.hxx>
59 #include <sfx2/docfile.hxx>
60 #include <sfx2/docfilt.hxx>
61 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
62 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
63 #include <com/sun/star/document/XCodeNameQuery.hpp>
64 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
65 #include <com/sun/star/form/XFormsSupplier.hpp>
66 #include <svx/unomod.hxx>
67 #include <vbahelper/vbaaccesshelper.hxx>
68 
69 #include <comphelper/processfactory.hxx>
70 #include <basic/basmgr.hxx>
71 #include <sfx2/app.hxx>
72 
73 using namespace ::com::sun::star;
74 
75 class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
76 {
77     uno::Any maWorkbook;
78     uno::Any maCachedObject;
79     ScDocShell* mpDocShell;
80 public:
81     ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
82     {
83         ScDocument* pDoc = mpDocShell->GetDocument();
84         if ( !pDoc )
85             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
86 
87         uno::Sequence< uno::Any > aArgs(2);
88         // access the application object ( parent for workbook )
89         aArgs[0] = uno::Any( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", uno::Sequence< uno::Any >() ) );
90         aArgs[1] = uno::Any( mpDocShell->GetModel() );
91         maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
92     }
93 
94     virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
95     {
96         ScUnoGuard aGuard;
97         maCachedObject = uno::Any(); // clear cached object
98         String sName = aName;
99 
100         ScDocument* pDoc = mpDocShell->GetDocument();
101         if ( !pDoc )
102             throw uno::RuntimeException();
103         if ( sName == pDoc->GetCodeName() )
104             maCachedObject = maWorkbook;
105         else
106         {
107             String sCodeName;
108             SCTAB nCount = pDoc->GetTableCount();
109             for( SCTAB i = 0; i < nCount; i++ )
110             {
111                 pDoc->GetCodeName( i, sCodeName );
112                 if( sCodeName == sName )
113                 {
114                     String sSheetName;
115                     if( pDoc->GetName( i, sSheetName ) )
116                     {
117                         uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
118                         uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
119                         uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
120                         uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
121                         uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
122                         uno::Sequence< uno::Any > aArgs(3);
123                         aArgs[0] = maWorkbook;
124                         aArgs[1] = uno::Any( xModel );
125                         aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
126                         // use the convience function
127                         maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
128                         break;
129                     }
130                 }
131             }
132         }
133         return maCachedObject.hasValue();
134 
135     }
136     ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
137     {
138         ScUnoGuard aGuard;
139         OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
140             rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
141         if ( !hasByName( aName ) )
142             throw ::com::sun::star::container::NoSuchElementException();
143         return maCachedObject;
144     }
145     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (::com::sun::star::uno::RuntimeException)
146     {
147         ScUnoGuard aGuard;
148         ScDocument* pDoc = mpDocShell->GetDocument();
149         if ( !pDoc )
150             throw uno::RuntimeException();
151         SCTAB nCount = pDoc->GetTableCount();
152         uno::Sequence< rtl::OUString > aNames( nCount + 1 );
153         SCTAB index = 0;
154         String sCodeName;
155         for( ; index < nCount; ++index )
156         {
157             pDoc->GetCodeName( index, sCodeName );
158             aNames[ index ] = sCodeName;
159         }
160         aNames[ index ] = pDoc->GetCodeName();
161         return aNames;
162     }
163     // XElemenAccess
164     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
165     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
166 
167 };
168 
169 class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
170 {
171 ScDocShell* mpDocShell;
172 public:
173     ScVbaCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell ) {}
174     // XCodeNameQuery
175     rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
176     {
177         ScUnoGuard aGuard;
178         rtl::OUString sCodeName;
179         if ( mpDocShell )
180         {
181             OSL_TRACE( "*** In ScVbaCodeNameProvider::getCodeNameForObject");
182             // need to find the page ( and index )  for this control
183             uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mpDocShell->GetModel(), uno::UNO_QUERY_THROW );
184             uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
185             sal_Int32 nLen = xIndex->getCount();
186             bool bMatched = false;
187             uno::Sequence< script::ScriptEventDescriptor > aFakeEvents;
188             for ( sal_Int32 index = 0; index < nLen; ++index )
189             {
190                 try
191                 {
192                     uno::Reference< form::XFormsSupplier >  xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
193                     uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
194                     // get the www-standard container
195                     uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
196                     sal_Int32 nCntrls = xFormControls->getCount();
197                     for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
198                     {
199                         uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
200                         bMatched = ( xControl == xIf );
201                         if ( bMatched )
202                         {
203                             String sName;
204                             mpDocShell->GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
205                             sCodeName = sName;
206                         }
207                     }
208                 }
209                 catch( uno::Exception& ) {}
210                 if ( bMatched )
211                     break;
212             }
213         }
214         // Probably should throw here ( if !bMatched )
215          return sCodeName;
216     }
217 
218 };
219 
220 //------------------------------------------------------------------------
221 //
222 struct ProvNamesId_Type
223 {
224     const char *    pName;
225     sal_uInt16      nType;
226 };
227 
228 static const ProvNamesId_Type __FAR_DATA aProvNamesId[] =
229 {
230     { "com.sun.star.sheet.Spreadsheet",                 SC_SERVICE_SHEET },
231     { "com.sun.star.text.TextField.URL",                SC_SERVICE_URLFIELD },
232     { "com.sun.star.text.TextField.PageNumber",         SC_SERVICE_PAGEFIELD },
233     { "com.sun.star.text.TextField.PageCount",          SC_SERVICE_PAGESFIELD },
234     { "com.sun.star.text.TextField.Date",               SC_SERVICE_DATEFIELD },
235     { "com.sun.star.text.TextField.Time",               SC_SERVICE_TIMEFIELD },
236     { "com.sun.star.text.TextField.DocumentTitle",      SC_SERVICE_TITLEFIELD },
237     { "com.sun.star.text.TextField.FileName",           SC_SERVICE_FILEFIELD },
238     { "com.sun.star.text.TextField.SheetName",          SC_SERVICE_SHEETFIELD },
239     { "com.sun.star.style.CellStyle",                   SC_SERVICE_CELLSTYLE },
240     { "com.sun.star.style.PageStyle",                   SC_SERVICE_PAGESTYLE },
241     { "com.sun.star.sheet.TableAutoFormat",             SC_SERVICE_AUTOFORMAT },
242     { "com.sun.star.sheet.SheetCellRanges",             SC_SERVICE_CELLRANGES },
243     { "com.sun.star.drawing.GradientTable",             SC_SERVICE_GRADTAB },
244     { "com.sun.star.drawing.HatchTable",                SC_SERVICE_HATCHTAB },
245     { "com.sun.star.drawing.BitmapTable",               SC_SERVICE_BITMAPTAB },
246     { "com.sun.star.drawing.TransparencyGradientTable", SC_SERVICE_TRGRADTAB },
247     { "com.sun.star.drawing.MarkerTable",               SC_SERVICE_MARKERTAB },
248     { "com.sun.star.drawing.DashTable",                 SC_SERVICE_DASHTAB },
249     { "com.sun.star.text.NumberingRules",               SC_SERVICE_NUMRULES },
250     { "com.sun.star.sheet.Defaults",                    SC_SERVICE_DOCDEFLTS },
251     { "com.sun.star.drawing.Defaults",                  SC_SERVICE_DRAWDEFLTS },
252     { "com.sun.star.comp.SpreadsheetSettings",          SC_SERVICE_DOCSPRSETT },
253     { "com.sun.star.document.Settings",                 SC_SERVICE_DOCCONF },
254     { "com.sun.star.image.ImageMapRectangleObject",     SC_SERVICE_IMAP_RECT },
255     { "com.sun.star.image.ImageMapCircleObject",        SC_SERVICE_IMAP_CIRC },
256     { "com.sun.star.image.ImageMapPolygonObject",       SC_SERVICE_IMAP_POLY },
257 
258 		// #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
259     { "com.sun.star.document.ExportGraphicObjectResolver",  SC_SERVICE_EXPORT_GOR },
260     { "com.sun.star.document.ImportGraphicObjectResolver",  SC_SERVICE_IMPORT_GOR },
261     { "com.sun.star.document.ExportEmbeddedObjectResolver", SC_SERVICE_EXPORT_EOR },
262     { "com.sun.star.document.ImportEmbeddedObjectResolver", SC_SERVICE_IMPORT_EOR },
263 
264     { SC_SERVICENAME_VALBIND,               SC_SERVICE_VALBIND },
265     { SC_SERVICENAME_LISTCELLBIND,          SC_SERVICE_LISTCELLBIND },
266     { SC_SERVICENAME_LISTSOURCE,            SC_SERVICE_LISTSOURCE },
267     { SC_SERVICENAME_CELLADDRESS,           SC_SERVICE_CELLADDRESS },
268     { SC_SERVICENAME_RANGEADDRESS,          SC_SERVICE_RANGEADDRESS },
269 
270     { "com.sun.star.sheet.DocumentSettings",SC_SERVICE_SHEETDOCSET },
271 
272     { SC_SERVICENAME_CHDATAPROV,            SC_SERVICE_CHDATAPROV },
273     { SC_SERVICENAME_FORMULAPARS,           SC_SERVICE_FORMULAPARS },
274     { SC_SERVICENAME_OPCODEMAPPER,          SC_SERVICE_OPCODEMAPPER },
275     { "ooo.vba.VBAObjectModuleObjectProvider", SC_SERVICE_VBAOBJECTPROVIDER },
276     { "ooo.vba.VBACodeNameProvider",        SC_SERVICE_VBACODENAMEPROVIDER },
277     { "ooo.vba.VBAGlobals",                 SC_SERVICE_VBAGLOBALS },
278 
279     // case-correct versions of the service names (#i102468#)
280     { "com.sun.star.text.textfield.URL",                SC_SERVICE_URLFIELD },
281     { "com.sun.star.text.textfield.PageNumber",         SC_SERVICE_PAGEFIELD },
282     { "com.sun.star.text.textfield.PageCount",          SC_SERVICE_PAGESFIELD },
283     { "com.sun.star.text.textfield.Date",               SC_SERVICE_DATEFIELD },
284     { "com.sun.star.text.textfield.Time",               SC_SERVICE_TIMEFIELD },
285     { "com.sun.star.text.textfield.DocumentTitle",      SC_SERVICE_TITLEFIELD },
286     { "com.sun.star.text.textfield.FileName",           SC_SERVICE_FILEFIELD },
287     { "com.sun.star.text.textfield.SheetName",          SC_SERVICE_SHEETFIELD }
288 };
289 
290 //
291 //	old service names that were in 567 still work in createInstance,
292 //	in case some macro is still using them
293 //
294 
295 static const sal_Char* __FAR_DATA aOldNames[SC_SERVICE_COUNT] =
296 	{
297 		"",											// SC_SERVICE_SHEET
298 		"stardiv.one.text.TextField.URL",			// SC_SERVICE_URLFIELD
299 		"stardiv.one.text.TextField.PageNumber",	// SC_SERVICE_PAGEFIELD
300 		"stardiv.one.text.TextField.PageCount",		// SC_SERVICE_PAGESFIELD
301 		"stardiv.one.text.TextField.Date",			// SC_SERVICE_DATEFIELD
302 		"stardiv.one.text.TextField.Time",			// SC_SERVICE_TIMEFIELD
303 		"stardiv.one.text.TextField.DocumentTitle",	// SC_SERVICE_TITLEFIELD
304 		"stardiv.one.text.TextField.FileName",		// SC_SERVICE_FILEFIELD
305 		"stardiv.one.text.TextField.SheetName",		// SC_SERVICE_SHEETFIELD
306 		"stardiv.one.style.CellStyle",				// SC_SERVICE_CELLSTYLE
307 		"stardiv.one.style.PageStyle",				// SC_SERVICE_PAGESTYLE
308 		"",											// SC_SERVICE_AUTOFORMAT
309 		"",											// SC_SERVICE_CELLRANGES
310 		"",											// SC_SERVICE_GRADTAB
311 		"",											// SC_SERVICE_HATCHTAB
312 		"",											// SC_SERVICE_BITMAPTAB
313 		"",											// SC_SERVICE_TRGRADTAB
314 		"",											// SC_SERVICE_MARKERTAB
315 		"",											// SC_SERVICE_DASHTAB
316 		"",											// SC_SERVICE_NUMRULES
317 		"",											// SC_SERVICE_DOCDEFLTS
318 		"",											// SC_SERVICE_DRAWDEFLTS
319 		"",											// SC_SERVICE_DOCSPRSETT
320 		"",											// SC_SERVICE_DOCCONF
321 		"",											// SC_SERVICE_IMAP_RECT
322 		"",											// SC_SERVICE_IMAP_CIRC
323 		"",											// SC_SERVICE_IMAP_POLY
324 
325 		// #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
326 		"",											// SC_SERVICE_EXPORT_GOR
327 		"",											// SC_SERVICE_IMPORT_GOR
328 		"",											// SC_SERVICE_EXPORT_EOR
329 		"",											// SC_SERVICE_IMPORT_EOR
330 
331 		"",											// SC_SERVICE_VALBIND
332 		"",											// SC_SERVICE_LISTCELLBIND
333 		"",											// SC_SERVICE_LISTSOURCE
334 		"",											// SC_SERVICE_CELLADDRESS
335 		"",											// SC_SERVICE_RANGEADDRESS
336         "",                                         // SC_SERVICE_SHEETDOCSET
337         "",                                         // SC_SERVICE_CHDATAPROV
338         "",                                         // SC_SERVICE_FORMULAPARS
339         "",                                         // SC_SERVICE_OPCODEMAPPER
340         "",                                         // SC_SERVICE_VBAOBJECTPROVIDER
341         "",                                         // SC_SERVICE_VBACODENAMEPROVIDER
342         "",                                         // SC_SERVICE_VBAGLOBALS
343 	};
344 
345 
346 
347 
348 //------------------------------------------------------------------------
349 
350 //	alles static
351 
352 //UNUSED2008-05  String ScServiceProvider::GetProviderName(sal_uInt16 nObjectType)
353 //UNUSED2008-05  {
354 //UNUSED2008-05      String sRet;
355 //UNUSED2008-05      if (nObjectType < SC_SERVICE_COUNT)
356 //UNUSED2008-05          sRet = String::CreateFromAscii( aProvNames[nObjectType] );
357 //UNUSED2008-05      return sRet;
358 //UNUSED2008-05  }
359 
360 sal_uInt16 ScServiceProvider::GetProviderType(const String& rServiceName)
361 {
362 	if (rServiceName.Len())
363 	{
364         const sal_uInt16 nEntries =
365             sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
366         for (sal_uInt16 i = 0; i < nEntries; i++)
367         {
368             if (rServiceName.EqualsAscii( aProvNamesId[i].pName ))
369             {
370                 return aProvNamesId[i].nType;
371             }
372         }
373 
374 		sal_uInt16 i;
375 		for (i=0; i<SC_SERVICE_COUNT; i++)
376         {
377             DBG_ASSERT( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
378 			if (rServiceName.EqualsAscii( aOldNames[i] ))
379 			{
380 				DBG_ERROR("old service name used");
381 				return i;
382 			}
383         }
384 	}
385 	return SC_SERVICE_INVALID;
386 }
387 
388 uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
389 									sal_uInt16 nType, ScDocShell* pDocShell )
390 {
391 	uno::Reference<uno::XInterface> xRet;
392 	switch (nType)
393 	{
394 		case SC_SERVICE_SHEET:
395 			//	noch nicht eingefuegt - DocShell=Null
396 			xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
397 			break;
398 		case SC_SERVICE_URLFIELD:
399 			xRet.set((text::XTextField*)new ScCellFieldObj( NULL, ScAddress(), ESelection() ));
400 			break;
401 		case SC_SERVICE_PAGEFIELD:
402 		case SC_SERVICE_PAGESFIELD:
403 		case SC_SERVICE_DATEFIELD:
404 		case SC_SERVICE_TIMEFIELD:
405 		case SC_SERVICE_TITLEFIELD:
406 		case SC_SERVICE_FILEFIELD:
407 		case SC_SERVICE_SHEETFIELD:
408 			xRet.set((text::XTextField*)new ScHeaderFieldObj( NULL, 0, nType, ESelection() ));
409 			break;
410 		case SC_SERVICE_CELLSTYLE:
411 			xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, String() ));
412 			break;
413 		case SC_SERVICE_PAGESTYLE:
414 			xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, String() ));
415 			break;
416 		case SC_SERVICE_AUTOFORMAT:
417 			xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
418 			break;
419 		case SC_SERVICE_CELLRANGES:
420 			//	wird nicht eingefuegt, sondern gefuellt
421 			//	-> DocShell muss gesetzt sein, aber leere Ranges
422 			if (pDocShell)
423 				xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
424 			break;
425 
426 		case SC_SERVICE_DOCDEFLTS:
427 			if (pDocShell)
428 				xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
429 			break;
430 		case SC_SERVICE_DRAWDEFLTS:
431 			if (pDocShell)
432 				xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
433 			break;
434 
435 		//	Drawing layer tables are not in SvxUnoDrawMSFactory,
436 		//	because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
437 		//	Drawing layer is always allocated if not there (MakeDrawLayer).
438 
439 		case SC_SERVICE_GRADTAB:
440 			if (pDocShell)
441 				xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
442 			break;
443 		case SC_SERVICE_HATCHTAB:
444 			if (pDocShell)
445 				xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
446 			break;
447 		case SC_SERVICE_BITMAPTAB:
448 			if (pDocShell)
449 				xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
450 			break;
451 		case SC_SERVICE_TRGRADTAB:
452 			if (pDocShell)
453 				xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
454 			break;
455 		case SC_SERVICE_MARKERTAB:
456 			if (pDocShell)
457 				xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
458 			break;
459 		case SC_SERVICE_DASHTAB:
460 			if (pDocShell)
461 				xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
462 			break;
463 		case SC_SERVICE_NUMRULES:
464 			if (pDocShell)
465 				xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
466 			break;
467 		case SC_SERVICE_DOCSPRSETT:
468         case SC_SERVICE_SHEETDOCSET:
469 		case SC_SERVICE_DOCCONF:
470 			if (pDocShell)
471 				xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
472 			break;
473 
474 		case SC_SERVICE_IMAP_RECT:
475 			xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
476 			break;
477 		case SC_SERVICE_IMAP_CIRC:
478 			xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
479 			break;
480 		case SC_SERVICE_IMAP_POLY:
481 			xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
482 			break;
483 
484 		// #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
485 		case SC_SERVICE_EXPORT_GOR:
486 			xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
487 			break;
488 
489 		case SC_SERVICE_IMPORT_GOR:
490 			xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
491 			break;
492 
493 		case SC_SERVICE_EXPORT_EOR:
494 			if (pDocShell)
495 				xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
496 			break;
497 
498 		case SC_SERVICE_IMPORT_EOR:
499 			if (pDocShell)
500 				xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
501 			break;
502 
503 		case SC_SERVICE_VALBIND:
504 		case SC_SERVICE_LISTCELLBIND:
505 			if (pDocShell)
506 			{
507 				sal_Bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
508 				uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
509 				xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
510 			}
511 			break;
512 		case SC_SERVICE_LISTSOURCE:
513 			if (pDocShell)
514 			{
515 				uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
516 				xRet.set(*new calc::OCellListSource( xDoc ));
517 			}
518 			break;
519 		case SC_SERVICE_CELLADDRESS:
520 		case SC_SERVICE_RANGEADDRESS:
521 			if (pDocShell)
522 			{
523 				sal_Bool bRange = ( nType == SC_SERVICE_RANGEADDRESS );
524 				xRet.set(*new ScAddressConversionObj( pDocShell, bRange ));
525 			}
526 			break;
527 
528         case SC_SERVICE_CHDATAPROV:
529             if (pDocShell && pDocShell->GetDocument())
530                 xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
531             break;
532 
533         case SC_SERVICE_FORMULAPARS:
534             if (pDocShell)
535                 xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
536             break;
537 
538         case SC_SERVICE_OPCODEMAPPER:
539 			if (pDocShell)
540             {
541                 ScDocument* pDoc = pDocShell->GetDocument();
542                 ScAddress aAddress;
543                 ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
544                 pComp->SetGrammar( pDoc->GetGrammar() );
545                 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
546 				break;
547             }
548         case SC_SERVICE_VBAOBJECTPROVIDER:
549 			if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
550             {
551                 OSL_TRACE("**** creating VBA Object mapper");
552                 xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
553             }
554             break;
555         case SC_SERVICE_VBACODENAMEPROVIDER:
556             if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
557             {
558                 OSL_TRACE("**** creating VBA Object provider");
559 				xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider( pDocShell )));
560 			}
561 			break;
562         case SC_SERVICE_VBAGLOBALS:
563 			if (pDocShell)
564 			{
565                 uno::Any aGlobs;
566 				if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
567 				{
568 					uno::Sequence< uno::Any > aArgs(1);
569 					aArgs[ 0 ] <<= pDocShell->GetModel();
570 					xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs );
571 					pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
572 					BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
573 					if ( pAppMgr )
574 						pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
575 
576                     // create the VBA document event processor
577                     uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
578                         ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
579                     pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents );
580 				}
581 			}
582         break;
583 	}
584 
585 	return xRet;
586 }
587 
588 uno::Sequence<rtl::OUString> ScServiceProvider::GetAllServiceNames()
589 {
590     const sal_uInt16 nEntries = sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
591     uno::Sequence<rtl::OUString> aRet(nEntries);
592 	rtl::OUString* pArray = aRet.getArray();
593     for (sal_uInt16 i = 0; i < nEntries; i++)
594     {
595         pArray[i] = rtl::OUString::createFromAscii( aProvNamesId[i].pName );
596     }
597 	return aRet;
598 }
599 
600 
601 
602 
603