Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / sc / source / ui / unoobj / servuno.cxx
blobf5eeccee27e5b1403ca32b6d0d57edf35e70b36f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/macros.h>
22 #include <svtools/unoimap.hxx>
23 #include <svx/unofill.hxx>
24 #include <editeng/unonrule.hxx>
25 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/text/textfield/Type.hpp>
29 #include "servuno.hxx"
30 #include "unonames.hxx"
31 #include "cellsuno.hxx"
32 #include "fielduno.hxx"
33 #include "styleuno.hxx"
34 #include "afmtuno.hxx"
35 #include "defltuno.hxx"
36 #include "drdefuno.hxx"
37 #include "docsh.hxx"
38 #include "drwlayer.hxx"
39 #include "confuno.hxx"
40 #include "shapeuno.hxx"
41 #include "cellvaluebinding.hxx"
42 #include "celllistsource.hxx"
43 #include "addruno.hxx"
44 #include "chart2uno.hxx"
45 #include "tokenuno.hxx"
47 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
48 #include <svx/xmleohlp.hxx>
49 #include <svx/xmlgrhlp.hxx>
50 #include <sfx2/docfile.hxx>
51 #include <sfx2/docfilt.hxx>
52 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
53 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
54 #include <com/sun/star/document/XCodeNameQuery.hpp>
55 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
56 #include <com/sun/star/form/XFormsSupplier.hpp>
57 #include <svx/unomod.hxx>
58 #include <vbahelper/vbaaccesshelper.hxx>
60 #include <comphelper/processfactory.hxx>
61 #include <basic/basmgr.hxx>
62 #include <sfx2/app.hxx>
64 #include <cppuhelper/component_context.hxx>
65 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
67 using namespace ::com::sun::star;
69 bool isInVBAMode( ScDocShell& rDocSh )
71 uno::Reference<script::XLibraryContainer> xLibContainer = rDocSh.GetBasicContainer();
72 uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY );
73 if ( xVBACompat.is() )
74 return xVBACompat->getVBACompatibilityMode();
75 return false;
78 class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
80 uno::Any maWorkbook;
81 uno::Any maCachedObject;
82 ScDocShell* mpDocShell;
83 public:
84 ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
86 ScDocument* pDoc = mpDocShell->GetDocument();
87 if ( !pDoc )
88 throw uno::RuntimeException("", uno::Reference< uno::XInterface >() );
90 uno::Sequence< uno::Any > aArgs(2);
91 // access the application object ( parent for workbook )
92 aArgs[0] = uno::Any( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", uno::Sequence< uno::Any >() ) );
93 aArgs[1] = uno::Any( mpDocShell->GetModel() );
94 maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
97 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw (::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
99 SolarMutexGuard aGuard;
100 maCachedObject = uno::Any(); // clear cached object
102 ScDocument* pDoc = mpDocShell->GetDocument();
103 if ( !pDoc )
104 throw uno::RuntimeException();
105 // aName is generated from the stream name which can be different ( case-wise )
106 // from the code name
107 if( aName.equalsIgnoreAsciiCase( pDoc->GetCodeName() ) )
108 maCachedObject = maWorkbook;
109 else
111 OUString sCodeName;
112 SCTAB nCount = pDoc->GetTableCount();
113 for( SCTAB i = 0; i < nCount; i++ )
115 pDoc->GetCodeName( i, sCodeName );
116 // aName is generated from the stream name which can be different ( case-wise )
117 // from the code name
118 if( sCodeName.equalsIgnoreAsciiCase( aName ) )
120 OUString sSheetName;
121 if( pDoc->GetName( i, sSheetName ) )
123 uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
124 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
125 uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
126 uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
127 uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
128 uno::Sequence< uno::Any > aArgs(3);
129 aArgs[0] = maWorkbook;
130 aArgs[1] = uno::Any( xModel );
131 aArgs[2] = uno::Any( OUString( sSheetName ) );
132 // use the convience function
133 maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
134 break;
139 return maCachedObject.hasValue();
142 ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
144 SolarMutexGuard aGuard;
145 OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
146 OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
147 if ( !hasByName( aName ) )
148 throw ::com::sun::star::container::NoSuchElementException();
149 return maCachedObject;
151 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
153 SolarMutexGuard aGuard;
154 ScDocument* pDoc = mpDocShell->GetDocument();
155 if ( !pDoc )
156 throw uno::RuntimeException();
157 SCTAB nCount = pDoc->GetTableCount();
158 uno::Sequence< OUString > aNames( nCount + 1 );
159 SCTAB index = 0;
160 OUString sCodeName;
161 for( ; index < nCount; ++index )
163 pDoc->GetCodeName( index, sCodeName );
164 aNames[ index ] = sCodeName;
166 aNames[ index ] = pDoc->GetCodeName();
167 return aNames;
169 // XElemenAccess
170 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE { return uno::Type(); }
171 virtual sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE { return sal_True; }
175 class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
177 ScDocShell& mrDocShell;
178 public:
179 ScVbaCodeNameProvider( ScDocShell& rDocShell ) : mrDocShell(rDocShell) {}
180 // XCodeNameQuery
181 OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
183 SolarMutexGuard aGuard;
184 OUString sCodeName;
186 // need to find the page ( and index ) for this control
187 uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
188 uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
189 sal_Int32 nLen = xIndex->getCount();
190 bool bMatched = false;
191 for ( sal_Int32 index = 0; index < nLen; ++index )
195 uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
196 uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
197 // get the www-standard container
198 uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
199 sal_Int32 nCntrls = xFormControls->getCount();
200 for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
202 uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
203 bMatched = ( xControl == xIf );
204 if ( bMatched )
206 OUString sName;
207 mrDocShell.GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
208 sCodeName = sName;
212 catch( uno::Exception& ) {}
213 if ( bMatched )
214 break;
216 // Probably should throw here ( if !bMatched )
217 return sCodeName;
220 OUString SAL_CALL getCodeNameForContainer( const uno::Reference<uno::XInterface>& xContainer )
221 throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
223 SolarMutexGuard aGuard;
224 uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mrDocShell.GetModel(), uno::UNO_QUERY_THROW);
225 uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
227 for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
231 uno::Reference<form::XFormsSupplier> xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
232 uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
233 // get the www-standard container
234 uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
235 if (xFormControls == xContainer)
237 OUString aName;
238 if (mrDocShell.GetDocument()->GetCodeName(static_cast<SCTAB>(i), aName))
239 return aName;
242 catch( uno::Exception& ) {}
244 return OUString();
248 struct ProvNamesId_Type
250 const char * pName;
251 sal_uInt16 nType;
254 static const ProvNamesId_Type aProvNamesId[] =
256 { "com.sun.star.sheet.Spreadsheet", SC_SERVICE_SHEET },
257 { "com.sun.star.text.TextField.URL", SC_SERVICE_URLFIELD },
258 { "com.sun.star.text.TextField.PageNumber", SC_SERVICE_PAGEFIELD },
259 { "com.sun.star.text.TextField.PageCount", SC_SERVICE_PAGESFIELD },
260 { "com.sun.star.text.TextField.Date", SC_SERVICE_DATEFIELD },
261 { "com.sun.star.text.TextField.Time", SC_SERVICE_TIMEFIELD },
262 { "com.sun.star.text.TextField.DateTime", SC_SERVICE_EXT_TIMEFIELD },
263 { "com.sun.star.text.TextField.DocInfo.Title", SC_SERVICE_TITLEFIELD },
264 { "com.sun.star.text.TextField.FileName", SC_SERVICE_FILEFIELD },
265 { "com.sun.star.text.TextField.SheetName", SC_SERVICE_SHEETFIELD },
266 { "com.sun.star.style.CellStyle", SC_SERVICE_CELLSTYLE },
267 { "com.sun.star.style.PageStyle", SC_SERVICE_PAGESTYLE },
268 { "com.sun.star.sheet.TableAutoFormat", SC_SERVICE_AUTOFORMAT },
269 { "com.sun.star.sheet.SheetCellRanges", SC_SERVICE_CELLRANGES },
270 { "com.sun.star.drawing.GradientTable", SC_SERVICE_GRADTAB },
271 { "com.sun.star.drawing.HatchTable", SC_SERVICE_HATCHTAB },
272 { "com.sun.star.drawing.BitmapTable", SC_SERVICE_BITMAPTAB },
273 { "com.sun.star.drawing.TransparencyGradientTable", SC_SERVICE_TRGRADTAB },
274 { "com.sun.star.drawing.MarkerTable", SC_SERVICE_MARKERTAB },
275 { "com.sun.star.drawing.DashTable", SC_SERVICE_DASHTAB },
276 { "com.sun.star.text.NumberingRules", SC_SERVICE_NUMRULES },
277 { "com.sun.star.sheet.Defaults", SC_SERVICE_DOCDEFLTS },
278 { "com.sun.star.drawing.Defaults", SC_SERVICE_DRAWDEFLTS },
279 { "com.sun.star.comp.SpreadsheetSettings", SC_SERVICE_DOCSPRSETT },
280 { "com.sun.star.document.Settings", SC_SERVICE_DOCCONF },
281 { "com.sun.star.image.ImageMapRectangleObject", SC_SERVICE_IMAP_RECT },
282 { "com.sun.star.image.ImageMapCircleObject", SC_SERVICE_IMAP_CIRC },
283 { "com.sun.star.image.ImageMapPolygonObject", SC_SERVICE_IMAP_POLY },
285 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
286 { "com.sun.star.document.ExportGraphicObjectResolver", SC_SERVICE_EXPORT_GOR },
287 { "com.sun.star.document.ImportGraphicObjectResolver", SC_SERVICE_IMPORT_GOR },
288 { "com.sun.star.document.ExportEmbeddedObjectResolver", SC_SERVICE_EXPORT_EOR },
289 { "com.sun.star.document.ImportEmbeddedObjectResolver", SC_SERVICE_IMPORT_EOR },
291 { SC_SERVICENAME_VALBIND, SC_SERVICE_VALBIND },
292 { SC_SERVICENAME_LISTCELLBIND, SC_SERVICE_LISTCELLBIND },
293 { SC_SERVICENAME_LISTSOURCE, SC_SERVICE_LISTSOURCE },
294 { SC_SERVICENAME_CELLADDRESS, SC_SERVICE_CELLADDRESS },
295 { SC_SERVICENAME_RANGEADDRESS, SC_SERVICE_RANGEADDRESS },
297 { "com.sun.star.sheet.DocumentSettings",SC_SERVICE_SHEETDOCSET },
299 { SC_SERVICENAME_CHDATAPROV, SC_SERVICE_CHDATAPROV },
300 { SC_SERVICENAME_FORMULAPARS, SC_SERVICE_FORMULAPARS },
301 { SC_SERVICENAME_OPCODEMAPPER, SC_SERVICE_OPCODEMAPPER },
302 { "ooo.vba.VBAObjectModuleObjectProvider", SC_SERVICE_VBAOBJECTPROVIDER },
303 { "ooo.vba.VBACodeNameProvider", SC_SERVICE_VBACODENAMEPROVIDER },
304 { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS },
306 // case-correct versions of the service names (#i102468#)
307 { "com.sun.star.text.textfield.URL", SC_SERVICE_URLFIELD },
308 { "com.sun.star.text.textfield.PageNumber", SC_SERVICE_PAGEFIELD },
309 { "com.sun.star.text.textfield.PageCount", SC_SERVICE_PAGESFIELD },
310 { "com.sun.star.text.textfield.Date", SC_SERVICE_DATEFIELD },
311 { "com.sun.star.text.textfield.Time", SC_SERVICE_TIMEFIELD },
312 { "com.sun.star.text.textfield.DateTime", SC_SERVICE_EXT_TIMEFIELD },
313 { "com.sun.star.text.textfield.docinfo.Title", SC_SERVICE_TITLEFIELD },
314 { "com.sun.star.text.textfield.FileName", SC_SERVICE_FILEFIELD },
315 { "com.sun.star.text.textfield.SheetName", SC_SERVICE_SHEETFIELD },
316 { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS },
320 // old service names that were in 567 still work in createInstance,
321 // in case some macro is still using them
324 static const sal_Char* aOldNames[SC_SERVICE_COUNT] =
326 "", // SC_SERVICE_SHEET
327 "stardiv.one.text.TextField.URL", // SC_SERVICE_URLFIELD
328 "stardiv.one.text.TextField.PageNumber", // SC_SERVICE_PAGEFIELD
329 "stardiv.one.text.TextField.PageCount", // SC_SERVICE_PAGESFIELD
330 "stardiv.one.text.TextField.Date", // SC_SERVICE_DATEFIELD
331 "stardiv.one.text.TextField.Time", // SC_SERVICE_TIMEFIELD
332 "stardiv.one.text.TextField.DocumentTitle", // SC_SERVICE_TITLEFIELD
333 "stardiv.one.text.TextField.FileName", // SC_SERVICE_FILEFIELD
334 "stardiv.one.text.TextField.SheetName", // SC_SERVICE_SHEETFIELD
335 "stardiv.one.style.CellStyle", // SC_SERVICE_CELLSTYLE
336 "stardiv.one.style.PageStyle", // SC_SERVICE_PAGESTYLE
337 "", // SC_SERVICE_AUTOFORMAT
338 "", // SC_SERVICE_CELLRANGES
339 "", // SC_SERVICE_GRADTAB
340 "", // SC_SERVICE_HATCHTAB
341 "", // SC_SERVICE_BITMAPTAB
342 "", // SC_SERVICE_TRGRADTAB
343 "", // SC_SERVICE_MARKERTAB
344 "", // SC_SERVICE_DASHTAB
345 "", // SC_SERVICE_NUMRULES
346 "", // SC_SERVICE_DOCDEFLTS
347 "", // SC_SERVICE_DRAWDEFLTS
348 "", // SC_SERVICE_DOCSPRSETT
349 "", // SC_SERVICE_DOCCONF
350 "", // SC_SERVICE_IMAP_RECT
351 "", // SC_SERVICE_IMAP_CIRC
352 "", // SC_SERVICE_IMAP_POLY
354 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
355 "", // SC_SERVICE_EXPORT_GOR
356 "", // SC_SERVICE_IMPORT_GOR
357 "", // SC_SERVICE_EXPORT_EOR
358 "", // SC_SERVICE_IMPORT_EOR
360 "", // SC_SERVICE_VALBIND
361 "", // SC_SERVICE_LISTCELLBIND
362 "", // SC_SERVICE_LISTSOURCE
363 "", // SC_SERVICE_CELLADDRESS
364 "", // SC_SERVICE_RANGEADDRESS
365 "", // SC_SERVICE_SHEETDOCSET
366 "", // SC_SERVICE_CHDATAPROV
367 "", // SC_SERVICE_FORMULAPARS
368 "", // SC_SERVICE_OPCODEMAPPER
369 "", // SC_SERVICE_VBAOBJECTPROVIDER
370 "", // SC_SERVICE_VBACODENAMEPROVIDER
371 "", // SC_SERVICE_VBAGLOBALS
372 "", // SC_SERVICE_EXT_TIMEFIELD
378 // alles static
381 sal_uInt16 ScServiceProvider::GetProviderType(const OUString& rServiceName)
383 if (!rServiceName.isEmpty())
385 const sal_uInt16 nEntries =
386 sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
387 for (sal_uInt16 i = 0; i < nEntries; i++)
389 if (rServiceName.equalsAscii( aProvNamesId[i].pName ))
391 return aProvNamesId[i].nType;
395 sal_uInt16 i;
396 for (i=0; i<SC_SERVICE_COUNT; i++)
398 OSL_ENSURE( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
399 if (rServiceName.equalsAscii( aOldNames[i] ))
401 OSL_FAIL("old service name used");
402 return i;
406 return SC_SERVICE_INVALID;
409 namespace {
411 sal_Int32 getFieldType(sal_uInt16 nOldType)
413 switch (nOldType)
415 case SC_SERVICE_URLFIELD:
416 return text::textfield::Type::URL;
417 case SC_SERVICE_PAGEFIELD:
418 return text::textfield::Type::PAGE;
419 case SC_SERVICE_PAGESFIELD:
420 return text::textfield::Type::PAGES;
421 case SC_SERVICE_DATEFIELD:
422 return text::textfield::Type::DATE;
423 case SC_SERVICE_TIMEFIELD:
424 return text::textfield::Type::TIME;
425 case SC_SERVICE_EXT_TIMEFIELD:
426 return text::textfield::Type::EXTENDED_TIME;
427 case SC_SERVICE_TITLEFIELD:
428 return text::textfield::Type::DOCINFO_TITLE;
429 case SC_SERVICE_FILEFIELD:
430 return text::textfield::Type::EXTENDED_FILE;
431 case SC_SERVICE_SHEETFIELD:
432 return text::textfield::Type::TABLE;
433 default:
437 return text::textfield::Type::URL; // default to URL for no reason whatsoever.
442 uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
443 sal_uInt16 nType, ScDocShell* pDocShell )
445 uno::Reference<uno::XInterface> xRet;
446 switch (nType)
448 case SC_SERVICE_SHEET:
449 // noch nicht eingefuegt - DocShell=Null
450 xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
451 break;
452 case SC_SERVICE_URLFIELD:
453 case SC_SERVICE_PAGEFIELD:
454 case SC_SERVICE_PAGESFIELD:
455 case SC_SERVICE_DATEFIELD:
456 case SC_SERVICE_TIMEFIELD:
457 case SC_SERVICE_EXT_TIMEFIELD:
458 case SC_SERVICE_TITLEFIELD:
459 case SC_SERVICE_FILEFIELD:
460 case SC_SERVICE_SHEETFIELD:
462 uno::Reference<text::XTextRange> xNullContent;
463 xRet.set(static_cast<text::XTextField*>(
464 new ScEditFieldObj(xNullContent, NULL, getFieldType(nType), ESelection())));
466 break;
467 case SC_SERVICE_CELLSTYLE:
468 xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, OUString() ));
469 break;
470 case SC_SERVICE_PAGESTYLE:
471 xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, OUString() ));
472 break;
473 case SC_SERVICE_AUTOFORMAT:
474 xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
475 break;
476 case SC_SERVICE_CELLRANGES:
477 // wird nicht eingefuegt, sondern gefuellt
478 // -> DocShell muss gesetzt sein, aber leere Ranges
479 if (pDocShell)
480 xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
481 break;
483 case SC_SERVICE_DOCDEFLTS:
484 if (pDocShell)
485 xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
486 break;
487 case SC_SERVICE_DRAWDEFLTS:
488 if (pDocShell)
489 xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
490 break;
492 // Drawing layer tables are not in SvxUnoDrawMSFactory,
493 // because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
494 // Drawing layer is always allocated if not there (MakeDrawLayer).
496 case SC_SERVICE_GRADTAB:
497 if (pDocShell)
498 xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
499 break;
500 case SC_SERVICE_HATCHTAB:
501 if (pDocShell)
502 xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
503 break;
504 case SC_SERVICE_BITMAPTAB:
505 if (pDocShell)
506 xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
507 break;
508 case SC_SERVICE_TRGRADTAB:
509 if (pDocShell)
510 xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
511 break;
512 case SC_SERVICE_MARKERTAB:
513 if (pDocShell)
514 xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
515 break;
516 case SC_SERVICE_DASHTAB:
517 if (pDocShell)
518 xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
519 break;
520 case SC_SERVICE_NUMRULES:
521 if (pDocShell)
522 xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
523 break;
524 case SC_SERVICE_DOCSPRSETT:
525 case SC_SERVICE_SHEETDOCSET:
526 case SC_SERVICE_DOCCONF:
527 if (pDocShell)
528 xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
529 break;
531 case SC_SERVICE_IMAP_RECT:
532 xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
533 break;
534 case SC_SERVICE_IMAP_CIRC:
535 xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
536 break;
537 case SC_SERVICE_IMAP_POLY:
538 xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
539 break;
541 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
542 case SC_SERVICE_EXPORT_GOR:
543 xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
544 break;
546 case SC_SERVICE_IMPORT_GOR:
547 xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
548 break;
550 case SC_SERVICE_EXPORT_EOR:
551 if (pDocShell)
552 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
553 break;
555 case SC_SERVICE_IMPORT_EOR:
556 if (pDocShell)
557 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
558 break;
560 case SC_SERVICE_VALBIND:
561 case SC_SERVICE_LISTCELLBIND:
562 if (pDocShell)
564 bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
565 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
566 xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
568 break;
569 case SC_SERVICE_LISTSOURCE:
570 if (pDocShell)
572 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
573 xRet.set(*new calc::OCellListSource( xDoc ));
575 break;
576 case SC_SERVICE_CELLADDRESS:
577 case SC_SERVICE_RANGEADDRESS:
578 if (pDocShell)
580 bool bIsRange = ( nType == SC_SERVICE_RANGEADDRESS );
581 xRet.set(*new ScAddressConversionObj( pDocShell, bIsRange ));
583 break;
585 case SC_SERVICE_CHDATAPROV:
586 if (pDocShell && pDocShell->GetDocument())
587 xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
588 break;
590 case SC_SERVICE_FORMULAPARS:
591 if (pDocShell)
592 xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
593 break;
595 case SC_SERVICE_OPCODEMAPPER:
596 if (pDocShell)
598 ScDocument* pDoc = pDocShell->GetDocument();
599 ScAddress aAddress;
600 ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
601 pComp->SetGrammar( pDoc->GetGrammar() );
602 SAL_WNODEPRECATED_DECLARATIONS_PUSH
603 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
604 SAL_WNODEPRECATED_DECLARATIONS_POP
605 break;
607 #ifndef DISABLE_SCRIPTING
608 case SC_SERVICE_VBAOBJECTPROVIDER:
609 if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
611 OSL_TRACE("**** creating VBA Object mapper");
612 xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
614 break;
615 case SC_SERVICE_VBACODENAMEPROVIDER:
616 if ( pDocShell && isInVBAMode( *pDocShell ) )
618 OSL_TRACE("**** creating VBA Object provider");
619 xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider(*pDocShell)));
621 break;
622 case SC_SERVICE_VBAGLOBALS:
623 if (pDocShell)
625 uno::Any aGlobs;
626 if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
628 uno::Sequence< uno::Any > aArgs(1);
629 aArgs[ 0 ] <<= pDocShell->GetModel();
630 xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( OUString( "ooo.vba.excel.Globals" ), aArgs );
631 pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
632 BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
633 if ( pAppMgr )
634 pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
636 // create the VBA document event processor
637 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
638 ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
639 pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents );
642 break;
643 #endif
646 return xRet;
649 uno::Sequence<OUString> ScServiceProvider::GetAllServiceNames()
651 const sal_uInt16 nEntries = sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
652 uno::Sequence<OUString> aRet(nEntries);
653 OUString* pArray = aRet.getArray();
654 for (sal_uInt16 i = 0; i < nEntries; i++)
656 pArray[i] = OUString::createFromAscii( aProvNamesId[i].pName );
658 return aRet;
662 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */