sync master with lastest vba changes
[ooovba.git] / sc / source / ui / unoobj / servuno.cxx
blobed2775de058351f40b770940aa3361a4a14adee5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: servuno.cxx,v $
10 * $Revision: 1.17.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <tools/debug.hxx>
37 #include <svtools/unoimap.hxx>
38 #include <svx/unofill.hxx>
39 #include <svx/unonrule.hxx>
40 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
41 #include <com/sun/star/container/XNameAccess.hpp>
43 #include "servuno.hxx"
44 #include "unonames.hxx"
45 #include "cellsuno.hxx"
46 #include "fielduno.hxx"
47 #include "styleuno.hxx"
48 #include "afmtuno.hxx"
49 #include "defltuno.hxx"
50 #include "drdefuno.hxx"
51 #include "docsh.hxx"
52 #include "drwlayer.hxx"
53 #include "confuno.hxx"
54 #include "shapeuno.hxx"
55 #include "cellvaluebinding.hxx"
56 #include "celllistsource.hxx"
57 #include "addruno.hxx"
58 #include "chart2uno.hxx"
59 #include "tokenuno.hxx"
61 // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
62 #include <svx/xmleohlp.hxx>
63 #include <svx/xmlgrhlp.hxx>
65 #include <comphelper/processfactory.hxx>
66 #include <com/sun/star/document/XCodeNameQuery.hpp>
67 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
68 #include <com/sun/star/form/XFormsSupplier.hpp>
69 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
70 #include <comphelper/componentcontext.hxx>
71 #include <cppuhelper/component_context.hxx>
72 #include <vbahelper/vbahelper.hxx>
73 using namespace ::com::sun::star;
75 class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
77 uno::Any maWorkbook;
78 uno::Any maCachedObject;
79 ScDocShell* mpDocShell;
80 public:
81 ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
83 ScDocument* pDoc = mpDocShell->GetDocument();
84 if ( !pDoc )
85 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
87 uno::Sequence< uno::Any > aArgs(2);
88 aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() );
89 aArgs[1] = uno::Any( mpDocShell->GetModel() );
90 maWorkbook <<= ov::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
93 virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
95 maCachedObject = uno::Any(); // clear cached object
96 String sName = aName;
97 ScDocument* pDoc = mpDocShell->GetDocument();
98 if ( !pDoc )
99 throw uno::RuntimeException();
100 if ( sName == pDoc->GetCodeName() )
101 maCachedObject = maWorkbook;
102 else
104 String sCodeName;
105 SCTAB nCount = pDoc->GetTableCount();
106 for( SCTAB i = 0; i < nCount; i++ )
108 pDoc->GetCodeName( i, sCodeName );
109 if( sCodeName == sName )
111 String sSheetName;
112 if( pDoc->GetName( i, sSheetName ) )
114 uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
115 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
116 uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
117 uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
118 uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
119 uno::Sequence< uno::Any > aArgs(3);
120 aArgs[0] = maWorkbook;
121 aArgs[1] = uno::Any( xModel );
122 aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
123 maCachedObject <<= ov::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
124 break;
129 return maCachedObject.hasValue();
132 ::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)
134 OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
135 rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
136 if ( !hasByName( aName ) )
137 throw ::com::sun::star::container::NoSuchElementException();
138 return maCachedObject;
140 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException)
142 ScDocument* pDoc = mpDocShell->GetDocument();
143 if ( !pDoc )
144 throw uno::RuntimeException();
145 SCTAB nCount = pDoc->GetTableCount();
146 uno::Sequence< rtl::OUString > aNames( nCount + 1 );
147 SCTAB index = 0;
148 String sCodeName;
149 for( ; index < nCount; ++index )
151 pDoc->GetCodeName( index, sCodeName );
152 aNames[ index ] = sCodeName;
154 aNames[ index ] = pDoc->GetCodeName();
155 return aNames;
157 // XElemenAccess
158 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
159 virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
163 class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
165 ScDocShell* mpDocShell;
166 public:
167 ScVbaCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell ) {}
168 // XCodeNameQuery
169 rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
171 rtl::OUString sCodeName;
172 if ( mpDocShell )
174 OSL_TRACE( "*** In ScVbaCodeNameProvider::getCodeNameForObject");
175 // need to find the page ( and index ) for this control
176 uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mpDocShell->GetModel(), uno::UNO_QUERY_THROW );
177 uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
178 sal_Int32 nLen = xIndex->getCount();
179 bool bMatched = false;
180 uno::Sequence< script::ScriptEventDescriptor > aFakeEvents;
181 for ( sal_Int32 index = 0; index < nLen; ++index )
185 uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
186 uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
187 // get the www-standard container
188 uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
189 sal_Int32 nCntrls = xFormControls->getCount();
190 for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
192 uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
193 bMatched = ( xControl == xIf );
194 if ( bMatched )
196 String sName;
197 mpDocShell->GetDocument()->GetCodeName( index, sName );
198 sCodeName = sName;
202 catch( uno::Exception& ) {}
203 if ( bMatched )
204 break;
207 // Probably should throw here ( if !bMatched )
208 return sCodeName;
213 //------------------------------------------------------------------------
215 static const sal_Char* __FAR_DATA aProvNames[SC_SERVICE_COUNT] =
217 "com.sun.star.sheet.Spreadsheet", // SC_SERVICE_SHEET
218 "com.sun.star.text.TextField.URL", // SC_SERVICE_URLFIELD
219 "com.sun.star.text.TextField.PageNumber", // SC_SERVICE_PAGEFIELD
220 "com.sun.star.text.TextField.PageCount", // SC_SERVICE_PAGESFIELD
221 "com.sun.star.text.TextField.Date", // SC_SERVICE_DATEFIELD
222 "com.sun.star.text.TextField.Time", // SC_SERVICE_TIMEFIELD
223 "com.sun.star.text.TextField.DocumentTitle",// SC_SERVICE_TITLEFIELD
224 "com.sun.star.text.TextField.FileName", // SC_SERVICE_FILEFIELD
225 "com.sun.star.text.TextField.SheetName", // SC_SERVICE_SHEETFIELD
226 "com.sun.star.style.CellStyle", // SC_SERVICE_CELLSTYLE
227 "com.sun.star.style.PageStyle", // SC_SERVICE_PAGESTYLE
228 "com.sun.star.sheet.TableAutoFormat", // SC_SERVICE_AUTOFORMAT
229 "com.sun.star.sheet.SheetCellRanges", // SC_SERVICE_CELLRANGES
230 "com.sun.star.drawing.GradientTable", // SC_SERVICE_GRADTAB
231 "com.sun.star.drawing.HatchTable", // SC_SERVICE_HATCHTAB
232 "com.sun.star.drawing.BitmapTable", // SC_SERVICE_BITMAPTAB
233 "com.sun.star.drawing.TransparencyGradientTable", // SC_SERVICE_TRGRADTAB
234 "com.sun.star.drawing.MarkerTable", // SC_SERVICE_MARKERTAB
235 "com.sun.star.drawing.DashTable", // SC_SERVICE_DASHTAB
236 "com.sun.star.text.NumberingRules", // SC_SERVICE_NUMRULES
237 "com.sun.star.sheet.Defaults", // SC_SERVICE_DOCDEFLTS
238 "com.sun.star.drawing.Defaults", // SC_SERVICE_DRAWDEFLTS
239 "com.sun.star.comp.SpreadsheetSettings", // SC_SERVICE_DOCSPRSETT
240 "com.sun.star.document.Settings", // SC_SERVICE_DOCCONF
241 "com.sun.star.image.ImageMapRectangleObject",// SC_SERVICE_IMAP_RECT
242 "com.sun.star.image.ImageMapCircleObject", // SC_SERVICE_IMAP_CIRC
243 "com.sun.star.image.ImageMapPolygonObject", // SC_SERVICE_IMAP_POLY
245 // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
246 "com.sun.star.document.ExportGraphicObjectResolver", // SC_SERVICE_EXPORT_GOR
247 "com.sun.star.document.ImportGraphicObjectResolver", // SC_SERVICE_IMPORT_GOR
248 "com.sun.star.document.ExportEmbeddedObjectResolver", // SC_SERVICE_EXPORT_EOR
249 "com.sun.star.document.ImportEmbeddedObjectResolver", // SC_SERVICE_IMPORT_EOR
251 SC_SERVICENAME_VALBIND, // SC_SERVICE_VALBIND
252 SC_SERVICENAME_LISTCELLBIND, // SC_SERVICE_LISTCELLBIND
253 SC_SERVICENAME_LISTSOURCE, // SC_SERVICE_LISTSOURCE
254 SC_SERVICENAME_CELLADDRESS, // SC_SERVICE_CELLADDRESS
255 SC_SERVICENAME_RANGEADDRESS, // SC_SERVICE_RANGEADDRESS
257 "com.sun.star.sheet.DocumentSettings", // SC_SERVICE_SHEETDOCSET
259 SC_SERVICENAME_CHDATAPROV, // SC_SERVICE_CHDATAPROV
260 SC_SERVICENAME_FORMULAPARS, // SC_SERVICE_FORMULAPARS
261 SC_SERVICENAME_OPCODEMAPPER, // SC_SERVICE_OPCODEMAPPER
262 "ooo.vba.VBAObjectModuleObjectProvider",// SC_SERVICE_VBAOBJECTPROVIDER
263 "ooo.vba.VBACodeNameProvider",// SC_SERVICE_VBACODENAMEPROVIDER
267 // old service names that were in 567 still work in createInstance,
268 // in case some macro is still using them
271 static const sal_Char* __FAR_DATA aOldNames[SC_SERVICE_COUNT] =
273 "", // SC_SERVICE_SHEET
274 "stardiv.one.text.TextField.URL", // SC_SERVICE_URLFIELD
275 "stardiv.one.text.TextField.PageNumber", // SC_SERVICE_PAGEFIELD
276 "stardiv.one.text.TextField.PageCount", // SC_SERVICE_PAGESFIELD
277 "stardiv.one.text.TextField.Date", // SC_SERVICE_DATEFIELD
278 "stardiv.one.text.TextField.Time", // SC_SERVICE_TIMEFIELD
279 "stardiv.one.text.TextField.DocumentTitle", // SC_SERVICE_TITLEFIELD
280 "stardiv.one.text.TextField.FileName", // SC_SERVICE_FILEFIELD
281 "stardiv.one.text.TextField.SheetName", // SC_SERVICE_SHEETFIELD
282 "stardiv.one.style.CellStyle", // SC_SERVICE_CELLSTYLE
283 "stardiv.one.style.PageStyle", // SC_SERVICE_PAGESTYLE
284 "", // SC_SERVICE_AUTOFORMAT
285 "", // SC_SERVICE_CELLRANGES
286 "", // SC_SERVICE_GRADTAB
287 "", // SC_SERVICE_HATCHTAB
288 "", // SC_SERVICE_BITMAPTAB
289 "", // SC_SERVICE_TRGRADTAB
290 "", // SC_SERVICE_MARKERTAB
291 "", // SC_SERVICE_DASHTAB
292 "", // SC_SERVICE_NUMRULES
293 "", // SC_SERVICE_DOCDEFLTS
294 "", // SC_SERVICE_DRAWDEFLTS
295 "", // SC_SERVICE_DOCSPRSETT
296 "", // SC_SERVICE_DOCCONF
297 "", // SC_SERVICE_IMAP_RECT
298 "", // SC_SERVICE_IMAP_CIRC
299 "", // SC_SERVICE_IMAP_POLY
301 // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
302 "", // SC_SERVICE_EXPORT_GOR
303 "", // SC_SERVICE_IMPORT_GOR
304 "", // SC_SERVICE_EXPORT_EOR
305 "", // SC_SERVICE_IMPORT_EOR
307 "", // SC_SERVICE_VALBIND
308 "", // SC_SERVICE_LISTCELLBIND
309 "", // SC_SERVICE_LISTSOURCE
310 "", // SC_SERVICE_CELLADDRESS
311 "", // SC_SERVICE_RANGEADDRESS
312 "", // SC_SERVICE_SHEETDOCSET
313 "", // SC_SERVICE_CHDATAPROV
314 "", // SC_SERVICE_FORMULAPARS
315 "", // SC_SERVICE_OPCODEMAPPER
316 "", // SC_SERVICE_VBAOBJECTPROVIDER
317 "", // SC_SERVICE_VBACODENAMEPROVIDER
323 //------------------------------------------------------------------------
325 // alles static
327 //UNUSED2008-05 String ScServiceProvider::GetProviderName(sal_uInt16 nObjectType)
328 //UNUSED2008-05 {
329 //UNUSED2008-05 String sRet;
330 //UNUSED2008-05 if (nObjectType < SC_SERVICE_COUNT)
331 //UNUSED2008-05 sRet = String::CreateFromAscii( aProvNames[nObjectType] );
332 //UNUSED2008-05 return sRet;
333 //UNUSED2008-05 }
335 sal_uInt16 ScServiceProvider::GetProviderType(const String& rServiceName)
337 if (rServiceName.Len())
339 USHORT i;
340 for (i=0; i<SC_SERVICE_COUNT; i++)
341 if (rServiceName.EqualsAscii( aProvNames[i] ))
342 return i;
344 for (i=0; i<SC_SERVICE_COUNT; i++)
346 DBG_ASSERT( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
347 if (rServiceName.EqualsAscii( aOldNames[i] ))
349 DBG_ERROR("old service name used");
350 return i;
354 return SC_SERVICE_INVALID;
357 uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
358 sal_uInt16 nType, ScDocShell* pDocShell )
360 uno::Reference<uno::XInterface> xRet;
361 switch (nType)
363 case SC_SERVICE_SHEET:
364 // noch nicht eingefuegt - DocShell=Null
365 xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
366 break;
367 case SC_SERVICE_URLFIELD:
368 xRet.set((text::XTextField*)new ScCellFieldObj( NULL, ScAddress(), ESelection() ));
369 break;
370 case SC_SERVICE_PAGEFIELD:
371 case SC_SERVICE_PAGESFIELD:
372 case SC_SERVICE_DATEFIELD:
373 case SC_SERVICE_TIMEFIELD:
374 case SC_SERVICE_TITLEFIELD:
375 case SC_SERVICE_FILEFIELD:
376 case SC_SERVICE_SHEETFIELD:
377 xRet.set((text::XTextField*)new ScHeaderFieldObj( NULL, 0, nType, ESelection() ));
378 break;
379 case SC_SERVICE_CELLSTYLE:
380 xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, String() ));
381 break;
382 case SC_SERVICE_PAGESTYLE:
383 xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, String() ));
384 break;
385 case SC_SERVICE_AUTOFORMAT:
386 xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
387 break;
388 case SC_SERVICE_CELLRANGES:
389 // wird nicht eingefuegt, sondern gefuellt
390 // -> DocShell muss gesetzt sein, aber leere Ranges
391 if (pDocShell)
392 xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
393 break;
395 case SC_SERVICE_DOCDEFLTS:
396 if (pDocShell)
397 xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
398 break;
399 case SC_SERVICE_DRAWDEFLTS:
400 if (pDocShell)
401 xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
402 break;
404 // Drawing layer tables are not in SvxUnoDrawMSFactory,
405 // because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
406 // Drawing layer is always allocated if not there (MakeDrawLayer).
408 case SC_SERVICE_GRADTAB:
409 if (pDocShell)
410 xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
411 break;
412 case SC_SERVICE_HATCHTAB:
413 if (pDocShell)
414 xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
415 break;
416 case SC_SERVICE_BITMAPTAB:
417 if (pDocShell)
418 xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
419 break;
420 case SC_SERVICE_TRGRADTAB:
421 if (pDocShell)
422 xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
423 break;
424 case SC_SERVICE_MARKERTAB:
425 if (pDocShell)
426 xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
427 break;
428 case SC_SERVICE_DASHTAB:
429 if (pDocShell)
430 xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
431 break;
432 case SC_SERVICE_NUMRULES:
433 if (pDocShell)
434 xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
435 break;
436 case SC_SERVICE_DOCSPRSETT:
437 case SC_SERVICE_SHEETDOCSET:
438 case SC_SERVICE_DOCCONF:
439 if (pDocShell)
440 xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
441 break;
443 case SC_SERVICE_IMAP_RECT:
444 xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
445 break;
446 case SC_SERVICE_IMAP_CIRC:
447 xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
448 break;
449 case SC_SERVICE_IMAP_POLY:
450 xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
451 break;
453 // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
454 case SC_SERVICE_EXPORT_GOR:
455 xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
456 break;
458 case SC_SERVICE_IMPORT_GOR:
459 xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
460 break;
462 case SC_SERVICE_EXPORT_EOR:
463 if (pDocShell)
464 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
465 break;
467 case SC_SERVICE_IMPORT_EOR:
468 if (pDocShell)
469 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
470 break;
472 case SC_SERVICE_VALBIND:
473 case SC_SERVICE_LISTCELLBIND:
474 if (pDocShell)
476 sal_Bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
477 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
478 xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
480 break;
481 case SC_SERVICE_LISTSOURCE:
482 if (pDocShell)
484 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
485 xRet.set(*new calc::OCellListSource( xDoc ));
487 break;
488 case SC_SERVICE_CELLADDRESS:
489 case SC_SERVICE_RANGEADDRESS:
490 if (pDocShell)
492 sal_Bool bRange = ( nType == SC_SERVICE_RANGEADDRESS );
493 xRet.set(*new ScAddressConversionObj( pDocShell, bRange ));
495 break;
497 case SC_SERVICE_CHDATAPROV:
498 if (pDocShell && pDocShell->GetDocument())
499 xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
500 break;
502 case SC_SERVICE_FORMULAPARS:
503 if (pDocShell)
504 xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
505 break;
507 case SC_SERVICE_OPCODEMAPPER:
509 ScDocument* pDoc = pDocShell->GetDocument();
510 ScAddress aAddress;
511 ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
512 pComp->SetGrammar( pDoc->GetGrammar() );
513 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
515 break;
516 case SC_SERVICE_VBAOBJECTPROVIDER:
517 xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
518 break;
519 case SC_SERVICE_VBACODENAMEPROVIDER:
520 xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider( pDocShell )));
521 break;
523 return xRet;
526 uno::Sequence<rtl::OUString> ScServiceProvider::GetAllServiceNames()
528 uno::Sequence<rtl::OUString> aRet(SC_SERVICE_COUNT);
529 rtl::OUString* pArray = aRet.getArray();
530 for (sal_uInt16 i = 0; i < SC_SERVICE_COUNT; i++)
531 pArray[i] = rtl::OUString::createFromAscii( aProvNames[i] );
532 return aRet;